@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.
- package/README.md +290 -272
- package/README.zh-CN.md +258 -240
- package/package.json +6 -2
- package/skills/proj-doc-builder/SKILL.md +97 -35
- package/skills/proj-doc-builder/references/audit_script.md +103 -96
- package/skills/proj-doc-builder/references/batch-generation.md +55 -0
- package/skills/proj-doc-builder/references/checklist.md +20 -10
- package/skills/proj-doc-builder/references/exclusions.md +1 -1
- package/skills/proj-doc-builder/references/linking.md +83 -83
- package/skills/proj-doc-builder/references/templates.md +57 -17
- package/skills/proj-doc-builder/tests/claims.json +76 -0
- package/skills/proj-doc-builder/tests/conftest.py +17 -5
- package/skills/proj-doc-builder/tests/test_claims_registry.py +81 -0
- package/skills/proj-doc-builder/tests/test_e2e_fresh_project.py +156 -0
- package/skills/proj-doc-builder/tests/test_load_docs.py +353 -248
- package/skills/proj-doc-builder/tests/test_project_docs_contract.py +32 -1
- package/skills/proj-doc-builder/tests/test_scan_dirs.py +1 -1
- package/skills/proj-doc-builder/tests/test_stage1_stage2_upgrades.py +395 -0
- package/skills/proj-doc-builder/tests/test_sync_project_docs.py +2169 -2169
- package/skills/proj-doc-builder/tests/test_v41_upgrades.py +614 -0
- package/skills/proj-doc-builder/tests/test_v42_upgrades.py +422 -0
- package/skills/proj-doc-builder/tests/test_v43_upgrades.py +198 -0
- package/skills/proj-doc-builder/tests/test_v44_upgrades.py +361 -0
- package/skills/proj-doc-builder/tests/test_v45_upgrades.py +212 -0
- package/skills/proj-doc-builder/tests/test_validate_doc.py +172 -15
- package/skills/proj-doc-builder/tools/_paths.py +39 -0
- package/skills/proj-doc-builder/tools/{claude_doc_index.py → core/claude_doc_index.py} +504 -298
- package/skills/proj-doc-builder/tools/{compute_link.py → core/compute_link.py} +239 -233
- package/skills/proj-doc-builder/tools/core/proj_doc_config.py +460 -0
- package/skills/proj-doc-builder/tools/{project_docs_contract.py → core/project_docs_contract.py} +460 -53
- package/skills/proj-doc-builder/tools/phase4/__init__.py +31 -6
- package/skills/proj-doc-builder/tools/phase4/cas_storage.py +11 -4
- package/skills/proj-doc-builder/tools/phase4/engine.py +17 -2
- package/skills/proj-doc-builder/tools/phase4/journal.py +15 -8
- package/skills/proj-doc-builder/tools/phase4/platform_handles.py +12 -5
- package/skills/proj-doc-builder/tools/phase4_exit.py +153 -47
- package/skills/proj-doc-builder/tools/pipeline/gen_docs_from_scaffold.py +789 -0
- package/skills/proj-doc-builder/tools/{sync_project_docs.py → pipeline/sync_project_docs.py} +5531 -3639
- package/skills/proj-doc-builder/tools/{load_docs.py → reader/load_docs.py} +654 -380
- package/skills/proj-doc-builder/tools/{link_check.py → scan/link_check.py} +203 -152
- package/skills/proj-doc-builder/tools/{normalize_markers.py → scan/normalize_markers.py} +211 -205
- package/skills/proj-doc-builder/tools/{scan_dirs.py → scan/scan_dirs.py} +2735 -2405
- package/skills/proj-doc-builder/tools/{validate_doc.py → validate/validate_doc.py} +1911 -1299
- package/skills/proj-doc-builder/tests/__pycache__/conftest.cpython-314-pytest-9.0.3.pyc +0 -0
- package/skills/proj-doc-builder/tests/__pycache__/test_claude_doc_index.cpython-314-pytest-9.0.3.pyc +0 -0
- package/skills/proj-doc-builder/tests/__pycache__/test_link_tools.cpython-314-pytest-9.0.3.pyc +0 -0
- package/skills/proj-doc-builder/tests/__pycache__/test_load_docs.cpython-314-pytest-9.0.3.pyc +0 -0
- package/skills/proj-doc-builder/tests/__pycache__/test_normalize_markers.cpython-314-pytest-9.0.3.pyc +0 -0
- package/skills/proj-doc-builder/tests/__pycache__/test_phase4_exit.cpython-314-pytest-9.0.3.pyc +0 -0
- package/skills/proj-doc-builder/tests/__pycache__/test_project_docs_contract.cpython-314-pytest-9.0.3.pyc +0 -0
- package/skills/proj-doc-builder/tests/__pycache__/test_scan_dirs.cpython-314-pytest-9.0.3.pyc +0 -0
- package/skills/proj-doc-builder/tests/__pycache__/test_sync_project_docs.cpython-314-pytest-9.0.3.pyc +0 -0
- package/skills/proj-doc-builder/tools/__pycache__/claude_doc_index.cpython-314.pyc +0 -0
- package/skills/proj-doc-builder/tools/__pycache__/compute_link.cpython-314.pyc +0 -0
- package/skills/proj-doc-builder/tools/__pycache__/link_check.cpython-314.pyc +0 -0
- package/skills/proj-doc-builder/tools/__pycache__/load_docs.cpython-314.pyc +0 -0
- package/skills/proj-doc-builder/tools/__pycache__/normalize_markers.cpython-314.pyc +0 -0
- package/skills/proj-doc-builder/tools/__pycache__/phase4_exit.cpython-314.pyc +0 -0
- package/skills/proj-doc-builder/tools/__pycache__/project_docs_contract.cpython-314.pyc +0 -0
- package/skills/proj-doc-builder/tools/__pycache__/scan_dirs.cpython-314.pyc +0 -0
- 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
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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())
|