Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ 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.79.2] - 2026-10-08

### Fixed
- **キット導入後、Claude Code の起動時に `Permission deny rule (...settings.json): Write(./.env) is not matched by file permission checks — only Edit(path) rules are. ...` という警告が 7 行表示される問題を修正**: `config/permissions.json` の `permissions.deny` に `Write(path)` 形式のルールが 7 件(`Write(./.env)` / `Write(./.env.*)` / `Write(./**/.env)` / `Write(./**/.env.*)` / `Write(/secrets/**)` / `Write(~/.zshrc)` / `Write(~/.bashrc)`)含まれていた。Claude Code はファイルの権限チェックに `Edit(path)` ルールだけを使い(`Edit` ルールはファイルを編集するすべての組み込みツールに適用される)、`Write(path)` ルールは一致させない。2.1.210 以降はこの形式のルールごとに起動時の警告を表示する
- **修正**: 7 件の `Write(path)` ルールを `config/permissions.json` から削除した。同じパスの `Edit(path)` ルールは以前から併記されているため、拒否されるファイル操作は変わらない(削除したルールはもともと一致していなかった)。`allow` と他の deny ルールは変更していない
- **既存インストールへの影響**: 次回の `setup.sh --update`(`/update-kit`、自動アップデート、`install.sh` の再実行)で、`settings.json` の `permissions.deny` から上の 7 件が取り除かれる。`permissions.deny` を手で編集していた環境では、非対話更新の 3-way merge が「キットが削除した項目」を利用者側の値として残すため、更新時にこの 7 つの文字列に完全一致するルールだけを取り除く `_strip_ineffective_permission_rules` を `lib/update.sh` に追加した。対話・非対話のどちらの更新でも、3-way merge の実行有無にかかわらず毎回実行する。利用者が追加したルール(7 件以外の `Write(path)` ルールを含む)、ルールの並び順、`allow` / `ask` などほかのキーは変更せず、該当するルールがない `settings.json` は書き換えない
- **対象外のケース**: manifest を持たず既存の `settings.json` だけがある状態への新規インストールは更新処理を通らない(bootstrap merge だけを行う)ため、その `settings.json` に 7 件のルールが残っていれば警告も残る。該当する場合は `permissions.deny` から上の 7 件を手で削除する
- **MDM**: `mdm/render-expected.py` は `config/permissions.json` から `settings.json` を描画するため、配備される `settings.json` から 7 件のルールがなくなる(MDM の更新は `settings.json` 全体を置き換える)。`KIT_MDM_EXPECTED_POLICY_SHA256` は変わらない(Minimal / Standard / Full × 日本語の 3 通りで、変更前後の `policy.json` の SHA-256 が一致することを確認)。renderer と installer は変更していないため、install bundle の再配布は不要
- **回帰テスト**: アサーションを 12 件追加した。`tests/unit/test-hook-fixtures.sh` に、`config/settings-base.json` / `config/permissions.json` / `features/*/hooks*.json` の `permissions` に `Write(path)` / `NotebookEdit(path)` / `Glob(path)` 形式のルールがないことの静的検査を 1 件、`tests/unit/test-retired-hooks.sh` に掃除関数の単体テストを 6 件(7 件の削除と並び順の保持、キットが出荷していない `Write` ルールと deny 以外のリストを変えないこと、該当がなければ書き換えないこと、`permissions.deny` がない・形が想定外の設定で壊れないこと、不正な JSON で失敗して書き換えないこと、掃除対象が v0.79.1 の 7 件に固定されていること)、`tests/unit/test-update-refactor.sh` に更新の設定フェーズ(`_update_phase_settings`)のテストを 5 件(呼び出しの検査 1 件と、実際のビルドを使って通す 4 件:`permissions.deny` を編集した環境の非対話更新、bootstrap merge、未編集の環境、7 件を持たない環境は書き換えないこと)。修正前のコードでは 12 件中 10 件が失敗する(静的検査は 7 件を検出する。成功する 2 件は、不正な JSON で失敗することと、7 件を持たない環境を書き換えないことの確認)

## [0.79.1] - 2026-10-07

### Fixed
Expand Down
9 changes: 1 addition & 8 deletions config/permissions.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,10 @@
"Edit(./.env.*)",
"Edit(./**/.env)",
"Edit(./**/.env.*)",
"Write(./.env)",
"Write(./.env.*)",
"Write(./**/.env)",
"Write(./**/.env.*)",
"Read(/secrets/**)",
"Edit(/secrets/**)",
"Write(/secrets/**)",
"Edit(~/.zshrc)",
"Write(~/.zshrc)",
"Edit(~/.bashrc)",
"Write(~/.bashrc)"
"Edit(~/.bashrc)"
],
"allow": [
"Read",
Expand Down
64 changes: 64 additions & 0 deletions lib/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2014,6 +2014,65 @@ _strip_retired_hook_entries() {
fi
}

# Write(path) deny rules config/permissions.json shipped until v0.79.1. Claude
# Code 2.1.210+ ignores Write(path) rules (file permission checks only match
# Edit(path), which covers every file-editing tool) and prints a startup
# warning for each one. Their Edit(path) pairs stay in the kit, so dropping
# them does not change what is protected. Historical list: never add to it.
_INEFFECTIVE_KIT_PERMISSION_RULES=(
"Write(./.env)"
"Write(./.env.*)"
"Write(./**/.env)"
"Write(./**/.env.*)"
"Write(/secrets/**)"
"Write(~/.zshrc)"
"Write(~/.bashrc)"
)

# _strip_ineffective_permission_rules - Remove the kit's former Write(path)
# deny rules from settings.json.
#
# Usage: _strip_ineffective_permission_rules <settings-file>
#
# A user-touched permissions.deny keeps kit-removed values through the
# non-interactive 3-way merge (and the bootstrap merge keeps every existing
# value), so the rules would survive the v0.79.2 update and keep the warnings.
# Only exact matches of the strings above are removed from permissions.deny;
# other rules (including Write rules the user added), their order and every
# other key stay as they are, and a file without a match is not rewritten.
_strip_ineffective_permission_rules() {
local settings_file="$1"
[[ -f "$settings_file" ]] || return 1
local rules_json
rules_json="$(printf '%s\n' "${_INEFFECTIVE_KIT_PERMISSION_RULES[@]}" \
| jq -R . | jq -cs .)" || return 1
local filter='
def ineffective: type == "string" and (. as $r | $rules | index($r) != null);'
local probe_rc=0
jq -e --argjson rules "$rules_json" "$filter"'
[.permissions? | objects | .deny? | arrays | .[] | select(ineffective)]
| length > 0
' "$settings_file" >/dev/null 2>&1 || probe_rc=$?
case "$probe_rc" in
0) ;;
1) return 0 ;;
*) return 1 ;;
esac
local tmp
tmp="$(mktemp)" || return 1
_SETUP_TMP_FILES+=("$tmp")
if jq --argjson rules "$rules_json" "$filter"'
.permissions.deny |= map(select(ineffective | not))
' "$settings_file" > "$tmp" 2>/dev/null; then
mv "$tmp" "$settings_file" || return 1
ok "Removed Write(path) permission rules Claude Code ignores from settings.json"
else
rm -f "$tmp" 2>/dev/null || true
warn "Could not remove ineffective Write(path) permission rules from settings.json"
return 1
fi
}

# ---------------------------------------------------------------------------
# _strip_superseded_kit_hook_generations - Drop stale generations of kit hooks
#
Expand Down Expand Up @@ -2506,6 +2565,11 @@ _update_phase_settings() {
# current and new kit all differ, so without this sweep an already-duplicated
# array persists until the kit next edits that very array.
_strip_superseded_kit_hook_generations "$current_settings" "$new_settings" || return 1

# A user-touched permissions.deny keeps the Write(path) rules the kit shipped
# until v0.79.1 (the non-interactive merge keeps kit-removed values), and
# Claude Code 2.1.210+ warns about each of them at startup. Drop them.
_strip_ineffective_permission_rules "$current_settings" || return 1
}

# _claude_md_user_section_has_content - Returns 0 when the user section of a
Expand Down
29 changes: 29 additions & 0 deletions tests/unit/test-hook-fixtures.sh
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,32 @@ if [[ "$_auf_rc" -eq 0 ]] \
else
fail "hook-fixtures: auto-update should consume SessionStart fixture without network access"
fi

# Claude Code 2.1.210+ ignores Write(path) / NotebookEdit(path) / Glob(path)
# permission rules and prints a startup warning for each one: file permission
# checks only match Edit(path) (which covers every file-editing tool) and
# Read(path). Every permission source the settings builder merges must avoid
# them.
_perm_bad_rules=""
for _perm_src in "$PROJECT_DIR/config/settings-base.json" \
"$PROJECT_DIR/config/permissions.json" \
"$PROJECT_DIR"/features/*/hooks*.json; do
[[ -f "$_perm_src" ]] || continue
_perm_found=""
if ! _perm_found="$(jq -r '
(.permissions // {}) | to_entries[]
| select(.value | type == "array") | .value[]
| select(type == "string" and test("^(Write|NotebookEdit|Glob)\\("))
' "$_perm_src" 2>/dev/null)"; then
_perm_found="(unreadable)"
fi
while IFS= read -r _perm_rule; do
[[ -n "$_perm_rule" ]] || continue
_perm_bad_rules+="${_perm_src#"$PROJECT_DIR"/}: ${_perm_rule}"$'\n'
done <<< "$_perm_found"
done
if [[ -z "$_perm_bad_rules" ]]; then
pass "hook-fixtures: permission rules avoid the Write/NotebookEdit/Glob(path) forms Claude Code ignores"
else
fail "hook-fixtures: permission rules must use Edit(path)/Read(path); found $(printf '%s' "$_perm_bad_rules" | grep -c .): $(printf '%s' "$_perm_bad_rules" | tr '\n' ' ')"
fi
135 changes: 135 additions & 0 deletions tests/unit/test-retired-hooks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -561,4 +561,139 @@ printf '%s\n' '{"hooks":{"PreToolUse":[{"matcher":"*","hooks":[{"type":"command"
fi
}

# ── _strip_ineffective_permission_rules ────────────────────────────────────
#
# Up to v0.79.1 the kit shipped seven Write(path) deny rules next to their
# Edit(path) pairs. Claude Code 2.1.210+ ignores Write(path) rules and prints a
# startup warning for each one. A user-touched permissions.deny keeps them
# through the non-interactive 3-way merge ("removed by the kit"), so this sweep
# removes exactly those seven strings on every update.
_rh_perm() { # <settings-file>
HOME=/home/u "${BASH:-bash}" -c '
set -uo pipefail
PROJECT_DIR="'"$PROJECT_DIR"'"
ok(){ :; }; warn(){ :; }; info(){ :; }; is_true(){ [[ "$1" == "true" ]]; }
_SETUP_TMP_FILES=()
source "$PROJECT_DIR/lib/features.sh"
source "$PROJECT_DIR/lib/snapshot.sh"
source "$PROJECT_DIR/lib/update.sh" 2>/dev/null || true
_strip_ineffective_permission_rules "'"$1"'"
'
}

_rh_kit_write_rules='["Write(./.env)","Write(./.env.*)","Write(./**/.env)","Write(./**/.env.*)","Write(/secrets/**)","Write(~/.zshrc)","Write(~/.bashrc)"]'

{
test_name="permission-sweep: the seven kit Write(path) deny rules are removed, other rules keep their order"
_rh_pm="$_rh_tmp/perm-strip.json"
printf '%s\n' '{"permissions":{
"allow":["Read","Write","Edit"],
"deny":["Bash(sudo *)","Edit(./.env)","Write(./.env)","Write(./.env.*)","Bash(my-own *)",
"Write(./**/.env)","Write(./**/.env.*)","Read(/secrets/**)","Edit(/secrets/**)",
"Write(/secrets/**)","Edit(~/.zshrc)","Write(~/.zshrc)","Edit(~/.bashrc)",
"Write(~/.bashrc)","Read(~/my-notes/**)"],
"defaultMode":"default"},
"env":{"A":"1"}}' > "$_rh_pm"
_rh_rc=0; _rh_perm "$_rh_pm" >/dev/null 2>&1 || _rh_rc=$?
if [[ "$_rh_rc" -eq 0 ]] \
&& jq -e '
.permissions.deny == ["Bash(sudo *)","Edit(./.env)","Bash(my-own *)","Read(/secrets/**)",
"Edit(/secrets/**)","Edit(~/.zshrc)","Edit(~/.bashrc)","Read(~/my-notes/**)"]
and .permissions.allow == ["Read","Write","Edit"]
and .permissions.defaultMode == "default"
and .env == {"A":"1"}' "$_rh_pm" >/dev/null 2>&1; then
pass "$test_name"
else
fail "$test_name"
fi
}

{
test_name="permission-sweep: Write rules the kit never shipped and non-deny lists are untouched"
_rh_pm="$_rh_tmp/perm-user-write.json"
printf '{"permissions":{"allow":["Write(./.env)"],"ask":["Write(~/.zshrc)"],"deny":["Write(./.env.local)","Write(~/.ssh/config)"," Write(./.env)"]}}\n' > "$_rh_pm"
_rh_before="$(cat "$_rh_pm")"
_rh_inode_before="$(_rh_inode "$_rh_pm")"
_rh_rc=0; _rh_perm "$_rh_pm" >/dev/null 2>&1 || _rh_rc=$?
if [[ "$_rh_rc" -eq 0 && "$(cat "$_rh_pm")" == "$_rh_before" \
&& "$(_rh_inode "$_rh_pm")" == "$_rh_inode_before" ]]; then
pass "$test_name"
else
fail "$test_name"
fi
}

{
test_name="permission-sweep: settings without a kit Write rule are not rewritten"
_rh_pm="$_rh_tmp/perm-clean.json"
# Compact, key order the kit never writes: any jq round trip changes bytes.
printf '{"permissions":{"deny":["Edit(./.env)","Read(./.env)"],"allow":["Edit"]},"env":{"A":"1"}}\n' > "$_rh_pm"
_rh_before="$(cat "$_rh_pm")"
_rh_inode_before="$(_rh_inode "$_rh_pm")"
_rh_rc=0; _rh_perm "$_rh_pm" >/dev/null 2>&1 || _rh_rc=$?
if [[ "$_rh_rc" -eq 0 && "$(cat "$_rh_pm")" == "$_rh_before" \
&& "$(_rh_inode "$_rh_pm")" == "$_rh_inode_before" ]]; then
pass "$test_name"
else
fail "$test_name"
fi
}

{
test_name="permission-sweep: settings without permissions.deny (or with odd shapes) are left alone"
_rh_ok=true
_rh_i=0
for _rh_doc in '{"env":{"A":"1"}}' '{"permissions":{"allow":["Edit"]}}' \
'{"permissions":{"deny":null}}' '{"permissions":{"deny":"Write(./.env)"}}' \
'{"permissions":"Write(./.env)"}' '{"permissions":{"deny":[{"rule":"Write(./.env)"},7]}}' \
'[]' '{}'; do
_rh_i=$((_rh_i + 1))
_rh_pm="$_rh_tmp/perm-shape-$_rh_i.json"
printf '%s\n' "$_rh_doc" > "$_rh_pm"
_rh_rc=0; _rh_perm "$_rh_pm" >/dev/null 2>&1 || _rh_rc=$?
if [[ "$_rh_rc" -ne 0 || "$(cat "$_rh_pm")" != "$_rh_doc" ]]; then
_rh_ok=false
fi
done
if [[ "$_rh_ok" == "true" ]]; then
pass "$test_name"
else
fail "$test_name"
fi
}

{
test_name="permission-sweep: invalid settings fail without being rewritten"
_rh_pm="$_rh_tmp/perm-broken.json"
printf '{"permissions": ' > "$_rh_pm"
_rh_rc=0; _rh_perm "$_rh_pm" >/dev/null 2>&1 || _rh_rc=$?
_rh_rc_missing=0; _rh_perm "$_rh_tmp/no-such-settings.json" >/dev/null 2>&1 || _rh_rc_missing=$?
if [[ "$_rh_rc" -ne 0 && "$_rh_rc_missing" -ne 0 \
&& "$(cat "$_rh_pm")" == '{"permissions": ' ]]; then
pass "$test_name"
else
fail "$test_name"
fi
}

{
test_name="permission-sweep: the swept list is exactly the Write rules v0.79.1 shipped"
# Pin the sweep to the historical kit rules; a new kit rule must never be
# added to this list (the static check in test-hook-fixtures.sh keeps
# config/permissions.json free of the form).
_rh_swept="$(HOME=/home/u "${BASH:-bash}" -c '
PROJECT_DIR="'"$PROJECT_DIR"'"
ok(){ :; }; warn(){ :; }; info(){ :; }; is_true(){ [[ "$1" == "true" ]]; }
source "$PROJECT_DIR/lib/features.sh"
source "$PROJECT_DIR/lib/snapshot.sh"
source "$PROJECT_DIR/lib/update.sh" 2>/dev/null || true
printf "%s\n" "${_INEFFECTIVE_KIT_PERMISSION_RULES[@]}"
' 2>/dev/null | jq -R . | jq -cs .)"
if [[ "$_rh_swept" == "$(jq -c . <<< "$_rh_kit_write_rules")" ]]; then
pass "$test_name"
else
fail "$test_name (got: $_rh_swept)"
fi
}

rm -rf "$_rh_tmp"
Loading
Loading