|
1 | 1 | --- |
2 | | -description: Set custom rules for the project |
3 | | -allowed-tools: Bash, Read, Write, Glob, AskUserQuestion |
| 2 | +description: Set custom rules for Safety Net |
| 3 | +allowed-tools: Bash, Read, Write, AskUserQuestion |
4 | 4 | --- |
5 | 5 |
|
6 | | -# Set Custom Rules for Safety Net |
7 | | - |
8 | 6 | You are helping the user configure custom blocking rules for claude-code-safety-net. |
9 | | -ALWAYS use AskUserQuestion tool when you need to ask the user questions. |
| 7 | + |
| 8 | +## Context |
| 9 | + |
| 10 | +### Schema Documentation |
| 11 | + |
| 12 | +!`npx -y cc-safety-net --custom-rules-doc` |
10 | 13 |
|
11 | 14 | ## Your Task |
12 | 15 |
|
13 | 16 | Follow this flow exactly: |
14 | 17 |
|
15 | | -### Step 1: Run `npx -y cc-safety-net --custom-rules-doc` to read the full schema details, field constraints, and usage examples |
| 18 | +### Step 1: Ask for Scope |
| 19 | + |
| 20 | +Use AskUserQuestion to let user select scope: |
| 21 | + |
| 22 | +```json |
| 23 | +{ |
| 24 | + "questions": [ |
| 25 | + { |
| 26 | + "question": "Which scope would you like to configure?", |
| 27 | + "header": "Configure", |
| 28 | + "multiSelect": false, |
| 29 | + "options": [ |
| 30 | + { |
| 31 | + "label": "User", |
| 32 | + "description": "(`~/.cc-safety-net/config.json`) - applies to all your projects" |
| 33 | + }, |
| 34 | + { |
| 35 | + "label": "Project", |
| 36 | + "description": "(`.safety-net.json`) - applies only to this project" |
| 37 | + } |
| 38 | + ] |
| 39 | + } |
| 40 | + ] |
| 41 | +} |
| 42 | +``` |
16 | 43 |
|
17 | | -### Step 2: Show Examples and Ask for Scope |
| 44 | +### Step 2: Show Examples and Ask for Rules |
18 | 45 |
|
19 | 46 | Show examples in natural language: |
20 | 47 | - "Block `git add -A` and `git add .` to prevent blanket staging" |
21 | 48 | - "Block `npm install -g` to prevent global package installs" |
22 | 49 | - "Block `docker system prune` to prevent accidental cleanup" |
23 | 50 |
|
24 | | -Ask: **Which scope would you like to configure?** |
25 | | -- **User** (`~/.cc-safety-net/config.json`) - applies to all your projects |
26 | | -- **Project** (`.safety-net.json`) - applies only to this project |
27 | | - |
28 | | -### Step 3: Ask for Rules |
29 | | - |
30 | 51 | Ask the user to describe rules in natural language. They can list multiple. |
31 | 52 |
|
32 | | -### Step 4: Generate JSON Config |
33 | | - |
34 | | -Parse user input and generate valid schema JSON. |
35 | | - |
36 | | -### Step 5: Show Config and Confirm |
37 | | - |
38 | | -Display the generated JSON and ask: |
39 | | -- "Does this look correct?" |
40 | | -- "Would you like to modify anything?" |
41 | | - |
42 | | -### Step 6: Check for Existing Config |
43 | | - |
44 | | -Check if config exists at target location: |
45 | | -```bash |
46 | | -cat ~/.cc-safety-net/config.json 2>/dev/null # user scope |
47 | | -cat .safety-net.json 2>/dev/null # project scope |
| 53 | +### Step 3: Generate and Show JSON Config |
| 54 | + |
| 55 | +Parse user input and generate valid schema JSON using the schema documentation above. |
| 56 | + |
| 57 | +Then show the generated config JSON to the user. |
| 58 | + |
| 59 | +### Step 4: Ask for Confirmation |
| 60 | + |
| 61 | +Use AskUserQuestion to let user choose: |
| 62 | + |
| 63 | +```json |
| 64 | +{ |
| 65 | + "questions": [ |
| 66 | + { |
| 67 | + "question": "Does this look correct?", |
| 68 | + "header": "Confirmation", |
| 69 | + "multiSelect": false, |
| 70 | + "options": [ |
| 71 | + { |
| 72 | + "label": "Yes", |
| 73 | + }, |
| 74 | + { |
| 75 | + "label": "No", |
| 76 | + } |
| 77 | + ] |
| 78 | + } |
| 79 | + ] |
| 80 | +} |
48 | 81 | ``` |
49 | 82 |
|
50 | | -If exists: |
51 | | -1. Show existing config |
52 | | -2. Ask: **Merge** (add new rules, duplicates use new version) or **Replace**? |
53 | | - |
54 | | -### Step 7: Validate and Write |
55 | | - |
56 | | -For user scope, ensure directory exists: |
57 | | -```bash |
58 | | -mkdir -p ~/.cc-safety-net |
| 83 | +### Step 5: Check and Handle Existing Config |
| 84 | + |
| 85 | +1. Check existing User Config with `cat ~/.cc-safety-net/config.json 2>/dev/null || echo "No user config found"` |
| 86 | +2. Check existing Project Config with `cat .safety-net.json 2>/dev/null || echo "No project config found"` |
| 87 | + |
| 88 | +If the chosen scope already has a config: |
| 89 | + |
| 90 | +Show the existing config to the user. |
| 91 | +Use AskUserQuestion tool to let user choose: |
| 92 | +```json |
| 93 | +{ |
| 94 | +"questions": [ |
| 95 | + { |
| 96 | + "question": "The chosen scope already has a config. What would you like to do?", |
| 97 | + "header": "Configure", |
| 98 | + "multiSelect": false, |
| 99 | + "options": [ |
| 100 | + { |
| 101 | + "label": "Merge", |
| 102 | + }, |
| 103 | + { |
| 104 | + "label": "Replace", |
| 105 | + } |
| 106 | + ] |
| 107 | + } |
| 108 | +] |
| 109 | +} |
59 | 110 | ``` |
60 | 111 |
|
61 | | -Write config, then validate: |
62 | | -```bash |
63 | | -npx -y cc-safety-net --verify-config |
64 | | -``` |
| 112 | +### Step 6: Write and Validate |
| 113 | + |
| 114 | +Write the config to the chosen scope, then validate with `npx -y cc-safety-net --verify-config`. |
65 | 115 |
|
66 | 116 | If validation errors: |
67 | 117 | - Show specific errors |
68 | 118 | - Offer to fix with your best suggestion |
69 | 119 | - Confirm before proceeding |
70 | 120 |
|
71 | | -### Step 8: Confirm Success |
| 121 | +### Step 7: Confirm Success |
72 | 122 |
|
73 | 123 | Tell the user: |
74 | 124 | 1. Config saved to [path] |
|
0 commit comments