Ver código fonte

refactor(scripts): Make statusline install opt-in via flag

The statusline is now installed only when the user passes --statusline
(bash) or -Statusline (PowerShell); it is skipped by default with a hint.
When opted in, it is still added only if no statusLine key exists, so an
existing statusline is never clobbered. A shared claude-mods install no
longer changes anyone's prompt UI unless they ask for it.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AwW2Sen58WCSMTvWzfW7sv
0xDarkMatter 1 mês atrás
pai
commit
c50ac41e67
2 arquivos alterados com 41 adições e 14 exclusões
  1. 24 10
      scripts/install.ps1
  2. 17 4
      scripts/install.sh

+ 24 - 10
scripts/install.ps1

@@ -6,11 +6,20 @@
     Copies commands, skills, agents, and rules to the global Claude Code config.
     Handles cleanup of deprecated items and command-to-skill migrations.
 
+.PARAMETER Statusline
+    Opt in to installing the context-usage statusline. Off by default so a
+    shared install never changes the user's prompt UI without being asked.
+
 .NOTES
     Run from the claude-mods directory:
     .\scripts\install.ps1
+    .\scripts\install.ps1 -Statusline
 #>
 
+param(
+    [switch]$Statusline
+)
+
 $ErrorActionPreference = "Stop"
 
 Write-Host "================================================================" -ForegroundColor Cyan
@@ -241,19 +250,24 @@ foreach ($eventProperty in $desired.hooks.PSObject.Properties) {
     $settings.hooks.$eventName = $eventGroups
 }
 
-# STATUSLINE - add ONLY if the user has none. A statusline is a whole-config
-# key; we never clobber one the user already set, and we touch nothing else.
-if (-not $settings.PSObject.Properties["statusLine"]) {
-    $statuslineTemplate = Join-Path $projectRoot "templates\settings.json"
-    if (Test-Path $statuslineTemplate) {
-        $tpl = Get-Content $statuslineTemplate -Raw | ConvertFrom-Json
-        if ($tpl.PSObject.Properties["statusLine"]) {
-            $settings | Add-Member -MemberType NoteProperty -Name statusLine -Value $tpl.statusLine
-            Write-Host "  Context-usage statusline added to settings.json" -ForegroundColor Green
+# STATUSLINE - opt-in only (-Statusline). Even when opted in we add it ONLY if
+# the user has none: a statusline is a whole-config key, so we never clobber
+# one the user already set, and we touch nothing else.
+if ($Statusline) {
+    if (-not $settings.PSObject.Properties["statusLine"]) {
+        $statuslineTemplate = Join-Path $projectRoot "templates\settings.json"
+        if (Test-Path $statuslineTemplate) {
+            $tpl = Get-Content $statuslineTemplate -Raw | ConvertFrom-Json
+            if ($tpl.PSObject.Properties["statusLine"]) {
+                $settings | Add-Member -MemberType NoteProperty -Name statusLine -Value $tpl.statusLine
+                Write-Host "  Context-usage statusline added to settings.json" -ForegroundColor Green
+            }
         }
+    } else {
+        Write-Host "  Existing statusline preserved (remove it first to use the claude-mods one)" -ForegroundColor Green
     }
 } else {
-    Write-Host "  Existing statusline preserved" -ForegroundColor Green
+    Write-Host "  Statusline skipped (re-run with -Statusline to install it)" -ForegroundColor DarkGray
 }
 
 $settings | ConvertTo-Json -Depth 20 | Set-Content $settingsPath -Encoding UTF8

+ 17 - 4
scripts/install.sh

@@ -7,9 +7,19 @@
 # Usage:
 #   Linux/macOS:       ./scripts/install.sh
 #   Windows Git Bash:  bash scripts/install.sh
+#   Opt into the statusline: add --statusline
 
 set -e
 
+# --statusline is opt-in: off by default so a shared install never changes the
+# user's prompt UI without being asked.
+WANT_STATUSLINE=false
+for arg in "$@"; do
+    case "$arg" in
+        --statusline) WANT_STATUSLINE=true ;;
+    esac
+done
+
 BLUE='\033[0;34m'
 GREEN='\033[0;32m'
 YELLOW='\033[1;33m'
@@ -267,14 +277,17 @@ else
     echo -e "  ${YELLOW}jq with walk/1 (>=1.6) not available, skipping hook wiring (plugin installs unaffected)${NC}"
 fi
 
-# STATUSLINE - add ONLY if the user has none. A statusline is a whole-config
-# key; we never clobber one the user already set, and we touch nothing else.
+# STATUSLINE - opt-in only (--statusline). Even when opted in we add it ONLY if
+# the user has none: a statusline is a whole-config key, so we never clobber one
+# the user already set, and we touch nothing else.
 statusline_tpl="$PROJECT_ROOT/templates/settings.json"
-if command -v jq >/dev/null 2>&1 && [ -f "$statusline_tpl" ]; then
+if ! $WANT_STATUSLINE; then
+    echo -e "  ${YELLOW}Statusline skipped (re-run with --statusline to install it)${NC}"
+elif command -v jq >/dev/null 2>&1 && [ -f "$statusline_tpl" ]; then
     settings_path="$CLAUDE_DIR/settings.json"
     [ -f "$settings_path" ] || printf '{}\n' > "$settings_path"
     if [ "$(jq 'has("statusLine")' "$settings_path" 2>/dev/null)" = "true" ]; then
-        echo -e "  ${GREEN}Existing statusline preserved${NC}"
+        echo -e "  ${GREEN}Existing statusline preserved (remove it first to use the claude-mods one)${NC}"
     else
         tmp_settings="$(mktemp)"
         if jq --slurpfile tpl "$statusline_tpl" '.statusLine = $tpl[0].statusLine' "$settings_path" > "$tmp_settings"; then