From 684d3f4f31445a4c3cea1e1c49873fe608bce78b Mon Sep 17 00:00:00 2001 From: Jeffery Date: Fri, 21 Aug 2026 08:23:27 +0000 Subject: [PATCH 1/3] =?UTF-8?q?feat(gitea):=20gitea.sh=20=E8=AA=8D?= =?UTF-8?q?=E8=AD=89=E5=A4=B1=E6=95=97=E6=99=82=E8=87=AA=E5=8B=95=E9=80=80?= =?UTF-8?q?=E5=9B=9E=20tea=20CLI=20=E7=99=BB=E5=85=A5=20token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit What(改了什麼) - tools/gitea.sh 新增 tea_token():解析 ~/.config/tea/config.yml,優先取 default: true 的登入 token,否則取第一個。 - 啟動時 GITEA_TOKEN 未設定或為空,改用 tea token;兩者皆無才維持原本的必填錯誤。 - req() 遇 HTTP 401/403 且 tea token 存在又與當前 token 不同時,換用 tea token 重試一次,之後不再重試。 - 檔頭用法註解補上退回機制的說明。 Why(為什麼改) - 使用者規則:api token 401/403 時,若 tea CLI 已登入就取其 token 重試,避免因 GITEA_TOKEN 過期或未設定就直接中斷流程。 How(怎麼改) - 以 awk 解析 tea 設定檔的 logins 清單,抓各登入的 token 與 default 旗標。 - req() 改為 while 迴圈包住 curl,retried 旗標保證最多重試一次;HTTP >= 400 仍以 exit 4 收場。 - 實測:sh -n 語法檢查通過;GITEA_TOKEN 為空時經 tea token 成功;GITEA_TOKEN=deadbeef 時走 401 重試路徑成功;無 tea 設定且 token 為空時維持原錯誤訊息。 Who(影響哪個功能/使用者) - 所有經 tools/gitea.sh 呼叫 Gitea API 的技能(wiki、repo-sync、jsc-git pr 等)與使用者:token 缺失或失效時多一層自動救援,行為只在原本會失敗的情境改變。 Co-Authored-By: Claude Fable 5 --- tools/gitea.sh | 50 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/tools/gitea.sh b/tools/gitea.sh index a31d21b..7b73169 100755 --- a/tools/gitea.sh +++ b/tools/gitea.sh @@ -17,24 +17,52 @@ # gitea.sh repo-set / [website] # 設定 repo 描述與網頁 # gitea.sh api [json-file] # 原始 API 呼叫(path 以 /repos/... 起始) # 環境變數: GITEA_HOST(例 https://gitea.jsc.idv.tw)、GITEA_TOKEN +# GITEA_TOKEN 未設定,或請求遇 401/403 時,自動退回 tea CLI 的登入 token +# (~/.config/tea/config.yml,優先取 default: true 的登入);兩者皆無才失敗。 set -eu +tea_token() { # 取 tea CLI 設定檔的 token(優先 default: true 的登入,否則第一個) + cfg="${HOME}/.config/tea/config.yml" + [ -f "$cfg" ] || return 1 + t=$(awk ' + /^ *- / { if (def && tok != "") { print tok; found=1; exit } tok=""; def=0 } + /^ *token: */ { line=$0; sub(/^ *token: */,"",line); gsub(/"/,"",line) + tok=line; if (first=="") first=line } + /^ *default: *true/ { def=1 } + END { if (!found) { if (def && tok != "") print tok; else print first } } + ' "$cfg") + [ -n "$t" ] && printf '%s\n' "$t" +} + : "${GITEA_HOST:?GITEA_HOST is required}" -: "${GITEA_TOKEN:?GITEA_TOKEN is required}" +TEA_TOKEN=$(tea_token 2>/dev/null || true) +if [ -z "${GITEA_TOKEN:-}" ]; then + if [ -n "$TEA_TOKEN" ]; then GITEA_TOKEN="$TEA_TOKEN"; else + : "${GITEA_TOKEN:?GITEA_TOKEN is required}" + fi +fi case "$GITEA_HOST" in http://*|https://*) HOST="$GITEA_HOST" ;; *) HOST="https://$GITEA_HOST" ;; esac API="${HOST%/}/api/v1" -req() { # METHOD path [json-file] -> body(HTTP >= 400 時 exit 4) +req() { # METHOD path [json-file] -> body(HTTP >= 400 時 exit 4;401/403 以 tea token 重試一次) method="$1"; path="$2"; body_file="${3:-}" - if [ -n "$body_file" ]; then - out=$(curl -sS -w '\n%{http_code}' -X "$method" \ - -H "Authorization: token $GITEA_TOKEN" -H "Content-Type: application/json" \ - --data-binary "@$body_file" "$API$path") - else - out=$(curl -sS -w '\n%{http_code}' -X "$method" \ - -H "Authorization: token $GITEA_TOKEN" "$API$path") - fi - code=$(printf '%s' "$out" | tail -n1) + retried=0 + while :; do + if [ -n "$body_file" ]; then + out=$(curl -sS -w '\n%{http_code}' -X "$method" \ + -H "Authorization: token $GITEA_TOKEN" -H "Content-Type: application/json" \ + --data-binary "@$body_file" "$API$path") + else + out=$(curl -sS -w '\n%{http_code}' -X "$method" \ + -H "Authorization: token $GITEA_TOKEN" "$API$path") + fi + code=$(printf '%s' "$out" | tail -n1) + if [ "$retried" -eq 0 ] && { [ "$code" = 401 ] || [ "$code" = 403 ]; } \ + && [ -n "$TEA_TOKEN" ] && [ "$TEA_TOKEN" != "$GITEA_TOKEN" ]; then + GITEA_TOKEN="$TEA_TOKEN"; retried=1; continue + fi + break + done printf '%s\n' "$out" | sed '$d' [ "$code" -lt 400 ] } From 1f17f1779ab0f308ed4c5ff21892441ad1a4df40 Mon Sep 17 00:00:00 2001 From: Jeffery Date: Fri, 21 Aug 2026 08:23:27 +0000 Subject: [PATCH 2/3] =?UTF-8?q?feat(wiki):=20wiki=20=E6=8A=80=E8=83=BD?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=9C=96=E8=A1=A8=E5=84=AA=E5=85=88=E5=85=A7?= =?UTF-8?q?=E5=AE=B9=E8=A6=8F=E5=89=87=E4=B8=A6=E6=9B=B4=E6=96=B0=20README?= =?UTF-8?q?=20=E8=AA=AA=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit What(改了什麼) - skills/wiki/SKILL.md 新增兩條規則:頁面內容以圖表優先(mermaid 流程圖、時序圖、甘特圖、圓餅圖與 markdown 表格),純文字為最後手段且保持精簡;tools/gitea.sh 已內建認證退回機制,兩條路徑都失敗才回報認證錯誤。 - SKILL.md frontmatter description 補上 chart-first 說明,讓技能挑選時就能看到此規則。 - README.md:「Skills 目錄」的 wiki 條目補上圖表優先說明;環境變數表的 GITEA_TOKEN 一列補上 401/403 自動退回 tea CLI token 的行為。 Why(為什麼改) - 使用者規則:wiki 輸出盡量用 mermaid 與表格呈現,不要只有純文字。 - 認證退回已在 tools/gitea.sh 實作,技能文件與 README 需同步,避免技能誤判認證失敗或文件與行為不一致。 How(怎麼改) - 在 SKILL.md 規則清單追加第 4、5 條,並同步改寫 frontmatter description。 - README 對應兩處文字更新,與 gitea.sh 的實際行為一致。 Who(影響哪個功能/使用者) - 使用 jsc-gitea:wiki 的所有呼叫方(jsc-ask、jsc-sdlc、jsc-log):之後寫出的 wiki 頁會以圖表為主;閱讀 README 的使用者能得知 token 退回行為。 備註:README.md 的 GITEA_TOKEN 環境變數表一列在語意上屬於前一個 commit(tea token 退回),但為避免以 hunk 拆分 README,整檔併入本 commit。 Co-Authored-By: Claude Fable 5 --- README.md | 4 ++-- skills/wiki/SKILL.md | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 974c9f2..65baa07 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ gitea.sh api [json-file] ### `wiki` -Gitea wiki 頁讀寫的統一入口:依頁面類型(QUESTION / PLAN / ANALYZE / MAINTAIN / REPO / LOG)解析 wiki 所在的 `{owner}/{repo}`,未設定環境變數時以決策樹詢問。 +Gitea wiki 頁讀寫的統一入口:依頁面類型(QUESTION / PLAN / ANALYZE / MAINTAIN / REPO / LOG)解析 wiki 所在的 `{owner}/{repo}`,未設定環境變數時以決策樹詢問。頁面內容以圖表優先(mermaid 圖、markdown 表格),純文字為最後手段。 ### `repo-sync` @@ -54,7 +54,7 @@ Gitea wiki 頁讀寫的統一入口:依頁面類型(QUESTION / PLAN / ANALYZ | 變數 | 用途 | 未設定時 | | --- | --- | --- | | `GITEA_HOST` | Gitea 站台(可省略 scheme,預設 https) | 詢問使用者 | -| `GITEA_TOKEN` | Gitea API token | 詢問使用者 | +| `GITEA_TOKEN` | Gitea API token;缺少或遇 401/403 時自動退回 tea CLI 登入 token | 詢問使用者 | | `JSC_WIKI_REPO_{TYPE}` | 各類型 wiki 頁的 `{owner}/{repo}`;TYPE = QUESTION / PLAN / ANALYZE / MAINTAIN / REPO / LOG | 退回 `JSC_WIKI_REPO` | | `JSC_WIKI_REPO` | 共用預設的 wiki `{owner}/{repo}` | 詢問使用者 | diff --git a/skills/wiki/SKILL.md b/skills/wiki/SKILL.md index 8e85c5a..efab159 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 with GITEA_TOKEN. Resolve the wiki repo per page type (QUESTION/PLAN/ANALYZE/MAINTAIN/REPO/LOG) via gitea.sh wiki-repo, falling back to JSC_WIKI_REPO or a decision-tree question. Used by jsc-ask, jsc-sdlc, and jsc-log for all wiki pages; not for repo code files. +description: Read or write a Gitea wiki page through tools/gitea.sh with GITEA_TOKEN. Resolve the wiki repo per page type (QUESTION/PLAN/ANALYZE/MAINTAIN/REPO/LOG) via gitea.sh wiki-repo, falling back to JSC_WIKI_REPO or a decision-tree question. Page content is chart-first - prefer mermaid diagrams and markdown tables over plain prose. Used by jsc-ask, jsc-sdlc, and jsc-log for all wiki pages; not for repo code files. --- # wiki — read and write Gitea wiki pages @@ -27,3 +27,5 @@ Different page types can live in different `{owner}/{repo}` repos, classified by 1. Page names must follow the wiki naming table in the skill guidelines (see `jsc-meta/references/guidelines.md`). 2. To update a contents page (`*_CONTENTS`): `wiki-get` it first, apply the template to append or modify, then `wiki-put` the whole page back. Never overwrite entries owned by others. 3. Write all wiki content in UTF-8 Traditional Chinese, per the STE100 output rule. +4. Prefer visual forms for page content: use mermaid diagrams (flowchart, sequence, gantt, pie) and markdown tables wherever the information allows. Plain running text is the last resort, kept short. +5. Authentication fallback is built into `tools/gitea.sh`: on a missing GITEA_TOKEN or a 401/403 response it retries with the tea CLI login token automatically, so only report an auth failure when both paths fail. From 5e732f42fded5798cd17b8497b7341b57fa745cf Mon Sep 17 00:00:00 2001 From: Jeffery Date: Fri, 21 Aug 2026 08:23:27 +0000 Subject: [PATCH 3/3] =?UTF-8?q?chore(plugin):=20=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E8=99=9F=E7=94=B1=200.0.1=20=E5=8D=87=E8=87=B3=200.0.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit What(改了什麼) - plugin.json、.claude-plugin/plugin.json、.codex-plugin/plugin.json 三份 manifest 的 version 同步由 0.0.1 改為 0.0.2。 Why(為什麼改) - 本次加入 tea CLI token 退回與 wiki 圖表優先規則兩項功能,需要提升版本讓各 AI CLI 的插件更新機制抓到新版。 How(怎麼改) - 三份 manifest 僅改 version 欄位,其餘內容不動,維持三處版本一致。 Who(影響哪個功能/使用者) - 安裝 jsc-gitea 插件的所有 AI CLI 使用者:更新後可取得本次的功能。 Co-Authored-By: Claude Fable 5 --- .claude-plugin/plugin.json | 2 +- .codex-plugin/plugin.json | 2 +- plugin.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json index b0d0b21..0de1c44 100644 --- a/.claude-plugin/plugin.json +++ b/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "jsc-gitea", - "version": "0.0.1", + "version": "0.0.2", "description": "Gitea API 工具、Wiki 讀寫與存取庫批次同步", "skills": "./skills", "author": { diff --git a/.codex-plugin/plugin.json b/.codex-plugin/plugin.json index e42cfcb..5c7f23e 100644 --- a/.codex-plugin/plugin.json +++ b/.codex-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "jsc-gitea", - "version": "0.0.1", + "version": "0.0.2", "description": "Gitea API 工具、Wiki 讀寫與存取庫批次同步", "skills": "./skills" } diff --git a/plugin.json b/plugin.json index 0f65b1e..add943c 100644 --- a/plugin.json +++ b/plugin.json @@ -1,6 +1,6 @@ { "name": "jsc-gitea", - "version": "0.0.1", + "version": "0.0.2", "description": "Gitea API 工具、Wiki 讀寫與存取庫批次同步", "skills": "./skills/" }