@@ -22,14 +22,20 @@ import { readFileSync, existsSync, mkdirSync } from 'fs';
2222import { join , dirname } from 'path' ;
2323import { execSync } from 'child_process' ;
2424import { FrameManager , FrameType } from '../../core/context/index.js' ;
25- import {
26- LinearTaskManager ,
25+ import { logger } from '../../core/monitoring/logger.js' ;
26+ import { isFeatureEnabled } from '../../core/config/feature-flags.js' ;
27+
28+ // Linear types - imported dynamically when needed
29+ type LinearTaskManager =
30+ import ( '../../features/tasks/linear-task-manager.js' ) . LinearTaskManager ;
31+ type LinearAuthManager = import ( '../linear/auth.js' ) . LinearAuthManager ;
32+ type LinearSyncEngine = import ( '../linear/sync.js' ) . LinearSyncEngine ;
33+
34+ // Re-export task types for handlers (these are just enums/types, not runtime deps)
35+ export {
2736 TaskPriority ,
2837 TaskStatus ,
2938} from '../../features/tasks/linear-task-manager.js' ;
30- import { LinearAuthManager , LinearOAuthSetup } from '../linear/auth.js' ;
31- import { LinearSyncEngine , DEFAULT_SYNC_CONFIG } from '../linear/sync.js' ;
32- import { logger } from '../../core/monitoring/logger.js' ;
3339import { BrowserMCPIntegration } from '../../features/browser/browser-mcp.js' ;
3440import { TraceDetector } from '../../core/trace/trace-detector.js' ;
3541import { ToolCall , Trace } from '../../core/trace/types.js' ;
@@ -59,9 +65,9 @@ class LocalStackMemoryMCP {
5965 private db : Database . Database ;
6066 private projectRoot : string ;
6167 private frameManager : FrameManager ;
62- private taskStore : LinearTaskManager ;
63- private linearAuthManager : LinearAuthManager ;
64- private linearSync : LinearSyncEngine ;
68+ private taskStore : LinearTaskManager | null = null ;
69+ private linearAuthManager : LinearAuthManager | null = null ;
70+ private linearSync : LinearSyncEngine | null = null ;
6571 private projectId : string ;
6672 private contexts : Map < string , any > = new Map ( ) ;
6773 private browserMCP : BrowserMCPIntegration ;
@@ -88,16 +94,8 @@ class LocalStackMemoryMCP {
8894 // Initialize frame manager
8995 this . frameManager = new FrameManager ( this . db , this . projectId ) ;
9096
91- // Initialize task store
92- this . taskStore = new LinearTaskManager ( this . projectRoot , this . db ) ;
93-
94- // Initialize Linear integration
95- this . linearAuthManager = new LinearAuthManager ( this . projectRoot ) ;
96- this . linearSync = new LinearSyncEngine (
97- this . taskStore ,
98- this . linearAuthManager ,
99- DEFAULT_SYNC_CONFIG
100- ) ;
97+ // Initialize Linear integration (optional - lazy loaded)
98+ this . initLinearIfEnabled ( ) ;
10199
102100 // Initialize MCP server
103101 this . server = new Server (
@@ -161,6 +159,36 @@ class LocalStackMemoryMCP {
161159 return process . cwd ( ) ;
162160 }
163161
162+ /**
163+ * Initialize Linear integration if enabled and credentials available
164+ */
165+ private async initLinearIfEnabled ( ) : Promise < void > {
166+ if ( ! isFeatureEnabled ( 'linear' ) ) {
167+ logger . info ( 'Linear integration disabled (no API key or LOCAL mode)' ) ;
168+ return ;
169+ }
170+
171+ try {
172+ const { LinearTaskManager } =
173+ await import ( '../../features/tasks/linear-task-manager.js' ) ;
174+ const { LinearAuthManager } = await import ( '../linear/auth.js' ) ;
175+ const { LinearSyncEngine, DEFAULT_SYNC_CONFIG } =
176+ await import ( '../linear/sync.js' ) ;
177+
178+ this . taskStore = new LinearTaskManager ( this . projectRoot , this . db ) ;
179+ this . linearAuthManager = new LinearAuthManager ( this . projectRoot ) ;
180+ this . linearSync = new LinearSyncEngine (
181+ this . taskStore ,
182+ this . linearAuthManager ,
183+ DEFAULT_SYNC_CONFIG
184+ ) ;
185+
186+ logger . info ( 'Linear integration initialized' ) ;
187+ } catch ( error ) {
188+ logger . warn ( 'Failed to initialize Linear integration' , { error } ) ;
189+ }
190+ }
191+
164192 private initDB ( ) {
165193 // Note: Don't create frames table here - FrameManager handles the schema
166194 // with the full run_id, project_id, parent_frame_id columns
0 commit comments