Skip to content

Commit ae272da

Browse files
authored
Merge pull request anomalyco#1002 from affaan-m/fix/unicode-safety-hardening
fix: harden unicode safety checks
2 parents dd675d4 + 7483d64 commit ae272da

220 files changed

Lines changed: 2186 additions & 1859 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.agents/skills/backend-patterns/SKILL.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ Backend architecture patterns and best practices for scalable server-side applic
2323
### RESTful API Structure
2424

2525
```typescript
26-
// ✅ Resource-based URLs
26+
// PASS: Resource-based URLs
2727
GET /api/markets # List resources
2828
GET /api/markets/:id # Get single resource
2929
POST /api/markets # Create resource
3030
PUT /api/markets/:id # Replace resource
3131
PATCH /api/markets/:id # Update resource
3232
DELETE /api/markets/:id # Delete resource
3333

34-
// ✅ Query parameters for filtering, sorting, pagination
34+
// PASS: Query parameters for filtering, sorting, pagination
3535
GET /api/markets?status=active&sort=volume&limit=20&offset=0
3636
```
3737
@@ -131,15 +131,15 @@ export default withAuth(async (req, res) => {
131131
### Query Optimization
132132
133133
```typescript
134-
// ✅ GOOD: Select only needed columns
134+
// PASS: GOOD: Select only needed columns
135135
const { data } = await supabase
136136
.from('markets')
137137
.select('id, name, status, volume')
138138
.eq('status', 'active')
139139
.order('volume', { ascending: false })
140140
.limit(10)
141141

142-
// ❌ BAD: Select everything
142+
// FAIL: BAD: Select everything
143143
const { data } = await supabase
144144
.from('markets')
145145
.select('*')
@@ -148,13 +148,13 @@ const { data } = await supabase
148148
### N+1 Query Prevention
149149
150150
```typescript
151-
// ❌ BAD: N+1 query problem
151+
// FAIL: BAD: N+1 query problem
152152
const markets = await getMarkets()
153153
for (const market of markets) {
154154
market.creator = await getUser(market.creator_id) // N queries
155155
}
156156

157-
// ✅ GOOD: Batch fetch
157+
// PASS: GOOD: Batch fetch
158158
const markets = await getMarkets()
159159
const creatorIds = markets.map(m => m.creator_id)
160160
const creators = await getUsers(creatorIds) // 1 query

‎.agents/skills/coding-standards/SKILL.md‎

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ Universal coding standards applicable across all projects.
4848
### Variable Naming
4949

5050
```typescript
51-
// ✅ GOOD: Descriptive names
51+
// PASS: GOOD: Descriptive names
5252
const marketSearchQuery = 'election'
5353
const isUserAuthenticated = true
5454
const totalRevenue = 1000
5555

56-
// ❌ BAD: Unclear names
56+
// FAIL: BAD: Unclear names
5757
const q = 'election'
5858
const flag = true
5959
const x = 1000
@@ -62,12 +62,12 @@ const x = 1000
6262
### Function Naming
6363

6464
```typescript
65-
// ✅ GOOD: Verb-noun pattern
65+
// PASS: GOOD: Verb-noun pattern
6666
async function fetchMarketData(marketId: string) { }
6767
function calculateSimilarity(a: number[], b: number[]) { }
6868
function isValidEmail(email: string): boolean { }
6969

70-
// ❌ BAD: Unclear or noun-only
70+
// FAIL: BAD: Unclear or noun-only
7171
async function market(id: string) { }
7272
function similarity(a, b) { }
7373
function email(e) { }
@@ -76,23 +76,23 @@ function email(e) { }
7676
### Immutability Pattern (CRITICAL)
7777

7878
```typescript
79-
// ✅ ALWAYS use spread operator
79+
// PASS: ALWAYS use spread operator
8080
const updatedUser = {
8181
...user,
8282
name: 'New Name'
8383
}
8484

8585
const updatedArray = [...items, newItem]
8686

87-
// ❌ NEVER mutate directly
87+
// FAIL: NEVER mutate directly
8888
user.name = 'New Name' // BAD
8989
items.push(newItem) // BAD
9090
```
9191

9292
### Error Handling
9393

9494
```typescript
95-
// ✅ GOOD: Comprehensive error handling
95+
// PASS: GOOD: Comprehensive error handling
9696
async function fetchData(url: string) {
9797
try {
9898
const response = await fetch(url)
@@ -108,7 +108,7 @@ async function fetchData(url: string) {
108108
}
109109
}
110110

111-
// ❌ BAD: No error handling
111+
// FAIL: BAD: No error handling
112112
async function fetchData(url) {
113113
const response = await fetch(url)
114114
return response.json()
@@ -118,14 +118,14 @@ async function fetchData(url) {
118118
### Async/Await Best Practices
119119

120120
```typescript
121-
// ✅ GOOD: Parallel execution when possible
121+
// PASS: GOOD: Parallel execution when possible
122122
const [users, markets, stats] = await Promise.all([
123123
fetchUsers(),
124124
fetchMarkets(),
125125
fetchStats()
126126
])
127127

128-
// ❌ BAD: Sequential when unnecessary
128+
// FAIL: BAD: Sequential when unnecessary
129129
const users = await fetchUsers()
130130
const markets = await fetchMarkets()
131131
const stats = await fetchStats()
@@ -134,7 +134,7 @@ const stats = await fetchStats()
134134
### Type Safety
135135

136136
```typescript
137-
// ✅ GOOD: Proper types
137+
// PASS: GOOD: Proper types
138138
interface Market {
139139
id: string
140140
name: string
@@ -146,7 +146,7 @@ function getMarket(id: string): Promise<Market> {
146146
// Implementation
147147
}
148148

149-
// ❌ BAD: Using 'any'
149+
// FAIL: BAD: Using 'any'
150150
function getMarket(id: any): Promise<any> {
151151
// Implementation
152152
}
@@ -157,7 +157,7 @@ function getMarket(id: any): Promise<any> {
157157
### Component Structure
158158

159159
```typescript
160-
// ✅ GOOD: Functional component with types
160+
// PASS: GOOD: Functional component with types
161161
interface ButtonProps {
162162
children: React.ReactNode
163163
onClick: () => void
@@ -182,7 +182,7 @@ export function Button({
182182
)
183183
}
184184

185-
// ❌ BAD: No types, unclear structure
185+
// FAIL: BAD: No types, unclear structure
186186
export function Button(props) {
187187
return <button onClick={props.onClick}>{props.children}</button>
188188
}
@@ -191,7 +191,7 @@ export function Button(props) {
191191
### Custom Hooks
192192

193193
```typescript
194-
// ✅ GOOD: Reusable custom hook
194+
// PASS: GOOD: Reusable custom hook
195195
export function useDebounce<T>(value: T, delay: number): T {
196196
const [debouncedValue, setDebouncedValue] = useState<T>(value)
197197

@@ -213,25 +213,25 @@ const debouncedQuery = useDebounce(searchQuery, 500)
213213
### State Management
214214

215215
```typescript
216-
// ✅ GOOD: Proper state updates
216+
// PASS: GOOD: Proper state updates
217217
const [count, setCount] = useState(0)
218218

219219
// Functional update for state based on previous state
220220
setCount(prev => prev + 1)
221221

222-
// ❌ BAD: Direct state reference
222+
// FAIL: BAD: Direct state reference
223223
setCount(count + 1) // Can be stale in async scenarios
224224
```
225225

226226
### Conditional Rendering
227227

228228
```typescript
229-
// ✅ GOOD: Clear conditional rendering
229+
// PASS: GOOD: Clear conditional rendering
230230
{isLoading && <Spinner />}
231231
{error && <ErrorMessage error={error} />}
232232
{data && <DataDisplay data={data} />}
233233

234-
// ❌ BAD: Ternary hell
234+
// FAIL: BAD: Ternary hell
235235
{isLoading ? <Spinner /> : error ? <ErrorMessage error={error} /> : data ? <DataDisplay data={data} /> : null}
236236
```
237237

@@ -254,7 +254,7 @@ GET /api/markets?status=active&limit=10&offset=0
254254
### Response Format
255255

256256
```typescript
257-
// ✅ GOOD: Consistent response structure
257+
// PASS: GOOD: Consistent response structure
258258
interface ApiResponse<T> {
259259
success: boolean
260260
data?: T
@@ -285,7 +285,7 @@ return NextResponse.json({
285285
```typescript
286286
import { z } from 'zod'
287287

288-
// ✅ GOOD: Schema validation
288+
// PASS: GOOD: Schema validation
289289
const CreateMarketSchema = z.object({
290290
name: z.string().min(1).max(200),
291291
description: z.string().min(1).max(2000),
@@ -348,14 +348,14 @@ types/market.types.ts # camelCase with .types suffix
348348
### When to Comment
349349

350350
```typescript
351-
// ✅ GOOD: Explain WHY, not WHAT
351+
// PASS: GOOD: Explain WHY, not WHAT
352352
// Use exponential backoff to avoid overwhelming the API during outages
353353
const delay = Math.min(1000 * Math.pow(2, retryCount), 30000)
354354

355355
// Deliberately using mutation here for performance with large arrays
356356
items.push(newItem)
357357

358-
// ❌ BAD: Stating the obvious
358+
// FAIL: BAD: Stating the obvious
359359
// Increment counter by 1
360360
count++
361361

@@ -395,12 +395,12 @@ export async function searchMarkets(
395395
```typescript
396396
import { useMemo, useCallback } from 'react'
397397

398-
// ✅ GOOD: Memoize expensive computations
398+
// PASS: GOOD: Memoize expensive computations
399399
const sortedMarkets = useMemo(() => {
400400
return markets.sort((a, b) => b.volume - a.volume)
401401
}, [markets])
402402

403-
// ✅ GOOD: Memoize callbacks
403+
// PASS: GOOD: Memoize callbacks
404404
const handleSearch = useCallback((query: string) => {
405405
setSearchQuery(query)
406406
}, [])
@@ -411,7 +411,7 @@ const handleSearch = useCallback((query: string) => {
411411
```typescript
412412
import { lazy, Suspense } from 'react'
413413

414-
// ✅ GOOD: Lazy load heavy components
414+
// PASS: GOOD: Lazy load heavy components
415415
const HeavyChart = lazy(() => import('./HeavyChart'))
416416

417417
export function Dashboard() {
@@ -426,13 +426,13 @@ export function Dashboard() {
426426
### Database Queries
427427

428428
```typescript
429-
// ✅ GOOD: Select only needed columns
429+
// PASS: GOOD: Select only needed columns
430430
const { data } = await supabase
431431
.from('markets')
432432
.select('id, name, status')
433433
.limit(10)
434434

435-
// ❌ BAD: Select everything
435+
// FAIL: BAD: Select everything
436436
const { data } = await supabase
437437
.from('markets')
438438
.select('*')
@@ -459,12 +459,12 @@ test('calculates similarity correctly', () => {
459459
### Test Naming
460460

461461
```typescript
462-
// ✅ GOOD: Descriptive test names
462+
// PASS: GOOD: Descriptive test names
463463
test('returns empty array when no markets match query', () => { })
464464
test('throws error when OpenAI API key is missing', () => { })
465465
test('falls back to substring search when Redis unavailable', () => { })
466466

467-
// ❌ BAD: Vague test names
467+
// FAIL: BAD: Vague test names
468468
test('works', () => { })
469469
test('test search', () => { })
470470
```
@@ -475,12 +475,12 @@ Watch for these anti-patterns:
475475

476476
### 1. Long Functions
477477
```typescript
478-
// ❌ BAD: Function > 50 lines
478+
// FAIL: BAD: Function > 50 lines
479479
function processMarketData() {
480480
// 100 lines of code
481481
}
482482

483-
// ✅ GOOD: Split into smaller functions
483+
// PASS: GOOD: Split into smaller functions
484484
function processMarketData() {
485485
const validated = validateData()
486486
const transformed = transformData(validated)
@@ -490,7 +490,7 @@ function processMarketData() {
490490

491491
### 2. Deep Nesting
492492
```typescript
493-
// ❌ BAD: 5+ levels of nesting
493+
// FAIL: BAD: 5+ levels of nesting
494494
if (user) {
495495
if (user.isAdmin) {
496496
if (market) {
@@ -503,7 +503,7 @@ if (user) {
503503
}
504504
}
505505

506-
// ✅ GOOD: Early returns
506+
// PASS: GOOD: Early returns
507507
if (!user) return
508508
if (!user.isAdmin) return
509509
if (!market) return
@@ -515,11 +515,11 @@ if (!hasPermission) return
515515

516516
### 3. Magic Numbers
517517
```typescript
518-
// ❌ BAD: Unexplained numbers
518+
// FAIL: BAD: Unexplained numbers
519519
if (retryCount > 3) { }
520520
setTimeout(callback, 500)
521521

522-
// ✅ GOOD: Named constants
522+
// PASS: GOOD: Named constants
523523
const MAX_RETRIES = 3
524524
const DEBOUNCE_DELAY_MS = 500
525525

0 commit comments

Comments
 (0)