@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
|
@@ -56,6 +56,7 @@ The spec is a contract for reimplementation. A statement that cannot be turned i
|
|
|
56
56
|
| 做相应处理 / 执行必要的校验 | 依次校验:裁剪首尾空白 → 判空 → 判长度 ≤ 100 |
|
|
57
57
|
| 存储到本地 | 写入歌单持久化存储,页面重进后仍生效 |
|
|
58
58
|
| 默认值合适即可 | 开关默认关闭;条目每页最多 20 条 |
|
|
59
|
+
| 否则不发生更新 / 其余情况不更新 | 每个状态写自己的可见结果;首帧与非默认语言写资源里的实际字面量 |
|
|
59
60
|
| 页面刷新 | 歌单列表页、歌单详情页、歌单选择弹窗中该歌单的歌曲数目实时刷新 |
|
|
60
61
|
| 调用云端接口 / 请求网络 | `POST https://...`,请求体字段为 `...`,根据响应字段 `code` 决定下一步 |
|
|
61
62
|
| 发送数据 / 按协议发送 | 明确方向、frame/message 字段、command/version、长度、payload、字段顺序和编码 |
|
|
@@ -71,7 +72,26 @@ The spec is a contract for reimplementation. A statement that cannot be turned i
|
|
|
71
72
|
|
|
72
73
|
**Also banned** (Principle 7): 返回错误码 / 返回 -1 / 抛出异常 / 接口返回 / 入参 / 返回值 — replace each with the user-visible outcome or the concrete data-transfer behavior. If a failure has no user-visible outcome at all, it does not belong in a UI spec.
|
|
73
74
|
|
|
74
|
-
**Also banned** (Principle 10): 宽度/高度/尺寸/左右/上下/间距/边距/对齐/层级/圆角/字号/字重/行高/颜色/背景/阴影 and their concrete values (`150dp`, `14sp`, `#FF5722`, `marginStart 16dp`). State what is shown and where it comes from; the visual form is the implementer's own design decision. A layout value quoted from the source is a leakage of evidence into the spec, not extra precision. 动效时长是唯一的例外(见上):写「0.35
|
|
75
|
+
**Also banned** (Principle 10): 宽度/高度/尺寸/左右/上下/间距/边距/对齐/层级/圆角/字号/字重/行高/颜色/背景/阴影 and their concrete values (`150dp`, `14sp`, `#FF5722`, `marginStart 16dp`). State what is shown and where it comes from; the visual form is the implementer's own design decision. A layout value quoted from the source is a leakage of evidence into the spec, not extra precision. 动效时长是唯一的例外(见上):写「0.35 秒」这类可移植表述;绝对位移、曲线名与资源/属性名仍不进正文。`## 数据契约` 的 `字节长度` 是另一项例外:它表示外部数据字段占用的字节数,不是界面尺寸。
|
|
76
|
+
|
|
77
|
+
## 数据契约(每个 SPEC 必填)
|
|
78
|
+
|
|
79
|
+
`## 数据契约` 位于 `## UI序列` 之后、第一个场景之前,为每一个外部字段(接口响应、缓存、数据库、文件、设置项、定位结果)写一个块:
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
- 字段:variable
|
|
83
|
+
- 类型:uint8
|
|
84
|
+
- 字节长度:1
|
|
85
|
+
- 取值域:0-255
|
|
86
|
+
- 样例:56
|
|
87
|
+
- 语义来源:接口协议字段定义
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
- 六个键固定:`字段`、`类型`、`字节长度`、`取值域`、`样例`、`语义来源`;缺键、重复键、空值都是错误。
|
|
91
|
+
- 类型与宽度是源码契约,不是推测:读接口定义、schema、序列化/反序列化代码或真实响应样本;查不到就按 Principle 15 报告缺口,**不许猜**「一般是 12 位」或「一般按 int32 读」。
|
|
92
|
+
- `样例` 必须是真实、可核对的值(源码字面量或已采集的响应),并同时出现在场景步骤所依赖的分支里。
|
|
93
|
+
- `语义来源` 写中立语义名(如「日期时间格式定义」「单位枚举定义」),不写平台文件名、`file:line` 或框架符号。契约定义文件必须放进本 SPEC 的 `citations`(发布后汇总到 `## 源码位置`),评审时确认该引用指向契约定义文件,而不是只指向 UI 实现。
|
|
94
|
+
- 没有外部数据时写一行 `不涉及外部数据`;不得省略整节或留空。
|
|
75
95
|
|
|
76
96
|
---
|
|
77
97
|
|
|
@@ -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 平台中立化规则 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. `## 数据契约` 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序列` 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 `设置-歌词-悬浮窗状态栏歌词` — copied verbatim. See `## UI序列规则`.
|
|
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 「按设计稿」, 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 秒」「内容先让位、页面随后滑入」), 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.
|
|
@@ -89,10 +89,33 @@ Take this requirement's title + description verbatim as the raw requirement; if
|
|
|
89
89
|
2. 身份行 `控件:<controlRef>` —— 需求带 `控件:` 行时逐字照抄,**没有则整行省略**,绝不编造;
|
|
90
90
|
3. 需求语义描述;
|
|
91
91
|
4. `## UI序列`(单行,逐字照抄需求标题);
|
|
92
|
-
5.
|
|
92
|
+
5. `## 数据契约`(见下节;没有外部数据时写一行 `不涉及外部数据`);
|
|
93
|
+
6. 原子场景。
|
|
93
94
|
|
|
94
95
|
文档以最后一个场景(或差异 H3 段)结束,没有页脚。
|
|
95
96
|
|
|
97
|
+
## 数据契约规则
|
|
98
|
+
|
|
99
|
+
SPEC 消费或读取外部数据(接口响应、缓存、数据库、文件、设置项、定位结果)时,`## 数据契约` 为**每一个外部字段**写一个块:
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
## 数据契约
|
|
103
|
+
|
|
104
|
+
- 字段:time
|
|
105
|
+
- 类型:string
|
|
106
|
+
- 字节长度:12
|
|
107
|
+
- 取值域:yyyyMMddHHmm
|
|
108
|
+
- 样例:202611121100
|
|
109
|
+
- 语义来源:接口时间字段定义
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
- 六个键缺一不可,顺序固定;多个字段用空行分隔成多个块。
|
|
113
|
+
- `类型` 写实际类型(如 `string`、`uint8`、`float32`、`int64`);`字节长度` 写该字段按源码声明编码占用的字节数:定长字段写具体字节数,变长字段写 `变长`。字符数不等于字节数(UTF-8 下一个中文字符通常 3 字节),不要用字符数代替。
|
|
114
|
+
- `取值域` 写格式、枚举范围或边界;`样例` 写一个真实、可核对的值,不是占位符。
|
|
115
|
+
- `语义来源` 写该契约的中立语义名称(如「接口时间字段定义」「单位枚举定义」),不得写平台文件名或 `file:line`。对应的契约定义文件必须放进本 SPEC 的 `citations`(发布后汇总到 `## 源码位置`),评审时核对该条引用指向契约定义文件,而不是只指向 UI 控件。
|
|
116
|
+
- SPEC 不读取任何外部数据时,这一节只写一行 `不涉及外部数据`,不得留空,也不得省略整节。
|
|
117
|
+
- 契约里的宽度、格式、枚举值必须来自源码或真实响应;查不到就按 Principle 15 在缺口清单里报告,不得猜一个「常见格式」。
|
|
118
|
+
|
|
96
119
|
## Step 3 汇报义务
|
|
97
120
|
**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 「证据不足」. 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.
|
|
98
121
|
|
|
@@ -426,7 +426,9 @@ function checkOneSpec(record, index, taskDir, draft) {
|
|
|
426
426
|
findings.push(...checkBehaviorMarkers(draft, text, record));
|
|
427
427
|
|
|
428
428
|
// Decidable SPEC rules: reuse check_spec.ts in process, evaluated on the already-read text (avoids a second disk read / TOCTOU).
|
|
429
|
-
|
|
429
|
+
// A page-flow SPEC (`owner.kind: "area"`) must also enumerate its states: the ledger below counts
|
|
430
|
+
// page flows, and a page flow without a state list is exactly how the first frame and empty data vanish.
|
|
431
|
+
findings.push(...checkSpecText(text, { requireStateList: record?.owner?.kind === "area" }));
|
|
430
432
|
|
|
431
433
|
return { spec: specFile, findings };
|
|
432
434
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
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序列`, no placeholders
|
|
6
|
+
* - H1, section order, single-line `## UI序列`, the six-key `## 数据契约` (or its opt-out), no placeholders
|
|
7
7
|
* - Principle 10 zero UI view descriptions (size/position/color/font size/alignment/animation)
|
|
8
8
|
* - Principle 6 no platform symbols
|
|
9
9
|
* - Principle 7 no interface contracts (signatures/parameter tables/return values/error codes)
|
|
@@ -178,16 +178,134 @@ const CONTROL_LINE = /^(?:控件:|Control:)/;
|
|
|
178
178
|
const CONTROL_VALUE = /^(?:控件:|Control: )control:/;
|
|
179
179
|
/** H2 name (with `## ` already stripped): `UI序列` / `UI Sequence` */
|
|
180
180
|
const UI_SEQ_NAME = /^(?:UI序列|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. The `字节长度` label is deliberate: the
|
|
186
|
+
* contract needs the byte width, while `宽度` alone is a banned view property. */
|
|
187
|
+
const DATA_CONTRACT_KEYS: ReadonlyArray<readonly [string, string]> = [
|
|
188
|
+
['字段', 'field'],
|
|
189
|
+
['类型', 'type'],
|
|
190
|
+
['字节长度', 'byte length'],
|
|
191
|
+
['取值域', 'range'],
|
|
192
|
+
['样例', 'sample'],
|
|
193
|
+
['语义来源', 'semantic source'],
|
|
194
|
+
];
|
|
181
195
|
/** H2 name: a scenario section (`场景…` / `Scenario…`) */
|
|
182
196
|
const SCENARIO_NAME = /^(?:场景|Scenario)/;
|
|
183
197
|
/** A valid scenario heading: `场景` + Chinese or Arabic numerals; in English only `Scenario <digits>` */
|
|
184
198
|
const SCENARIO_NAME_STRICT = /^(?:场景[一二三四五六七八九十百零\d]+|Scenario[ \t]+\d+)$/;
|
|
185
199
|
|
|
200
|
+
/** Resolve a contract-block label to its canonical (zh, en) pair, in either language. */
|
|
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 (raw.trim() === pair[0] || key === pair[1]) return pair;
|
|
205
|
+
}
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Check one `## 数据契约` body: either the explicit opt-out line, or blocks of
|
|
211
|
+
* `- <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
|
+
|
|
225
|
+
while (body.length > 0 && body[0].text === '') body.shift();
|
|
226
|
+
while (body.length > 0 && body[body.length - 1].text === '') body.pop();
|
|
227
|
+
if (body.length === 0) {
|
|
228
|
+
add(sectionIndex + 1, 'the data contract body is empty: declare at least one field block, or write the opt-out line');
|
|
229
|
+
return out;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const optOut = body.filter(({ text }) => DATA_CONTRACT_OPTOUT.test(text));
|
|
233
|
+
if (optOut.length > 0) {
|
|
234
|
+
if (body.length > 1) {
|
|
235
|
+
add(optOut[0].line, 'the opt-out line must be the only body of the data contract');
|
|
236
|
+
}
|
|
237
|
+
return out;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
let block: Array<{ key: readonly [string, string]; value: string; line: number }> = [];
|
|
241
|
+
const flush = () => {
|
|
242
|
+
if (block.length === 0) return;
|
|
243
|
+
for (const [zh, en] of DATA_CONTRACT_KEYS) {
|
|
244
|
+
const hits = block.filter((item) => item.key[0] === zh);
|
|
245
|
+
if (hits.length === 0) add(block[0].line, `data contract block is missing the \`${zh}\` (${en}) key`);
|
|
246
|
+
if (hits.length > 1) add(hits[1].line, `data contract block repeats the \`${zh}\` (${en}) key (check for a missing blank line between field blocks)`);
|
|
247
|
+
}
|
|
248
|
+
const positions = block.map((item) => DATA_CONTRACT_KEYS.findIndex(([zh]) => zh === item.key[0]));
|
|
249
|
+
const complete = positions.length === DATA_CONTRACT_KEYS.length && positions.every((position) => position >= 0);
|
|
250
|
+
if (complete && new Set(positions).size === positions.length) {
|
|
251
|
+
const ordered = positions.every((position, index) => position === index);
|
|
252
|
+
if (!ordered) {
|
|
253
|
+
add(block[0].line, `data contract keys must appear in order: ${DATA_CONTRACT_KEYS.map(([zh]) => zh).join(' → ')}`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
block = [];
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
for (const { text, line } of body) {
|
|
260
|
+
if (text === '') { flush(); continue; }
|
|
261
|
+
const match = /^-\s*([^::]{1,24})\s*[::]\s*(.*)$/.exec(text);
|
|
262
|
+
if (!match) {
|
|
263
|
+
add(line, 'the data contract only accepts `- <key>: <value>` lines (one block per external field)');
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
const key = contractKeyOf(match[1]);
|
|
267
|
+
if (key === null) {
|
|
268
|
+
add(line, `unknown data contract key: "${match[1].trim()}"`);
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
const value = match[2].trim();
|
|
272
|
+
if (value === '') {
|
|
273
|
+
add(line, `data contract key \`${key[0]}\` (${key[1]}) has an empty value`);
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
block.push({ key, value, line });
|
|
277
|
+
}
|
|
278
|
+
flush();
|
|
279
|
+
return out;
|
|
280
|
+
}
|
|
281
|
+
|
|
186
282
|
/** H2 name: the trailing provenance section the publisher appends (`源码位置` /
|
|
187
283
|
* `Source locations`). It is the ONE place a source path may appear, so it is
|
|
188
284
|
* also the one place `code-anchor-leak` has to stand down. */
|
|
189
285
|
const SOURCE_SECTION_NAME = /^(?:源码位置|Source[ \t]+locations)$/;
|
|
190
286
|
|
|
287
|
+
/** H2 name: the state list (`状态清单` / `State list`). One row per state, placed
|
|
288
|
+
* between `## UI序列` and the first scenario: the scenarios then say what each
|
|
289
|
+
* state does, instead of a catch-all "otherwise nothing updates". */
|
|
290
|
+
const STATE_LIST_NAME = /^(?:状态清单|State[ \t]+list)$/;
|
|
291
|
+
|
|
292
|
+
/** The states every page flow must account for. A row per state; a state this
|
|
293
|
+
* page cannot reach is written `- 加载中:不适用(理由)`, never omitted. */
|
|
294
|
+
const STATE_KEYS: ReadonlyArray<{ key: string; labels: readonly string[] }> = [
|
|
295
|
+
{ key: '首帧', labels: ['首帧', '初始帧', '首次显示', 'first frame', 'initial frame'] },
|
|
296
|
+
{ key: '加载中', labels: ['加载中', '加载状态', 'loading'] },
|
|
297
|
+
{ key: '成功', labels: ['成功', 'success'] },
|
|
298
|
+
{ key: '数据为空', labels: ['数据为空', '空数据', '内容为空', 'empty data', 'no data'] },
|
|
299
|
+
{ key: '数据不足', labels: ['数据不足', '数据过短', 'insufficient data', 'short data'] },
|
|
300
|
+
{ key: '失败', labels: ['失败', '错误', 'failure', 'error'] },
|
|
301
|
+
{ key: '非默认语言', labels: ['非默认语言', '其他语言', '非默认 locale', 'non-default locale', 'other locale'] },
|
|
302
|
+
{ key: '离开后重新进入', labels: ['离开后重新进入', '重新进入', '离开再回来', 'return after leaving', 're-entry', 'reentry'] },
|
|
303
|
+
];
|
|
304
|
+
|
|
305
|
+
/** One state row: `- 首帧:风速显示 \`%1$d km/h\`` (a bracketed label is allowed). */
|
|
306
|
+
const STATE_ROW = /^[ \t]*-\s*(?:\[)?([^::\]]{1,24})(?:\])?\s*[::]\s*(.*)$/u;
|
|
307
|
+
const NOT_APPLICABLE = /^(?:不适用|not[ \t]+applicable|n\/a)(?=$|[\s((::,,。])/i;
|
|
308
|
+
|
|
191
309
|
/** One provenance bullet, in the exact shape `collect-specs` writes:
|
|
192
310
|
* `- 整页:`a/Main.kt:12-20`、`a/A.kt:3`` or `- Whole page: `a/Main.kt:12-20`, `a/A.kt:3``.
|
|
193
311
|
* Deliberately strict: the exemption follows the SHAPE, not the section, so a
|
|
@@ -197,6 +315,7 @@ const SOURCE_BULLET = /^[ \t]*-[ \t]+[^::`\n]{1,24}(?::|:[ \t])`[^\s`]+:\d+(
|
|
|
197
315
|
function checkStructure(lines: string[]): Finding[] {
|
|
198
316
|
const out: Finding[] = [];
|
|
199
317
|
const add = (line: number, note: string) => out.push({ level: 'error', rule: 'structure', line, text: lines[line - 1]?.slice(0, 60) ?? '', note });
|
|
318
|
+
const addContract = (line: number, note: string) => out.push({ level: 'error', rule: 'data-contract', line, text: lines[line - 1]?.slice(0, 60) ?? '', note });
|
|
200
319
|
|
|
201
320
|
// H1
|
|
202
321
|
const h1 = lines.findIndex((l) => /^#\s+\S/.test(l));
|
|
@@ -225,13 +344,36 @@ function checkStructure(lines: string[]): Finding[] {
|
|
|
225
344
|
const h2 = lines.map((l, i) => ({ l, i })).filter(({ l }) => /^##\s+/.test(l));
|
|
226
345
|
const names = h2.map(({ l }) => l.replace(/^##\s+/, '').trim());
|
|
227
346
|
let cursor = 0;
|
|
347
|
+
let uiSeen = false;
|
|
348
|
+
let contractSeen = 0;
|
|
349
|
+
let scenarioSeen = false;
|
|
350
|
+
const contractSections: number[] = [];
|
|
228
351
|
for (let k = 0; k < names.length; k++) {
|
|
229
352
|
const n = names[k];
|
|
230
|
-
if (UI_SEQ_NAME.test(n)) {
|
|
353
|
+
if (UI_SEQ_NAME.test(n)) {
|
|
354
|
+
if (cursor > 0) add(h2[k].i + 1, `\`${UI_SEQUENCE_TOKEN}\` must come before every scenario`);
|
|
355
|
+
uiSeen = true;
|
|
356
|
+
cursor = Math.max(cursor, 1);
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
359
|
+
if (DATA_CONTRACT_NAME.test(n)) {
|
|
360
|
+
contractSeen += 1;
|
|
361
|
+
contractSections.push(h2[k].i);
|
|
362
|
+
if (cursor < 1) addContract(h2[k].i + 1, `\`## 数据契约\` must come after \`${UI_SEQUENCE_TOKEN}\``);
|
|
363
|
+
if (cursor >= 2) addContract(h2[k].i + 1, '`## 数据契约` must come before every scenario');
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
231
366
|
if (SCENARIO_NAME.test(n)) {
|
|
232
367
|
if (!SCENARIO_NAME_STRICT.test(n)) add(h2[k].i + 1, `scenario heading should be \`${'## 场景N'}\`, got "${n}"`);
|
|
233
368
|
if (cursor === 3) add(h2[k].i + 1, 'a scenario section must come before the source-locations section');
|
|
234
|
-
|
|
369
|
+
scenarioSeen = true;
|
|
370
|
+
cursor = Math.max(cursor, 2);
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
if (STATE_LIST_NAME.test(n)) {
|
|
374
|
+
// `cursor === 1` means `## UI序列` was seen and no scenario has started.
|
|
375
|
+
if (cursor !== 1) add(h2[k].i + 1, `\`## ${n}\` must sit between \`${UI_SEQUENCE_TOKEN}\` and the first scenario`);
|
|
376
|
+
continue;
|
|
235
377
|
}
|
|
236
378
|
if (SOURCE_SECTION_NAME.test(n)) {
|
|
237
379
|
if (cursor < 2) add(h2[k].i + 1, 'the source-locations section must come after every scenario');
|
|
@@ -239,8 +381,11 @@ function checkStructure(lines: string[]): Finding[] {
|
|
|
239
381
|
}
|
|
240
382
|
add(h2[k].i + 1, `H2 section not allowed: "${n}"`);
|
|
241
383
|
}
|
|
242
|
-
if (!
|
|
243
|
-
if (
|
|
384
|
+
if (!uiSeen) add(1, `missing \`${UI_SEQUENCE_TOKEN}\` section`);
|
|
385
|
+
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');
|
|
386
|
+
if (contractSeen > 1) addContract(h2.find(({ l }) => DATA_CONTRACT_NAME.test(l.replace(/^##\s+/, '').trim()))!.i + 1, 'the `## 数据契约` section may appear at most once');
|
|
387
|
+
if (!scenarioSeen) add(1, 'missing scenario section');
|
|
388
|
+
if (contractSections.length > 0) out.push(...checkDataContract(lines, contractSections[0]!));
|
|
244
389
|
|
|
245
390
|
// The provenance section is optional (batch mode and a lost draft have none),
|
|
246
391
|
// but when present it must actually carry the bullets it exists for.
|
|
@@ -418,6 +563,115 @@ function checkTraceRefs(lines: string[]): Finding[] {
|
|
|
418
563
|
return out;
|
|
419
564
|
}
|
|
420
565
|
|
|
566
|
+
/** State space — the fallback half of a state machine.
|
|
567
|
+
*
|
|
568
|
+
* A screen has a finite set of states. A spec that closes with "otherwise nothing
|
|
569
|
+
* updates" makes every state it does not name legal, which is how initial frames,
|
|
570
|
+
* empty data and non-default locales disappear from a published SPEC: the sentence
|
|
571
|
+
* is true for every omission. The catch-all wording is an error; one overview that
|
|
572
|
+
* merges two states into a single "no change" result is a warning, because naming
|
|
573
|
+
* one state's no-op is honest and naming two is not. */
|
|
574
|
+
const CATCH_ALL = /(否则|其余情况|其他情况|以上情况之外)[^。;\n]{0,12}(不发生|不更新|不产生|不显示)/;
|
|
575
|
+
const MERGED_STATE = /或[^。;\n]{0,30}(为空|失败|不是成功)/;
|
|
576
|
+
const NO_CHANGE = /不发生更新|不产生可见变化|不发生变化/;
|
|
577
|
+
|
|
578
|
+
function checkStateSpace(lines: string[]): Finding[] {
|
|
579
|
+
const out: Finding[] = [];
|
|
580
|
+
let inOverview = false;
|
|
581
|
+
lines.forEach((text, i) => {
|
|
582
|
+
if (/^###\s+/.test(text)) {
|
|
583
|
+
inOverview = /场景概述|Scenario overview/i.test(text);
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
const catchAll = CATCH_ALL.exec(text);
|
|
587
|
+
if (catchAll) {
|
|
588
|
+
out.push({
|
|
589
|
+
level: 'error',
|
|
590
|
+
rule: 'state-space(No-Catch-All)',
|
|
591
|
+
line: i + 1,
|
|
592
|
+
text: catchAll[0].slice(0, 60),
|
|
593
|
+
note: `"${catchAll[0]}" makes every state it does not name legal; give each state its own scenario, or state the source's no-op for that one state`,
|
|
594
|
+
});
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
if (!inOverview || !MERGED_STATE.test(text) || !NO_CHANGE.test(text)) return;
|
|
598
|
+
out.push({
|
|
599
|
+
level: 'warn',
|
|
600
|
+
rule: 'state-space(Merged-States)',
|
|
601
|
+
line: i + 1,
|
|
602
|
+
text: text.slice(0, 60),
|
|
603
|
+
note: 'this overview merges two states into one "no change" result; split them so each state names its own visible outcome',
|
|
604
|
+
});
|
|
605
|
+
});
|
|
606
|
+
return out;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/** The state list: one row per state, each row a visible result.
|
|
610
|
+
*
|
|
611
|
+
* A page flow that does not enumerate its states closes with a catch-all; that is
|
|
612
|
+
* how the first frame, empty data and a non-default locale disappear. Required for
|
|
613
|
+
* page flows (`requireStateList`), optional elsewhere; whenever the section exists
|
|
614
|
+
* its shape is judged. */
|
|
615
|
+
function checkStateList(lines: string[], required: boolean): Finding[] {
|
|
616
|
+
const out: Finding[] = [];
|
|
617
|
+
const start = lines.findIndex((line) => STATE_LIST_NAME.test(line.replace(/^##\s+/, '').trim()));
|
|
618
|
+
if (start < 0) {
|
|
619
|
+
if (required) {
|
|
620
|
+
out.push({
|
|
621
|
+
level: 'error',
|
|
622
|
+
rule: 'state-space(State-List)',
|
|
623
|
+
line: 1,
|
|
624
|
+
text: '',
|
|
625
|
+
note: 'a page-flow SPEC must carry `## 状态清单` between `## UI序列` and the first scenario: one row per state, never a catch-all',
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
return out;
|
|
629
|
+
}
|
|
630
|
+
let end = lines.length;
|
|
631
|
+
for (let i = start + 1; i < lines.length; i += 1) {
|
|
632
|
+
if (/^##\s+/.test(lines[i])) { end = i; break; }
|
|
633
|
+
}
|
|
634
|
+
const labels = new Set<string>();
|
|
635
|
+
let rows = 0;
|
|
636
|
+
for (let i = start + 1; i < end; i += 1) {
|
|
637
|
+
const line = lines[i];
|
|
638
|
+
if (line.trim() === '') continue;
|
|
639
|
+
const row = STATE_ROW.exec(line);
|
|
640
|
+
if (!row) {
|
|
641
|
+
out.push({ level: 'error', rule: 'state-space(State-List)', line: i + 1, text: line.trim().slice(0, 60), note: 'every state row must read `- <state>:<what the user sees>`' });
|
|
642
|
+
continue;
|
|
643
|
+
}
|
|
644
|
+
rows += 1;
|
|
645
|
+
const label = row[1].trim();
|
|
646
|
+
labels.add(label.toLowerCase());
|
|
647
|
+
const value = row[2].trim();
|
|
648
|
+
if (value === '') {
|
|
649
|
+
out.push({ level: 'error', rule: 'state-space(State-List)', line: i + 1, text: line.trim().slice(0, 60), note: 'an empty state cell is an unwritten state: write the visible result, or `不适用(reason)`' });
|
|
650
|
+
continue;
|
|
651
|
+
}
|
|
652
|
+
const catchAll = CATCH_ALL.exec(value);
|
|
653
|
+
if (catchAll) {
|
|
654
|
+
out.push({ level: 'error', rule: 'state-space(State-List)', line: i + 1, text: catchAll[0].slice(0, 60), note: 'the row must name its own visible result; a catch-all makes every state it does not name legal' });
|
|
655
|
+
}
|
|
656
|
+
if (NOT_APPLICABLE.test(value)) {
|
|
657
|
+
const reason = value.replace(NOT_APPLICABLE, '').replace(/^[\s((::]+|[\s))]+$/g, '');
|
|
658
|
+
if (reason.length < 2) {
|
|
659
|
+
out.push({ level: 'error', rule: 'state-space(State-List)', line: i + 1, text: line.trim().slice(0, 60), note: '`不适用` needs a reason: say why this page cannot reach the state' });
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
if (rows === 0) {
|
|
664
|
+
out.push({ level: 'error', rule: 'state-space(State-List)', line: start + 1, text: lines[start].trim().slice(0, 60), note: 'the state list is empty' });
|
|
665
|
+
return out;
|
|
666
|
+
}
|
|
667
|
+
if (!required) return out;
|
|
668
|
+
for (const { key, labels: names } of STATE_KEYS) {
|
|
669
|
+
if (names.some((name) => labels.has(name.toLowerCase()))) continue;
|
|
670
|
+
out.push({ level: 'error', rule: 'state-space(State-List)', line: start + 1, text: lines[start].trim().slice(0, 60), note: `the state list has no row for \`${key}\`; add the row, or write \`${key}:不适用(reason)\`` });
|
|
671
|
+
}
|
|
672
|
+
return out;
|
|
673
|
+
}
|
|
674
|
+
|
|
421
675
|
function checkLineReferences(lines: string[]): Finding[] {
|
|
422
676
|
const out: Finding[] = [];
|
|
423
677
|
lines.forEach((text, i) => {
|
|
@@ -432,7 +686,7 @@ function checkLineReferences(lines: string[]): Finding[] {
|
|
|
432
686
|
* Runs every decidable check on raw spec text and returns findings sorted by line number.
|
|
433
687
|
* Pure function: no file reads, no printing, no process.exit — for in-process reuse.
|
|
434
688
|
*/
|
|
435
|
-
export function checkSpecText(text: string): Finding[] {
|
|
689
|
+
export function checkSpecText(text: string, options: { requireStateList?: boolean } = {}): Finding[] {
|
|
436
690
|
const lines = text.split(/\r?\n/);
|
|
437
691
|
const findings: Finding[] = [
|
|
438
692
|
...checkStructure(lines),
|
|
@@ -442,6 +696,8 @@ export function checkSpecText(text: string): Finding[] {
|
|
|
442
696
|
...lineScan(lines, CONTRACT_PATTERNS, 'error', 'interface-contract(Principle 7)', 'spec does not define interface contracts'),
|
|
443
697
|
...lineScan(lines, VAGUE_PATTERNS, 'warn', 'vague-wording(No-Vagueness)', 'replace with a concrete value'),
|
|
444
698
|
...checkPlaceholders(lines),
|
|
699
|
+
...checkStateSpace(lines),
|
|
700
|
+
...checkStateList(lines, Boolean(options.requireStateList)),
|
|
445
701
|
...checkTraceRefs(lines),
|
|
446
702
|
...checkLineReferences(lines),
|
|
447
703
|
];
|
|
@@ -143,7 +143,16 @@ const FUSED_RULES = `### 融合草稿规则(R1–R5、R7、R8 由 check-fusion
|
|
|
143
143
|
但属于未完成任务。
|
|
144
144
|
- **R6a 展示值派生(必需)**:每个数值/文案字段都必须写出来源与派生,不允许只写展示结果。至少
|
|
145
145
|
覆盖:来源字段、时间窗口(如 24 小时、当天、15 分钟序列前 24 点)、聚合(max/min/取整)、
|
|
146
|
-
符号(\`绝对值\`
|
|
146
|
+
符号(\`绝对值\` 或带符号)、单位换算。规则必须唯一确定一个结果:运算顺序(先取整再相减 / 先
|
|
147
|
+
相减再取整)、取整方式(四舍五入、截断、负半值)、时间基准(最近槽位还是向下取整、哪个时区)
|
|
148
|
+
会给出不同数字的,必须写出该选择;每个派生数值字段给一个算式示例(具体输入 → 具体输出),
|
|
149
|
+
写不出示例或示例与规则不符,回源码重写。字段逐个列出,不得用“每条记录/每个值”概括。
|
|
150
|
+
一个流程内的共享派生规则写一次,后续字段引用它。
|
|
151
|
+
- **R6b 状态空间(必需)**:页面流程 SPEC 在 \`## UI序列\` 之后、第一个场景之前写 \`## 状态清单\`,
|
|
152
|
+
逐行 \`- <情况>:<用户看到什么>\`。八种情况每种一行,一个不能少:首帧、加载中、成功、数据为空、
|
|
153
|
+
数据不足、失败、非默认语言、离开后重新进入;本页面到不了的情况写 \`- 加载中:不适用(理由)\`,
|
|
154
|
+
理由不能空。值写该状态下用户看到的结果,或“保持上一次成功数据的显示”,不许写“否则不发生更新”。
|
|
155
|
+
首帧与非默认语言写资源/布局里的实际字面量。
|
|
147
156
|
- **R7 SPEC 唯一性(check-fusion 机械校验)**:\`owner.kind="area"\` 可以有**多份**(页面 owner 按
|
|
148
157
|
用户可见流程拆分,如 eco 的一个页批次写多份 SPEC);每个 \`controlGroup\`/\`discovery\` 至多一条
|
|
149
158
|
\`specRecord\`(重复会失败——合并为一份 SPEC);\`agent-added\` 数量不限(stem 仍须唯一)。
|
|
@@ -389,6 +398,7 @@ const SPEC_RESIDENT_REQUIRED_SECTIONS = [
|
|
|
389
398
|
["## Principles"],
|
|
390
399
|
["## UI序列规则", "## UI Sequence Rules"],
|
|
391
400
|
["## 写盘与正文形状", "## File Write and Body Shape"],
|
|
401
|
+
["## 数据契约规则", "## Data Contract Rules"],
|
|
392
402
|
["## Forbidden"]
|
|
393
403
|
] as const;
|
|
394
404
|
|
|
@@ -478,7 +488,7 @@ export function residentRuleSections(
|
|
|
478
488
|
*/
|
|
479
489
|
export function fusedSpecSection(specSkillDir: string): string {
|
|
480
490
|
const { featureStem } = specCommands(specSkillDir);
|
|
481
|
-
return `### C. 产出 SPEC\n\n采用 **eco 式页面 owner**:本 Area 是一个页面,但**一份 SPEC 对应一个用户可见流程**,不是一张\n卡片或一个展示面。流程按“取数 → 派生 → 展示 → 保存/恢复”划分,例如“下拉刷新”“选择温度单位”\n“搜索地点”;一个流程覆盖跨控件的数据来源、派生规则、异常/空态和生命周期。一个页批次通常 1–6 份\nSPEC;不要把每个 Control 机械拆成独立 SPEC,也不要只写一份大 SPEC 把可独立测试的功能压扁。\n只有某个局部交互需要独立绑定时,才额外产出 \`controlGroup\`/\`discovery\` SPEC。area-owned SPEC\n不对应单一 Control,发布时不注入 \`控件:\` 行;只有局部细拆的 SPEC 才绑定单个 controlRef。\n\n**必须提供 \`dataFlow\` 数据契约账本**:每份 area-owned SPEC 恰好一行,写出 \`entry\`(用户入口)、\n\`sources\`(请求地址/存储键/定位来源/设置项)、\`transforms\`(窗口、聚合、取整、符号、单位换算)、\n\`displays\`(用户可见字段),有写入/恢复时写 \`persistence\`。账本是 R8 的机器校验依据;缺行、\n悬空 \`specStem\`、重复 \`flowKey\` 都会失败。\n\n**必须提供 \`pageCoverage\` 覆盖账本**:本 Area 的每个 \`controlGroup\`/\`discovery\` 恰好一行;\n\`covered\` 行必须写出它归属的 \`specStem\`(该 stem 必须在 \`specs[]\` 中存在),\`excluded\`\n行必须写出 reason。账本是 L1 的覆盖指派表,也是 R4 的机器校验依据;缺项、重复项、指向不存在\n的 stem 都会导致门禁失败。L2 会把账本投影成 \`spec-bindings.json\` 中每份 area SPEC 的\n\`controlRefs[]\`,发布面据此恢复控件覆盖关系。\n\n9. **写 SPEC 文件**:在**本任务目录**的 \`specs/<stem>-SPEC.md\` 写一份 SPEC,\`## UI序列\`\n 单行**逐字等于**该条 \`specs[].title\`。SPEC 正文遵循 specgen 的写作规则(\`## 门禁清单\` 按需\n 读):H1 逐字为 \`# <stem>SPEC\`;局部 controlGroup/discovery SPEC 的身份行 \`控件:<controlRef>\`\n 由脚本铸造(你只提交锚点,R1),area-owned SPEC 不注入该行;\n 需求语义描述;\`## UI
|
|
491
|
+
return `### C. 产出 SPEC\n\n采用 **eco 式页面 owner**:本 Area 是一个页面,但**一份 SPEC 对应一个用户可见流程**,不是一张\n卡片或一个展示面。流程按“取数 → 派生 → 展示 → 保存/恢复”划分,例如“下拉刷新”“选择温度单位”\n“搜索地点”;一个流程覆盖跨控件的数据来源、派生规则、异常/空态和生命周期。一个页批次通常 1–6 份\nSPEC;不要把每个 Control 机械拆成独立 SPEC,也不要只写一份大 SPEC 把可独立测试的功能压扁。\n只有某个局部交互需要独立绑定时,才额外产出 \`controlGroup\`/\`discovery\` SPEC。area-owned SPEC\n不对应单一 Control,发布时不注入 \`控件:\` 行;只有局部细拆的 SPEC 才绑定单个 controlRef。\n\n**必须提供 \`dataFlow\` 数据契约账本**:每份 area-owned SPEC 恰好一行,写出 \`entry\`(用户入口)、\n\`sources\`(请求地址/存储键/定位来源/设置项)、\`transforms\`(窗口、聚合、取整、符号、单位换算)、\n\`displays\`(用户可见字段),有写入/恢复时写 \`persistence\`。账本是 R8 的机器校验依据;缺行、\n悬空 \`specStem\`、重复 \`flowKey\` 都会失败。\n\n**必须提供 \`pageCoverage\` 覆盖账本**:本 Area 的每个 \`controlGroup\`/\`discovery\` 恰好一行;\n\`covered\` 行必须写出它归属的 \`specStem\`(该 stem 必须在 \`specs[]\` 中存在),\`excluded\`\n行必须写出 reason。账本是 L1 的覆盖指派表,也是 R4 的机器校验依据;缺项、重复项、指向不存在\n的 stem 都会导致门禁失败。L2 会把账本投影成 \`spec-bindings.json\` 中每份 area SPEC 的\n\`controlRefs[]\`,发布面据此恢复控件覆盖关系。\n\n9. **写 SPEC 文件**:在**本任务目录**的 \`specs/<stem>-SPEC.md\` 写一份 SPEC,\`## UI序列\`\n 单行**逐字等于**该条 \`specs[].title\`。SPEC 正文遵循 specgen 的写作规则(\`## 门禁清单\` 按需\n 读):H1 逐字为 \`# <stem>SPEC\`;局部 controlGroup/discovery SPEC 的身份行 \`控件:<controlRef>\`\n 由脚本铸造(你只提交锚点,R1),area-owned SPEC 不注入该行;\n 需求语义描述;\`## UI序列\`;\`## 数据契约\`(每个外部字段写出 \`字段\`/\`类型\`/\`字节长度\`/\`取值域\`/\`样例\`/\`语义来源\`,无外部数据时写「不涉及外部数据」);\`## 状态清单\`(页面流程,见第 16 条);然后是原子场景。**SPEC 正文只存在于 SPEC 文件,绝不写进\n \`output.json\`。**\n10. **title 规则**:\`title\` 用中文功能标题(含页面/入口定位感),并**逐字等于**该 SPEC 的\n \`## UI序列\` 行。\n11. **stem 必须用 CLI 铸造,不得手写 sanitize**:对该条 \`title\` 跑\n \`node ${JSON.stringify(featureStem)} "<title>"\`,把打印出来的 stem 原样用作文件名。若本任务\n \`specs/\` 下已存在同名 \`<stem>-SPEC.md\`,按本任务内的产出顺序追加 \`-2\`、\`-3\`…;\`stem\` 在\n \`output.json.specs[]\` 内必须唯一。手写 sanitize 会让 \`check-fused-spec\` 的 canonical-stem\n 校验失败。\n12. **按流程切 SPEC 并加 \`specs[]\` 记录**:形状即「输出契约」里的 \`SpecRecord\`。一个流程\n (取数→派生→展示→保存)对应一份 \`owner: { kind: "area" }\` SPEC;不要把同一流程拆到多份\n SPEC。只有局部独立绑定时才额外加 \`controlGroup\`/\`discovery\` 记录,各自至多一条。\n \`agent-added\` 展示类 SPEC 自带 \`identityAnchors\`(\`control\` 必填)且\n \`disposition:"added"\`。本任务为**必需**字段。\n13. **写 \`dataFlow\` 数据契约账本**:每份 area-owned SPEC 恰好一行,写出 \`entry\`、≥1 个\n \`sources\`、≥1 条 \`transforms\`、≥1 个 \`displays\`,有写入/恢复时写 \`persistence\`。\n \`specStem\` 必须存在于 \`specs[]\`。R8 以此为准;缺行、悬空 stem、重复 \`flowKey\` 都会失败。\n14. **写 \`pageCoverage\` 账本**:本 Area 的每个 \`controlGroup\`/\`discovery\` 恰好一行;\`covered\`\n 必须给出 \`specStem\`(存在于 \`specs[]\`),\`excluded\` 必须给出 \`reason\`。R4 以此为准。\n15. **展示值派生(R6a)**:每个数值/文案字段写出来源字段、时间窗口、聚合、取整、符号、单位换算;\n 不允许只写“显示 N”或“差值整数”。规则必须唯一确定结果:运算顺序、取整方式(含负半值)、\n 时间基准(最近槽位/向下取整、时区)换一种读法会得到不同数字的,必须写出该选择;每个派生\n 数值字段给一个算式示例(具体输入 → 具体输出)。字段逐个列出,不得用“每条记录”概括。\n 共享派生规则在一个流程内写一次,后续字段引用。\n16. **状态空间(R6b)**:页面流程 SPEC 在 \`## 数据契约\` 之后、第一个场景之前写 \`## 状态清单\`,\n 逐行 \`- <情况>:<用户看到什么>\`,八种情况一行一个,一个不能少:首帧、加载中、成功、数据\n 为空、数据不足、失败、非默认语言、离开后重新进入。到不了的写 \`- 加载中:不适用(理由)\`,\n 理由不能空;值写具体结果或“保持上一次成功数据的显示”,不许写“否则不发生更新”。首帧与\n 非默认语言写资源/布局里的实际字面量。\n17. **展示类 SPEC 完备性(R6)是必需步骤,不是可选项**:按输出契约中 R6 的定义,对本 Area\n 渲染/展示出来的数据做一次源码复核;凡源码能证明、用户可见且未被任何 SPEC 覆盖的展示行为,\n 补 \`owner.kind="agent-added"\` 的 \`specRecord\` 及对应 SPEC 文件(自带 identityAnchors、\n ≥1 条可核对 citation、\`disposition:"added"\`)。交互面为空时也不例外。\n18. **显式不出 SPEC**:某 Control/discovery 本轮确实不应生成独立 SPEC 时,在\n \`pageCoverage\` 里用 \`disposition:"excluded"\` 和 reason 记账;旧式\n \`renderConfirmations\` 仅在未提供账本时使用。\n19. **正文边界**:SPEC 正文不得出现 Android/UniApp/Compose 等框架名、\`file:line\` 锚点、源码\n 符号、占位符或含糊措辞(R5 同适用),也不写界面视觉细节;不得把 unresolved 字段升格为确定\n 事实,需要保留但源码不可确定的内容照实省略。**不要**手写 \`控件:\` 行或 \`controlRef\`。\n20. 单份 SPEC 可用 \`check_spec\` 自检(命令见「输出与校验」的 SPEC 命令);整任务的自检命令\n 同时覆盖融合草稿与全部 SPEC。`;
|
|
482
492
|
}
|
|
483
493
|
|
|
484
494
|
/** 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. **写 SPEC 文件**");
|
|
342
|
+
const end = md.indexOf("10. **title 规则**", 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序列");
|
|
346
|
+
const contract = step.indexOf("## 数据契约");
|
|
347
|
+
assert.ok(ui >= 0, "the step must name `## UI序列`");
|
|
348
|
+
assert.ok(contract >= 0, "the step must name `## 数据契约`");
|
|
349
|
+
assert.ok(ui < contract, "the template must put `## UI序列` before `## 数据契约`; check_spec rejects the reverse order");
|
|
350
|
+
assert.ok(contract < step.indexOf("原子场景"), "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序列规则\nu\n## 写盘与正文形状\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序列规则\nu\n## 写盘与正文形状\nw\n## 数据契约规则\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"]];
|
|
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: ## 步骤纪律$/u);
|
|
@@ -26,6 +26,9 @@ function cleanSpec(stem, title) {
|
|
|
26
26
|
"## UI序列",
|
|
27
27
|
title,
|
|
28
28
|
"",
|
|
29
|
+
"## 数据契约",
|
|
30
|
+
"不涉及外部数据",
|
|
31
|
+
"",
|
|
29
32
|
"## 场景一",
|
|
30
33
|
"- 1. 用户打开开关后保存该状态",
|
|
31
34
|
""
|
|
@@ -40,6 +43,9 @@ function dpViolatingSpec(stem, title) {
|
|
|
40
43
|
"## UI序列",
|
|
41
44
|
title,
|
|
42
45
|
"",
|
|
46
|
+
"## 数据契约",
|
|
47
|
+
"不涉及外部数据",
|
|
48
|
+
"",
|
|
43
49
|
"## 场景一",
|
|
44
50
|
"- 1. 按钮宽度 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("开关默认关闭", "开关默认关闭")] }, 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序列: this fixture has content violations only.
|
|
160
166
|
assert.deepEqual(findings.filter((f) => f.rule === "SPEC naming" || f.rule === "SPEC UI序列"), []);
|
|
@@ -168,6 +174,9 @@ function specWithBody(stem, title, body) {
|
|
|
168
174
|
"## UI序列",
|
|
169
175
|
title,
|
|
170
176
|
"",
|
|
177
|
+
"## 数据契约",
|
|
178
|
+
"不涉及外部数据",
|
|
179
|
+
"",
|
|
171
180
|
"## 场景一",
|
|
172
181
|
body,
|
|
173
182
|
""
|
|
@@ -188,7 +197,7 @@ test("an easing curve name still fails through the shared check_spec rules", ()
|
|
|
188
197
|
const findings = checkDraftSpecs({ specs: [record("设置滑入曲线", "设置滑入曲线")] }, taskDir);
|
|
189
198
|
const view = findings.find((f) => f.level === "error" && f.rule === "UI-view-description(Principle 10)");
|
|
190
199
|
assert.ok(view, "the curve name must be flagged by the shared check_spec rules");
|
|
191
|
-
assert.equal(view.line,
|
|
200
|
+
assert.equal(view.line, 10);
|
|
192
201
|
assert.equal(view.text, "accelerate_decelerate");
|
|
193
202
|
});
|
|
194
203
|
|
|
@@ -797,6 +806,9 @@ function cleanSpecEn(stem, title) {
|
|
|
797
806
|
"## UI Sequence",
|
|
798
807
|
title,
|
|
799
808
|
"",
|
|
809
|
+
"## Data Contract",
|
|
810
|
+
"No external data",
|
|
811
|
+
"",
|
|
800
812
|
"## Scenario 1",
|
|
801
813
|
"- 1. The user turns the switch on and the state is saved",
|
|
802
814
|
""
|
|
@@ -850,7 +862,7 @@ test("en: a `### Deviations from Requirement` section is rejected like `### 与
|
|
|
850
862
|
const deviation = findings.find((f) => f.rule === "SPEC deviation section");
|
|
851
863
|
assert.ok(deviation, "an English deviation H3 section must be flagged");
|
|
852
864
|
assert.equal(deviation.level, "error");
|
|
853
|
-
assert.equal(deviation.line,
|
|
865
|
+
assert.equal(deviation.line, 12);
|
|
854
866
|
// case / plural variants are no bypass either
|
|
855
867
|
const variant = cleanSpecEn("开关默认关闭", "开关默认关闭") + "\n## Deviations From Requirements\n- x\n";
|
|
856
868
|
writeSpec(taskDir, "开关默认关闭-SPEC.md", variant);
|
|
@@ -877,3 +889,42 @@ test("en: a marker on an empty `## Scenario N` body fails", () => {
|
|
|
877
889
|
const findings = checkDraftSpecs(draft, taskDir);
|
|
878
890
|
assert.ok(findings.some((item) => item.note.includes("empty")), JSON.stringify(findings));
|
|
879
891
|
});
|
|
892
|
+
|
|
893
|
+
// ---- Page flow: counted by state, not by card ---------------------------------
|
|
894
|
+
|
|
895
|
+
/** A page-flow SPEC that carries the eight state rows R6b requires. */
|
|
896
|
+
function pageFlowSpec(stem, title) {
|
|
897
|
+
return [
|
|
898
|
+
`# ${stem}SPEC`, "", "## UI序列", title, "",
|
|
899
|
+
"## 数据契约", "不涉及外部数据", "",
|
|
900
|
+
"## 状态清单", "",
|
|
901
|
+
"- 首帧:显示占位文案",
|
|
902
|
+
"- 加载中:显示刷新指示",
|
|
903
|
+
"- 成功:按场景一展示",
|
|
904
|
+
"- 数据为空:列表保持为空",
|
|
905
|
+
"- 数据不足:展示已返回的条目",
|
|
906
|
+
"- 失败:弹出错误提示",
|
|
907
|
+
"- 非默认语言:文案显示翻译后的文本",
|
|
908
|
+
"- 离开后重新进入:恢复上一次的数据",
|
|
909
|
+
"", "## 场景一", "- 1. 用户进入页面后展示数据", "",
|
|
910
|
+
].join("\n");
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
test("an area-owned SPEC without a state list fails: a page flow is counted by state, not by card", () => {
|
|
914
|
+
const taskDir = tmp();
|
|
915
|
+
writeSpec(taskDir, "天气页-SPEC.md", cleanSpec("天气页", "天气页"));
|
|
916
|
+
const draft = { specs: [{ ...record("天气页", "天气页"), owner: { kind: "area" } }] };
|
|
917
|
+
const findings = checkDraftSpecs(draft, taskDir);
|
|
918
|
+
assert.ok(
|
|
919
|
+
findings.some((f) => f.rule === "state-space(State-List)" && f.level === "error"),
|
|
920
|
+
JSON.stringify(findings)
|
|
921
|
+
);
|
|
922
|
+
});
|
|
923
|
+
|
|
924
|
+
test("an area-owned SPEC with all eight state rows passes the state-list rule", () => {
|
|
925
|
+
const taskDir = tmp();
|
|
926
|
+
writeSpec(taskDir, "天气页-SPEC.md", pageFlowSpec("天气页", "天气页"));
|
|
927
|
+
const draft = { specs: [{ ...record("天气页", "天气页"), owner: { kind: "area" } }] };
|
|
928
|
+
const findings = checkDraftSpecs(draft, taskDir).filter((f) => f.rule === "state-space(State-List)");
|
|
929
|
+
assert.deepEqual(findings, []);
|
|
930
|
+
});
|