@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.
- package/agents/a2h-executor.md +37 -0
- package/env-requirements.json +15 -1
- package/i18n/platforms/codebuddy/skills/a2h-app-migrate/SKILL.unique.md +2 -2
- package/i18n/platforms/deveco/skills/a2h-app-migrate/SKILL.unique.md +1 -1
- package/i18n/platforms/opencode/skills/a2h-app-migrate/SKILL.unique.md +13 -6
- package/i18n/skills/a2h-app-migrate/SKILL.md +2 -2
- package/i18n/skills/a2h-app-migrate/references/workflow.yaml +27 -4
- package/i18n/skills/a2h-app-migrate/scripts/opencode_depth.mjs +418 -0
- package/i18n/skills/a2h-arkts-logic-coder/references/ISSUES.md +2 -0
- package/i18n/skills/a2h-batch-ui-align/SKILL.md +7 -7
- package/i18n/skills/a2h-batch-ui-align/references/cards/alignment.md +1 -1
- package/i18n/skills/a2h-batch-ui-align/references/cards/state.md +20 -2
- package/i18n/skills/a2h-batch-ui-align/references/cards/widgets.md +2 -2
- package/i18n/skills/a2h-batch-ui-align/references/checker-rules.md +3 -3
- package/i18n/skills/a2h-batch-ui-align/references/conversion-procedure.md +3 -1
- package/i18n/skills/a2h-batch-ui-align/references/incremental-scope.md +2 -2
- package/i18n/skills/a2h-batch-ui-align/references/step3-capture.md +10 -6
- package/i18n/skills/a2h-batch-ui-align/references/step5-convert.md +13 -9
- package/i18n/skills/a2h-batch-ui-align/scripts/build_conversion_set.mjs +59 -7
- package/i18n/skills/a2h-batch-ui-align/scripts/group_pack.mjs +3 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/interactions.mjs +186 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/phase5_check.mjs +33 -7
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/hit_test.ts +83 -22
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/media_tint.ts +39 -5
- package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_scroll_padding_raster.test.mjs +25 -1
- package/i18n/skills/a2h-page-specgen/SKILL.md +1 -1
- package/i18n/skills/a2h-page-specgen/references/gates.md +3 -1
- package/i18n/skills/a2h-page-specgen/references/scenario-authoring.md +11 -11
- package/i18n/skills/a2h-page-specgen/references/spec-template.md +3 -3
- package/i18n/skills/a2h-page-specgen/scripts/contract-calls.mjs +40 -3
- package/i18n/skills/a2h-page-specgen/scripts/entry-evidence.mjs +73 -5
- package/i18n/skills/a2h-page-specgen/scripts/gate.mjs +144 -0
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.prompt.md +11 -11
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.worker.md +11 -11
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.prompt.md +11 -11
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.worker.md +11 -11
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.json +10 -10
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.post-review.json +1 -1
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.prompt.md +11 -11
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.worker.md +11 -11
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.prompt.md +11 -11
- package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.worker.md +11 -11
- package/i18n/skills/a2h-page-specgen/scripts/test/contract-calls.test.mjs +45 -1
- package/i18n/skills/a2h-page-specgen/scripts/test/entry-evidence.test.mjs +100 -0
- package/i18n/skills/a2h-page-specgen/scripts/test/gate.test.mjs +132 -3
- package/i18n/skills/a2h-resource-convert/scripts/a2h_resource_convert.ts +36 -1
- package/i18n/skills/a2h-spec-design-pipeline/SKILL.md +1 -1
- package/i18n/skills/a2h-spec-design-pipeline/references/coding-loop.md +16 -0
- package/i18n/skills/a2h-utg-static/SKILL.md +2 -0
- package/package.json +1 -1
- package/platforms/atomcode/agents/a2h-executor.frontmatter.md +6 -0
- package/platforms/codebuddy/agents/a2h-executor.frontmatter.md +5 -0
- package/platforms/codebuddy/skills/a2h-app-migrate/SKILL.unique.md +2 -2
- package/platforms/deveco/agents/a2h-executor.frontmatter.md +7 -0
- package/platforms/deveco/agents/build-fixer.frontmatter.md +0 -2
- package/platforms/deveco/agents/code-reviewer.frontmatter.md +0 -2
- package/platforms/deveco/agents/model-render-worker.frontmatter.md +0 -2
- package/platforms/deveco/agents/model-worker.frontmatter.md +0 -2
- package/platforms/deveco/agents/specgen-worker.frontmatter.md +0 -2
- package/platforms/deveco/skills/a2h-app-migrate/SKILL.unique.md +1 -1
- package/platforms/opencode/agents/a2h-executor.frontmatter.md +7 -0
- package/platforms/opencode/agents/build-fixer.frontmatter.md +0 -2
- package/platforms/opencode/agents/code-reviewer.frontmatter.md +0 -2
- package/platforms/opencode/agents/model-render-worker.frontmatter.md +0 -2
- package/platforms/opencode/agents/model-worker.frontmatter.md +0 -2
- package/platforms/opencode/agents/specgen-worker.frontmatter.md +0 -2
- package/platforms/opencode/skills/a2h-app-migrate/SKILL.unique.md +13 -6
- package/skills/a2h-app-migrate/SKILL.md +29 -3
- package/skills/a2h-app-migrate/references/host-rules.md +33 -0
- package/skills/a2h-app-migrate/references/workflow.yaml +24 -4
- package/skills/a2h-app-migrate/scripts/opencode_depth.mjs +418 -0
- package/skills/a2h-app-migrate/test/test_executor_header_sync.mjs +78 -0
- package/skills/a2h-app-migrate/test/test_opencode_depth.mjs +312 -0
- package/skills/a2h-app-migrate/tools/dag.mjs +267 -0
- package/skills/a2h-arkts-logic-coder/references/ISSUES.md +2 -0
- package/skills/a2h-batch-ui-align/SKILL.md +7 -7
- package/skills/a2h-batch-ui-align/references/cards/alignment.md +1 -1
- package/skills/a2h-batch-ui-align/references/cards/state.md +20 -2
- package/skills/a2h-batch-ui-align/references/cards/widgets.md +2 -2
- package/skills/a2h-batch-ui-align/references/checker-rules.md +3 -3
- package/skills/a2h-batch-ui-align/references/conversion-procedure.md +3 -1
- package/skills/a2h-batch-ui-align/references/host-dispatch.md +5 -5
- package/skills/a2h-batch-ui-align/references/incremental-scope.md +2 -2
- package/skills/a2h-batch-ui-align/references/step3-capture.md +10 -6
- package/skills/a2h-batch-ui-align/references/step5-convert.md +13 -9
- package/skills/a2h-batch-ui-align/scripts/build_conversion_set.mjs +59 -7
- package/skills/a2h-batch-ui-align/scripts/group_pack.mjs +3 -0
- package/skills/a2h-batch-ui-align/scripts/group_pass.mjs +3 -2
- package/skills/a2h-batch-ui-align/scripts/group_queue.mjs +139 -23
- package/skills/a2h-batch-ui-align/scripts/host_env.mjs +32 -8
- package/skills/a2h-batch-ui-align/scripts/interactions.mjs +186 -0
- package/skills/a2h-batch-ui-align/scripts/phase5_check.mjs +33 -7
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/hit_test.ts +83 -22
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/media_tint.ts +39 -5
- package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_hit_test.test.mjs +82 -0
- package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_scroll_padding_raster.test.mjs +25 -1
- package/skills/a2h-batch-ui-align/scripts/tests/group_queue.test.mjs +184 -2
- package/skills/a2h-batch-ui-align/scripts/tests/host_env.test.mjs +33 -0
- package/skills/a2h-batch-ui-align/scripts/tests/interactions.test.mjs +258 -0
- package/skills/a2h-page-specgen/SKILL.md +1 -1
- package/skills/a2h-page-specgen/references/evidence.md +15 -0
- package/skills/a2h-page-specgen/references/gates.md +3 -1
- package/skills/a2h-page-specgen/references/scenario-authoring.md +10 -10
- package/skills/a2h-page-specgen/references/spec-template.md +2 -2
- package/skills/a2h-page-specgen/scripts/contract-calls.mjs +40 -3
- package/skills/a2h-page-specgen/scripts/entry-evidence.mjs +73 -5
- package/skills/a2h-page-specgen/scripts/gate.mjs +141 -0
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.prompt.md +10 -10
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.worker.md +10 -10
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.prompt.md +10 -10
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.worker.md +10 -10
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.json +10 -10
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.post-review.json +1 -1
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.prompt.md +10 -10
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.worker.md +10 -10
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.prompt.md +10 -10
- package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.worker.md +10 -10
- package/skills/a2h-page-specgen/scripts/test/contract-calls.test.mjs +45 -1
- package/skills/a2h-page-specgen/scripts/test/entry-evidence.test.mjs +100 -0
- package/skills/a2h-page-specgen/scripts/test/gate.test.mjs +104 -3
- package/skills/a2h-resource-convert/references/conversion-rules.md +2 -0
- package/skills/a2h-resource-convert/scripts/a2h_resource_convert.ts +36 -1
- package/skills/a2h-resource-convert/scripts/tests/adaptive_icon.test.mjs +42 -0
- package/skills/a2h-spec-design-pipeline/SKILL.md +1 -1
- package/skills/a2h-spec-design-pipeline/references/coding-loop.md +16 -0
- package/skills/a2h-spec-design-pipeline/references/execution-model.md +2 -2
- package/skills/a2h-spec-design-pipeline/references/static-defect-gate.md +5 -1
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/config/ruleMeta.json +5 -0
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/config/ruleSet.json +4 -0
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/arkui-runtime-pitfall-cn.md +2 -1
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/arkui-runtime-pitfall-en.md +3 -1
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/arkui-v2-observation-cn.md +105 -0
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/arkui-v2-observation-en.md +122 -0
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/ArkUIRuntimePitfallCheck.js +4 -4
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/ArkUIV2ObservationCheck.js +1862 -0
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/index.js +2 -0
- package/skills/a2h-spec-design-pipeline/rules/migration-rules/package.json +1 -1
- package/skills/a2h-spec-design-pipeline/scripts/dispatch/wait.mjs +15 -2
- package/skills/a2h-spec-design-pipeline/scripts/dispatch.mjs +20 -4
- package/skills/a2h-spec-design-pipeline/scripts/test_arkui_v2_observation.ts +284 -0
- package/skills/a2h-spec-design-pipeline/scripts/test_dispatch_commands.mjs +32 -0
- package/skills/a2h-spec-design-pipeline/scripts/test_dispatch_wait.mjs +22 -1
- package/skills/a2h-utg-static/SKILL.md +2 -0
- package/skills/a2h-utg-static/references/extractors.md +16 -0
- package/skills/a2h-utg-static/scripts/run_pipeline.mjs +22 -1
- package/skills/a2h-utg-static/scripts/tests/regression_matrix.mjs +4 -0
- package/skills/a2h-utg-static/scripts/tests/test_pr169_review_fixes.mjs +15 -0
- package/skills/a2h-utg-static/scripts/tests/test_view_attachments.mjs +330 -0
- package/skills/a2h-utg-static/scripts/view_attachments.mjs +465 -0
- package/platforms/codebuddy/agents/build-fixer.frontmatter.md +0 -5
- package/platforms/codebuddy/agents/code-reviewer.frontmatter.md +0 -5
- package/platforms/codebuddy/agents/model-render-worker.frontmatter.md +0 -5
- package/platforms/codebuddy/agents/model-worker.frontmatter.md +0 -5
- package/platforms/codebuddy/agents/specgen-worker.frontmatter.md +0 -5
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import test from "node:test";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
|
|
7
|
+
// agents/a2h-executor.md repeats the common task-prompt header of policy.dispatch: the header
|
|
8
|
+
// stays in force when a host falls back to its general agent. Guard the parts both must share,
|
|
9
|
+
// reading the header section itself rather than the whole file.
|
|
10
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
const ROOT = path.join(HERE, "..", "..", "..");
|
|
12
|
+
const read = (rel) => fs.readFileSync(path.join(ROOT, rel), "utf8");
|
|
13
|
+
const agent = read("agents/a2h-executor.md");
|
|
14
|
+
|
|
15
|
+
const between = (text, start, end, what) => {
|
|
16
|
+
const a = text.indexOf(start);
|
|
17
|
+
assert.ok(a >= 0, `${what}: start marker not found: ${start}`);
|
|
18
|
+
const b = text.indexOf(end, a + start.length);
|
|
19
|
+
assert.ok(b > a, `${what}: end marker not found: ${end}`);
|
|
20
|
+
return text.slice(a, b);
|
|
21
|
+
};
|
|
22
|
+
// Under an English staging build (build-lang/en-*) there is no i18n/ tree and the zh workflow is already
|
|
23
|
+
// English: this check guards the source tree only, so skip there.
|
|
24
|
+
const SOURCE_TREE = fs.existsSync(path.join(ROOT, "i18n", "skills", "a2h-app-migrate", "references", "workflow.yaml"))
|
|
25
|
+
&& read("skills/a2h-app-migrate/references/workflow.yaml").includes("通用头:");
|
|
26
|
+
const workflows = !SOURCE_TREE ? [] : [
|
|
27
|
+
{ lang: "zh", file: "skills/a2h-app-migrate/references/workflow.yaml", marks: ["通用头:", "primary 收到返回后:"] },
|
|
28
|
+
{ lang: "en", file: "i18n/skills/a2h-app-migrate/references/workflow.yaml", marks: ["Common header:", "After a sub-agent returns, the primary:"] },
|
|
29
|
+
].map((w) => {
|
|
30
|
+
const text = read(w.file);
|
|
31
|
+
// policy.dispatch up to the primary's after-return steps; the common header is its tail
|
|
32
|
+
const dispatch = between(text, "\n dispatch: |", w.marks[1], `${w.lang} policy.dispatch`);
|
|
33
|
+
const header = dispatch.slice(dispatch.indexOf(w.marks[0]));
|
|
34
|
+
assert.ok(dispatch.includes(w.marks[0]), `${w.lang}: common header marker not found`);
|
|
35
|
+
return { ...w, text, dispatch, header };
|
|
36
|
+
});
|
|
37
|
+
const SKIP = { skip: SOURCE_TREE ? false : "English staging tree: no i18n/ sources" };
|
|
38
|
+
const NEEDS_INPUT = '{ "ok": false, "needs_input": { "question": "...", "options": [...], "context": "..." } }';
|
|
39
|
+
|
|
40
|
+
test("a2h-executor and the common header share the needs_input reply shape", SKIP, () => {
|
|
41
|
+
assert.ok(agent.includes(NEEDS_INPUT), "agents/a2h-executor.md lost the needs_input shape");
|
|
42
|
+
for (const w of workflows) assert.ok(w.header.includes(NEEDS_INPUT), `${w.lang} common header lost the needs_input shape`);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// rule 8 of the agent ("Stay inside the node"), not just any mention elsewhere in the file
|
|
46
|
+
const rule8 = (() => {
|
|
47
|
+
const m = agent.match(/^8\. \*\*Stay inside the node\.\*\*[^\n]*/m);
|
|
48
|
+
assert.ok(m, "agents/a2h-executor.md lost rule 8 (Stay inside the node)");
|
|
49
|
+
return m[0];
|
|
50
|
+
})();
|
|
51
|
+
|
|
52
|
+
test("both keep the Runner-owned work out of the node: ledger, before_run, after_run", SKIP, () => {
|
|
53
|
+
for (const word of ["ledger", "before_run", "after_run"]) {
|
|
54
|
+
assert.ok(rule8.toLowerCase().includes(word), `rule 8 of agents/a2h-executor.md no longer mentions ${word}`);
|
|
55
|
+
for (const w of workflows) assert.ok(w.header.includes(word), `${w.lang} common header no longer mentions ${word}`);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test("policy names a2h-executor as the node sub-agent type, in both languages", SKIP, () => {
|
|
60
|
+
for (const w of workflows) {
|
|
61
|
+
assert.match(w.text, /^\s*default_task_type:\s*a2h-executor\s*$/m, `${w.lang} default_task_type`);
|
|
62
|
+
assert.ok(w.dispatch.includes("a2h-executor"), `${w.lang} policy.dispatch names a2h-executor`);
|
|
63
|
+
assert.ok(w.dispatch.includes("fallback: general agent"), `${w.lang} policy.dispatch keeps the fallback note prefix`);
|
|
64
|
+
assert.ok(w.header.includes("a2h-executor"), `${w.lang} common header names a2h-executor`);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("every platform frontmatter of a2h-executor keeps the name a2h-executor", () => {
|
|
69
|
+
const dir = path.join(ROOT, "platforms");
|
|
70
|
+
const files = fs.readdirSync(dir)
|
|
71
|
+
.map((p) => path.join(dir, p, "agents", "a2h-executor.frontmatter.md"))
|
|
72
|
+
.filter((f) => fs.existsSync(f));
|
|
73
|
+
assert.ok(files.length > 0, "no platform frontmatter for a2h-executor");
|
|
74
|
+
assert.match(agent, /^---\r?\nname: a2h-executor\r?\n/, "agents/a2h-executor.md name");
|
|
75
|
+
for (const f of files) {
|
|
76
|
+
assert.match(fs.readFileSync(f, "utf8"), /^---\r?\nname: a2h-executor\r?\n/, path.relative(ROOT, f));
|
|
77
|
+
}
|
|
78
|
+
});
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import test from "node:test";
|
|
7
|
+
|
|
8
|
+
import { depthOf, ensure, majorOf, parseJsonc } from "../scripts/opencode_depth.mjs";
|
|
9
|
+
|
|
10
|
+
function sandbox() {
|
|
11
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "oc-depth-"));
|
|
12
|
+
const globalDir = path.join(root, "global");
|
|
13
|
+
const dir = path.join(root, "project");
|
|
14
|
+
const home = path.join(root, "home");
|
|
15
|
+
const managedDir = path.join(root, "managed");
|
|
16
|
+
for (const d of [globalDir, dir, home, managedDir]) fs.mkdirSync(d, { recursive: true });
|
|
17
|
+
return { root, globalDir, dir, home, managedDir };
|
|
18
|
+
}
|
|
19
|
+
// Isolate from this machine: no real env vars, ~/.opencode or system-managed directory.
|
|
20
|
+
let box = null;
|
|
21
|
+
const run = (o) => ensure({ env: {}, home: (box ?? o).home ?? os.tmpdir(), managedDir: (box ?? o).managedDir ?? os.tmpdir(), ...o });
|
|
22
|
+
const write = (file, value) => fs.writeFileSync(file, typeof value === "string" ? value : JSON.stringify(value));
|
|
23
|
+
const read = (file) => JSON.parse(fs.readFileSync(file, "utf8"));
|
|
24
|
+
|
|
25
|
+
test("majorOf parses opencode --version output", () => {
|
|
26
|
+
assert.equal(majorOf("1.19.6"), 1);
|
|
27
|
+
assert.equal(majorOf("opencode v2.4.2"), 2);
|
|
28
|
+
assert.equal(majorOf(null), null);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("depthOf: v1 accepts both forms, v2 only experimental", () => {
|
|
32
|
+
assert.equal(depthOf({ subagent_depth: 2 }, 1), 2);
|
|
33
|
+
assert.equal(depthOf({ experimental: { subagent_depth: 3 } }, 1), 3);
|
|
34
|
+
assert.equal(depthOf({ subagent_depth: 2 }, 2), null);
|
|
35
|
+
assert.equal(depthOf({ experimental: { subagent_depth: 2 } }, 2), 2);
|
|
36
|
+
assert.equal(depthOf({ subagent_depth: 2 }, null), 2);
|
|
37
|
+
assert.equal(depthOf({}, 1), null);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("parseJsonc strips comments and trailing commas but keeps // inside strings", () => {
|
|
41
|
+
const c = parseJsonc('{\n // c\n "a": "http://x", /* b */ "experimental": { "subagent_depth": 2, },\n}');
|
|
42
|
+
assert.equal(c.a, "http://x");
|
|
43
|
+
assert.equal(c.experimental.subagent_depth, 2);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
for (const [version, globalCfg] of [
|
|
47
|
+
["1.19.6", { subagent_depth: 2 }],
|
|
48
|
+
["1.19.6", { experimental: { subagent_depth: 2 } }],
|
|
49
|
+
["2.4.2", { experimental: { subagent_depth: 3 } }],
|
|
50
|
+
]) {
|
|
51
|
+
test(`global depth >= 2 (v${version}, ${JSON.stringify(globalCfg)}) → continue, no project file`, () => {
|
|
52
|
+
const { globalDir, dir } = (box = sandbox());
|
|
53
|
+
write(path.join(globalDir, "opencode.json"), globalCfg);
|
|
54
|
+
const r = run({ dir, version, globalDir });
|
|
55
|
+
assert.equal(r.next, "continue");
|
|
56
|
+
assert.equal(r.source, "global");
|
|
57
|
+
assert.equal(fs.existsSync(path.join(dir, "opencode.json")), false);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
test("global jsonc with comments is read", () => {
|
|
62
|
+
const { globalDir, dir } = (box = sandbox());
|
|
63
|
+
write(path.join(globalDir, "opencode.jsonc"), '{ // mine\n "experimental": { "subagent_depth": 2 } }');
|
|
64
|
+
assert.equal(run({ dir, version: "2.4.2", globalDir }).next, "continue");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("v2 ignores the v1 top-level form in global config → writes project file, no restart", () => {
|
|
68
|
+
const { globalDir, dir } = (box = sandbox());
|
|
69
|
+
write(path.join(globalDir, "opencode.json"), { subagent_depth: 2 });
|
|
70
|
+
const r = run({ dir, version: "2.4.2", globalDir });
|
|
71
|
+
assert.equal(r.action, "created");
|
|
72
|
+
assert.equal(r.next, "continue");
|
|
73
|
+
assert.deepEqual(read(path.join(dir, "opencode.json")), { experimental: { subagent_depth: 2 } });
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("v1 without global depth → project file with only the depth, restart", () => {
|
|
77
|
+
const { globalDir, dir } = (box = sandbox());
|
|
78
|
+
const r = run({ dir, version: "1.19.6", globalDir });
|
|
79
|
+
assert.equal(r.action, "created");
|
|
80
|
+
assert.equal(r.next, "restart");
|
|
81
|
+
assert.deepEqual(read(path.join(dir, "opencode.json")), { experimental: { subagent_depth: 2 } });
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test("unknown version is treated as v1 (restart)", () => {
|
|
85
|
+
const { globalDir, dir } = (box = sandbox());
|
|
86
|
+
assert.equal(run({ dir, version: "", globalDir }).next, "restart");
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test("project file already declares depth (written last run) → continue without rewriting", () => {
|
|
90
|
+
const { globalDir, dir } = (box = sandbox());
|
|
91
|
+
write(path.join(dir, "opencode.json"), { experimental: { subagent_depth: 2 } });
|
|
92
|
+
const r = run({ dir, version: "1.19.6", globalDir });
|
|
93
|
+
assert.equal(r.next, "continue");
|
|
94
|
+
assert.equal(r.source, "project");
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test("existing strict project opencode.json keeps its other keys", () => {
|
|
98
|
+
const { globalDir, dir } = (box = sandbox());
|
|
99
|
+
write(path.join(dir, "opencode.json"), { model: "x", experimental: { other: true, subagent_depth: 1 } });
|
|
100
|
+
const r = run({ dir, version: "2.4.2", globalDir });
|
|
101
|
+
assert.equal(r.action, "updated");
|
|
102
|
+
assert.deepEqual(read(path.join(dir, "opencode.json")), { model: "x", experimental: { other: true, subagent_depth: 2 } });
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("existing project jsonc with comments is not rewritten → manual", () => {
|
|
106
|
+
const { globalDir, dir } = (box = sandbox());
|
|
107
|
+
const file = path.join(dir, "opencode.jsonc");
|
|
108
|
+
const text = '{ // keep me\n "model": "x" }';
|
|
109
|
+
write(file, text);
|
|
110
|
+
const r = run({ dir, version: "1.19.6", globalDir });
|
|
111
|
+
assert.equal(r.next, "manual");
|
|
112
|
+
assert.equal(fs.readFileSync(file, "utf8"), text);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test("parseJsonc keeps ',}' and ',]' inside strings", () => {
|
|
116
|
+
const c = parseJsonc('{ "a": "x,}", "b": "y,]", "c": [1, 2,], }');
|
|
117
|
+
assert.equal(c.a, "x,}");
|
|
118
|
+
assert.equal(c.b, "y,]");
|
|
119
|
+
assert.deepEqual(c.c, [1, 2]);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test("project config overrides global: global 3 + project 1 → project file raised to 2", () => {
|
|
123
|
+
const { globalDir, dir } = (box = sandbox());
|
|
124
|
+
write(path.join(globalDir, "opencode.json"), { experimental: { subagent_depth: 3 } });
|
|
125
|
+
write(path.join(dir, "opencode.json"), { experimental: { subagent_depth: 1 } });
|
|
126
|
+
const r = run({ dir, version: "2.4.2", globalDir });
|
|
127
|
+
assert.equal(r.source, "project");
|
|
128
|
+
assert.equal(r.action, "updated");
|
|
129
|
+
assert.equal(r.report, true);
|
|
130
|
+
assert.equal(r.next, "continue");
|
|
131
|
+
assert.deepEqual(read(path.join(dir, "opencode.json")), { experimental: { subagent_depth: 2 } });
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test("project without a depth falls back to global", () => {
|
|
135
|
+
const { globalDir, dir } = (box = sandbox());
|
|
136
|
+
write(path.join(globalDir, "opencode.json"), { experimental: { subagent_depth: 2 } });
|
|
137
|
+
write(path.join(dir, "opencode.json"), { model: "x" });
|
|
138
|
+
const r = run({ dir, version: "1.19.6", globalDir });
|
|
139
|
+
assert.equal(r.source, "global");
|
|
140
|
+
assert.equal(r.next, "continue");
|
|
141
|
+
assert.deepEqual(read(path.join(dir, "opencode.json")), { model: "x" });
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test("v1 project top-level depth 1 is raised together with the experimental one", () => {
|
|
145
|
+
const { globalDir, dir } = (box = sandbox());
|
|
146
|
+
write(path.join(dir, "opencode.json"), { subagent_depth: 1 });
|
|
147
|
+
run({ dir, version: "1.19.6", globalDir });
|
|
148
|
+
assert.deepEqual(read(path.join(dir, "opencode.json")), { subagent_depth: 2, experimental: { subagent_depth: 2 } });
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
const hasGit = spawnSync("git", ["--version"]).status === 0;
|
|
152
|
+
const gitIn = (dir, ...args) => spawnSync("git", ["-C", dir, ...args], { encoding: "utf8" });
|
|
153
|
+
|
|
154
|
+
test("created file inside a git worktree is added to .git/info/exclude, not committed", { skip: !hasGit }, () => {
|
|
155
|
+
const { globalDir, dir } = (box = sandbox());
|
|
156
|
+
gitIn(dir, "init", "-q");
|
|
157
|
+
const r = run({ dir, version: "2.4.2", globalDir });
|
|
158
|
+
assert.equal(r.action, "created");
|
|
159
|
+
assert.equal(r.git.excluded, true);
|
|
160
|
+
assert.match(fs.readFileSync(path.join(dir, ".git", "info", "exclude"), "utf8"), /^\/opencode\.json$/m);
|
|
161
|
+
assert.equal(gitIn(dir, "status", "--porcelain").stdout.trim(), "");
|
|
162
|
+
// idempotent: a second run (project already >= 2) touches nothing
|
|
163
|
+
assert.equal(run({ dir, version: "2.4.2", globalDir }).action, "none");
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test("tracked opencode.json is updated but not excluded, and the result says so", { skip: !hasGit }, () => {
|
|
167
|
+
const { globalDir, dir } = (box = sandbox());
|
|
168
|
+
gitIn(dir, "init", "-q");
|
|
169
|
+
write(path.join(dir, "opencode.json"), { model: "x" });
|
|
170
|
+
gitIn(dir, "add", "opencode.json");
|
|
171
|
+
const r = run({ dir, version: "2.4.2", globalDir });
|
|
172
|
+
assert.equal(r.action, "updated");
|
|
173
|
+
assert.equal(r.git.tracked, true);
|
|
174
|
+
assert.equal(r.git.excluded, undefined);
|
|
175
|
+
assert.ok(r.message.includes(r.file));
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test("outside a git worktree nothing git-related is written", () => {
|
|
179
|
+
const { globalDir, dir } = (box = sandbox());
|
|
180
|
+
const r = run({ dir, version: "1.19.6", globalDir });
|
|
181
|
+
assert.equal(r.git.worktree, false);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
// ---- second review round ----
|
|
185
|
+
|
|
186
|
+
test("same directory: opencode.jsonc is loaded after opencode.json and wins", () => {
|
|
187
|
+
const { globalDir, dir } = (box = sandbox());
|
|
188
|
+
write(path.join(dir, "opencode.json"), { experimental: { subagent_depth: 3 } });
|
|
189
|
+
write(path.join(dir, "opencode.jsonc"), { experimental: { subagent_depth: 1 } });
|
|
190
|
+
const r = run({ dir, version: "2.4.2", globalDir });
|
|
191
|
+
assert.equal(r.effective_depth, 1);
|
|
192
|
+
assert.equal(r.action, "updated");
|
|
193
|
+
assert.equal(r.file, path.join(fs.realpathSync.native(dir), "opencode.jsonc"));
|
|
194
|
+
assert.deepEqual(read(path.join(dir, "opencode.jsonc")), { experimental: { subagent_depth: 2 } });
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
test("project files are searched up to the git root: a root depth 1 overrides global 2", { skip: !hasGit }, () => {
|
|
198
|
+
const { globalDir, dir } = (box = sandbox());
|
|
199
|
+
gitIn(dir, "init", "-q");
|
|
200
|
+
write(path.join(globalDir, "opencode.json"), { experimental: { subagent_depth: 2 } });
|
|
201
|
+
write(path.join(dir, "opencode.json"), { experimental: { subagent_depth: 1 } });
|
|
202
|
+
const sub = path.join(dir, "app", "src");
|
|
203
|
+
fs.mkdirSync(sub, { recursive: true });
|
|
204
|
+
const r = run({ dir: sub, version: "2.4.2", globalDir });
|
|
205
|
+
assert.equal(r.effective_depth, 1);
|
|
206
|
+
assert.equal(r.source, "project");
|
|
207
|
+
assert.equal(r.action, "created");
|
|
208
|
+
assert.deepEqual(read(path.join(sub, "opencode.json")), { experimental: { subagent_depth: 2 } });
|
|
209
|
+
// the subdirectory rule is computed by git itself and actually ignores the file
|
|
210
|
+
assert.equal(r.git.excluded, true);
|
|
211
|
+
assert.match(fs.readFileSync(path.join(dir, ".git", "info", "exclude"), "utf8"), /^\/app\/src\/opencode\.json$/m);
|
|
212
|
+
// only the user's own root opencode.json shows up; the generated one does not
|
|
213
|
+
assert.doesNotMatch(gitIn(dir, "status", "--porcelain", "-uall").stdout, /app\/src\/opencode\.json/);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test("a layer loaded after project files (OPENCODE_CONFIG_CONTENT, .opencode) that pins depth 1 → manual, no write", () => {
|
|
217
|
+
const { globalDir, dir, home } = (box = sandbox());
|
|
218
|
+
let r = run({ dir, version: "2.4.2", globalDir, env: { OPENCODE_CONFIG_CONTENT: '{"experimental":{"subagent_depth":1}}' } });
|
|
219
|
+
assert.equal(r.next, "manual");
|
|
220
|
+
assert.equal(r.source, "OPENCODE_CONFIG_CONTENT");
|
|
221
|
+
assert.equal(fs.existsSync(path.join(dir, "opencode.json")), false);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
test("~/.opencode/opencode.json declaring 1 overrides the project → manual naming that file", () => {
|
|
225
|
+
const { globalDir, dir, home } = (box = sandbox());
|
|
226
|
+
fs.mkdirSync(path.join(home, ".opencode"), { recursive: true });
|
|
227
|
+
write(path.join(home, ".opencode", "opencode.json"), { experimental: { subagent_depth: 1 } });
|
|
228
|
+
const r = run({ dir, version: "1.19.6", globalDir });
|
|
229
|
+
assert.equal(r.next, "manual");
|
|
230
|
+
assert.equal(r.file, path.join(home, ".opencode", "opencode.json"));
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
test("OPENCODE_CONFIG is read between global and project", () => {
|
|
234
|
+
const { root, globalDir, dir } = (box = sandbox());
|
|
235
|
+
const custom = path.join(root, "custom.json");
|
|
236
|
+
write(custom, { experimental: { subagent_depth: 2 } });
|
|
237
|
+
const r = run({ dir, version: "2.4.2", globalDir, env: { OPENCODE_CONFIG: custom } });
|
|
238
|
+
assert.equal(r.next, "continue");
|
|
239
|
+
assert.equal(r.source, "OPENCODE_CONFIG");
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
test("existing untracked project file is updated but NOT added to exclude", { skip: !hasGit }, () => {
|
|
243
|
+
const { globalDir, dir } = (box = sandbox());
|
|
244
|
+
gitIn(dir, "init", "-q");
|
|
245
|
+
write(path.join(dir, "opencode.json"), { model: "x" });
|
|
246
|
+
const r = run({ dir, version: "2.4.2", globalDir });
|
|
247
|
+
assert.equal(r.action, "updated");
|
|
248
|
+
assert.equal(r.git.tracked, false);
|
|
249
|
+
assert.equal(r.git.excluded, undefined);
|
|
250
|
+
assert.equal(fs.existsSync(path.join(dir, ".git", "info", "exclude")) && /opencode/.test(fs.readFileSync(path.join(dir, ".git", "info", "exclude"), "utf8")), false);
|
|
251
|
+
assert.match(gitIn(dir, "status", "--porcelain").stdout, /opencode\.json/);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
test("v1: after the restart the rerun still reports the file this script wrote", { skip: !hasGit }, () => {
|
|
255
|
+
const { globalDir, dir } = (box = sandbox());
|
|
256
|
+
gitIn(dir, "init", "-q");
|
|
257
|
+
assert.equal(run({ dir, version: "1.19.6", globalDir }).next, "restart");
|
|
258
|
+
const again = run({ dir, version: "1.19.6", globalDir });
|
|
259
|
+
assert.equal(again.action, "none");
|
|
260
|
+
assert.equal(again.next, "continue");
|
|
261
|
+
assert.equal(again.report, true);
|
|
262
|
+
// a user's own file that already satisfies the depth is not reported
|
|
263
|
+
const other = (box = sandbox());
|
|
264
|
+
gitIn(other.dir, "init", "-q");
|
|
265
|
+
write(path.join(other.dir, "opencode.json"), { experimental: { subagent_depth: 2 } });
|
|
266
|
+
assert.equal(run({ dir: other.dir, version: "1.19.6", globalDir: other.globalDir }).report, undefined);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
test("directory reached through a junction / symlink: exclude still works", { skip: !hasGit }, () => {
|
|
270
|
+
const { root, globalDir, dir } = (box = sandbox());
|
|
271
|
+
gitIn(dir, "init", "-q");
|
|
272
|
+
const link = path.join(root, "link");
|
|
273
|
+
try {
|
|
274
|
+
fs.symlinkSync(dir, link, "junction");
|
|
275
|
+
} catch {
|
|
276
|
+
return; // no permission to create links here
|
|
277
|
+
}
|
|
278
|
+
const r = run({ dir: link, version: "2.4.2", globalDir });
|
|
279
|
+
assert.equal(r.action, "created");
|
|
280
|
+
assert.equal(r.git.excluded, true);
|
|
281
|
+
assert.equal(gitIn(dir, "status", "--porcelain").stdout.trim(), "");
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
test("symlinked project opencode.json: the link target is updated, the link stays a link", () => {
|
|
285
|
+
const { root, globalDir, dir } = (box = sandbox());
|
|
286
|
+
const real = path.join(root, "dotfiles-opencode.json");
|
|
287
|
+
write(real, { model: "x" });
|
|
288
|
+
const link = path.join(dir, "opencode.json");
|
|
289
|
+
try {
|
|
290
|
+
fs.symlinkSync(real, link, "file");
|
|
291
|
+
} catch {
|
|
292
|
+
return; // Windows without developer mode cannot create file symlinks
|
|
293
|
+
}
|
|
294
|
+
run({ dir, version: "2.4.2", globalDir });
|
|
295
|
+
assert.equal(fs.lstatSync(link).isSymbolicLink(), true);
|
|
296
|
+
assert.deepEqual(read(real), { model: "x", experimental: { subagent_depth: 2 } });
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
test("project file whose root is not an object → manual, nothing claimed as updated", () => {
|
|
300
|
+
const { globalDir, dir } = (box = sandbox());
|
|
301
|
+
write(path.join(dir, "opencode.json"), []);
|
|
302
|
+
const r = run({ dir, version: "2.4.2", globalDir });
|
|
303
|
+
assert.equal(r.next, "manual");
|
|
304
|
+
assert.deepEqual(read(path.join(dir, "opencode.json")), []);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
test("OPENCODE_DISABLE_PROJECT_CONFIG → manual pointing at the global config", () => {
|
|
308
|
+
const { globalDir, dir } = (box = sandbox());
|
|
309
|
+
const r = run({ dir, version: "2.4.2", globalDir, env: { OPENCODE_DISABLE_PROJECT_CONFIG: "true" } });
|
|
310
|
+
assert.equal(r.next, "manual");
|
|
311
|
+
assert.equal(fs.existsSync(path.join(dir, "opencode.json")), false);
|
|
312
|
+
});
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Host-side wrapper around dag_runner.mjs / dag_production_executor.mjs.
|
|
4
|
+
*
|
|
5
|
+
* Not part of the DAG contract: the Runner owns topology, gateways, ledger and
|
|
6
|
+
* node terminal states. This helper only removes shell-quoting, BOM and
|
|
7
|
+
* "stderr looks like an error" hazards on Windows / PowerShell hosts.
|
|
8
|
+
*
|
|
9
|
+
* node tools/dag.mjs selfcheck --hmos <HMOS>
|
|
10
|
+
* node tools/dag.mjs exec <spec.json>
|
|
11
|
+
* node tools/dag.mjs state --hmos <HMOS> [run-name]
|
|
12
|
+
* node tools/dag.mjs json <dir>
|
|
13
|
+
*
|
|
14
|
+
* exec spec: { "runner": "dag" | "executor", "args": ["run", "--run-dir", "..."], "cwd": "..." }
|
|
15
|
+
* `run` / `continue` get `--workflow <this skill>/references/workflow.yaml` injected.
|
|
16
|
+
*/
|
|
17
|
+
import fs from "node:fs";
|
|
18
|
+
import path from "node:path";
|
|
19
|
+
import { spawnSync } from "node:child_process";
|
|
20
|
+
import { fileURLToPath } from "node:url";
|
|
21
|
+
|
|
22
|
+
const TOOLS_DIR = path.dirname(fileURLToPath(import.meta.url));
|
|
23
|
+
const SKILL_DIR = path.resolve(TOOLS_DIR, "..");
|
|
24
|
+
const SKILLS_ROOT = path.dirname(SKILL_DIR);
|
|
25
|
+
const RUNNER = path.join(SKILL_DIR, "scripts", "dag_runner.mjs");
|
|
26
|
+
const EXECUTOR = path.join(SKILL_DIR, "scripts", "dag_production_executor.mjs");
|
|
27
|
+
const WORKFLOW = path.join(SKILL_DIR, "references", "workflow.yaml");
|
|
28
|
+
|
|
29
|
+
const IGNORED_ENTRIES = new Set([".git", ".DS_Store", ".hometrans"]);
|
|
30
|
+
const PROJECT_MARKERS = [path.join("AppScope", "app.json5"), "build-profile.json5", "oh-package.json5"];
|
|
31
|
+
|
|
32
|
+
function out(value) {
|
|
33
|
+
process.stdout.write(JSON.stringify(value, null, 2) + "\n");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function die(message, code = 2) {
|
|
37
|
+
out({ ok: false, error: message });
|
|
38
|
+
process.exit(code);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function readJsonNoBom(file) {
|
|
42
|
+
const raw = fs.readFileSync(file, "utf8");
|
|
43
|
+
return JSON.parse(raw.charCodeAt(0) === 0xfeff ? raw.slice(1) : raw);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function listJsonFiles(dir) {
|
|
47
|
+
if (!fs.existsSync(dir)) return [];
|
|
48
|
+
return fs
|
|
49
|
+
.readdirSync(dir)
|
|
50
|
+
.filter((name) => name.toLowerCase().endsWith(".json"))
|
|
51
|
+
.map((name) => path.join(dir, name));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function runNode(script, args, cwd) {
|
|
55
|
+
const result = spawnSync(process.execPath, [script, ...args], {
|
|
56
|
+
cwd: cwd || process.cwd(),
|
|
57
|
+
encoding: "utf8",
|
|
58
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
59
|
+
});
|
|
60
|
+
if (result.error) return { exit_code: 1, stdout: "", stderr: String(result.error.message) };
|
|
61
|
+
return {
|
|
62
|
+
exit_code: result.status === null ? 1 : result.status,
|
|
63
|
+
stdout: result.stdout || "",
|
|
64
|
+
stderr: result.stderr || "",
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function gitIn(hmos, args) {
|
|
69
|
+
const result = spawnSync("git", ["-C", hmos, ...args], { encoding: "utf8" });
|
|
70
|
+
return {
|
|
71
|
+
exit_code: result.status === null ? 1 : result.status,
|
|
72
|
+
stdout: (result.stdout || "").trim(),
|
|
73
|
+
stderr: (result.stderr || "").trim(),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function parseFlags(argv) {
|
|
78
|
+
const flags = {};
|
|
79
|
+
const rest = [];
|
|
80
|
+
for (let index = 0; index < argv.length; index++) {
|
|
81
|
+
const token = argv[index];
|
|
82
|
+
if (token.startsWith("--")) {
|
|
83
|
+
const equal = token.indexOf("=");
|
|
84
|
+
if (equal >= 0) flags[token.slice(2, equal)] = token.slice(equal + 1);
|
|
85
|
+
else {
|
|
86
|
+
const next = argv[index + 1];
|
|
87
|
+
if (next !== undefined && !next.startsWith("--")) {
|
|
88
|
+
flags[token.slice(2)] = next;
|
|
89
|
+
index++;
|
|
90
|
+
} else flags[token.slice(2)] = true;
|
|
91
|
+
}
|
|
92
|
+
} else rest.push(token);
|
|
93
|
+
}
|
|
94
|
+
return { flags, rest };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function requireHmos(flags) {
|
|
98
|
+
const hmos = flags.hmos || process.env.HMOS;
|
|
99
|
+
if (!hmos || hmos === true) die("selfcheck/state require --hmos <harmony project root> (or env HMOS)");
|
|
100
|
+
const resolved = path.resolve(String(hmos));
|
|
101
|
+
if (!fs.existsSync(resolved)) die(`HMOS does not exist: ${resolved}`);
|
|
102
|
+
return resolved;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function checkSkills() {
|
|
106
|
+
const missing = [RUNNER, EXECUTOR, WORKFLOW].filter((file) => !fs.existsSync(file));
|
|
107
|
+
return {
|
|
108
|
+
name: "skills",
|
|
109
|
+
ok: missing.length === 0,
|
|
110
|
+
detail: missing.length === 0 ? SKILL_DIR : `missing: ${missing.join(", ")}`,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function checkGitRepo(hmos) {
|
|
115
|
+
const probe = gitIn(hmos, ["rev-parse", "--show-toplevel"]);
|
|
116
|
+
const root = probe.exit_code === 0 ? probe.stdout.replace(/\\/g, "/").toLowerCase() : "";
|
|
117
|
+
const expected = hmos.replace(/\\/g, "/").toLowerCase();
|
|
118
|
+
return {
|
|
119
|
+
name: "hmos_git_repo_root",
|
|
120
|
+
ok: root === expected,
|
|
121
|
+
detail: probe.exit_code === 0 ? probe.stdout : "not a git repository",
|
|
122
|
+
hint: "git -C <HMOS> init 后做一次空提交(不要放 .gitignore 等文件,会把工程判成 invalid_nonempty)",
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function checkHmosShape(hmos) {
|
|
127
|
+
const entries = fs.readdirSync(hmos).filter((name) => !IGNORED_ENTRIES.has(name));
|
|
128
|
+
const isProject = PROJECT_MARKERS.some((marker) => fs.existsSync(path.join(hmos, marker)));
|
|
129
|
+
if (entries.length === 0) return { name: "hmos_project_shape", ok: true, detail: "scaffold_new (empty)" };
|
|
130
|
+
if (isProject) return { name: "hmos_project_shape", ok: true, detail: "existing_project" };
|
|
131
|
+
return {
|
|
132
|
+
name: "hmos_project_shape",
|
|
133
|
+
ok: false,
|
|
134
|
+
detail: `not empty and not a HarmonyOS project: ${entries.slice(0, 5).join(", ")}`,
|
|
135
|
+
hint: "预检会判 invalid_nonempty;清空该目录(保留 .git / .hometrans)或改用合法工程",
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function checkWritable(hmos) {
|
|
140
|
+
const dir = path.join(hmos, ".hometrans");
|
|
141
|
+
const probe = path.join(dir, ".write-probe");
|
|
142
|
+
try {
|
|
143
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
144
|
+
fs.writeFileSync(probe, "ok", "utf8");
|
|
145
|
+
fs.unlinkSync(probe);
|
|
146
|
+
return { name: "hmos_writable", ok: true, detail: dir.replace(/\\/g, "/") };
|
|
147
|
+
} catch (error) {
|
|
148
|
+
return { name: "hmos_writable", ok: false, detail: String(error.message) };
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function checkNode() {
|
|
153
|
+
const major = Number(process.version.replace(/^v/, "").split(".")[0]);
|
|
154
|
+
return { name: "node", ok: major >= 18, detail: process.version };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function selfcheck(hmos) {
|
|
158
|
+
const checks = [checkNode(), checkSkills(), checkGitRepo(hmos), checkHmosShape(hmos), checkWritable(hmos)];
|
|
159
|
+
const failed = checks.filter((item) => !item.ok);
|
|
160
|
+
out({
|
|
161
|
+
ok: failed.length === 0,
|
|
162
|
+
hmos: hmos.replace(/\\/g, "/"),
|
|
163
|
+
checks,
|
|
164
|
+
hints: failed.map((item) => `${item.name}: ${item.hint || item.detail}`),
|
|
165
|
+
});
|
|
166
|
+
process.exit(failed.length === 0 ? 0 : 2);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function normalizeArgs(runnerName, args) {
|
|
170
|
+
if (runnerName !== "dag") return args;
|
|
171
|
+
const command = args[0];
|
|
172
|
+
if (command !== "run" && command !== "continue") return args;
|
|
173
|
+
if (args.includes("--workflow")) return args;
|
|
174
|
+
return [command, "--workflow", WORKFLOW, ...args.slice(1)];
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function execSpec(specFile) {
|
|
178
|
+
if (!specFile) die("exec requires <spec.json>");
|
|
179
|
+
if (!fs.existsSync(specFile)) die(`spec not found: ${specFile}`);
|
|
180
|
+
let spec;
|
|
181
|
+
try {
|
|
182
|
+
spec = readJsonNoBom(specFile);
|
|
183
|
+
} catch (error) {
|
|
184
|
+
die(`spec is not valid JSON: ${error.message}`);
|
|
185
|
+
}
|
|
186
|
+
const runnerName = spec.runner === "executor" ? "executor" : "dag";
|
|
187
|
+
const script = runnerName === "executor" ? EXECUTOR : RUNNER;
|
|
188
|
+
const args = normalizeArgs(runnerName, Array.isArray(spec.args) ? spec.args.map(String) : []);
|
|
189
|
+
if (args.length === 0) die("spec.args is empty");
|
|
190
|
+
const result = runNode(script, args, spec.cwd);
|
|
191
|
+
if (result.stdout) process.stdout.write(result.stdout);
|
|
192
|
+
if (result.stderr) process.stdout.write(result.stderr);
|
|
193
|
+
process.exit(result.exit_code);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function printState(hmos, name) {
|
|
197
|
+
const runName = name || "app-migrate-run3";
|
|
198
|
+
const direct = path.isAbsolute(runName) ? runName : path.join(hmos, ".hometrans", "dag-run", runName);
|
|
199
|
+
const state = path.join(direct, "dag-run-state.json");
|
|
200
|
+
if (!fs.existsSync(state)) die(`state not found: ${state}`);
|
|
201
|
+
const json = readJsonNoBom(state);
|
|
202
|
+
out({
|
|
203
|
+
ok: true,
|
|
204
|
+
run_dir: direct.replace(/\\/g, "/"),
|
|
205
|
+
status: json.status,
|
|
206
|
+
current_node: json.current_node,
|
|
207
|
+
error: json.error ? { code: json.error.code, message: String(json.error.message).slice(0, 400) } : null,
|
|
208
|
+
blocked: json.blocked || null,
|
|
209
|
+
nodes: Object.entries(json.nodes || {})
|
|
210
|
+
.map(([id, node]) => `${id}=${node.status}`)
|
|
211
|
+
.join(" "),
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function jsonScan(dir) {
|
|
216
|
+
if (!dir) die("json requires <dir>");
|
|
217
|
+
const resolved = path.resolve(dir);
|
|
218
|
+
const broken = [];
|
|
219
|
+
let total = 0;
|
|
220
|
+
for (const file of listJsonFiles(resolved)) {
|
|
221
|
+
total++;
|
|
222
|
+
try {
|
|
223
|
+
readJsonNoBom(file);
|
|
224
|
+
} catch (error) {
|
|
225
|
+
broken.push({ file: file.replace(/\\/g, "/"), error: String(error.message) });
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
out({ ok: broken.length === 0, dir: resolved.replace(/\\/g, "/"), files: total, broken });
|
|
229
|
+
process.exit(broken.length === 0 ? 0 : 2);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function usage() {
|
|
233
|
+
process.stdout.write(
|
|
234
|
+
[
|
|
235
|
+
"用法:",
|
|
236
|
+
" node tools/dag.mjs selfcheck --hmos <HMOS> # 环境自检(脚本齐全 / git 仓库 / 工程形态 / 可写)",
|
|
237
|
+
" node tools/dag.mjs exec <spec.json> # 按 spec 执行 Runner 或 executor",
|
|
238
|
+
" node tools/dag.mjs state --hmos <HMOS> [name] # 打印某次运行的状态",
|
|
239
|
+
" node tools/dag.mjs json <dir> # 只解析目录下 .json(BOM 容错)",
|
|
240
|
+
"",
|
|
241
|
+
'spec 示例:{"runner":"dag","args":["status","--state","<DAG_RUN_DIR>/dag-run-state.json"]}',
|
|
242
|
+
"run / continue 会自动补 --workflow,不要手写;也不要传 shell 引号包裹的 --vars,改用 vars 文件。",
|
|
243
|
+
].join("\n") + "\n",
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const [command, ...rest] = process.argv.slice(2);
|
|
248
|
+
switch (command) {
|
|
249
|
+
case "--selfcheck":
|
|
250
|
+
case "selfcheck":
|
|
251
|
+
selfcheck(requireHmos(parseFlags(rest).flags));
|
|
252
|
+
break;
|
|
253
|
+
case "exec":
|
|
254
|
+
execSpec(rest.find((token) => !token.startsWith("--")));
|
|
255
|
+
break;
|
|
256
|
+
case "state": {
|
|
257
|
+
const { flags, rest: positional } = parseFlags(rest);
|
|
258
|
+
printState(requireHmos(flags), positional[0]);
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
case "json":
|
|
262
|
+
jsonScan(rest.find((token) => !token.startsWith("--")));
|
|
263
|
+
break;
|
|
264
|
+
default:
|
|
265
|
+
usage();
|
|
266
|
+
process.exit(command ? 2 : 0);
|
|
267
|
+
}
|
|
@@ -8,3 +8,5 @@
|
|
|
8
8
|
* 大量列表(歌曲、消息、动态等可能上百条的列表/网格)不要用 `ForEach`:它首次加载就创建全部子节点,条目多时首帧卡顿明显甚至白屏超时。优先 `LazyForEach` + `IDataSource` 按需创建屏幕内节点;注意数据源变更必须经 `notifyDataReload` / `notifyDataAdd` / `notifyDataChange` 等接口通知,整体替换数组而不通知时 UI 不刷新(配合 `@Observed`/`@ObjectLink` 时是已见过的坑)。固定少量选项(菜单、页签)仍用 `ForEach` 即可。
|
|
9
9
|
* 跨「无类型边界」进入强类型代码的值一律按可空归一,不允许假设有值:反序列化结果、数据库行、本地缓存、跨页传参都算。ArkTS 的类型只是编译期标注,运行时不做校验,`as T` 不会补默认值,`null` 会原样进入实体;映射只判 `=== undefined` 就漏了它——读侧在 `.length`、遍历、方法调用处抛 `TypeError`(闪退),数值比较则把 `null` 静默当 0;写侧被非空约束拒绝而写不进库,或写进 JSON 后读回缺值(对象内的 `null` 仍是 `null`,`undefined` 属性的键直接消失)。规则:归一一律写在做「外部数据→实体」映射的那个函数里,没有就先补一个;字段声明成 `?: T | null`,缺失时用 `??` 取类型默认值(字符串 `''`、数值 `0`、数组 `[]`、对象 `{}`),整体兜住后再逐项、逐字段归一;读库按列的可空声明取值,不要用空串或 0 冒充缺失;兜底只用 `??`,不要 `||` 或 `if (!v)`,它们会把合法的 `0`、`''` 当空值。非空字段上写 `=== null` 不算兜底:漏掉 `undefined`,还会被判为无重叠比较;正解是先把声明改成 `?: T | null`。
|
|
10
10
|
* 平台 API 别凭记忆写,也别凭一次搜索结果选页:参数顺序、同步/异步、生命周期(create → use → destroy/off)和返回值单位以本地 `.d.ts` 为准(返回字段的可得性也是契约:非可选声明不代表运行期有值,字段注释写了 flag/option 条件时先确认调用满足),调用顺序与用法用 `scripts/state_doc.mjs search "<模块或方法>"` + `read-id "<documentId>" --section "<小节标题>" --max-lines 80` 取一段(API 页动辄两三千行,整页读会把正文上下文挤掉;重载会重复同名小节,`--section` 会把几个同名小节全带出来并标 `<!-- section "request" 2/3 -->`,要挑某一个时加 `--occurrence <n>`)。工作区里已有同一 API 的可用调用点时:**形状**问题(参数顺序、同步/异步、生命周期、返回值单位)可直接照抄、`.d.ts` 优先于文档;**含义**问题(作用目标、执行顺序、权限等级、边界、读写哪个键)即使有调用点也必须读官方页面,并以页面为准,记录里摘一句原文;小节标题旁的 `phone 12+` 之类标签高于工程 `compatibleSdkVersion` 时改用低版本重载或 `canIUse`。查文档时按工程 `compatibleSdkVersion` 选版本;优先使用非废弃 API——`.d.ts` 或文档标注 `@deprecated` 的 API 尽量不用,改用弃用说明给出的替代,确需使用时在 `## Platform API lookups` 的 `conclusion` 写明原因与后续替换计划。查不到就记 `api-docs: unavailable`,走 `.d.ts` 和本文件继续,不要静默猜。
|
|
11
|
+
* 全局状态(主题/风格、登录态、当前用户、语言等)在运行期变化后,已渲染的页面必须跟着变:本该跟随主题或深浅模式的颜色写成字面量(`'#FFFFFF'`、`Color.Red`),或把状态在初始化时算一次就缓存住,都会让这一页停在旧值。颜色用 `$r('app.color.*')` 并配 `resources/dark/` 限定目录(系统色用 `$r('sys.color.*')`),应用内深浅色开关须调 `getApplicationContext().setColorMode(...)` 才生效,且不持久化,入口 Ability 启动时按已存模式重设;文案用 `$r('app.string.*')` 跟随语言,应用内可切换的自定义主题用 `WithTheme`/`CustomTheme`;其余全局状态落到工程已有的范式:V1 用 `AppStorage`/`PersistentStorage`(配 `@StorageLink`/`@StorageProp`),V2 用 `AppStorageV2`/`PersistenceV2`(配 `@ObservedV2`/`@Trace`),不往已用一种范式的文件里引入另一种,见 code-generation.md 的状态文档一节。局部只算一次的值见上文 `@ComponentV2` 条。
|
|
12
|
+
* 全局状态涉及本地存储时,不仅要考虑何时存,还要考虑何时读:只写不读或读回太晚,会「改完立即生效、重启却回到默认」。手动持久化(preferences/RDB)须在 `loadContent` 前**完成**读回(只发起异步读取不算),写入运行时状态后再加载首页;`PersistentStorage.persistProp` 依赖 UI 实例,须在其初始化后调用(`loadContent` 回调,或入口 `@Entry` 页面模块顶层;首页自己读该键时用后者,回调太晚),不要放 `onCreate` 或 `loadContent` 之前;`PersistenceV2` 在使用处 `connect` 即读回,按官方示例放在组件内(UI 线程),不要放进 `onCreate`。
|