feat(link): 連結一律寫成 [文字](絕對網址),寫入前先驗證連得到
取消 [[頁名]] 與 [[顯示文字|頁名]] 兩種同 wiki 寫法,不再分「同存取庫」與 「跨存取庫」兩條規則。那種寫法只在自己那個 wiki 內解析,寫錯不報錯,畫面上 看起來像普通文字或死連結,巡不到也修不了。 連結寫進頁面前先過 jsc-gitea 的 link-check.sh,結束碼 0 才寫。驗證一律走 API, 不看網頁狀態碼:私有存取庫的網頁網址對未登入請求一律回 404,拿狀態碼判會把 好連結判成壞的。認證失敗回 7,與死連結的 1 分開,免得金鑰一過期就把還在的頁 整批判死。
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
| 項目 | 內容 |
|
||||
| --- | --- |
|
||||
| 觸發時機 | 任何 jsc 技能需要使用者做決定時叫用。答案已經寫在 `QUESTION_{HASH}` 且意圖相符時不叫用,直接採用舊答案。答案查得到程式碼、設定檔或環境變數時不叫用,自己去查。 |
|
||||
| 關鍵步驟 | 確認目前工作的 `{owner}/{repo}`、執行 `jsc-gitea/tools/hash-id {owner}/{repo}` 取得完整 40 碼大寫 `HASH`、每個工作階段各解析一次 `QUESTION` 與 `CONTENTS` 兩個 wiki 存取庫、讀入 `QUESTION_CONTENTS`(`CONTENTS` 庫)與 `QUESTION_{HASH}`(`QUESTION` 庫)並留成階段副本、把這一輪每一題標成「照紀錄回答」或「要問」、以決策樹選單一次問一個決策點且每個選項標明影響範圍、依答案決定下一題直到沒有疑慮、交一個 sub agent 先用 `jsc-gitea:wiki` 寫 `QUESTION_{HASH}`、再用 `jsc-gitea/tools/gitea.sh wiki-url` 取紀錄頁的絕對網址並依結束碼分流(4 是紀錄頁還沒寫上去要重寫、5 是沒有 `html_url`、7 金鑰失效、8 重試一次,其餘非 0 一律停下並註明那一列沒有被索引,網址取不到就不寫那一列)、再用 `jsc-gitea/tools/wiki-contents.sh upsert` 把單列寫進 `QUESTION_CONTENTS` 並依結束碼分流、寫入後同步更新階段副本、把答案交回叫用的技能 |
|
||||
| 外部呼叫 | `jsc-gitea/tools/hash-id`、`jsc-gitea:wiki`(`wiki-repo QUESTION`、`wiki-repo CONTENTS`、`wiki-get`、寫入)、`jsc-gitea/tools/wiki-contents.sh upsert`、`jsc-gitea/tools/gitea.sh wiki-url`(目錄頁連到紀錄頁的絕對網址)、AskUserQuestion 或等效選單、一個負責兩次 wiki 寫入的 sub agent;範本 `templates/question-record.md`、`templates/question-contents.md` |
|
||||
| 完成條件 | 這一輪每一題都有答案,來源是紀錄或使用者;答案交回叫用的技能;有存取庫名稱時,sub agent 回報兩頁都寫成功(`wiki-contents.sh` 退 0),主代理接受那一次回報。沒有存取庫名稱時,問完直接交回答案,不寫任何頁。目錄頁寫不成的另一種完成條件:`wiki-contents.sh` 退 2、退 3、退 7,或 `wiki-url` 取不到網址,四種都算這一步走完——紀錄頁記成「已寫、未被索引」,回報講明結束碼與沒寫成的那一頁,答案照樣交回叫用的技能。退 3 特別要交回答案:`JSC_WIKI_REPO_CONTENTS` 在 `jsc-cli/tools/config-spec.tsv` 是 `fix=ask`,`/jsc-cli:setup` 只能靠這一支問到值,答案在這裡被吞掉,變數就永遠設不起來。退 4 代表範本參數被漏掉了,本技能的呼叫一律帶第五個參數,所以不會出現;範本路徑不存在回的是 2。停止執行並回報的情況:`hash-id` 找不到 SHA-1 工具、wiki 讀取非 exit 4 的失敗、重試後仍寫不進去(`wiki-contents.sh` 退 1 或 8)。寫入失敗一律把答案交回並註明沒有記錄。 |
|
||||
| 可驗證跡象 | `QUESTION` 存取庫的 wiki `QUESTION_{HASH}` 頁尾多一節,頁名是完整 40 碼大寫十六進位,開頭是使用者意圖,底下每題一張選項與影響範圍的表,附答案與時間;`CONTENTS` 存取庫的 wiki `QUESTION_CONTENTS` 該存取庫那一列的「最後更新」變成這次執行的時間戳,沒有該列就新增一列,該列的問詢紀錄欄是指向紀錄頁的絕對網址,不是 `[[...]]`,別的存取庫那幾列一字不動。沒有 `{owner}/{repo}` 時無寫入跡象,只有回報內容。 |
|
||||
| 關鍵步驟 | 確認目前工作的 `{owner}/{repo}`、執行 `jsc-gitea/tools/hash-id {owner}/{repo}` 取得完整 40 碼大寫 `HASH`、每個工作階段各解析一次 `QUESTION` 與 `CONTENTS` 兩個 wiki 存取庫、讀入 `QUESTION_CONTENTS`(`CONTENTS` 庫)與 `QUESTION_{HASH}`(`QUESTION` 庫)並留成階段副本、把這一輪每一題標成「照紀錄回答」或「要問」、以決策樹選單一次問一個決策點且每個選項標明影響範圍、依答案決定下一題直到沒有疑慮、交一個 sub agent 做兩次寫入:先把新一節要放進 `QUESTION_{HASH}` 的每個連結交給 `jsc-gitea/tools/link-check.sh` 驗證,退 0 才用 `jsc-gitea:wiki` 寫那一節;再用 `jsc-gitea/tools/gitea.sh wiki-url` 取紀錄頁的絕對網址並依結束碼分流(4 是紀錄頁還沒寫上去要重寫、5 是沒有 `html_url`、7 金鑰失效、8 重試一次,其餘非 0 一律停下並註明那一列沒有被索引,網址取不到就不寫那一列)、把該列的連結再交給 `link-check.sh` 驗證,退 0 才用 `jsc-gitea/tools/wiki-contents.sh upsert` 把單列寫進 `QUESTION_CONTENTS` 並依結束碼分流、寫入後同步更新階段副本、把答案交回叫用的技能。頁面裡的連結一律寫成 `[{文字}]({連結})`,wiki 連結取自 `wiki-url` 印出的絕對網址,不自行組路徑。 |
|
||||
| 外部呼叫 | `jsc-gitea/tools/hash-id`、`jsc-gitea:wiki`(`wiki-repo QUESTION`、`wiki-repo CONTENTS`、`wiki-get`、寫入)、`jsc-gitea/tools/wiki-contents.sh upsert`、`jsc-gitea/tools/gitea.sh wiki-url`(目錄頁連到紀錄頁的絕對網址)、`jsc-gitea/tools/link-check.sh`(兩頁寫入前各驗證一次連結)、AskUserQuestion 或等效選單、一個負責兩次 wiki 寫入的 sub agent;範本 `templates/question-record.md`、`templates/question-contents.md` |
|
||||
| 完成條件 | 這一輪每一題都有答案,來源是紀錄或使用者;答案交回叫用的技能;有存取庫名稱時,sub agent 回報兩頁都寫成功(`wiki-contents.sh` 退 0),主代理接受那一次回報。沒有存取庫名稱時,問完直接交回答案,不寫任何頁。目錄頁寫不成的另一種完成條件:`wiki-contents.sh` 退 2、退 3、退 7,或 `wiki-url` 取不到網址,四種都算這一步走完——紀錄頁記成「已寫、未被索引」,回報講明結束碼與沒寫成的那一頁,答案照樣交回叫用的技能。退 3 特別要交回答案:`JSC_WIKI_REPO_CONTENTS` 在 `jsc-cli/tools/config-spec.tsv` 是 `fix=ask`,`/jsc-cli:setup` 只能靠這一支問到值,答案在這裡被吞掉,變數就永遠設不起來。退 4 代表範本參數被漏掉了,本技能的呼叫一律帶第五個參數,所以不會出現;範本路徑不存在回的是 2。`link-check.sh` 非 0 也算這一步走完:退 1 就那一頁不寫並回報 DEAD 清單,退 2 補參數重跑,退 3 先設定 `GITEA_HOST` 再驗證,退 7 停下來回報金鑰,四種都不得跳過驗證直接寫入。停止執行並回報的情況:`hash-id` 找不到 SHA-1 工具、wiki 讀取非 exit 4 的失敗、重試後仍寫不進去(`wiki-contents.sh` 退 1 或 8)。寫入失敗一律把答案交回並註明沒有記錄。 |
|
||||
| 可驗證跡象 | `QUESTION` 存取庫的 wiki `QUESTION_{HASH}` 頁尾多一節,頁名是完整 40 碼大寫十六進位,開頭是使用者意圖,底下每題一張選項與影響範圍的表,附答案與時間;`CONTENTS` 存取庫的 wiki `QUESTION_CONTENTS` 該存取庫那一列的「最後更新」變成這次執行的時間戳,沒有該列就新增一列,該列的問詢紀錄欄是 `[QUESTION_{HASH}]({絕對網址})`,網址與 `wiki-url` 印出的一字不差,別的存取庫那幾列一字不動;兩頁寫進去的每個連結都通得過 `link-check.sh`,驗不過那一輪頁面停在舊內容,回報裡有 DEAD 清單或結束碼。沒有 `{owner}/{repo}` 時無寫入跡象,只有回報內容。 |
|
||||
|
||||
+5
-3
@@ -35,9 +35,11 @@ Inside one work session this skill is the only writer of `QUESTION_{HASH}` and `
|
||||
|
||||
1. Without a repository name, do not record; stop here. Done when the answers are handed back to the calling skill and no wiki page was touched.
|
||||
2. After each Q&A round, hand both wiki writes to one sub agent, content page first and directory page second, so the directory never links a page that failed to write.
|
||||
- `QUESTION_{HASH}` is written through `jsc-gitea:wiki` — it owns the `JSC_WIKI_REPO_QUESTION` → `JSC_WIKI_REPO` resolution and the tea-token fallback, which a hand-rolled Gitea API call loses. Apply `templates/question-record.md`: append this round as a new section, keep every earlier section, and open the section with the user's original intent (why this questioning round happened), which lets a later reader judge why the user chose as they did and whether the answer still applies. `QUESTION_{HASH}` belongs to this one repository, which is why appending a section is the right shape there.
|
||||
- `QUESTION_CONTENTS` is written by one call to `jsc-gitea/tools/wiki-contents.sh upsert QUESTION 1 {owner}/{repo} {row-file} templates/question-contents.md`. `key-col` is the 1-based column index, not a column name, and column 1 of `QUESTION_CONTENTS` is 存取庫名稱 — that cell holds the bare `{owner}/{repo}` text. The script compares the whole cell, so pass the key exactly as the row file writes it. The row file holds this repository's single row, and its 問詢紀錄 cell is the absolute URL printed by `jsc-gitea/tools/gitea.sh wiki-url {question-repo} QUESTION_{HASH}` — never `[[...]]`, which resolves only inside one wiki and now points at nothing, because the directory page lives in the `CONTENTS` repo while the record page lives in the `QUESTION` repo. Always pass the template argument. The script owns the read-merge-write of that shared directory: it upserts this one row and touches no other repository's row, so do not read the page and rebuild it by hand.
|
||||
- `QUESTION_{HASH}` is written through `jsc-gitea:wiki` — it owns the `JSC_WIKI_REPO_QUESTION` → `JSC_WIKI_REPO` resolution and the tea-token fallback, which a hand-rolled Gitea API call loses. Apply `templates/question-record.md`: append this round as a new section, keep every earlier section, and open the section with the user's original intent (why this questioning round happened), which lets a later reader judge why the user chose as they did and whether the answer still applies. `QUESTION_{HASH}` belongs to this one repository, which is why appending a section is the right shape there. Write every link in the section as `[{text}]({url})`, and take each wiki `{url}` from `jsc-gitea/tools/gitea.sh wiki-url` — never assemble a path by hand.
|
||||
- Verify before writing: hand every link of the new section to `jsc-gitea/tools/link-check.sh` and branch on its exit code. 0: every link answers, so write the section. 1: at least one link is DEAD, so write nothing and report the DEAD lines to the calling skill — a dead link on a record page reads as a real page and nobody finds it again. 2: no URL reached the script, so pass the links again. 3: `GITEA_HOST` is unset, so report that it must be set and run the check again; never write a link that skipped the check. 7: the Gitea key failed, so stop and report the key problem — a failed key makes live pages look dead. A section carrying no link goes straight to the write. Done when the check exited 0 and the section is written, or nothing was written and the report names the failing links or the exit code.
|
||||
- `QUESTION_CONTENTS` is written by one call to `jsc-gitea/tools/wiki-contents.sh upsert QUESTION 1 {owner}/{repo} {row-file} templates/question-contents.md`. `key-col` is the 1-based column index, not a column name, and column 1 of `QUESTION_CONTENTS` is 存取庫名稱 — that cell holds the bare `{owner}/{repo}` text. The script compares the whole cell, so pass the key exactly as the row file writes it. The row file holds this repository's single row, and its 問詢紀錄 cell is written as `[QUESTION_{HASH}]({url})`, where `{url}` is the absolute URL printed by `jsc-gitea/tools/gitea.sh wiki-url {question-repo} QUESTION_{HASH}`. Take that URL from the command only; never assemble a path by hand. The two pages sit in different repositories — the directory page in the `CONTENTS` repo, the record page in the `QUESTION` repo — so only an absolute URL crosses from one to the other. Always pass the template argument. The script owns the read-merge-write of that shared directory: it upserts this one row and touches no other repository's row, so do not read the page and rebuild it by hand.
|
||||
- Branch on `wiki-url`'s exit code before the row is built, because a URL that never arrived leaves that cell silently empty and the row still looks written. 0: put the printed URL in the cell, verbatim. 4: `QUESTION_{HASH}` is not on the wiki yet, so the record-page write has not landed — write that page again, then ask for the URL once more. 5: the page carries no `html_url`, so report it and never assemble a URL by hand. 7: the key is invalid or has no permission, so stop without retrying. 8: any other API failure, so retry once, then stop. Any other non-zero exit stops the same way. Whenever no URL comes back, write no row at all — an empty or hand-made cell is worse than a missing one — stop, report the exit code, and state that this repository's row was not indexed this round.
|
||||
- Verify before writing: hand that URL, and every other link the row carries, to `jsc-gitea/tools/link-check.sh`, and branch on its exit code. 0: the links answer, so run the upsert. 1: at least one link is DEAD, so write no row and report the DEAD lines; `QUESTION_{HASH}` counts as written and unindexed, and this round's answers still go back to the calling skill. 2: no URL reached the script, so pass the links again. 3: `GITEA_HOST` is unset, so report that it must be set and run the check again; never upsert a row whose link skipped the check. 7: the Gitea key failed, so stop and report the key problem — a failed key makes live pages look dead, and an unchecked row would carry the blame instead. Done when the check exited 0 and the upsert ran, or no row was written and the report names the failing links or the exit code.
|
||||
- Branch on `wiki-contents.sh`'s exit code, every code its own branch. 0: the row was added or updated, so this round is recorded. 1: the write failed, so retry once per step 3. 2: usage error, so stop and report the arguments that were passed — the same call retried fails the same way. A template path that does not exist lands here too, and means the plugin installation is incomplete. 3: no `CONTENTS` repo is configured, so report that `JSC_WIKI_REPO_CONTENTS` (or `JSC_WIKI_REPO`) must be set, note `QUESTION_{HASH}` as written but unindexed, and hand this round's answers back to the calling skill all the same. **Never withhold the answers over this code.** `JSC_WIKI_REPO_CONTENTS` is a `fix=ask` item in `jsc-cli/tools/config-spec.tsv`, so `/jsc-cli:setup` can only learn its value by asking through this skill; an answer dropped here leaves the variable unset, and the unset variable makes the next round drop the answer again. 4: the page does not exist and no template reached the script. The call form above always passes the template as the fifth argument, so this code cannot come out of it — getting it means that argument was dropped, so restore it and run the same call once more. 7: the key is invalid or has no permission, so stop and report without retrying. 8: any other API failure, so retry once per step 3, then stop and report.
|
||||
- Done when the sub agent has reported both writes as succeeded and the main agent has accepted that one report — this single confirmation covers both pages and both templates; do not re-read the pages to prove it. Exit 2, 3 or 7 from `wiki-contents.sh`, and any `wiki-url` failure, close this step the second way: `QUESTION_{HASH}` counts as written and unindexed, the report names the exit code and the page that stayed unwritten, and this round's answers go back to the calling skill regardless. **The answers of a finished questioning round are never lost because the directory page could not be written.**
|
||||
- Done when the sub agent has reported both writes as succeeded and the main agent has accepted that one report — this single confirmation covers both pages and both templates; do not re-read the pages to prove it. Exit 2, 3 or 7 from `wiki-contents.sh`, any `wiki-url` failure, and any non-zero `link-check.sh` exit on the directory row, close this step the second way: `QUESTION_{HASH}` counts as written and unindexed, the report names the exit code and the page that stayed unwritten, and this round's answers go back to the calling skill regardless. **The answers of a finished questioning round are never lost because the directory page could not be written.**
|
||||
3. On a reported write failure, retry that one page once — a `QUESTION_{HASH}` failure, or `wiki-contents.sh` exit 1 or 8. Exit 2, 3 and 7 are not retried, because the same call fails identically until someone fixes the arguments, the environment or the key; they end the recording, not the round. Every one of these paths ends the same way: the answers go back to the calling skill, and the report names the page that stayed unwritten, the exit code behind it, and what was recorded and what was not. Done when the retry succeeded and step 3 of "Session cache" refreshed that page's copy, or — when the retry also failed, or the code was 2, 3 or 7 — the report above has been printed and the answers have been handed back.
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
>
|
||||
> 寫入語意:一列代表一個存取庫。一律用 `jsc-gitea/tools/wiki-contents.sh upsert` 寫入:它讀回整頁,該存取庫已經有列就更新那一列,沒有才在文末附加一列,最後整頁寫回。只動自己那一列,禁止整頁覆蓋,也不得改動別人的列。
|
||||
>
|
||||
> 連結寫法:問詢紀錄那一欄放 `jsc-gitea/tools/gitea.sh wiki-url` 印出的絕對網址,不用 `[[...]]`。兩頁分屬不同存取庫,`[[...]]` 連不過去,畫面上還看不出壞掉。
|
||||
> 連結寫法:問詢紀錄那一欄一律寫成 `[{文字}]({連結})`,連結取自 `jsc-gitea/tools/gitea.sh wiki-url` 印出的絕對網址,不自行組路徑。兩頁分屬不同存取庫,只有絕對網址連得過去。
|
||||
>
|
||||
> 連結驗證:這一列寫進頁面前,先把該列的每一個連結交給 `jsc-gitea/tools/link-check.sh`,結束碼 0 才寫入。有任一筆 DEAD 就整列不寫,把連不到的清單回報給呼叫端。結束碼 3 代表 `GITEA_HOST` 沒設定,先設定再驗證,不得跳過;結束碼 7 代表金鑰失效,停下來回報,別把還在的頁當成死連結。
|
||||
|
||||
| 存取庫名稱 | 問詢紀錄 | 最後更新 |
|
||||
| --- | --- | --- |
|
||||
|
||||
Reference in New Issue
Block a user