diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json index a9c234f..28d05ca 100644 --- a/.claude-plugin/plugin.json +++ b/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "jsc-gitea", - "version": "0.2.4", + "version": "0.2.5", "description": "Gitea API 工具、Wiki 讀寫、議題轉換、HTML 匯出與存取庫批次同步", "skills": "./skills", "author": { diff --git a/.codex-plugin/plugin.json b/.codex-plugin/plugin.json index 19cf779..e895b09 100644 --- a/.codex-plugin/plugin.json +++ b/.codex-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "jsc-gitea", - "version": "0.2.4", + "version": "0.2.5", "description": "Gitea API 工具、Wiki 讀寫、議題轉換、HTML 匯出與存取庫批次同步", "skills": "./skills", "jsc": { diff --git a/README.md b/README.md index b1640ac..cb7b9f1 100644 --- a/README.md +++ b/README.md @@ -66,13 +66,22 @@ page-name.sh regex | check # 頁名樣式的唯一正本 # 8 碼與 H 加 7 碼留給尚未遷移的舊頁;舊演算法多數情況會加 H,兩種都要收 # 前綴只收十四種內容型別。CONTENTS 只解存取庫,沒有 CONTENTS_CONTENTS 這一頁 # 結束碼 0=合法、1=不合法、2=用法錯誤 -wiki-contents.sh upsert [template-file] - # 目錄頁的整列 upsert:解 CONTENTS 存取庫、讀舊頁、換掉鍵相同那一列或附加到表尾、整頁寫回 - # key-col 是 1 起算的欄位序號,不是欄位名稱 - # 用範本建新頁時剝掉分隔列之後的示範列,正式頁上不留佔位的死連結 - # 結束碼 0=已更新或已新增、1=寫入失敗、2=用法錯誤、3=CONTENTS 存取庫未設定 +wiki-contents.sh upsert [template-file] + # 目錄頁的區塊 upsert:解 CONTENTS 存取庫、讀舊頁、換掉「## {key}」那一塊或附加到頁尾、整頁寫回 + # 目錄頁一筆一個 H2 區塊:標題就是內容頁頁名,欄位是底下一層條列「- {欄位名}:{值}」 + # entry-file 放整個 H2 區塊;舊頁還是表格時先整頁轉成區塊,再做 upsert + # key-col 只給轉檔用:舊表格裡持有身分那一欄的序號,1 起算,頁面已是條列就忽略 + # 轉檔的 H2 標題只看那一格:有連結取網址最後一段路徑(百分號編碼先解碼),沒連結取純文字 + # 連結文字常常是工作包或計畫名稱不是頁名;拿它當標題會跟呼叫端的鍵對不上,同一筆長出第二個區塊 + # 轉檔那一次有給範本,就連 H1 與「>」引言一起換成範本那一份:只搬表格不動散文,舊引言會一直講「一列一筆」 + # 頁面已是條列就不動引言,那時只是更新自己那一筆;沒給範本也保留舊引言,沒有正本可換 + # 用範本建新頁時剝掉示範區塊,只留 H1 與引言,正式頁上不留佔位的死紀錄 + # 結束碼 0=已更新或已新增、1=組不出頁面內容或寫入失敗、2=用法錯誤、3=CONTENTS 存取庫未設定 # 4=頁不存在且沒給範本、7=金鑰失效或權限不足、8=其他 API 失敗 # 只有 4 才准建新頁;7 與 8 一律中止,不得當成「頁面不存在」 +wiki-contents.sh format [template-file|--fresh] + # 同一份轉檔與 upsert 判斷,只讀寫檔案、不碰 API,供離線驗證用 + # 第六個參數給 --fresh 是「old-file 就是範本」,給路徑則等同 upsert 的範本檔 migrate-wiki.sh [--apply] [--key <候選鍵>]... # 把舊頁搬到新規則:目錄頁換存取庫、內容頁換頁名 # 只做正推配對,配不上的一律列成孤兒,不猜;不帶 --apply 只印對照表 # 寫目的地之前先讀:只有 4 才准寫,0 列成需人工確認且不覆蓋,7 與 8 中止 @@ -81,6 +90,7 @@ migrate-wiki.sh [--apply] [--key <候選鍵>]... # 把舊頁搬到新規則 repo-sync.sh / [target-dir] # 同步單一存取庫;印出 cloned、updated、dirty {分支} 或 failed {原因} # 基準分支的優先序只在這支腳本裡;dirty 會把解析好的分支帶出來當 PR 的 base check-wiki-rules.sh # 驗證 wiki repo 解析、hash-id 與頁名樣式規則 +check-contents-format.sh # 驗證目錄頁的區塊轉檔與 upsert 規則;全走 format 子命令,不打 API link-check.sh <網址>... # 連結寫進文件之前先驗證連得到;也吃標準輸入,一行一個 # 每個網址一行「{OK|DEAD|SKIP}{網址}{說明}」 # wiki 頁與議題轉成 API 查,其他 Gitea 網址帶金鑰 HEAD,外部網址不帶金鑰 HEAD @@ -150,7 +160,7 @@ html-render.sh --markdown <檔案> --title <標題> --out <輸出檔> [--layout] ### `wiki` -Gitea wiki 頁讀寫的統一入口:依頁面類型(QUESTION / PLAN / ANALYZE / DELIVER / MAINTAIN / REPO / LOG / LEARN / ERROR / CHECK / REPORT / SKILLSET / TOOLING / MONITOR / CONTENTS)解析 wiki 所在的 `{owner}/{repo}`,先讀對應的 `JSC_WIKI_REPO_{TYPE}`,再退回 `JSC_WIKI_REPO`,不同類型不可互相代用。所有 `*_CONTENTS` 頁一律走 `CONTENTS` 這個型別,內容頁走自己的型別;目錄頁的整列 upsert 交給 `tools/wiki-contents.sh`。頁面內容以圖表優先(mermaid 圖、markdown 表格),純文字每節最多三句。 +Gitea wiki 頁讀寫的統一入口:依頁面類型(QUESTION / PLAN / ANALYZE / DELIVER / MAINTAIN / REPO / LOG / LEARN / ERROR / CHECK / REPORT / SKILLSET / TOOLING / MONITOR / CONTENTS)解析 wiki 所在的 `{owner}/{repo}`,先讀對應的 `JSC_WIKI_REPO_{TYPE}`,再退回 `JSC_WIKI_REPO`,不同類型不可互相代用。所有 `*_CONTENTS` 頁一律走 `CONTENTS` 這個型別,內容頁走自己的型別;目錄頁的區塊 upsert 交給 `tools/wiki-contents.sh`,一筆紀錄一個 H2 區塊,標題就是內容頁頁名,欄位是底下一層條列。內容頁的內容以圖表優先(mermaid 圖、markdown 表格),純文字每節最多三句;目錄頁不放表格。 ### `repo-sync` diff --git a/plugin.json b/plugin.json index c2d3810..85c8389 100644 --- a/plugin.json +++ b/plugin.json @@ -1,6 +1,6 @@ { "name": "jsc-gitea", - "version": "0.2.4", + "version": "0.2.5", "description": "Gitea API 工具、Wiki 讀寫、議題轉換、HTML 匯出與存取庫批次同步", "skills": "./skills/", "jsc": { diff --git a/references/behaviors.md b/references/behaviors.md index fbea735..eb527a1 100644 --- a/references/behaviors.md +++ b/references/behaviors.md @@ -36,11 +36,11 @@ | 項目 | 內容 | | --- | --- | -| 觸發時機 | 技能組裡任何一次 wiki 頁的讀、寫、刪或搬移,都經過這一支。呼叫端有 jsc-ask、jsc-sdlc、jsc-log、jsc-hooks 的 ERROR 頁、jsc-cli 的 CHECK 頁、jsc-meta 的 SKILLSET 與 TOOLING 頁、jsc-assist 的 MONITOR 頁。存放庫裡的程式碼檔案不歸這一支管。 | -| 關鍵步驟 | 確認 GITEA_HOST 有值、用 tools/gitea.sh wiki-repo {TYPE} 解出 {owner}/{repo}、用 tools/hash-id 算頁名要用的 HASH、用 tools/page-name.sh check 驗過頁名、再依動作跑 wiki-list、wiki-get、wiki-put、wiki-delete 或 wiki-url,每一次呼叫都照結束碼表分流。所有 *_CONTENTS 頁一律走型別 CONTENTS,內容頁走自己的型別;存放庫的解法是先讀 JSC_WIKI_REPO_{TYPE}、再讀 JSC_WIKI_REPO、兩個都沒有才問使用者,而且不借用別的頁型的存放庫。頁面裡的連結一律寫成 [文字](絕對網址),網址取自 wiki-url,不自行組路徑;wiki-put 之前先把這一頁要放的每一條連結交給 tools/link-check.sh,結束碼 0 才寫,1 就不寫並回報 DEAD 那幾筆,7 停下來回報金鑰問題。目錄頁的整列 upsert 交給 tools/wiki-contents.sh,寫入前一定先 wiki-get 讀回舊內容,只有結束碼 4 才准用範本建新頁;舊頁搬到新規則走 tools/migrate-wiki.sh,不帶 --apply 只印對照表,寫每一個目的地之前也一樣先 wiki-get 讀一次。收尾一律呼叫 jsc-hooks/tools/report-status.sh skill-end jsc-gitea:wiki 寫下這一輪的結果,走每一條出口,連停在主機閘門那一條也要寫;這支被幾乎每支技能呼叫,只回報這一次 wiki 動作的成敗,不回報呼叫端自己的結果。status 五選一,讀到頁面或寫入落地是 ok,主機沒值、或 wiki-repo 回 3 而使用者沒給 {owner}/{repo}、整輪沒讀也沒寫是 blocked,金鑰失效那個結束碼 7 算 failed 不算頁面不存在、結束碼 8 與 link-check 回 1 擋下寫入也是 failed,內容頁寫成功但目錄頁沒更新(wiki-contents.sh 回 3 或 1)是 degraded、搬移只搬掉一部分也是 degraded,人工確認被否決或頁型不在允許清單而停在 wiki-repo 回 2 是 aborted。detail 只放頁名,不放頁面內容。腳本不在這台機器就安靜跳過,回報失敗不得改變回給呼叫端的結果。 | -| 外部呼叫 | tools/gitea.sh 的 wiki-repo、wiki-list、wiki-get、wiki-put、wiki-delete、wiki-url、tools/hash-id、tools/page-name.sh、tools/link-check.sh、tools/wiki-contents.sh、tools/migrate-wiki.sh、tools/write-confirm.sh、jsc-ask:ask、jsc-hooks/tools/report-status.sh skill-end、Gitea 的 wiki API 與議題 API。 | -| 完成條件 | 讀取動作拿到頁面內容,或拿到一個講得清楚的結束碼。這一輪還要留下一筆 skill-end 事件,或是腳本不在而略過,兩者都算收好;略過不影響回給呼叫端的結束碼。寫入動作先讓 tools/link-check.sh 回結束碼 0,再通過人工確認、wiki-put 回結束碼 0,而且送出去的是舊內容加上這次的異動,不是整頁覆蓋。連結檢查回 1 就不寫入,回 7 連同整個動作一起中止。wiki-put 的結束碼 7 與 8 一律中止整個動作,不建頁、不寫入、不用原參數重試。搬移動作要嘛全部搬完回 0,要嘛把失敗頁、孤兒頁、目的地已有內容的頁、指向被搬頁卻沒被搬的引用方逐條列出來,這四種一律交給人判斷。 | -| 可驗證跡象 | 目標 wiki 存放庫多一頁或改一頁。內容頁的頁名是 {型別}_{40 碼大寫十六進位},目錄頁是 {型別}_CONTENTS 且落在 JSC_WIKI_REPO_CONTENTS 指的那個存放庫。頁面內容是 UTF-8 繁體中文,以 mermaid 圖與 markdown 表格為主,散文每節最多三句;頁面裡每一條連結都是 [文字](絕對網址),沒有 wiki 內部連結語法,而且每一條在寫入前都被 tools/link-check.sh 判成 OK。寫入與刪除前 tools/write-confirm.sh 會各留下一次人工確認。$JSC_HOME/usage/events.jsonl 會多一筆 {kind:skill,phase:end} 事件,name 是 jsc-gitea:wiki,status 與 exit 就是這一次 wiki 動作的結果。只做讀取的呼叫沒有 wiki 寫入跡象,只有回報內容與那一筆事件。 | +| 觸發時機 | 技能組裡任何一次 wiki 頁的讀、寫、刪或搬移,都經過這一支。呼叫端有 jsc-ask、jsc-sdlc、jsc-log、jsc-hooks 的 ERROR 頁、jsc-cli 的 CHECK 頁、jsc-meta 的 SKILLSET 與 TOOLING 頁、jsc-assist 的 MONITOR 頁。要在目錄頁登記一筆紀錄,也走這一支。存放庫裡的程式碼檔案不歸這一支管。 | +| 關鍵步驟 | 確認 GITEA_HOST 有值、用 tools/gitea.sh wiki-repo {TYPE} 解出 {owner}/{repo}、用 tools/hash-id 算頁名要用的 HASH、用 tools/page-name.sh check 驗過頁名、再依動作跑 wiki-list、wiki-get、wiki-put、wiki-delete 或 wiki-url,每一次呼叫都照結束碼表分流。所有 *_CONTENTS 頁一律走型別 CONTENTS,內容頁走自己的型別;存放庫的解法是先讀 JSC_WIKI_REPO_{TYPE}、再讀 JSC_WIKI_REPO、兩個都沒有才問使用者,而且不借用別的頁型的存放庫。頁面裡的連結一律寫成 [文字](絕對網址),網址取自 wiki-url,不自行組路徑;wiki-put 之前先把這一頁要放的每一條連結交給 tools/link-check.sh,結束碼 0 才寫,1 就不寫並回報 DEAD 那幾筆,7 停下來回報金鑰問題。內容頁的內容以圖表優先,目錄頁不放表格:一筆紀錄一個 H2 區塊,標題就是那一筆對應的內容頁頁名,欄位是標題底下一層條列「- {欄位名}:{值}」。目錄頁的區塊 upsert 交給 tools/wiki-contents.sh,參數是 upsert {TYPE} {key-col} {key} {區塊檔} [範本檔]:它先 wiki-get 讀回舊內容,舊頁還是 markdown 表格就整頁轉成區塊,再找「## {key}」,命中換掉整塊、沒命中附加到頁尾,最後整頁寫回;key-col 只給轉檔認舊表格的身分欄用,頁面已是條列就忽略;轉檔的 H2 標題只看身分欄那一格,有連結就取網址最後一段路徑、百分號編碼先解碼,沒連結才取格子純文字,取到什麼就用什麼,不拿頁名樣式去驗;轉檔那一次呼叫端有給範本,就把第一個「## 」之前的 H1 與「>」引言換成範本那一段,範本的示範區塊不得混進來,因為轉檔只搬表格不動散文,舊引言會一直講「每個存取庫一列」這種只對表格成立的話,頁面已是條列或沒給範本則引言原樣不動。只有結束碼 4 才准用範本建新頁,7 與 8 一律中止;建新頁時範本的示範區塊要剝掉。舊頁搬到新規則走 tools/migrate-wiki.sh,不帶 --apply 只印對照表,寫每一個目的地之前也一樣先 wiki-get 讀一次。收尾一律呼叫 jsc-hooks/tools/report-status.sh skill-end jsc-gitea:wiki 寫下這一輪的結果,走每一條出口,連停在主機閘門那一條也要寫;這支被幾乎每支技能呼叫,只回報這一次 wiki 動作的成敗,不回報呼叫端自己的結果。status 五選一,讀到頁面或寫入落地是 ok,主機沒值、或 wiki-repo 回 3 而使用者沒給 {owner}/{repo}、整輪沒讀也沒寫是 blocked,金鑰失效那個結束碼 7 算 failed 不算頁面不存在、結束碼 8 與 link-check 回 1 擋下寫入也是 failed,內容頁寫成功但目錄頁沒更新(wiki-contents.sh 回 3,或回 1 組不出頁面內容、寫入沒落地)是 degraded、搬移只搬掉一部分也是 degraded,人工確認被否決或頁型不在允許清單而停在 wiki-repo 回 2 是 aborted。detail 只放頁名,不放頁面內容。腳本不在這台機器就安靜跳過,回報失敗不得改變回給呼叫端的結果。 | +| 外部呼叫 | tools/gitea.sh 的 wiki-repo、wiki-list、wiki-get、wiki-put、wiki-delete、wiki-url、tools/hash-id、tools/page-name.sh、tools/link-check.sh、tools/wiki-contents.sh 的 upsert 與 format、tools/migrate-wiki.sh、tools/write-confirm.sh、jsc-ask:ask、jsc-hooks/tools/report-status.sh skill-end、Gitea 的 wiki API 與議題 API。 | +| 完成條件 | 讀取動作拿到頁面內容,或拿到一個講得清楚的結束碼。這一輪還要留下一筆 skill-end 事件,或是腳本不在而略過,兩者都算收好;略過不影響回給呼叫端的結束碼。寫入動作先讓 tools/link-check.sh 回結束碼 0,再通過人工確認、wiki-put 回結束碼 0,而且送出去的是舊內容加上這次的異動,不是整頁覆蓋。目錄頁的異動只動自己那一個 H2 區塊:別人那幾筆一字不變,頁面上不留 markdown 表格,也不出現兩個同名的 H2 標題;只有從表格轉成區塊那一次,且呼叫端有給範本,引言才會換成範本那一份,其餘情況引言與別人那幾筆一起一字不動。連結檢查回 1 就不寫入,回 7 連同整個動作一起中止。wiki-put 的結束碼 7 與 8 一律中止整個動作,不建頁、不寫入、不用原參數重試。搬移動作要嘛全部搬完回 0,要嘛把失敗頁、孤兒頁、目的地已有內容的頁、指向被搬頁卻沒被搬的引用方逐條列出來,這四種一律交給人判斷。 | +| 可驗證跡象 | 目標 wiki 存放庫多一頁或改一頁。內容頁的頁名是 {型別}_{40 碼大寫十六進位},目錄頁是 {型別}_CONTENTS 且落在 JSC_WIKI_REPO_CONTENTS 指的那個存放庫。頁面內容是 UTF-8 繁體中文;內容頁以 mermaid 圖與 markdown 表格為主,散文每節最多三句。目錄頁只有三段:H1 頁名、「>」引言、一筆一個 H2 區塊,區塊之間空一行,H2 與第一條條列之間也空一行,H2 標題就是內容頁頁名而且不帶連結。頁面裡每一條連結都是 [文字](絕對網址),沒有 wiki 內部連結語法,而且每一條在寫入前都被 tools/link-check.sh 判成 OK。wiki-contents.sh 印出一行 updated 或 added 加上 {owner}/{repo}/{頁名}。寫入與刪除前 tools/write-confirm.sh 會各留下一次人工確認。$JSC_HOME/usage/events.jsonl 會多一筆 {kind:skill,phase:end} 事件,name 是 jsc-gitea:wiki,status 與 exit 就是這一次 wiki 動作的結果。只做讀取的呼叫沒有 wiki 寫入跡象,只有回報內容與那一筆事件。 | ## wiki-to-issue diff --git a/references/wiki-links.md b/references/wiki-links.md index beb694e..adcf705 100644 --- a/references/wiki-links.md +++ b/references/wiki-links.md @@ -8,7 +8,7 @@ | 情境 | 寫法 | | --- | --- | -| 目錄頁指向內容頁(例:`PLAN_CONTENTS` → `PLAN_{HASH}`) | `[PLAN_{HASH}](https://…/wiki/PLAN_…)` | +| 目錄頁指向內容頁(例:`PLAN_CONTENTS` → `PLAN_{HASH}`):連結寫在該筆 H2 區塊的條列裡,H2 標題本身只放頁名,不放連結 | `- 計畫頁:[PLAN_{HASH}](https://…/wiki/PLAN_…)` | | 內容頁指向目錄頁,或指向別的型別 | `[顯示文字](絕對網址)` | | 目錄頁之間、同型別的內容頁之間 | `[顯示文字](絕對網址)` | | 議題、PR、存放庫檔案 | `[顯示文字](絕對網址)` | diff --git a/skills/wiki/SKILL.md b/skills/wiki/SKILL.md index 7bba34a..61f78cd 100644 --- a/skills/wiki/SKILL.md +++ b/skills/wiki/SKILL.md @@ -1,6 +1,6 @@ --- name: wiki -description: Read or write a Gitea wiki page through tools/gitea.sh, tools/hash-id and tools/page-name.sh. Resolve the wiki repo per page type with JSC_WIKI_REPO_{TYPE} first, then JSC_WIKI_REPO, and ask only when neither is set - every *_CONTENTS page resolves through type CONTENTS and is updated with tools/wiki-contents.sh, and {HASH} is the full 40-char uppercase SHA-1 from tools/hash-id. Page content is chart-first - prefer mermaid diagrams and markdown tables over plain prose, and every link is written as [text](absolute URL) that tools/link-check.sh passed before the write. Callers are jsc-ask, jsc-sdlc, jsc-log, jsc-hooks (ERROR), jsc-cli (CHECK), jsc-meta (SKILLSET, TOOLING) and jsc-assist (MONITOR). Use for any wiki page in the skill set; not for repo code files. +description: Read or write a Gitea wiki page through tools/gitea.sh, tools/hash-id and tools/page-name.sh. Resolve the wiki repo per page type with JSC_WIKI_REPO_{TYPE} first, then JSC_WIKI_REPO, and ask only when neither is set - every *_CONTENTS page resolves through type CONTENTS and is upserted by tools/wiki-contents.sh as one H2 block per record, and {HASH} is the full 40-char uppercase SHA-1 from tools/hash-id. A contents page carries no markdown table - one H2 block per record, headed by that record's content-page name with one bullet per field - while a content page is chart-first, preferring mermaid diagrams and markdown tables over plain prose, and every link is written as [text](absolute URL) that tools/link-check.sh passed before the write. Callers are jsc-ask, jsc-sdlc, jsc-log, jsc-hooks (ERROR), jsc-cli (CHECK), jsc-meta (SKILLSET, TOOLING) and jsc-assist (MONITOR). Use for any wiki page in the skill set; not for repo code files. --- # wiki — read and write Gitea wiki pages @@ -24,7 +24,7 @@ Different page types can live in different `{owner}/{repo}` repos, classified by | write page | write the content to a temp file first, then `tools/gitea.sh wiki-put {owner}/{repo} {page} {file}` (asks for confirmation first, then creates or updates) | | delete page | `tools/gitea.sh wiki-delete {owner}/{repo} {page}` — asks for the same confirmation as a write. Only a migration or an explicit user request may call it | | page URL | `tools/gitea.sh wiki-url {owner}/{repo} {page}` — the page's absolute URL, taken from the API's `html_url` | -| update a contents page | `tools/wiki-contents.sh upsert {TYPE} {key-col} {key} {row-file} [template-file]` — resolves the CONTENTS repo, replaces the row whose key column matches, appends when none does, writes the whole page back. `{key-col}` is the column's 1-based position number, not the column name | +| update a contents page | `tools/wiki-contents.sh upsert {TYPE} {key-col} {key} {entry-file} [template-file]` — resolves the CONTENTS repo, replaces the `## {key}` block, appends when the page holds no such heading, writes the whole page back. `{entry-file}` is that record's whole H2 block. `{key-col}` only matters while the old page is still a markdown table: it is the 1-based position of the column that carries the record's identity, and the script converts such a page to H2 blocks before the upsert, taking each heading from that cell's link URL — its last path segment, percent-decoded — or from the cell's plain text when the cell holds no link. On that conversion, a supplied `{template-file}` also replaces the page's H1 and `>` intro with the template's own, because a conversion moves the table alone and the old intro keeps describing rows; an already-converted page keeps its intro untouched, and so does a conversion run without a template | | check a page name | `tools/page-name.sh check {page}` — the single source of the page-name pattern; `tools/page-name.sh regex` prints it | | move pages to the current rules | `tools/migrate-wiki.sh [--apply] [--key {key}]...` — prints the mapping table and the orphan list; writes only with `--apply` | | check links before a write | `tools/link-check.sh {url}...` — prints `{OK\|DEAD\|SKIP}{url}{reason}` per URL; exit 0 means every link is reachable | @@ -57,8 +57,8 @@ Every code below gets its own branch. Nothing here is retried unchanged. | `tools/page-name.sh` | 0 | the page name follows the pattern | continue with that page name | | | 1 | the page name breaks the pattern | stop and report the name; build the correct one instead of writing to a wrong page | | | 2 | usage error | fix the arguments, then call again | -| `tools/wiki-contents.sh` | 0 | the row was updated or added | report which of the two, and the page | -| | 1 | the write failed, or the page held no markdown table | stop and report; fix the page or the row before calling again | +| `tools/wiki-contents.sh` | 0 | the block was updated or added | report which of the two, and the page | +| | 1 | the page content could not be built, or the write failed | stop and report; fix the page or the entry before calling again. A missing `## {key}` is not this code — that path appends | | | 2 | usage error, or an unknown page type | fix the arguments, then call again | | | 3 | the CONTENTS repo is not configured | go to step 3 and ask for `JSC_WIKI_REPO_CONTENTS` | | | 4 | the page is not there and no template was given | supply the template for that page type, then call again | @@ -89,7 +89,7 @@ This skill is called by almost every other one, so its status is what the caller | `ok` | The read returned the page, or the write landed: `link-check.sh` exited 0, the confirmation was given, and `wiki-put` exited 0 | | `blocked` | The location could not be resolved, so nothing was read and nothing was written: `GITEA_HOST` holds no value and the user gave none, or `wiki-repo` exited 3 and the user supplied no `{owner}/{repo}` for that page type | | `failed` | The operation ran and broke. **Exit 7 belongs here**: the key is invalid or lacks permission, so the whole operation stopped, and that is a failure, never an absent page. Exit 8, a `wiki-put` that did not land, a `link-check.sh` exit 1 that refused the write, and a `hash-id` or `page-name.sh` rejection all sit here too | -| `degraded` | The content page landed and the contents page did not — `wiki-put` on `{TYPE}_{HASH}` exited 0, then `wiki-contents.sh upsert` exited 3 with no CONTENTS repo configured, or exited 1 on a page holding no markdown table. The record exists but nothing indexes it, so the next reader will not find it. A migration that moved some pages and left orphans or occupied destinations behind sits here as well | +| `degraded` | The content page landed and the contents page did not — `wiki-put` on `{TYPE}_{HASH}` exited 0, then `wiki-contents.sh upsert` exited 3 with no CONTENTS repo configured, or exited 1 because the page content could not be built or the write did not land. The record exists but nothing indexes it, so the next reader will not find it. A migration that moved some pages and left orphans or occupied destinations behind sits here as well | | `aborted` | The premise did not hold or the user stopped it: `write-confirm.sh` was refused before a write or a delete, or the caller asked for a page type outside the allowed list and the run stopped at `wiki-repo` exit 2 | Completion condition: exactly one `skill-end` line was recorded for this run, or the script was absent and the run finished without it. @@ -98,14 +98,14 @@ Completion condition: exactly one `skill-end` line was recorded for this run, or 1. Page names must follow the wiki naming table in the skill guidelines (see `jsc-meta/references/guidelines.md`). Check any page name you build with `tools/page-name.sh check {page}` before it reaches an API call. 2. Use `tools/hash-id` for `{HASH}` values. It returns the full 40 uppercase SHA-1 hex chars — no truncation, no prefix. Never compute a hash by hand: a hand-made page name lands the content on a page nobody else reads. -3. To update a contents page (`*_CONTENTS`), run `tools/wiki-contents.sh upsert {TYPE} {key-col} {key} {row-file} [template-file]`, where `{key-col}` is the column's 1-based position number, not the column name. It reads the page, replaces the row whose key column equals the key, appends the row when no line matches, and writes the whole page back through the same confirmation. Never overwrite entries owned by others. Whether the page may be created from the template instead is decided by rule 4, and by nothing else. +3. **A contents page (`*_CONTENTS`) is one H2 block per record, never a table.** The H2 heading is that record's key, written as the content page's own name (`{TYPE}_{HASH}`) — no link, no URL, no prefix, no date. Every field is one bullet under it, `- {field}:{value}`, full-width colon, one bullet per field including the key's own. Update it with `tools/wiki-contents.sh upsert {TYPE} {key-col} {key} {entry-file} [template-file]`, where `{entry-file}` holds that whole H2 block. The script reads the page, converts a page still holding a markdown table into H2 blocks first, replaces the block whose heading equals `{key}`, appends the block when no heading matches, and writes the whole page back through the same confirmation. `{key-col}` is used only by that conversion: it is the 1-based position of the old table's identity column, and it is ignored once the page is already in block form. That conversion takes the heading from the identity cell's markdown link — the URL's last path segment, percent-decoded, because the link text is often a work-package or plan name rather than the page name — and from the cell's plain text, backticks stripped, only when the cell holds no link; it never checks the result against the page-name pattern, since old timestamped names, new 40-char names, and plain `{owner}/{repo}` identities all appear online. **That conversion is also the one moment the intro may be rewritten:** when `{template-file}` is given, everything before the first `## ` — the H1, the `>` intro, the blank lines between them — is replaced by the template's own preamble, taken the same way and carrying none of the template's demo blocks. Why: the conversion moves the table and leaves the prose, so an intro still saying "one row per repository" outlives the rows it describes, and the template holds the canonical wording. A page already in block form keeps its intro exactly as its owner wrote it — that call only updates its own record — and a conversion run without a template keeps the old intro, there being no canonical copy to install. Never overwrite entries owned by others. Whether the page may be created from the template instead is decided by rule 4, and by nothing else. 4. **Only exit 4 means the page is not there yet — this rule binds every "create it if it does not exist" path, without exception.** It is not limited to contents pages: a content page (`*_{HASH}`), a work log, an error page, a report, any page at all, follows the same branch. - **Correct branch.** Read the page with `wiki-get`. Exit 0 means the page exists, so append or modify the content that came back and `wiki-put` the whole page. Exit 4 (HTTP 404) is the one and only code that permits creating a new page from the template. - **Exit 7 and exit 8 abort.** Exit 7 (HTTP 401 or 403) and exit 8 (any other API failure) both mean the old content is unknown, never that the page is missing. Stop the operation and report the exit code with its cause. Create no page, write nothing, and do not retry the same call unchanged. - **Why.** Wiki writes in this skill set are append-not-overwrite, and that semantics rests entirely on reading the old page back first. Reading a 401 as a 404 makes the caller believe it holds a brand-new page and `wiki-put` a fresh template over a live one, and the whole earlier record is gone — the write carries no merge and no backup. - `tools/wiki-contents.sh` implements exactly this branch for contents pages and reports the same codes. 5. Write all wiki content in UTF-8 Traditional Chinese, per the STE100 output rule. -6. Prefer visual forms for page content: use mermaid diagrams (flowchart, sequence, gantt, pie) and markdown tables wherever the information allows. Prose is capped at 3 sentences per section, and a sentence stays only when neither a mermaid diagram nor a markdown table can carry the same information. +6. **Chart-first applies to content pages (`*_{HASH}`) only.** On a content page, prefer visual forms: use mermaid diagrams (flowchart, sequence, gantt, pie) and markdown tables wherever the information allows. Prose is capped at 3 sentences per section, and a sentence stays only when neither a mermaid diagram nor a markdown table can carry the same information. **A contents page (`*_CONTENTS`) always takes the H2-heading-plus-bullets form of rule 3 instead** — no table, and no diagram, whatever the field count. Why: the heading is the key the upsert matches on, so the layout is fixed by the tool, not by which form reads better. 7. `tools/gitea.sh` retries once with the tea CLI login token when `GITEA_TOKEN` is missing or the response is 401/403. Report a failure only after that retry also fails. 8. **Rule A — every link is written as `[text](absolute URL)`.** That is the only form. `[[page]]` and `[[display|page]]` are gone, and there is no longer a same-repo case that keeps them. The URL always comes from `tools/gitea.sh wiki-url {owner}/{repo} {page}`, never from a path built by hand. Why: `[[...]]` resolves only inside the current wiki, so a cross-repo link silently lands on a same-named page in this one — and it fails as plain text or a dead link, with nothing to catch it. Contents pages and content pages already live in different repos, so keeping two forms would mean judging, link by link, which repo each end resolves to. 9. **Rule B — check every link before the write.** Run `tools/link-check.sh {url}...` over every link that is going into the page. Exit 0 is the only code that opens `wiki-put`. Exit 1 means at least one link is dead: write nothing, and hand the caller the `DEAD` rows. Exit 7 means the key failed, not that the pages are gone — stop and report the key problem. Checking after the write is not the same thing: the dead link is already published, and the next reader follows it. diff --git a/tools/check-contents-format.sh b/tools/check-contents-format.sh new file mode 100755 index 0000000..f495ff4 --- /dev/null +++ b/tools/check-contents-format.sh @@ -0,0 +1,518 @@ +#!/usr/bin/env sh +# check-contents-format.sh — 驗證目錄頁的區塊轉檔與 upsert 規則。 +# 全部走 wiki-contents.sh 的 format 子命令,只讀寫暫存檔,不打任何 API。 +# 涵蓋五種舊頁狀態:純表格、已是條列且鍵命中、已是條列且鍵未命中、表格與區塊混合、 +# 用範本建新頁。另外驗三件事:表格取不出鍵那一列要擋下來不猜標題、轉檔後重跑同一筆 +# 結果一字不變、區塊檔沒帶標題也照樣補上。 +# 轉檔取 H2 標題另外驗四種身分欄:連結文字不是頁名、連結文字剛好等於頁名、純文字沒有 +# 連結、網址帶百分號編碼。四種都要取到真正的頁名,呼叫端那一筆才會是 updated。 +# 引言另外驗五種情形:轉檔且有範本要換成範本那一份、轉檔但沒範本保留舊的、已是條列 +# 加了範本也不准動引言、--fresh 建新頁照舊、拿轉檔結果重跑引言不再變動。 +# 全部通過印 OK 並 exit 0;任一項不符印出 want 與 got 並 exit 1。 +# 結束碼: 0=全部通過,stdout 印 OK +# 1=有一項不符,stderr 印出 {項目}: want=… got=… 之後立刻停住,不續跑其餘項目。 +# 只有 0 與 1 兩種;這支不吃參數,也沒有用法錯誤那條路。 +set -eu + +dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) +contents="$dir/wiki-contents.sh" + +work=$(mktemp -d) +trap 'rm -rf "$work"' EXIT + +fail() { + printf '%s\n' "$1" >&2 + exit 1 +} + +expect_eq() { # got want label + [ "$1" = "$2" ] || fail "$(printf '%s: want=\n%s\ngot=\n%s' "$3" "$2" "$1")" +} + +# run