Skip to content

Commit 12a700e

Browse files
committed
refactor: 用 DocGit 替换自定义版本系统 + Arranger 模块化拆分
- 移除自定义的 VersionMismatchError / HistoryEntry / Snapshot 版本追踪,改用 git 管理文档变更(DocGit: status/commit/blame) - Arranger 从单文件拆分为 agentFactory / graphStore / pipeline / promptBuilder / runtime 等独立模块 - 简化 MCP mutation tools,移除 baseVersion 参数 - 新增 DocGitPanel 前端组件,移除 ConflictDialog / DiffView / HistoryPanel - 新增项目级文档锁 docLock.ts
1 parent 6329257 commit 12a700e

46 files changed

Lines changed: 3116 additions & 2562 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AGENTS.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pnpm monorepo with two packages: root (backend) and `web/` (frontend).
1717

1818
### Backend: 4-Agent Pipeline
1919

20-
The system generates interactive documentation for any code repository using a pipeline of 4 Codex agents orchestrated by the **Arranger** state machine:
20+
The system generates interactive documentation for any code repository using a pipeline of 4 agent roles orchestrated by the **Arranger** state machine:
2121

2222
```
2323
Scaffold → Checker → [per-module loop: Decomposer → Checker → Writer] → done
@@ -28,7 +28,7 @@ Scaffold → Checker → [per-module loop: Decomposer → Checker → Writer]
2828
- **Writer**: Generates Markdown documentation for leaf `page` nodes
2929
- **Checker**: Validates graph structures from Scaffold and Decomposer (not Writer output); failures trigger retry via `agent.continue()`
3030
31-
Each agent has both a Codex and Codex backend implementation, located in `src/agents/tsukai/` (e.g. `claudescaffold.ts` / `codexscaffold.ts`). All share identical interface: `run(prompt, workpath)`, `continue(prompt)`, `restore(sessionId, workpath)`, `getSessionId()`. A barrel file `src/agents/tsukai/index.ts` re-exports all classes.
31+
Each agent has both a Claude Code and Codex backend implementation, located in `src/agents/tsukai/` (e.g. `claudescaffold.ts` / `codexscaffold.ts`). All share identical interface: `run(prompt, workpath)`, `continue(prompt)`, `restore(sessionId, workpath)`, `getSessionId()`. A barrel file `src/agents/tsukai/index.ts` re-exports all classes.
3232
3333
### Arranger (`src/workflow/arranger.ts`)
3434
@@ -45,7 +45,7 @@ All data structures use Zod schemas. The `Graph` type includes `decomposerSessio
4545
4646
### Incremental Update Pipeline (`src/workflow/updateOrchestrator.ts`)
4747
48-
After initial generation, per-PR documentation updates are handled by the **PrUpdater** agent (Codex or Codex backend, `src/agents/tsukai/claudeprupdater.ts` / `codexprupdater.ts`). The orchestrator:
48+
After initial generation, per-PR documentation updates are handled by the **PrUpdater** agent (Claude Code or Codex backend, `src/agents/tsukai/claudeprupdater.ts` / `codexprupdater.ts`). The orchestrator:
4949
5050
1. Discovers new merged PRs via `gh pr list` (fallback: `git log --first-parent`), sorted oldest-first by `mergedAt`
5151
2. Queues them as `TaskItem`s and processes sequentially under a per-project lock
@@ -63,10 +63,10 @@ API endpoints: `POST /api/update/{start,continue,skip,cancel}`, `POST /api/updat
6363
6464
The `autodoc` MCP server exposes tools for agents to read/write doc artifacts:
6565
66-
- **Query tools** (`src/mcp/tools/query.ts`): `list_projects`, `get_top`, `get_graph`, `get_page`, `search_nodes`, `list_source_files`, `read_source_files`, `list_docs`, `read_docs`, `list_history`, `get_history`
67-
- **Mutation tools** (`src/mcp/tools/mutate.ts`): `patch_page` (string match + replace), `update_page`, `update_node`, `update_graph_meta`, `create_node`, `delete_node` (preserves `.history` via `.tombstones/`), `update_top`, `revert`
66+
- **Query tools** (`src/mcp/tools/query.ts`): `list_projects`, `get_top`, `get_graph`, `get_page`, `search_nodes`, `list_source_files`, `read_source_files`, `list_docs`, `read_docs`
67+
- **Mutation tools** (`src/mcp/tools/mutate.ts`): `patch_page` (string match + replace), `update_page`, `update_node`, `update_graph_meta`, `create_node`, `delete_node`, `update_top`
6868
69-
All write tools enforce optimistic locking via `baseVersion` (must match current `version` from read tools). The doc-drill skill template at `src/skill-template/SKILL.md` documents these tools for agent consumption.
69+
All write tools share the project-level document lock and only dirty the documentation working tree. Users commit accumulated doc changes manually through `/api/doc-git/commit`; blame data comes from `/api/doc-git/blame`. The doc-drill skill template at `src/skill-template/SKILL.md` documents the MCP tools for agent consumption.
7070
7171
### Frontend: Vue 3 + TypeScript
7272
@@ -101,4 +101,4 @@ Project matching: `path.basename(repoPath)` maps to `web/doc/{name}/`. Re-runnin
101101
- The `codeScope` field on graph nodes tracks which source files/directories each module covers; child scopes must be subsets of parent scopes
102102
- `CheckerIssueType` enum: `broken-target`, `empty-content`, `invalid-path`
103103
- Task status lifecycle: `idle → running → done` (auto) or `idle → running → awaiting-review → done` (manual, with optional follow-up loops back to running)
104-
- Runtime logs go to `log/{project}.txt` (gitignored); JSONL mutation history in `src/souko/updateLog.ts`
104+
- Runtime logs go to `log/{project}.txt` (gitignored); PR update reports are appended through `src/souko/updateLog.ts`

CLAUDE.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ API endpoints: `POST /api/update/{start,continue,skip,cancel}`, `POST /api/updat
6363
6464
The `autodoc` MCP server exposes tools for agents to read/write doc artifacts:
6565
66-
- **Query tools** (`src/mcp/tools/query.ts`): `list_projects`, `get_top`, `get_graph`, `get_page`, `search_nodes`, `list_source_files`, `read_source_files`, `list_docs`, `read_docs`, `list_history`, `get_history`
67-
- **Mutation tools** (`src/mcp/tools/mutate.ts`): `patch_page` (string match + replace), `update_page`, `update_node`, `update_graph_meta`, `create_node`, `delete_node` (preserves `.history` via `.tombstones/`), `update_top`, `revert`
66+
- **Query tools** (`src/mcp/tools/query.ts`): `list_projects`, `get_top`, `get_graph`, `get_page`, `search_nodes`, `list_source_files`, `read_source_files`, `list_docs`, `read_docs`
67+
- **Mutation tools** (`src/mcp/tools/mutate.ts`): `patch_page` (string match + replace), `update_page`, `update_node`, `update_graph_meta`, `create_node`, `delete_node`, `update_top`
6868
69-
All write tools enforce optimistic locking via `baseVersion` (must match current `version` from read tools). The doc-drill skill template at `src/skill-template/SKILL.md` documents these tools for agent consumption.
69+
All write tools share the project-level document lock and only dirty the documentation working tree. Users commit accumulated doc changes manually through `/api/doc-git/commit`; blame data comes from `/api/doc-git/blame`. The doc-drill skill template at `src/skill-template/SKILL.md` documents the MCP tools for agent consumption.
7070
7171
### Frontend: Vue 3 + TypeScript
7272
@@ -101,4 +101,4 @@ Project matching: `path.basename(repoPath)` maps to `web/doc/{name}/`. Re-runnin
101101
- The `codeScope` field on graph nodes tracks which source files/directories each module covers; child scopes must be subsets of parent scopes
102102
- `CheckerIssueType` enum: `broken-target`, `empty-content`, `invalid-path`
103103
- Task status lifecycle: `idle → running → done` (auto) or `idle → running → awaiting-review → done` (manual, with optional follow-up loops back to running)
104-
- Runtime logs go to `log/{project}.txt` (gitignored); JSONL mutation history in `src/souko/updateLog.ts`
104+
- Runtime logs go to `log/{project}.txt` (gitignored); PR update reports are appended through `src/souko/updateLog.ts`

README.en.md

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Paste a git URL in the frontend and generation begins. **For the full onboarding
7373

7474
### Codex Profile Configuration
7575

76-
The Codex backend uses [profiles](https://developers.openai.com/codex/config-reference) per Agent role to isolate model parameters. Add one profile per role to `~/.codex/config.toml`. Names must be exactly `scaffold`, `decomposer`, `writer`, `checker`, `flowanalyzer`, `updater`:
76+
The Codex backend uses [profiles](https://developers.openai.com/codex/config-reference) per Agent role to isolate model parameters. Add one profile per role to `~/.codex/config.toml`. Names must be exactly `scaffold`, `decomposer`, `writer`, `checker`, `flowanalyzer`, `prupdater`, `knowledge`:
7777

7878
```toml
7979
[profiles.scaffold]
@@ -96,9 +96,13 @@ model_reasoning_effort = "high"
9696
model = "gpt-5.4"
9797
model_reasoning_effort = "medium"
9898

99-
[profiles.updater]
99+
[profiles.prupdater]
100100
model = "gpt-5.4"
101101
model_reasoning_effort = "high"
102+
103+
[profiles.knowledge]
104+
model = "gpt-5.4"
105+
model_reasoning_effort = "medium"
102106
```
103107

104108
Replace models or tweak `model_reasoning_effort` / `service_tier` as needed. See the official [Config Reference](https://developers.openai.com/codex/config-reference) for all keys.
@@ -185,7 +189,7 @@ Each Agent role independently uses **Claude** (Claude Agent SDK) or **Codex** (O
185189
- **🔗 One-step git URL ingestion** — paste an SSH/HTTPS git URL; backend auto-clones, tracks the main branch head, keeps everything under `src/souko/`
186190
- **🔁 Per-PR incremental updates** — discovers all newly merged PRs via `gh pr list` (or `git log` fallback) and PrUpdater Agent navigates docs via MCP tools for targeted edits. Auto mode runs hands-free; Manual mode adds a review gate with session continuation for iterative refinement
187191
- **🛰️ HTTP MCP server** — same-process `/mcp` endpoint (Streamable HTTP) exposes the full query + mutate toolset for direct Code Agent access
188-
- **📜 Document version control**every write carries optimistic locking (`baseVersion`) and snapshots to `.history/{file}.v{n}`; `revert` restores any historical version
192+
- **📜 Manual Git commits and blame**doc writes only create uncommitted changes; the Git panel shows dirty status, commits manually, and surfaces Git blame in preview/editing views
189193
- **🔗 Interactive directed graphs**[AntV G6](https://g6.antv.antgroup.com/) with 6 semantic edge types (calls, depends, data-flow, event, extends, composes) and hover popovers
190194
- **🔍 Progressive disclosure** — start at the top-level overview, drill into nodes down to leaf Markdown
191195
- **🔄 Interaction flow diagrams** — cross-module business flows auto-extracted and rendered as sequence diagrams with participants, steps, and code references
@@ -199,7 +203,7 @@ Each Agent role independently uses **Claude** (Claude Agent SDK) or **Codex** (O
199203

200204
The backend exposes an MCP server named `autodoc` at `http://localhost:3100/mcp` as a stateless Streamable HTTP transport. All tools operate on real files under `src/souko/doc/{project}/`.
201205

202-
### Wire it up in Claude Code
206+
### Wire it up in Claude Code / Codex
203207

204208
Drop an `.mcp.json` into the target repo root:
205209

@@ -214,6 +218,14 @@ Drop an `.mcp.json` into the target repo root:
214218
}
215219
```
216220

221+
Codex uses project-scoped `.codex/config.toml`; autoDoc writes the equivalent config when assembling the skill:
222+
223+
```toml
224+
[mcp_servers.autodoc]
225+
url = "http://localhost:3100/mcp"
226+
enabled_tools = ["list_projects", "get_top", "get_graph", "get_page", "search_nodes", "list_source_files", "read_source_files", "list_docs", "read_docs", "patch_page", "update_page", "update_node", "update_graph_meta", "create_node", "delete_node", "update_top"]
227+
```
228+
217229
The matching [doc-drill skill](src/skill-template/SKILL.md) is a thin instruction set that only describes **how to call the MCP tools**, and ships with autoDoc.
218230

219231
### Tool list
@@ -222,15 +234,15 @@ The matching [doc-drill skill](src/skill-template/SKILL.md) is a thin instructio
222234

223235
| Tool | Purpose |
224236
|---|---|
225-
| `list_projects` | List all registered projects (with sourceUrl / head / lastUpdated) |
226-
| `get_top` | Read a project's top.json (with `version`) |
227-
| `get_graph` | Read a sub-graph (with `version` and the `pageVersions` map) |
228-
| `get_page` | Read a leaf Markdown page (with its `version`) |
237+
| `list_projects` | List available doc projects (name / description) |
238+
| `get_top` | Read a project's top.json |
239+
| `get_graph` | Read a sub-graph with `codeScope`, `nodes`, and `description` |
240+
| `get_page` | Read a leaf Markdown page |
229241
| `search_nodes` | Search node names/descriptions across all levels |
230-
| `list_history` | List all historical versions of a file |
231-
| `get_history` | Read a specific historical version |
242+
| `list_source_files` / `read_source_files` | Locate and read source files by regex |
243+
| `list_docs` / `read_docs` | Batch-list/read raw docs by nodeId |
232244

233-
#### Mutate (optimistic lock via `baseVersion`)
245+
#### Mutate (serialized by project lock)
234246

235247
| Tool | Purpose |
236248
|---|---|
@@ -240,10 +252,9 @@ The matching [doc-drill skill](src/skill-template/SKILL.md) is a thin instructio
240252
| `update_node` | Update a node's name / description / codeScope / edges in its parent graph |
241253
| `delete_node` | Remove a node from its parent graph (page deletes the md; graph recursively deletes its subtree) |
242254
| `patch_page` | Targeted string-match-and-replace edits to a leaf md, more efficient and safer than update_page |
243-
| `update_page` | Overwrite a leaf md; uses `pageVersions[ref]` as baseVersion |
244-
| `revert` | Write a historical version back as a new version, keeping intermediate versions intact |
255+
| `update_page` | Overwrite a leaf md |
245256

246-
Write flow: **read → obtain version → write with baseVersionserver snapshots the old version to `.history/` → version+1 → persist**. A version mismatch returns `VersionMismatch` so the client re-reads and retries.
257+
Write flow: **read → mutate tools dirty the working treereview dirty status in the frontend Git panel → user commits manually**. Mutate tools no longer accept `baseVersion` and never auto-commit; concurrent writes are serialized by the project-level lock.
247258

248259
> ⚠️ `/mcp` is unauthenticated and CORS-open by default. Add access control or bind to loopback before production use.
249260
@@ -263,7 +274,6 @@ src/souko/
263274
│ ├── flows.json
264275
│ ├── {Module}/
265276
│ │ ├── {Module}.json
266-
│ │ ├── .history/ # Historical snapshots
267277
│ │ ├── {Leaf}.md
268278
│ │ └── {SubModule}/...
269279
│ └── ...
@@ -274,19 +284,19 @@ src/souko/
274284

275285
Each module's documentation is a self-contained unit. Three ways to edit it:
276286

277-
- **Via MCP tools** (recommended): `update_node` / `update_page` / `create_node` / `delete_node`automatic version tracking and history snapshots; ideal for Code Agents
278-
- **Direct file edits**: edit `.md` / `.json` under `src/souko/doc/{project}/`; restart the server to pick it up (bypasses version control)
287+
- **Via MCP tools** (recommended): `update_node` / `update_page` / `create_node` / `delete_node`writes dirty the doc working tree and wait for a manual commit in the frontend Git panel
288+
- **Direct file edits**: edit `.md` / `.json` under `src/souko/doc/{project}/`; refresh to pick it up and show it as uncommitted
279289
- **Trigger an incremental update**: click the Update button on the home page; PrUpdater Agent automatically discovers all newly merged PRs and processes them one by one. Manual mode gates each PR behind a review confirmation
280290

281291
## doc-drill: Native Code Agent Integration
282292

283-
autoDoc installs the thin [doc-drill](src/skill-template/SKILL.md) skill into the target repo's `.claude/skills/doc-drill/` and writes an `.mcp.json` pointing at the local MCP server. Any Code Agent can then:
293+
autoDoc installs the thin [doc-drill](src/skill-template/SKILL.md) skill into the target repo's `.claude/skills/doc-drill/`, then writes Claude Code's `.mcp.json` and Codex's `.codex/config.toml` to point at the local HTTP MCP server. Any Code Agent can then:
284294

285295
- **Browse progressively**`list_projects``get_top``get_graph``get_page`, lazy-loaded, context-efficient
286296
- **Trace relationships** — follow the 6 semantic edge types to trace call chains and data flows
287297
- **Keyword search**`search_nodes` across all doc layers
288298
- **Navigate business flows** — understand end-to-end interactions via `flows.json`
289-
- **Maintain directly** — edit docs in place via mutate tools, and use `list_history` / `revert` to inspect or roll back
299+
- **Maintain directly** — edit docs in place via mutate tools, then let the user commit from autoDoc's frontend Git panel
290300

291301
> This Agent-native integration is something DeepWiki (web chat only) and Google Code Wiki (web browsing only) do not offer.
292302
@@ -316,8 +326,9 @@ autoDoc/
316326
│ │ └── projects.json # gitignored: shared registry
317327
│ ├── mcp/ # HTTP MCP server (same process as HTTP API)
318328
│ │ ├── server.ts # buildMcpServer(store)
319-
│ │ ├── docStore.ts # doc read/write + version + .history snapshots
320-
│ │ ├── schema.ts # Zod schemas (with version / pageVersions)
329+
│ │ ├── docStore.ts # doc read/write + project-level lock
330+
│ │ ├── docGit.ts # doc Git status / commit / blame
331+
│ │ ├── schema.ts # Zod schemas
321332
│ │ └── tools/{query,mutate}.ts
322333
│ ├── agents/ # Agent implementations (Claude + Codex)
323334
│ │ ├── tsukai/ # All Agent classes (barrel: index.ts)

0 commit comments

Comments
 (0)