cc-safe-setup 29.6.2 → 29.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/examples/auto-answer-question.sh +17 -8
- package/examples/fish-shell-wrapper.sh +37 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -117,7 +117,7 @@ Install any of these: `npx cc-safe-setup --install-example <name>`
|
|
|
117
117
|
| `--scan [--apply]` | Tech stack detection |
|
|
118
118
|
| `--export / --import` | Team config sharing |
|
|
119
119
|
| `--verify` | Test each hook |
|
|
120
|
-
| `--install-example <name>` | Install from
|
|
120
|
+
| `--install-example <name>` | Install from 412 examples |
|
|
121
121
|
| `--examples [filter]` | Browse examples by keyword |
|
|
122
122
|
| `--full` | All-in-one setup |
|
|
123
123
|
| `--status` | Check installed hooks |
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
2
|
# auto-answer-question.sh — Auto-answer AskUserQuestion for headless/autonomous mode
|
|
3
3
|
#
|
|
4
|
-
# NOTE: updatedInput schema (question/answer vs questions/answers array)
|
|
5
|
-
# may vary. Verify with your Claude Code version before production use.
|
|
6
|
-
#
|
|
7
4
|
# TRIGGER: PreToolUse
|
|
8
5
|
# MATCHER: AskUserQuestion
|
|
9
6
|
#
|
|
10
|
-
# v2.1.85+: PreToolUse hooks can
|
|
11
|
-
#
|
|
7
|
+
# v2.1.85+: PreToolUse hooks can return updatedInput with pre-filled answers
|
|
8
|
+
# alongside permissionDecision: "allow" to auto-answer questions.
|
|
9
|
+
#
|
|
10
|
+
# AskUserQuestion schema:
|
|
11
|
+
# tool_input.questions[] = { question: string, options?: string[] }
|
|
12
|
+
# updatedInput.answers = { "question text": "answer text" }
|
|
12
13
|
#
|
|
13
14
|
# Usage:
|
|
14
15
|
# {
|
|
@@ -28,7 +29,11 @@
|
|
|
28
29
|
# Unknown questions → pass through to human
|
|
29
30
|
|
|
30
31
|
INPUT=$(cat)
|
|
31
|
-
|
|
32
|
+
|
|
33
|
+
# Extract first question text from questions array
|
|
34
|
+
QUESTION=$(echo "$INPUT" | jq -r '.tool_input.questions[0].question // empty' 2>/dev/null)
|
|
35
|
+
# Fallback: try singular form for compatibility
|
|
36
|
+
[ -z "$QUESTION" ] && QUESTION=$(echo "$INPUT" | jq -r '.tool_input.question // empty' 2>/dev/null)
|
|
32
37
|
[ -z "$QUESTION" ] && exit 0
|
|
33
38
|
|
|
34
39
|
# Log all auto-answered questions for audit
|
|
@@ -42,7 +47,9 @@ if echo "$QUESTION" | grep -qiE 'delete|削除|drop|truncate|destroy|remove.*all
|
|
|
42
47
|
hookSpecificOutput: {
|
|
43
48
|
hookEventName: "PreToolUse",
|
|
44
49
|
permissionDecision: "allow",
|
|
45
|
-
updatedInput: {
|
|
50
|
+
updatedInput: {
|
|
51
|
+
answers: { ($q): "No. This operation is too risky for unattended mode." }
|
|
52
|
+
}
|
|
46
53
|
}
|
|
47
54
|
}'
|
|
48
55
|
echo "$(date -u '+%Y-%m-%dT%H:%M:%SZ') A: NO (dangerous)" >> "$LOG_DIR/auto-answers.log"
|
|
@@ -55,7 +62,9 @@ if echo "$QUESTION" | grep -qiE 'test|テスト|build|ビルド|lint|format|chec
|
|
|
55
62
|
hookSpecificOutput: {
|
|
56
63
|
hookEventName: "PreToolUse",
|
|
57
64
|
permissionDecision: "allow",
|
|
58
|
-
updatedInput: {
|
|
65
|
+
updatedInput: {
|
|
66
|
+
answers: { ($q): "Yes, proceed." }
|
|
67
|
+
}
|
|
59
68
|
}
|
|
60
69
|
}'
|
|
61
70
|
echo "$(date -u '+%Y-%m-%dT%H:%M:%SZ') A: YES (safe op)" >> "$LOG_DIR/auto-answers.log"
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# ================================================================
|
|
3
|
+
# fish-shell-wrapper.sh — Run Bash tool commands in fish shell
|
|
4
|
+
# ================================================================
|
|
5
|
+
# PURPOSE:
|
|
6
|
+
# Users who develop in fish lose PATH, aliases, and env vars because
|
|
7
|
+
# Claude Code's Bash tool uses the system default shell (usually zsh/bash).
|
|
8
|
+
# This hook wraps commands in `fish -c '...'` so they execute in fish.
|
|
9
|
+
#
|
|
10
|
+
# TRIGGER: PreToolUse
|
|
11
|
+
# MATCHER: "Bash"
|
|
12
|
+
#
|
|
13
|
+
# See: https://github.com/anthropics/claude-code/issues/7490
|
|
14
|
+
# ================================================================
|
|
15
|
+
|
|
16
|
+
INPUT=$(cat)
|
|
17
|
+
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // empty' 2>/dev/null)
|
|
18
|
+
[ -z "$COMMAND" ] && exit 0
|
|
19
|
+
|
|
20
|
+
# Skip if already wrapped in fish
|
|
21
|
+
echo "$COMMAND" | grep -q '^fish -c' && exit 0
|
|
22
|
+
|
|
23
|
+
# Skip simple builtins that work identically in any shell
|
|
24
|
+
echo "$COMMAND" | grep -qE '^\s*(cd|echo|cat|ls|pwd|true|false|test|mkdir|touch|rm|cp|mv)\b' && exit 0
|
|
25
|
+
|
|
26
|
+
# Escape single quotes for fish -c '...'
|
|
27
|
+
ESCAPED=$(printf '%s' "$COMMAND" | sed "s/'/'\\\\''/g")
|
|
28
|
+
|
|
29
|
+
jq -n --arg cmd "fish -c '$ESCAPED'" '{
|
|
30
|
+
hookSpecificOutput: {
|
|
31
|
+
hookEventName: "PreToolUse",
|
|
32
|
+
permissionDecision: "allow",
|
|
33
|
+
updatedInput: { command: $cmd }
|
|
34
|
+
}
|
|
35
|
+
}'
|
|
36
|
+
|
|
37
|
+
exit 0
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cc-safe-setup",
|
|
3
|
-
"version": "29.6.
|
|
4
|
-
"description": "One command to make Claude Code safe.
|
|
3
|
+
"version": "29.6.4",
|
|
4
|
+
"description": "One command to make Claude Code safe. 413 example hooks + 8 built-in. 52 CLI commands. 5613 tests. Works with Auto Mode.",
|
|
5
5
|
"main": "index.mjs",
|
|
6
6
|
"bin": {
|
|
7
7
|
"cc-safe-setup": "index.mjs"
|