@walvka-code/proj-doc-builder 4.0.0 → 4.5.2

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.
Files changed (61) hide show
  1. package/README.md +290 -272
  2. package/README.zh-CN.md +258 -240
  3. package/package.json +6 -2
  4. package/skills/proj-doc-builder/SKILL.md +97 -35
  5. package/skills/proj-doc-builder/references/audit_script.md +103 -96
  6. package/skills/proj-doc-builder/references/batch-generation.md +55 -0
  7. package/skills/proj-doc-builder/references/checklist.md +20 -10
  8. package/skills/proj-doc-builder/references/exclusions.md +1 -1
  9. package/skills/proj-doc-builder/references/linking.md +83 -83
  10. package/skills/proj-doc-builder/references/templates.md +57 -17
  11. package/skills/proj-doc-builder/tests/claims.json +76 -0
  12. package/skills/proj-doc-builder/tests/conftest.py +17 -5
  13. package/skills/proj-doc-builder/tests/test_claims_registry.py +81 -0
  14. package/skills/proj-doc-builder/tests/test_e2e_fresh_project.py +156 -0
  15. package/skills/proj-doc-builder/tests/test_load_docs.py +353 -248
  16. package/skills/proj-doc-builder/tests/test_project_docs_contract.py +32 -1
  17. package/skills/proj-doc-builder/tests/test_scan_dirs.py +1 -1
  18. package/skills/proj-doc-builder/tests/test_stage1_stage2_upgrades.py +395 -0
  19. package/skills/proj-doc-builder/tests/test_sync_project_docs.py +2169 -2169
  20. package/skills/proj-doc-builder/tests/test_v41_upgrades.py +614 -0
  21. package/skills/proj-doc-builder/tests/test_v42_upgrades.py +422 -0
  22. package/skills/proj-doc-builder/tests/test_v43_upgrades.py +198 -0
  23. package/skills/proj-doc-builder/tests/test_v44_upgrades.py +361 -0
  24. package/skills/proj-doc-builder/tests/test_v45_upgrades.py +212 -0
  25. package/skills/proj-doc-builder/tests/test_validate_doc.py +172 -15
  26. package/skills/proj-doc-builder/tools/_paths.py +39 -0
  27. package/skills/proj-doc-builder/tools/{claude_doc_index.py → core/claude_doc_index.py} +504 -298
  28. package/skills/proj-doc-builder/tools/{compute_link.py → core/compute_link.py} +239 -233
  29. package/skills/proj-doc-builder/tools/core/proj_doc_config.py +460 -0
  30. package/skills/proj-doc-builder/tools/{project_docs_contract.py → core/project_docs_contract.py} +460 -53
  31. package/skills/proj-doc-builder/tools/phase4/__init__.py +31 -6
  32. package/skills/proj-doc-builder/tools/phase4/cas_storage.py +11 -4
  33. package/skills/proj-doc-builder/tools/phase4/engine.py +17 -2
  34. package/skills/proj-doc-builder/tools/phase4/journal.py +15 -8
  35. package/skills/proj-doc-builder/tools/phase4/platform_handles.py +12 -5
  36. package/skills/proj-doc-builder/tools/phase4_exit.py +153 -47
  37. package/skills/proj-doc-builder/tools/pipeline/gen_docs_from_scaffold.py +789 -0
  38. package/skills/proj-doc-builder/tools/{sync_project_docs.py → pipeline/sync_project_docs.py} +5531 -3639
  39. package/skills/proj-doc-builder/tools/{load_docs.py → reader/load_docs.py} +654 -380
  40. package/skills/proj-doc-builder/tools/{link_check.py → scan/link_check.py} +203 -152
  41. package/skills/proj-doc-builder/tools/{normalize_markers.py → scan/normalize_markers.py} +211 -205
  42. package/skills/proj-doc-builder/tools/{scan_dirs.py → scan/scan_dirs.py} +2735 -2405
  43. package/skills/proj-doc-builder/tools/{validate_doc.py → validate/validate_doc.py} +1911 -1299
  44. package/skills/proj-doc-builder/tests/__pycache__/conftest.cpython-314-pytest-9.0.3.pyc +0 -0
  45. package/skills/proj-doc-builder/tests/__pycache__/test_claude_doc_index.cpython-314-pytest-9.0.3.pyc +0 -0
  46. package/skills/proj-doc-builder/tests/__pycache__/test_link_tools.cpython-314-pytest-9.0.3.pyc +0 -0
  47. package/skills/proj-doc-builder/tests/__pycache__/test_load_docs.cpython-314-pytest-9.0.3.pyc +0 -0
  48. package/skills/proj-doc-builder/tests/__pycache__/test_normalize_markers.cpython-314-pytest-9.0.3.pyc +0 -0
  49. package/skills/proj-doc-builder/tests/__pycache__/test_phase4_exit.cpython-314-pytest-9.0.3.pyc +0 -0
  50. package/skills/proj-doc-builder/tests/__pycache__/test_project_docs_contract.cpython-314-pytest-9.0.3.pyc +0 -0
  51. package/skills/proj-doc-builder/tests/__pycache__/test_scan_dirs.cpython-314-pytest-9.0.3.pyc +0 -0
  52. package/skills/proj-doc-builder/tests/__pycache__/test_sync_project_docs.cpython-314-pytest-9.0.3.pyc +0 -0
  53. package/skills/proj-doc-builder/tools/__pycache__/claude_doc_index.cpython-314.pyc +0 -0
  54. package/skills/proj-doc-builder/tools/__pycache__/compute_link.cpython-314.pyc +0 -0
  55. package/skills/proj-doc-builder/tools/__pycache__/link_check.cpython-314.pyc +0 -0
  56. package/skills/proj-doc-builder/tools/__pycache__/load_docs.cpython-314.pyc +0 -0
  57. package/skills/proj-doc-builder/tools/__pycache__/normalize_markers.cpython-314.pyc +0 -0
  58. package/skills/proj-doc-builder/tools/__pycache__/phase4_exit.cpython-314.pyc +0 -0
  59. package/skills/proj-doc-builder/tools/__pycache__/project_docs_contract.cpython-314.pyc +0 -0
  60. package/skills/proj-doc-builder/tools/__pycache__/scan_dirs.cpython-314.pyc +0 -0
  61. package/skills/proj-doc-builder/tools/__pycache__/sync_project_docs.cpython-314.pyc +0 -0
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
- """Focused tests for ``tools/validate_doc.py``."""
2
+ """Focused tests for ``tools/validate/validate_doc.py``."""
3
3
 
4
4
  from __future__ import annotations
5
5
 
@@ -11,9 +11,14 @@ import pytest
11
11
  import validate_doc as validator
12
12
 
13
13
  STANDARD_OVERVIEW = (
14
- "本目录属于测试子系统中的算法模块。"
15
- "它接收上游协议层输入并调用核心实现完成确定性处理。"
16
- "结果输出给下游测试组件,且与相邻适配器目录协作。"
14
+ "本目录属于测试子系统中的算法模块,定位为接收协议向量并产出验证结论的执行单元。"
15
+ "它从上游协议层 `proto` 接收结构化测试向量与配置参数。"
16
+ "核心处理由 `PublicApi` 与 `run_case` 协作完成确定性计算。"
17
+ "处理结果以 `Result` 结构交付给下游验证组件 `verifier`。"
18
+ "本目录不负责测试调度与报告生成,仅承担单用例的执行。"
19
+ "失败路径通过 `DEFAULT_MODE` 切换降级,并在异常时回滚中间产物。"
20
+ "与同级 `adapter` 目录共享测试上下文总线但无写竞争。"
21
+ "文件清单含 `__init__.py` 与 `core.py` 两个直接文件。"
17
22
  )
18
23
  STANDARD_ROLE = (
19
24
  "本目录位于测试子系统的数据层,作为算法模块接收上游协议栈传入的测试向量。"
@@ -67,6 +72,21 @@ def _standard_document(*, overview: str = STANDARD_OVERVIEW) -> str:
67
72
 
68
73
  {STANDARD_ROLE}
69
74
 
75
+ ## 数据与状态
76
+
77
+ 本目录读取 `core.py` 中的 `DEFAULT_MODE` 常量作为运行期开关,不写入持久化文件。
78
+ 跨进程状态由上层 `project_docs` 契约管理,本目录不持有独立锁或 journal。
79
+
80
+ ## 性能与资源特征
81
+
82
+ 符号提取对 `core.py` 做单次 AST 解析,复杂度与文件数线性相关,当前量级为 O(2)。
83
+ 无并发 worker 常驻,单次校验内存占用与文档字数成正比。
84
+
85
+ ## 变更与迁移注意
86
+
87
+ 本文档遵循 doc_contract_version=4.2,接口 `PublicApi.run_case` 自 v4.1 起保持签名不变。
88
+ 契约升级时通过 `--upgrade-plan` 报告差异,再以 `--migrate-manifest` 迁移。
89
+
70
90
  ## 状态
71
91
 
72
92
  ✅ 完整 — 标准模块已经实现。
@@ -132,7 +152,7 @@ def test_standard_profile_passes_exact_inventory_links_and_content(
132
152
  assert result["ok"] is True
133
153
  assert result["failed"] == 0
134
154
  assert result["critical_failed"] == 0
135
- assert len(result["checks"]) == 9
155
+ assert len(result["checks"]) == 12
136
156
  assert _check(result, 1)["result"] == "PASS"
137
157
  assert _check(result, 4)["result"] == "PASS"
138
158
  assert _check(result, 9)["result"] == "PASS"
@@ -143,12 +163,13 @@ def test_standard_profile_passes_exact_inventory_links_and_content(
143
163
  [
144
164
  ("本目录属于测试模块。它向下游输出结果。", 2),
145
165
  (
146
- "本目录属于测试模块。它接收输入。它执行处理。它输出结果。它记录状态。",
147
- 5,
166
+ "本目录属于测试模块。它接收输入。它执行处理。它输出结果。它记录状态。"
167
+ "它读取配置。它校验参数。",
168
+ 7,
148
169
  ),
149
170
  ],
150
171
  )
151
- def test_standard_overview_requires_three_to_four_sentences(
172
+ def test_standard_overview_requires_at_least_eight_sentences(
152
173
  tmp_path: Path,
153
174
  overview: str,
154
175
  sentence_count: int,
@@ -341,9 +362,14 @@ def test_validate_index_doc_against_root(tmp_path: Path) -> None:
341
362
 
342
363
  ## 概述
343
364
 
344
- 系统提供统一端到端量化分析与自动交易能力。
345
- 微内核分层架构解耦数据采集、因子计算与执行撮合。
346
- 通过统一事件总线调度全链路生命周期并交付研报。
365
+ 系统提供统一端到端量化分析与自动交易能力,定位为顶层总控与架构拓扑中枢。
366
+ 微内核分层架构解耦数据采集、因子计算与执行撮合,由 `main` 入口统一调度。
367
+ 上游从数据中台接收行情快照与配置参数,经事件总线分发到研判与执行子系统。
368
+ 核心处理由 `微内核` 与 `动态研判` 协作完成策略生成与风控校验。
369
+ 交付产物为交易指令与研报,向 `交易执行` 子系统输出。
370
+ 本目录不承担单用例测试与日志归档,仅做顶层编排。
371
+ 失败路径通过事件总线回滚未完成事务并降级为只读研报模式。
372
+ 顶层直接文件 `main.py` 与子目录 `src/` 共同构成运行入口。
347
373
 
348
374
  ## 文件清单
349
375
 
@@ -373,6 +399,21 @@ def test_validate_index_doc_against_root(tmp_path: Path) -> None:
373
399
 
374
400
  本模块作为系统的顶层总控与架构拓扑中枢,统一调用底层微内核、数据中台、动态研判与交易执行交付子系统,为下游提供统一服务接口。
375
401
 
402
+ ## 数据与状态
403
+
404
+ 顶层目录不直接持有持久化数据,运行期状态由事件总线在内存中流转。
405
+ 跨进程协调通过 `project_docs` 契约定义的路径约定,无独立锁。
406
+
407
+ ## 性能与资源特征
408
+
409
+ 单次启动按子目录线性分发任务,开销与子目录数成正比(当前量级 O(2))。
410
+ 无并发 worker 常驻,顶层编排延迟主要来自下游子系统的处理时长。
411
+
412
+ ## 变更与迁移注意
413
+
414
+ 本文档遵循 doc_contract_version=4.2,`main` 入口签名自首版保持不变。
415
+ 契约升级时通过 `--upgrade-plan` 报告差异,再以 `--migrate-manifest` 迁移。
416
+
376
417
  ## 状态
377
418
 
378
419
  ✅ 完整
@@ -457,6 +498,9 @@ def test_missing_and_invalid_utf8_documents_return_complete_stable_results(
457
498
  "passed",
458
499
  "failed",
459
500
  "na",
501
+ "known_issue_count",
502
+ "known_issues",
503
+ "advisories",
460
504
  "critical_failed",
461
505
  "critical",
462
506
  "qualified",
@@ -467,10 +511,10 @@ def test_missing_and_invalid_utf8_documents_return_complete_stable_results(
467
511
  }
468
512
  assert set(missing_result) == expected_keys
469
513
  assert set(bad_result) == expected_keys
470
- assert len(missing_result["checks"]) == 9
471
- assert len(bad_result["checks"]) == 9
472
- assert missing_result["na"] == 9
473
- assert bad_result["na"] == 9
514
+ assert len(missing_result["checks"]) == 12
515
+ assert len(bad_result["checks"]) == 12
516
+ assert missing_result["na"] == 12
517
+ assert bad_result["na"] == 12
474
518
  assert missing_result["error_code"] == "document-not-found"
475
519
  assert bad_result["error_code"] == "invalid-utf8"
476
520
  assert missing_result["qualified"] is False
@@ -553,3 +597,116 @@ def test_cli_exit_policy_distinguishes_advisory_strict_and_critical(
553
597
  assert critical_exit == validator.EXIT_VALIDATION_FAILED
554
598
  assert json.loads(critical_output.out)["critical_failed"] >= 1
555
599
  assert critical_output.err == ""
600
+
601
+
602
+ def _rich_section_doc(section: str, body: str) -> str:
603
+ """Minimal standard-profile document carrying one v4.5 rich section."""
604
+
605
+ return (
606
+ "# 模块文档\n\n## 概述\n\n"
607
+ + STANDARD_OVERVIEW
608
+ + "\n\n## 数据与状态\n\n"
609
+ + (body if section == "数据与状态" else "状态落在 `_manifest.json`,无进程内缓存。\n进程退出后由磁盘文件恢复。")
610
+ + "\n\n## 性能与资源特征\n\n"
611
+ + (body if section == "性能与资源特征" else "按目录数线性扫描,复杂度 O(n)。\n单次运行内存占用与文档数成正比。")
612
+ + "\n\n## 变更与迁移注意\n\n"
613
+ + (body if section == "变更与迁移注意" else "契约版本变化时先跑 `--upgrade-plan` 查看差异。\n再用 `--migrate-manifest` 迁移旧清单。")
614
+ + "\n"
615
+ )
616
+
617
+
618
+ @pytest.mark.parametrize(
619
+ ("check", "section"),
620
+ [
621
+ (validator.check_10_data_state, "数据与状态"),
622
+ (validator.check_11_perf_resources, "性能与资源特征"),
623
+ (validator.check_12_change_migration, "变更与迁移注意"),
624
+ ],
625
+ )
626
+ def test_rich_sections_accept_declared_not_applicable_with_reason(check, section) -> None:
627
+ content = _rich_section_doc(section, "本节不适用:该目录只做纯函数计算,不持有任何持久化数据。")
628
+
629
+ ok, detail = check(content)
630
+
631
+ assert ok is True, detail
632
+ assert "不适用" in detail
633
+
634
+
635
+ @pytest.mark.parametrize(
636
+ ("check", "section"),
637
+ [
638
+ (validator.check_10_data_state, "数据与状态"),
639
+ (validator.check_11_perf_resources, "性能与资源特征"),
640
+ (validator.check_12_change_migration, "变更与迁移注意"),
641
+ ],
642
+ )
643
+ def test_rich_sections_reject_not_applicable_without_reason(check, section) -> None:
644
+ content = _rich_section_doc(section, "本节不适用:")
645
+
646
+ ok, detail = check(content)
647
+
648
+ assert ok is False
649
+ assert "未给出具体理由" in detail
650
+
651
+
652
+ def test_rich_section_reason_strips_whitespace_not_letters() -> None:
653
+ """Regression: the not-applicable reason stripper must trim whitespace and
654
+ punctuation, never the ASCII letters n/t (a prior build used ``\\n\\t``
655
+ in the source, which Python evaluated to backslash+n and stripped letters)."""
656
+
657
+ reason = "nnnnnn"
658
+ assert len(reason) == 6
659
+ content = _rich_section_doc("数据与状态", f"本节不适用:{reason}")
660
+
661
+ ok, detail = validator.check_10_data_state(content)
662
+
663
+ assert ok is True, detail
664
+ assert "不适用" in detail
665
+
666
+
667
+ def test_rich_section_reason_trims_trailing_newline() -> None:
668
+ """A reason followed by stray whitespace must still be measured by its text."""
669
+
670
+ content = _rich_section_doc(
671
+ "数据与状态",
672
+ "本节不适用:该模块不落盘任何运行期状态\n\n",
673
+ )
674
+
675
+ ok, detail = validator.check_10_data_state(content)
676
+
677
+ assert ok is True, detail
678
+
679
+
680
+ @pytest.mark.parametrize(
681
+ ("check", "section"),
682
+ [
683
+ (validator.check_10_data_state, "数据与状态"),
684
+ (validator.check_11_perf_resources, "性能与资源特征"),
685
+ (validator.check_12_change_migration, "变更与迁移注意"),
686
+ ],
687
+ )
688
+ def test_rich_sections_reject_short_body(check, section) -> None:
689
+ content = _rich_section_doc(section, "只有一句话。")
690
+
691
+ ok, detail = check(content)
692
+
693
+ assert ok is False
694
+ assert "过短" in detail or "2 句" in detail
695
+
696
+
697
+ def test_rich_sections_are_skipped_for_placeholder_profile() -> None:
698
+ context = validator._ValidationContext(
699
+ doc_path=Path("placeholder.md"),
700
+ docs_root=Path("project_docs"),
701
+ doc_relative="placeholder.md",
702
+ project_root=Path("."),
703
+ source_dir=None,
704
+ source_files=None,
705
+ source_subdirs=None,
706
+ profile=validator.PROFILE_PLACEHOLDER,
707
+ )
708
+
709
+ ok, detail = validator.check_10_data_state("# 占位\n", context=context)
710
+
711
+ assert ok is True
712
+ assert "placeholder" in detail
@@ -0,0 +1,39 @@
1
+ # -*- coding: utf-8 -*-
2
+ """Path bootstrap for the layered ``tools`` layout.
3
+
4
+ Modules live in subpackages (``core``, ``scan``, ``validate``, ``pipeline``,
5
+ ``reader``) but keep flat sibling imports (`import scan_dirs`,
6
+ `import project_docs_contract as contract`, ...). Every CLI entry script and
7
+ the test ``conftest.py`` call :func:`install` so those imports resolve no matter
8
+ which directory the process was started from.
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ import sys
14
+ from pathlib import Path
15
+
16
+ _TOOLS_ROOT = Path(__file__).resolve().parent
17
+ # ``phase4`` is a real package imported as ``import phase4``; only the tools root
18
+ # needs to be on the path for it. Its modules are never imported flat, so adding
19
+ # the directory itself would inject ``engine``/``journal``/... into the top-level
20
+ # namespace for no reason.
21
+ _SUBPACKAGES = ("core", "scan", "validate", "pipeline", "reader")
22
+
23
+
24
+ def install(tools_root: str | Path | None = None) -> Path:
25
+ """Insert the tools root and every subpackage dir at the front of ``sys.path``.
26
+
27
+ Idempotent. Returns the effective tools root so callers can reuse it.
28
+ """
29
+
30
+ root = Path(tools_root).resolve() if tools_root else _TOOLS_ROOT
31
+ for sub in _SUBPACKAGES:
32
+ candidate = root / sub
33
+ if candidate.is_dir():
34
+ text = str(candidate)
35
+ if text not in sys.path:
36
+ sys.path.insert(0, text)
37
+ if str(root) not in sys.path:
38
+ sys.path.insert(0, str(root))
39
+ return root