@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,152 +1,203 @@
1
- # -*- coding: utf-8 -*-
2
- """严格校验 ``project_docs`` 内的 Markdown 文档链接。
3
-
4
- 本工具只校验和报告,不生成或写入 manifest。manifest 发布由
5
- ``sync_project_docs.py`` 的最终协调阶段负责。
6
- """
7
-
8
- from __future__ import annotations
9
-
10
- import argparse
11
- import concurrent.futures
12
- import os
13
- import sys
14
- from pathlib import Path, PurePosixPath
15
- from typing import Any, Sequence
16
-
17
- from project_docs_contract import (
18
- LinkDisposition,
19
- PathConflictError,
20
- PathValidationError,
21
- ProjectDocsContractError,
22
- configure_stdio_utf8,
23
- discover_active_markdown_paths,
24
- read_markdown_links,
25
- resolve_docs_root,
26
- stable_json_dumps,
27
- )
28
-
29
-
30
- def discover_documents(project_docs: str | os.PathLike[str]) -> list[tuple[str, Path]]:
31
- """使用共享契约确定性枚举完整活动 Markdown 集合。"""
32
-
33
- root = resolve_docs_root(project_docs)
34
- return [
35
- (relative, root.joinpath(*PurePosixPath(relative).parts))
36
- for relative in discover_active_markdown_paths(root)
37
- ]
38
-
39
-
40
- def check_links(
41
- project_docs: str | os.PathLike[str],
42
- ) -> tuple[int, list[dict[str, Any]]]:
43
- """检查全部本地文档链接,返回 ``(问题数, 详情)``。"""
44
-
45
- root = resolve_docs_root(project_docs)
46
- docs = discover_documents(root)
47
- issues: list[dict[str, Any]] = []
48
-
49
- def _check_doc(doc_rel: str) -> list[dict[str, Any]]:
50
- doc_issues: list[dict[str, Any]] = []
51
- for link in read_markdown_links(doc_rel, root):
52
- if link.disposition is LinkDisposition.SKIPPED:
53
- continue
54
- if link.disposition is LinkDisposition.INVALID:
55
- doc_issues.append(
56
- {
57
- "doc": doc_rel,
58
- "text": link.text,
59
- "target": link.raw_target,
60
- "resolved": link.normalized_target,
61
- "kind": "invalid",
62
- "reason": link.reason,
63
- }
64
- )
65
- elif link.exists is False:
66
- doc_issues.append(
67
- {
68
- "doc": doc_rel,
69
- "text": link.text,
70
- "target": link.raw_target,
71
- "resolved": link.project_relative_path,
72
- "kind": "missing",
73
- "reason": link.reason,
74
- }
75
- )
76
- return doc_issues
77
-
78
- if len(docs) > 1:
79
- max_workers = min(32, (os.cpu_count() or 4) * 4)
80
- with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as executor:
81
- doc_rels = [doc_rel for doc_rel, _ in docs]
82
- for doc_issues in executor.map(_check_doc, doc_rels):
83
- issues.extend(doc_issues)
84
- else:
85
- for doc_rel, _ in docs:
86
- issues.extend(_check_doc(doc_rel))
87
-
88
- return len(issues), issues
89
-
90
-
91
- def _parser() -> argparse.ArgumentParser:
92
- parser = argparse.ArgumentParser(description="校验 project_docs Markdown 链接")
93
- parser.add_argument(
94
- "--project-docs",
95
- default="project_docs",
96
- help="project_docs 目录(默认: project_docs)",
97
- )
98
- parser.add_argument("--json", action="store_true", help="stdout 仅输出 JSON")
99
- parser.add_argument(
100
- "--check-only",
101
- action="store_true",
102
- help="兼容旧参数;当前工具始终只执行链接检查",
103
- )
104
- parser.add_argument(
105
- "--manifest-only",
106
- action="store_true",
107
- help="已废弃;manifest 只能由同步协调器发布",
108
- )
109
- return parser
110
-
111
-
112
- def main(argv: Sequence[str] | None = None) -> int:
113
- configure_stdio_utf8()
114
- args = _parser().parse_args(argv)
115
- if args.manifest_only:
116
- message = "--manifest-only 已废弃;请使用 sync_project_docs.py 构建 manifest"
117
- if args.json:
118
- print(stable_json_dumps({"error": message, "ok": False}), end="")
119
- else:
120
- print(f"ERROR: {message}", file=sys.stderr)
121
- return 2
122
-
123
- try:
124
- issue_count, issues = check_links(args.project_docs)
125
- result = {
126
- "ok": issue_count == 0,
127
- "broken_count": issue_count,
128
- "broken": issues,
129
- "manifest_written": False,
130
- }
131
- if args.json:
132
- print(stable_json_dumps(result), end="")
133
- elif issue_count:
134
- print(f"发现 {issue_count} 条无效或断开的文档链接:")
135
- for issue in issues:
136
- print(
137
- f" {issue['doc']} -> {issue['target']} "
138
- f"({issue['kind']}: {issue['reason']})"
139
- )
140
- else:
141
- print("文档链接校验通过:0 条断链。")
142
- return 1 if issue_count else 0
143
- except (OSError, ProjectDocsContractError, PathConflictError) as exc:
144
- if args.json:
145
- print(stable_json_dumps({"error": str(exc), "ok": False}), end="")
146
- else:
147
- print(f"ERROR: {exc}", file=sys.stderr)
148
- return 2
149
-
150
-
151
- if __name__ == "__main__":
152
- raise SystemExit(main())
1
+ # -*- coding: utf-8 -*-
2
+ """严格校验 ``project_docs`` 内的 Markdown 文档链接。
3
+
4
+ 本工具只校验和报告,不生成或写入 manifest。manifest 发布由
5
+ ``sync_project_docs.py`` 的最终协调阶段负责。
6
+ """
7
+
8
+ from __future__ import annotations
9
+ import sys as _bootstrap_sys
10
+ from pathlib import Path as _bootstrap_path
11
+ _bootstrap_sys.dont_write_bytecode = True
12
+ _bootstrap_sys.path.insert(0, str(_bootstrap_path(__file__).resolve().parents[1]))
13
+ import _paths # noqa: E402
14
+ _paths.install()
15
+
16
+ import argparse
17
+ import concurrent.futures
18
+ import os
19
+ import sys
20
+ from pathlib import Path, PurePosixPath
21
+ from typing import Any, Sequence
22
+
23
+ from project_docs_contract import (
24
+ LinkDisposition,
25
+ PathConflictError,
26
+ PathValidationError, # noqa: F401 — re-exported; callers raise/catch via link_check
27
+ ProjectDocsContractError,
28
+ configure_stdio_utf8,
29
+ discover_active_markdown_paths,
30
+ read_markdown_links,
31
+ resolve_docs_root,
32
+ stable_json_dumps,
33
+ )
34
+
35
+
36
+ def discover_documents(project_docs: str | os.PathLike[str]) -> list[tuple[str, Path]]:
37
+ """使用共享契约确定性枚举完整活动 Markdown 集合。"""
38
+
39
+ root = resolve_docs_root(project_docs)
40
+ return [
41
+ (relative, root.joinpath(*PurePosixPath(relative).parts))
42
+ for relative in discover_active_markdown_paths(root)
43
+ ]
44
+
45
+
46
+ def _is_quarantine_relative(relative_path: str) -> bool:
47
+ parts = PurePosixPath(relative_path).parts
48
+ return bool(parts) and parts[0].casefold() == ".quarantine"
49
+
50
+
51
+ def check_links_with_graph(
52
+ project_docs: str | os.PathLike[str],
53
+ ) -> tuple[int, list[dict[str, Any]], dict[str, set[str]], list[dict[str, str]]]:
54
+ """一次遍历完成链接校验并构建入链图,供下游 ``phase4_exit`` 复用。
55
+
56
+ 返回 ``(问题数, 问题详情, inbound_sources, invalid_links)``。
57
+ """
58
+
59
+ root = resolve_docs_root(project_docs)
60
+ docs = discover_documents(root)
61
+ issues: list[dict[str, Any]] = []
62
+ inbound: dict[str, set[str]] = {doc_rel: set() for doc_rel, _ in docs}
63
+ invalid_links: list[dict[str, str]] = []
64
+
65
+ def _check_doc(
66
+ doc_rel: str,
67
+ ) -> tuple[list[dict[str, Any]], list[str], list[dict[str, str]]]:
68
+ doc_issues: list[dict[str, Any]] = []
69
+ targets: list[str] = []
70
+ doc_invalid: list[dict[str, str]] = []
71
+ for link in read_markdown_links(doc_rel, root):
72
+ if link.disposition is LinkDisposition.SKIPPED:
73
+ continue
74
+ if link.disposition is LinkDisposition.INVALID:
75
+ reason = link.reason or "invalid-local-target"
76
+ doc_issues.append(
77
+ {
78
+ "doc": doc_rel,
79
+ "text": link.text,
80
+ "target": link.raw_target,
81
+ "resolved": link.normalized_target,
82
+ "kind": "invalid",
83
+ "reason": link.reason,
84
+ }
85
+ )
86
+ doc_invalid.append(
87
+ {
88
+ "source": doc_rel,
89
+ "target": link.raw_target,
90
+ "reason": reason,
91
+ }
92
+ )
93
+ else:
94
+ if link.exists is False:
95
+ doc_issues.append(
96
+ {
97
+ "doc": doc_rel,
98
+ "text": link.text,
99
+ "target": link.raw_target,
100
+ "resolved": link.project_relative_path,
101
+ "kind": "missing",
102
+ "reason": link.reason,
103
+ }
104
+ )
105
+ if link.is_local_document and link.project_relative_path is not None:
106
+ target = link.project_relative_path
107
+ if not _is_quarantine_relative(target) and target != doc_rel:
108
+ targets.append(target)
109
+ return doc_issues, targets, doc_invalid
110
+
111
+ if len(docs) > 1:
112
+ max_workers = min(32, (os.cpu_count() or 4) * 4)
113
+ with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as executor:
114
+ doc_rels = [doc_rel for doc_rel, _ in docs]
115
+ for doc_rel, (doc_issues, targets, doc_invalid) in zip(
116
+ doc_rels, executor.map(_check_doc, doc_rels)
117
+ ):
118
+ issues.extend(doc_issues)
119
+ invalid_links.extend(doc_invalid)
120
+ for target in targets:
121
+ inbound.setdefault(target, set()).add(doc_rel)
122
+ else:
123
+ for doc_rel, _ in docs:
124
+ doc_issues, targets, doc_invalid = _check_doc(doc_rel)
125
+ issues.extend(doc_issues)
126
+ invalid_links.extend(doc_invalid)
127
+ for target in targets:
128
+ inbound.setdefault(target, set()).add(doc_rel)
129
+
130
+ return len(issues), issues, inbound, invalid_links
131
+
132
+
133
+ def check_links(
134
+ project_docs: str | os.PathLike[str],
135
+ ) -> tuple[int, list[dict[str, Any]]]:
136
+ """检查全部本地文档链接,返回 ``(问题数, 详情)``。"""
137
+
138
+ issue_count, issues, _, _ = check_links_with_graph(project_docs)
139
+ return issue_count, issues
140
+
141
+
142
+ def _parser() -> argparse.ArgumentParser:
143
+ parser = argparse.ArgumentParser(description="校验 project_docs Markdown 链接")
144
+ parser.add_argument(
145
+ "--project-docs",
146
+ default="project_docs",
147
+ help="project_docs 目录(默认: project_docs)",
148
+ )
149
+ parser.add_argument("--json", action="store_true", help="stdout 仅输出 JSON")
150
+ parser.add_argument(
151
+ "--check-only",
152
+ action="store_true",
153
+ help="兼容旧参数;当前工具始终只执行链接检查",
154
+ )
155
+ parser.add_argument(
156
+ "--manifest-only",
157
+ action="store_true",
158
+ help="已废弃;manifest 只能由同步协调器发布",
159
+ )
160
+ return parser
161
+
162
+
163
+ def main(argv: Sequence[str] | None = None) -> int:
164
+ configure_stdio_utf8()
165
+ args = _parser().parse_args(argv)
166
+ if args.manifest_only:
167
+ message = "--manifest-only 已废弃;请使用 sync_project_docs.py 构建 manifest"
168
+ if args.json:
169
+ print(stable_json_dumps({"error": message, "ok": False}), end="")
170
+ else:
171
+ print(f"ERROR: {message}", file=sys.stderr)
172
+ return 2
173
+
174
+ try:
175
+ issue_count, issues = check_links(args.project_docs)
176
+ result = {
177
+ "ok": issue_count == 0,
178
+ "broken_count": issue_count,
179
+ "broken": issues,
180
+ "manifest_written": False,
181
+ }
182
+ if args.json:
183
+ print(stable_json_dumps(result), end="")
184
+ elif issue_count:
185
+ print(f"发现 {issue_count} 条无效或断开的文档链接:")
186
+ for issue in issues:
187
+ print(
188
+ f" {issue['doc']} -> {issue['target']} "
189
+ f"({issue['kind']}: {issue['reason']})"
190
+ )
191
+ else:
192
+ print("文档链接校验通过:0 条断链。")
193
+ return 1 if issue_count else 0
194
+ except (OSError, ProjectDocsContractError, PathConflictError) as exc:
195
+ if args.json:
196
+ print(stable_json_dumps({"error": str(exc), "ok": False}), end="")
197
+ else:
198
+ print(f"ERROR: {exc}", file=sys.stderr)
199
+ return 2
200
+
201
+
202
+ if __name__ == "__main__":
203
+ raise SystemExit(main())