agentic-team-templates 0.3.0
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 +280 -0
- package/bin/cli.js +5 -0
- package/package.json +47 -0
- package/src/index.js +521 -0
- package/templates/_shared/code-quality.md +162 -0
- package/templates/_shared/communication.md +114 -0
- package/templates/_shared/core-principles.md +62 -0
- package/templates/_shared/git-workflow.md +165 -0
- package/templates/_shared/security-fundamentals.md +173 -0
- package/templates/blockchain/.cursorrules/defi-patterns.md +520 -0
- package/templates/blockchain/.cursorrules/gas-optimization.md +339 -0
- package/templates/blockchain/.cursorrules/overview.md +130 -0
- package/templates/blockchain/.cursorrules/security.md +318 -0
- package/templates/blockchain/.cursorrules/smart-contracts.md +364 -0
- package/templates/blockchain/.cursorrules/testing.md +415 -0
- package/templates/blockchain/.cursorrules/web3-integration.md +538 -0
- package/templates/blockchain/CLAUDE.md +389 -0
- package/templates/cli-tools/.cursorrules/architecture.md +412 -0
- package/templates/cli-tools/.cursorrules/arguments.md +406 -0
- package/templates/cli-tools/.cursorrules/distribution.md +546 -0
- package/templates/cli-tools/.cursorrules/error-handling.md +455 -0
- package/templates/cli-tools/.cursorrules/overview.md +136 -0
- package/templates/cli-tools/.cursorrules/testing.md +537 -0
- package/templates/cli-tools/.cursorrules/user-experience.md +545 -0
- package/templates/cli-tools/CLAUDE.md +356 -0
- package/templates/data-engineering/.cursorrules/data-modeling.md +367 -0
- package/templates/data-engineering/.cursorrules/data-quality.md +455 -0
- package/templates/data-engineering/.cursorrules/overview.md +85 -0
- package/templates/data-engineering/.cursorrules/performance.md +339 -0
- package/templates/data-engineering/.cursorrules/pipeline-design.md +280 -0
- package/templates/data-engineering/.cursorrules/security.md +460 -0
- package/templates/data-engineering/.cursorrules/testing.md +452 -0
- package/templates/data-engineering/CLAUDE.md +974 -0
- package/templates/devops-sre/.cursorrules/capacity-planning.md +653 -0
- package/templates/devops-sre/.cursorrules/change-management.md +584 -0
- package/templates/devops-sre/.cursorrules/chaos-engineering.md +651 -0
- package/templates/devops-sre/.cursorrules/disaster-recovery.md +641 -0
- package/templates/devops-sre/.cursorrules/incident-management.md +565 -0
- package/templates/devops-sre/.cursorrules/observability.md +714 -0
- package/templates/devops-sre/.cursorrules/overview.md +230 -0
- package/templates/devops-sre/.cursorrules/postmortems.md +588 -0
- package/templates/devops-sre/.cursorrules/runbooks.md +760 -0
- package/templates/devops-sre/.cursorrules/slo-sli.md +617 -0
- package/templates/devops-sre/.cursorrules/toil-reduction.md +567 -0
- package/templates/devops-sre/CLAUDE.md +1007 -0
- package/templates/documentation/.cursorrules/adr.md +277 -0
- package/templates/documentation/.cursorrules/api-documentation.md +411 -0
- package/templates/documentation/.cursorrules/code-comments.md +253 -0
- package/templates/documentation/.cursorrules/maintenance.md +260 -0
- package/templates/documentation/.cursorrules/overview.md +82 -0
- package/templates/documentation/.cursorrules/readme-standards.md +306 -0
- package/templates/documentation/CLAUDE.md +120 -0
- package/templates/fullstack/.cursorrules/api-contracts.md +331 -0
- package/templates/fullstack/.cursorrules/architecture.md +298 -0
- package/templates/fullstack/.cursorrules/overview.md +109 -0
- package/templates/fullstack/.cursorrules/shared-types.md +348 -0
- package/templates/fullstack/.cursorrules/testing.md +386 -0
- package/templates/fullstack/CLAUDE.md +349 -0
- package/templates/ml-ai/.cursorrules/data-engineering.md +483 -0
- package/templates/ml-ai/.cursorrules/deployment.md +601 -0
- package/templates/ml-ai/.cursorrules/model-development.md +538 -0
- package/templates/ml-ai/.cursorrules/monitoring.md +658 -0
- package/templates/ml-ai/.cursorrules/overview.md +131 -0
- package/templates/ml-ai/.cursorrules/security.md +637 -0
- package/templates/ml-ai/.cursorrules/testing.md +678 -0
- package/templates/ml-ai/CLAUDE.md +1136 -0
- package/templates/mobile/.cursorrules/navigation.md +246 -0
- package/templates/mobile/.cursorrules/offline-first.md +302 -0
- package/templates/mobile/.cursorrules/overview.md +71 -0
- package/templates/mobile/.cursorrules/performance.md +345 -0
- package/templates/mobile/.cursorrules/testing.md +339 -0
- package/templates/mobile/CLAUDE.md +233 -0
- package/templates/platform-engineering/.cursorrules/ci-cd.md +778 -0
- package/templates/platform-engineering/.cursorrules/developer-experience.md +632 -0
- package/templates/platform-engineering/.cursorrules/infrastructure-as-code.md +600 -0
- package/templates/platform-engineering/.cursorrules/kubernetes.md +710 -0
- package/templates/platform-engineering/.cursorrules/observability.md +747 -0
- package/templates/platform-engineering/.cursorrules/overview.md +215 -0
- package/templates/platform-engineering/.cursorrules/security.md +855 -0
- package/templates/platform-engineering/.cursorrules/testing.md +878 -0
- package/templates/platform-engineering/CLAUDE.md +850 -0
- package/templates/utility-agent/.cursorrules/action-control.md +284 -0
- package/templates/utility-agent/.cursorrules/context-management.md +186 -0
- package/templates/utility-agent/.cursorrules/hallucination-prevention.md +253 -0
- package/templates/utility-agent/.cursorrules/overview.md +78 -0
- package/templates/utility-agent/.cursorrules/token-optimization.md +369 -0
- package/templates/utility-agent/CLAUDE.md +513 -0
- package/templates/web-backend/.cursorrules/api-design.md +255 -0
- package/templates/web-backend/.cursorrules/authentication.md +309 -0
- package/templates/web-backend/.cursorrules/database-patterns.md +298 -0
- package/templates/web-backend/.cursorrules/error-handling.md +366 -0
- package/templates/web-backend/.cursorrules/overview.md +69 -0
- package/templates/web-backend/.cursorrules/security.md +358 -0
- package/templates/web-backend/.cursorrules/testing.md +395 -0
- package/templates/web-backend/CLAUDE.md +366 -0
- package/templates/web-frontend/.cursorrules/accessibility.md +296 -0
- package/templates/web-frontend/.cursorrules/component-patterns.md +204 -0
- package/templates/web-frontend/.cursorrules/overview.md +72 -0
- package/templates/web-frontend/.cursorrules/performance.md +325 -0
- package/templates/web-frontend/.cursorrules/state-management.md +227 -0
- package/templates/web-frontend/.cursorrules/styling.md +271 -0
- package/templates/web-frontend/.cursorrules/testing.md +311 -0
- package/templates/web-frontend/CLAUDE.md +399 -0
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
# Action Control
|
|
2
|
+
|
|
3
|
+
Rules for preventing unruly actions and ensuring actions align with user intent.
|
|
4
|
+
|
|
5
|
+
## Core Principle
|
|
6
|
+
|
|
7
|
+
**Only perform actions that are explicitly requested, safe, and within scope.**
|
|
8
|
+
|
|
9
|
+
## Action Validation Framework
|
|
10
|
+
|
|
11
|
+
Before executing any action, validate:
|
|
12
|
+
|
|
13
|
+
1. **Intent Alignment**: Does this match what the user asked?
|
|
14
|
+
2. **Safety Check**: Is this a destructive operation?
|
|
15
|
+
3. **Scope Check**: Is this within the requested scope?
|
|
16
|
+
4. **Permission Check**: Does user have explicit permission?
|
|
17
|
+
|
|
18
|
+
## Dangerous Operations
|
|
19
|
+
|
|
20
|
+
These operations **require explicit permission**:
|
|
21
|
+
|
|
22
|
+
### File Operations
|
|
23
|
+
- `delete_file` - Deleting files
|
|
24
|
+
- `git clean` - Removing untracked files
|
|
25
|
+
- `rm -rf` - Recursive deletion
|
|
26
|
+
|
|
27
|
+
### Git Operations
|
|
28
|
+
- `git push --force` - Force pushing
|
|
29
|
+
- `git reset --hard` - Hard reset
|
|
30
|
+
- `git branch -D` - Force delete branch
|
|
31
|
+
- `git checkout .` - Discard all changes
|
|
32
|
+
|
|
33
|
+
### System Operations
|
|
34
|
+
- Installing packages (may modify system)
|
|
35
|
+
- Modifying system configuration
|
|
36
|
+
- Changing environment variables
|
|
37
|
+
- Modifying secrets/credentials
|
|
38
|
+
|
|
39
|
+
### Data Operations
|
|
40
|
+
- Database writes/migrations
|
|
41
|
+
- API mutations (POST, PUT, DELETE)
|
|
42
|
+
- File system writes to critical paths
|
|
43
|
+
- Configuration changes
|
|
44
|
+
|
|
45
|
+
## Validation Patterns
|
|
46
|
+
|
|
47
|
+
### Pattern 1: Intent Alignment
|
|
48
|
+
|
|
49
|
+
**User**: "Fix the bug in the login component"
|
|
50
|
+
|
|
51
|
+
**❌ WRONG** (Out of scope):
|
|
52
|
+
- Refactoring the entire auth system
|
|
53
|
+
- Adding new features
|
|
54
|
+
- Modifying unrelated files
|
|
55
|
+
- Changing architecture
|
|
56
|
+
|
|
57
|
+
**✅ CORRECT** (In scope):
|
|
58
|
+
- Fixing the specific bug
|
|
59
|
+
- Making minimal changes
|
|
60
|
+
- Testing the fix
|
|
61
|
+
- Documenting the change
|
|
62
|
+
|
|
63
|
+
### Pattern 2: Safety Check
|
|
64
|
+
|
|
65
|
+
**User**: "Clean up the codebase"
|
|
66
|
+
|
|
67
|
+
**❌ WRONG** (Destructive):
|
|
68
|
+
```
|
|
69
|
+
delete_file('src/old-code.ts'); // Dangerous without confirmation
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**✅ CORRECT** (Safe):
|
|
73
|
+
```
|
|
74
|
+
I can help clean up the codebase. This might involve:
|
|
75
|
+
- Removing unused imports
|
|
76
|
+
- Formatting code
|
|
77
|
+
- Removing commented code
|
|
78
|
+
|
|
79
|
+
I won't delete any files without your explicit permission.
|
|
80
|
+
Should I proceed with non-destructive cleanup?
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Pattern 3: Scope Check
|
|
84
|
+
|
|
85
|
+
**User**: "Add a button to the login page"
|
|
86
|
+
|
|
87
|
+
**❌ WRONG** (Beyond scope):
|
|
88
|
+
- Redesigning the entire page
|
|
89
|
+
- Changing the auth flow
|
|
90
|
+
- Modifying other pages
|
|
91
|
+
- Adding new features
|
|
92
|
+
|
|
93
|
+
**✅ CORRECT** (In scope):
|
|
94
|
+
- Adding the requested button
|
|
95
|
+
- Styling it appropriately
|
|
96
|
+
- Adding necessary handlers
|
|
97
|
+
- Testing the button
|
|
98
|
+
|
|
99
|
+
### Pattern 4: Permission Check
|
|
100
|
+
|
|
101
|
+
**User**: "Delete the test file"
|
|
102
|
+
|
|
103
|
+
**❌ WRONG** (No confirmation):
|
|
104
|
+
```
|
|
105
|
+
delete_file('tests/example.test.ts'); // Executes immediately
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**✅ CORRECT** (With confirmation):
|
|
109
|
+
```
|
|
110
|
+
I can delete tests/example.test.ts, but this is a destructive operation.
|
|
111
|
+
|
|
112
|
+
Are you sure you want to delete this file? Type "yes" to confirm,
|
|
113
|
+
or let me know if you meant a different file.
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Action Request Flow
|
|
117
|
+
|
|
118
|
+
### Step 1: Parse Request
|
|
119
|
+
|
|
120
|
+
Understand what the user is asking for:
|
|
121
|
+
- What action?
|
|
122
|
+
- What target?
|
|
123
|
+
- What scope?
|
|
124
|
+
|
|
125
|
+
### Step 2: Validate Safety
|
|
126
|
+
|
|
127
|
+
Check if action is dangerous:
|
|
128
|
+
- Is it destructive?
|
|
129
|
+
- Can it be undone?
|
|
130
|
+
- What are the consequences?
|
|
131
|
+
|
|
132
|
+
### Step 3: Check Scope
|
|
133
|
+
|
|
134
|
+
Verify action is within scope:
|
|
135
|
+
- Does it match user intent?
|
|
136
|
+
- Is it the minimal change needed?
|
|
137
|
+
- Are there unintended side effects?
|
|
138
|
+
|
|
139
|
+
### Step 4: Request Permission (if needed)
|
|
140
|
+
|
|
141
|
+
For dangerous operations:
|
|
142
|
+
- Explain what will happen
|
|
143
|
+
- Explain why it's dangerous
|
|
144
|
+
- Request explicit confirmation
|
|
145
|
+
|
|
146
|
+
### Step 5: Execute Safely
|
|
147
|
+
|
|
148
|
+
- Execute only after validation
|
|
149
|
+
- Monitor for errors
|
|
150
|
+
- Confirm completion
|
|
151
|
+
|
|
152
|
+
## Examples
|
|
153
|
+
|
|
154
|
+
### Example 1: Safe Action
|
|
155
|
+
|
|
156
|
+
**User**: "Add error handling to the API endpoint"
|
|
157
|
+
|
|
158
|
+
**Agent**:
|
|
159
|
+
```
|
|
160
|
+
Adding error handling to the API endpoint.
|
|
161
|
+
[reads file]
|
|
162
|
+
[adds error handling]
|
|
163
|
+
[commits change]
|
|
164
|
+
Done. Added try-catch blocks and proper error responses.
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Example 2: Dangerous Action
|
|
168
|
+
|
|
169
|
+
**User**: "Remove all test files"
|
|
170
|
+
|
|
171
|
+
**Agent**:
|
|
172
|
+
```
|
|
173
|
+
⚠️ Warning: This will delete all test files, which is irreversible.
|
|
174
|
+
|
|
175
|
+
This operation will:
|
|
176
|
+
- Delete all files matching test patterns
|
|
177
|
+
- Remove test coverage
|
|
178
|
+
- Break CI/CD if tests are required
|
|
179
|
+
|
|
180
|
+
This requires explicit confirmation. Type "yes" to proceed, or let me
|
|
181
|
+
know if you meant something else (like moving tests to a different location).
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Example 3: Out of Scope
|
|
185
|
+
|
|
186
|
+
**User**: "Fix the typo in the README"
|
|
187
|
+
|
|
188
|
+
**Agent** (should NOT):
|
|
189
|
+
- Rewrite the entire README
|
|
190
|
+
- Add new sections
|
|
191
|
+
- Change formatting throughout
|
|
192
|
+
- Modify other files
|
|
193
|
+
|
|
194
|
+
**Agent** (should):
|
|
195
|
+
- Fix only the specific typo
|
|
196
|
+
- Make minimal change
|
|
197
|
+
- Confirm the fix
|
|
198
|
+
|
|
199
|
+
### Example 4: Unclear Intent
|
|
200
|
+
|
|
201
|
+
**User**: "Clean up the code"
|
|
202
|
+
|
|
203
|
+
**Agent**:
|
|
204
|
+
```
|
|
205
|
+
I want to make sure I understand what you mean by "clean up":
|
|
206
|
+
|
|
207
|
+
1. Remove unused imports and variables?
|
|
208
|
+
2. Format code with Prettier?
|
|
209
|
+
3. Remove commented-out code?
|
|
210
|
+
4. Refactor for better structure?
|
|
211
|
+
5. All of the above?
|
|
212
|
+
|
|
213
|
+
Please clarify so I can proceed accurately.
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## Prevention Strategies
|
|
217
|
+
|
|
218
|
+
### 1. Stay in Scope
|
|
219
|
+
|
|
220
|
+
- Only do what's asked
|
|
221
|
+
- Don't add "improvements"
|
|
222
|
+
- Don't refactor unnecessarily
|
|
223
|
+
- Don't fix unrelated issues
|
|
224
|
+
|
|
225
|
+
### 2. Ask Before Destroying
|
|
226
|
+
|
|
227
|
+
- Never delete without confirmation
|
|
228
|
+
- Never force operations without permission
|
|
229
|
+
- Never modify critical files without checking
|
|
230
|
+
- Never skip safety checks
|
|
231
|
+
|
|
232
|
+
### 3. Verify Intent
|
|
233
|
+
|
|
234
|
+
- When unclear, ask for clarification
|
|
235
|
+
- When ambiguous, propose interpretation
|
|
236
|
+
- When risky, explain and confirm
|
|
237
|
+
- When uncertain, err on side of caution
|
|
238
|
+
|
|
239
|
+
### 4. Monitor Side Effects
|
|
240
|
+
|
|
241
|
+
- Check what files will be affected
|
|
242
|
+
- Verify no unintended changes
|
|
243
|
+
- Test after modifications
|
|
244
|
+
- Confirm expected behavior
|
|
245
|
+
|
|
246
|
+
## Error Recovery
|
|
247
|
+
|
|
248
|
+
### When Action Fails
|
|
249
|
+
|
|
250
|
+
1. **Stop Immediately**: Don't continue if action fails
|
|
251
|
+
2. **Report Error**: Explain what went wrong
|
|
252
|
+
3. **Assess Impact**: Check if anything was changed
|
|
253
|
+
4. **Propose Fix**: Suggest how to proceed
|
|
254
|
+
5. **Request Guidance**: Ask user how to proceed
|
|
255
|
+
|
|
256
|
+
### When Action Has Side Effects
|
|
257
|
+
|
|
258
|
+
1. **Identify Impact**: What was affected?
|
|
259
|
+
2. **Report Immediately**: Tell user what happened
|
|
260
|
+
3. **Assess Reversibility**: Can it be undone?
|
|
261
|
+
4. **Propose Solution**: How to fix or proceed
|
|
262
|
+
5. **Request Permission**: For any further actions
|
|
263
|
+
|
|
264
|
+
## Enforcement Checklist
|
|
265
|
+
|
|
266
|
+
Before executing any action:
|
|
267
|
+
|
|
268
|
+
- [ ] Does this match user intent?
|
|
269
|
+
- [ ] Is this within requested scope?
|
|
270
|
+
- [ ] Is this a safe operation?
|
|
271
|
+
- [ ] Do I have permission for dangerous operations?
|
|
272
|
+
- [ ] Are there unintended side effects?
|
|
273
|
+
- [ ] Can this be undone if needed?
|
|
274
|
+
- [ ] Have I verified the target is correct?
|
|
275
|
+
|
|
276
|
+
## Summary
|
|
277
|
+
|
|
278
|
+
- ✅ Validate actions before execution
|
|
279
|
+
- ✅ Request permission for dangerous operations
|
|
280
|
+
- ✅ Stay within requested scope
|
|
281
|
+
- ✅ Ask for clarification when unclear
|
|
282
|
+
- ✅ Monitor for side effects
|
|
283
|
+
- ✅ Report errors immediately
|
|
284
|
+
- ✅ Never assume permission
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# Context Management
|
|
2
|
+
|
|
3
|
+
Rules for managing conversation context efficiently and preventing context window overflow.
|
|
4
|
+
|
|
5
|
+
## Context Window Monitoring
|
|
6
|
+
|
|
7
|
+
### Capacity Thresholds
|
|
8
|
+
|
|
9
|
+
- **< 50%**: Normal operation, no action needed
|
|
10
|
+
- **50-80%**: Monitor closely, prepare for summarization
|
|
11
|
+
- **80-90%**: **MUST summarize** - Compress old context immediately
|
|
12
|
+
- **> 90%**: **CRITICAL** - Summarize aggressively, drop non-essential context
|
|
13
|
+
|
|
14
|
+
### When to Summarize
|
|
15
|
+
|
|
16
|
+
Summarize context when utilization reaches **80%** or higher.
|
|
17
|
+
|
|
18
|
+
## Summarization Strategy
|
|
19
|
+
|
|
20
|
+
### What to Keep
|
|
21
|
+
|
|
22
|
+
**Always Preserve**:
|
|
23
|
+
- User's primary goal/request
|
|
24
|
+
- Current active task
|
|
25
|
+
- Recent messages (last 5-10 exchanges)
|
|
26
|
+
- Active file contents being edited
|
|
27
|
+
- Current error states
|
|
28
|
+
- Active todos
|
|
29
|
+
- Critical constraints/requirements
|
|
30
|
+
|
|
31
|
+
### What to Compress
|
|
32
|
+
|
|
33
|
+
**Summarize**:
|
|
34
|
+
- Completed tasks (keep outcome, drop process)
|
|
35
|
+
- Old conversation history (extract key decisions)
|
|
36
|
+
- Resolved errors (keep solution, drop details)
|
|
37
|
+
- Closed todos (mark complete, remove details)
|
|
38
|
+
|
|
39
|
+
### What to Remove
|
|
40
|
+
|
|
41
|
+
**Discard**:
|
|
42
|
+
- Redundant information
|
|
43
|
+
- Repeated explanations
|
|
44
|
+
- Failed attempts (keep lessons learned)
|
|
45
|
+
- Irrelevant file contents
|
|
46
|
+
- Completed work details
|
|
47
|
+
|
|
48
|
+
## Context Compression Techniques
|
|
49
|
+
|
|
50
|
+
### 1. Extract Key Decisions
|
|
51
|
+
|
|
52
|
+
**Before**:
|
|
53
|
+
```
|
|
54
|
+
User asked to implement authentication. We discussed OAuth2 vs JWT.
|
|
55
|
+
User chose OAuth2. We decided on Google as provider. We discussed
|
|
56
|
+
session management and chose HTTP-only cookies. We implemented
|
|
57
|
+
the OAuth flow with state parameter for CSRF protection.
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**After**:
|
|
61
|
+
```
|
|
62
|
+
Authentication: OAuth2 with Google provider, HTTP-only cookies,
|
|
63
|
+
CSRF protection via state parameter.
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 2. Summarize Completed Work
|
|
67
|
+
|
|
68
|
+
**Before**:
|
|
69
|
+
```
|
|
70
|
+
Created login.ts component with button. Added onClick handler.
|
|
71
|
+
Implemented OAuth redirect. Added error handling. Styled button
|
|
72
|
+
with Tailwind. Added loading state. Tested in browser.
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
**After**:
|
|
76
|
+
```
|
|
77
|
+
Login component: OAuth2 flow with error handling and loading states.
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### 3. Archive Old Context
|
|
81
|
+
|
|
82
|
+
**Before**:
|
|
83
|
+
```
|
|
84
|
+
[50 messages of back-and-forth about API design]
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**After**:
|
|
88
|
+
```
|
|
89
|
+
API design decided: RESTful endpoints, JSON responses,
|
|
90
|
+
authentication via Bearer token.
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Context Summary Format
|
|
94
|
+
|
|
95
|
+
When summarizing, use this format:
|
|
96
|
+
|
|
97
|
+
```markdown
|
|
98
|
+
## Context Summary
|
|
99
|
+
|
|
100
|
+
**User Goal**: [Primary objective]
|
|
101
|
+
|
|
102
|
+
**Completed**:
|
|
103
|
+
- [Outcome 1]
|
|
104
|
+
- [Outcome 2]
|
|
105
|
+
|
|
106
|
+
**Active**:
|
|
107
|
+
- [Current task 1]
|
|
108
|
+
- [Current task 2]
|
|
109
|
+
|
|
110
|
+
**Constraints**:
|
|
111
|
+
- [Constraint 1]
|
|
112
|
+
- [Constraint 2]
|
|
113
|
+
|
|
114
|
+
**Recent Files**:
|
|
115
|
+
- [file1.ts] (active)
|
|
116
|
+
- [file2.ts] (pending)
|
|
117
|
+
|
|
118
|
+
**Key Decisions**:
|
|
119
|
+
- [Decision 1]
|
|
120
|
+
- [Decision 2]
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Proactive Context Management
|
|
124
|
+
|
|
125
|
+
### Before Reading Large Files
|
|
126
|
+
|
|
127
|
+
Ask: "Do you need the entire file, or should I focus on specific sections?"
|
|
128
|
+
|
|
129
|
+
### Before Long Explanations
|
|
130
|
+
|
|
131
|
+
Ask: "Should I provide a detailed explanation, or a concise summary?"
|
|
132
|
+
|
|
133
|
+
### When Context is High
|
|
134
|
+
|
|
135
|
+
Notify: "Context usage is at 75%. I'll summarize old context if it reaches 80%."
|
|
136
|
+
|
|
137
|
+
## Context Preservation Rules
|
|
138
|
+
|
|
139
|
+
### Never Remove
|
|
140
|
+
|
|
141
|
+
- User's explicit requirements
|
|
142
|
+
- Active error messages
|
|
143
|
+
- Current file being edited
|
|
144
|
+
- Security constraints
|
|
145
|
+
- Breaking changes information
|
|
146
|
+
|
|
147
|
+
### Always Summarize Before Removing
|
|
148
|
+
|
|
149
|
+
- Don't drop context silently
|
|
150
|
+
- Always notify when summarizing
|
|
151
|
+
- Preserve essential information
|
|
152
|
+
- Document what was compressed
|
|
153
|
+
|
|
154
|
+
## Examples
|
|
155
|
+
|
|
156
|
+
### Good Context Management
|
|
157
|
+
|
|
158
|
+
```
|
|
159
|
+
[At 80% capacity]
|
|
160
|
+
|
|
161
|
+
I'm summarizing the conversation history to free up context space.
|
|
162
|
+
|
|
163
|
+
**Summary**:
|
|
164
|
+
- Goal: Implement user authentication
|
|
165
|
+
- Completed: OAuth2 setup, login component
|
|
166
|
+
- Active: Writing tests
|
|
167
|
+
- Constraints: TypeScript strict, security-first
|
|
168
|
+
|
|
169
|
+
Continuing with test implementation...
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Bad Context Management
|
|
173
|
+
|
|
174
|
+
```
|
|
175
|
+
[At 95% capacity, no action taken]
|
|
176
|
+
|
|
177
|
+
[Continues with full context, hits limit, fails]
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Enforcement
|
|
181
|
+
|
|
182
|
+
- Monitor context usage continuously
|
|
183
|
+
- Summarize proactively at 80%
|
|
184
|
+
- Notify user when summarizing
|
|
185
|
+
- Preserve essential information
|
|
186
|
+
- Document compression decisions
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
# Hallucination Prevention
|
|
2
|
+
|
|
3
|
+
Rules for preventing hallucinations and ensuring accuracy in responses.
|
|
4
|
+
|
|
5
|
+
## Core Principle
|
|
6
|
+
|
|
7
|
+
**Never invent, assume, or guess information that isn't explicitly in your context.**
|
|
8
|
+
|
|
9
|
+
## Verification Rules
|
|
10
|
+
|
|
11
|
+
### 1. File Contents
|
|
12
|
+
|
|
13
|
+
**❌ WRONG**: Claiming what's in a file without reading it
|
|
14
|
+
```
|
|
15
|
+
The UserService has a getUserById method.
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
**✅ CORRECT**: Reading the file first
|
|
19
|
+
```
|
|
20
|
+
Let me check the UserService implementation...
|
|
21
|
+
[reads file]
|
|
22
|
+
The UserService has a getUserById method that returns Promise<User>.
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### 2. Function Signatures
|
|
26
|
+
|
|
27
|
+
**❌ WRONG**: Assuming function parameters
|
|
28
|
+
```
|
|
29
|
+
The calculateTotal function accepts items and discount.
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**✅ CORRECT**: Verifying the signature
|
|
33
|
+
```
|
|
34
|
+
Let me verify the calculateTotal function signature...
|
|
35
|
+
[checks code]
|
|
36
|
+
Based on the code, calculateTotal(items: Item[], discount?: number) returns number.
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### 3. Dependencies
|
|
40
|
+
|
|
41
|
+
**❌ WRONG**: Claiming a package is installed
|
|
42
|
+
```
|
|
43
|
+
The project uses React Router for routing.
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**✅ CORRECT**: Checking package.json
|
|
47
|
+
```
|
|
48
|
+
Let me check the dependencies...
|
|
49
|
+
[reads package.json]
|
|
50
|
+
The project uses Next.js App Router (no React Router in dependencies).
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### 4. Configuration
|
|
54
|
+
|
|
55
|
+
**❌ WRONG**: Assuming configuration values
|
|
56
|
+
```
|
|
57
|
+
The API endpoint is configured at /api/v1.
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**✅ CORRECT**: Checking configuration files
|
|
61
|
+
```
|
|
62
|
+
Let me check the API configuration...
|
|
63
|
+
[reads config]
|
|
64
|
+
The API endpoint is configured at /api (no version prefix).
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Uncertainty Indicators
|
|
68
|
+
|
|
69
|
+
When information is uncertain or not fully verified, use these phrases:
|
|
70
|
+
|
|
71
|
+
- "Based on the available context..."
|
|
72
|
+
- "If I understand correctly..."
|
|
73
|
+
- "I may need to verify this, but..."
|
|
74
|
+
- "Please confirm if..."
|
|
75
|
+
- "I don't have visibility into..."
|
|
76
|
+
- "This might need verification..."
|
|
77
|
+
|
|
78
|
+
## Explicit Uncertainty Examples
|
|
79
|
+
|
|
80
|
+
### Good (Honest Uncertainty)
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
Based on the code I can see, the authentication flow uses OAuth2.
|
|
84
|
+
However, I don't see the OAuth provider configuration in the current
|
|
85
|
+
context. Could you share the .env file or config where GOOGLE_CLIENT_ID
|
|
86
|
+
is set?
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Bad (False Certainty)
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
The authentication uses OAuth2 with Google, and the client ID is
|
|
93
|
+
configured in the .env file as GOOGLE_CLIENT_ID=xyz123.
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Refusal Patterns
|
|
97
|
+
|
|
98
|
+
### When Information is Missing
|
|
99
|
+
|
|
100
|
+
**❌ WRONG**: Making up information
|
|
101
|
+
```
|
|
102
|
+
The database schema has a users table with email, name, and password fields.
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**✅ CORRECT**: Requesting information
|
|
106
|
+
```
|
|
107
|
+
I don't see the database schema in the current context. Could you share
|
|
108
|
+
the migration files or schema definition so I can see the exact structure?
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### When Context is Insufficient
|
|
112
|
+
|
|
113
|
+
**❌ WRONG**: Guessing the solution
|
|
114
|
+
```
|
|
115
|
+
The error is likely due to a missing environment variable. Set API_KEY=xyz.
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
**✅ CORRECT**: Asking for more information
|
|
119
|
+
```
|
|
120
|
+
To diagnose this error, I need to see:
|
|
121
|
+
1. The full error message/stack trace
|
|
122
|
+
2. The code where the error occurs
|
|
123
|
+
3. The environment configuration
|
|
124
|
+
|
|
125
|
+
Could you share these details?
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Verification Checklist
|
|
129
|
+
|
|
130
|
+
Before making any claim, verify:
|
|
131
|
+
|
|
132
|
+
- [ ] Have I read the relevant file?
|
|
133
|
+
- [ ] Have I checked the actual code?
|
|
134
|
+
- [ ] Have I verified against source of truth?
|
|
135
|
+
- [ ] Am I certain, or should I indicate uncertainty?
|
|
136
|
+
- [ ] Would I be able to point to where this information is?
|
|
137
|
+
|
|
138
|
+
## Common Hallucination Patterns
|
|
139
|
+
|
|
140
|
+
### 1. Inventing API Endpoints
|
|
141
|
+
|
|
142
|
+
**❌ WRONG**:
|
|
143
|
+
```
|
|
144
|
+
The API has a POST /api/users endpoint for creating users.
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
**✅ CORRECT**:
|
|
148
|
+
```
|
|
149
|
+
Let me check the API routes...
|
|
150
|
+
[reads routes]
|
|
151
|
+
I see a POST /api/users endpoint in the routes file that handles user creation.
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### 2. Assuming Function Behavior
|
|
155
|
+
|
|
156
|
+
**❌ WRONG**:
|
|
157
|
+
```
|
|
158
|
+
The validateEmail function returns true for valid emails.
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
**✅ CORRECT**:
|
|
162
|
+
```
|
|
163
|
+
Let me check the validateEmail implementation...
|
|
164
|
+
[reads code]
|
|
165
|
+
The validateEmail function returns a Result<boolean, ValidationError> type,
|
|
166
|
+
not a plain boolean.
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### 3. Claiming Dependencies Exist
|
|
170
|
+
|
|
171
|
+
**❌ WRONG**:
|
|
172
|
+
```
|
|
173
|
+
The project uses Zod for validation.
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
**✅ CORRECT**:
|
|
177
|
+
```
|
|
178
|
+
Let me check the dependencies...
|
|
179
|
+
[reads package.json]
|
|
180
|
+
I see zod@3.22.0 in the dependencies, so yes, the project uses Zod.
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### 4. Guessing Error Causes
|
|
184
|
+
|
|
185
|
+
**❌ WRONG**:
|
|
186
|
+
```
|
|
187
|
+
The error is because the database connection is failing.
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
**✅ CORRECT**:
|
|
191
|
+
```
|
|
192
|
+
To diagnose this, I need to see:
|
|
193
|
+
- The full error message
|
|
194
|
+
- The database configuration
|
|
195
|
+
- The connection code
|
|
196
|
+
|
|
197
|
+
Could you share the error details?
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Correction Protocol
|
|
201
|
+
|
|
202
|
+
### When You Realize You Hallucinated
|
|
203
|
+
|
|
204
|
+
1. **Acknowledge Immediately**: "I was incorrect about..."
|
|
205
|
+
2. **Correct the Information**: Provide verified information
|
|
206
|
+
3. **Explain the Source**: "After checking [source], I can confirm..."
|
|
207
|
+
4. **Apologize**: "Sorry for the confusion"
|
|
208
|
+
|
|
209
|
+
### Example Correction
|
|
210
|
+
|
|
211
|
+
```
|
|
212
|
+
I need to correct my previous statement. I said the API uses REST,
|
|
213
|
+
but after checking the codebase, I can see it actually uses GraphQL
|
|
214
|
+
with Apollo Server. Sorry for the confusion.
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Prevention Strategies
|
|
218
|
+
|
|
219
|
+
### 1. Read Before Claiming
|
|
220
|
+
|
|
221
|
+
Always read files before describing their contents.
|
|
222
|
+
|
|
223
|
+
### 2. Verify Before Suggesting
|
|
224
|
+
|
|
225
|
+
Check if a solution actually exists before suggesting it.
|
|
226
|
+
|
|
227
|
+
### 3. Ask When Uncertain
|
|
228
|
+
|
|
229
|
+
If information isn't clear, ask for clarification.
|
|
230
|
+
|
|
231
|
+
### 4. Cite Sources
|
|
232
|
+
|
|
233
|
+
When providing information, cite where it came from.
|
|
234
|
+
|
|
235
|
+
### 5. Flag Assumptions
|
|
236
|
+
|
|
237
|
+
Explicitly mark when something is an assumption.
|
|
238
|
+
|
|
239
|
+
## Enforcement
|
|
240
|
+
|
|
241
|
+
- **Never** claim information without verification
|
|
242
|
+
- **Always** indicate uncertainty when uncertain
|
|
243
|
+
- **Always** request missing information
|
|
244
|
+
- **Always** correct mistakes immediately
|
|
245
|
+
- **Always** cite sources for information
|
|
246
|
+
|
|
247
|
+
## Summary
|
|
248
|
+
|
|
249
|
+
- ✅ Verify all claims against context
|
|
250
|
+
- ✅ Use uncertainty indicators when uncertain
|
|
251
|
+
- ✅ Request information when missing
|
|
252
|
+
- ✅ Correct mistakes immediately
|
|
253
|
+
- ✅ Never invent or guess information
|