From 01a751c653a4d47b3dc24d2c32333a1485eb7efc Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 2 Dec 2026 15:04:54 +0700 Subject: [PATCH 1/4] fix(install): fix uninstall, force-both, toml mode, and copy trims Fix three installer bugs and add two out-of-place copy trims: - Skip deleting checkout files under dwarves-kit/ during in-place --uninstall (direct clone or symlinked checkout). - Replace ls-1 pipelines in the install summary with glob loops so --force-both after compat install exits 0 under pipefail. - Preserve existing kit.toml permissions (or source mode on fresh install) before moving mktemp output into place. - Exclude lib/*/tests and lib/*/*/tests when copying lib/ out of place. - Copy only the 9 referenced docs/impl-playbook files into out-of-place installs. --- docs/reference/FEATURES.md | 6 +- install.sh | 203 ++++++++++++---------- tests/test-install-fixes.sh | 327 ++++++++++++++++++++++++++++++++++++ 3 files changed, 448 insertions(+), 88 deletions(-) create mode 100755 tests/test-install-fixes.sh diff --git a/docs/reference/FEATURES.md b/docs/reference/FEATURES.md index 2c30f9d8..7b7195a4 100644 --- a/docs/reference/FEATURES.md +++ b/docs/reference/FEATURES.md @@ -20,7 +20,7 @@ GENERATED , do not hand-edit. Regenerate: `bash lib/registry/feature-registry.sh | `/kit:design` | `[H/I]` | Opt-in interactive solution-design beat between /think and /spec. Use when the operator wants to shape HOW to build after the idea passed /… | SPEC-003, SPEC-004, SPEC-005 +162 | test-anomalies-advisor.sh, test-board-mirror-cleanup.sh, test-ceremony-fits-diff.sh +40 | | `/kit:devs-team` | `[H/I]` | Parallel multi-lens critique of a solution design (the active spec if present, else the decision brief). Dispatches 5 engineering lenses, m… | SPEC-016, SPEC-018, SPEC-019 +14 | test-gate-vocab-recording.sh, test-meta-review-verifiers.sh, test-meta-spec-depth.sh +1 | | `/kit:dispatch` | `[H/I]` | Fire several disjoint VALIDATED specs concurrently, each in its own worktree, then converge. Cross-goal fan-out behind a disjointness gate … | SPEC-002, SPEC-016, SPEC-017 +114 | test-advisor.sh, test-agent-effectiveness.sh, test-attempt-state-race.sh +52 | -| `/kit:docs` | `[H/I]` | Update all project documentation to match the current codebase. Cross-references the diff against every doc file and fixes drift. | SPEC-001, SPEC-002, SPEC-003 +292 | conform.sh, test-active-spec-pick.sh, test-adapters.sh +161 | +| `/kit:docs` | `[H/I]` | Update all project documentation to match the current codebase. Cross-references the diff against every doc file and fixes drift. | SPEC-001, SPEC-002, SPEC-003 +292 | conform.sh, test-active-spec-pick.sh, test-adapters.sh +162 | | `/kit:draft-agent` | `[H/I]` | Meta-agent agent-builder. From a one-line description, generates a new subagent definition OR a mega-goal sub-goal file and (by default) in… | SPEC-089, SPEC-108, SPEC-139 +1 | test-agent-effectiveness.sh, test-command-emit-sweep.sh, test-meta-agent.sh +1 | | `/kit:execute` | `[H/I]` | Whole-spec execution with verification. Dispatches one builder for the whole spec, verifies every task's criteria once at the end, retries … | SPEC-001, SPEC-003, SPEC-004 +82 | test-board-work.sh, test-break-it.sh, test-config-registry.sh +29 | | `/kit:explain` | `[H/I]` | Turn a merged change into a literate-diff explainer a human READS to understand: background -> goal + intuition -> a prose-ordered diff -> … | SPEC-050, SPEC-060, SPEC-094 +25 | test-boundary-lint.sh, test-clean-room.sh, test-command-emit-sweep.sh +13 | @@ -103,7 +103,7 @@ GENERATED , do not hand-edit. Regenerate: `bash lib/registry/feature-registry.sh | `observe` | `[I]` | Query and render the kit's control plane (fleet runs, spend, debt; backed by lib/bench) from an agent session. NOT for your own Claude Code… | SPEC-033, SPEC-052, SPEC-128 +17 | smoke.sh, test-bin-forwarders.sh, test-kit-contract.sh +4 | | `repo-hygiene` | `[I]` | Use for the whole-repo decay audit, "run the repo-hygiene loop", "what has rotted in this repo", "is anything mis-shelved", "dọn repo", o… | SPEC-256 | test-audit-cadence.sh, test-audit-verdict-grammar.sh, test-repohygiene.sh | | `skill-review` | `[I]` | Review and promote skill drafts that skill-curator staged from past sessions. Use when the user runs /skill-review, says "review my skill d… | SPEC-218, SPEC-285 | test-async.sh, test-bin-forwarders.sh, test-egress-visible.sh +7 | -| `stats` | `[I]` | Query or render ledger state and propose backlog rows off anomalies. Use when asked to SEE it -- "show me the ledger state", "my waived gat… | SPEC-001, SPEC-182, SPEC-192 +24 | test-anomalies-advisor.sh, test-bin-forwarders.sh, test-board-brief.sh +38 | +| `stats` | `[I]` | Query or render ledger state and propose backlog rows off anomalies. Use when asked to SEE it -- "show me the ledger state", "my waived gat… | SPEC-001, SPEC-182, SPEC-192 +24 | test-anomalies-advisor.sh, test-bin-forwarders.sh, test-board-brief.sh +39 | | `system-design` | `[I]` | Own the repo's system design document at docs/SYSTEM-DESIGN.md: its format, its updates per feature, and rendering it as a UML drawing set … | SPEC-292, SPEC-426, SPEC-427 | test-doc-figures.sh, test-system-design.sh | | `topology-drift` | `[I]` | Maintainer-only. Use to audit THIS KIT's OWN feature estate against its path map, "run the topology-drift loop", "feature inventory drift".… | SPEC-225, SPEC-235, SPEC-237 | test-audit-cadence.sh, test-audit-scanner-contract.sh, test-audit-verdict-grammar.sh +1 | | `web-drift` | `[I]` | Use for the live-website agent-readiness audit, "run the web-drift loop", "web drift sweep", "check the public sites", or a scheduled caden… | SPEC-232, SPEC-256, SPEC-298 | test-audit-cadence.sh, test-audit-verdict-grammar.sh, test-web-drift-refusal-guard.sh | @@ -134,7 +134,7 @@ GENERATED , do not hand-edit. Regenerate: `bash lib/registry/feature-registry.sh | `post-compact-reinject.sh` | `[E]` | SessionStart | SessionStart hook (matcher compact) that re-injects the critical project rules compaction strips from context. | SPEC-003, SPEC-010, SPEC-034 +5 | test-active-spec-pick.sh, test-hooks.sh, test-install-modules.sh +2 | | `pre-compact-backup.sh` | `[E]` | PreCompact | PreCompact hook that saves a structured snapshot of the session before auto-compaction. | SPEC-010, SPEC-084, SPEC-334 +3 | test-active-spec-pick.sh, test-hooks.sh, test-install-modules.sh +3 | | `prose-rag.sh` | `[E]` | UserPromptSubmit | UserPromptSubmit shim that injects prior-note recall when PROSE_RAG_INJECT=1; dormant otherwise. | SPEC-194, SPEC-204, SPEC-249 +6 | smoke.sh, test-adopt.sh, test-bin-forwarders.sh +8 | -| `safety-gate.sh` | `[E]` | PreToolUse | PreToolUse hook that blocks destructive deletes, direct pushes to main or master, and force-pushes. | SPEC-003, SPEC-014, SPEC-019 +15 | test-anchor-module-gate.sh, test-codex-hooks.sh, test-codex-manifest.sh +12 | +| `safety-gate.sh` | `[E]` | PreToolUse | PreToolUse hook that blocks destructive deletes, direct pushes to main or master, and force-pushes. | SPEC-003, SPEC-014, SPEC-019 +15 | test-anchor-module-gate.sh, test-codex-hooks.sh, test-codex-manifest.sh +13 | | `secrets-guard.sh` | `[E]` | PreToolUse | PreToolUse hook that blocks the agent from reading secret files, with the path canonicalized first. | SPEC-014, SPEC-084, SPEC-288 +4 | test-codex-hooks.sh, test-codex-manifest.sh, test-entry.sh +6 | | `ship-gate.sh` | `[E]` | PreToolUse | PreToolUse hook that refuses a push onto a default branch, or a push or PR when the spec lane has a required gate with no ran or override e… | SPEC-006, SPEC-042, SPEC-044 +88 | test-active-spec-pick.sh, test-anchor-module-gate.sh, test-ceremony-fits-diff.sh +52 | | `slop-cleaner.sh` | `[E]` | Stop | Stop hook that nudges, never blocks, on bloat signals in recently modified source files after long sessions. | SPEC-013, SPEC-014, SPEC-084 +4 | test-anchor-module-gate.sh, test-codex-hooks.sh, test-egress-visible.sh +3 | diff --git a/install.sh b/install.sh index 0d5aa0f9..6510140b 100755 --- a/install.sh +++ b/install.sh @@ -41,6 +41,10 @@ KIT_MOD_BASE="integrations/claude-code" KIT_MODS="board-pane secrets-veil memory-lens loop-detective context-inspector" KIT_MOD_PARTS=".claude-plugin hooks src types LICENSE VENDORED.md" +# Implementation playbooks referenced by agents/, commands/, hooks/, or lib/. +# Out-of-place installs copy only these files instead of unreferenced playbooks. +KIT_IMPL_PLAYBOOKS="cloudflare.md coding-hygiene.md exploratory-testing.md financial-data-handling.md frontend-design-engineering.md security.md test-case-design.md testing-strategy.md threat-modeling.md" + # kit_drop_mod_dirs ... -- remove each path from env.CLAUDE_CODE_PLUGIN_DIRS in settings.json # (every other entry stays) and drop the key when it ends empty. kit_drop_mod_dirs() { @@ -160,78 +164,85 @@ if [ "${1:-}" = "--uninstall" ]; then fi done - # Remove the hook links we created (and the dir if it is now empty). Only - # symlinks are removed, so an in-place clone (KIT_DIR == ~/.claude/dwarves-kit, - # where the scripts are real files) keeps its hooks; that layout is torn down by - # deleting the clone, per the message at the end of this block. - HOOKS_DEST="$CLAUDE_DIR/dwarves-kit/hooks" - if [ -L "$HOOKS_DEST" ]; then - rm "$HOOKS_DEST" - echo "[ok] Removed hooks symlink: $HOOKS_DEST" - elif [ -d "$HOOKS_DEST" ]; then - for HOOK_FILE in "$KIT_DIR/hooks/"*.sh; do - LINK="$HOOKS_DEST/$(basename "$HOOK_FILE")" - # symlinks (pre-SPEC-066) and copied files (SPEC-066) both belong to the kit - { [ -L "$LINK" ] || [ -f "$LINK" ]; } && rm "$LINK" - done - # Companion *.py/*.json files installed alongside a hooks/*.sh shim (see install, - # step 1b); hooks.json (the plugin manifest) is excluded, matching install. - for AUX_FILE in "$KIT_DIR/hooks/"*.py "$KIT_DIR/hooks/"*.json; do - [ -f "$AUX_FILE" ] || continue - [ "$(basename "$AUX_FILE")" = "hooks.json" ] && continue - LINK="$HOOKS_DEST/$(basename "$AUX_FILE")" - { [ -L "$LINK" ] || [ -f "$LINK" ]; } && rm "$LINK" - done - rmdir "$HOOKS_DEST" 2>/dev/null && echo "[ok] Removed hooks directory: $HOOKS_DEST" + # Detect an in-place install (checkout IS $CLAUDE_DIR/dwarves-kit, directly or via symlink). + # Uninstall only removes what install created outside the checkout; checkout files stay intact. + UNINSTALL_KIT_REAL="$(cd "$KIT_DIR" && pwd -P)" + UNINSTALL_DEST_REAL="$(cd "$CLAUDE_DIR/dwarves-kit" 2>/dev/null && pwd -P || true)" + UNINSTALL_IN_PLACE=0 + if [ -n "$UNINSTALL_DEST_REAL" ] && [ "$UNINSTALL_KIT_REAL" = "$UNINSTALL_DEST_REAL" ]; then + UNINSTALL_IN_PLACE=1 fi - # Remove the bin/ stable-entrypoint dir we deployed (SPEC-184). - BIN_DEST="$CLAUDE_DIR/dwarves-kit/bin" - if [ -L "$BIN_DEST" ]; then - rm "$BIN_DEST" && echo "[ok] Removed bin symlink: $BIN_DEST" - elif [ -d "$BIN_DEST" ] && [ -f "$CLAUDE_DIR/dwarves-kit/INSTALL-STAMP" ]; then - rm -rf "$BIN_DEST" && echo "[ok] Removed copied bin dir: $BIN_DEST" - fi + if [ "$UNINSTALL_IN_PLACE" -eq 1 ]; then + echo "[skip] In-place checkout ($KIT_DIR); keeping checkout hooks, lib, bin, docs, settings.json, and kit.toml" + else + # Remove the hook links/copies we created (and the dir if it is now empty). + HOOKS_DEST="$CLAUDE_DIR/dwarves-kit/hooks" + if [ -L "$HOOKS_DEST" ]; then + rm "$HOOKS_DEST" + echo "[ok] Removed hooks symlink: $HOOKS_DEST" + elif [ -d "$HOOKS_DEST" ]; then + for HOOK_FILE in "$KIT_DIR/hooks/"*.sh; do + [ -f "$HOOK_FILE" ] || continue + LINK="$HOOKS_DEST/$(basename "$HOOK_FILE")" + # symlinks (pre-SPEC-066) and copied files (SPEC-066) both belong to the kit + { [ -L "$LINK" ] || [ -f "$LINK" ]; } && rm "$LINK" + done + # Companion *.py/*.json files installed alongside a hooks/*.sh shim (see install, + # step 1b); hooks.json (the plugin manifest) is excluded, matching install. + for AUX_FILE in "$KIT_DIR/hooks/"*.py "$KIT_DIR/hooks/"*.json; do + [ -f "$AUX_FILE" ] || continue + [ "$(basename "$AUX_FILE")" = "hooks.json" ] && continue + LINK="$HOOKS_DEST/$(basename "$AUX_FILE")" + { [ -L "$LINK" ] || [ -f "$LINK" ]; } && rm "$LINK" + done + rmdir "$HOOKS_DEST" 2>/dev/null && echo "[ok] Removed hooks directory: $HOOKS_DEST" || true + fi - # Remove the lib we deployed (SPEC-045; symlink pre-066, real dir post-066). - LIB_DEST="$CLAUDE_DIR/dwarves-kit/lib" - if [ -L "$LIB_DEST" ]; then - rm "$LIB_DEST" && echo "[ok] Removed lib symlink: $LIB_DEST" - elif [ -d "$LIB_DEST" ] && [ -f "$CLAUDE_DIR/dwarves-kit/INSTALL-STAMP" ]; then - rm -rf "$LIB_DEST" && echo "[ok] Removed copied lib dir: $LIB_DEST" - fi + # Remove the bin/ stable-entrypoint dir we deployed (SPEC-184). + BIN_DEST="$CLAUDE_DIR/dwarves-kit/bin" + if [ -L "$BIN_DEST" ]; then + rm "$BIN_DEST" && echo "[ok] Removed bin symlink: $BIN_DEST" + elif [ -d "$BIN_DEST" ] && [ -f "$CLAUDE_DIR/dwarves-kit/INSTALL-STAMP" ]; then + rm -rf "$BIN_DEST" && echo "[ok] Removed copied bin dir: $BIN_DEST" + fi - # Remove the docs/impl-playbook/ dir we deployed (review-team agent reference rules). - PLAYBOOK_DEST="$CLAUDE_DIR/dwarves-kit/docs/impl-playbook" - if [ -L "$PLAYBOOK_DEST" ]; then - rm "$PLAYBOOK_DEST" && echo "[ok] Removed docs/impl-playbook symlink: $PLAYBOOK_DEST" - elif [ -d "$PLAYBOOK_DEST" ] && [ -f "$CLAUDE_DIR/dwarves-kit/INSTALL-STAMP" ]; then - rm -rf "$PLAYBOOK_DEST" && echo "[ok] Removed copied docs/impl-playbook dir: $PLAYBOOK_DEST" - fi + # Remove the lib we deployed (SPEC-045; symlink pre-066, real dir post-066). + LIB_DEST="$CLAUDE_DIR/dwarves-kit/lib" + if [ -L "$LIB_DEST" ]; then + rm "$LIB_DEST" && echo "[ok] Removed lib symlink: $LIB_DEST" + elif [ -d "$LIB_DEST" ] && [ -f "$CLAUDE_DIR/dwarves-kit/INSTALL-STAMP" ]; then + rm -rf "$LIB_DEST" && echo "[ok] Removed copied lib dir: $LIB_DEST" + fi - # Remove the settings.json template we deployed (compat symlink or out-of-place copy). - SETTINGS_TEMPLATE_DEST="$CLAUDE_DIR/dwarves-kit/settings.json" - if [ -L "$SETTINGS_TEMPLATE_DEST" ]; then - rm "$SETTINGS_TEMPLATE_DEST" && echo "[ok] Removed settings.json symlink: $SETTINGS_TEMPLATE_DEST" - elif [ -f "$SETTINGS_TEMPLATE_DEST" ] && [ -f "$CLAUDE_DIR/dwarves-kit/INSTALL-STAMP" ]; then - rm "$SETTINGS_TEMPLATE_DEST" && echo "[ok] Removed copied settings.json template: $SETTINGS_TEMPLATE_DEST" - fi + # Remove the docs/impl-playbook/ dir we deployed (review-team agent reference rules). + PLAYBOOK_DEST="$CLAUDE_DIR/dwarves-kit/docs/impl-playbook" + if [ -L "$PLAYBOOK_DEST" ]; then + rm "$PLAYBOOK_DEST" && echo "[ok] Removed docs/impl-playbook symlink: $PLAYBOOK_DEST" + elif [ -d "$PLAYBOOK_DEST" ] && [ -f "$CLAUDE_DIR/dwarves-kit/INSTALL-STAMP" ]; then + rm -rf "$PLAYBOOK_DEST" && echo "[ok] Removed copied docs/impl-playbook dir: $PLAYBOOK_DEST" + fi - # Remove the operate-contract files (SPEC-049 symlinks, or SPEC-066 copies recorded in - # the stamp's managed= list; a user's own file is never in the list and never removed). - UNMANAGED="$(grep '^managed=' "$CLAUDE_DIR/dwarves-kit/INSTALL-STAMP" 2>/dev/null | cut -d= -f2- || true)" - for CONTRACT in AGENTS.md WORKFLOW.md docs/WORKFLOW.md; do - LINK="$CLAUDE_DIR/dwarves-kit/$CONTRACT" - if [ -L "$LINK" ]; then rm "$LINK" && echo "[ok] Removed $CONTRACT symlink: $LINK" - elif [ -f "$LINK" ] && printf '%s' " $UNMANAGED " | grep -q " $CONTRACT "; then - rm "$LINK" && echo "[ok] Removed kit-managed $CONTRACT: $LINK" + # Remove the settings.json template we deployed (compat symlink or out-of-place copy). + SETTINGS_TEMPLATE_DEST="$CLAUDE_DIR/dwarves-kit/settings.json" + if [ -L "$SETTINGS_TEMPLATE_DEST" ]; then + rm "$SETTINGS_TEMPLATE_DEST" && echo "[ok] Removed settings.json symlink: $SETTINGS_TEMPLATE_DEST" + elif [ -f "$SETTINGS_TEMPLATE_DEST" ] && [ -f "$CLAUDE_DIR/dwarves-kit/INSTALL-STAMP" ]; then + rm "$SETTINGS_TEMPLATE_DEST" && echo "[ok] Removed copied settings.json template: $SETTINGS_TEMPLATE_DEST" fi - done - [ -f "$CLAUDE_DIR/dwarves-kit/INSTALL-STAMP" ] && rm "$CLAUDE_DIR/dwarves-kit/INSTALL-STAMP" && echo "[ok] Removed install stamp" - for CONTRACT in AGENTS.md WORKFLOW.md docs/WORKFLOW.md; do - LINK="$CLAUDE_DIR/dwarves-kit/$CONTRACT" - if [ -L "$LINK" ]; then rm "$LINK" && echo "[ok] Removed $CONTRACT symlink: $LINK"; fi - done + + # Remove the operate-contract files (SPEC-049 symlinks, or SPEC-066 copies recorded in + # the stamp's managed= list; a user's own file is never in the list and never removed). + UNMANAGED="$(grep '^managed=' "$CLAUDE_DIR/dwarves-kit/INSTALL-STAMP" 2>/dev/null | cut -d= -f2- || true)" + for CONTRACT in AGENTS.md WORKFLOW.md docs/WORKFLOW.md; do + LINK="$CLAUDE_DIR/dwarves-kit/$CONTRACT" + if [ -L "$LINK" ]; then rm "$LINK" && echo "[ok] Removed $CONTRACT symlink: $LINK" + elif [ -f "$LINK" ] && printf '%s' " $UNMANAGED " | grep -q " $CONTRACT "; then + rm "$LINK" && echo "[ok] Removed kit-managed $CONTRACT: $LINK" + fi + done + [ -f "$CLAUDE_DIR/dwarves-kit/INSTALL-STAMP" ] && rm "$CLAUDE_DIR/dwarves-kit/INSTALL-STAMP" && echo "[ok] Removed install stamp" + fi # Remove dwarves-kit hooks from settings.json if [ -f "$SETTINGS_FILE" ] && command -v jq >/dev/null 2>&1; then @@ -271,7 +282,7 @@ if [ "${1:-}" = "--uninstall" ]; then kit_drop_mod_dirs "${_mod_paths[@]}" echo "[ok] Removed the Claude Code mod paths from settings.json env.CLAUDE_CODE_PLUGIN_DIRS" fi - if [ "$(cd "$KIT_DIR" && pwd -P)" != "$(cd "$CLAUDE_DIR/dwarves-kit" 2>/dev/null && pwd -P || true)" ]; then + if [ "$UNINSTALL_IN_PLACE" -eq 0 ]; then for _m in $KIT_MODS; do if [ -d "$CLAUDE_DIR/dwarves-kit/$KIT_MOD_BASE/$_m" ]; then rm -rf "$CLAUDE_DIR/dwarves-kit/$KIT_MOD_BASE/$_m" @@ -279,14 +290,14 @@ if [ "${1:-}" = "--uninstall" ]; then fi done rmdir "$CLAUDE_DIR/dwarves-kit/$KIT_MOD_BASE" "$CLAUDE_DIR/dwarves-kit/integrations" 2>/dev/null || true - fi - unset _m _mod_paths - # Remove the module manifest (ID-277 SG-04); it is meaningless without an install. - if [ -f "$CLAUDE_DIR/dwarves-kit/kit.toml" ]; then - rm "$CLAUDE_DIR/dwarves-kit/kit.toml" - echo "[ok] Removed module manifest: kit.toml" + # Remove the module manifest (ID-277 SG-04); only for out-of-place installs. + if [ -L "$CLAUDE_DIR/dwarves-kit/kit.toml" ] || [ -f "$CLAUDE_DIR/dwarves-kit/kit.toml" ]; then + rm "$CLAUDE_DIR/dwarves-kit/kit.toml" + echo "[ok] Removed module manifest: kit.toml" + fi fi + unset _m _mod_paths echo "" echo "=== Uninstall complete ===" @@ -376,7 +387,16 @@ kit_toml_modules_section_true() { # `[gate]`, `[features]`, `[team]`) rides through unchanged, so the install copy is # the full schema, not just the old minimal manifest. kit_render_install_toml() { - local src="$1" dst="$2" tmp + local src="$1" dst="$2" tmp mode="" + if [ -f "$dst" ] && [ ! -L "$dst" ]; then + mode="$(stat -c '%a' "$dst" 2>/dev/null || stat -f '%Lp' "$dst" 2>/dev/null || true)" + elif [ -f "$src" ]; then + mode="$(stat -c '%a' "$src" 2>/dev/null || stat -f '%Lp' "$src" 2>/dev/null || true)" + fi + case "$mode" in + [0-7][0-7][0-7]|[0-7][0-7][0-7][0-7]) ;; + *) mode="0644" ;; + esac tmp="$(mktemp "$(dirname "$dst")/.kit.toml.XXXXXX")" { echo "# --- Rendered by install.sh from the repo-root kit.toml + --with (SPEC-183). ---" @@ -396,7 +416,7 @@ kit_render_install_toml() { } { print } ' "$src" - } > "$tmp" && mv -f "$tmp" "$dst" + } > "$tmp" && chmod "$mode" "$tmp" && mv -f "$tmp" "$dst" || { rm -f "$tmp"; return 1; } } KIT_WITH_ARG="" @@ -718,9 +738,10 @@ else # Patterns mirror the .gitignore build-output rules. (cd "$KIT_DIR" && tar -cf - \ --exclude='.venv' --exclude='__pycache__' --exclude='*.pyc' \ - --exclude='lib/*/rust/target' --exclude='lib/*/bin/*-rs' lib) \ + --exclude='lib/*/rust/target' --exclude='lib/*/bin/*-rs' \ + --exclude='lib/*/tests' --exclude='lib/*/*/tests' lib) \ | tar -xpf - -C "$CLAUDE_DIR/dwarves-kit" - echo "[ok] Copied lib into $LIB_DEST (pinned, SPEC-066; build output skipped)" + echo "[ok] Copied lib into $LIB_DEST (pinned, SPEC-066; build output and module tests skipped)" fi # 1c-bis. Deploy bin/ -- the STABLE consumer entrypoint dir (SPEC-184). Consumers (an @@ -791,8 +812,13 @@ else mkdir -p "$CLAUDE_DIR/dwarves-kit/docs" [ -L "$PLAYBOOK_DEST" ] && rm "$PLAYBOOK_DEST" [ -d "$PLAYBOOK_DEST" ] && [ ! -L "$PLAYBOOK_DEST" ] && rm -rf "$PLAYBOOK_DEST" - cp -R "$KIT_DIR/docs/impl-playbook" "$PLAYBOOK_DEST" - echo "[ok] Copied docs/impl-playbook into $PLAYBOOK_DEST (pinned, SPEC-066)" + mkdir -p "$PLAYBOOK_DEST" + for _pb in $KIT_IMPL_PLAYBOOKS; do + [ -f "$KIT_DIR/docs/impl-playbook/$_pb" ] || continue + cp "$KIT_DIR/docs/impl-playbook/$_pb" "$PLAYBOOK_DEST/$_pb" + done + unset _pb + echo "[ok] Copied referenced docs/impl-playbook files into $PLAYBOOK_DEST (pinned, SPEC-066)" fi # 1d-ter. Deploy root settings.json so lib/adopt.sh run from the installed path can wire @@ -1255,22 +1281,29 @@ echo " --no-mods to skip the Claude Code mods" echo "Hooks wired into settings.json:" printf '%s\n' $KIT_ENABLED_HOOK_NAMES | sort -u | while read -r h; do [ -n "$h" ] && echo " [hook] $h"; done echo "Hooks directory (all shipped, not all wired): $KIT_DIR/hooks/" -ls -1 "$KIT_DIR/hooks/"*.sh 2>/dev/null | while read f; do echo " [hook] $(basename "$f")"; done +for f in "$KIT_DIR/hooks/"*.sh; do + [ -e "$f" ] || continue + echo " [hook] $(basename "$f")" +done echo "Commands:" -ls -1 "$CLAUDE_DIR/commands/"*.md 2>/dev/null | while read f; do +for f in "$CLAUDE_DIR/commands/"*.md; do + [ -e "$f" ] || continue NAME=$(basename "$f" .md) echo " /$NAME" done echo "Skills:" -find -L "$CLAUDE_DIR/skills" -name "SKILL.md" 2>/dev/null | while read f; do - DIR=$(dirname "$f") - echo " $(basename "$DIR")" -done +if [ -d "$CLAUDE_DIR/skills" ]; then + while IFS= read -r f; do + DIR=$(dirname "$f") + echo " $(basename "$DIR")" + done < <(find -L "$CLAUDE_DIR/skills" -name "SKILL.md" 2>/dev/null || true) +fi echo "Agents:" -ls -1 "$CLAUDE_DIR/agents/"*.md 2>/dev/null | while read f; do +for f in "$CLAUDE_DIR/agents/"*.md; do + [ -e "$f" ] || continue NAME=$(basename "$f" .md) echo " $NAME" done diff --git a/tests/test-install-fixes.sh b/tests/test-install-fixes.sh new file mode 100755 index 00000000..2ff50364 --- /dev/null +++ b/tests/test-install-fixes.sh @@ -0,0 +1,327 @@ +#!/usr/bin/env bash +# test-install-fixes.sh -- regression tests for install.sh fixes and trims: +# 1. In-place --uninstall keeps checkout hooks and kit.toml, removing only outside artifacts. +# 2. --force-both after a plugin-compat install exits 0 (empty commands/ and agents/ under pipefail). +# 3. kit.toml keeps its original mode on fresh install and update (never drops to 0600 via mktemp). +# 4. Out-of-place installs skip lib/*/tests and lib/*/*/tests. +# 5. Out-of-place installs copy only impl-playbooks referenced by agents, commands, hooks, or lib. +set -euo pipefail + +KIT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd -P)" +PASS=0 +FAIL=0 + +ok() { PASS=$((PASS + 1)); printf ' PASS %s\n' "$1"; } +bad() { FAIL=$((FAIL + 1)); printf ' FAIL %s\n' "$1"; } + +file_mode() { + stat -c '%a' "$1" 2>/dev/null || stat -f '%Lp' "$1" 2>/dev/null +} + +SB="$(mktemp -d "${TMPDIR:-/tmp}/kit-install-fixes.XXXXXX")" || exit 1 +trap 'rm -rf "$SB"' EXIT + +# Helper: build a self-contained minimal checkout fixture under $1. +make_checkout_fixture() { + local dir="$1" + mkdir -p "$dir/hooks" "$dir/lib/config" "$dir/lib/telemetry" "$dir/bin" \ + "$dir/docs/impl-playbook" "$dir/commands" "$dir/agents" \ + "$dir/.agents/skills/demo" "$dir/output-styles" \ + "$dir/lib/demo/tests" "$dir/lib/demo/sub/tests" + cp "$KIT_DIR/install.sh" "$dir/install.sh" + cp "$KIT_DIR/kit.toml" "$dir/kit.toml" + cp "$KIT_DIR/settings.json" "$dir/settings.json" + cp "$KIT_DIR/AGENTS.md" "$dir/AGENTS.md" + cp "$KIT_DIR/WORKFLOW.md" "$dir/WORKFLOW.md" + cp "$KIT_DIR/docs/WORKFLOW.md" "$dir/docs/WORKFLOW.md" + cp "$KIT_DIR/VERSION" "$dir/VERSION" + cp "$KIT_DIR/docs/impl-playbook/security.md" "$dir/docs/impl-playbook/security.md" + cp "$KIT_DIR/lib/config/modules.sh" "$KIT_DIR/lib/config/modules.tsv" "$KIT_DIR/lib/config/kit-config.sh" "$dir/lib/config/" + cp "$KIT_DIR/lib/onboard-detect.sh" "$dir/lib/onboard-detect.sh" + cp "$KIT_DIR/lib/telemetry/kit-migrate.sh" "$dir/lib/telemetry/kit-migrate.sh" + cp "$KIT_DIR/hooks/safety-gate.sh" "$dir/hooks/safety-gate.sh" + printf '# helper py\n' > "$dir/hooks/helper.py" + printf '{"ok":true}\n' > "$dir/hooks/rules.json" + printf '#!/usr/bin/env bash\n' > "$dir/bin/config" + chmod +x "$dir/bin/config" + printf 'command\n' > "$dir/commands/demo.md" + printf 'agent\n' > "$dir/agents/demo.md" + printf 'skill\n' > "$dir/.agents/skills/demo/SKILL.md" + printf 'style\n' > "$dir/output-styles/demo.md" + printf 'keep\n' > "$dir/lib/demo/keep.sh" + printf 'deep\n' > "$dir/lib/demo/sub/deep.sh" + printf 'unit test\n' > "$dir/lib/demo/tests/test-demo.sh" + printf 'sub test\n' > "$dir/lib/demo/sub/tests/test-sub.sh" +} + +# Helper: run install.sh inside an isolated sandbox home ($1 = sandbox root, $2 = kit dir, shift 2 -> args). +run_in_sandbox() { + local sroot="$1" kdir="$2" + shift 2 + mkdir -p "$sroot/home" "$sroot/xdg" "$sroot/claude" + : > "$sroot/gitconfig" + ( + cd "$sroot/home" + HOME="$sroot/home" \ + CLAUDE_DIR="$sroot/claude" \ + XDG_CONFIG_HOME="$sroot/xdg" \ + GIT_CONFIG_GLOBAL="$sroot/gitconfig" \ + KIT_CONFIG_OPERATOR="$sroot/no-op" \ + bash "$kdir/install.sh" "$@" + ) +} + +# ============================================================ +echo "== 1. In-place --uninstall keeps checkout hooks and kit.toml ==" +# ============================================================ +S1="$SB/case1-inplace" +mkdir -p "$S1/claude" +make_checkout_fixture "$S1/claude/dwarves-kit" +cp "$S1/claude/dwarves-kit/kit.toml" "$S1/kit.toml.orig" + +if run_in_sandbox "$S1" "$S1/claude/dwarves-kit" --no-mods >/dev/null 2>&1; then + ok "in-place install exits 0" +else + bad "in-place install exits 0" +fi + +if run_in_sandbox "$S1" "$S1/claude/dwarves-kit" --uninstall >/dev/null 2>&1; then + ok "in-place --uninstall exits 0" +else + bad "in-place --uninstall exits 0" +fi + +if [ -f "$S1/claude/dwarves-kit/hooks/safety-gate.sh" ] \ + && [ -f "$S1/claude/dwarves-kit/hooks/helper.py" ] \ + && [ -f "$S1/claude/dwarves-kit/hooks/rules.json" ]; then + ok "in-place uninstall keeps checkout hooks (.sh, .py, .json)" +else + bad "in-place uninstall keeps checkout hooks (.sh, .py, .json)" +fi + +if [ -f "$S1/claude/dwarves-kit/kit.toml" ] && cmp -s "$S1/kit.toml.orig" "$S1/claude/dwarves-kit/kit.toml"; then + ok "in-place uninstall keeps checkout kit.toml byte-intact" +else + bad "in-place uninstall keeps checkout kit.toml byte-intact" +fi + +if [ -f "$S1/claude/dwarves-kit/bin/config" ] \ + && [ -f "$S1/claude/dwarves-kit/lib/onboard-detect.sh" ] \ + && [ -f "$S1/claude/dwarves-kit/settings.json" ]; then + ok "in-place uninstall keeps checkout bin, lib, and settings.json" +else + bad "in-place uninstall keeps checkout bin, lib, and settings.json" +fi + +if [ ! -e "$S1/claude/commands/demo.md" ] \ + && [ ! -e "$S1/claude/agents/demo.md" ] \ + && [ ! -e "$S1/claude/skills/demo" ] \ + && [ ! -e "$S1/home/.agents/skills/demo" ] \ + && [ ! -e "$S1/claude/output-styles/demo.md" ]; then + ok "in-place uninstall removes outside commands, agents, skills, and output-styles" +else + bad "in-place uninstall removes outside commands, agents, skills, and output-styles" +fi + +if ! jq -e '[.hooks // {} | .. | strings | select(contains("dwarves-kit"))] | length > 0' "$S1/claude/settings.json" >/dev/null 2>&1; then + ok "in-place uninstall strips dwarves-kit hooks from settings.json" +else + bad "in-place uninstall strips dwarves-kit hooks from settings.json" +fi + +# Symlinked in-place checkout ($CLAUDE_DIR/dwarves-kit -> checkout) +S1B="$SB/case1b-symlink" +mkdir -p "$S1B/claude" +make_checkout_fixture "$S1B/checkout" +cp "$S1B/checkout/kit.toml" "$S1B/kit.toml.orig" +ln -s "$S1B/checkout" "$S1B/claude/dwarves-kit" + +run_in_sandbox "$S1B" "$S1B/checkout" --no-mods >/dev/null 2>&1 || true +if run_in_sandbox "$S1B" "$S1B/checkout" --uninstall >/dev/null 2>&1; then + ok "symlinked in-place --uninstall exits 0" +else + bad "symlinked in-place --uninstall exits 0" +fi + +if [ -f "$S1B/checkout/hooks/safety-gate.sh" ] \ + && [ -f "$S1B/checkout/hooks/helper.py" ] \ + && [ -f "$S1B/checkout/hooks/rules.json" ] \ + && [ -f "$S1B/checkout/kit.toml" ] \ + && cmp -s "$S1B/kit.toml.orig" "$S1B/checkout/kit.toml"; then + ok "symlinked in-place uninstall keeps checkout hooks and kit.toml intact" +else + bad "symlinked in-place uninstall keeps checkout hooks and kit.toml intact" +fi + +if [ ! -e "$S1B/claude/commands/demo.md" ] && [ ! -e "$S1B/claude/agents/demo.md" ]; then + ok "symlinked in-place uninstall removes outside command and agent" +else + bad "symlinked in-place uninstall removes outside command and agent" +fi + +# Positive control: out-of-place uninstall still deletes the installed copies +S1C="$SB/case1c-oop" +make_checkout_fixture "$S1C/checkout" +run_in_sandbox "$S1C" "$S1C/checkout" --no-mods >/dev/null 2>&1 || true +if run_in_sandbox "$S1C" "$S1C/checkout" --uninstall >/dev/null 2>&1; then + ok "out-of-place --uninstall exits 0" +else + bad "out-of-place --uninstall exits 0" +fi + +if [ ! -e "$S1C/claude/dwarves-kit/hooks/safety-gate.sh" ] && [ ! -e "$S1C/claude/dwarves-kit/kit.toml" ]; then + ok "out-of-place uninstall removes installed hooks and kit.toml copies" +else + bad "out-of-place uninstall removes installed hooks and kit.toml copies" +fi + +if [ -f "$S1C/checkout/hooks/safety-gate.sh" ] && [ -f "$S1C/checkout/kit.toml" ]; then + ok "out-of-place uninstall leaves source checkout intact" +else + bad "out-of-place uninstall leaves source checkout intact" +fi + +# ============================================================ +echo "== 2. --force-both after plugin-compat install exits 0 ==" +# ============================================================ +S2="$SB/case2-force-both" +mkdir -p "$S2/claude/plugins/cache/dwarves-marketplace/kit/1.0.0/lib" + +if run_in_sandbox "$S2" "$KIT_DIR" --no-mods >/dev/null 2>&1; then + ok "plugin-compat install exits 0" +else + bad "plugin-compat install exits 0" +fi + +rc2=0 +out2="$(run_in_sandbox "$S2" "$KIT_DIR" --no-mods --force-both 2>&1)" || rc2=$? +if [ "$rc2" -eq 0 ]; then + ok "--force-both after plugin-compat install exits 0" +else + bad "--force-both after plugin-compat install exits 0 (rc=$rc2)" +fi + +if grep -qF '=== Done ===' <<<"$out2"; then + ok "--force-both after compat reaches === Done ===" +else + bad "--force-both after compat reaches === Done ===" +fi + +if jq -e '.hooks.PreToolUse | length > 0' "$S2/claude/settings.json" >/dev/null 2>&1; then + ok "--force-both after compat wires hooks into settings.json" +else + bad "--force-both after compat wires hooks into settings.json" +fi + +if [ -f "$S2/claude/dwarves-kit/kit.toml" ] && [ ! -L "$S2/claude/dwarves-kit/kit.toml" ]; then + ok "--force-both after compat replaces kit.toml symlink with real file" +else + bad "--force-both after compat replaces kit.toml symlink with real file" +fi + +if [ -z "$(ls -A "$S2/claude/commands" 2>/dev/null)" ] && [ -z "$(ls -A "$S2/claude/agents" 2>/dev/null)" ]; then + ok "--force-both after compat keeps bare commands/ and agents/ empty" +else + bad "--force-both after compat keeps bare commands/ and agents/ empty" +fi + +# Also check KIT_FORCE_FULL=1 exits 0 directly with plugin cached +S2B="$SB/case2b-force-full" +mkdir -p "$S2B/claude/plugins/cache/dwarves-marketplace/kit/1.0.0/lib" "$S2B/home" "$S2B/xdg" +: > "$S2B/gitconfig" +rc2b=0 +( + cd "$S2B/home" + HOME="$S2B/home" CLAUDE_DIR="$S2B/claude" XDG_CONFIG_HOME="$S2B/xdg" \ + GIT_CONFIG_GLOBAL="$S2B/gitconfig" KIT_CONFIG_OPERATOR="$S2B/no-op" \ + KIT_FORCE_FULL=1 bash "$KIT_DIR/install.sh" --no-mods >/dev/null 2>&1 +) || rc2b=$? +if [ "$rc2b" -eq 0 ]; then + ok "KIT_FORCE_FULL=1 with plugin cached exits 0" +else + bad "KIT_FORCE_FULL=1 with plugin cached exits 0 (rc=$rc2b)" +fi + +# ============================================================ +echo "== 3. kit.toml keeps its original mode on install and update ==" +# ============================================================ +S3="$SB/case3-mode" +SRC_MODE="$(file_mode "$KIT_DIR/kit.toml")" +run_in_sandbox "$S3" "$KIT_DIR" --no-mods >/dev/null 2>&1 || true +M3_FRESH="$(file_mode "$S3/claude/dwarves-kit/kit.toml")" +if [ "$M3_FRESH" = "$SRC_MODE" ]; then + ok "fresh install kit.toml keeps source mode ($SRC_MODE)" +else + bad "fresh install kit.toml keeps source mode (want $SRC_MODE, got $M3_FRESH)" +fi + +chmod 640 "$S3/claude/dwarves-kit/kit.toml" +run_in_sandbox "$S3" "$KIT_DIR" --no-mods --with board,stats >/dev/null 2>&1 || true +M3_640="$(file_mode "$S3/claude/dwarves-kit/kit.toml")" +if [ "$M3_640" = "640" ]; then + ok "update preserves custom kit.toml mode 640" +else + bad "update preserves custom kit.toml mode 640 (got $M3_640)" +fi + +chmod 644 "$S3/claude/dwarves-kit/kit.toml" +run_in_sandbox "$S3" "$KIT_DIR" --no-mods --with board >/dev/null 2>&1 || true +M3_644="$(file_mode "$S3/claude/dwarves-kit/kit.toml")" +if [ "$M3_644" = "644" ]; then + ok "update preserves kit.toml mode 644" +else + bad "update preserves kit.toml mode 644 (got $M3_644)" +fi + +# ============================================================ +echo "== 4. Out-of-place installs skip lib/*/tests and lib/*/*/tests ==" +# ============================================================ +S4="$SB/case4-lib-tests" +make_checkout_fixture "$S4/checkout" +run_in_sandbox "$S4" "$S4/checkout" --no-mods >/dev/null 2>&1 || true +if [ -f "$S4/claude/dwarves-kit/lib/demo/keep.sh" ] && [ -f "$S4/claude/dwarves-kit/lib/demo/sub/deep.sh" ]; then + ok "fixture install copies tracked lib files" +else + bad "fixture install copies tracked lib files" +fi + +if [ ! -e "$S4/claude/dwarves-kit/lib/demo/tests" ] && [ ! -e "$S4/claude/dwarves-kit/lib/demo/sub/tests" ]; then + ok "fixture install skips lib/*/tests and lib/*/*/tests" +else + bad "fixture install skips lib/*/tests and lib/*/*/tests" +fi + +# Real checkout check (reuses S3 out-of-place install of real $KIT_DIR) +REAL_TEST_DIRS="$(find "$S3/claude/dwarves-kit/lib" -type d -name tests 2>/dev/null || true)" +if [ -z "$REAL_TEST_DIRS" ]; then + ok "real checkout out-of-place install copies zero lib/**/tests dirs" +else + bad "real checkout out-of-place install copies zero lib/**/tests dirs (found: $REAL_TEST_DIRS)" +fi + +# ============================================================ +echo "== 5. Out-of-place installs copy only referenced impl-playbooks ==" +# ============================================================ +EXPECTED_PB="$(grep -rohE 'docs/impl-playbook/[A-Za-z0-9._-]+\.md' \ + "$KIT_DIR/agents" "$KIT_DIR/commands" "$KIT_DIR/hooks" "$KIT_DIR/lib" 2>/dev/null \ + | sed 's|docs/impl-playbook/||' | sort -u)" +INSTALLED_PB="$(find "$S3/claude/dwarves-kit/docs/impl-playbook" -maxdepth 1 -type f -exec basename {} \; 2>/dev/null | sort)" +if [ "$INSTALLED_PB" = "$EXPECTED_PB" ]; then + ok "out-of-place install copies exactly the referenced impl-playbooks" +else + bad "out-of-place install copies exactly the referenced impl-playbooks" + printf ' expected: %s\n' "$(printf '%s' "$EXPECTED_PB" | tr '\n' ' ')" + printf ' got: %s\n' "$(printf '%s' "$INSTALLED_PB" | tr '\n' ' ')" +fi + +printf 'stale\n' > "$S3/claude/dwarves-kit/docs/impl-playbook/rust.md" +run_in_sandbox "$S3" "$KIT_DIR" --no-mods >/dev/null 2>&1 || true +if [ ! -e "$S3/claude/dwarves-kit/docs/impl-playbook/rust.md" ]; then + ok "re-install removes stale unreferenced impl-playbook files" +else + bad "re-install removes stale unreferenced impl-playbook files" +fi + +echo "---" +echo "PASS=$PASS FAIL=$FAIL" +[ "$FAIL" -eq 0 ] From f7a2a02ee91790227e7300395acd76a6c73fc903 Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 2 Dec 2026 15:08:27 +0700 Subject: [PATCH 2/4] docs(verification): record proof for installer fixes and trims --- docs/verification/l312-install-fixes.md | 75 +++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 docs/verification/l312-install-fixes.md diff --git a/docs/verification/l312-install-fixes.md b/docs/verification/l312-install-fixes.md new file mode 100644 index 00000000..8b08c805 --- /dev/null +++ b/docs/verification/l312-install-fixes.md @@ -0,0 +1,75 @@ +# Verification: Installer bugs and out-of-place copy trims + +## Scope + +Three installer bugs fixed and two out-of-place copy trims applied in `install.sh`, with sandboxed regression coverage in `tests/test-install-fixes.sh`: + +1. In-place `--uninstall` (direct clone or symlinked `$CLAUDE_DIR/dwarves-kit -> checkout`) keeps checkout files (`hooks/`, `kit.toml`, `bin/`, `lib/`, `settings.json`, `docs/`) and removes only artifacts created outside the checkout. +2. `--force-both` (and `KIT_FORCE_FULL=1`) after a plugin-compat install exits 0 by replacing `ls -1 ... | while read` summary pipelines with glob loops that tolerate empty `commands/` and `agents/` directories under `set -euo pipefail`. +3. `kit_render_install_toml` preserves the destination `kit.toml` mode on update (or the source `kit.toml` mode on fresh install, fallback `0644`) instead of letting `mktemp` drop it to `0600`. +4. Out-of-place `lib/` tar copy excludes `lib/*/tests` and `lib/*/*/tests` (grep over `bin/`, `hooks/`, `lib/`, `agents/`, `commands/`, `.agents/` confirmed zero installed runtime tools read module test directories; only checkout-only dev scripts `bin/test-affected`, `lib/registry/feature-registry.sh`, and `hooks/ship-gate.sh` inspect them in a kit checkout). +5. Out-of-place `docs/impl-playbook/` copy installs only the 9 files referenced by `agents/`, `commands/`, `hooks/`, or `lib/`: + - Kept (9): `cloudflare.md` (`agents/infra-reviewer.md:29`), `coding-hygiene.md` (`agents/code-reviewer.md:24,99`), `exploratory-testing.md` (`commands/test-plan.md:17`), `financial-data-handling.md` (`agents/security-reviewer.md:70,108`), `frontend-design-engineering.md` (`agents/frontend-reviewer.md:28`), `security.md` (`agents/security-reviewer.md:27,108`), `test-case-design.md` (`agents/test-writer.md:34,82`; `agents/code-reviewer.md:66,99`), `testing-strategy.md` (`agents/test-writer.md:33,82`; `agents/code-reviewer.md:65,99`), `threat-modeling.md` (`agents/security-reviewer.md:70,108`). + - Dropped (12, zero references in `agents/`, `commands/`, `hooks/`, `lib/`): `README.md`, `architecture-decision.md`, `bash.md`, `ci-cd-pipeline.md`, `go.md`, `logging-observability.md`, `notification-design.md`, `python.md`, `red-team-engagement.md`, `requirements-gathering.md`, `rust.md`, `typescript.md`. + +## Verification runs + +### Regression suite (all 5 items) + +Command: bash tests/test-install-fixes.sh +Exit: 0 +Output: + == 4. Out-of-place installs skip lib/*/tests and lib/*/*/tests == + PASS fixture install copies tracked lib files + PASS fixture install skips lib/*/tests and lib/*/*/tests + PASS real checkout out-of-place install copies zero lib/**/tests dirs + == 5. Out-of-place installs copy only referenced impl-playbooks == + PASS out-of-place install copies exactly the referenced impl-playbooks + PASS re-install removes stale unreferenced impl-playbook files + --- + PASS=28 FAIL=0 + +### Existing installer and adopt suites + +Command: bash tests/test-adopt.sh && bash tests/test-install-modules.sh && bash tests/test-install-compat.sh && bash tests/test-clean-room.sh +Exit: 0 +Output: + tests/test-adopt.sh: PASS=88 FAIL=0 + tests/test-install-modules.sh: 67 passed, 0 failed + tests/test-install-compat.sh: PASS: install compat + tests/test-clean-room.sh: clean-room: 75 passed, 0 failed + +### Shellcheck lint + +Command: shellcheck --norc -S warning install.sh tests/test-install-fixes.sh +Exit: 0 +Output: + (no warnings or errors) + +### Host sandbox integrity + +Before and after all test runs, real `~/.gitconfig` (`2c3e7653...57d4f21`) and `~/.claude/settings.json` (`203cd3b9...7a6a2adf`) SHA-256 digests were unchanged. + +## Negative control + +Reverted `install.sh` to `origin/master:install.sh` via `bash lib/gate/negctl.sh . "bash tests/test-install-fixes.sh" "git show origin/master:install.sh > install.sh"` and also verified each of the 5 fixes/trims with an individual planted fault. + +Command: bash lib/gate/negctl.sh . "bash tests/test-install-fixes.sh" "git show origin/master:install.sh > install.sh" +Exit: 1 (under mutation against origin/master:install.sh; 0 before mutation and 0 after restore) +Output: + == 5. Out-of-place installs copy only referenced impl-playbooks == + FAIL out-of-place install copies exactly the referenced impl-playbooks + FAIL re-install removes stale unreferenced impl-playbook files + --- + PASS=15 FAIL=13 + Individual planted faults: + Bug1-inplace-uninstall: rc=1 (PASS=25 FAIL=3) + Bug2-force-both-pipefail: rc=1 (PASS=25 FAIL=3) + Bug3-kit-toml-mode: rc=1 (PASS=25 FAIL=3) + Trim4-lib-tests: rc=1 (PASS=26 FAIL=2) + Trim5-impl-playbooks: rc=1 (PASS=26 FAIL=2) +Verdict: RED + +## Rollback + +Revert the commit on `install.sh`, `tests/test-install-fixes.sh`, and `docs/reference/FEATURES.md` with `git revert `, then re-run `bash install.sh` to restore the previous installer behavior and full `lib/` + `docs/impl-playbook/` copy set. From ac2b72e00eb2bdc37158e941d41c8a50b52a9cf9 Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 2 Dec 2026 16:26:40 +0700 Subject: [PATCH 3/4] fix(install): inode-check in-place uninstall and ship linked playbook Resolve review blockers B1 and B2: - Compare KIT_DIR and CLAUDE_DIR/dwarves-kit by inode (-ef) in --uninstall so case-variant paths on macOS APFS stay protected. - Add red-team-engagement.md (linked from threat-modeling.md) to KIT_IMPL_PLAYBOOKS and widen tests/test-install-fixes.sh to follow playbook-to-playbook links transitively. - Add a case-variant in-place uninstall regression test (skipped on case-sensitive filesystems) and refresh docs/reference/FEATURES.md. --- docs/reference/FEATURES.md | 2 +- install.sh | 12 ++++----- tests/test-install-fixes.sh | 53 +++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 7 deletions(-) diff --git a/docs/reference/FEATURES.md b/docs/reference/FEATURES.md index 7b7195a4..b5da919b 100644 --- a/docs/reference/FEATURES.md +++ b/docs/reference/FEATURES.md @@ -38,7 +38,7 @@ GENERATED , do not hand-edit. Regenerate: `bash lib/registry/feature-registry.sh | `/kit:retro` | `[H/I]` | Run a retrospective after shipping. Captures what worked, what didn't, and action items for the next cycle. Outputs to docs/retro/RETRO.md. | SPEC-002, SPEC-003, SPEC-006 +48 | smoke.sh, test-command-emit-sweep.sh, test-gate-vocab-recording.sh +10 | | `/kit:review-team` | `[H/I]` | Parallel code review with 3 specialist lenses plus the kit-default kit:advisor extra lens. Dispatches the security, architecture, and test-… | SPEC-002, SPEC-003, SPEC-007 +50 | test-advisor.sh, test-config-registry.sh, test-every-step-review.sh +10 | | `/kit:review` | `[H/I]` | Paranoid code review. Security, architecture, regressions, missing tests, edge cases. Produces actionable TODOS. | SPEC-001, SPEC-002, SPEC-003 +155 | smoke.sh, test-adopt.sh, test-advisor.sh +90 | -| `/kit:ship` | `[H/I]` | Ship: review gate, tests, version bump, changelog, conventional commit, docs update, PR. Complete pipeline from done to merged. | SPEC-001, SPEC-002, SPEC-003 +111 | test-active-spec-pick.sh, test-adopt.sh, test-board-mirror.sh +64 | +| `/kit:ship` | `[H/I]` | Ship: review gate, tests, version bump, changelog, conventional commit, docs update, PR. Complete pipeline from done to merged. | SPEC-001, SPEC-002, SPEC-003 +111 | test-active-spec-pick.sh, test-adopt.sh, test-board-mirror.sh +65 | | `/kit:spec-validate` | `[H/I]` | Adversarial review of a spec before implementation. 7 specialist lenses attack the spec from different angles (6 advisory, 1 blocking on th… | SPEC-002, SPEC-003, SPEC-004 +70 | test-command-emit-sweep.sh, test-design-record.sh, test-every-step-review.sh +10 | | `/kit:spec` | `[H/I]` | Generate a development spec from a feature idea or decision brief. Creates docs/specs/ with structured requirements. | SPEC-001, SPEC-002, SPEC-003 +241 | test-active-spec-pick.sh, test-audit-verdict-grammar.sh, test-bin-forwarders.sh +109 | | `/kit:start` | `[H/I]` | Detect project state and suggest the right next command. The entry point for any session. | SPEC-002, SPEC-003, SPEC-004 +94 | test-anomalies-advisor.sh, test-audit-cadence.sh, test-board-add.sh +95 | diff --git a/install.sh b/install.sh index 6510140b..3ccf1daf 100755 --- a/install.sh +++ b/install.sh @@ -41,9 +41,10 @@ KIT_MOD_BASE="integrations/claude-code" KIT_MODS="board-pane secrets-veil memory-lens loop-detective context-inspector" KIT_MOD_PARTS=".claude-plugin hooks src types LICENSE VENDORED.md" -# Implementation playbooks referenced by agents/, commands/, hooks/, or lib/. +# Implementation playbooks referenced by agents/, commands/, hooks/, or lib/, +# plus sibling playbooks they point to (threat-modeling.md -> red-team-engagement.md). # Out-of-place installs copy only these files instead of unreferenced playbooks. -KIT_IMPL_PLAYBOOKS="cloudflare.md coding-hygiene.md exploratory-testing.md financial-data-handling.md frontend-design-engineering.md security.md test-case-design.md testing-strategy.md threat-modeling.md" +KIT_IMPL_PLAYBOOKS="cloudflare.md coding-hygiene.md exploratory-testing.md financial-data-handling.md frontend-design-engineering.md red-team-engagement.md security.md test-case-design.md testing-strategy.md threat-modeling.md" # kit_drop_mod_dirs ... -- remove each path from env.CLAUDE_CODE_PLUGIN_DIRS in settings.json # (every other entry stays) and drop the key when it ends empty. @@ -164,12 +165,11 @@ if [ "${1:-}" = "--uninstall" ]; then fi done - # Detect an in-place install (checkout IS $CLAUDE_DIR/dwarves-kit, directly or via symlink). + # Detect an in-place install (checkout IS $CLAUDE_DIR/dwarves-kit, directly, via symlink, + # or through a case-variant path on case-insensitive filesystems). Compare by inode (-ef). # Uninstall only removes what install created outside the checkout; checkout files stay intact. - UNINSTALL_KIT_REAL="$(cd "$KIT_DIR" && pwd -P)" - UNINSTALL_DEST_REAL="$(cd "$CLAUDE_DIR/dwarves-kit" 2>/dev/null && pwd -P || true)" UNINSTALL_IN_PLACE=0 - if [ -n "$UNINSTALL_DEST_REAL" ] && [ "$UNINSTALL_KIT_REAL" = "$UNINSTALL_DEST_REAL" ]; then + if [ -e "$CLAUDE_DIR/dwarves-kit" ] && [ "$KIT_DIR" -ef "$CLAUDE_DIR/dwarves-kit" ]; then UNINSTALL_IN_PLACE=1 fi diff --git a/tests/test-install-fixes.sh b/tests/test-install-fixes.sh index 2ff50364..1f303ed7 100755 --- a/tests/test-install-fixes.sh +++ b/tests/test-install-fixes.sh @@ -159,6 +159,40 @@ else bad "symlinked in-place uninstall removes outside command and agent" fi +# Case-variant in-place path on case-insensitive filesystems (e.g. macOS APFS) +mkdir -p "$SB/case-probe" +if [ -d "$SB/CASE-PROBE" ] && [ "$SB/case-probe" -ef "$SB/CASE-PROBE" ]; then + S1D="$SB/case1d-case-variant" + mkdir -p "$S1D/claude" + make_checkout_fixture "$S1D/claude/dwarves-kit" + cp "$S1D/claude/dwarves-kit/kit.toml" "$S1D/kit.toml.orig" + + run_in_sandbox "$S1D" "$S1D/claude/dwarves-kit" --no-mods >/dev/null 2>&1 || true + if run_in_sandbox "$S1D" "$S1D/CLAUDE/dwarves-kit" --uninstall >/dev/null 2>&1; then + ok "case-variant in-place --uninstall exits 0" + else + bad "case-variant in-place --uninstall exits 0" + fi + + if [ -f "$S1D/claude/dwarves-kit/hooks/safety-gate.sh" ] \ + && [ -f "$S1D/claude/dwarves-kit/hooks/helper.py" ] \ + && [ -f "$S1D/claude/dwarves-kit/hooks/rules.json" ] \ + && [ -f "$S1D/claude/dwarves-kit/kit.toml" ] \ + && cmp -s "$S1D/kit.toml.orig" "$S1D/claude/dwarves-kit/kit.toml"; then + ok "case-variant in-place uninstall keeps checkout hooks and kit.toml intact" + else + bad "case-variant in-place uninstall keeps checkout hooks and kit.toml intact" + fi + + if [ ! -e "$S1D/claude/commands/demo.md" ] && [ ! -e "$S1D/claude/agents/demo.md" ]; then + ok "case-variant in-place uninstall removes outside command and agent" + else + bad "case-variant in-place uninstall removes outside command and agent" + fi +else + printf ' SKIP case-variant in-place uninstall (case-sensitive filesystem)\n' +fi + # Positive control: out-of-place uninstall still deletes the installed copies S1C="$SB/case1c-oop" make_checkout_fixture "$S1C/checkout" @@ -305,6 +339,25 @@ echo "== 5. Out-of-place installs copy only referenced impl-playbooks ==" EXPECTED_PB="$(grep -rohE 'docs/impl-playbook/[A-Za-z0-9._-]+\.md' \ "$KIT_DIR/agents" "$KIT_DIR/commands" "$KIT_DIR/hooks" "$KIT_DIR/lib" 2>/dev/null \ | sed 's|docs/impl-playbook/||' | sort -u)" +# Follow playbook-to-playbook links transitively: any kept playbook that names +# a sibling playbook requires that sibling to ship too (bounded fixpoint). +_pb_pass=0 +while [ "$_pb_pass" -lt 10 ]; do + _pb_pass=$((_pb_pass + 1)) + _pb_next="$( + { + printf '%s\n' "$EXPECTED_PB" + while IFS= read -r _pbf; do + [ -n "$_pbf" ] && [ -f "$KIT_DIR/docs/impl-playbook/$_pbf" ] || continue + grep -ohE '[A-Za-z0-9._-]+\.md' "$KIT_DIR/docs/impl-playbook/$_pbf" 2>/dev/null || true + done <<<"$EXPECTED_PB" + } | while IFS= read -r _pbn; do + [ -n "$_pbn" ] && [ -f "$KIT_DIR/docs/impl-playbook/$_pbn" ] && printf '%s\n' "$_pbn" + done | sort -u + )" + [ "$_pb_next" = "$EXPECTED_PB" ] && break + EXPECTED_PB="$_pb_next" +done INSTALLED_PB="$(find "$S3/claude/dwarves-kit/docs/impl-playbook" -maxdepth 1 -type f -exec basename {} \; 2>/dev/null | sort)" if [ "$INSTALLED_PB" = "$EXPECTED_PB" ]; then ok "out-of-place install copies exactly the referenced impl-playbooks" From ea200d72d7122b3f4eb0967faf8bd002724c5662 Mon Sep 17 00:00:00 2001 From: Han Ngo Date: Wed, 2 Dec 2026 16:29:23 +0700 Subject: [PATCH 4/4] docs(verification): update proof for review blockers B1 and B2 --- docs/verification/l312-install-fixes.md | 59 ++++++++++++++----------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/docs/verification/l312-install-fixes.md b/docs/verification/l312-install-fixes.md index 8b08c805..1d81723d 100644 --- a/docs/verification/l312-install-fixes.md +++ b/docs/verification/l312-install-fixes.md @@ -2,42 +2,43 @@ ## Scope -Three installer bugs fixed and two out-of-place copy trims applied in `install.sh`, with sandboxed regression coverage in `tests/test-install-fixes.sh`: +Three installer bugs fixed and two out-of-place copy trims applied in `install.sh`, with sandboxed regression coverage in `tests/test-install-fixes.sh` (including review round 1 blockers B1 and B2): -1. In-place `--uninstall` (direct clone or symlinked `$CLAUDE_DIR/dwarves-kit -> checkout`) keeps checkout files (`hooks/`, `kit.toml`, `bin/`, `lib/`, `settings.json`, `docs/`) and removes only artifacts created outside the checkout. +1. In-place `--uninstall` (direct clone, symlinked `$CLAUDE_DIR/dwarves-kit -> checkout`, or case-variant path on case-insensitive filesystems such as macOS APFS) compares `$KIT_DIR` and `$CLAUDE_DIR/dwarves-kit` by inode (`-ef`), keeping checkout files (`hooks/`, `kit.toml`, `bin/`, `lib/`, `settings.json`, `docs/`) and removing only artifacts created outside the checkout. 2. `--force-both` (and `KIT_FORCE_FULL=1`) after a plugin-compat install exits 0 by replacing `ls -1 ... | while read` summary pipelines with glob loops that tolerate empty `commands/` and `agents/` directories under `set -euo pipefail`. 3. `kit_render_install_toml` preserves the destination `kit.toml` mode on update (or the source `kit.toml` mode on fresh install, fallback `0644`) instead of letting `mktemp` drop it to `0600`. 4. Out-of-place `lib/` tar copy excludes `lib/*/tests` and `lib/*/*/tests` (grep over `bin/`, `hooks/`, `lib/`, `agents/`, `commands/`, `.agents/` confirmed zero installed runtime tools read module test directories; only checkout-only dev scripts `bin/test-affected`, `lib/registry/feature-registry.sh`, and `hooks/ship-gate.sh` inspect them in a kit checkout). -5. Out-of-place `docs/impl-playbook/` copy installs only the 9 files referenced by `agents/`, `commands/`, `hooks/`, or `lib/`: - - Kept (9): `cloudflare.md` (`agents/infra-reviewer.md:29`), `coding-hygiene.md` (`agents/code-reviewer.md:24,99`), `exploratory-testing.md` (`commands/test-plan.md:17`), `financial-data-handling.md` (`agents/security-reviewer.md:70,108`), `frontend-design-engineering.md` (`agents/frontend-reviewer.md:28`), `security.md` (`agents/security-reviewer.md:27,108`), `test-case-design.md` (`agents/test-writer.md:34,82`; `agents/code-reviewer.md:66,99`), `testing-strategy.md` (`agents/test-writer.md:33,82`; `agents/code-reviewer.md:65,99`), `threat-modeling.md` (`agents/security-reviewer.md:70,108`). - - Dropped (12, zero references in `agents/`, `commands/`, `hooks/`, `lib/`): `README.md`, `architecture-decision.md`, `bash.md`, `ci-cd-pipeline.md`, `go.md`, `logging-observability.md`, `notification-design.md`, `python.md`, `red-team-engagement.md`, `requirements-gathering.md`, `rust.md`, `typescript.md`. +5. Out-of-place `docs/impl-playbook/` copy installs only the 10 files referenced by `agents/`, `commands/`, `hooks/`, or `lib/`, plus sibling playbooks they point to: + - Kept (10): `cloudflare.md` (`agents/infra-reviewer.md:29`), `coding-hygiene.md` (`agents/code-reviewer.md:24,99`), `exploratory-testing.md` (`commands/test-plan.md:17`), `financial-data-handling.md` (`agents/security-reviewer.md:70,108`), `frontend-design-engineering.md` (`agents/frontend-reviewer.md:28`), `red-team-engagement.md` (`docs/impl-playbook/threat-modeling.md:27`), `security.md` (`agents/security-reviewer.md:27,108`), `test-case-design.md` (`agents/test-writer.md:34,82`; `agents/code-reviewer.md:66,99`), `testing-strategy.md` (`agents/test-writer.md:33,82`; `agents/code-reviewer.md:65,99`), `threat-modeling.md` (`agents/security-reviewer.md:70,108`). + - Dropped (11, zero direct or transitive references from `agents/`, `commands/`, `hooks/`, `lib/`): `README.md`, `architecture-decision.md`, `bash.md`, `ci-cd-pipeline.md`, `go.md`, `logging-observability.md`, `notification-design.md`, `python.md`, `requirements-gathering.md`, `rust.md`, `typescript.md`. ## Verification runs -### Regression suite (all 5 items) +### Regression suite on `/bin/bash` (3.2.57) and bash 5 (5.3.20) -Command: bash tests/test-install-fixes.sh +Command: /bin/bash tests/test-install-fixes.sh && bash tests/test-install-fixes.sh Exit: 0 Output: - == 4. Out-of-place installs skip lib/*/tests and lib/*/*/tests == - PASS fixture install copies tracked lib files - PASS fixture install skips lib/*/tests and lib/*/*/tests - PASS real checkout out-of-place install copies zero lib/**/tests dirs - == 5. Out-of-place installs copy only referenced impl-playbooks == + /bin/bash 3.2.57: + PASS case-variant in-place --uninstall exits 0 + PASS case-variant in-place uninstall keeps checkout hooks and kit.toml intact PASS out-of-place install copies exactly the referenced impl-playbooks PASS re-install removes stale unreferenced impl-playbook files - --- - PASS=28 FAIL=0 + PASS=31 FAIL=0 + bash 5.3.20: + PASS case-variant in-place --uninstall exits 0 + PASS case-variant in-place uninstall keeps checkout hooks and kit.toml intact + PASS out-of-place install copies exactly the referenced impl-playbooks + PASS re-install removes stale unreferenced impl-playbook files + PASS=31 FAIL=0 -### Existing installer and adopt suites +### Suites selected by `tests/run-all.sh --changed --list` (40 suites) -Command: bash tests/test-adopt.sh && bash tests/test-install-modules.sh && bash tests/test-install-compat.sh && bash tests/test-clean-room.sh -Exit: 0 +Command: bash tests/run-all.sh --changed --list (executed per suite on bash 5.3.20 and /bin/bash 3.2.57) +Exit: 0 (for all 39 unlocked suites on bash 5.3.20) Output: - tests/test-adopt.sh: PASS=88 FAIL=0 - tests/test-install-modules.sh: 67 passed, 0 failed - tests/test-install-compat.sh: PASS: install compat - tests/test-clean-room.sh: clean-room: 75 passed, 0 failed + bash 5.3.20: 39/40 passed (test-adopt 88/0, test-install-modules 67/0, test-install-compat PASS, test-clean-room 75/0, test-install-fixes 31/0, test-meta-docs-registry 123/123, test-hooks 843/843, plus all other 32 unlocked suites). 1/40 (tests/test-wrap-land.sh, unrelated to install.sh) timed out waiting on the host test lock held by a sibling worktree. + /bin/bash 3.2.57: 33/40 passed (all installer, adopt, clean-room, and meta-docs-registry suites passed: test-install-fixes 31/0, test-install-modules, test-install-compat, test-install-lib-copy, test-install-self-symlink, test-install-mods, test-install-contract, test-install-plugin-detect, test-adopt, test-clean-room, test-meta-docs-registry 123/123). 7/40 failed for pre-existing reasons outside install.sh (test-board-registry-env, test-board-states, test-install-clis board promote, test-hooks 837/843, test-wrap-merge require bash 4+; test-boundary-lint hit pre-existing lib/mega/mega-review.py; test-wrap-land waited on the sibling host test lock). ### Shellcheck lint @@ -52,16 +53,20 @@ Before and after all test runs, real `~/.gitconfig` (`2c3e7653...57d4f21`) and ` ## Negative control -Reverted `install.sh` to `origin/master:install.sh` via `bash lib/gate/negctl.sh . "bash tests/test-install-fixes.sh" "git show origin/master:install.sh > install.sh"` and also verified each of the 5 fixes/trims with an individual planted fault. +Ran `lib/gate/negctl.sh` against both the pre-round-1 commit (`f7a2a02e:install.sh`, proving B1 and B2 fail red) and `origin/master:install.sh` (proving all five items fail red), plus five individual planted faults. -Command: bash lib/gate/negctl.sh . "bash tests/test-install-fixes.sh" "git show origin/master:install.sh > install.sh" -Exit: 1 (under mutation against origin/master:install.sh; 0 before mutation and 0 after restore) +Command: bash lib/gate/negctl.sh . "bash tests/test-install-fixes.sh" "git show f7a2a02e:install.sh > install.sh" +Exit: 1 (under mutation against f7a2a02e:install.sh; 0 before mutation and 0 after restore) Output: + == 1. In-place --uninstall keeps checkout hooks and kit.toml == + FAIL case-variant in-place uninstall keeps checkout hooks and kit.toml intact == 5. Out-of-place installs copy only referenced impl-playbooks == FAIL out-of-place install copies exactly the referenced impl-playbooks - FAIL re-install removes stale unreferenced impl-playbook files + expected: ... red-team-engagement.md ... + got: (9 files without red-team-engagement.md) --- - PASS=15 FAIL=13 + PASS=29 FAIL=2 + Against origin/master:install.sh: rc=1 (PASS=17 FAIL=14); restore rc=0 (PASS=31 FAIL=0). Individual planted faults: Bug1-inplace-uninstall: rc=1 (PASS=25 FAIL=3) Bug2-force-both-pipefail: rc=1 (PASS=25 FAIL=3) @@ -72,4 +77,4 @@ Verdict: RED ## Rollback -Revert the commit on `install.sh`, `tests/test-install-fixes.sh`, and `docs/reference/FEATURES.md` with `git revert `, then re-run `bash install.sh` to restore the previous installer behavior and full `lib/` + `docs/impl-playbook/` copy set. +Revert the commits on `install.sh`, `tests/test-install-fixes.sh`, and `docs/reference/FEATURES.md` with `git revert `, then re-run `bash install.sh` to restore the previous installer behavior and full `lib/` + `docs/impl-playbook/` copy set.