@walvka-code/proj-doc-builder 0.0.0-stage → 4.0.0
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/LICENSE +21 -0
- package/README.md +271 -2
- package/README.zh-CN.md +240 -0
- package/cordis.patch.yml +8 -0
- package/icon.svg +11 -0
- package/index.js +164 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +55 -4
- package/skills/proj-doc-builder/SKILL.md +350 -0
- package/skills/proj-doc-builder/references/audit_script.md +96 -0
- package/skills/proj-doc-builder/references/checklist.md +80 -0
- package/skills/proj-doc-builder/references/exclusions.md +79 -0
- package/skills/proj-doc-builder/references/linking.md +83 -0
- package/skills/proj-doc-builder/references/migration.md +32 -0
- package/skills/proj-doc-builder/references/phase4.md +200 -0
- package/skills/proj-doc-builder/references/templates.md +172 -0
- 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/tests/conftest.py +11 -0
- package/skills/proj-doc-builder/tests/test_claude_doc_index.py +157 -0
- package/skills/proj-doc-builder/tests/test_link_tools.py +279 -0
- package/skills/proj-doc-builder/tests/test_load_docs.py +248 -0
- package/skills/proj-doc-builder/tests/test_normalize_markers.py +120 -0
- package/skills/proj-doc-builder/tests/test_phase4_exit.py +3895 -0
- package/skills/proj-doc-builder/tests/test_project_docs_contract.py +781 -0
- package/skills/proj-doc-builder/tests/test_scan_dirs.py +1159 -0
- package/skills/proj-doc-builder/tests/test_sync_project_docs.py +2169 -0
- package/skills/proj-doc-builder/tests/test_validate_doc.py +555 -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
- package/skills/proj-doc-builder/tools/claude_doc_index.py +298 -0
- package/skills/proj-doc-builder/tools/compute_link.py +233 -0
- package/skills/proj-doc-builder/tools/link_check.py +152 -0
- package/skills/proj-doc-builder/tools/load_docs.py +380 -0
- package/skills/proj-doc-builder/tools/normalize_markers.py +205 -0
- package/skills/proj-doc-builder/tools/phase4/__init__.py +57 -0
- package/skills/proj-doc-builder/tools/phase4/cas_storage.py +18 -0
- package/skills/proj-doc-builder/tools/phase4/engine.py +20 -0
- package/skills/proj-doc-builder/tools/phase4/journal.py +22 -0
- package/skills/proj-doc-builder/tools/phase4/platform_handles.py +20 -0
- package/skills/proj-doc-builder/tools/phase4_exit.py +8459 -0
- package/skills/proj-doc-builder/tools/project_docs_contract.py +2318 -0
- package/skills/proj-doc-builder/tools/scan_dirs.py +2405 -0
- package/skills/proj-doc-builder/tools/sync_project_docs.py +3639 -0
- package/skills/proj-doc-builder/tools/validate_doc.py +1299 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 walvka-code
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,272 @@
|
|
|
1
|
-
#
|
|
1
|
+
# proj_doc_builder
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Turn a codebase into documentation an AI can actually read.** One command to build the outline,
|
|
4
|
+
one command to load it.
|
|
5
|
+
|
|
6
|
+
> **Language**: **English** (default) · [中文](README.zh-CN.md)
|
|
7
|
+
>
|
|
8
|
+
> `README.zh-CN.md` is a synced translation — update both together.
|
|
9
|
+
>
|
|
10
|
+
> Ships as a **DeepSeek Harness bundle** (`@walvka-code/proj-doc-builder`) **and** as a plain CLI.
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
# The skill directory: SKILL.md + tools/ live here
|
|
14
|
+
SKILL="$(pwd)/skills/proj-doc-builder"
|
|
15
|
+
|
|
16
|
+
# Sync: build/refresh the documentation index (preview first, then publish)
|
|
17
|
+
python "$SKILL/tools/sync_project_docs.py" . --dry-run --json
|
|
18
|
+
python "$SKILL/tools/sync_project_docs.py" . --apply --json
|
|
19
|
+
|
|
20
|
+
# Load: give a fresh conversation an entry point (overview → one document)
|
|
21
|
+
python "$SKILL/tools/load_docs.py" . --json
|
|
22
|
+
python "$SKILL/tools/load_docs.py" . --mode target --target src/core --json
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
What it does:
|
|
26
|
+
|
|
27
|
+
1. Keeps **one Markdown outline per source directory** (file inventory, key symbols, dependencies,
|
|
28
|
+
role in the system).
|
|
29
|
+
2. Remembers "what the tree looked like last time" via **content hashes + a manifest**, so the next
|
|
30
|
+
sync only touches directories that **actually changed**.
|
|
31
|
+
3. Publishes as a **recoverable transaction**; retiring a document is an explicit, evidence-gated
|
|
32
|
+
decision — never an automatic cleanup.
|
|
33
|
+
|
|
34
|
+
The stance, in one sentence: **"docs are in sync" must be backed by a manifest the tooling wrote,
|
|
35
|
+
not by the model that produced the prose.**
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Contents
|
|
40
|
+
|
|
41
|
+
- [Install](#install)
|
|
42
|
+
- [Repository layout](#repository-layout)
|
|
43
|
+
- [The two problems it solves](#the-two-problems-it-solves)
|
|
44
|
+
- [Guarantees](#guarantees)
|
|
45
|
+
- [The six-phase workflow](#the-six-phase-workflow)
|
|
46
|
+
- [Data model](#data-model)
|
|
47
|
+
- [Using the loader](#using-the-loader)
|
|
48
|
+
- [Platform support](#platform-support)
|
|
49
|
+
- [Tests](#tests)
|
|
50
|
+
- [Limitations and trade-offs](#limitations-and-trade-offs)
|
|
51
|
+
- [License](#license)
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Install
|
|
56
|
+
|
|
57
|
+
The repository is a **DeepSeek Harness bundle** that packages the skill, its Python tools and its
|
|
58
|
+
tests. Pick the install that fits your agent:
|
|
59
|
+
|
|
60
|
+
**Option 1 — DeepSeek Harness bundle (recommended)**
|
|
61
|
+
|
|
62
|
+
Add this market index under **Plugins → More → Custom plugin markets → Discover**, then install
|
|
63
|
+
`proj-doc-builder`:
|
|
64
|
+
|
|
65
|
+
```text
|
|
66
|
+
https://walvka-code.github.io/proj-doc-builder/index.json
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
(The same file is also served from `https://raw.githubusercontent.com/walvka-code/proj-doc-builder/main/index.json`,
|
|
70
|
+
but that host is unreachable from some networks; GitHub Pages is the primary address.)
|
|
71
|
+
|
|
72
|
+
Without the market, pin one commit (the bundle is a package directory in Git):
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
git+https://github.com/walvka-code/proj-doc-builder.git#<40-hex-commit>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
or install a local checkout with the `plugin_manager` tool:
|
|
79
|
+
|
|
80
|
+
```json
|
|
81
|
+
{ "action": "install_bundle", "target": "C:/path/to/proj-doc-builder" }
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The bundle mounts one bundled skill provider (rank 600): the skill is available in **every** session
|
|
85
|
+
of the profile, and a project-local `.dsh/skills/proj-doc-builder/` copy still wins when a repository
|
|
86
|
+
wants to pin its own version.
|
|
87
|
+
|
|
88
|
+
**Option 2 — as a project skill**
|
|
89
|
+
|
|
90
|
+
Copy `skills/proj-doc-builder/` to
|
|
91
|
+
`<project>/.dsh/skills/proj-doc-builder/`. `SKILL.md` resolves its tools through the skill directory
|
|
92
|
+
the host reports, so both layouts work unchanged.
|
|
93
|
+
|
|
94
|
+
**Option 3 — as a plain CLI** (no agent framework needed)
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
git clone <this-repo> proj-doc-builder
|
|
98
|
+
SKILL="$(pwd)/proj-doc-builder/skills/proj-doc-builder"
|
|
99
|
+
python "$SKILL/tools/sync_project_docs.py" /path/to/your/project --dry-run --json
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**Python 3.12+, zero third-party runtime dependencies** (standard library only).
|
|
103
|
+
Tests need `pytest` (see `requirements-dev.txt`).
|
|
104
|
+
|
|
105
|
+
Prerequisites: your project root needs a `project_docs/` directory and a `CLAUDE.md` entry point.
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Repository layout
|
|
110
|
+
|
|
111
|
+
```text
|
|
112
|
+
proj-doc-builder/
|
|
113
|
+
├── package.json # name / dsh.bundle.patch / engines
|
|
114
|
+
├── cordis.patch.yml # mounts the bundled skill provider
|
|
115
|
+
├── index.js # reads SKILL.md, registers the skill
|
|
116
|
+
├── index.json # plugin market index (format 1)
|
|
117
|
+
├── icon.svg / locale/ # bundle display metadata
|
|
118
|
+
├── skills/proj-doc-builder/ # SKILL.md + tools/ + references/ + tests/
|
|
119
|
+
├── scripts/check-bundle.mjs # offline bundle checks (CI)
|
|
120
|
+
└── .github/workflows/ci.yml
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## The two problems it solves
|
|
126
|
+
|
|
127
|
+
| # | Problem | What this repo gives you |
|
|
128
|
+
|---|---|---|
|
|
129
|
+
| **1** | You want to map an unfamiliar codebase quickly, and keep a baseline for "what changed since" | **Outline**: `project_docs/**/*.md`, one document per source directory. **Baseline**: `_scan_state.json` (per-file SHA-256 + directory fingerprints) plus the manifest's `generation_id` (content-only hash). Together they make the next sync **incremental** instead of a full rewrite. |
|
|
130
|
+
| **2** | You want a new AI conversation to load the project shape instead of re-reading source from scratch | **The loader ships in this repo**: `tools/load_docs.py` first verifies the manifest against the documents (per-file hashes + complete-set check), then serves either an **overview** (tree + metadata + section names) or a **single document / single section**. Writer and reader import the same contract, so the rules cannot drift apart. |
|
|
131
|
+
|
|
132
|
+
Why not just "have a model write a pile of `.md` files"? Because **the producer and the verifier must
|
|
133
|
+
be separate actors** — otherwise "the model says it's in sync" can never be falsified.
|
|
134
|
+
|
|
135
|
+
| Failure mode | Symptom | What this tool does |
|
|
136
|
+
|---|---|---|
|
|
137
|
+
| Drift | Source gained a file; the document's inventory is permanently one row short | Content-hash snapshot + worklist; only changed directories are rewritten |
|
|
138
|
+
| Unfalsifiable claims | "It's synced" with nothing to check | An independent manifest records size/SHA-256/title/status per document; mismatch is refused |
|
|
139
|
+
| Mass rewrite destroys history | Everything is rewritten just to pass validation | Only documents for changed directories block; unchanged history is audited, not rewritten |
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## Guarantees
|
|
144
|
+
|
|
145
|
+
| Guarantee | Mechanism |
|
|
146
|
+
|---|---|
|
|
147
|
+
| **No writes by default** | Without `--apply` everything is report-only; staging lives in the system temp dir, never in the project tree |
|
|
148
|
+
| **Single commit point** | The atomic replace of `project_docs/_manifest.json` is the only documentation-generation commit point |
|
|
149
|
+
| **Never clobbers concurrent writes** | Publication uses no-replace rename (Windows `os.rename`, Linux `renameat2(RENAME_NOREPLACE)`); a mismatched preimage aborts |
|
|
150
|
+
| **Failures are classified** | Only `NOT_INSTALLED` / `INSTALLED` / `UNKNOWN` / `PARTIALLY_INSTALLED` — never a fabricated "committed" |
|
|
151
|
+
| **Working copy stays clean** | Locks, transaction journals and CAS artifacts live in the temp dir; your VCS never sees them |
|
|
152
|
+
| **Deletion is a burden of proof** | A document is only quarantined when its source directory is proven gone, it has zero inbound links, carries the exact marker and is registered — and even then it is report-only by default |
|
|
153
|
+
| **Idempotent** | A zero-change run reports `planned_writes == []` and does not refresh `last_synced` |
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## The six-phase workflow
|
|
158
|
+
|
|
159
|
+
| Phase | Action | Key output |
|
|
160
|
+
|---|---|---|
|
|
161
|
+
| 0 | Preflight: project root, `project_docs/`, `CLAUDE.md`, no pending recovery | — |
|
|
162
|
+
| 1 | `--dry-run` yields change classes and a worklist | `scan.worklist.scaffold` (profile + precomputed relative links) |
|
|
163
|
+
| 2 | The **producer** writes prose per worklist entry and `--strict` validates each one | `project_docs/*.md` |
|
|
164
|
+
| 3 | Whole-tree dry-run (links, blockers, manifest coverage) | `validation.blocking_failures == []` |
|
|
165
|
+
| 4 | Retirement report: documents whose source is gone and unreferenced | `phase4.candidates` (report-only by default) |
|
|
166
|
+
| 5 | `--apply` publishes | manifest / CLAUDE tree / scan state |
|
|
167
|
+
| 6 | Terminal verification + read-only VCS scope check | `planned_writes == []` |
|
|
168
|
+
|
|
169
|
+
The coordinator **never generates natural language**: it validates and publishes; the prose is
|
|
170
|
+
written by the producer (a human or a model).
|
|
171
|
+
|
|
172
|
+
Exit codes: `0` all gates passed / `1` a gate failed (including "a transaction needs recovery") /
|
|
173
|
+
`2` input or runtime error / `3` publish failed (**not the same as "not published"** — read
|
|
174
|
+
`publish.disposition`).
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## Data model
|
|
179
|
+
|
|
180
|
+
| File | Purpose |
|
|
181
|
+
|---|---|
|
|
182
|
+
| `project_docs/_manifest.json` | Schema v2; per document `path/depth/title/status/bytes/sha256/synced_at`, plus `generation_id` (content-only, timestamps excluded) and `depth_counts` |
|
|
183
|
+
| `project_docs/_scan_state.json` | Source-tree snapshot (per-file SHA-256 + directory fingerprints): **this is the change-tracking baseline** that produces the next worklist |
|
|
184
|
+
| Six marker groups in `CLAUDE.md` | `doc-tree-instruction` / `project-overview` / `common-commands` / `architecture` / `test-structure` / `dependencies`. The tool **replaces only the first group**; the rest are only checked for unique, paired, non-overlapping markers |
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## Using the loader
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
# Overview: tree + per-document title/status/bytes/section names
|
|
192
|
+
# (defaults: 80 documents, 6 section names each)
|
|
193
|
+
python tools/load_docs.py . --json
|
|
194
|
+
python tools/load_docs.py . --limit 0 --sections 0 --json # every document, metadata only
|
|
195
|
+
|
|
196
|
+
# Target: a source directory, a document path, or a project-relative path
|
|
197
|
+
python tools/load_docs.py . --mode target --target src/core --json
|
|
198
|
+
python tools/load_docs.py . --mode target --target project_docs/src/core.md --json
|
|
199
|
+
|
|
200
|
+
# One section only
|
|
201
|
+
python tools/load_docs.py . --mode target --target src/core --section Dependencies --json
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
**Verify, then serve.** If the manifest disagrees with the documents (edited files, or an
|
|
205
|
+
unregistered document), the loader exits `1` with `manifest-stale` — it will not serve a stale index.
|
|
206
|
+
|
|
207
|
+
Exit codes: `0` verified and served / `1` stale index or unregistered target / `2` usage or
|
|
208
|
+
path-safety error (including `../` traversal).
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
## Platform support
|
|
213
|
+
|
|
214
|
+
| Platform | Status | Notes |
|
|
215
|
+
|---|---|---|
|
|
216
|
+
| **Windows** | ✅ Verified | Reparse-point/junction detection, handle-bound deletion (reclaims tombstones), `msvcrt` locks |
|
|
217
|
+
| **Linux** | ✅ Verified | `fcntl` locks, `dir_fd` + `O_NOFOLLOW` path walking, `renameat2(RENAME_NOREPLACE)`, directory `fsync` |
|
|
218
|
+
| **macOS** | ⚠️ Untested | A `renamex_np` branch exists but CI does not cover it; APFS case-insensitivity and `fsync` semantics are unverified |
|
|
219
|
+
|
|
220
|
+
Three things to know on Linux:
|
|
221
|
+
|
|
222
|
+
1. **`renameat2(RENAME_NOREPLACE)` is a hard requirement.** When unsupported, the tool raises
|
|
223
|
+
`NoReplaceRenameUnsupported` and **refuses** to fall back to a replacing rename — a silent
|
|
224
|
+
fallback would quietly break crash consistency.
|
|
225
|
+
2. **Directory `fsync` degrades instead of aborting.** Filesystems that reject it are recorded and
|
|
226
|
+
surfaced (`warnings.warn` plus a `durability-degraded` warning in the report); real I/O errors
|
|
227
|
+
still propagate.
|
|
228
|
+
3. **On POSIX, tombstones are archived, not deleted.** Retired transaction directories are renamed to
|
|
229
|
+
`.phase4-archive-*` and kept forever (there is no handle-bound `unlink`), so they accumulate and
|
|
230
|
+
need manual cleanup. Windows reclaims them.
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
## Tests
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
python -m pytest skills/proj-doc-builder/tests -q # the Python tools (360 cases)
|
|
238
|
+
npm test # the bundled provider + frontmatter reader
|
|
239
|
+
npm run check # manifest, patch, packaged files, market index
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
**360 tests** (Windows: 354 passed / 6 skipped; on Linux only the Windows-handle-semantics tests
|
|
243
|
+
flip to skipped). Everything runs in `tmp_path` — your real `project_docs/` is never touched. They
|
|
244
|
+
pin **crash consistency**, not features:
|
|
245
|
+
|
|
246
|
+
- a failure before the manifest commit must roll back completely; after it, only
|
|
247
|
+
`installed/partial/unknown` may be reported and rollback is forbidden
|
|
248
|
+
- `KeyboardInterrupt` injected before and after every rename
|
|
249
|
+
- forged journal slots, ABA races, documents modified concurrently during staging
|
|
250
|
+
- unavailable `renameat2` → typed failure; rejected directory `fsync` → visible degradation
|
|
251
|
+
(CI runs a dedicated container/overlayfs job for both)
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
## Limitations and trade-offs
|
|
256
|
+
|
|
257
|
+
- Journal and CAS artifact directories must live on **the same filesystem** as the project root
|
|
258
|
+
(cross-volume setups make `--apply` refuse).
|
|
259
|
+
- Path whitelist: relative POSIX, lowercase `.md` only; absolute paths, drive letters, backslashes,
|
|
260
|
+
`..`, ADS, reserved device names and case-only conflicts are rejected.
|
|
261
|
+
- **Symlinks, junctions and reparse points are never followed**; when path identity cannot be proven,
|
|
262
|
+
the tool fails closed.
|
|
263
|
+
- `--full` is only the scanner's `force_full` switch — it is **not** "reconcile every document's file
|
|
264
|
+
inventory"; that remains a producer step.
|
|
265
|
+
- Document retirement is a **burden-of-proof flow**, not a cleanup utility: report-only by default,
|
|
266
|
+
`--apply` requires explicit authorization.
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
## License
|
|
271
|
+
|
|
272
|
+
[MIT](LICENSE)
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
# proj_doc_builder
|
|
2
|
+
|
|
3
|
+
**把工程变成 AI 读得懂的文档索引。** 一条命令生成大纲,一条命令加载概况。
|
|
4
|
+
|
|
5
|
+
> **语言**:[English](README.md)(默认)· **中文**
|
|
6
|
+
>
|
|
7
|
+
> 英文是默认版本;本文件为同步翻译,改内容时两版一起改。
|
|
8
|
+
>
|
|
9
|
+
> 同时提供 **DeepSeek Harness bundle**(`@walvka-code/proj-doc-builder`)与普通 CLI 两种用法。
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# 技能目录:SKILL.md 与 tools/ 都在这里
|
|
13
|
+
SKILL="$(pwd)/skills/proj-doc-builder"
|
|
14
|
+
|
|
15
|
+
# 同步:生成/更新文档索引(先看,不写盘 → 确认后发布)
|
|
16
|
+
python "$SKILL/tools/sync_project_docs.py" . --dry-run --json
|
|
17
|
+
python "$SKILL/tools/sync_project_docs.py" . --apply --json
|
|
18
|
+
|
|
19
|
+
# 加载:给新对话一个入口(概览 → 定位到某一份)
|
|
20
|
+
python "$SKILL/tools/load_docs.py" . --json
|
|
21
|
+
python "$SKILL/tools/load_docs.py" . --mode target --target src/core --json
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
它做的三件事:
|
|
25
|
+
|
|
26
|
+
1. 为**每个源码目录**维护一份 Markdown 大纲(文件清单 / 关键符号 / 依赖关系 / 系统角色)。
|
|
27
|
+
2. 用**内容哈希 + manifest** 记住"上次同步时的样子",所以下一次只处理**真正变化**的目录。
|
|
28
|
+
3. 发布是**可回滚事务**;退役文档需要单独举证,不会自动删除。
|
|
29
|
+
|
|
30
|
+
一句话立场:**文档"已同步"必须由工具写下的 manifest 背书,而不是由生成它的模型自述。**
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## 目录
|
|
35
|
+
|
|
36
|
+
- [安装](#安装)
|
|
37
|
+
- [仓库布局](#仓库布局)
|
|
38
|
+
- [它解决的两个问题](#它解决的两个问题)
|
|
39
|
+
- [核心保证](#核心保证)
|
|
40
|
+
- [工作流六阶段](#工作流六阶段)
|
|
41
|
+
- [数据模型](#数据模型)
|
|
42
|
+
- [加载器用法](#加载器用法)
|
|
43
|
+
- [平台支持](#平台支持)
|
|
44
|
+
- [测试](#测试)
|
|
45
|
+
- [限制与取舍](#限制与取舍)
|
|
46
|
+
- [License](#license)
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## 安装
|
|
51
|
+
|
|
52
|
+
本仓本身是一个 **DeepSeek Harness bundle**,把技能、Python 工具和测试一起打包。按你的 agent 选一种:
|
|
53
|
+
|
|
54
|
+
**方式一:DSH bundle(推荐)**
|
|
55
|
+
|
|
56
|
+
在 **Plugins → More → 开启 Custom plugin markets → Discover** 里加入本仓的索引地址,然后安装
|
|
57
|
+
`proj-doc-builder`:
|
|
58
|
+
|
|
59
|
+
```text
|
|
60
|
+
https://walvka-code.github.io/proj-doc-builder/index.json
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
(同一份索引也发布在 `https://raw.githubusercontent.com/walvka-code/proj-doc-builder/main/index.json`,
|
|
64
|
+
但部分网络无法直连该域名;以 GitHub Pages 地址为准。)
|
|
65
|
+
|
|
66
|
+
不用市场时,可直接钉住某个 commit(bundle 是仓库里的一个包目录):
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
git+https://github.com/walvka-code/proj-doc-builder.git#<40 位 commit>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
或用 `plugin_manager` 装本地检出:
|
|
73
|
+
|
|
74
|
+
```json
|
|
75
|
+
{ "action": "install_bundle", "target": "C:/path/to/proj-doc-builder" }
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
bundle 挂载一个 bundled 技能提供方(rank 600):技能在 profile 的**所有会话**里可用;若某个项目自带
|
|
79
|
+
`.dsh/skills/proj-doc-builder/`,项目副本优先(用于钉住版本)。
|
|
80
|
+
|
|
81
|
+
**方式二:作为项目技能**
|
|
82
|
+
|
|
83
|
+
把 `skills/proj-doc-builder/` 复制到
|
|
84
|
+
`<project>/.dsh/skills/proj-doc-builder/`。`SKILL.md` 用宿主报告的技能目录解析工具路径,
|
|
85
|
+
两种布局都成立。
|
|
86
|
+
|
|
87
|
+
**方式三:当普通 CLI 用**(不需要任何 agent 框架)
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
git clone <this-repo> proj-doc-builder
|
|
91
|
+
SKILL="$(pwd)/proj-doc-builder/skills/proj-doc-builder"
|
|
92
|
+
python "$SKILL/tools/sync_project_docs.py" /path/to/your/project --dry-run --json
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**Python 3.12+,运行时零第三方依赖**(仅标准库)。测试需要 `pytest`(见 `requirements-dev.txt`)。
|
|
96
|
+
|
|
97
|
+
前置条件:你的项目根要有 `project_docs/` 与 `CLAUDE.md` 两个入口。
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## 仓库布局
|
|
102
|
+
|
|
103
|
+
```text
|
|
104
|
+
proj-doc-builder/
|
|
105
|
+
├── package.json # name / dsh.bundle.patch / engines
|
|
106
|
+
├── cordis.patch.yml # 挂载 bundled 技能提供方
|
|
107
|
+
├── index.js # 读取 SKILL.md 并注册技能
|
|
108
|
+
├── index.json # 插件市场索引(format 1)
|
|
109
|
+
├── icon.svg / locale/ # bundle 展示元数据
|
|
110
|
+
├── skills/proj-doc-builder/ # SKILL.md + tools/ + references/ + tests/
|
|
111
|
+
├── scripts/check-bundle.mjs # 离线 bundle 自检(CI)
|
|
112
|
+
└── .github/workflows/ci.yml
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## 它解决的两个问题
|
|
118
|
+
|
|
119
|
+
| # | 问题 | 本仓给出的答案 |
|
|
120
|
+
|---|---|---|
|
|
121
|
+
| **1** | 想快速梳理一个陌生工程,并留下"后续改了什么"的跟踪基线 | **大纲**:`project_docs/**/*.md`,每个源码目录一份。**基线**:`_scan_state.json`(逐文件 SHA-256 + 目录 fingerprint)与 `_manifest.json` 的 `generation_id`(只哈希内容)。两者合起来让下一次同步**只处理真正变化的目录**,而不是全量重写。 |
|
|
122
|
+
| **2** | 想让新开的 AI 对话快速加载工程概况,而不是每次从零读源码 | **加载器就在本仓**:`tools/load_docs.py` 先校验 manifest 与文档完全一致(逐份 hash + 集合完整),再输出**概览**(目录树 + 元数据 + 小节名)或**单份文档 / 单节**。写侧与读侧共用同一契约,不会各写一套解析而漂移。 |
|
|
123
|
+
|
|
124
|
+
为什么不是"让模型写一堆 md":**生成者和校验者必须是两个执行体**,否则"模型说已同步"永远无法被证伪。
|
|
125
|
+
|
|
126
|
+
| 崩点 | 表现 | 本工具的应对 |
|
|
127
|
+
|---|---|---|
|
|
128
|
+
| 漂移 | 源码加了文件,文档"文件清单"永远少一行 | 内容哈希快照 + 变更工作清单,只重写变化的目录 |
|
|
129
|
+
| 自证不可信 | 模型说"已同步",你无法复核 | 独立 manifest 记录每份文档的 size/SHA-256/title/status,不一致即拒绝 |
|
|
130
|
+
| 批量翻新毁历史 | 为过校验把所有历史文档重写一遍 | 只有"本轮变化"的文档是阻断项;历史文档只审计、不改写 |
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## 核心保证
|
|
135
|
+
|
|
136
|
+
| 保证 | 机制 |
|
|
137
|
+
|---|---|
|
|
138
|
+
| **默认零写入** | 不带 `--apply` 一律只报告;staging 在系统临时目录,不在项目树建路径 |
|
|
139
|
+
| **单一提交点** | `project_docs/_manifest.json` 的那一次原子替换是文档代际的唯一 commit point |
|
|
140
|
+
| **不覆盖并发写入** | 发布用 no-replace rename(Windows `os.rename` / Linux `renameat2(RENAME_NOREPLACE)`),前置镜像不符即拒绝 |
|
|
141
|
+
| **失败必须分类** | 只报 `NOT_INSTALLED` / `INSTALLED` / `UNKNOWN` / `PARTIALLY_INSTALLED`,绝不虚构"已提交" |
|
|
142
|
+
| **不污染工作副本** | 锁、事务 journal、CAS 产物全在系统临时目录,版本控制里看不到 |
|
|
143
|
+
| **删除是举证而非清理** | 只在"源码目录确认消失 + 零入站引用 + 精确 marker + 已注册"时生成隔离候选,且默认只报告 |
|
|
144
|
+
| **幂等** | 零变化运行时 `planned_writes == []`,不刷新 `last_synced` |
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## 工作流六阶段
|
|
149
|
+
|
|
150
|
+
| Phase | 动作 | 关键产物 |
|
|
151
|
+
|---|---|---|
|
|
152
|
+
| 0 | 预检:项目根、`project_docs/`、`CLAUDE.md`、无待恢复事务 | — |
|
|
153
|
+
| 1 | `--dry-run` 得到变化分类与工作清单 | `scan.worklist.scaffold`(推荐 profile + 预计算相对链接) |
|
|
154
|
+
| 2 | **生成方**按工作清单写正文并逐份 `--strict` 校验 | `project_docs/*.md` |
|
|
155
|
+
| 3 | 全局 dry-run 闭环(断链、阻断、manifest 覆盖面) | `validation.blocking_failures == []` |
|
|
156
|
+
| 4 | 退役报告:哪些文档的源码已消失且零引用 | `phase4.candidates`(默认只报告) |
|
|
157
|
+
| 5 | `--apply` 发布 | manifest / CLAUDE 文档树 / scan state |
|
|
158
|
+
| 6 | 终验 + 版本控制只读范围检查 | `planned_writes == []` |
|
|
159
|
+
|
|
160
|
+
**协调器不生成任何自然语言**:它只做校验与事务发布,正文由生成方(人或模型)写入。
|
|
161
|
+
|
|
162
|
+
退出码:`0` 全过 / `1` 闸门失败(含"存在待恢复事务")/ `2` 输入或运行错误 / `3` 发布失败(**不等于未发布**,以 `publish.disposition` 为准)。
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## 数据模型
|
|
167
|
+
|
|
168
|
+
| 文件 | 作用 |
|
|
169
|
+
|---|---|
|
|
170
|
+
| `project_docs/_manifest.json` | schema v2,每份文档记录 `path/depth/title/status/bytes/sha256/synced_at`,并给出 `generation_id`(只哈希内容,不含时间戳)与 `depth_counts` |
|
|
171
|
+
| `project_docs/_scan_state.json` | 源码目录快照(逐文件 SHA-256 + 目录 fingerprint):**这是"改动跟踪基线"**,决定下一轮 worklist |
|
|
172
|
+
| `CLAUDE.md` 六组 marker | `doc-tree-instruction` / `project-overview` / `common-commands` / `architecture` / `test-structure` / `dependencies`。工具**只替换第一组**,其余仅校验 marker 唯一、成对、不交叠 |
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## 加载器用法
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
# 概览:树 + 每份文档的 title/status/字节数/小节名(默认 80 份、每份 6 个小节名)
|
|
180
|
+
python "$SKILL/tools/load_docs.py" . --json
|
|
181
|
+
python "$SKILL/tools/load_docs.py" . --limit 0 --sections 0 --json # 全部文档、只要元数据
|
|
182
|
+
|
|
183
|
+
# 定位:源码目录 / 文档路径 / 工程相对路径都可以
|
|
184
|
+
python "$SKILL/tools/load_docs.py" . --mode target --target src/core --json
|
|
185
|
+
python "$SKILL/tools/load_docs.py" . --mode target --target project_docs/src/core.md --json
|
|
186
|
+
|
|
187
|
+
# 只要某一节
|
|
188
|
+
python "$SKILL/tools/load_docs.py" . --mode target --target src/core --section 依赖关系 --json
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
**先校验再加载**:manifest 与磁盘文档不一致(被改过、或多出未注册文档)时退出 `1` 并报 `manifest-stale`,绝不在陈旧索引上服务。
|
|
192
|
+
|
|
193
|
+
退出码:`0` 已校验可服务 / `1` 索引陈旧或目标未注册 / `2` 用法或路径安全问题(含 `../` 越界)。
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## 平台支持
|
|
198
|
+
|
|
199
|
+
| 平台 | 状态 | 说明 |
|
|
200
|
+
|---|---|---|
|
|
201
|
+
| **Windows** | ✅ 已验证 | 重解析点/junction 识别、句柄级删除(可回收墓碑)、`msvcrt` 锁 |
|
|
202
|
+
| **Linux** | ✅ 已验证 | `fcntl` 锁、`dir_fd` 逐级 `O_NOFOLLOW` 走查、`renameat2(RENAME_NOREPLACE)`、目录 `fsync` |
|
|
203
|
+
| **macOS** | ⚠️ 未验证 | 有 `renamex_np` 分支但无 CI;APFS 大小写不敏感与 `fsync` 语义差异未取证 |
|
|
204
|
+
|
|
205
|
+
Linux 上必须知道的三条:
|
|
206
|
+
|
|
207
|
+
1. **`renameat2(RENAME_NOREPLACE)` 是硬依赖。** 不支持时抛 `NoReplaceRenameUnsupported` 并**明确拒绝**回退到会覆盖的 `rename`——覆盖会静默破坏崩溃一致性。
|
|
208
|
+
2. **目录 `fsync` 被拒时降级不中断。** 跳过并显式暴露(`warnings.warn` + 报告 `durability-degraded`);真实 I/O 错误仍上抛。
|
|
209
|
+
3. **POSIX 下墓碑只归档不删除。** 退役事务目录改名为 `.phase4-archive-*` 永久保留(无句柄绑定 unlink),需人工清理;Windows 可回收。
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## 测试
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
python -m pytest skills/proj-doc-builder/tests -q
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
**360 个用例**(Windows:354 passed / 6 skipped;Linux 差异仅在于"Windows 句柄语义"用例反向跳过),全部使用 `tmp_path`,不触碰真实 `project_docs/`。锁定的不是"功能"而是**崩溃一致性**:
|
|
220
|
+
|
|
221
|
+
- manifest 之前失败必须完整回滚;之后失败只准报 `installed/partial/unknown`,禁止回滚
|
|
222
|
+
- `KeyboardInterrupt` 落在每一个 rename 前后的落点
|
|
223
|
+
- 伪造 journal 槽位、ABA 竞态、staging 期间文档被并发修改
|
|
224
|
+
- `renameat2` 不可用 → 类型化失败;目录 `fsync` 被拒 → 降级且可见(CI 有专门的容器/overlayfs 作业)
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## 限制与取舍
|
|
229
|
+
|
|
230
|
+
- 事务 journal 与 CAS 产物目录必须与项目根**同一文件系统**(跨盘会让 `--apply` 直接拒绝)。
|
|
231
|
+
- 路径白名单:只接受相对 POSIX、小写 `.md`;拒绝绝对路径、盘符、反斜杠、`..`、ADS、保留设备名与大小写冲突。
|
|
232
|
+
- **不跟随** symlink / junction / reparse point;路径身份无法证明时一律拒绝。
|
|
233
|
+
- `--full` 只是扫描器的 `force_full` 开关,**不等于**"逐份文档盘点文件清单"。
|
|
234
|
+
- 文档退役是**举证流程**,不是清理工具:默认只报告,`--apply` 需另行明确授权。
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
## License
|
|
239
|
+
|
|
240
|
+
[MIT](LICENSE)
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# proj-doc-builder bundle patch.
|
|
2
|
+
#
|
|
3
|
+
# One row: the bundled skill provider of this package. It registers the
|
|
4
|
+
# `proj-doc-builder` skill on `ctx.skills` at the bundled rank (600), so a
|
|
5
|
+
# project-local `.dsh/skills/proj-doc-builder/` copy still wins when present.
|
|
6
|
+
- insert:
|
|
7
|
+
- id: proj-doc-builder-skill
|
|
8
|
+
name: "@walvka-code/proj-doc-builder"
|
package/icon.svg
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<svg width="36" height="36" viewBox="0 0 36 36" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<rect x="2" y="2" width="32" height="32" rx="9" fill="#E7F0EE" />
|
|
3
|
+
<path d="M12 8.75h7.2L23.5 13v13.25A1.75 1.75 0 0 1 21.75 28h-9.5A1.75 1.75 0 0 1 10.5 26.25V10.5A1.75 1.75 0 0 1 12.25 8.75Z" fill="#2F6F6B" />
|
|
4
|
+
<path d="M19.2 8.75V13h4.3" fill="#9CCFC8" />
|
|
5
|
+
<rect x="13" y="16" width="7" height="1.6" rx="0.8" fill="#E7F0EE" />
|
|
6
|
+
<rect x="13" y="19.4" width="7" height="1.6" rx="0.8" fill="#E7F0EE" />
|
|
7
|
+
<rect x="13" y="22.8" width="4.6" height="1.6" rx="0.8" fill="#E7F0EE" />
|
|
8
|
+
<path d="M24.9 19.1a3.6 3.6 0 0 1 0 5.1" stroke="#2F6F6B" stroke-width="1.7" stroke-linecap="round" />
|
|
9
|
+
<path d="M26.6 23.1l-1.7 1.2-1.2-1.7" stroke="#2F6F6B" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" />
|
|
10
|
+
<path d="M28.1 25.4a3.6 3.6 0 0 1-3.1 2.1" stroke="#2F6F6B" stroke-width="1.7" stroke-linecap="round" />
|
|
11
|
+
</svg>
|