brain-dev 2.2.0 → 2.2.1

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.
@@ -5,7 +5,7 @@ const path = require('node:path');
5
5
  const { readState, writeState, atomicWriteSync } = require('../state.cjs');
6
6
  const { parseRoadmap } = require('../roadmap.cjs');
7
7
  const { loadTemplate, interpolate } = require('../templates.cjs');
8
- const { output, error, success, pipelineGate } = require('../core.cjs');
8
+ const { output, error, success, prefix, pipelineGate } = require('../core.cjs');
9
9
  const { generateExpertise } = require('../stack-expert.cjs');
10
10
 
11
11
  /**
@@ -230,8 +230,11 @@ function handleSave(args, brainDir, state) {
230
230
  nextAction: '/brain:plan'
231
231
  };
232
232
 
233
- success("Context captured.");
234
- output(result, pipelineGate(`npx brain-dev plan --phase ${phaseNumber}`));
233
+ const humanLines = [
234
+ prefix('Context captured.'),
235
+ pipelineGate(`npx brain-dev plan --phase ${phaseNumber}`)
236
+ ].join('\n');
237
+ output(result, humanLines);
235
238
 
236
239
  return result;
237
240
  }
@@ -504,12 +504,12 @@ function handleLogRecovery(args, logRecoveryIdx, brainDir, state) {
504
504
  ? parseInt(args[phaseIdx + 1], 10)
505
505
  : state.phase.current;
506
506
 
507
- logEvent(brainDir, phaseNumber, event);
508
-
509
507
  if (!event || typeof event !== 'object') {
510
508
  error('--log-recovery requires a JSON object, not null/primitive');
511
509
  return { error: 'invalid-json' };
512
510
  }
511
+
512
+ logEvent(brainDir, phaseNumber, event);
513
513
  output({ action: 'recovery-logged', event }, `[brain] Recovery event logged: ${event.type || 'unknown'}`);
514
514
  return { action: 'recovery-logged', event };
515
515
  }
@@ -30,7 +30,7 @@ const STACK_PATTERNS = {
30
30
  antiPatterns: 'N+1 queries (use eager loading with/load), fat controllers (extract to Services/Actions), raw SQL in controllers, logic in models (use Services), not using Form Requests for validation',
31
31
  testing: 'Feature tests in tests/Feature, Unit tests in tests/Unit, use RefreshDatabase trait, factories for test data',
32
32
  migration: 'php artisan make:migration create_X_table, php artisan migrate, php artisan migrate:rollback',
33
- commonBugs: 'N+1 query on relationships (use ->with()), mass assignment vulnerability (use $fillable), missing foreign key constraints, not using transactions for multi-table writes, queue job serialization with deleted models',
33
+ commonBugs: ['N+1 query on relationships (use ->with())', 'Mass assignment vulnerability (use $fillable)', 'Missing foreign key constraints', 'Not using transactions for multi-table writes', 'Queue job serialization with deleted models'],
34
34
  verificationRules: ['Migrations exist for all new models', '.env.example has all required keys', 'Routes registered in routes/api.php or routes/web.php', 'Form Requests validate all user input', 'API Resources used for JSON responses', 'Factories exist for all models'],
35
35
  planningHints: ['Plan migration tasks BEFORE model/controller tasks', 'Each model needs: migration, model, factory, controller, request, resource, test', 'Group related migrations in same plan', 'Include seeder tasks for test data'],
36
36
  testExamples: {
@@ -44,7 +44,7 @@ const STACK_PATTERNS = {
44
44
  patterns: 'Server Components by default, use client directive for interactivity, Server Actions for mutations, Route Handlers for API, Metadata API for SEO, Suspense for loading states',
45
45
  antiPatterns: 'useEffect for data fetching (use Server Components), client-side state for server data, large client bundles, not using loading.tsx/error.tsx, fetching in client when server component suffices',
46
46
  testing: 'Jest + React Testing Library, or Vitest, test in __tests__/ or *.test.tsx',
47
- commonBugs: 'Hydration mismatch (server vs client render difference), importing server-only code in client components, not handling loading/error states, stale cache in fetch(), middleware running on every request',
47
+ commonBugs: ['Hydration mismatch (server vs client render difference)', 'Importing server-only code in client components', 'Not handling loading/error states', 'Stale cache in fetch()', 'Middleware running on every request'],
48
48
  verificationRules: ['Page components exist in app/ directory', 'loading.tsx exists for async pages', 'error.tsx exists for error boundaries', 'API Route Handlers use correct HTTP method exports', 'Client components have "use client" directive', 'Metadata exported for SEO pages'],
49
49
  planningHints: ['Plan layout components before page components', 'Server Components first, add "use client" only when needed', 'Plan API Route Handlers separate from page components', 'Include loading.tsx and error.tsx for each route group'],
50
50
  testExamples: {
@@ -58,7 +58,7 @@ const STACK_PATTERNS = {
58
58
  patterns: 'Functional components + hooks, React Navigation/Expo Router, AsyncStorage, StyleSheet.create, Platform.select for platform-specific code',
59
59
  antiPatterns: 'Inline styles (use StyleSheet.create), heavy computation on JS thread, large FlatList without getItemLayout/keyExtractor, not using Platform.OS for platform checks, synchronous storage calls',
60
60
  testing: 'Jest + React Native Testing Library, detox for E2E',
61
- commonBugs: 'Platform-specific rendering not tested on both OS, keyboard covering inputs (use KeyboardAvoidingView), memory leaks from unsubscribed listeners, navigation state persistence issues, StatusBar behavior differences iOS vs Android',
61
+ commonBugs: ['Platform-specific rendering not tested on both OS', 'Keyboard covering inputs (use KeyboardAvoidingView)', 'Memory leaks from unsubscribed listeners', 'Navigation state persistence issues', 'StatusBar behavior differences iOS vs Android'],
62
62
  verificationRules: ['Platform-specific code uses Platform.OS or Platform.select', 'FlatList has keyExtractor and getItemLayout', 'Navigation screens registered in navigator', 'Assets imported correctly (require() for local)', 'No web-only APIs used (document, window)'],
63
63
  planningHints: ['Plan shared components before screen-specific ones', 'Consider both iOS and Android in task descriptions', 'Plan navigation structure before individual screens', 'Include platform-specific testing tasks'],
64
64
  testExamples: {
@@ -72,7 +72,7 @@ const STACK_PATTERNS = {
72
72
  patterns: 'Router middleware chain, error handling middleware, async/await with express-async-errors, request validation with Joi/Zod, controller-service separation',
73
73
  antiPatterns: 'Callback hell, no error middleware, sync operations blocking event loop, not validating request body, try/catch in every route (use express-async-errors)',
74
74
  testing: 'Jest/Mocha + supertest for HTTP assertions',
75
- commonBugs: 'Unhandled promise rejections crashing server, missing error middleware (must have 4 params), route order matters (specific before generic), CORS misconfiguration, not closing DB connections on shutdown',
75
+ commonBugs: ['Unhandled promise rejections crashing server', 'Missing error middleware (must have 4 params: err, req, res, next)', 'Route order matters (specific before generic)', 'CORS misconfiguration', 'Not closing DB connections on shutdown'],
76
76
  verificationRules: ['Error handling middleware exists (4 params: err, req, res, next)', 'Routes validate input before processing', 'Async handlers properly catch errors', 'CORS configured for production origins', 'Graceful shutdown handler exists'],
77
77
  planningHints: ['Plan middleware before routes', 'Error handling middleware is a separate task at the end', 'Group related routes in same router file', 'Plan validation schemas alongside route handlers'],
78
78
  testExamples: {
@@ -87,7 +87,7 @@ const STACK_PATTERNS = {
87
87
  antiPatterns: 'N+1 queries (use select_related/prefetch_related), logic in views (use services), not using serializers for validation, raw SQL without parameterization',
88
88
  testing: 'pytest-django or TestCase, factory_boy for fixtures',
89
89
  migration: 'python manage.py makemigrations, python manage.py migrate, python manage.py migrate <app> zero (rollback)',
90
- commonBugs: 'Circular imports between apps, migration conflicts in teams, not using select_related causing N+1, signals firing during tests unexpectedly, timezone-naive datetime comparisons',
90
+ commonBugs: ['Circular imports between apps', 'Migration conflicts in teams', 'Not using select_related causing N+1', 'Signals firing during tests unexpectedly', 'Timezone-naive datetime comparisons'],
91
91
  verificationRules: ['Migrations created for all model changes', 'URLs registered in app urls.py and included in root urls.py', 'Admin registered for all models', 'Serializers validate all user input', 'Permissions set on views'],
92
92
  planningHints: ['Plan models and migrations before views', 'Each app should be self-contained', 'Plan serializers alongside models', 'Include admin registration tasks', 'Plan management commands for data operations'],
93
93
  testExamples: {
@@ -137,7 +137,7 @@ const STACK_PATTERNS = {
137
137
  antiPatterns: 'Sync database calls in async endpoints, no Pydantic validation, global mutable state, not using Depends() for shared logic, blocking the event loop',
138
138
  testing: 'pytest + httpx AsyncClient',
139
139
  migration: 'alembic init, alembic revision --autogenerate -m "description", alembic upgrade head',
140
- commonBugs: 'Mixing sync/async database drivers, Pydantic v2 model_validator vs v1 validator, circular imports in routers, not closing DB connections in lifespan, CORS middleware order matters',
140
+ commonBugs: ['Mixing sync/async database drivers', 'Pydantic v2 model_validator vs v1 validator', 'Circular imports in routers', 'Not closing DB connections in lifespan', 'CORS middleware order matters'],
141
141
  verificationRules: ['Pydantic schemas exist for all request/response models', 'Dependencies use Depends() injection', 'Async endpoints use async database driver', 'Alembic migrations exist for schema changes', 'Error handlers return consistent JSON format'],
142
142
  planningHints: ['Plan Pydantic schemas before routers', 'Plan database models with Alembic migrations', 'Group related endpoints in same router', 'Plan dependency injection for shared resources (DB, auth)'],
143
143
  testExamples: {
@@ -318,7 +318,8 @@ function generateExpertise(brainDir, role = 'general') {
318
318
  if (fwInfo.commonBugs) {
319
319
  sections.push('');
320
320
  sections.push(`### Common ${framework} Bugs to Avoid`);
321
- for (const [i, bug] of fwInfo.commonBugs.split(', ').entries()) {
321
+ const bugs = Array.isArray(fwInfo.commonBugs) ? fwInfo.commonBugs : fwInfo.commonBugs.split(', ');
322
+ for (const [i, bug] of bugs.entries()) {
322
323
  sections.push(`${i + 1}. ${bug}`);
323
324
  }
324
325
  }
@@ -0,0 +1,30 @@
1
+ ## Next.js-Specific Planning
2
+
3
+ ### Task Ordering
4
+ 1. **Layouts first**: Create layout.tsx before page components
5
+ 2. **Server Components first**: Default to Server Components, add "use client" only when needed
6
+ 3. **API Routes separate**: Plan Route Handlers as distinct tasks from pages
7
+ 4. **Error boundaries**: Include loading.tsx and error.tsx for each route group
8
+
9
+ ### Standard Feature Pattern
10
+ For each new route/feature, plan these tasks:
11
+ 1. Layout component (if new route group)
12
+ 2. Page component (Server Component by default)
13
+ 3. Loading state (loading.tsx)
14
+ 4. Error boundary (error.tsx)
15
+ 5. API Route Handler (if needed)
16
+ 6. Client components (only for interactivity)
17
+ 7. Tests
18
+
19
+ ### must_haves Template for Next.js
20
+ ```yaml
21
+ truths:
22
+ - "Page renders correctly as Server Component"
23
+ - "loading.tsx shows skeleton/spinner during data fetch"
24
+ - "error.tsx catches and displays errors gracefully"
25
+ - "No useEffect used for data fetching (Server Component handles it)"
26
+ artifacts:
27
+ - path: "app/{route}/page.tsx"
28
+ - path: "app/{route}/loading.tsx"
29
+ - path: "app/{route}/error.tsx"
30
+ ```
@@ -0,0 +1,27 @@
1
+ ## React Native-Specific Planning
2
+
3
+ ### Task Ordering
4
+ 1. **Navigation first**: Define navigation structure before screens
5
+ 2. **Shared components**: Plan reusable components before screen-specific ones
6
+ 3. **Platform handling**: Consider both iOS and Android in each task
7
+ 4. **Performance**: Plan FlatList optimization tasks alongside data display tasks
8
+
9
+ ### Standard Feature Pattern
10
+ For each new screen/feature, plan these tasks:
11
+ 1. Navigation registration (add to navigator)
12
+ 2. Screen component with StyleSheet
13
+ 3. Shared sub-components (if needed)
14
+ 4. Platform-specific adjustments (Platform.OS checks)
15
+ 5. Tests (component + interaction)
16
+
17
+ ### must_haves Template for React Native
18
+ ```yaml
19
+ truths:
20
+ - "Screen renders correctly on both iOS and Android"
21
+ - "Navigation to/from screen works with correct params"
22
+ - "StyleSheet.create used (no inline styles)"
23
+ - "FlatList has keyExtractor for list screens"
24
+ artifacts:
25
+ - path: "app/{screen}.tsx or src/screens/{Screen}.tsx"
26
+ - path: "components/{Component}.tsx"
27
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brain-dev",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "AI-powered development workflow orchestrator",
5
5
  "author": "halilcosdu",
6
6
  "license": "MIT",