diff --git a/plugins/jsc-wiki/README.md b/plugins/jsc-wiki/README.md index 4149d7f..bdf8c6d 100644 --- a/plugins/jsc-wiki/README.md +++ b/plugins/jsc-wiki/README.md @@ -50,7 +50,7 @@ - 讀取:第一次使用會 clone wiki 到 `~/.cache/jsc-wiki`,之後每次先更新,離線時用快取。 - 頁面格式:規則在 wiki 的 [頁面格式](https://gitea.jsc.idv.tw/jiantw83/jsc-marketplace/wiki/%E9%A0%81%E9%9D%A2%E6%A0%BC%E5%BC%8F) 頁,包含固定結構、簡化技術中文(參考 [ASD-STE100 skill](https://github.com/danyuchn/asd-ste100-skill)),以及繁體中文無亂碼、盡量用圖表。 - 寫入:`scripts/book.sh`(TypeScript,需要 Node 與 git;Node 不支援直接執行 TypeScript 時自動用 `npx tsx`)。推送需要 `tea` 的預設 login,或環境變數 `JSC_WIKI_TOKEN`。 -- 新增領域:在 marketplace repo 的 clone 內執行 `book-import`,技能檔才會寫進 repo(可 commit);寫進已安裝的插件目錄,下次更新插件時會消失。新指令需 `/reload-plugins` 後才會出現。 +- 新增領域:在 marketplace repo 的 clone 內執行 `book-import`,會同步更新插件 README、市集 README、`marketplace.json`、`plugin.json` 的指令清單並升一個修訂版本,技能檔也才會寫進 repo(可 commit);寫進已安裝的插件目錄,下次更新插件時會消失。新指令需 `/reload-plugins` 後才會出現。 - 其他環境變數:`JSC_WIKI_URL`(wiki git 位址)、`JSC_WIKI_CACHE`(讀取快取)、`JSC_WIKI_WORK`(寫入工作副本)。 ```bash diff --git a/plugins/jsc-wiki/scripts/book.ts b/plugins/jsc-wiki/scripts/book.ts index f69ad8b..430da0c 100644 --- a/plugins/jsc-wiki/scripts/book.ts +++ b/plugins/jsc-wiki/scripts/book.ts @@ -267,6 +267,32 @@ function cmdAddChapter(args: string[]): void { touched.push(wikiSkill); } } + + // 在 marketplace repo 內:同步市集 README、市集 manifest 與插件 manifest 的指令清單,並升一個修訂版本 + const pluginDir = join(skillsDir, ".."); + const repoRoot = join(pluginDir, "..", ".."); + const edit = (file: string, fn: (s: string) => string): void => { + if (!existsSync(file)) return; + const before = read(file); + const after = fn(before); + if (after !== before) { + write(file, after); + touched.push(file); + } + }; + const bump = (v: string): string => v.replace(/(\d+\.\d+\.)(\d+)/, (_, a, b) => a + (Number(b) + 1)); + let version = ""; + edit(join(pluginDir, ".claude-plugin", "plugin.json"), (j) => { + j = j.replace(/(:[a-z0-9-]+)(;\/jsc-wiki:book-search)/, `$1、:${key}$2`); + return j.replace(/("version": ")([^"]+)"/, (_, a, v) => `${a}${(version = bump(v))}"`); + }); + edit(join(repoRoot, ".claude-plugin", "marketplace.json"), (j) => + j.replace(/(system(?:、[a-z0-9-]+)*)( 指令)/, `$1、${key}$2`)); + edit(join(repoRoot, "README.md"), (r) => { + r = r.replace(/(### \[jsc-wiki\]\(plugins\/jsc-wiki\) `)[^`]+`/, (_, a) => `${a}${version || "未知"}\``); + return r.replace(/(### \[jsc-wiki\][\s\S]*?`:[a-z0-9-]+`)( 等指令)/, `$1、\`:${key}\`$2`); + }); + console.log(`已新增:${name.slice(0, -3)}(wiki 工作副本,尚未推送)`); console.log(`已產生領域技能 /jsc-wiki:${key},變更的檔案:\n${touched.map((f) => " " + f).join("\n")}`); console.log("提醒:技能檔在插件目錄,需 commit 進 jsc-marketplace repo 才會保留;重新載入插件後指令才會出現。"); diff --git a/plugins/jsc-wiki/skills/book-import/SKILL.md b/plugins/jsc-wiki/skills/book-import/SKILL.md index 9796d6b..6fb94ed 100644 --- a/plugins/jsc-wiki/skills/book-import/SKILL.md +++ b/plugins/jsc-wiki/skills/book-import/SKILL.md @@ -37,7 +37,7 @@ flowchart LR - 新增一章(**新領域必須同時產生對應的技能**): 1. 擬定章節標題、一句說明,以及英文小寫的指令名稱 ``(例如 `security`;不可用 `wiki`、`book-search`、`book-import`,也不可與既有技能重名)。向使用者確認這三項。 2. 技能要放進 jsc-marketplace repo 才會被保留。目前目錄若是該 repo 的 clone(存在 `plugins/jsc-wiki/skills/`),加上 `--skills-dir <目前目錄>/plugins/jsc-wiki/skills`;否則不加,技能會寫進已安裝的插件目錄,下次更新插件時會消失,必須向使用者說明。 - 3. 執行 `B add-chapter <標題> <說明> --key [--skills-dir …]`。它會建立章節頁、產生 `skills//SKILL.md`,並更新插件 README 的領域表與 `wiki` 技能的指令清單。 + 3. 執行 `B add-chapter <標題> <說明> --key [--skills-dir …]`。它會建立章節頁、產生 `skills//SKILL.md`,並同步更新插件 README 的領域表、`wiki` 技能的指令清單;在 repo 內時還會更新市集 README 與 `marketplace.json`、`plugin.json` 的指令清單,並把插件版本號加一。 4. 回報新增的檔案,並提醒:重新載入插件(`/reload-plugins`)後 `/jsc-wiki:` 才會出現。 5. 技能檔在 repo 內時,wiki 推送完成後問使用者是否要開分支、commit 並發 PR(不要自行推送 repo)。 3. **判斷主題是否已存在**:執行 `B find <主題關鍵字…>`,再讀取高分的候選頁面。