@buaa_smat/hometrans 26.0.4 → 26.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agents/code-reviewer.md +2 -0
- package/agents/model-render-worker.md +1 -1
- package/i18n/agents/code-reviewer.md +2 -0
- package/i18n/agents/model-render-worker.md +1 -1
- package/i18n/skills/a2h-app-migrate/SKILL.md +51 -3
- package/i18n/skills/a2h-app-migrate/references/workflow.yaml +140 -32
- package/i18n/skills/a2h-app-migrate/scripts/dag_graph.mjs +297 -0
- package/i18n/skills/a2h-app-migrate/scripts/validate_workflow.mjs +134 -21
- package/i18n/skills/a2h-app-migrate/test/test_finalize.mjs +21 -4
- package/i18n/skills/a2h-app-migrate/test/test_image_probe.mjs +3 -3
- package/i18n/skills/a2h-app-migrate/test/test_resume_plan.mjs +1 -1
- package/i18n/skills/a2h-app-migrate/test/test_reuse_static_utg.mjs +1 -1
- package/i18n/skills/a2h-app-migrate/test/test_utg_static_done.mjs +12 -5
- package/i18n/skills/a2h-arkts-logic-coder/SKILL.md +7 -8
- package/i18n/skills/a2h-arkts-logic-coder/references/ISSUES.md +1 -1
- package/i18n/skills/a2h-arkts-logic-coder/references/code-generation.md +27 -15
- package/i18n/skills/a2h-batch-ui-align/SKILL.md +1 -1
- package/i18n/skills/a2h-batch-ui-align/references/cards/widgets.md +4 -0
- package/i18n/skills/a2h-batch-ui-align/references/checker-rules.md +36 -0
- package/i18n/skills/a2h-batch-ui-align/references/conversion-procedure.md +4 -0
- package/i18n/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-layout-mapping-reference.md +4 -0
- package/i18n/skills/a2h-batch-ui-align/references/step5-convert.md +3 -3
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/main.ts +8 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/overlay_in_linear.ts +164 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/self_drawn_sheet.ts +105 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/staggered_lanes.ts +127 -0
- package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/window_size_constant.ts +114 -0
- package/i18n/skills/a2h-page-specgen/references/scenario-authoring.md +4 -1
- package/i18n/skills/a2h-page-specgen/references/spec-example.md +35 -5
- package/i18n/skills/a2h-page-specgen/references/spec-template.md +4 -4
- package/i18n/skills/a2h-spec-generate/SKILL.md +3 -1
- package/i18n/skills/a2h-spec-generate/references/fusion-task-contract.md +15 -3
- package/i18n/skills/a2h-spec-generate/references/review-checklist.md +1 -0
- package/i18n/skills/a2h-spec-generate/references/spec-sample-complex.md +16 -0
- package/i18n/skills/a2h-spec-generate/references/spec-sample-transfer.md +16 -0
- package/i18n/skills/a2h-spec-generate/references/spec-samples.md +5 -1
- package/i18n/skills/a2h-spec-generate/references/synthesis-rules.md +21 -1
- package/i18n/skills/a2h-spec-generate/references/worker-rules.md +25 -2
- package/i18n/skills/a2h-spec-generate/scripts/check_spec.ts +121 -6
- package/i18n/skills/a2h-spec-generate/scripts/reqgen/src/fusion/task-contract.ts +2 -1
- package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-e2e.test.ts +3 -0
- package/i18n/skills/a2h-spec-generate/scripts/reqgen/test/fusion-spec.test.ts +16 -2
- package/i18n/skills/a2h-spec-generate/test/check-fused-spec.test.mjs +11 -2
- package/i18n/skills/a2h-spec-generate/test/check-spec.test.ts +35 -0
- package/package.json +1 -1
- package/skills/a2h-app-migrate/SKILL.md +53 -5
- package/skills/a2h-app-migrate/references/workflow.yaml +140 -32
- package/skills/a2h-app-migrate/scripts/assert_dag_complete.mjs +226 -0
- package/skills/a2h-app-migrate/scripts/dag_graph.mjs +297 -0
- package/skills/a2h-app-migrate/scripts/dag_process_executor.mjs +199 -0
- package/skills/a2h-app-migrate/scripts/dag_production_executor.mjs +897 -0
- package/skills/a2h-app-migrate/scripts/dag_runner.mjs +1767 -0
- package/skills/a2h-app-migrate/scripts/ledger.mjs +15 -2
- package/skills/a2h-app-migrate/scripts/lib-yaml-lite.mjs +8 -2
- package/skills/a2h-app-migrate/scripts/resume_plan.mjs +3 -8
- package/skills/a2h-app-migrate/scripts/validate_workflow.mjs +134 -21
- package/skills/a2h-app-migrate/test/test_dag_complete.mjs +222 -0
- package/skills/a2h-app-migrate/test/test_dag_production.mjs +670 -0
- package/skills/a2h-app-migrate/test/test_dag_runner.mjs +423 -0
- package/skills/a2h-app-migrate/test/test_finalize.mjs +21 -4
- package/skills/a2h-app-migrate/test/test_image_probe.mjs +1 -1
- package/skills/a2h-app-migrate/test/test_resume_plan.mjs +16 -1
- package/skills/a2h-app-migrate/test/test_reuse_static_utg.mjs +1 -1
- package/skills/a2h-app-migrate/test/test_utg_static_done.mjs +12 -5
- package/skills/a2h-arkts-logic-coder/SKILL.md +7 -8
- package/skills/a2h-arkts-logic-coder/references/ISSUES.md +1 -1
- package/skills/a2h-arkts-logic-coder/references/code-generation.md +27 -15
- package/skills/a2h-batch-ui-align/SKILL.md +1 -1
- package/skills/a2h-batch-ui-align/references/cards/widgets.md +4 -0
- package/skills/a2h-batch-ui-align/references/checker-rules.md +36 -0
- package/skills/a2h-batch-ui-align/references/conversion-procedure.md +4 -0
- package/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-layout-mapping-reference.md +4 -0
- package/skills/a2h-batch-ui-align/references/step5-convert.md +3 -3
- package/skills/a2h-batch-ui-align/scripts/group_queue.mjs +49 -3
- package/skills/a2h-batch-ui-align/scripts/static_check/core/android.ts +36 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/main.ts +8 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/registry.ts +8 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/overlay_in_linear.ts +164 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/self_drawn_sheet.ts +105 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/staggered_lanes.ts +127 -0
- package/skills/a2h-batch-ui-align/scripts/static_check/rules/window_size_constant.ts +114 -0
- package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_coolmall_ds1123.test.mjs +433 -0
- package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_overlay_in_linear.test.mjs +288 -0
- package/skills/a2h-batch-ui-align/scripts/tests/group_queue.test.mjs +46 -0
- package/skills/a2h-page-specgen/references/scenario-authoring.md +4 -1
- package/skills/a2h-page-specgen/references/spec-example.md +35 -5
- package/skills/a2h-page-specgen/references/spec-template.md +4 -4
- package/skills/a2h-spec-generate/SKILL.md +3 -1
- package/skills/a2h-spec-generate/references/fusion-task-contract.md +15 -3
- package/skills/a2h-spec-generate/references/review-checklist.md +1 -0
- package/skills/a2h-spec-generate/references/spec-sample-complex.md +16 -0
- package/skills/a2h-spec-generate/references/spec-sample-transfer.md +16 -0
- package/skills/a2h-spec-generate/references/spec-samples.md +5 -1
- package/skills/a2h-spec-generate/references/synthesis-rules.md +21 -1
- package/skills/a2h-spec-generate/references/worker-rules.md +25 -2
- package/skills/a2h-spec-generate/scripts/check-fused-spec.mjs +3 -1
- package/skills/a2h-spec-generate/scripts/check_spec.ts +262 -6
- package/skills/a2h-spec-generate/scripts/reqgen/src/fusion/task-contract.ts +12 -2
- package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-behavior-e2e.test.ts +3 -0
- package/skills/a2h-spec-generate/scripts/reqgen/test/fusion-spec.test.ts +16 -2
- package/skills/a2h-spec-generate/test/check-fused-spec.test.mjs +54 -3
- package/skills/a2h-spec-generate/test/check-spec.test.ts +247 -0
|
@@ -13,7 +13,7 @@ These are the authoring rules the final spec MUST follow:
|
|
|
13
13
|
4. The spec document must include a requirement semantic description, a UI-sequence section, scenario semantic descriptions, and scenario flow descriptions.
|
|
14
14
|
5. The scenario flow description must include the trigger operation sequence and the logical execution steps: what the user does and sees when the behavior is user-facing, and what data moves, in which direction, in what business format, and how the result changes what happens next when it crosses a service/data boundary.
|
|
15
15
|
6. **The spec is an input to HarmonyOS code generation and describes only what the HarmonyOS side must implement.** It must not contain Android or UniApp implementation knowledge — no platform types, framework mechanisms/APIs, constants, file paths, package names, storage/event identifiers, transaction ids, or source log text. Source evidence stays in the exploration and is never copied into the spec. See the Platform-Neutralization Rules in `references/synthesis-rules.md`.
|
|
16
|
-
7. **The spec never defines the service interface contract** — no signatures, parameter tables, return values, or error codes. Backend behavior enters only where it has a user-visible outcome, as concrete data-transfer steps; a failure with no user-visible outcome does not belong in a UI spec.
|
|
16
|
+
7. **The spec never defines the service interface contract** — no signatures, parameter tables, return values, or error codes. `## Data Contract` is the one exception: the type, byte length, range/enum values and code values of an external field belong in that section. Scenario steps still describe only user-visible outcomes and data movement, and never restate the contract as an interface spec. Backend behavior enters only where it has a user-visible outcome, as concrete data-transfer steps; a failure with no user-visible outcome does not belong in a UI spec.
|
|
17
17
|
8. The `## UI Sequence` section is mandatory, placed **above** all scenario sections, and its body is a single line: the requirement's UI path — its title line, a hyphen-separated path such as `Settings-Lyrics-Floating window status bar lyrics` — copied verbatim. See `## UI Sequence Rules`.
|
|
18
18
|
9. The spec must contain **no vague wording**. Every value the software produces, consumes, displays, stores, sends, receives, or branches on — toast text, limits, defaults, sort rules, switch states, HTTP endpoints, protocol versions, command values, field order, encodings, callback payload fields — is stated as its concrete value once source evidence exists. See the No-Vagueness Rules in `references/synthesis-rules.md`. Platform-neutrality is never an excuse for vagueness: dropping an Android detail obliges you to define the neutral replacement concretely.
|
|
19
19
|
10. **No view description.** The spec says what is shown, from where, under which condition — never how it looks or where it sits. Sizes, dp/px, coordinates, margins, padding, alignment, stacking, spacing, radius, font, weight, line height, colors, backgrounds and shadows stay out even when the source fixes them; layout and styling come from the HarmonyOS side's own design spec. Such a value is exploration evidence only and is dropped at synthesis — not restated, not paraphrased into "per the design mockup", not stubbed. An element is named for what it is, never for where it sits. **Motion timing is the one exception**: a transition's duration and the order of concurrent animations are behavior, not styling, so they ARE stated ("0.35 seconds", "the content makes room first, the page slides in afterwards"), while its displacement, curve name and resource name stay out (see `references/synthesis-rules.md`). Read the animation resource for the number if you must, but keep the citation on the citable line that loads *or declares* it — the code that starts the animation, or a `res/navigation` `app:enterAnim` / `res/values` `windowAnimationStyle` declaration; `res/anim*/` is outside the citable census and citing it aborts finalize.
|
|
@@ -88,10 +88,33 @@ Write to `<output>/<feature>-SPEC.md` (**overwrite if it already exists**; the s
|
|
|
88
88
|
2. Identity line `Control: <controlRef>` — copied verbatim when the requirement carries a `Control:` line; **when it does not, omit the whole line**, never fabricate one;
|
|
89
89
|
3. Requirement semantic description;
|
|
90
90
|
4. `## UI Sequence` (a single line, the requirement title copied verbatim);
|
|
91
|
-
5.
|
|
91
|
+
5. `## Data Contract` (see the next section; write the single line `No external data` when the SPEC reads none);
|
|
92
|
+
6. Atomic scenarios.
|
|
92
93
|
|
|
93
94
|
The document ends with the last scenario (or the deviation H3 section); there is no footer.
|
|
94
95
|
|
|
96
|
+
## Data Contract Rules
|
|
97
|
+
|
|
98
|
+
When the SPEC consumes or reads external data (an API response, cache, database, file, setting or location result), `## Data Contract` carries **one block per external field**:
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
## Data Contract
|
|
102
|
+
|
|
103
|
+
- Field: time
|
|
104
|
+
- Type: string
|
|
105
|
+
- Byte length: 12
|
|
106
|
+
- Range: yyyyMMddHHmm
|
|
107
|
+
- Sample: 202611121100
|
|
108
|
+
- Semantic source: interface time field definition
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
- All six keys are required, in this order; separate multiple fields with a blank line.
|
|
112
|
+
- `Type` is the actual type (`string`, `uint8`, `float32`, `int64`, …); `Byte length` is the width in bytes under the encoding the source declares: a fixed-width field states the number, a variable-length field says `variable`. Character count is not byte count (one CJK character is usually 3 bytes in UTF-8) — never substitute one for the other.
|
|
113
|
+
- `Range` states the format, enum range or boundaries; `Sample` is one real, checkable value — never a placeholder.
|
|
114
|
+
- `Semantic source` is the neutral name of the contract definition (e.g. "interface time field definition", "unit enum definition"). Never write a platform filename or `file:line`. The contract definition file itself must be included in this SPEC's `citations` (published under `## Source locations`); review confirms that citation points at the definition, not only at the UI widget.
|
|
115
|
+
- A SPEC that reads no external data writes only `No external data` in this section. Never leave it empty and never omit the section.
|
|
116
|
+
- Width, format and enum values come from the source or a real response. If they cannot be found, report the gap per Principle 15; never guess a "common" format.
|
|
117
|
+
|
|
95
118
|
## Step 3 Reporting Duty
|
|
96
119
|
**The part it cannot decide stays with you**: name, per requirement, every unsupported claim, every requirement skipped as no-recall, and every REQ detail the source does not implement — the reporter only sees files on disk, and this report is the only place such gaps surface, since the spec carries neither placeholders nor "insufficient evidence". If HomeGraph failed, report the exact error, the stopped file/requirement, and any completed outputs — never describe the interrupted batch as complete or continue its remaining SPECs.
|
|
97
120
|
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* Mechanical spec checker — a2h-spec-generate
|
|
4
4
|
*
|
|
5
5
|
* Turns the decidable rules of STAGE.md into a script, replacing the Agent's item-by-item visual scan:
|
|
6
|
-
* - H1, section order, single-line `## UI Sequence`, no placeholders
|
|
7
|
-
* - Principle 10 zero UI view descriptions (size/position/color/font size/alignment); motion *timing* is its one exception
|
|
6
|
+
* - H1, section order, single-line `## UI Sequence`, the six-key `## Data Contract` (or its opt-out), no placeholders
|
|
7
|
+
* - Principle 10 zero UI view descriptions (size/position/color/font size/alignment/animation); motion *timing* is its one exception
|
|
8
8
|
* - Principle 6 no platform symbols
|
|
9
9
|
* - Principle 7 no interface contracts (signatures/parameter tables/return values/error codes)
|
|
10
10
|
* - Forbidden no `file:line` anchors and no `.trace` references in the body (trace is retired)
|
|
@@ -178,11 +178,104 @@ const CONTROL_LINE = /^(?:Control:)/;
|
|
|
178
178
|
const CONTROL_VALUE = /^(?:Control: )control:/;
|
|
179
179
|
/** H2 name (with `## ` already stripped): `UI Sequence` */
|
|
180
180
|
const UI_SEQ_NAME = /^(?:UI Sequence|UI[ \t]*Sequence)/;
|
|
181
|
+
/** H2 name: the external-data contract (`Data Contract`) */
|
|
182
|
+
const DATA_CONTRACT_NAME = /^(?:Data[ \t]*Contract)$/;
|
|
183
|
+
/** The explicit "this SPEC reads no external data" body (the only opt-out) */
|
|
184
|
+
const DATA_CONTRACT_OPTOUT = /^(?:No[ \t]+external[ \t]+data)$/i;
|
|
185
|
+
/** Required keys of one contract block. `Byte length` is deliberate: the
|
|
186
|
+
* contract needs the byte width, while `width` alone is a banned view property. */
|
|
187
|
+
const DATA_CONTRACT_KEYS: ReadonlyArray<readonly [string, string]> = [
|
|
188
|
+
['Field', 'field'],
|
|
189
|
+
['Type', 'type'],
|
|
190
|
+
['Byte length', 'byte length'],
|
|
191
|
+
['Range', 'range'],
|
|
192
|
+
['Sample', 'sample'],
|
|
193
|
+
['Semantic source', 'semantic source'],
|
|
194
|
+
];
|
|
181
195
|
/** H2 name: a scenario section (`Scenario…`) */
|
|
182
196
|
const SCENARIO_NAME = /^(?:Scenario)/;
|
|
183
197
|
/** A valid scenario heading: `scenario` + Chinese or Arabic numerals; in English only `Scenario <digits>` */
|
|
184
198
|
const SCENARIO_NAME_STRICT = /^(?:Scenario[0-9]+|Scenario[ \t]+\d+)$/;
|
|
185
199
|
|
|
200
|
+
/** Resolve a contract-block label to its canonical (en, alias) pair. */
|
|
201
|
+
function contractKeyOf(raw: string): readonly [string, string] | null {
|
|
202
|
+
const key = raw.trim().toLowerCase().replace(/[ \t]+/g, ' ');
|
|
203
|
+
for (const pair of DATA_CONTRACT_KEYS) {
|
|
204
|
+
if (key === pair[1]) return pair;
|
|
205
|
+
}
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Check one `## Data Contract` body: either the explicit opt-out line, or blocks
|
|
211
|
+
* of `- <key>: <value>` carrying every required key exactly once.
|
|
212
|
+
*/
|
|
213
|
+
function checkDataContract(lines: string[], sectionIndex: number): Finding[] {
|
|
214
|
+
const out: Finding[] = [];
|
|
215
|
+
const add = (line: number, note: string, text = '') =>
|
|
216
|
+
out.push({ level: 'error', rule: 'data-contract', line, text, note });
|
|
217
|
+
|
|
218
|
+
const body: Array<{ text: string; line: number }> = [];
|
|
219
|
+
for (let i = sectionIndex + 1; i < lines.length; i++) {
|
|
220
|
+
if (/^##\s+/.test(lines[i])) break;
|
|
221
|
+
if (HTML_COMMENT_LINE.test(lines[i])) continue;
|
|
222
|
+
body.push({ text: lines[i].trim(), line: i + 1 });
|
|
223
|
+
}
|
|
224
|
+
while (body.length > 0 && body[0].text === '') body.shift();
|
|
225
|
+
while (body.length > 0 && body[body.length - 1].text === '') body.pop();
|
|
226
|
+
if (body.length === 0) {
|
|
227
|
+
add(sectionIndex + 1, 'the data contract body is empty: declare at least one field block, or write the opt-out line');
|
|
228
|
+
return out;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const optOut = body.filter(({ text }) => DATA_CONTRACT_OPTOUT.test(text));
|
|
232
|
+
if (optOut.length > 0) {
|
|
233
|
+
if (body.length > 1) add(optOut[0].line, 'the opt-out line must be the only body of the data contract');
|
|
234
|
+
return out;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
let block: Array<{ key: readonly [string, string]; value: string; line: number }> = [];
|
|
238
|
+
const flush = () => {
|
|
239
|
+
if (block.length === 0) return;
|
|
240
|
+
for (const [label, alias] of DATA_CONTRACT_KEYS) {
|
|
241
|
+
const hits = block.filter((item) => item.key[0] === label);
|
|
242
|
+
if (hits.length === 0) add(block[0].line, `data contract block is missing the \`${label}\` (${alias}) key`);
|
|
243
|
+
if (hits.length > 1) add(hits[1].line, `data contract block repeats the \`${label}\` (${alias}) key (check for a missing blank line between field blocks)`);
|
|
244
|
+
}
|
|
245
|
+
const positions = block.map((item) => DATA_CONTRACT_KEYS.findIndex(([label]) => label === item.key[0]));
|
|
246
|
+
const complete = positions.length === DATA_CONTRACT_KEYS.length && positions.every((position) => position >= 0);
|
|
247
|
+
if (complete && new Set(positions).size === positions.length) {
|
|
248
|
+
const ordered = positions.every((position, index) => position === index);
|
|
249
|
+
if (!ordered) {
|
|
250
|
+
add(block[0].line, `data contract keys must appear in order: ${DATA_CONTRACT_KEYS.map(([label]) => label).join(' → ')}`);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
block = [];
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
for (const { text, line } of body) {
|
|
257
|
+
if (text === '') { flush(); continue; }
|
|
258
|
+
const match = /^-\s*([^::]{1,24})\s*[::]\s*(.*)$/.exec(text);
|
|
259
|
+
if (!match) {
|
|
260
|
+
add(line, 'the data contract only accepts `- <key>: <value>` lines (one block per external field)');
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
const key = contractKeyOf(match[1]);
|
|
264
|
+
if (key === null) {
|
|
265
|
+
add(line, `unknown data contract key: "${match[1].trim()}"`);
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
const value = match[2].trim();
|
|
269
|
+
if (value === '') {
|
|
270
|
+
add(line, `data contract key \`${key[0]}\` (${key[1]}) has an empty value`);
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
block.push({ key, value, line });
|
|
274
|
+
}
|
|
275
|
+
flush();
|
|
276
|
+
return out;
|
|
277
|
+
}
|
|
278
|
+
|
|
186
279
|
/** H2 name: the trailing provenance section the publisher appends
|
|
187
280
|
* (`Source locations`). It is the ONE place a source path may appear, so it is
|
|
188
281
|
* also the one place `code-anchor-leak` has to stand down. */
|
|
@@ -225,13 +318,32 @@ function checkStructure(lines: string[]): Finding[] {
|
|
|
225
318
|
const h2 = lines.map((l, i) => ({ l, i })).filter(({ l }) => /^##\s+/.test(l));
|
|
226
319
|
const names = h2.map(({ l }) => l.replace(/^##\s+/, '').trim());
|
|
227
320
|
let cursor = 0;
|
|
321
|
+
let uiSeen = false;
|
|
322
|
+
let contractSeen = 0;
|
|
323
|
+
let scenarioSeen = false;
|
|
324
|
+
const contractSections: number[] = [];
|
|
325
|
+
const addContract = (line: number, note: string) => out.push({ level: 'error', rule: 'data-contract', line, text: lines[line - 1]?.slice(0, 60) ?? '', note });
|
|
228
326
|
for (let k = 0; k < names.length; k++) {
|
|
229
327
|
const n = names[k];
|
|
230
|
-
if (UI_SEQ_NAME.test(n)) {
|
|
328
|
+
if (UI_SEQ_NAME.test(n)) {
|
|
329
|
+
if (cursor > 0) add(h2[k].i + 1, `\`${UI_SEQUENCE_TOKEN}\` must come before every scenario`);
|
|
330
|
+
uiSeen = true;
|
|
331
|
+
cursor = Math.max(cursor, 1);
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
if (DATA_CONTRACT_NAME.test(n)) {
|
|
335
|
+
contractSeen += 1;
|
|
336
|
+
contractSections.push(h2[k].i);
|
|
337
|
+
if (cursor < 1) addContract(h2[k].i + 1, `\`## Data Contract\` must come after \`${UI_SEQUENCE_TOKEN}\``);
|
|
338
|
+
if (cursor >= 2) addContract(h2[k].i + 1, '`## Data Contract` must come before every scenario');
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
231
341
|
if (SCENARIO_NAME.test(n)) {
|
|
232
342
|
if (!SCENARIO_NAME_STRICT.test(n)) add(h2[k].i + 1, `scenario heading should be \`${"## Scenario N"}\`, got "${n}"`);
|
|
233
343
|
if (cursor === 3) add(h2[k].i + 1, 'a scenario section must come before the source-locations section');
|
|
234
|
-
|
|
344
|
+
scenarioSeen = true;
|
|
345
|
+
cursor = Math.max(cursor, 2);
|
|
346
|
+
continue;
|
|
235
347
|
}
|
|
236
348
|
if (SOURCE_SECTION_NAME.test(n)) {
|
|
237
349
|
if (cursor < 2) add(h2[k].i + 1, 'the source-locations section must come after every scenario');
|
|
@@ -239,8 +351,11 @@ function checkStructure(lines: string[]): Finding[] {
|
|
|
239
351
|
}
|
|
240
352
|
add(h2[k].i + 1, `H2 section not allowed: "${n}"`);
|
|
241
353
|
}
|
|
242
|
-
if (!
|
|
243
|
-
if (
|
|
354
|
+
if (!uiSeen) add(1, `missing \`${UI_SEQUENCE_TOKEN}\` section`);
|
|
355
|
+
if (contractSeen === 0) addContract(1, 'missing `## Data Contract` section: declare the input shape, or write the opt-out line when the SPEC reads no external data');
|
|
356
|
+
if (contractSeen > 1) addContract(h2.find(({ l }) => DATA_CONTRACT_NAME.test(l.replace(/^##\s+/, '').trim()))!.i + 1, 'the `## Data Contract` section may appear at most once');
|
|
357
|
+
if (!scenarioSeen) add(1, 'missing scenario section');
|
|
358
|
+
if (contractSections.length > 0) out.push(...checkDataContract(lines, contractSections[0]!));
|
|
244
359
|
|
|
245
360
|
// The provenance section is optional (batch mode and a lost draft have none),
|
|
246
361
|
// but when present it must actually carry the bullets it exists for.
|
|
@@ -274,6 +274,7 @@ const SPEC_RESIDENT_REQUIRED_SECTIONS = [
|
|
|
274
274
|
["## Principles"],
|
|
275
275
|
["## UI Sequence Rules", "## UI Sequence Rules"],
|
|
276
276
|
["## File Write and Body Shape", "## File Write and Body Shape"],
|
|
277
|
+
["## Data Contract Rules", "## Data Contract Rules"],
|
|
277
278
|
["## Forbidden"]
|
|
278
279
|
] as const;
|
|
279
280
|
|
|
@@ -363,7 +364,7 @@ export function residentRuleSections(
|
|
|
363
364
|
*/
|
|
364
365
|
export function fusedSpecSection(specSkillDir: string): string {
|
|
365
366
|
const { featureStem } = specCommands(specSkillDir);
|
|
366
|
-
return `### C. Produce SPECs\n\nUse the **eco-style page owner**: this Area is one page, but **one SPEC corresponds to one user-visible flow**, not one\ncard or one display surface. Flows are cut along "data acquisition → derivation → display → save/restore", e.g. "pull to refresh", "choose the temperature unit",\n"search for a place"; one flow covers the data sources across controls, the derivation rules, error/empty states and the lifecycle. One page batch usually has 1–6\nSPECs; do not mechanically split every Control into its own SPEC, and do not write one big SPEC that flattens independently testable features either.\nProduce an extra \`controlGroup\`/\`discovery\` SPEC only when a local interaction needs a standalone binding. An area-owned SPEC\ndoes not correspond to a single Control and gets no \`Control:\` line on publishing; only a locally split SPEC is bound to a single controlRef.\n\n**A \`dataFlow\` data contract ledger is required**: exactly one row per area-owned SPEC, writing out \`entry\` (the user entry point),\n\`sources\` (request address/storage key/location source/setting), \`transforms\` (window, aggregation, rounding, sign, unit conversion),\n\`displays\` (user-visible fields), and \`persistence\` when there is a write/restore. The ledger is what R8 checks mechanically; a missing row,\na dangling \`specStem\` or a duplicate \`flowKey\` all fail.\n\n**A \`pageCoverage\` coverage ledger is required**: exactly one row for every \`controlGroup\`/\`discovery\` of this Area;\na \`covered\` row must name the \`specStem\` it belongs to (that stem must exist in \`specs[]\`), an \`excluded\`\nrow must give a reason. The ledger is L1's coverage assignment table and also what R4 checks mechanically; missing items, duplicate items and pointers to a\nnonexistent stem all fail the gate. L2 projects the ledger into each area SPEC's\n\`controlRefs[]\` in \`spec-bindings.json\`, from which the publish surface restores control coverage.\n\n9. **Write the SPEC file**: write one SPEC at \`specs/<stem>-SPEC.md\` in **this task directory**; the single \`## UI Sequence\`\n line **equals** that entry's \`specs[].title\` **verbatim**. The SPEC body follows specgen's writing rules (read \`## Gate List\` as\n needed): H1 is exactly \`# <stem>SPEC\`; the identity line \`Control: <controlRef>\` of a local controlGroup/discovery SPEC\n is minted by the script (you submit anchors only, R1), and an area-owned SPEC gets no such line;\n the requirement-semantics description; \`## UI Sequence\`; then the atomic scenarios. **The SPEC body exists only in the SPEC file and is never written into\n \`output.json\`.**\n10. **title rule**: \`title\` is a feature title in the SPEC's language (with a sense of page/entry location), and **equals** that SPEC's\n \`## UI Sequence\` line **verbatim**.\n11. **stem must be minted with the CLI, never hand-sanitized**: for that entry's \`title\` run\n \`node ${JSON.stringify(featureStem)} "<title>"\`, and use the printed stem as the file name unchanged. If this task's\n \`specs/\` already has a \`<stem>-SPEC.md\` of the same name, append \`-2\`, \`-3\`… in this task's production order; \`stem\` must be unique within\n \`output.json.specs[]\`. Hand-sanitizing makes \`check-fused-spec\`'s canonical-stem\n check fail.\n12. **Cut SPECs per flow and add the \`specs[]\` records**: the shape is \`SpecRecord\` in the "Output contract". One flow\n (data acquisition → derivation → display → persistence) corresponds to one \`owner: { kind: "area" }\` SPEC; do not split one flow across several\n SPECs. Add \`controlGroup\`/\`discovery\` records only for local standalone bindings, at most one each.\n An \`agent-added\` display SPEC carries its own \`identityAnchors\` (\`control\` required) and\n \`disposition:"added"\`. This field is **required** for this task.\n13. **Write the \`dataFlow\` data contract ledger**: exactly one row per area-owned SPEC, writing out \`entry\`, ≥1\n \`sources\`, ≥1 \`transforms\`, ≥1 \`displays\`, and \`persistence\` when there is a write/restore.\n \`specStem\` must exist in \`specs[]\`. R8 goes by it; a missing row, a dangling stem or a duplicate \`flowKey\` all fail.\n14. **Write the \`pageCoverage\` ledger**: exactly one row for every \`controlGroup\`/\`discovery\` of this Area; \`covered\`\n must give a \`specStem\` (existing in \`specs[]\`), \`excluded\` must give a \`reason\`. R4 goes by it.\n15. **Displayed-value derivation (R6a)**: every numeric/text field states its source field, time window, aggregation, rounding, sign and unit conversion;\n writing only "shows N" or "integer difference" is not allowed. A shared derivation rule is written once within a flow and referenced by later fields.\n16. **Display SPEC completeness (R6) is a required step, not an option**: per R6's definition in the output contract, do one source review of the data this Area\n renders/displays; for every display behavior the source can prove, that is user-visible and not covered by any SPEC,\n add an \`owner.kind="agent-added"\` \`specRecord\` and the corresponding SPEC file (own identityAnchors,\n ≥1 verifiable citation, \`disposition:"added"\`). An empty interaction surface is no exception.\n17. **Explicitly producing no SPEC**: when a Control/discovery really should not get a standalone SPEC this round, record it in\n \`pageCoverage\` with \`disposition:"excluded"\` and a reason; the legacy\n \`renderConfirmations\` are used only when no ledger is provided.\n18. **Body boundaries**: the SPEC body must not contain framework names such as Android/UniApp/Compose, \`file:line\` anchors, source\n symbols, placeholders or vague wording (R5 applies as well), and does not describe visual details of the UI; do not promote unresolved fields to established\n facts — content that must stay but the source cannot determine is simply omitted. **Do not** hand-write a \`Control:\` line or a \`controlRef\`.\n19. A single SPEC can be self-checked with \`check_spec\` (see the SPEC commands under "Output and Checks"); the whole-task self-check command\n covers both the fused draft and all SPECs.`;
|
|
367
|
+
return `### C. Produce SPECs\n\nUse the **eco-style page owner**: this Area is one page, but **one SPEC corresponds to one user-visible flow**, not one\ncard or one display surface. Flows are cut along "data acquisition → derivation → display → save/restore", e.g. "pull to refresh", "choose the temperature unit",\n"search for a place"; one flow covers the data sources across controls, the derivation rules, error/empty states and the lifecycle. One page batch usually has 1–6\nSPECs; do not mechanically split every Control into its own SPEC, and do not write one big SPEC that flattens independently testable features either.\nProduce an extra \`controlGroup\`/\`discovery\` SPEC only when a local interaction needs a standalone binding. An area-owned SPEC\ndoes not correspond to a single Control and gets no \`Control:\` line on publishing; only a locally split SPEC is bound to a single controlRef.\n\n**A \`dataFlow\` data contract ledger is required**: exactly one row per area-owned SPEC, writing out \`entry\` (the user entry point),\n\`sources\` (request address/storage key/location source/setting), \`transforms\` (window, aggregation, rounding, sign, unit conversion),\n\`displays\` (user-visible fields), and \`persistence\` when there is a write/restore. The ledger is what R8 checks mechanically; a missing row,\na dangling \`specStem\` or a duplicate \`flowKey\` all fail.\n\n**A \`pageCoverage\` coverage ledger is required**: exactly one row for every \`controlGroup\`/\`discovery\` of this Area;\na \`covered\` row must name the \`specStem\` it belongs to (that stem must exist in \`specs[]\`), an \`excluded\`\nrow must give a reason. The ledger is L1's coverage assignment table and also what R4 checks mechanically; missing items, duplicate items and pointers to a\nnonexistent stem all fail the gate. L2 projects the ledger into each area SPEC's\n\`controlRefs[]\` in \`spec-bindings.json\`, from which the publish surface restores control coverage.\n\n9. **Write the SPEC file**: write one SPEC at \`specs/<stem>-SPEC.md\` in **this task directory**; the single \`## UI Sequence\`\n line **equals** that entry's \`specs[].title\` **verbatim**. The SPEC body follows specgen's writing rules (read \`## Gate List\` as\n needed): H1 is exactly \`# <stem>SPEC\`; the identity line \`Control: <controlRef>\` of a local controlGroup/discovery SPEC\n is minted by the script (you submit anchors only, R1), and an area-owned SPEC gets no such line;\n the requirement-semantics description; \`## UI Sequence\`; a Data Contract section (six keys per external field: Field/Type/Byte length/Range/Sample/Semantic source, or the single line No external data); then the atomic scenarios. **The SPEC body exists only in the SPEC file and is never written into\n \`output.json\`.**\n10. **title rule**: \`title\` is a feature title in the SPEC's language (with a sense of page/entry location), and **equals** that SPEC's\n \`## UI Sequence\` line **verbatim**.\n11. **stem must be minted with the CLI, never hand-sanitized**: for that entry's \`title\` run\n \`node ${JSON.stringify(featureStem)} "<title>"\`, and use the printed stem as the file name unchanged. If this task's\n \`specs/\` already has a \`<stem>-SPEC.md\` of the same name, append \`-2\`, \`-3\`… in this task's production order; \`stem\` must be unique within\n \`output.json.specs[]\`. Hand-sanitizing makes \`check-fused-spec\`'s canonical-stem\n check fail.\n12. **Cut SPECs per flow and add the \`specs[]\` records**: the shape is \`SpecRecord\` in the "Output contract". One flow\n (data acquisition → derivation → display → persistence) corresponds to one \`owner: { kind: "area" }\` SPEC; do not split one flow across several\n SPECs. Add \`controlGroup\`/\`discovery\` records only for local standalone bindings, at most one each.\n An \`agent-added\` display SPEC carries its own \`identityAnchors\` (\`control\` required) and\n \`disposition:"added"\`. This field is **required** for this task.\n13. **Write the \`dataFlow\` data contract ledger**: exactly one row per area-owned SPEC, writing out \`entry\`, ≥1\n \`sources\`, ≥1 \`transforms\`, ≥1 \`displays\`, and \`persistence\` when there is a write/restore.\n \`specStem\` must exist in \`specs[]\`. R8 goes by it; a missing row, a dangling stem or a duplicate \`flowKey\` all fail.\n14. **Write the \`pageCoverage\` ledger**: exactly one row for every \`controlGroup\`/\`discovery\` of this Area; \`covered\`\n must give a \`specStem\` (existing in \`specs[]\`), \`excluded\` must give a \`reason\`. R4 goes by it.\n15. **Displayed-value derivation (R6a)**: every numeric/text field states its source field, time window, aggregation, rounding, sign and unit conversion;\n writing only "shows N" or "integer difference" is not allowed. A shared derivation rule is written once within a flow and referenced by later fields.\n16. **Display SPEC completeness (R6) is a required step, not an option**: per R6's definition in the output contract, do one source review of the data this Area\n renders/displays; for every display behavior the source can prove, that is user-visible and not covered by any SPEC,\n add an \`owner.kind="agent-added"\` \`specRecord\` and the corresponding SPEC file (own identityAnchors,\n ≥1 verifiable citation, \`disposition:"added"\`). An empty interaction surface is no exception.\n17. **Explicitly producing no SPEC**: when a Control/discovery really should not get a standalone SPEC this round, record it in\n \`pageCoverage\` with \`disposition:"excluded"\` and a reason; the legacy\n \`renderConfirmations\` are used only when no ledger is provided.\n18. **Body boundaries**: the SPEC body must not contain framework names such as Android/UniApp/Compose, \`file:line\` anchors, source\n symbols, placeholders or vague wording (R5 applies as well), and does not describe visual details of the UI; do not promote unresolved fields to established\n facts — content that must stay but the source cannot determine is simply omitted. **Do not** hand-write a \`Control:\` line or a \`controlRef\`.\n19. A single SPEC can be self-checked with \`check_spec\` (see the SPEC commands under "Output and Checks"); the whole-task self-check command\n covers both the fused draft and all SPECs.`;
|
|
367
368
|
}
|
|
368
369
|
|
|
369
370
|
/** The specgen script paths, resolved once so task.md and tests share them. */
|
|
@@ -336,9 +336,23 @@ test("residentRuleSections accepts the English rulebook copy (i18n/terms.json he
|
|
|
336
336
|
assert.match(kept, /```\n## UI Sequence\n[\s\S]*?```/u);
|
|
337
337
|
});
|
|
338
338
|
|
|
339
|
+
test("the SPEC writing step puts the UI sequence before the data contract (gate order)", () => {
|
|
340
|
+
const md = render();
|
|
341
|
+
const start = md.indexOf("9. **Write the SPEC file**");
|
|
342
|
+
const end = md.indexOf("10. **title rule**", start);
|
|
343
|
+
assert.ok(start >= 0 && end > start, "the SPEC step must be present");
|
|
344
|
+
const step = md.slice(start, end);
|
|
345
|
+
const ui = step.indexOf("## UI Sequence");
|
|
346
|
+
const contract = step.indexOf("Data Contract");
|
|
347
|
+
assert.ok(ui >= 0, "the step must name `## UI Sequence`");
|
|
348
|
+
assert.ok(contract >= 0, "the step must name the data contract");
|
|
349
|
+
assert.ok(ui < contract, "the template must put `## UI Sequence` before the data contract; check_spec rejects the reverse order");
|
|
350
|
+
assert.ok(contract < step.indexOf("atomic scenarios"), "the data contract must precede the atomic scenarios");
|
|
351
|
+
});
|
|
352
|
+
|
|
339
353
|
test("residentRuleSections still fails closed for a zh or en rulebook missing a section", () => {
|
|
340
|
-
const zh = "## Principles\np\n## UI Sequence Rules\nu\n## File Write and Body Shape\nw\n## Forbidden\nf\n";
|
|
341
|
-
const en = "## Principles\np\n## UI Sequence Rules\nu\n## File Write and Body Shape\nw\n## Forbidden\nf\n";
|
|
354
|
+
const zh = "## Principles\np\n## UI Sequence Rules\nu\n## File Write and Body Shape\nw\n## Data Contract Rules\nc\n## Forbidden\nf\n";
|
|
355
|
+
const en = "## Principles\np\n## UI Sequence Rules\nu\n## File Write and Body Shape\nw\n## Data Contract Rules\nc\n## Forbidden\nf\n";
|
|
342
356
|
const dropOne = [["## Step Discipline", "## Step Discipline"]];
|
|
343
357
|
// A declared dropped section that is absent in both languages throws (message names the zh heading).
|
|
344
358
|
assert.throws(() => residentRuleSections(zh, dropOne), /cannot drop them: ## Step Discipline$/u);
|
|
@@ -26,6 +26,9 @@ function cleanSpec(stem, title) {
|
|
|
26
26
|
"## UI Sequence",
|
|
27
27
|
title,
|
|
28
28
|
"",
|
|
29
|
+
"## Data Contract",
|
|
30
|
+
"No external data",
|
|
31
|
+
"",
|
|
29
32
|
"## Scenario 1",
|
|
30
33
|
"- 1. The user turns on the switch and the state is saved",
|
|
31
34
|
""
|
|
@@ -40,6 +43,9 @@ function dpViolatingSpec(stem, title) {
|
|
|
40
43
|
"## UI Sequence",
|
|
41
44
|
title,
|
|
42
45
|
"",
|
|
46
|
+
"## Data Contract",
|
|
47
|
+
"No external data",
|
|
48
|
+
"",
|
|
43
49
|
"## Scenario 1",
|
|
44
50
|
"- 1. Button width 48dp",
|
|
45
51
|
""
|
|
@@ -154,7 +160,7 @@ test("a SPEC content violation (a dp size line) fails through the shared check_s
|
|
|
154
160
|
const findings = checkDraftSpecs({ specs: [record("Switch-Off-By-Default", "Switch-Off-By-Default")] }, taskDir);
|
|
155
161
|
const view = findings.find((f) => f.level === "error" && f.rule === "UI-view-description(Principle 10)");
|
|
156
162
|
assert.ok(view, "the 48dp line must be flagged by the shared check_spec rules");
|
|
157
|
-
assert.equal(view.line,
|
|
163
|
+
assert.equal(view.line, 10);
|
|
158
164
|
assert.equal(view.text, "48dp");
|
|
159
165
|
// Must not falsely report H1 / UI Sequence: this fixture has content violations only.
|
|
160
166
|
assert.deepEqual(findings.filter((f) => f.rule === "SPEC naming" || f.rule === "SPEC UI Sequence"), []);
|
|
@@ -765,6 +771,9 @@ function cleanSpecEn(stem, title) {
|
|
|
765
771
|
"## UI Sequence",
|
|
766
772
|
title,
|
|
767
773
|
"",
|
|
774
|
+
"## Data Contract",
|
|
775
|
+
"No external data",
|
|
776
|
+
"",
|
|
768
777
|
"## Scenario 1",
|
|
769
778
|
"- 1. The user turns the switch on and the state is saved",
|
|
770
779
|
""
|
|
@@ -818,7 +827,7 @@ test("en: a `### Deviations from Requirement` section is rejected like `### Devi
|
|
|
818
827
|
const deviation = findings.find((f) => f.rule === "SPEC deviation section");
|
|
819
828
|
assert.ok(deviation, "an English deviation H3 section must be flagged");
|
|
820
829
|
assert.equal(deviation.level, "error");
|
|
821
|
-
assert.equal(deviation.line,
|
|
830
|
+
assert.equal(deviation.line, 12);
|
|
822
831
|
// case / plural variants are no bypass either
|
|
823
832
|
const variant = cleanSpecEn("Switch-Off-By-Default", "Switch-Off-By-Default") + "\n## Deviations From Requirements\n- x\n";
|
|
824
833
|
writeSpec(taskDir, "Switch-Off-By-Default-SPEC.md", variant);
|
|
@@ -31,6 +31,9 @@ const VIOLATING = [
|
|
|
31
31
|
"Background color #FF0000",
|
|
32
32
|
"The button is on the right side of the list",
|
|
33
33
|
"",
|
|
34
|
+
"## Data Contract",
|
|
35
|
+
"No external data",
|
|
36
|
+
"",
|
|
34
37
|
"## Scenario 1",
|
|
35
38
|
"- 1. The user taps and content is displayed",
|
|
36
39
|
"",
|
|
@@ -42,6 +45,9 @@ const CLEAN = [
|
|
|
42
45
|
"## UI Sequence",
|
|
43
46
|
"Switch-Off-By-Default",
|
|
44
47
|
"",
|
|
48
|
+
"## Data Contract",
|
|
49
|
+
"No external data",
|
|
50
|
+
"",
|
|
45
51
|
"## Scenario 1",
|
|
46
52
|
"- 1. The user turns on the switch and the state is saved",
|
|
47
53
|
"",
|
|
@@ -54,6 +60,9 @@ const WARN_ONLY = [
|
|
|
54
60
|
"## UI Sequence",
|
|
55
61
|
"After tapping, the corresponding prompt appears",
|
|
56
62
|
"",
|
|
63
|
+
"## Data Contract",
|
|
64
|
+
"No external data",
|
|
65
|
+
"",
|
|
57
66
|
"## Scenario 1",
|
|
58
67
|
"- 1. The user taps the button and the corresponding prompt appears",
|
|
59
68
|
"",
|
|
@@ -269,6 +278,9 @@ const CLEAN_EN = [
|
|
|
269
278
|
"## UI Sequence",
|
|
270
279
|
"Switch off by default",
|
|
271
280
|
"",
|
|
281
|
+
"## Data Contract",
|
|
282
|
+
"No external data",
|
|
283
|
+
"",
|
|
272
284
|
"## Scenario 1",
|
|
273
285
|
"- 1. The user turns the switch on and the state is saved",
|
|
274
286
|
"",
|
|
@@ -413,3 +425,26 @@ test("en: a step citing `Scenario N` gets the same self-reference warning as the
|
|
|
413
425
|
assert.ok(zh.some((f) => f.rule === "step self-reference" && f.level === "warn"));
|
|
414
426
|
assert.ok(en.some((f) => f.rule === "step self-reference" && f.level === "warn"), JSON.stringify(en));
|
|
415
427
|
});
|
|
428
|
+
|
|
429
|
+
test("en: data contract keys must appear in the documented order", () => {
|
|
430
|
+
const text = [
|
|
431
|
+
"# TimeSPEC",
|
|
432
|
+
"",
|
|
433
|
+
"## UI Sequence",
|
|
434
|
+
"Home - Hourly forecast",
|
|
435
|
+
"",
|
|
436
|
+
"## Data Contract",
|
|
437
|
+
"- Type: string",
|
|
438
|
+
"- Field: time",
|
|
439
|
+
"- Byte length: 12",
|
|
440
|
+
"- Range: yyyyMMddHHmm",
|
|
441
|
+
"- Sample: 202611121100",
|
|
442
|
+
"- Semantic source: interface time field definition",
|
|
443
|
+
"",
|
|
444
|
+
"## Scenario 1",
|
|
445
|
+
"- 1. The user opens the hourly forecast",
|
|
446
|
+
"",
|
|
447
|
+
].join("\n");
|
|
448
|
+
const findings = checkSpecText(text).filter((f) => f.rule === "data-contract");
|
|
449
|
+
assert.ok(findings.some((f) => f.note.includes("order")), JSON.stringify(findings));
|
|
450
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buaa_smat/hometrans",
|
|
3
|
-
"version": "26.0.
|
|
3
|
+
"version": "26.0.5",
|
|
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": {
|
|
@@ -10,10 +10,56 @@ description: "Production Android→HarmonyOS migration orchestrator. Loads refer
|
|
|
10
10
|
**拓扑、闸门、invoke、产物契约、失败策略的唯一权威:** `references/workflow.yaml`(尤其 `policy.*` + 节点 DAG)。
|
|
11
11
|
产物真源 / CLI 契约速查:[references/stage-map.md](references/stage-map.md)。
|
|
12
12
|
|
|
13
|
-
加载 yaml → 按 `PROFILE` 裁剪 → 按节点 `needs`
|
|
13
|
+
加载 yaml → 按 `PROFILE` 裁剪 → 由生产 DAG Runner 按节点 `needs` 推进,并把语义 `invoke` 交给当前宿主;子代理返回 JSON;MANIFEST 由生产 executor 初始化,LEDGER 与节点终态由 Runner 独占提交。细节勿在本文件复述。
|
|
14
14
|
|
|
15
15
|
**禁止模型因上下文预算主动结束**(`policy.context_budget`)。上下文窗口、token 余量、会话变长或压缩都不是停机条件。
|
|
16
16
|
|
|
17
|
+
## 确定性 DAG Runner(生产入口)
|
|
18
|
+
|
|
19
|
+
真实 `workflow.yaml` 的全部节点都由 Node 状态机推进:拓扑、变量、artifact 校验、失败策略、ledger 和唯一 `run_end` 归 Runner;`dag_production_executor.mjs` 只执行当前节点的确定性动作,或把语义工作交给当前宿主。生产运行自动选择该 executor,不需要 `--executor-command`,也不启用并行调度。
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
node ${SKILLS_ROOT}/a2h-app-migrate/scripts/dag_runner.mjs run \
|
|
23
|
+
--workflow ${SKILLS_ROOT}/a2h-app-migrate/references/workflow.yaml \
|
|
24
|
+
--run-dir <DAG_RUN_DIR> --profile full \
|
|
25
|
+
--vars '{"ANDROID":"<ANDROID>","HMOS":"<HMOS>"}'
|
|
26
|
+
node ${SKILLS_ROOT}/a2h-app-migrate/scripts/dag_runner.mjs continue --state <DAG_RUN_DIR>/dag-run-state.json
|
|
27
|
+
node ${SKILLS_ROOT}/a2h-app-migrate/scripts/dag_runner.mjs status --state <DAG_RUN_DIR>/dag-run-state.json
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`DAG_RUN_DIR` 只保存 Runner 状态、attempt 请求/结果和 action cursor,必须与生产 `${WORK}`、`${RUN_DIR}`、`${HMOS}` 分离。预检通过前不得写生产目录;`run_start` 延迟到 `boot.workspace` 成功后提交。`continue` 恢复同一 `run_id`,已提交的 action cursor 只在 Runner 中断恢复时继承,业务重试和 review rewind 使用新 cursor。
|
|
31
|
+
|
|
32
|
+
每次 `run` / `continue` / `complete` / `confirm` / `rewind` 的 stdout 都带 `presentation`。宿主处理 wait 前必须按 `events` 顺序刷新 `policy.user_facing` 的固定进度块:用 `checklist` 和当前 `nodes` 渲染整份清单;`doing` / `terminal` 事件按 `event.user_facing`、状态、reason/evidence 选句;`notice` 事件按 `event.text` 的提示要求立即告知用户。同一响应的多个事件合并到一份清单,不逐条刷屏。只有 Runner 返回 `terminal` 后才能宣布终态,不得凭 executor 的 `ok:true` 自行宣布完成;`status` 不重放历史事件。
|
|
33
|
+
|
|
34
|
+
### 宿主处理等待与回调
|
|
35
|
+
|
|
36
|
+
`run` / `continue` 返回 `waiting_external` 时,从当前 attempt 的 `<file_id>.request.json` 读取 `wait.kind`:
|
|
37
|
+
|
|
38
|
+
- `skill`:当前主会话按 `wait.skill` 加载指定 Skill,以 `primary_skill_inline` 执行 `wait.invoke`;不得用 shell worker 冒充 Skill。
|
|
39
|
+
- `host_action`:当前宿主完成签名采用或最终报告等宿主动作。
|
|
40
|
+
- `config`:向用户收集启动配置;`image_read`:严格按 `wait.instructions` 派一次性前台子代理读图。两者用 executor 的 `answer` 回调,其余用 `complete` 回调。
|
|
41
|
+
|
|
42
|
+
Skill / host action 完成后写 `{"attempt_id":"<id>","ok":true,"set_vars":{}}`;失败写 `ok:false` 和非空 `reason`。随后执行:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
node ${SKILLS_ROOT}/a2h-app-migrate/scripts/dag_production_executor.mjs complete \
|
|
46
|
+
--request <DAG_RUN_DIR>/attempts/<file_id>.request.json --outcome <outcome.json>
|
|
47
|
+
node ${SKILLS_ROOT}/a2h-app-migrate/scripts/dag_runner.mjs complete \
|
|
48
|
+
--state <DAG_RUN_DIR>/dag-run-state.json --attempt-id <id> \
|
|
49
|
+
--result-file <DAG_RUN_DIR>/attempts/<file_id>.result.json
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
配置 / 读图应答把 executor 子命令换成 `answer --answer <answer.json>`,再同样调用 Runner `complete`。executor 只生成严格结果,宿主不得自行追加节点终态、`run_start` 或 `run_end`。迟到 attempt、非法结果、executor 早停会阻塞,绝不记成业务 soft failure 或冒充完成。只有契约脚本按约定非零退出(含 capture_audit / 闸门脚本)和宿主 `ok:false` 才记业务 failed;executor 的协议错误、配置错误(如 `INVALID_SKILL`、`INVALID_SET_VARS`)和实现缺口(`UNSUPPORTED_*`)一律非零退出、不写结果,由 Runner 阻塞。
|
|
53
|
+
|
|
54
|
+
`waiting_human` 只能由真实闸门确认或受限 rewind 推进,不能用普通 `complete` 绕过:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
node ${SKILLS_ROOT}/a2h-app-migrate/scripts/dag_runner.mjs confirm --state <DAG_RUN_DIR>/dag-run-state.json --node review.arch --confirmed-by user
|
|
58
|
+
node ${SKILLS_ROOT}/a2h-app-migrate/scripts/dag_runner.mjs rewind --state <DAG_RUN_DIR>/dag-run-state.json --node review.arch
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
`rewind` 仅重跑当前 gate 的 `runner.rewind_to` 及下游,清除对应 REUSE 变量并增加 generation。`FROM_NODE` 续跑使用新的 DAG 控制目录和 `run --resume-from <node> --base-profile <profile>`,沿用生产 `${WORK}` / `${LEDGER}`,仍走 `planResume()` 的 profile、SPEC_ENGINE、产物探测和继承规则。若 hard_stop 的 `error.ledger_started` 为 false(run_start 之前就停了,ledger 里没有本轮记录),不要用 `--resume-from`,按 `error.hint` 修复后重新 `run`。
|
|
62
|
+
|
|
17
63
|
---
|
|
18
64
|
|
|
19
65
|
## 参数
|
|
@@ -61,7 +107,7 @@ description: "Production Android→HarmonyOS migration orchestrator. Loads refer
|
|
|
61
107
|
|
|
62
108
|
## ★ 启动第一步(不可跳过)
|
|
63
109
|
|
|
64
|
-
**参数清单的唯一权威是 workflow.yaml → `bootstrap.run_env_preflight.args
|
|
110
|
+
**参数清单的唯一权威是 workflow.yaml → `bootstrap.run_env_preflight.args`**。生产 executor 按该契约逐项渲染并执行下面的脚本;宿主不得绕过 Runner 提前手工预检或写工作区。
|
|
65
111
|
|
|
66
112
|
每个参数渲染成单个 `--key=<值>`(值为空也照传 `--key=`);布尔参数先求值成 `true` / `false` 再传。
|
|
67
113
|
|
|
@@ -106,7 +152,7 @@ devecocli 登录:只在**工程还没有签名配置**、且不是「只连了
|
|
|
106
152
|
2. **scaffold_new** — `discover.arch` 必须第一个碰 `${HMOS}`(`create_project` 判空只忽略 `.git`)→ `policy.parallel_rule`。
|
|
107
153
|
3. **post_utg** — 固定串行:`ui.batch` → `enrich.spec_gen`;spec_gen 一律只读 `${UTG_SNAPSHOT}` → `policy.parallel_rule`。
|
|
108
154
|
4. **调度** — 固定串行(无调度变量)。post_utg 与 `discover.utg_static` 均 primary 内联;叶子内部 worker 仍可用主会话 Task。`logic.spec_pipeline` **一律 primary 内联**:它 B1/B2 会结束本轮等后台通知,被唤醒后继续它的事件循环,直到它输出最终报告才算节点结束;完成判定用 `check_spec_pipeline_done.mjs`(state 文件存在不算)。
|
|
109
|
-
5. **闸门** — 禁止因 `auto` 确认而 skip 节点(否则无人写 checkpoint);`auto` 或闸门不在 `INTERACTIVE_GATES` → `--write-confirmed --confirmed-by auto`;白名单内停等,用户确认后 `--write-confirmed --confirmed-by user` → `policy.human_interaction`。`review.arch` **不**因 `REUSE_DISCOVER_ARCH` 而 `skip_if`(文档复用 ≠ 确认;缺 checkpoint 时须补写/重问,见 `policy.human_gate_protocol`)。产出节点(`discover.arch` / `enrich.spec_gen` / `ui.batch`)**真正执行前**必须先跑它的 `before_run`(`--clear-checkpoint` 作废对应闸门);复用产物或 skip
|
|
155
|
+
5. **闸门** — 禁止因 `auto` 确认而 skip 节点(否则无人写 checkpoint);`auto` 或闸门不在 `INTERACTIVE_GATES` → `--write-confirmed --confirmed-by auto`;白名单内停等,用户确认后 `--write-confirmed --confirmed-by user` → `policy.human_interaction`。`review.arch` **不**因 `REUSE_DISCOVER_ARCH` 而 `skip_if`(文档复用 ≠ 确认;缺 checkpoint 时须补写/重问,见 `policy.human_gate_protocol`)。产出节点(`discover.arch` / `enrich.spec_gen` / `ui.batch`)**真正执行前**必须先跑它的 `before_run`(`--clear-checkpoint` 作废对应闸门);复用产物或 skip 时**禁止**清除。生产 executor 逐项提交 before_run cursor 后才返回 Skill 等待;节点有 `after_run` 的,宿主回调后由 executor 先执行它,再由 Runner 判 success。
|
|
110
156
|
6. **spec 边界** — `specs.json` 只由 enrich.spec_gen 的叶子按 `SPEC_ENGINE` 写出(`spec-generate` → a2h-spec-generate 的 `publish-specs`;`page-specgen` → a2h-page-specgen 的 `finalize`);禁展开叶子内部;禁改 `${RUN_DIR}` 布局 → `policy.spec_order_boundary`。语义不完整时按 **deveco-cli 契约**带洞发布:三步用 `--allow-incomplete`,specs.json 记 `completeness: "incomplete-known"` + `incomplete{...}`,节点仍成功、下游照常消费,缺口只记录在 specs.json 的 incomplete 里,不写进最终报告(见 enrich.spec_gen 的 invoke);唯一例外:增量运行时范围内没生成 SPEC 的页面(`incomplete.scopeUnmatched` / `scope.unmatched`)是增量范围的结果、不是 SPEC 质量缺口,由 logic.finalize 的「增量范围」一节(`scope_report.mjs`)列进「跳过的内容」。`page-specgen` 同样带洞发布:`finalize` 只要发布出 `specs.json` 就 exit 0,partial 或 gate 失败把 `incomplete{areas,pages,failedShards,...}` 写入清单与 ledger,不写进最终报告,下游照常消费;只有“一个 SPEC 都没发布”才是节点失败。切换引擎 = 新 run。
|
|
111
157
|
|
|
112
158
|
7. **module_docs** — 只传 `--engine-mode` / `--incremental preserve` / `--scope project-source`(无 `--hometrans-dir` / `--doc-layout`);它会刷新 arch 写的 `.hometrans/project_design.md`,完成判定看 `module_understanding/.module_semantic_docs_state.json`。
|
|
@@ -155,7 +201,9 @@ node ${SKILLS_ROOT}/a2h-app-migrate/scripts/validate_workflow.mjs
|
|
|
155
201
|
| `scripts/env_preflight.mjs` | 启动预检 / 客户一键自检(缺省填 work/run-dir/ui-info-root);固定 serial |
|
|
156
202
|
| `scripts/infer_android_root.mjs` | 入口按 APK 路径前缀确定 Android 工程根(给定路径不是工程根时替换,预检前) |
|
|
157
203
|
| `scripts/paths_preflight.mjs` | 路径子模块 |
|
|
158
|
-
| `scripts/validate_workflow.mjs` | workflow.yaml
|
|
204
|
+
| `scripts/validate_workflow.mjs` | workflow.yaml 静态自检(含全部生产节点的 Runner kind、固定顺序、reuse/skip、gate 与 finalize 所有权) |
|
|
205
|
+
| `scripts/dag_runner.mjs` | 生产 DAG 状态机;独占节点终态、resume/rewind、ledger 提交和唯一 run_end |
|
|
206
|
+
| `scripts/dag_production_executor.mjs` | 生产节点 action driver;确定性脚本、逐项 cursor、Skill/config/image/host_action 等待与严格回调 |
|
|
159
207
|
| `scripts/human_review_gate.mjs` | 人工闸门(arch / spec_gen / ui_batch) |
|
|
160
208
|
| `scripts/run_dir.mjs` | spec 生成的 run 目录:`--show` 读指针 / 决定续跑或新建(`--fresh`)/ `--record` 以实际目录为准(指针 `${WORK}/reqgen/current.json` 记当前这一次) |
|
|
161
209
|
| `scripts/spec_layout.mjs` | enrich.spec_gen 产物布局(`<run>/generation/pages` 页面分组根、specs.json 位置)的唯一实现;两个引擎共用该发布根(page-specgen 的私有工作区也在根下) |
|
|
@@ -163,7 +211,7 @@ node ${SKILLS_ROOT}/a2h-app-migrate/scripts/validate_workflow.mjs
|
|
|
163
211
|
| `scripts/check_spec_pipeline_done.mjs` | logic.spec_pipeline 完成判定(全部 group 终态、无未结束 chunk、Finalization 已写 `state.finalization` 且 `finalization.homecheck` / `finalization.smoke` 两个标记齐全——只写 `done` 不算完成;全部 failed → exit 3;硬指纹 `specs_json_sha256`/路径不一致 → exit 4;软旋钮 `wave_width` 等只进 `soft_stale` 不归档;`--archive-stale` / `--archive-failed` 仅在 exit 4/3 归档,供 before_run 新开一轮) |
|
|
164
212
|
| `scripts/check_module_docs_done.mjs` | enrich.module_docs 完成判定(`--mark` 记开跑时间;状态文件须不早于它——状态文件是增量基线,跨运行保留) |
|
|
165
213
|
| `scripts/check_ui_batch_done.mjs` | 探测 4:ui.batch 可复用判定(batch_report.md 存在、batch_progress.json 的 mode 为 full、无 pending 页) |
|
|
166
|
-
| `scripts/ledger.mjs` | `${LEDGER}`
|
|
214
|
+
| `scripts/ledger.mjs` | `${LEDGER}` 只追加、跨运行保留;支持 `--start` / `--node … --status` / `--failures`,生产中仅由 Runner 提交 `run_start`、节点终态与唯一 `run_end`,宿主不得直接追加 |
|
|
167
215
|
| `scripts/diagnose.mjs` | 增量启动诊断(只读):场景 1 / 2 / 3、每类产物复用 / 修复 / 重建、源码变化的已迁页面与新页面、`SCOPE=auto` 的推荐范围 |
|
|
168
216
|
| `scripts/source_fp.mjs` | 页面级 Android 源码指纹(UTG 锚点 + 引用的布局,行尾归一化);收尾时写进台账,诊断据此找出源码变化的已迁页面 |
|
|
169
217
|
| `scripts/migration_manifest.mjs` | logic.finalize 第 4 步:按 UTG 页面 id 把本轮界面 / 业务逻辑状态合并进 `${HMOS}/.hometrans/migration_manifest.json`(跨运行、跨范围保留;失败的重试不覆盖已迁记录;永不失败节点) |
|