From b1a04182110a929e08e11ec7a64d0acd9aaeb2c5 Mon Sep 17 00:00:00 2001 From: Jeffery Date: Mon, 24 Aug 2026 14:47:26 +0800 Subject: [PATCH] =?UTF-8?q?refactor(worklog):=20worklog-target.sh=20?= =?UTF-8?q?=E6=94=B9=E7=82=BA=E6=8E=A5=E6=94=B6=E5=B7=B2=E7=AE=97=E5=A5=BD?= =?UTF-8?q?=E7=9A=84=20hash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 什麼:tools/worklog-target.sh 不再自行重算 SHA-1,改為直接接收呼叫端算好的 hash 參數;skills/worklog/SKILL.md、README.md 同步更新呼叫方式與工具說明;plugin.json、.claude-plugin/plugin.json、.codex-plugin/plugin.json 版本號由 0.0.3 升至 0.0.4。 為什麼:原本 worklog-target.sh 重複實作了共享的 SHA-1 wiki-hash 演算法,與 jsc-gitea/tools/hash-id 的邏輯重複,違反單一事實來源原則,也和 learn 技能已採用的正確呼叫模式不一致。 如何:移除腳本內建的 sha1sum/shasum 計算與 hash 前綴修正邏輯,改為直接使用傳入的 hash 參數組出 LOG_{HASH}、LOG_CONTENTS;SKILL.md 改為先呼叫 jsc-gitea/tools/hash-id 算出 HASH 再傳給 worklog-target.sh;輸出行為與結果不變。 誰:jsc-meta:skill-check 例行合規稽核(worklog 技能)。 --- .claude-plugin/plugin.json | 2 +- .codex-plugin/plugin.json | 2 +- README.md | 2 +- plugin.json | 2 +- skills/worklog/SKILL.md | 3 ++- tools/worklog-target.sh | 27 ++++++--------------------- 6 files changed, 12 insertions(+), 26 deletions(-) diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json index b4c54fe..51a0132 100644 --- a/.claude-plugin/plugin.json +++ b/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "jsc-log", - "version": "0.0.3", + "version": "0.0.4", "description": "工作日誌(LOG_{HASH} wiki 頁)、技能使用統計與教訓紀錄(LEARN_{HASH} wiki 頁)", "skills": "./skills", "author": { diff --git a/.codex-plugin/plugin.json b/.codex-plugin/plugin.json index a5ed236..c3fdd64 100644 --- a/.codex-plugin/plugin.json +++ b/.codex-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "jsc-log", - "version": "0.0.3", + "version": "0.0.4", "description": "工作日誌(LOG_{HASH} wiki 頁)、技能使用統計與教訓紀錄(LEARN_{HASH} wiki 頁)", "skills": "./skills" } diff --git a/README.md b/README.md index 10e11a6..c9e1151 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Marketplace 統一為 `jsc`(https://gitea.jsc.idv.tw/plugins/jsc.git),安 | 工具 | 用途 | | --- | --- | | `tools/usage-stats.sh` | 聚合 `$JSC_HOME/usage/*.jsonl`:`skills` 列技能使用次數、`chains` 列呼叫鏈次數(皆降冪),`--cli ` 過濾 | -| `tools/worklog-target.sh` | 依 `{owner}/{repo}` 產生 `LOG_{HASH}`、`LOG_CONTENTS` 與符合共享規則的 `HASH` | +| `tools/worklog-target.sh` | 接收已由 `jsc-gitea/tools/hash-id` 算好的 `HASH`,組出 `LOG_{HASH}`、`LOG_CONTENTS`(本身不再計算 SHA-1) | ## Skills 目錄 diff --git a/plugin.json b/plugin.json index e46824f..449fce1 100644 --- a/plugin.json +++ b/plugin.json @@ -1,6 +1,6 @@ { "name": "jsc-log", - "version": "0.0.3", + "version": "0.0.4", "description": "工作日誌(LOG_{HASH} wiki 頁)、技能使用統計與教訓紀錄(LEARN_{HASH} wiki 頁)", "skills": "./skills/" } diff --git a/skills/worklog/SKILL.md b/skills/worklog/SKILL.md index d52c831..b08c2c7 100644 --- a/skills/worklog/SKILL.md +++ b/skills/worklog/SKILL.md @@ -35,7 +35,8 @@ After work completes, collect the ten items below and append a `templates/log-en ## Target page and work week - Page name: `LOG_{HASH}`. -- Compute the target page by running `tools/worklog-target.sh "{owner}/{repo}" all`. Use `PAGE` for `LOG_{HASH}` and `CONTENTS` for `LOG_CONTENTS`. +- Compute `{HASH}` from `{owner}/{repo}` with `jsc-gitea/tools/hash-id` (shared wiki hash rule: first 8 uppercase SHA-1 hex chars; `H` plus the first 7 chars when the raw hash starts with `0-9`, `A`, `B`, or `C`). +- Compute the target page by running `tools/worklog-target.sh "{HASH}" all`. Use `PAGE` for `LOG_{HASH}` and `CONTENTS` for `LOG_CONTENTS`. - The work-week Friday still drives the page content and the row dates. - Read the page via `jsc-gitea:wiki`. If it does not exist, create it with the structure described in `templates/log-contents.md`; otherwise APPEND the new entry at the end. - Update `LOG_CONTENTS` in the same pass (apply `templates/log-contents.md`; add the row if missing). diff --git a/tools/worklog-target.sh b/tools/worklog-target.sh index 0e0028b..f8b102f 100755 --- a/tools/worklog-target.sh +++ b/tools/worklog-target.sh @@ -1,47 +1,32 @@ #!/usr/bin/env sh -# worklog-target.sh: 產生 worklog wiki 目標頁。 +# worklog-target.sh: 由已算好的 hash 組出 worklog wiki 目標頁名稱。 +# hash 一律由 jsc-gitea/tools/hash-id 算出後傳入,本腳本不再自行計算 SHA-1。 # 用法: -# worklog-target.sh [hash|page|contents|all] +# worklog-target.sh [page|contents|all] set -eu usage() { - echo 'usage: worklog-target.sh [hash|page|contents|all]' >&2 + echo 'usage: worklog-target.sh [page|contents|all]' >&2 exit 2 } [ "$#" -ge 1 ] || usage [ "$#" -le 2 ] || usage -repo=$1 +hash=$1 field=${2:-page} -if [ -z "$repo" ]; then +if [ -z "$hash" ]; then usage fi -if command -v sha1sum >/dev/null 2>&1; then - raw=$(printf '%s' "$repo" | sha1sum | awk '{print $1}') -elif command -v shasum >/dev/null 2>&1; then - raw=$(printf '%s' "$repo" | shasum -a 1 | awk '{print $1}') -else - echo 'no SHA-1 helper found' >&2 - exit 1 -fi - -hash=$(printf '%s' "$raw" | cut -c1-8 | tr a-f A-F) -case "$hash" in - [0-9ABC]*) hash="H$(printf '%s' "$hash" | cut -c1-7)" ;; -esac - page="LOG_${hash}" contents='LOG_CONTENTS' case "$field" in - hash) printf '%s\n' "$hash" ;; page) printf '%s\n' "$page" ;; contents) printf '%s\n' "$contents" ;; all) - printf 'HASH=%s\n' "$hash" printf 'PAGE=%s\n' "$page" printf 'CONTENTS=%s\n' "$contents" ;;