diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bbc1ba..2c086af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/), and this project adheres to [Semantic Versioning](https://semver.org/). +## [0.60.0] - 2026-06-12 + +LLM 性能監査(#121)P1 の最終弾(#110)。pre-compact-commit を opt-in 化し、履歴を汚さない stash 方式に書き換えた。 + +### Changed +- **pre-compact-commit を opt-in 化(#110)**: standard / full プロファイルの既定を `false` に変更(全プロファイル既定 OFF)。現行 Claude Code はネイティブの checkpoint / rewind を備え、compaction でディスク上のファイルが失われることはないため、既定有効の価値より `git add -A` の害(untracked の機微ファイル巻き込み・checkpoint コミットによる履歴汚染・squash 時の混入)が上回っていた。**既存ユーザーが明示的に有効化した設定(保存済み config)は上書きされない** +- **実装を stash スナップショット方式に書換(#110)**: `git add -A` + `git commit` を廃止し、`git stash create` + `git stash store -m 'pre-compact snapshot'` に変更。ブランチ履歴にコミットを作らず、作業ツリー・ステージ状態・untracked ファイルに一切触れない。復元は `git stash list` → `git stash apply`。表示名も「Pre-compact Snapshot(コンパクト前スナップショット)」に変更 +- README を「ネイティブ checkpoint / rewind がある現在は opt-in のレガシー保険」という位置づけに書き直し + ## [0.59.0] - 2026-06-12 LLM 性能監査(#121)P1 の第 3 弾(#109)。strategic-compact hook を撤去した。 diff --git a/README.en.md b/README.en.md index 960d21e..3990f9e 100644 --- a/README.en.md +++ b/README.en.md @@ -54,7 +54,7 @@ Claude Code Starter Kit bootstraps a consistent, high-quality Claude Code enviro - **10 rules**: coding-style, git-workflow, hooks, patterns, performance, security, testing, agents, anti-patterns, permissions-guide - **21 slash commands**: /plan, /tdd, /build-fix, /e2e, /verify, /research, /web-article, /oss-analyze, /web-source-review, /handover, /update-kit, and more - **12 skill modules**: backend-patterns, frontend-patterns, security-review, tdd-workflow, prompt-patterns, and more -- **13 optional hooks/settings**: safety net (cc-safety-net), auto update, web content update, tmux reminder, git push review, doc blocker, Prettier or Biome formatting, console.log guard, PR creation log, pre-compact auto-commit, statusline, doc size guard, feature recommendation +- **13 optional hooks/settings**: safety net (cc-safety-net), auto update, web content update, tmux reminder, git push review, doc blocker, Prettier or Biome formatting, console.log guard, PR creation log, pre-compact snapshot (opt-in), statusline, doc size guard, feature recommendation - **14 plugins** from multiple marketplaces: security-guidance, commit-commands, pr-review-toolkit, feature-dev, code-review, claude-md-management, superpowers, code-simplifier, document-skills, example-skills, typescript-lsp, gopls-lsp, pyright-lsp, rust-analyzer-lsp - **i18n**: English & Japanese - **Codex Plugin** sub-agent integration (optional, supports ChatGPT sign-in or OpenAI API key auth) @@ -197,7 +197,7 @@ Hooks are automated safety checks that run automatically when Claude Code execut | Biome Auto-format | Formats and lints JS/TS files after edits (Full uses Biome instead of Prettier) | | Console.log Guard | Warns about console.log statements left in code | | PR Creation Log | Logs PR URL after creation | -| Pre-compact Auto-commit | Auto-commits changes before context compaction | +| Pre-compact Snapshot | Stashes tracked changes before context compaction (opt-in) | | Doc Size Guard | Warns when CLAUDE.md/AGENTS.md exceeds recommended line count (Full only) | | Web Content Update | Auto-updates the web-content-extraction skill's deps on session start (opt-in; default in Full only) | | Feature Recommendation | Notifies about newly available features for the selected profile | diff --git a/README.md b/README.md index d0502e1..2f14261 100644 --- a/README.md +++ b/README.md @@ -477,7 +477,7 @@ URL・公式ドキュメント・ブログ・ニュース・OSS ページを読 | Biome 自動フォーマット | JS/TS ファイルを整形・lint(Full は Prettier の代わりに Biome) | | Console.log ガード | デバッグ用コードの消し忘れを警告 | | PR 作成ログ | Pull Request の URL を記録 | -| **コンパクト前自動コミット** | **コンテキスト圧縮の直前に変更を自動コミット** | +| コンパクト前スナップショット | compact 直前に tracked 変更を git stash に退避(opt-in) | | ドキュメントサイズガード | CLAUDE.md/AGENTS.md の肥大化を警告(Full のみ) | | Web 取得スキル更新 | web-content-extraction スキルの依存を起動時に自動更新(opt-in・Full のみ既定有効) | | 機能レコメンド | 選択プロファイルで利用可能になった新機能を通知 | @@ -538,24 +538,22 @@ SessionStart / SessionEnd フック発火 > **Standard / Full プロファイルでデフォルト有効です。** ウィザードのフック選択で無効にできます。 -#### コンパクト前自動コミットとは? +#### コンパクト前スナップショットとは?(opt-in) -Claude Code を長時間使い続けると、会話が長くなりすぎて **コンテキスト圧縮(compact)** が自動で実行されることがあります。このとき、まだコミットしていない作業中の変更があると、圧縮後に Claude がその変更の文脈を忘れてしまい、**意図しない上書きや作業の消失** が起きる可能性があります。 - -このフックは、compact が実行される **直前** に自動で `git commit` を行い、作業中の変更を安全に保存します。 +compact 直前に、tracked ファイルの変更を `git stash create` + `git stash store` で **stash リストに退避** するフックです。ブランチ履歴にコミットは作られず、作業ツリーもステージ状態も一切変化しません。untracked ファイル(.gitignore 漏れの機微ファイル等)を巻き込むこともありません。 ``` compact が発火 ↓ PreCompact フック実行 - └── 自動コミット: git add -A && git commit(変更がある場合のみ) + └── git stash create + store: tracked 変更を 'pre-compact snapshot' として stash に退避 ↓ compact 実行(コンテキスト圧縮) ``` -コミットメッセージは `checkpoint: pre-compact auto-commit` となるため、通常のコミットと区別できます。git リポジトリ外のプロジェクトでは何も起きません(エラーにはなりません)。 +復元したい場合は `git stash list` で `pre-compact snapshot` を探して `git stash apply` してください。git リポジトリ外のプロジェクトでは何も起きません(エラーにはなりません)。 -> **Standard / Full プロファイルでデフォルト有効です。** 長時間の作業セッションで特に効果を発揮します。 +> **全プロファイルでデフォルト無効(opt-in)です。** 現行の Claude Code はネイティブの checkpoint / rewind を備えており、通常はこのフックは不要です。圧縮前の状態を git 側にも残したい場合のみ、ウィザードのフック選択で有効化してください。過去に有効化した設定(保存済み config)はアップデートで上書きされません。 ### 🧩 プラグイン(14個・マルチマーケットプレイス対応) diff --git a/docs/wizard-config-mapping.en.md b/docs/wizard-config-mapping.en.md index 406453e..0ccffc0 100644 --- a/docs/wizard-config-mapping.en.md +++ b/docs/wizard-config-mapping.en.md @@ -67,7 +67,7 @@ These flags are used to merge the corresponding `features/*/hooks.json` fragment | `ENABLE_MEMORY_PERSISTENCE` | (retired) superseded by native auto-memory | None | Read as a legacy key and ignored | | `ENABLE_STRATEGIC_COMPACT` | (retired) hook removed; skill remains on-demand | None | Read as a legacy key and ignored | | `ENABLE_PR_CREATION_LOG` | PR Creation Log | PR creation logging support | Yes | -| `ENABLE_PRE_COMPACT_COMMIT` | Pre-compact Commit | Commit helper before compact | Yes | +| `ENABLE_PRE_COMPACT_COMMIT` | Pre-compact Snapshot | Stash tracked changes before compact (opt-in; default false in all profiles) | Yes | | `ENABLE_STATUSLINE` | Statusline | Statusline feature toggle | Yes | | `ENABLE_DOC_SIZE_GUARD` | Doc Size Guard | Warn when `CLAUDE.md` / `AGENTS.md` is too large | Yes | | `ENABLE_NO_FLICKER` | No Flicker | Reduce display flicker | Yes | diff --git a/docs/wizard-config-mapping.md b/docs/wizard-config-mapping.md index a8a212a..8723df8 100644 --- a/docs/wizard-config-mapping.md +++ b/docs/wizard-config-mapping.md @@ -67,7 +67,7 @@ | `ENABLE_MEMORY_PERSISTENCE` | (廃止)native auto-memory に委譲 | なし | レガシーキーとして読み捨て | | `ENABLE_STRATEGIC_COMPACT` | (廃止)hook は撤去、skill のみオンデマンドで残存 | なし | レガシーキーとして読み捨て | | `ENABLE_PR_CREATION_LOG` | PR Creation Log | PR 作成ログの補助 | はい | -| `ENABLE_PRE_COMPACT_COMMIT` | Pre-compact Commit | compact 前のコミット補助 | はい | +| `ENABLE_PRE_COMPACT_COMMIT` | Pre-compact Snapshot | compact 前に tracked 変更を git stash へ退避(opt-in・全プロファイル既定 false) | はい | | `ENABLE_STATUSLINE` | Statusline | ステータスライン機能 | はい | | `ENABLE_DOC_SIZE_GUARD` | Doc Size Guard | 大きすぎる `CLAUDE.md` / `AGENTS.md` を警告 | はい | | `ENABLE_NO_FLICKER` | No Flicker | 表示のちらつき低減設定 | はい | diff --git a/features/pre-compact-commit/feature.json b/features/pre-compact-commit/feature.json index 02b305d..f71d683 100644 --- a/features/pre-compact-commit/feature.json +++ b/features/pre-compact-commit/feature.json @@ -1,13 +1,13 @@ { "name": "pre-compact-commit", - "displayName": "Pre-compact Auto-commit", - "description": "Auto-commit all changes before context compaction to prevent work loss during long sessions", + "displayName": "Pre-compact Snapshot", + "description": "Opt-in: snapshot tracked changes to the git stash list before context compaction (legacy insurance; native checkpoint/rewind covers most cases)", "category": "hook", "default": false, "profiles": { "minimal": false, - "standard": true, - "full": true + "standard": false, + "full": false }, "dependencies": [], "conflicts": [] diff --git a/features/pre-compact-commit/hooks.json b/features/pre-compact-commit/hooks.json index 4933131..ed06eb5 100644 --- a/features/pre-compact-commit/hooks.json +++ b/features/pre-compact-commit/hooks.json @@ -6,7 +6,7 @@ "hooks": [ { "type": "command", - "command": "if [ -n \"${CLAUDE_PROJECT_DIR:-}\" ] && cd \"${CLAUDE_PROJECT_DIR}\" 2>/dev/null; then git add -A && { git diff --cached --quiet || git commit -m 'checkpoint: pre-compact auto-commit'; }; fi" + "command": "if [ -n \"${CLAUDE_PROJECT_DIR:-}\" ] && cd \"${CLAUDE_PROJECT_DIR}\" 2>/dev/null; then ref=$(git stash create 2>/dev/null); case \"$ref\" in [0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]*) git stash store -m 'pre-compact snapshot' \"$ref\" 2>/dev/null || true ;; esac; fi" } ] } diff --git a/i18n/en/strings.sh b/i18n/en/strings.sh index 9facfc2..69bf3d1 100644 --- a/i18n/en/strings.sh +++ b/i18n/en/strings.sh @@ -91,7 +91,7 @@ STR_HOOKS_PRETTIER="Prettier Auto-format - Format JS/TS files after edits" STR_HOOKS_BIOME="Biome Auto-format - Format and lint JS/TS files after edits" STR_HOOKS_CONSOLE="Console.log Guard - Warn about console.log statements" STR_HOOKS_PR_LOG="PR Creation Log - Log PR URL after creation" -STR_HOOKS_PRE_COMMIT="Pre-compact Auto-commit - Auto-commit before context compaction" +STR_HOOKS_PRE_COMMIT="Pre-compact Snapshot - Stash tracked changes before context compaction (opt-in)" STR_HOOKS_DOC_SIZE="Doc Size Guard - Warn when CLAUDE.md/AGENTS.md is too large" STR_HOOKS_FEATURE_RECOMMENDATION="Feature Recommendation - Notify about new features on session start" diff --git a/i18n/ja/strings.sh b/i18n/ja/strings.sh index 04a7568..8b0e420 100644 --- a/i18n/ja/strings.sh +++ b/i18n/ja/strings.sh @@ -89,7 +89,7 @@ STR_HOOKS_PRETTIER="Prettier 自動フォーマット - JS/TS ファイルを編 STR_HOOKS_BIOME="Biome 自動フォーマット - JS/TS ファイルを編集後に整形と lint 修正" STR_HOOKS_CONSOLE="Console.log ガード - console.log の警告" STR_HOOKS_PR_LOG="PR 作成ログ - PR 作成後に URL をログ" -STR_HOOKS_PRE_COMMIT="コンパクト前自動コミット - compact 前に変更を自動コミット" +STR_HOOKS_PRE_COMMIT="コンパクト前スナップショット - compact 前に tracked 変更を git stash に退避(opt-in)" STR_HOOKS_DOC_SIZE="ドキュメントサイズガード - CLAUDE.md/AGENTS.md の肥大化を警告" STR_HOOKS_FEATURE_RECOMMENDATION="機能レコメンド - セッション開始時に新機能を通知" diff --git a/profiles/full.conf b/profiles/full.conf index bdc1510..a7fa3de 100644 --- a/profiles/full.conf +++ b/profiles/full.conf @@ -16,7 +16,7 @@ ENABLE_PRETTIER_HOOKS=false ENABLE_BIOME_HOOKS=true ENABLE_CONSOLE_LOG_GUARD=true ENABLE_PR_CREATION_LOG=true -ENABLE_PRE_COMPACT_COMMIT=true +ENABLE_PRE_COMPACT_COMMIT=false ENABLE_SAFETY_NET=true ENABLE_AUTO_UPDATE=true ENABLE_WEB_CONTENT_UPDATE=true diff --git a/profiles/standard.conf b/profiles/standard.conf index 5293f46..61233f3 100644 --- a/profiles/standard.conf +++ b/profiles/standard.conf @@ -16,7 +16,7 @@ ENABLE_PRETTIER_HOOKS=true ENABLE_BIOME_HOOKS=false ENABLE_CONSOLE_LOG_GUARD=true ENABLE_PR_CREATION_LOG=true -ENABLE_PRE_COMPACT_COMMIT=true +ENABLE_PRE_COMPACT_COMMIT=false ENABLE_SAFETY_NET=true ENABLE_AUTO_UPDATE=true ENABLE_WEB_CONTENT_UPDATE=false diff --git a/tests/unit/test-hook-fixtures.sh b/tests/unit/test-hook-fixtures.sh index 838d9e1..99a6768 100644 --- a/tests/unit/test-hook-fixtures.sh +++ b/tests/unit/test-hook-fixtures.sh @@ -172,23 +172,28 @@ mkdir -p "$_pcc_home" "$_pcc_repo" && git init -q . \ && git config user.name "Fixture" \ && git config user.email "fixture@example.com" \ - && printf 'pending change\n' >notes.txt + && printf 'base\n' >notes.txt \ + && git add notes.txt \ + && git commit -q -m "init" \ + && printf 'pending change\n' >>notes.txt ) >/dev/null 2>&1 || _pcc_setup_ok=false _pcc_rc=0 HOME="$_pcc_home" GIT_CONFIG_NOSYSTEM=1 CLAUDE_PROJECT_DIR="$_pcc_repo" \ bash -c "$_pcc_cmd" <"$_hook_fixture_dir/precompact-manual.json" >/dev/null 2>&1 || _pcc_rc=$? -_pcc_last_subject="$(HOME="$_pcc_home" git -C "$_pcc_repo" log -1 --format=%s 2>/dev/null || true)" +_pcc_stash_subject="$(HOME="$_pcc_home" git -C "$_pcc_repo" stash list --format=%gs 2>/dev/null | head -1 || true)" _pcc_dirty="$(HOME="$_pcc_home" git -C "$_pcc_repo" status --porcelain 2>/dev/null || true)" +_pcc_commit_count="$(HOME="$_pcc_home" git -C "$_pcc_repo" rev-list --count HEAD 2>/dev/null || true)" if [[ "$_pcc_setup_ok" == "true" ]] \ && [[ "$_pcc_rc" -eq 0 ]] \ - && assert_equals "checkpoint: pre-compact auto-commit" "$_pcc_last_subject" \ - && assert_empty "$_pcc_dirty"; then - pass "hook-fixtures: pre-compact-commit inline command commits inside CLAUDE_PROJECT_DIR" + && assert_matches "pre-compact snapshot" "$_pcc_stash_subject" \ + && assert_matches "notes\\.txt" "$_pcc_dirty" \ + && assert_equals "1" "$_pcc_commit_count"; then + pass "hook-fixtures: pre-compact-commit stashes tracked changes without touching history or worktree" else - fail "hook-fixtures: pre-compact-commit inline command should commit inside CLAUDE_PROJECT_DIR" + fail "hook-fixtures: pre-compact-commit should store a stash snapshot, keep worktree dirty, add no commit" fi # pre-compact-commit safety: with CLAUDE_PROJECT_DIR unset the command must @@ -211,15 +216,15 @@ _pcc_norun_rc=0 ) || _pcc_norun_rc=$? _pcc_norun_status="$(HOME="$_pcc_home" git -C "$_pcc_norun_repo" status --porcelain 2>/dev/null || true)" -_pcc_norun_head="$(HOME="$_pcc_home" git -C "$_pcc_norun_repo" rev-parse --quiet --verify HEAD 2>/dev/null || true)" +_pcc_norun_stash="$(HOME="$_pcc_home" git -C "$_pcc_norun_repo" stash list 2>/dev/null || true)" if [[ "$_pcc_norun_setup_ok" == "true" ]] \ && [[ "$_pcc_norun_rc" -eq 0 ]] \ && assert_matches "\\?\\? stray\\.txt" "$_pcc_norun_status" \ - && assert_empty "$_pcc_norun_head"; then - pass "hook-fixtures: pre-compact-commit skips commit when CLAUDE_PROJECT_DIR is unset" + && assert_empty "$_pcc_norun_stash"; then + pass "hook-fixtures: pre-compact-commit skips snapshot when CLAUDE_PROJECT_DIR is unset" else - fail "hook-fixtures: pre-compact-commit should not commit in cwd when CLAUDE_PROJECT_DIR is unset" + fail "hook-fixtures: pre-compact-commit should not stash in cwd when CLAUDE_PROJECT_DIR is unset" fi # auto-update.sh (SessionStart) — offline short-circuit: a missing KIT_DIR/.git diff --git a/tests/unit/test-runtime-hooks.sh b/tests/unit/test-runtime-hooks.sh index 7e297f4..4ad82c1 100644 --- a/tests/unit/test-runtime-hooks.sh +++ b/tests/unit/test-runtime-hooks.sh @@ -49,13 +49,17 @@ } { - test_name="pre-compact-commit: cd failure cannot fall through to git commit" + test_name="pre-compact-commit: cd failure cannot fall through to git stash" cmd="$(jq -r '.hooks.PreCompact[0].hooks[0].command' "$PROJECT_DIR/features/pre-compact-commit/hooks.json")" # Guard must check non-empty BEFORE cd: Linux bash treats `cd ""` as a # successful no-op, so a bare `if cd "${VAR:-}"` fail-opens into the cwd. + # The snapshot must use stash create/store (no history commits, no add -A). if jq -e '.hooks.PreCompact[0].matcher == "*"' "$PROJECT_DIR/features/pre-compact-commit/hooks.json" >/dev/null \ && [[ "$cmd" == 'if [ -n "${CLAUDE_PROJECT_DIR:-}" ] && cd '* ]] \ - && [[ "$cmd" == *"git add -A &&"* ]]; then + && [[ "$cmd" == *"git stash create"* ]] \ + && [[ "$cmd" == *"git stash store"* ]] \ + && [[ "$cmd" != *"git add -A"* ]] \ + && [[ "$cmd" != *"git commit"* ]]; then pass "$test_name" else fail "$test_name" diff --git a/wizard/registry.sh b/wizard/registry.sh index 936dfca..9b225db 100644 --- a/wizard/registry.sh +++ b/wizard/registry.sh @@ -211,7 +211,7 @@ _init_hook_labels() { "${STR_HOOKS_BIOME:-Biome Auto-format - Format and lint JS/TS files after edits}" "$STR_HOOKS_CONSOLE" "$STR_HOOKS_PR_LOG" - "${STR_HOOKS_PRE_COMMIT:-Pre-compact auto-commit}" + "${STR_HOOKS_PRE_COMMIT:-Pre-compact Snapshot}" "${STR_HOOKS_DOC_SIZE:-Doc Size Guard - Warn when CLAUDE.md/AGENTS.md is too large}" "${STR_HOOKS_FEATURE_RECOMMENDATION:-Feature Recommendation - Notify about new features on session start}" )