@cloudstreamsoftware/claude-tools 1.0.0 → 1.2.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.
Files changed (190) hide show
  1. package/README.md +152 -37
  2. package/agents/INDEX.md +183 -0
  3. package/agents/architect.md +247 -0
  4. package/agents/build-error-resolver.md +555 -0
  5. package/agents/catalyst-deployer.md +132 -0
  6. package/agents/code-reviewer.md +121 -0
  7. package/agents/compliance-auditor.md +148 -0
  8. package/agents/creator-architect.md +395 -0
  9. package/agents/deluge-reviewer.md +98 -0
  10. package/agents/doc-updater.md +471 -0
  11. package/agents/e2e-runner.md +711 -0
  12. package/agents/planner.md +122 -0
  13. package/agents/refactor-cleaner.md +309 -0
  14. package/agents/security-reviewer.md +582 -0
  15. package/agents/tdd-guide.md +302 -0
  16. package/bin/cloudstream-setup.js +16 -6
  17. package/config/versions.json +63 -0
  18. package/dist/hooks/hooks.json +209 -0
  19. package/dist/index.js +47 -0
  20. package/dist/lib/asset-value.js +609 -0
  21. package/dist/lib/client-manager.js +300 -0
  22. package/dist/lib/command-matcher.js +242 -0
  23. package/dist/lib/cross-session-patterns.js +754 -0
  24. package/dist/lib/intent-classifier.js +1075 -0
  25. package/dist/lib/package-manager.js +374 -0
  26. package/dist/lib/recommendation-engine.js +597 -0
  27. package/dist/lib/session-memory.js +489 -0
  28. package/dist/lib/skill-effectiveness.js +486 -0
  29. package/dist/lib/skill-matcher.js +595 -0
  30. package/dist/lib/tutorial-metrics.js +242 -0
  31. package/dist/lib/tutorial-progress.js +209 -0
  32. package/dist/lib/tutorial-renderer.js +431 -0
  33. package/dist/lib/utils.js +380 -0
  34. package/dist/lib/verify-formatter.js +143 -0
  35. package/dist/lib/workflow-state.js +249 -0
  36. package/hooks/hooks.json +209 -0
  37. package/package.json +5 -1
  38. package/scripts/aggregate-sessions.js +290 -0
  39. package/scripts/branch-name-validator.js +291 -0
  40. package/scripts/build.js +101 -0
  41. package/scripts/commands/client-switch.js +231 -0
  42. package/scripts/deprecate-skill.js +610 -0
  43. package/scripts/diagnose.js +324 -0
  44. package/scripts/doc-freshness.js +168 -0
  45. package/scripts/generate-weekly-digest.js +393 -0
  46. package/scripts/health-check.js +270 -0
  47. package/scripts/hooks/credential-check.js +101 -0
  48. package/scripts/hooks/evaluate-session.js +81 -0
  49. package/scripts/hooks/pre-compact.js +66 -0
  50. package/scripts/hooks/prompt-analyzer.js +276 -0
  51. package/scripts/hooks/prompt-router.js +422 -0
  52. package/scripts/hooks/quality-gate-enforcer.js +371 -0
  53. package/scripts/hooks/session-end.js +156 -0
  54. package/scripts/hooks/session-start.js +195 -0
  55. package/scripts/hooks/skill-injector.js +333 -0
  56. package/scripts/hooks/suggest-compact.js +58 -0
  57. package/scripts/lib/asset-value.js +609 -0
  58. package/scripts/lib/client-manager.js +300 -0
  59. package/scripts/lib/command-matcher.js +242 -0
  60. package/scripts/lib/cross-session-patterns.js +754 -0
  61. package/scripts/lib/intent-classifier.js +1075 -0
  62. package/scripts/lib/package-manager.js +374 -0
  63. package/scripts/lib/recommendation-engine.js +597 -0
  64. package/scripts/lib/session-memory.js +489 -0
  65. package/scripts/lib/skill-effectiveness.js +486 -0
  66. package/scripts/lib/skill-matcher.js +595 -0
  67. package/scripts/lib/tutorial-metrics.js +242 -0
  68. package/scripts/lib/tutorial-progress.js +209 -0
  69. package/scripts/lib/tutorial-renderer.js +431 -0
  70. package/scripts/lib/utils.js +380 -0
  71. package/scripts/lib/verify-formatter.js +143 -0
  72. package/scripts/lib/workflow-state.js +249 -0
  73. package/scripts/onboard.js +363 -0
  74. package/scripts/quarterly-report.js +692 -0
  75. package/scripts/setup-package-manager.js +204 -0
  76. package/scripts/sync-upstream.js +391 -0
  77. package/scripts/test.js +108 -0
  78. package/scripts/tutorial-runner.js +351 -0
  79. package/scripts/validate-all.js +201 -0
  80. package/scripts/verifiers/agents.js +245 -0
  81. package/scripts/verifiers/config.js +186 -0
  82. package/scripts/verifiers/environment.js +123 -0
  83. package/scripts/verifiers/hooks.js +188 -0
  84. package/scripts/verifiers/index.js +38 -0
  85. package/scripts/verifiers/persistence.js +140 -0
  86. package/scripts/verifiers/plugin.js +215 -0
  87. package/scripts/verifiers/skills.js +209 -0
  88. package/scripts/verify-setup.js +164 -0
  89. package/skills/INDEX.md +157 -0
  90. package/skills/backend-patterns/SKILL.md +586 -0
  91. package/skills/backend-patterns/catalyst-patterns.md +128 -0
  92. package/skills/bigquery-patterns/SKILL.md +27 -0
  93. package/skills/bigquery-patterns/performance-optimization.md +518 -0
  94. package/skills/bigquery-patterns/query-patterns.md +372 -0
  95. package/skills/bigquery-patterns/schema-design.md +78 -0
  96. package/skills/cloudstream-project-template/SKILL.md +20 -0
  97. package/skills/cloudstream-project-template/structure.md +65 -0
  98. package/skills/coding-standards/SKILL.md +524 -0
  99. package/skills/coding-standards/deluge-standards.md +83 -0
  100. package/skills/compliance-patterns/SKILL.md +28 -0
  101. package/skills/compliance-patterns/hipaa/audit-requirements.md +251 -0
  102. package/skills/compliance-patterns/hipaa/baa-process.md +298 -0
  103. package/skills/compliance-patterns/hipaa/data-archival-strategy.md +387 -0
  104. package/skills/compliance-patterns/hipaa/phi-handling.md +52 -0
  105. package/skills/compliance-patterns/pci-dss/saq-a-requirements.md +307 -0
  106. package/skills/compliance-patterns/pci-dss/tokenization-patterns.md +382 -0
  107. package/skills/compliance-patterns/pci-dss/zoho-checkout-patterns.md +56 -0
  108. package/skills/compliance-patterns/soc2/access-controls.md +344 -0
  109. package/skills/compliance-patterns/soc2/audit-logging.md +458 -0
  110. package/skills/compliance-patterns/soc2/change-management.md +403 -0
  111. package/skills/compliance-patterns/soc2/deluge-execution-logging.md +407 -0
  112. package/skills/consultancy-workflows/SKILL.md +19 -0
  113. package/skills/consultancy-workflows/client-isolation.md +21 -0
  114. package/skills/consultancy-workflows/documentation-automation.md +454 -0
  115. package/skills/consultancy-workflows/handoff-procedures.md +257 -0
  116. package/skills/consultancy-workflows/knowledge-capture.md +513 -0
  117. package/skills/consultancy-workflows/time-tracking.md +26 -0
  118. package/skills/continuous-learning/SKILL.md +84 -0
  119. package/skills/continuous-learning/config.json +18 -0
  120. package/skills/continuous-learning/evaluate-session.sh +60 -0
  121. package/skills/continuous-learning-v2/SKILL.md +126 -0
  122. package/skills/continuous-learning-v2/config.json +61 -0
  123. package/skills/frontend-patterns/SKILL.md +635 -0
  124. package/skills/frontend-patterns/zoho-widget-patterns.md +103 -0
  125. package/skills/gcp-data-engineering/SKILL.md +36 -0
  126. package/skills/gcp-data-engineering/bigquery/performance-optimization.md +337 -0
  127. package/skills/gcp-data-engineering/dataflow/error-handling.md +496 -0
  128. package/skills/gcp-data-engineering/dataflow/pipeline-patterns.md +444 -0
  129. package/skills/gcp-data-engineering/dbt/model-organization.md +63 -0
  130. package/skills/gcp-data-engineering/dbt/testing-patterns.md +503 -0
  131. package/skills/gcp-data-engineering/medallion-architecture/bronze-layer.md +60 -0
  132. package/skills/gcp-data-engineering/medallion-architecture/gold-layer.md +311 -0
  133. package/skills/gcp-data-engineering/medallion-architecture/layer-transitions.md +517 -0
  134. package/skills/gcp-data-engineering/medallion-architecture/silver-layer.md +305 -0
  135. package/skills/gcp-data-engineering/zoho-to-gcp/data-extraction.md +543 -0
  136. package/skills/gcp-data-engineering/zoho-to-gcp/real-time-vs-batch.md +337 -0
  137. package/skills/security-review/SKILL.md +498 -0
  138. package/skills/security-review/compliance-checklist.md +53 -0
  139. package/skills/strategic-compact/SKILL.md +67 -0
  140. package/skills/tdd-workflow/SKILL.md +413 -0
  141. package/skills/tdd-workflow/zoho-testing.md +124 -0
  142. package/skills/tutorial/SKILL.md +249 -0
  143. package/skills/tutorial/docs/ACCESSIBILITY.md +169 -0
  144. package/skills/tutorial/lessons/00-philosophy-and-workflow.md +198 -0
  145. package/skills/tutorial/lessons/01-basics.md +81 -0
  146. package/skills/tutorial/lessons/02-training.md +86 -0
  147. package/skills/tutorial/lessons/03-commands.md +109 -0
  148. package/skills/tutorial/lessons/04-workflows.md +115 -0
  149. package/skills/tutorial/lessons/05-compliance.md +116 -0
  150. package/skills/tutorial/lessons/06-zoho.md +121 -0
  151. package/skills/tutorial/lessons/07-hooks-system.md +277 -0
  152. package/skills/tutorial/lessons/08-mcp-servers.md +316 -0
  153. package/skills/tutorial/lessons/09-client-management.md +215 -0
  154. package/skills/tutorial/lessons/10-testing-e2e.md +260 -0
  155. package/skills/tutorial/lessons/11-skills-deep-dive.md +272 -0
  156. package/skills/tutorial/lessons/12-rules-system.md +326 -0
  157. package/skills/tutorial/lessons/13-golden-standard-graduation.md +213 -0
  158. package/skills/tutorial/lessons/14-fork-setup-and-sync.md +312 -0
  159. package/skills/tutorial/lessons/15-living-examples-system.md +221 -0
  160. package/skills/tutorial/tracks/accelerated/README.md +134 -0
  161. package/skills/tutorial/tracks/accelerated/assessment/checkpoint-1.md +161 -0
  162. package/skills/tutorial/tracks/accelerated/assessment/checkpoint-2.md +175 -0
  163. package/skills/tutorial/tracks/accelerated/day-1-core-concepts.md +234 -0
  164. package/skills/tutorial/tracks/accelerated/day-2-essential-commands.md +270 -0
  165. package/skills/tutorial/tracks/accelerated/day-3-workflow-mastery.md +305 -0
  166. package/skills/tutorial/tracks/accelerated/day-4-compliance-zoho.md +304 -0
  167. package/skills/tutorial/tracks/accelerated/day-5-hooks-skills.md +344 -0
  168. package/skills/tutorial/tracks/accelerated/day-6-client-testing.md +386 -0
  169. package/skills/tutorial/tracks/accelerated/day-7-graduation.md +369 -0
  170. package/skills/zoho-patterns/CHANGELOG.md +108 -0
  171. package/skills/zoho-patterns/SKILL.md +446 -0
  172. package/skills/zoho-patterns/analytics/dashboard-patterns.md +352 -0
  173. package/skills/zoho-patterns/analytics/zoho-to-bigquery-pipeline.md +427 -0
  174. package/skills/zoho-patterns/catalyst/appsail-deployment.md +349 -0
  175. package/skills/zoho-patterns/catalyst/context-close-patterns.md +354 -0
  176. package/skills/zoho-patterns/catalyst/cron-batch-processing.md +374 -0
  177. package/skills/zoho-patterns/catalyst/function-patterns.md +439 -0
  178. package/skills/zoho-patterns/creator/form-design.md +304 -0
  179. package/skills/zoho-patterns/creator/publish-api-patterns.md +313 -0
  180. package/skills/zoho-patterns/creator/widget-integration.md +306 -0
  181. package/skills/zoho-patterns/creator/workflow-automation.md +253 -0
  182. package/skills/zoho-patterns/deluge/api-patterns.md +468 -0
  183. package/skills/zoho-patterns/deluge/batch-processing.md +403 -0
  184. package/skills/zoho-patterns/deluge/cross-app-integration.md +356 -0
  185. package/skills/zoho-patterns/deluge/error-handling.md +423 -0
  186. package/skills/zoho-patterns/deluge/syntax-reference.md +65 -0
  187. package/skills/zoho-patterns/integration/cors-proxy-architecture.md +426 -0
  188. package/skills/zoho-patterns/integration/crm-books-native-sync.md +277 -0
  189. package/skills/zoho-patterns/integration/oauth-token-management.md +461 -0
  190. package/skills/zoho-patterns/integration/zoho-flow-patterns.md +334 -0
@@ -0,0 +1,524 @@
1
+ ---
2
+ name: coding-standards
3
+ description: Universal coding standards, best practices, and patterns for TypeScript, JavaScript, React, and Node.js development.
4
+ version: 1.0.0
5
+ status: active
6
+ introduced: 1.0.0
7
+ lastUpdated: 2026-01-25
8
+ ---
9
+
10
+ # Coding Standards & Best Practices
11
+
12
+ Universal coding standards applicable across all projects.
13
+
14
+ ## Code Quality Principles
15
+
16
+ ### 1. Readability First
17
+ - Code is read more than written
18
+ - Clear variable and function names
19
+ - Self-documenting code preferred over comments
20
+ - Consistent formatting
21
+
22
+ ### 2. KISS (Keep It Simple, Stupid)
23
+ - Simplest solution that works
24
+ - Avoid over-engineering
25
+ - No premature optimization
26
+ - Easy to understand > clever code
27
+
28
+ ### 3. DRY (Don't Repeat Yourself)
29
+ - Extract common logic into functions
30
+ - Create reusable components
31
+ - Share utilities across modules
32
+ - Avoid copy-paste programming
33
+
34
+ ### 4. YAGNI (You Aren't Gonna Need It)
35
+ - Don't build features before they're needed
36
+ - Avoid speculative generality
37
+ - Add complexity only when required
38
+ - Start simple, refactor when needed
39
+
40
+ ## TypeScript/JavaScript Standards
41
+
42
+ ### Variable Naming
43
+
44
+ ```typescript
45
+ // ✅ GOOD: Descriptive names
46
+ const marketSearchQuery = 'election'
47
+ const isUserAuthenticated = true
48
+ const totalRevenue = 1000
49
+
50
+ // ❌ BAD: Unclear names
51
+ const q = 'election'
52
+ const flag = true
53
+ const x = 1000
54
+ ```
55
+
56
+ ### Function Naming
57
+
58
+ ```typescript
59
+ // ✅ GOOD: Verb-noun pattern
60
+ async function fetchMarketData(marketId: string) { }
61
+ function calculateSimilarity(a: number[], b: number[]) { }
62
+ function isValidEmail(email: string): boolean { }
63
+
64
+ // ❌ BAD: Unclear or noun-only
65
+ async function market(id: string) { }
66
+ function similarity(a, b) { }
67
+ function email(e) { }
68
+ ```
69
+
70
+ ### Immutability Pattern (CRITICAL)
71
+
72
+ ```typescript
73
+ // ✅ ALWAYS use spread operator
74
+ const updatedUser = {
75
+ ...user,
76
+ name: 'New Name'
77
+ }
78
+
79
+ const updatedArray = [...items, newItem]
80
+
81
+ // ❌ NEVER mutate directly
82
+ user.name = 'New Name' // BAD
83
+ items.push(newItem) // BAD
84
+ ```
85
+
86
+ ### Error Handling
87
+
88
+ ```typescript
89
+ // ✅ GOOD: Comprehensive error handling
90
+ async function fetchData(url: string) {
91
+ try {
92
+ const response = await fetch(url)
93
+
94
+ if (!response.ok) {
95
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`)
96
+ }
97
+
98
+ return await response.json()
99
+ } catch (error) {
100
+ console.error('Fetch failed:', error)
101
+ throw new Error('Failed to fetch data')
102
+ }
103
+ }
104
+
105
+ // ❌ BAD: No error handling
106
+ async function fetchData(url) {
107
+ const response = await fetch(url)
108
+ return response.json()
109
+ }
110
+ ```
111
+
112
+ ### Async/Await Best Practices
113
+
114
+ ```typescript
115
+ // ✅ GOOD: Parallel execution when possible
116
+ const [users, markets, stats] = await Promise.all([
117
+ fetchUsers(),
118
+ fetchMarkets(),
119
+ fetchStats()
120
+ ])
121
+
122
+ // ❌ BAD: Sequential when unnecessary
123
+ const users = await fetchUsers()
124
+ const markets = await fetchMarkets()
125
+ const stats = await fetchStats()
126
+ ```
127
+
128
+ ### Type Safety
129
+
130
+ ```typescript
131
+ // ✅ GOOD: Proper types
132
+ interface Market {
133
+ id: string
134
+ name: string
135
+ status: 'active' | 'resolved' | 'closed'
136
+ created_at: Date
137
+ }
138
+
139
+ function getMarket(id: string): Promise<Market> {
140
+ // Implementation
141
+ }
142
+
143
+ // ❌ BAD: Using 'any'
144
+ function getMarket(id: any): Promise<any> {
145
+ // Implementation
146
+ }
147
+ ```
148
+
149
+ ## React Best Practices
150
+
151
+ ### Component Structure
152
+
153
+ ```typescript
154
+ // ✅ GOOD: Functional component with types
155
+ interface ButtonProps {
156
+ children: React.ReactNode
157
+ onClick: () => void
158
+ disabled?: boolean
159
+ variant?: 'primary' | 'secondary'
160
+ }
161
+
162
+ export function Button({
163
+ children,
164
+ onClick,
165
+ disabled = false,
166
+ variant = 'primary'
167
+ }: ButtonProps) {
168
+ return (
169
+ <button
170
+ onClick={onClick}
171
+ disabled={disabled}
172
+ className={`btn btn-${variant}`}
173
+ >
174
+ {children}
175
+ </button>
176
+ )
177
+ }
178
+
179
+ // ❌ BAD: No types, unclear structure
180
+ export function Button(props) {
181
+ return <button onClick={props.onClick}>{props.children}</button>
182
+ }
183
+ ```
184
+
185
+ ### Custom Hooks
186
+
187
+ ```typescript
188
+ // ✅ GOOD: Reusable custom hook
189
+ export function useDebounce<T>(value: T, delay: number): T {
190
+ const [debouncedValue, setDebouncedValue] = useState<T>(value)
191
+
192
+ useEffect(() => {
193
+ const handler = setTimeout(() => {
194
+ setDebouncedValue(value)
195
+ }, delay)
196
+
197
+ return () => clearTimeout(handler)
198
+ }, [value, delay])
199
+
200
+ return debouncedValue
201
+ }
202
+
203
+ // Usage
204
+ const debouncedQuery = useDebounce(searchQuery, 500)
205
+ ```
206
+
207
+ ### State Management
208
+
209
+ ```typescript
210
+ // ✅ GOOD: Proper state updates
211
+ const [count, setCount] = useState(0)
212
+
213
+ // Functional update for state based on previous state
214
+ setCount(prev => prev + 1)
215
+
216
+ // ❌ BAD: Direct state reference
217
+ setCount(count + 1) // Can be stale in async scenarios
218
+ ```
219
+
220
+ ### Conditional Rendering
221
+
222
+ ```typescript
223
+ // ✅ GOOD: Clear conditional rendering
224
+ {isLoading && <Spinner />}
225
+ {error && <ErrorMessage error={error} />}
226
+ {data && <DataDisplay data={data} />}
227
+
228
+ // ❌ BAD: Ternary hell
229
+ {isLoading ? <Spinner /> : error ? <ErrorMessage error={error} /> : data ? <DataDisplay data={data} /> : null}
230
+ ```
231
+
232
+ ## API Design Standards
233
+
234
+ ### REST API Conventions
235
+
236
+ ```
237
+ GET /api/markets # List all markets
238
+ GET /api/markets/:id # Get specific market
239
+ POST /api/markets # Create new market
240
+ PUT /api/markets/:id # Update market (full)
241
+ PATCH /api/markets/:id # Update market (partial)
242
+ DELETE /api/markets/:id # Delete market
243
+
244
+ # Query parameters for filtering
245
+ GET /api/markets?status=active&limit=10&offset=0
246
+ ```
247
+
248
+ ### Response Format
249
+
250
+ ```typescript
251
+ // ✅ GOOD: Consistent response structure
252
+ interface ApiResponse<T> {
253
+ success: boolean
254
+ data?: T
255
+ error?: string
256
+ meta?: {
257
+ total: number
258
+ page: number
259
+ limit: number
260
+ }
261
+ }
262
+
263
+ // Success response
264
+ return NextResponse.json({
265
+ success: true,
266
+ data: markets,
267
+ meta: { total: 100, page: 1, limit: 10 }
268
+ })
269
+
270
+ // Error response
271
+ return NextResponse.json({
272
+ success: false,
273
+ error: 'Invalid request'
274
+ }, { status: 400 })
275
+ ```
276
+
277
+ ### Input Validation
278
+
279
+ ```typescript
280
+ import { z } from 'zod'
281
+
282
+ // ✅ GOOD: Schema validation
283
+ const CreateMarketSchema = z.object({
284
+ name: z.string().min(1).max(200),
285
+ description: z.string().min(1).max(2000),
286
+ endDate: z.string().datetime(),
287
+ categories: z.array(z.string()).min(1)
288
+ })
289
+
290
+ export async function POST(request: Request) {
291
+ const body = await request.json()
292
+
293
+ try {
294
+ const validated = CreateMarketSchema.parse(body)
295
+ // Proceed with validated data
296
+ } catch (error) {
297
+ if (error instanceof z.ZodError) {
298
+ return NextResponse.json({
299
+ success: false,
300
+ error: 'Validation failed',
301
+ details: error.errors
302
+ }, { status: 400 })
303
+ }
304
+ }
305
+ }
306
+ ```
307
+
308
+ ## File Organization
309
+
310
+ ### Project Structure
311
+
312
+ ```
313
+ src/
314
+ ├── app/ # Next.js App Router
315
+ │ ├── api/ # API routes
316
+ │ ├── markets/ # Market pages
317
+ │ └── (auth)/ # Auth pages (route groups)
318
+ ├── components/ # React components
319
+ │ ├── ui/ # Generic UI components
320
+ │ ├── forms/ # Form components
321
+ │ └── layouts/ # Layout components
322
+ ├── hooks/ # Custom React hooks
323
+ ├── lib/ # Utilities and configs
324
+ │ ├── api/ # API clients
325
+ │ ├── utils/ # Helper functions
326
+ │ └── constants/ # Constants
327
+ ├── types/ # TypeScript types
328
+ └── styles/ # Global styles
329
+ ```
330
+
331
+ ### File Naming
332
+
333
+ ```
334
+ components/Button.tsx # PascalCase for components
335
+ hooks/useAuth.ts # camelCase with 'use' prefix
336
+ lib/formatDate.ts # camelCase for utilities
337
+ types/market.types.ts # camelCase with .types suffix
338
+ ```
339
+
340
+ ## Comments & Documentation
341
+
342
+ ### When to Comment
343
+
344
+ ```typescript
345
+ // ✅ GOOD: Explain WHY, not WHAT
346
+ // Use exponential backoff to avoid overwhelming the API during outages
347
+ const delay = Math.min(1000 * Math.pow(2, retryCount), 30000)
348
+
349
+ // Deliberately using mutation here for performance with large arrays
350
+ items.push(newItem)
351
+
352
+ // ❌ BAD: Stating the obvious
353
+ // Increment counter by 1
354
+ count++
355
+
356
+ // Set name to user's name
357
+ name = user.name
358
+ ```
359
+
360
+ ### JSDoc for Public APIs
361
+
362
+ ```typescript
363
+ /**
364
+ * Searches markets using semantic similarity.
365
+ *
366
+ * @param query - Natural language search query
367
+ * @param limit - Maximum number of results (default: 10)
368
+ * @returns Array of markets sorted by similarity score
369
+ * @throws {Error} If OpenAI API fails or Redis unavailable
370
+ *
371
+ * @example
372
+ * ```typescript
373
+ * const results = await searchMarkets('election', 5)
374
+ * console.log(results[0].name) // "Trump vs Biden"
375
+ * ```
376
+ */
377
+ export async function searchMarkets(
378
+ query: string,
379
+ limit: number = 10
380
+ ): Promise<Market[]> {
381
+ // Implementation
382
+ }
383
+ ```
384
+
385
+ ## Performance Best Practices
386
+
387
+ ### Memoization
388
+
389
+ ```typescript
390
+ import { useMemo, useCallback } from 'react'
391
+
392
+ // ✅ GOOD: Memoize expensive computations
393
+ const sortedMarkets = useMemo(() => {
394
+ return markets.sort((a, b) => b.volume - a.volume)
395
+ }, [markets])
396
+
397
+ // ✅ GOOD: Memoize callbacks
398
+ const handleSearch = useCallback((query: string) => {
399
+ setSearchQuery(query)
400
+ }, [])
401
+ ```
402
+
403
+ ### Lazy Loading
404
+
405
+ ```typescript
406
+ import { lazy, Suspense } from 'react'
407
+
408
+ // ✅ GOOD: Lazy load heavy components
409
+ const HeavyChart = lazy(() => import('./HeavyChart'))
410
+
411
+ export function Dashboard() {
412
+ return (
413
+ <Suspense fallback={<Spinner />}>
414
+ <HeavyChart />
415
+ </Suspense>
416
+ )
417
+ }
418
+ ```
419
+
420
+ ### Database Queries
421
+
422
+ ```typescript
423
+ // ✅ GOOD: Select only needed columns
424
+ const { data } = await supabase
425
+ .from('markets')
426
+ .select('id, name, status')
427
+ .limit(10)
428
+
429
+ // ❌ BAD: Select everything
430
+ const { data } = await supabase
431
+ .from('markets')
432
+ .select('*')
433
+ ```
434
+
435
+ ## Testing Standards
436
+
437
+ ### Test Structure (AAA Pattern)
438
+
439
+ ```typescript
440
+ test('calculates similarity correctly', () => {
441
+ // Arrange
442
+ const vector1 = [1, 0, 0]
443
+ const vector2 = [0, 1, 0]
444
+
445
+ // Act
446
+ const similarity = calculateCosineSimilarity(vector1, vector2)
447
+
448
+ // Assert
449
+ expect(similarity).toBe(0)
450
+ })
451
+ ```
452
+
453
+ ### Test Naming
454
+
455
+ ```typescript
456
+ // ✅ GOOD: Descriptive test names
457
+ test('returns empty array when no markets match query', () => { })
458
+ test('throws error when OpenAI API key is missing', () => { })
459
+ test('falls back to substring search when Redis unavailable', () => { })
460
+
461
+ // ❌ BAD: Vague test names
462
+ test('works', () => { })
463
+ test('test search', () => { })
464
+ ```
465
+
466
+ ## Code Smell Detection
467
+
468
+ Watch for these anti-patterns:
469
+
470
+ ### 1. Long Functions
471
+ ```typescript
472
+ // ❌ BAD: Function > 50 lines
473
+ function processMarketData() {
474
+ // 100 lines of code
475
+ }
476
+
477
+ // ✅ GOOD: Split into smaller functions
478
+ function processMarketData() {
479
+ const validated = validateData()
480
+ const transformed = transformData(validated)
481
+ return saveData(transformed)
482
+ }
483
+ ```
484
+
485
+ ### 2. Deep Nesting
486
+ ```typescript
487
+ // ❌ BAD: 5+ levels of nesting
488
+ if (user) {
489
+ if (user.isAdmin) {
490
+ if (market) {
491
+ if (market.isActive) {
492
+ if (hasPermission) {
493
+ // Do something
494
+ }
495
+ }
496
+ }
497
+ }
498
+ }
499
+
500
+ // ✅ GOOD: Early returns
501
+ if (!user) return
502
+ if (!user.isAdmin) return
503
+ if (!market) return
504
+ if (!market.isActive) return
505
+ if (!hasPermission) return
506
+
507
+ // Do something
508
+ ```
509
+
510
+ ### 3. Magic Numbers
511
+ ```typescript
512
+ // ❌ BAD: Unexplained numbers
513
+ if (retryCount > 3) { }
514
+ setTimeout(callback, 500)
515
+
516
+ // ✅ GOOD: Named constants
517
+ const MAX_RETRIES = 3
518
+ const DEBOUNCE_DELAY_MS = 500
519
+
520
+ if (retryCount > MAX_RETRIES) { }
521
+ setTimeout(callback, DEBOUNCE_DELAY_MS)
522
+ ```
523
+
524
+ **Remember**: Code quality is not negotiable. Clear, maintainable code enables rapid development and confident refactoring.
@@ -0,0 +1,83 @@
1
+ # Deluge Coding Standards
2
+
3
+ ## Naming Conventions
4
+ - Variables: camelCase (e.g., `recordId`, `customerName`)
5
+ - Functions: verb_noun pattern (e.g., `get_customer_details`, `update_invoice_status`)
6
+ - Form fields: Title_Case_With_Underscores (e.g., `Customer_Name`, `Invoice_Total`)
7
+ - Connections: lowercase-with-hyphens (e.g., `zoho-crm-connection`)
8
+
9
+ ## Structure
10
+ - Maximum function length: 100 statements (extract sub-functions for longer)
11
+ - One function per workflow action where possible
12
+ - Group related functions in the same workflow
13
+ - Use standalone functions for reusable logic
14
+
15
+ ## Error Handling Pattern
16
+ ```deluge
17
+ // Standard function wrapper
18
+ response = Map();
19
+ try {
20
+ // Business logic here
21
+ result = performOperation();
22
+
23
+ if (result == null) {
24
+ response.put("status", "error");
25
+ response.put("message", "Operation returned null");
26
+ return response;
27
+ }
28
+
29
+ response.put("status", "success");
30
+ response.put("data", result);
31
+ } catch (e) {
32
+ response.put("status", "error");
33
+ response.put("message", e.toString());
34
+ // Log to audit form if compliance mode active
35
+ }
36
+ return response;
37
+ ```
38
+
39
+ ## API Call Pattern
40
+ ```deluge
41
+ // Standard invokeUrl pattern
42
+ headers = Map();
43
+ headers.put("Content-Type", "application/json");
44
+
45
+ try {
46
+ apiResponse = invokeUrl [
47
+ url: endpoint
48
+ type: POST
49
+ headers: headers
50
+ body: payload.toString()
51
+ connection: "connection-name"
52
+ ];
53
+
54
+ responseCode = apiResponse.get("status_code");
55
+ if (responseCode != 200 && responseCode != 201) {
56
+ info "API Error: " + apiResponse;
57
+ // Handle error
58
+ }
59
+ } catch (e) {
60
+ info "invokeUrl failed: " + e;
61
+ // 40-second timeout - handle gracefully
62
+ }
63
+ ```
64
+
65
+ ## Performance Rules
66
+ - Never use getRecords without criteria (limit results)
67
+ - Use updateRecords (batch) instead of loops with updateRecord
68
+ - Cache connection responses when called multiple times
69
+ - Avoid Deluge in report formulas (causes N+1 queries)
70
+ - Count loop iterations: 5000 total statement limit
71
+
72
+ ## Security Rules
73
+ - Never hardcode API keys, tokens, or org IDs
74
+ - Use Zoho Connections for OAuth
75
+ - Sanitize all user inputs before queries
76
+ - Don't expose internal record IDs in responses
77
+ - Log all sensitive operations to audit form
78
+
79
+ ## Comments
80
+ - Header comment on every function: purpose, parameters, returns
81
+ - Inline comments for complex logic only
82
+ - TODO comments for known limitations
83
+ - No commented-out code in production
@@ -0,0 +1,28 @@
1
+ ---
2
+ name: compliance-patterns
3
+ description: HIPAA, SOC2, and PCI-DSS compliance patterns for Zoho and GCP applications. Activated when compliance mode is set or data handling changes are made.
4
+ version: 1.0.0
5
+ status: active
6
+ introduced: 1.0.0
7
+ lastUpdated: 2026-01-25
8
+ activation: Compliance mode active, data handling changes, audit requests, security reviews
9
+ ---
10
+
11
+ # Compliance Patterns
12
+
13
+ > Last reviewed: 2026-01
14
+
15
+ Regulatory compliance implementation patterns for CloudStream clients.
16
+
17
+ ## Active Modes
18
+ Set per-client in their .claude/CLAUDE.md:
19
+ - `hipaa` - Healthcare (ePHI handling, BAA, audit archival)
20
+ - `soc2` - Enterprise (audit logging, change management, access controls)
21
+ - `pci-dss` - Financial (Zoho Checkout only, tokenization, SAQ-A)
22
+ - `standard` - Non-regulated
23
+
24
+ ## Critical Platform Limitations
25
+ - Creator audit data: Retained only 1 year (implement archival)
26
+ - Deluge execution: NOT automatically logged (custom logging required)
27
+ - Change management: NOT native in Creator (custom workflow needed)
28
+ - Zoho Checkout: Hosted pages ONLY for PCI compliance