feat: diag_refs 對帳診斷 + ingest 進度可見性/Ctrl-C 安全 (Closes #2) (#5)

## 摘要

本 PR 含兩個獨立關注點,各一 commit。

### 1. `diag_refs` — source_ref↔manifest 對帳診斷 (`04f4fd5`) — 回應 #4

lint 的「source_ref 不在 manifest」只報對不上、不辨成因。新增 `tools/diag_refs.py`,把每個對不上的 source_ref 分成五類(hash 不符/路徑字串岔開/檔名 hash 後綴岔開/檔在磁碟未登記/完全無對應),各附修法,讓「補帳本(§14.3)」與「修規則(§12)」的相反處置不再混為一談。純唯讀、結束碼 `0/1`,可當搬機或改 manifest 後的閘門。附 selfcheck 驗五型別分類、結束碼與零寫檔。README §3.3/§6/§7/§8 同步。

### 2. ingest 進度可見性 + Ctrl-C 安全回復 (`4add7fa`) — Closes #2

`--all-pending` 長時間本地 Ollama 攝入全程靜默,使用者不確定有沒有在跑、又不敢中斷:

- **進度可見**:每份來源 `[i/N]`、長文件逐段 `分段 k/n`、每個 item `↳ 新增/更新`、完成 `✓`,全 `flush=True` 即時顯示。
- **Ctrl-C 安全**:獨立攔 `KeyboardInterrupt`(它不是 `Exception` 子類,原本會略過善後)。因 commit 在迴圈之後,**main 必然未受影響**;中斷時印可照做的回復指令並以結束碼 130 收場。

## 測試

- `python tools/selfcheck_diag_refs.py` — ALL PASS
- `python tools/selfcheck_ingest.py` — ALL PASS(含進度標記、中斷後 main 未動、回復指令實測可回乾淨 main)
- README markdownlint 0 issues

Closes #2

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: LittleYellow <crazytea@gmail.com>
Reviewed-on: #5
This commit was merged in pull request #5.
This commit is contained in:
2026-07-24 05:42:35 +00:00
parent 356ae9367c
commit b90727fc11
5 changed files with 334 additions and 10 deletions

View File

@@ -126,6 +126,16 @@ ollama list # 對照 tasks.ingest.model / tasks.lint.model / tasks.fallba
- **結束碼**`0` = 無發現;`1` = 有待人工核准項目(供 CI 判斷 / 標紅通知)。
- 排程:[.gitea/workflows/lint.yaml](.gitea/workflows/lint.yaml)(每週一台北時間 05:00草稿部署 Gitea 時啟用)。
> **`source_ref 不在 manifest` 的成因分類**lint 只報「對不上」,不分辨成因。跑
> [tools/diag_refs.py](tools/diag_refs.py) 把每個對不上的 source_ref 分成五類hash 不符 /
> 路徑字串岔開 / 檔名 hash 後綴岔開 / 檔在磁碟未登記 / 完全無對應),各附修法——
> 「補帳本」§14.3與「修規則」§12的處置相反先分類再動手。純唯讀不改任何檔
> 結束碼同 lint`0` 全部解得開 / `1` 有對不上),可當搬機或改 manifest 後的閘門。
>
> ```powershell
> .venv\Scripts\python tools\diag_refs.py
> ```
### 3.4 查詢 `search` — BM25 檢索
```powershell
@@ -180,7 +190,7 @@ wiki/entities/ # 實體頁(系統/模組/API/法規/專案)
wiki/concepts/ # 概念頁(跨來源綜合)
index.md # 目錄式導航(由 ingest 自動重建)
log.md # append-only 操作日誌
tools/ # convert/ ingest.py lint.py search.py kb.py共用模組
tools/ # convert/ ingest.py lint.py diag_refs.py search.py kb.py共用模組
mcp/server.py # MCP 薄殼
```
@@ -197,8 +207,10 @@ mcp/server.py # MCP 薄殼
| `須在 main 分支執行` | 攝入前先切回 `main`。 |
| `工作區有 raw/ 以外的未提交變更` | 先 commit / stash 非 `raw/` 的變更再攝入。 |
| `... 不在 manifest 的 converted 條目中` | 該來源尚未轉換;先跑 `convert.py`。 |
| lint 報 `source_ref 不在 manifest` | 跑 `tools/diag_refs.py` 分類成因:帳本掉條目→補登走 PR§14.3路徑字串岔開→修規則§12別逐頁改。 |
| `LLM 輸出驗證失敗(含 fallback` | 本地模型連主模型 + fallback 都無法產出合規 JSON檢查 Ollama 是否在線、模型是否拉好。 |
| `push 失敗(無 remote 或離線)` | 正常;分支已保留本地,手動 push 後開 PR。 |
| ingest 跑很久、看不到進度/想中斷 | 已逐來源 `[i/N]` 逐分段回報進度。Ctrl-C 安全main 不受影響,中斷時會印回復指令(`git checkout main && git stash -u && git branch -D <branch>`),續跑 `--all-pending` 自動接續。 |
---
@@ -210,5 +222,6 @@ mcp/server.py # MCP 薄殼
.venv\Scripts\python tools\convert\selfcheck.py
.venv\Scripts\python tools\selfcheck_ingest.py
.venv\Scripts\python tools\selfcheck_lint.py
.venv\Scripts\python tools\selfcheck_diag_refs.py
.venv\Scripts\python tools\selfcheck_search.py
```