Deterministic external-evidence web validation workflow for Sanguo ETL/RAG. USE FOR: 外部證據網站檢查、來源健康度、allowlist 驗證、來源 seed 覆蓋、3kweb-check、external evidence source health、fetch/parse/hash first、LLM reviewer second。
日本語の概要は準備中です。原文の説明を表示しています。
文件分片管理 SKILL — 管理「大型文件 → shard 目錄群」的生命週期。USE FOR: 任何大型 .md / .json 檔案需要拆分為小分片、更新分片後重建索引、 驗證分片完整性,或新增 shard 目錄給新的大型文件。
DO NOT USE FOR: 程式碼編輯、UI layout 調整、任務卡狀態更新(那些直接改對應 JSON)。
インストールする前に、エージェントに与えられる指示の中身を確認できます。
大型文件(>6000 tokens)會觸發 Token 節流警戒線。解法是將其拆分為「shard 目錄群」:
本 SKILL 的核心工具是 tools_node/shard-manager.js,設定檔為各 shard 目錄下的 .shardrc.json。
| 索引 stub | Shard 目錄 | 分片數 | 類型 | 備註 |
|---|---|---|---|---|
docs/keep.md (doc_index_0011) (doc_index_0011) | docs/keep-shards/ | 4 | markdown-h2 | 主共識文件 |
docs/ui-quality-todo.json | docs/tasks/ | 4 | json-array | 按 id 前綴分 |
docs/cross-reference-index.md (doc_index_0005) (doc_index_0005) | docs/cross-ref/ | 3 | markdown-h2 | A/B/C 節 |
docs/tasks/tasks-ui.json | docs/tasks-ui-shards/ | 2 | json-array | 按 status 細拆(子分片,keepSourceIntact) |
docs/tasks/tasks-ui.json | docs/tasks/tasks-ui/ | 4 | auto-parts | auto-split 從 112 KB 等分為 4 parts |
docs/tasks/tasks-dc.json | docs/tasks/tasks-dc/ | 2 | auto-parts | auto-split 從 41 KB 等分為 2 parts |
# 初始分片(首次拆分 or 原始大檔有重大更新後重跑)
node tools_node/shard-manager.js shard <shardDir>
# 反向維護:分片有修改 → 重建索引 stub
node tools_node/shard-manager.js rebuild-index <shardDir>
# 完整性驗證(CI 前 / 收工前必跑)
node tools_node/shard-manager.js validate <shardDir>
# 狀態瀏覽(大小 + 修改時間)
node tools_node/shard-manager.js status <shardDir>
# 一次分片多個 shard 目錄
node tools_node/shard-manager.js shard-all docs/keep-shards docs/tasks docs/cross-ref
# 偵測未管理的大型文件(> 6 KB)
node tools_node/shard-manager.js scan docs
node tools_node/shard-manager.js scan docs --threshold 10 # 自訂門檻(KB)
# 動態等分拆分:偵測 > 門檻的分片並自動產生 N 個 parts
node tools_node/shard-manager.js auto-split <shardDir>
node tools_node/shard-manager.js auto-split docs/tasks --threshold 30 # 預設 30 KB
auto-split 特性:
N = ceil(shardSize / threshold),動態決定,不必寫死<shardDir>/<shardName>/ 子目錄,.shardrc.json 標記 _autoGenerated: trueauto-split 會依最新 shard 內容重新產生 parts(冪等操作)validate 執行 >40 KB 警告,並遞迴驗證 auto-parts 子目錄觸發時機:某個 shard 檔案的內容被修改(加新條目、更新狀態、新增章節等)。
不要改索引 stub,直接找到對應的 shard 檔案修改:
docs/keep-shards/keep-*.mddocs/tasks/tasks-<prefix>.jsondocs/cross-ref/cross-ref-*.mdnode tools_node/shard-manager.js rebuild-index docs/keep-shards
# 或
node tools_node/shard-manager.js rebuild-index docs/tasks
# 或
node tools_node/shard-manager.js rebuild-index docs/cross-ref
→ 索引 stub 自動更新為最新分片大小。
node tools_node/shard-manager.js validate docs/keep-shards
觸發時機:遇到 > 6000 tokens 的新文件需要拆分。
| 文件類型 | 建議 type | 拆分依據 |
|---|---|---|
Markdown 筆記(有 ## 章節) | markdown-h2 | 章節前綴 regex(如 `^(1 |
| JSON 陣列(如任務清單) | json-array | 每 item 的特定 field 值 regex |
目標:每個 shard ~3–10 KB,單份讀入不超過 6000 tokens(約 4 KB)。
docs/
my-new-large-file.md ← 原始大檔(稍後會變成 stub)
my-new-shards/ ← 新建目錄
.shardrc.json ← 設定檔(見下方格式)
README.md ← 選填:給人讀的說明
.shardrc.json 格式(markdown-h2):
{
"version": 1,
"source": "../my-new-large-file.md",
"indexTitle": "My Document Title",
"indexPath": "docs/my-new-large-file.md",
"type": "markdown-h2",
"preambleShard": "shard-a",
"defaultShard": "shard-a",
"shards": [
{ "name": "shard-a", "title": "A 部分(§1–§5)", "pattern": "^[1-5]\\." },
{ "name": "shard-b", "title": "B 部分(§6–§10)", "pattern": "^([6-9]|10)\\." }
]
}
.shardrc.json 格式(json-array):
{
"version": 1,
"source": "../items.json",
"indexTitle": "Items Index",
"type": "json-array",
"arrayPath": "items",
"splitField": "category",
"defaultShard": "items-other",
"shards": [
{ "name": "items-a", "title": "Category A", "pattern": "^A-" },
{ "name": "items-b", "title": "Category B", "pattern": "^B-" },
{ "name": "items-other", "title": "Others", "pattern": "." }
]
}
node tools_node/shard-manager.js shard docs/my-new-shards
→ 產生各 shard 檔案,原始大檔自動被索引 stub 取代。
node tools_node/shard-manager.js validate docs/my-new-shards
若新的 shard group 對應本專案的重要参考文件,請同步更新:
docs/keep.summary.md (doc_index_0012) (doc_index_0012) — 新增分片路徑提示.github/instructions/token-guard.instructions.md (doc_ai_0015) (doc_ai_0015) — 新增禁止整份讀入的規則若大檔有大量新章節(非單章節修改),需重新執行 shard:
# 1. 先確認大檔有原始內容(不是 stub)
# 2. 若已是 stub,從 git 恢復原版或手動合併分片
git show HEAD:docs/keep.md (doc_index_0011) > docs/keep.md (doc_index_0011) # 範例
# 3. 重新分片
node tools_node/shard-manager.js shard docs/keep-shards
# 4. 驗證
node tools_node/shard-manager.js validate docs/keep-shards
.shardrc.json 的 pattern 欄位是 JavaScript 正規表達式字串,作用於 h2 標題除去前置 ## 之後的文字(markdown-h2)或 splitField 欄位值(json-array)。
| 常見情境 | 推薦 pattern |
|---|---|
## 3. 標題 | "^3\\." |
## 2b. 標題 | "^2b\\." |
## P0. 標題 | "^P0\\." |
## A. 標題 | "^A\\." |
id 以 UI- 開頭 | "^UI-" |
| fallback(任何) | "." |
多章節 alternation:"^(3|4|5|6|13)\\." 匹配 3.、4.、5.、6.、13.。
警告:避免使用過短的前綴(如 "^1" 不加 \\.),否則會誤匹配 10.、11. 等。
觸發時機:某個 shard 仍然 > 30 KB(例如 tasks-ui.json 112 KB),需要依另一個欄位再次細拆。
關鍵旗標:"keepSourceIntact": true — 告訴 shard-manager 不要用 index stub 覆蓋來源檔(因為來源本身是父層的 shard 檔)。
範例:docs/tasks-ui-shards/.shardrc.json
{
"version": 1,
"source": "../tasks/tasks-ui.json",
"type": "json-array",
"arrayPath": "tasks",
"splitField": "status",
"keepSourceIntact": true,
"shards": [
{ "name": "tasks-ui-open", "title": "Active(open + in-progress)", "pattern": "^(open|in-progress)$" },
{ "name": "tasks-ui-done", "title": "Done(done + completed)", "pattern": "^(done|completed)$" }
]
}
分片讀取策略:
docs/tasks-ui-shards/tasks-ui-open.json(約 35 KB)docs/tasks-ui-shards/tasks-ui-done.json(約 71 KB)觸發時機:某 shard 超過 30 KB,且無法透過欄位/章節路由進一步細分,需要等分拆成 N 個 parts。
核心差異(vs Workflow D 子分片):
| Workflow D(Sub-Shard) | Workflow F(Auto-Split) | |
|---|---|---|
| 設定方式 | 手動寫 .shardrc.json,指定路由規則 | 全自動,無需手寫設定 |
| 分片策略 | 依業務欄位值(status、category…) | 純等分(item count 或 line count) |
| 分片數 | 固定寫在設定中 | 動態計算:ceil(size / threshold) |
| 適用情境 | 有業務語意的拆法(active vs done) | 內容均勻、無明顯分類軸 |
產出 .shardrc.json | 手寫(keepSourceIntact: true) | 自動產生(_autoGenerated: true) |
node tools_node/shard-manager.js validate docs/tasks
# WARN: tasks-ui.json is 112.6 KB > 40 KB.
# Consider: node tools_node/shard-manager.js auto-split docs/tasks
node tools_node/shard-manager.js auto-split docs/tasks --threshold 30
→ 輸出範例:
[shard-manager] tasks-ui.json 112.6 KB > 30 KB → auto-split
[shard-manager] → docs/tasks/tasks-ui/tasks-ui-part-1.json (25 items, 18.3 KB)
[shard-manager] → docs/tasks/tasks-ui/tasks-ui-part-2.json (25 items, 26.5 KB)
[shard-manager] → docs/tasks/tasks-ui/tasks-ui-part-3.json (25 items, 26.0 KB)
[shard-manager] → docs/tasks/tasks-ui/tasks-ui-part-4.json (25 items, 35.3 KB)
[shard-manager] OK: Auto-split tasks-ui.json → 4 parts in docs/tasks/tasks-ui/
node tools_node/shard-manager.js validate docs/tasks
# ... ✓ auto-parts sub-dir OK: docs/tasks/tasks-ui/
重新執行(原 shard 內容更新後):
# 先重建 shard(若 source 有改)或直接 auto-split(若只是分片大小변化)
node tools_node/shard-manager.js auto-split docs/tasks
auto-split 為冪等操作,每次都從當前 shard 檔重新等分。
觸發時機:需要直接修改 shard 管理範圍內的文件(任務狀態、keep 共識、交叉索引等)。
docs/tasks/tasks-ui.json、docs/keep-shards/keep-workflow.md (doc_index_0009) (doc_index_0009)…)status、notes、completed-date 等業務欄位## 邊界)修改後必須:
node tools_node/shard-manager.js rebuild-index <shardDir>
node tools_node/shard-manager.js validate <shardDir>
| 禁止行為 | 理由 |
|---|---|
| 直接編輯 index stub 的分片索引表 | stub 是 auto-generated,下次 rebuild-index 會覆蓋 |
更改任務 id 的前綴(PROG-001 → UI-001) | id 前綴決定路由,改了會在下次 shard 落入錯誤分片 |
把 Markdown ## section 貼進錯誤分片不重跑 shard | 路由依然按舊設定,下次 shard 才修正 |
直接編輯 auto-parts 子目錄的 part-*.json | auto-parts 由 auto-split 全量重產,手改會被覆蓋 |
刪除 .shardrc.json | 整個分片群失去設定 |
| 情境 | 命令 |
|---|---|
keep.md (doc_index_0011) 新增整個 ## section | shard docs/keep-shards |
| tasks-ui.json 新增 >10 筆後接近/超過 40 KB | validate docs/tasks → 出現 WARN 則 auto-split docs/tasks |
| 某分片已超過 40 KB(validate 警告) | auto-split <shardDir> --threshold 30 |
觸發時機:不確定 docs/ 下是否有新的大型文件需要納管;或定期健康檢查。
node tools_node/shard-manager.js scan docs
→ 列出所有 > 6 KB 且未在任何 .shardrc.json 中管理的 .md / .json 檔案。
優先處理:
跳過:
docs/遊戲規格文件/討論來源/ — 歷史討論,不常讀# 確認結構後建立目錄 + .shardrc.json,再執行分片
node tools_node/shard-manager.js shard docs/my-new-shards
validate 所有 shard groups 全 pass(包含 auto-parts sub-dirs)auto-splitrebuild-index 後大小顯示最新)node tools_node/check-encoding-touched.js --files <修改的檔案>まだレビューはありません。使ってみた感想をお寄せください。
概要と使いどころ
Deterministic external-evidence web validation workflow for Sanguo ETL/RAG. USE FOR: 外部證據網站檢查、來源健康度、allowlist 驗證、來源 seed 覆蓋、3kweb-check、external evidence source health、fetch/parse/hash first、LLM reviewer second。
日本語の概要は準備中です。原文の説明を表示しています。
Use when the user asks to switch AI role/mode/persona or uses role-trigger words such as Captain, Coordinator, 寫文章, 寫文章模式, 文章模式, 技術文章, 部落格, 出版, 預覽. Routes the request to Project Captain, Publishing Director, or Article Writing Mode, loads the matching keep memory when available, and applies the role's workflow without excessive roleplay.
日本語の概要は準備中です。原文の説明を表示しています。
Write or revise AI-learning-notes article pages in "寫文章模式" when the user asks for articles, technical articles, blog posts, bilingual versions, article formatting consistency, shared article-base alignment, responsive layout, summary/TOC decisions, contrast, or publishing-flow compatibility.
日本語の概要は準備中です。原文の説明を表示しています。
Plan ATM framework refactors by preserving atom/map semantics before splitting large governance modules.
日本語の概要は準備中です。原文の説明を表示しています。
Captain 派工規範與決策手冊。當 AI 進入隊長模式或進行派工/派任務語境時,遵照這套標準,產出可供人類直接轉貼、高度結構化、符合 token 經濟且能動態適應可用 Roster 的派工單。
日本語の概要は準備中です。原文の説明を表示しています。
Create and register an atom through the provisioning facade.
日本語の概要は準備中です。原文の説明を表示しています。