Jelajahi Sumber

feat: naturalize CPLD teaching prose

Codex 5 bulan lalu
induk
melakukan
d622fa6e3b

+ 20 - 12
docs/cpld-html-teaching-requirements.zh-CN.md

@@ -1,30 +1,36 @@
 # CPLD 交互式 HTML 教学文档要求
 # CPLD 交互式 HTML 教学文档要求
 
 
-本文档是 `C:\Users\Administration\CodexWorkspaces\CPLD` 的 CPLD 教学 HTML 专用规格。目标不是规定一种死板版式,而是保证 13 章内容能把工程事实、源码行为、板级现象和验证动作讲透。
+本文档是 `C:\Users\Administration\CodexWorkspaces\CPLD` 的 CPLD 教学 HTML 专用规范。目标不是规定一种死板版式,而是保证 13 章内容能把工程事实、源码行为、板级现象、工具报告和验证动作讲透。
 
 
 ## 目标
 ## 目标
 
 
-输出 13 个单文件交互式 HTML,覆盖 `C:\Users\Administration\Downloads\cpld_ch*_learning_report_v1.html`。读者定位是“零基础到下板”:先建立硬件、Verilog、TD 工具和 I2C 的基本心智模型,再进入本工程源码、仿真、约束、UART/PID、温控集成和烧写排障。
+输出 13 个单文件交互式 HTML,覆盖 `C:\Users\Administration\Downloads\cpld_ch*_learning_report_v1.html`。读者定位是“零基础到下板”:先建立硬件、Verilog、TD 工具和 I2C 的基础心智模型,再进入本工程源码、仿真、约束、UART/PID、温控集成和烧写排障。
 
 
 ## 内容原则
 ## 内容原则
 
 
-- 每个专节都必须讲清一个完整知识点的来龙去脉:现场会看到什么、为什么会这样设计、硬件或工具内部怎样工作、错了会导致什么、应该如何验证、失败时下一步查哪里。
-- 上述要素是写作质量要求,不是页面结构模板。不要把“现象 / 前因 / 机制 / 后果 / 验证 / Runbook”机械拆成固定六个卡片,也不要生成十段换标题的模板文。
-- 推荐写法是自然讲解为主,辅以证据旁栏、Runbook、表格、SVG、交互工具和术语 tooltip。读者读起来应像工程师在带他分析一个真实问题,而不是在填表。
+- 每个专节都必须讲清一个完整知识点的来龙去脉:现场会看到什么、为什么这样设计、硬件或工具内部怎样工作、错了会导致什么、应该如何验证、失败时下一步查哪里。
+- 上述要素是写作质量要求,不是页面结构模板。不要把“现象 / 前因 / 机制 / 后果 / 验证 / Runbook”机械拆成固定六张卡片,也不要生成十段换标题的模板文。
+- 推荐写法是以自然讲解为主,辅以证据旁栏、Runbook、表格、SVG、交互工具和术语 tooltip。读者读起来应像工程师在带他分析一个真实问题,而不是在填表。
 - 每章至少 4 个专节;每个专节至少一个明确工程锚点。锚点可以是源码文件、参数、日志现象、手册条目、约束文件、TD 报告或板级连接要求。
 - 每章至少 4 个专节;每个专节至少一个明确工程锚点。锚点可以是源码文件、参数、日志现象、手册条目、约束文件、TD 报告或板级连接要求。
 - 允许由浅入深解释基础概念,但必须最终落回“我在这块板、这个 TD 工程、这些 Verilog 文件里应该怎么验证”。
 - 允许由浅入深解释基础概念,但必须最终落回“我在这块板、这个 TD 工程、这些 Verilog 文件里应该怎么验证”。
-- 自然化不等于减少细节。每章必须有“从浅到深的学习阶梯”和“本章知识系统”:前者说明零基础读者先抓哪一个现象、再进入哪一层机制、最后扩展到哪个系统问题;后者说明专业知识之间的关系,例如工具层、RTL 层、协议层、电气层、仿真层、约束层、控制算法层和排障层。
-- 扩展内容必须成体系,不能把额外术语撒在正文里。新增一个专业知识点时,要同时说明它服务的现场问题、依赖的前置概念、影响的后续章节、可验证的工程锚点,以及不掌握它会导致的误判。
-- 每个专节应有自然的学习线索:先用工程锚点定事实边界,再解释机制,再做最小验证,最后说明它如何连接到本章知识系统或后续章节。这个线索可以写成自然段或旁注,但不能变成固定六宫格。
 - 禁止跨章乱入无关术语。I2C 章节不得泛泛讲 PID/DSP;PID 章节不得用 I2C 模板填充;烧写章节不得用 RTL 状态机替代线缆、电源、VREF、CRC 和设备识别。
 - 禁止跨章乱入无关术语。I2C 章节不得泛泛讲 PID/DSP;PID 章节不得用 I2C 模板填充;烧写章节不得用 RTL 状态机替代线缆、电源、VREF、CRC 和设备识别。
 
 
+## 自然化与体系化
+
+- 自然化不是减少细节,也不是口语化糊弄。每个专节应有连续讲解:先用本工程现象定入口,再解释设计前因,再拆机制,再落到验证和排障,最后说明它在本章知识系统和后续章节中的位置。
+- 结构化源文件可以保留 `beginner_entry`、`engineering_story`、`mechanism_walkthrough`、`verification_story`、`system_extension` 这类审稿字段,但 HTML 正文不应把它们机械显示成五宫格或固定模板。页面应优先呈现为自然段、证据栏、Runbook、表格、SVG 和交互工具的组合。
+- 禁止用可复制到任意章节的元话术撑篇幅,例如“讨论某某时”“读者真正会遇到的不是抽象名词”“顺着这个点往下学”“放进系统里看”“讲解时可以采用一个很小的实验”“本节的交付标准是”“问题链自问”“最小复述标准”。如果一句话换掉标题仍然成立,通常就不是合格正文。
+- 扩展内容必须成体系。新增一个专业知识点时,要同时说明它的前置概念、所在层级、影响的后续章节、可验证锚点和误判后果。
+- 由浅入深要体现在知识递进,而不是标题递进。零基础入口可以从“会看到什么现象”开始,但必须逐步推进到源码行、状态机、工具报告、线缆/电气条件、仿真波形或板级验证。
+- 专业体系要能闭环。例如 SCL 分频要连接 25MHz/50MHz 时钟事实、4 相计数、波形周期测量和 control FSM 的字节节拍;PID 时分复用要连接 24 通道、3 DSP、sample_tick、done、限幅和后续执行器映射。
+
 ## 必须覆盖的事实锚点
 ## 必须覆盖的事实锚点
 
 
-- `i2c_bit_shift.v`:开漏 SDA 只拉低不驱高;`SCL_CNT_M = SYS_CLOCK / SCL_CLOCK / 4 - 1`;当前参数是 25MHz 到 100kHz;写/读 ACK 都按 4 相计数推进。
+- `i2c_bit_shift.v`:开漏 SDA 只拉低不驱高;`SCL_CNT_M = SYS_CLOCK / SCL_CLOCK / 4 - 1`;当前参数是 25MHz 到 100kHz;写/读/ACK 都按 4 相计数推进。
 - `i2c_control.v`:`addr_mode=0` 会把 `addr` 高低字节交换;`ack <= ack | ack_o` 汇总任意阶段 NACK;读流程先写寄存器地址,再 repeated START 切到读方向。
 - `i2c_control.v`:`addr_mode=0` 会把 `addr` 高低字节交换;`ack <= ack | ack_o` 汇总任意阶段 NACK;读流程先写寄存器地址,再 repeated START 切到读方向。
 - `iic_top.v`:顶层注释写 50MHz,但子模块参数写 25MHz,这是必须被教学化的勘误点;当前 bit 不是完整温控系统,而是周期性 I2C 写 EEPROM demo。
 - `iic_top.v`:顶层注释写 50MHz,但子模块参数写 25MHz,这是必须被教学化的勘误点;当前 bit 不是完整温控系统,而是周期性 I2C 写 EEPROM demo。
 - `test_pid.v`:24 通道增量式 PID、三个 DSP 并行乘法、通道时分复用、历史误差寄存器、限幅与回写。
 - `test_pid.v`:24 通道增量式 PID、三个 DSP 并行乘法、通道时分复用、历史误差寄存器、限幅与回写。
-- `iic.adc` 和 `uart.adc`:引脚、IOSTANDARD、PULLTYPE、DRIVESTRENGTH;现有 `anchor_index.zh-CN.md` 中记录的约束与综合/报告引脚差异必须提示为版本迁移风险。
+- `iic.adc` 和 `uart.adc`:引脚、IOSTANDARD、PULLTYPE、DRIVESTRENGTH;现有锚点索引记录的约束与综合/报告引脚差异必须提示为版本迁移风险。
 - TD 手册下载流程:生成位流后进入 Download、Add 位流、Run 下载;速度 90Kbps 到 3Mbps;成功提示;`No hardware` 与 `USB Cable is connected` 的不同含义;芯片 ID 和 CRC 校验。
 - TD 手册下载流程:生成位流后进入 Download、Add 位流、Run 下载;速度 90Kbps 到 3Mbps;成功提示;`No hardware` 与 `USB Cable is connected` 的不同含义;芯片 ID 和 CRC 校验。
 - AL-Link Mini:VREF 不供电,只检测目标板电压;目标板必须独立供电;常接 6 根线 VREF/GND/TMS/TCK/TDI/TDO;10P 排线三角形是 1 脚。
 - AL-Link Mini:VREF 不供电,只检测目标板电压;目标板必须独立供电;常接 6 根线 VREF/GND/TMS/TCK/TDI/TDO;10P 排线三角形是 1 脚。
 
 
@@ -33,8 +39,8 @@
 - 单文件交付,无外部 CSS/JS/字体依赖。
 - 单文件交付,无外部 CSS/JS/字体依赖。
 - 必须包含 sticky 顶栏、阅读进度、系列导航、目录、全局术语表、tooltip、SVG/表格、跨章链接。
 - 必须包含 sticky 顶栏、阅读进度、系列导航、目录、全局术语表、tooltip、SVG/表格、跨章链接。
 - 正文结构必须避免固定模板感。每节可以使用自然段、证据旁栏、Runbook、对照表和 SVG,但不得出现固定六宫格 `causal-grid`,也不得把因果链硬拆成几张英文小标题卡片。
 - 正文结构必须避免固定模板感。每节可以使用自然段、证据旁栏、Runbook、对照表和 SVG,但不得出现固定六宫格 `causal-grid`,也不得把因果链硬拆成几张英文小标题卡片。
-- 允许使用章级学习阶梯、章级知识系统和节级学习线索,但它们必须服务阅读路径。禁止出现“本节的交付标准是……”这类所有章节都能套用的通用段落;禁止用“问题链自问”“最小复述标准”之类元话术撑篇幅。
-- `ch4/ch5` 必须包含 SCL 分频或 I2C 帧计算交互;`ch6/ch7` 必须包含写/读事务步骤交互;`ch9` 必须包含引脚约束对照;`ch11` 必须包含 PID 通道调度可视化;`ch13` 必须包含排障决策树。
+- 允许使用章级学习阶梯、章级知识系统和节级渐进旁注,但它们必须服务阅读路径。禁止出现所有章节都能套用的通用段落。
+- `ch4/ch5` 必须包含 SCL 分频或 I2C 帧计算交互;`ch6/ch7` 必须包含写/读事务步进交互;`ch9` 必须包含引脚约束对照;`ch11` 必须包含 PID 通道调度可视化;`ch13` 必须包含排障决策树。
 - 1920x945 为主验收分辨率,1280x945 不应横向溢出;移动端应保持可阅读和可点击。
 - 1920x945 为主验收分辨率,1280x945 不应横向溢出;移动端应保持可阅读和可点击。
 
 
 ## 验收
 ## 验收
@@ -46,4 +52,6 @@ C:\Users\Administration\.cache\codex-runtimes\codex-primary-runtime\dependencies
 C:\Users\Administration\.cache\codex-runtimes\codex-primary-runtime\dependencies\python\python.exe scripts\validate_cpld_teaching_html.py --dir "$env:USERPROFILE\Downloads" --json --receipt workspace\teaching_receipts\latest-validation.json
 C:\Users\Administration\.cache\codex-runtimes\codex-primary-runtime\dependencies\python\python.exe scripts\validate_cpld_teaching_html.py --dir "$env:USERPROFILE\Downloads" --json --receipt workspace\teaching_receipts\latest-validation.json
 ```
 ```
 
 
+自动校验必须检查旧模板话术、章节错配术语、每节最小深度、工程锚点、术语 tooltip、SVG/表格、交互组件、互链和无外部依赖。人工审读重点看 ch5、ch6、ch11、ch13 是否真正讲透复杂点,而不是只把旧模板换成新模板。
+
 校验通过不等于下板通过。若没有真实 TD、板卡、逻辑分析仪或串口环境,只能声明文档与当前源码、摘录和静态交互一致,不能声明硬件烧写或仿真已经通过。
 校验通过不等于下板通过。若没有真实 TD、板卡、逻辑分析仪或串口环境,只能声明文档与当前源码、摘录和静态交互一致,不能声明硬件烧写或仿真已经通过。

File diff ditekan karena terlalu besar
+ 24 - 46
scripts/generate_cpld_teaching_html.py


+ 27 - 3
scripts/validate_cpld_teaching_html.py

@@ -59,6 +59,18 @@ GENERIC_NARRATION_MARKERS = [
     "常见误判要单独拎出来",
     "常见误判要单独拎出来",
     "复盘本章时建议按下面的问题链自问",
     "复盘本章时建议按下面的问题链自问",
     "本章的最小复述标准是",
     "本章的最小复述标准是",
+    "讨论「",
+    "读者真正会遇到的不是抽象名词",
+    "这个现象要落到证据上看",
+    "顺着这个点往下学",
+    "放进系统里看",
+    "扩展学习时不要把",
+    "讲解时可以采用一个很小的实验",
+    "不要从术语背诵开始",
+    "自然串讲:从现象走到验证",
+    "工程化深挖",
+    "问题链自问",
+    "最小复述标准",
 ]
 ]
 
 
 
 
@@ -120,9 +132,13 @@ def validate_file(path: Path, chapter: dict[str, Any], glossary: dict[str, Any])
             findings.append(Finding("error", name, f"section {index} missing natural explanation flow"))
             findings.append(Finding("error", name, f"section {index} missing natural explanation flow"))
         if 'class="evidence-panel"' not in block:
         if 'class="evidence-panel"' not in block:
             findings.append(Finding("error", name, f"section {index} missing evidence panel"))
             findings.append(Finding("error", name, f"section {index} missing evidence panel"))
-        if 'class="section-thread"' not in block:
-            findings.append(Finding("error", name, f"section {index} missing progressive section thread"))
-        for required_text in ["工程讲解", "证据与操作", "验证", "Runbook"]:
+        if 'class="section-story"' not in block:
+            findings.append(Finding("error", name, f"section {index} missing section-specific story"))
+        if 'class="progressive-note"' not in block:
+            findings.append(Finding("error", name, f"section {index} missing progressive note"))
+        if 'class="section-thread"' in block:
+            findings.append(Finding("error", name, f"section {index} still uses generic section thread"))
+        for required_text in ["工程讲解", "证据与操作", "验证", "Runbook", "完整讲解"]:
             if required_text not in block_plain:
             if required_text not in block_plain:
                 findings.append(Finding("error", name, f"section {index} missing required text {required_text}"))
                 findings.append(Finding("error", name, f"section {index} missing required text {required_text}"))
 
 
@@ -211,6 +227,13 @@ def validate(directory: Path, content: Path) -> dict[str, Any]:
     mechanical_join_errors = [f for f in errors if "mechanical join marker" in f.message]
     mechanical_join_errors = [f for f in errors if "mechanical join marker" in f.message]
     learning_progression_errors = [f for f in errors if "progressive" in f.message or "learning ladder" in f.message]
     learning_progression_errors = [f for f in errors if "progressive" in f.message or "learning ladder" in f.message]
     knowledge_system_errors = [f for f in errors if "knowledge system" in f.message]
     knowledge_system_errors = [f for f in errors if "knowledge system" in f.message]
+    natural_section_story_errors = [
+        f
+        for f in errors
+        if "section-specific story" in f.message
+        or "generic section thread" in f.message
+        or "generic narration marker" in f.message
+    ]
 
 
     return {
     return {
         "summary": {
         "summary": {
@@ -227,6 +250,7 @@ def validate(directory: Path, content: Path) -> dict[str, Any]:
             "mechanical_join": {"passed": not mechanical_join_errors, "errors": len(mechanical_join_errors)},
             "mechanical_join": {"passed": not mechanical_join_errors, "errors": len(mechanical_join_errors)},
             "learning_progression": {"passed": not learning_progression_errors, "errors": len(learning_progression_errors)},
             "learning_progression": {"passed": not learning_progression_errors, "errors": len(learning_progression_errors)},
             "knowledge_system": {"passed": not knowledge_system_errors, "errors": len(knowledge_system_errors)},
             "knowledge_system": {"passed": not knowledge_system_errors, "errors": len(knowledge_system_errors)},
+            "natural_section_story": {"passed": not natural_section_story_errors, "errors": len(natural_section_story_errors)},
         },
         },
         "findings": [f.__dict__ for f in all_findings],
         "findings": [f.__dict__ for f in all_findings],
     }
     }

+ 54 - 6
tests/test_cpld_teaching_pipeline.py

@@ -9,6 +9,23 @@ GENERATOR = ROOT / "scripts" / "generate_cpld_teaching_html.py"
 VALIDATOR = ROOT / "scripts" / "validate_cpld_teaching_html.py"
 VALIDATOR = ROOT / "scripts" / "validate_cpld_teaching_html.py"
 CONTENT = ROOT / "workspace" / "teaching_content" / "chapters" / "cpld_teaching_content.json"
 CONTENT = ROOT / "workspace" / "teaching_content" / "chapters" / "cpld_teaching_content.json"
 
 
+GENERIC_NARRATION_MARKERS = [
+    "讨论「",
+    "读者真正会遇到的不是抽象名词",
+    "这个现象要落到证据上看",
+    "顺着这个点往下学",
+    "放进系统里看",
+    "扩展学习时不要把",
+    "讲解时可以采用一个很小的实验",
+    "不要从术语背诵开始",
+    "自然串讲:从现象走到验证",
+    "工程化深挖",
+    "常见误判要单独拎出来",
+    "本节的交付标准是",
+    "问题链自问",
+    "最小复述标准",
+]
+
 
 
 def run_cmd(*args: str) -> subprocess.CompletedProcess[str]:
 def run_cmd(*args: str) -> subprocess.CompletedProcess[str]:
     return subprocess.run(
     return subprocess.run(
@@ -54,12 +71,16 @@ def test_generator_creates_all_thirteen_single_file_reports(tmp_path: Path) -> N
     assert "class=\"evidence-panel\"" in ch5
     assert "class=\"evidence-panel\"" in ch5
     assert "class=\"section learning-ladder\"" in ch5
     assert "class=\"section learning-ladder\"" in ch5
     assert "class=\"section knowledge-system\"" in ch5
     assert "class=\"section knowledge-system\"" in ch5
-    assert "class=\"section-thread\"" in ch5
+    assert "class=\"section-story\"" in ch5
+    assert "class=\"progressive-note\"" in ch5
+    assert "class=\"section-thread\"" not in ch5
     assert "从浅到深的学习阶梯" in ch5
     assert "从浅到深的学习阶梯" in ch5
     assert "本章知识系统" in ch5
     assert "本章知识系统" in ch5
     assert "本节的交付标准是读者能把" not in ch5
     assert "本节的交付标准是读者能把" not in ch5
     assert "常见误判要单独拎出来" not in ch5
     assert "常见误判要单独拎出来" not in ch5
     assert "复盘本章时建议按下面的问题链自问" not in ch5
     assert "复盘本章时建议按下面的问题链自问" not in ch5
+    for marker in GENERIC_NARRATION_MARKERS:
+        assert marker not in ch5
 
 
     ch13 = (tmp_path / "cpld_ch13_program_debug_runbook_learning_report_v1.html").read_text(encoding="utf-8")
     ch13 = (tmp_path / "cpld_ch13_program_debug_runbook_learning_report_v1.html").read_text(encoding="utf-8")
     assert "No hardware" in ch13
     assert "No hardware" in ch13
@@ -67,6 +88,18 @@ def test_generator_creates_all_thirteen_single_file_reports(tmp_path: Path) -> N
     assert "id=\"debugTree\"" in ch13
     assert "id=\"debugTree\"" in ch13
     assert "VREF 不供电" in ch13
     assert "VREF 不供电" in ch13
     assert "class=\"causal-grid\"" not in ch13
     assert "class=\"causal-grid\"" not in ch13
+    for marker in GENERIC_NARRATION_MARKERS:
+        assert marker not in ch13
+
+    for file_name in [
+        "cpld_ch6_i2c_control_learning_report_v1.html",
+        "cpld_ch11_pid_24ch_learning_report_v1.html",
+    ]:
+        text = (tmp_path / file_name).read_text(encoding="utf-8")
+        assert "class=\"section-story\"" in text
+        assert "class=\"progressive-note\"" in text
+        for marker in GENERIC_NARRATION_MARKERS:
+            assert marker not in text
 
 
 
 
 def test_validator_accepts_generated_reports_and_writes_json_receipt(tmp_path: Path) -> None:
 def test_validator_accepts_generated_reports_and_writes_json_receipt(tmp_path: Path) -> None:
@@ -88,9 +121,10 @@ def test_validator_accepts_generated_reports_and_writes_json_receipt(tmp_path: P
     assert payload["checks"]["mechanical_join"]["passed"] is True
     assert payload["checks"]["mechanical_join"]["passed"] is True
     assert payload["checks"]["learning_progression"]["passed"] is True
     assert payload["checks"]["learning_progression"]["passed"] is True
     assert payload["checks"]["knowledge_system"]["passed"] is True
     assert payload["checks"]["knowledge_system"]["passed"] is True
+    assert payload["checks"]["natural_section_story"]["passed"] is True
 
 
 
 
-def test_content_source_models_progressive_learning_and_system_context() -> None:
+def test_content_source_models_section_specific_progressive_learning_and_system_context() -> None:
     data = json.loads(CONTENT.read_text(encoding="utf-8-sig"))
     data = json.loads(CONTENT.read_text(encoding="utf-8-sig"))
 
 
     for chapter in data["chapters"]:
     for chapter in data["chapters"]:
@@ -101,10 +135,24 @@ def test_content_source_models_progressive_learning_and_system_context() -> None
         assert any(word in ladder_text for word in ["扩展", "系统", "集成", "排障"]), chapter["short"]
         assert any(word in ladder_text for word in ["扩展", "系统", "集成", "排障"]), chapter["short"]
 
 
         for section in chapter["sections"]:
         for section in chapter["sections"]:
-            path = section.get("learning_path", [])
-            assert len(path) >= 3, section["title"]
-            assert section.get("system_hint"), section["title"]
-            assert section.get("mentor_note"), section["title"]
+            assert "mentor_note" not in section, section["title"]
+            assert "learning_path" not in section, section["title"]
+            assert "system_hint" not in section, section["title"]
+            for field in [
+                "beginner_entry",
+                "engineering_story",
+                "mechanism_walkthrough",
+                "verification_story",
+                "system_extension",
+            ]:
+                value = section.get(field, "")
+                assert len(value) >= 80, f"{section['title']} missing {field}"
+                assert section["title"][:4] in value or any(anchor in value for anchor in section["anchors"]), (
+                    section["title"],
+                    field,
+                )
+                for marker in GENERIC_NARRATION_MARKERS:
+                    assert marker not in value
 
 
 
 
 def test_validator_rejects_old_template_repetition(tmp_path: Path) -> None:
 def test_validator_rejects_old_template_repetition(tmp_path: Path) -> None:

File diff ditekan karena terlalu besar
+ 265 - 424
workspace/teaching_content/chapters/cpld_teaching_content.json