Skip to content

Commit f4a274d

Browse files
committed
agents.md
1 parent cef968c commit f4a274d

File tree

1 file changed

+156
-0
lines changed

1 file changed

+156
-0
lines changed

AGENTS.md

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
# AI Agent Guidelines
2+
3+
This document contains critical rules and guidelines for AI agents working on this codebase.
4+
5+
## Security Rules
6+
7+
### CRITICAL: No Dynamic Values in Logs
8+
9+
**All log statements MUST use static strings only. NEVER include dynamic values, regardless of severity.**
10+
11+
#### Bad Examples (DO NOT DO THIS):
12+
```typescript
13+
// BAD - Contains dynamic values
14+
await logger.info(`Task created: ${taskId}`)
15+
await logger.error(`Failed to process ${filename}`)
16+
console.log(`User ${userId} logged in`)
17+
console.error(`Error for ${provider}:`, error)
18+
```
19+
20+
#### Good Examples (DO THIS):
21+
```typescript
22+
// GOOD - Static strings only
23+
await logger.info('Task created')
24+
await logger.error('Failed to process file')
25+
console.log('User logged in')
26+
console.error('Error occurred:', error)
27+
```
28+
29+
#### Rationale:
30+
- **Prevents data leakage**: Dynamic values in logs can expose sensitive information (user IDs, file paths, credentials, etc.) to end users
31+
- **Security by default**: Logs are displayed directly in the UI and returned in API responses
32+
- **No exceptions**: This applies to ALL log levels (info, error, success, command, console.log, console.error, console.warn, etc.)
33+
34+
#### Sensitive Data That Must NEVER Appear in Logs:
35+
- API keys and tokens (ANTHROPIC_API_KEY, OPENAI_API_KEY, GITHUB_TOKEN, etc.)
36+
- Vercel credentials (VERCEL_TOKEN, VERCEL_TEAM_ID, VERCEL_PROJECT_ID)
37+
- User IDs and personal information
38+
- File paths and repository URLs
39+
- Branch names and commit messages
40+
- Error details that may contain sensitive context
41+
- Any dynamic values that could reveal system internals
42+
43+
### Credential Redaction
44+
45+
The `redactSensitiveInfo()` function in `lib/utils/logging.ts` automatically redacts known sensitive patterns, but this is a **backup measure only**. The primary defense is to never log dynamic values in the first place.
46+
47+
#### Current Redaction Patterns:
48+
- API keys (ANTHROPIC_API_KEY, OPENAI_API_KEY, etc.)
49+
- GitHub tokens (ghp_, gho_, ghu_, ghs_, ghr_)
50+
- Vercel credentials (VERCEL_TOKEN, VERCEL_TEAM_ID, VERCEL_PROJECT_ID)
51+
- Bearer tokens
52+
- JSON fields (teamId, projectId)
53+
- Environment variables containing KEY, TOKEN, SECRET, PASSWORD, TEAM_ID, PROJECT_ID
54+
55+
## Code Quality Guidelines
56+
57+
### Logging Best Practices
58+
59+
1. **Use descriptive static messages**
60+
```typescript
61+
// Instead of logging the value, log the action
62+
await logger.info('Sandbox created successfully')
63+
await logger.info('Dependencies installed')
64+
await logger.error('Build failed')
65+
```
66+
67+
2. **Server-side logging for debugging**
68+
```typescript
69+
// Use console.error for server-side debugging (not shown to users)
70+
// But still avoid sensitive data
71+
console.error('Sandbox creation error:', error)
72+
```
73+
74+
3. **Progress updates**
75+
```typescript
76+
// Use static progress messages
77+
await logger.updateProgress(50, 'Installing dependencies')
78+
await logger.updateProgress(75, 'Running build')
79+
```
80+
81+
### Error Handling
82+
83+
1. **Generic error messages to users**
84+
```typescript
85+
await logger.error('Operation failed')
86+
// NOT: await logger.error(`Operation failed: ${error.message}`)
87+
```
88+
89+
2. **Detailed server-side logging**
90+
```typescript
91+
console.error('Detailed error for debugging:', error)
92+
// This appears in server logs, not user-facing logs
93+
```
94+
95+
## Testing Changes
96+
97+
When making changes that involve logging:
98+
99+
1. **Search for dynamic values**
100+
```bash
101+
# Check for logger statements with template literals
102+
grep -r "logger\.(info|error|success|command)\(\`.*\$\{" .
103+
104+
# Check for console statements with template literals
105+
grep -r "console\.(log|error|warn|info)\(\`.*\$\{" .
106+
```
107+
108+
2. **Verify no sensitive data exposure**
109+
- Test the feature in the UI
110+
- Check the logs displayed to users
111+
- Ensure no sensitive information is visible
112+
113+
## Configuration Security
114+
115+
### Environment Variables
116+
117+
Never expose these in logs or to the client:
118+
- `VERCEL_TOKEN` - Vercel API token
119+
- `VERCEL_TEAM_ID` - Vercel team identifier
120+
- `VERCEL_PROJECT_ID` - Vercel project identifier
121+
- `ANTHROPIC_API_KEY` - Anthropic/Claude API key
122+
- `OPENAI_API_KEY` - OpenAI API key
123+
- `GITHUB_TOKEN` - GitHub API token
124+
- `JWE_SECRET` - Encryption secret
125+
- `ENCRYPTION_KEY` - Encryption key
126+
- Any user-provided API keys
127+
128+
### Client-Safe Variables
129+
130+
Only these variables should be exposed to the client (via `NEXT_PUBLIC_` prefix):
131+
- `NEXT_PUBLIC_AUTH_PROVIDERS` - Available auth providers
132+
- `NEXT_PUBLIC_GITHUB_CLIENT_ID` - GitHub OAuth client ID (public)
133+
134+
## Compliance Checklist
135+
136+
Before submitting changes, verify:
137+
138+
- [ ] No template literals with `${}` in any log statements
139+
- [ ] All logger calls use static strings
140+
- [ ] All console calls use static strings (for user-facing logs)
141+
- [ ] No sensitive data in error messages
142+
- [ ] Tested in UI to confirm no data leakage
143+
- [ ] Server-side debugging logs don't expose credentials
144+
145+
## Questions?
146+
147+
If you need to log information for debugging purposes:
148+
1. Use server-side console logs (not shown to users)
149+
2. Still avoid logging sensitive credentials
150+
3. Consider adding better error handling instead of logging details
151+
4. Use generic user-facing messages
152+
153+
---
154+
155+
**Remember: When in doubt, use a static string. No exceptions.**
156+

0 commit comments

Comments
 (0)