@stackmemoryai/stackmemory 0.5.28 → 0.5.30

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 (48) hide show
  1. package/README.md +37 -16
  2. package/dist/cli/claude-sm.js +17 -5
  3. package/dist/cli/claude-sm.js.map +2 -2
  4. package/dist/core/database/batch-operations.js +29 -4
  5. package/dist/core/database/batch-operations.js.map +2 -2
  6. package/dist/core/database/connection-pool.js +13 -2
  7. package/dist/core/database/connection-pool.js.map +2 -2
  8. package/dist/core/database/migration-manager.js +130 -34
  9. package/dist/core/database/migration-manager.js.map +2 -2
  10. package/dist/core/database/paradedb-adapter.js +23 -7
  11. package/dist/core/database/paradedb-adapter.js.map +2 -2
  12. package/dist/core/database/query-router.js +8 -3
  13. package/dist/core/database/query-router.js.map +2 -2
  14. package/dist/core/database/sqlite-adapter.js +152 -33
  15. package/dist/core/database/sqlite-adapter.js.map +2 -2
  16. package/dist/hooks/session-summary.js +23 -2
  17. package/dist/hooks/session-summary.js.map +2 -2
  18. package/dist/hooks/sms-notify.js +47 -13
  19. package/dist/hooks/sms-notify.js.map +2 -2
  20. package/dist/integrations/linear/auth.js +34 -20
  21. package/dist/integrations/linear/auth.js.map +2 -2
  22. package/dist/integrations/linear/auto-sync.js +18 -8
  23. package/dist/integrations/linear/auto-sync.js.map +2 -2
  24. package/dist/integrations/linear/client.js +42 -9
  25. package/dist/integrations/linear/client.js.map +2 -2
  26. package/dist/integrations/linear/migration.js +94 -36
  27. package/dist/integrations/linear/migration.js.map +2 -2
  28. package/dist/integrations/linear/oauth-server.js +77 -34
  29. package/dist/integrations/linear/oauth-server.js.map +2 -2
  30. package/dist/integrations/linear/rest-client.js +13 -3
  31. package/dist/integrations/linear/rest-client.js.map +2 -2
  32. package/dist/integrations/linear/sync-service.js +18 -15
  33. package/dist/integrations/linear/sync-service.js.map +2 -2
  34. package/dist/integrations/linear/sync.js +12 -4
  35. package/dist/integrations/linear/sync.js.map +2 -2
  36. package/dist/integrations/linear/unified-sync.js +33 -8
  37. package/dist/integrations/linear/unified-sync.js.map +2 -2
  38. package/dist/integrations/linear/webhook-handler.js +5 -1
  39. package/dist/integrations/linear/webhook-handler.js.map +2 -2
  40. package/dist/integrations/linear/webhook-server.js +7 -7
  41. package/dist/integrations/linear/webhook-server.js.map +2 -2
  42. package/dist/integrations/linear/webhook.js +9 -2
  43. package/dist/integrations/linear/webhook.js.map +2 -2
  44. package/dist/integrations/mcp/schemas.js +147 -0
  45. package/dist/integrations/mcp/schemas.js.map +7 -0
  46. package/dist/integrations/mcp/server.js +19 -3
  47. package/dist/integrations/mcp/server.js.map +2 -2
  48. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/integrations/linear/auto-sync.ts"],
4
- "sourcesContent": ["/**\n * Linear Auto-Sync Service\n * Background service for automatic bidirectional synchronization\n */\n\nimport { logger } from '../../core/monitoring/logger.js';\nimport { LinearTaskManager } from '../../features/tasks/linear-task-manager.js';\nimport { LinearAuthManager } from './auth.js';\nimport { LinearSyncEngine, DEFAULT_SYNC_CONFIG, SyncConfig } from './sync.js';\nimport { LinearConfigManager } from './config.js';\nimport Database from 'better-sqlite3';\nimport { join } from 'path';\nimport { existsSync } from 'fs';\n\nexport interface AutoSyncConfig extends SyncConfig {\n enabled: boolean;\n interval: number; // minutes\n retryAttempts: number;\n retryDelay: number; // milliseconds\n quietHours?: {\n start: number; // hour 0-23\n end: number; // hour 0-23\n };\n}\n\nexport class LinearAutoSyncService {\n private config: AutoSyncConfig;\n private projectRoot: string;\n private configManager: LinearConfigManager;\n private syncEngine?: LinearSyncEngine;\n private intervalId?: NodeJS.Timeout;\n private isRunning = false;\n private lastSyncTime = 0;\n private retryCount = 0;\n\n constructor(projectRoot: string, config?: Partial<AutoSyncConfig>) {\n this.projectRoot = projectRoot;\n this.configManager = new LinearConfigManager(projectRoot);\n\n // Load persisted config or use defaults\n const persistedConfig = this.configManager.loadConfig();\n const baseConfig = persistedConfig\n ? this.configManager.toAutoSyncConfig(persistedConfig)\n : {\n ...DEFAULT_SYNC_CONFIG,\n enabled: true,\n interval: 5,\n retryAttempts: 3,\n retryDelay: 30000,\n autoSync: true,\n direction: 'bidirectional' as const,\n conflictResolution: 'newest_wins' as const,\n quietHours: { start: 22, end: 7 },\n };\n\n this.config = { ...baseConfig, ...config };\n\n // Save any new config updates\n if (config && Object.keys(config).length > 0) {\n this.configManager.saveConfig(config);\n }\n }\n\n /**\n * Start the auto-sync service\n */\n async start(): Promise<void> {\n if (this.isRunning) {\n logger.warn('Linear auto-sync service is already running');\n return;\n }\n\n try {\n // Verify Linear integration is configured\n const authManager = new LinearAuthManager(this.projectRoot);\n if (!authManager.isConfigured()) {\n throw new Error(\n 'Linear integration not configured. Run \"stackmemory linear setup\" first.'\n );\n }\n\n // Initialize sync engine\n const dbPath = join(this.projectRoot, '.stackmemory', 'context.db');\n if (!existsSync(dbPath)) {\n throw new Error(\n 'StackMemory not initialized. Run \"stackmemory init\" first.'\n );\n }\n\n const db = new Database(dbPath);\n const taskStore = new LinearTaskManager(this.projectRoot, db);\n\n this.syncEngine = new LinearSyncEngine(\n taskStore,\n authManager,\n this.config\n );\n\n // Test connection before starting\n const token = await authManager.getValidToken();\n if (!token) {\n throw new Error(\n 'Unable to get valid Linear token. Check authentication.'\n );\n }\n\n this.isRunning = true;\n this.scheduleNextSync();\n\n logger.info('Linear auto-sync service started', {\n interval: this.config.interval,\n direction: this.config.direction,\n conflictResolution: this.config.conflictResolution,\n });\n\n // Perform initial sync\n this.performSync();\n } catch (error: unknown) {\n logger.error('Failed to start Linear auto-sync service:', error as Error);\n throw error;\n }\n }\n\n /**\n * Stop the auto-sync service\n */\n stop(): void {\n if (this.intervalId) {\n clearTimeout(this.intervalId);\n this.intervalId = undefined;\n }\n\n this.isRunning = false;\n logger.info('Linear auto-sync service stopped');\n }\n\n /**\n * Get service status\n */\n getStatus(): {\n running: boolean;\n lastSyncTime: number;\n nextSyncTime?: number;\n retryCount: number;\n config: AutoSyncConfig;\n } {\n const nextSyncTime = this.intervalId\n ? this.lastSyncTime + this.config.interval * 60 * 1000\n : undefined;\n\n return {\n running: this.isRunning,\n lastSyncTime: this.lastSyncTime,\n nextSyncTime,\n retryCount: this.retryCount,\n config: this.config,\n };\n }\n\n /**\n * Update configuration\n */\n updateConfig(newConfig: Partial<AutoSyncConfig>): void {\n this.config = { ...this.config, ...newConfig };\n\n if (this.isRunning) {\n // Restart with new config\n this.stop();\n this.start();\n }\n\n logger.info('Linear auto-sync config updated', newConfig);\n }\n\n /**\n * Force immediate sync\n */\n async forceSync(): Promise<void> {\n if (!this.syncEngine) {\n throw new Error('Sync engine not initialized');\n }\n\n logger.info('Forcing immediate Linear sync');\n await this.performSync();\n }\n\n /**\n * Schedule next sync based on configuration\n */\n private scheduleNextSync(): void {\n if (!this.isRunning) return;\n\n const delay = this.config.interval * 60 * 1000; // Convert minutes to milliseconds\n\n this.intervalId = setTimeout(() => {\n if (this.isRunning) {\n this.performSync();\n }\n }, delay);\n }\n\n /**\n * Perform synchronization with error handling and retries\n */\n private async performSync(): Promise<void> {\n if (!this.syncEngine) {\n logger.error('Sync engine not available');\n return;\n }\n\n // Check quiet hours\n if (this.isInQuietHours()) {\n logger.debug('Skipping sync during quiet hours');\n this.scheduleNextSync();\n return;\n }\n\n try {\n logger.debug('Starting Linear auto-sync');\n\n const result = await this.syncEngine.sync();\n\n if (result.success) {\n this.lastSyncTime = Date.now();\n this.retryCount = 0;\n\n // Log sync results\n const hasChanges =\n result.synced.toLinear > 0 ||\n result.synced.fromLinear > 0 ||\n result.synced.updated > 0;\n\n if (hasChanges) {\n logger.info('Linear auto-sync completed with changes', {\n toLinear: result.synced.toLinear,\n fromLinear: result.synced.fromLinear,\n updated: result.synced.updated,\n conflicts: result.conflicts.length,\n });\n } else {\n logger.debug('Linear auto-sync completed - no changes');\n }\n\n // Handle conflicts\n if (result.conflicts.length > 0) {\n logger.warn('Linear sync conflicts detected', {\n count: result.conflicts.length,\n conflicts: result.conflicts.map((c) => ({\n taskId: c.taskId,\n reason: c.reason,\n })),\n });\n }\n } else {\n throw new Error(`Sync failed: ${result.errors.join(', ')}`);\n }\n } catch (error: unknown) {\n logger.error('Linear auto-sync failed:', error as Error);\n\n this.retryCount++;\n\n if (this.retryCount <= this.config.retryAttempts) {\n logger.info(\n `Retrying Linear sync in ${this.config.retryDelay / 1000}s (attempt ${this.retryCount}/${this.config.retryAttempts})`\n );\n\n // Schedule retry\n setTimeout(() => {\n if (this.isRunning) {\n this.performSync();\n }\n }, this.config.retryDelay);\n\n return; // Don't schedule next sync yet\n } else {\n logger.error(\n `Linear auto-sync failed after ${this.config.retryAttempts} attempts, skipping until next interval`\n );\n this.retryCount = 0;\n }\n }\n\n // Schedule next sync\n this.scheduleNextSync();\n }\n\n /**\n * Check if current time is within quiet hours\n */\n private isInQuietHours(): boolean {\n if (!this.config.quietHours) return false;\n\n const now = new Date();\n const currentHour = now.getHours();\n const { start, end } = this.config.quietHours;\n\n if (start < end) {\n // Quiet hours within same day (e.g., 22:00 - 07:00 next day)\n return currentHour >= start || currentHour < end;\n } else {\n // Quiet hours span midnight (e.g., 10:00 - 18:00)\n return currentHour >= start && currentHour < end;\n }\n }\n}\n\n/**\n * Global auto-sync service instance\n */\nlet autoSyncService: LinearAutoSyncService | null = null;\n\n/**\n * Initialize global auto-sync service\n */\nexport function initializeAutoSync(\n projectRoot: string,\n config?: Partial<AutoSyncConfig>\n): LinearAutoSyncService {\n if (autoSyncService) {\n autoSyncService.stop();\n }\n\n autoSyncService = new LinearAutoSyncService(projectRoot, config);\n return autoSyncService;\n}\n\n/**\n * Get global auto-sync service\n */\nexport function getAutoSyncService(): LinearAutoSyncService | null {\n return autoSyncService;\n}\n\n/**\n * Stop global auto-sync service\n */\nexport function stopAutoSync(): void {\n if (autoSyncService) {\n autoSyncService.stop();\n autoSyncService = null;\n }\n}\n"],
5
- "mappings": ";;;;AAKA,SAAS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oBAAgB,KAAK;AACrB,sBAAkB;AAAA,EACpB;AACF;",
4
+ "sourcesContent": ["/**\n * Linear Auto-Sync Service\n * Background service for automatic bidirectional synchronization\n */\n\nimport { logger } from '../../core/monitoring/logger.js';\nimport { LinearTaskManager } from '../../features/tasks/linear-task-manager.js';\nimport { LinearAuthManager } from './auth.js';\nimport { LinearSyncEngine, DEFAULT_SYNC_CONFIG, SyncConfig } from './sync.js';\nimport { LinearConfigManager } from './config.js';\nimport { IntegrationError, ErrorCode } from '../../core/errors/index.js';\nimport Database from 'better-sqlite3';\nimport { join } from 'path';\nimport { existsSync } from 'fs';\n\nexport interface AutoSyncConfig extends SyncConfig {\n enabled: boolean;\n interval: number; // minutes\n retryAttempts: number;\n retryDelay: number; // milliseconds\n quietHours?: {\n start: number; // hour 0-23\n end: number; // hour 0-23\n };\n}\n\nexport class LinearAutoSyncService {\n private config: AutoSyncConfig;\n private projectRoot: string;\n private configManager: LinearConfigManager;\n private syncEngine?: LinearSyncEngine;\n private intervalId?: NodeJS.Timeout;\n private isRunning = false;\n private lastSyncTime = 0;\n private retryCount = 0;\n\n constructor(projectRoot: string, config?: Partial<AutoSyncConfig>) {\n this.projectRoot = projectRoot;\n this.configManager = new LinearConfigManager(projectRoot);\n\n // Load persisted config or use defaults\n const persistedConfig = this.configManager.loadConfig();\n const baseConfig = persistedConfig\n ? this.configManager.toAutoSyncConfig(persistedConfig)\n : {\n ...DEFAULT_SYNC_CONFIG,\n enabled: true,\n interval: 5,\n retryAttempts: 3,\n retryDelay: 30000,\n autoSync: true,\n direction: 'bidirectional' as const,\n conflictResolution: 'newest_wins' as const,\n quietHours: { start: 22, end: 7 },\n };\n\n this.config = { ...baseConfig, ...config };\n\n // Save any new config updates\n if (config && Object.keys(config).length > 0) {\n this.configManager.saveConfig(config);\n }\n }\n\n /**\n * Start the auto-sync service\n */\n async start(): Promise<void> {\n if (this.isRunning) {\n logger.warn('Linear auto-sync service is already running');\n return;\n }\n\n try {\n // Verify Linear integration is configured\n const authManager = new LinearAuthManager(this.projectRoot);\n if (!authManager.isConfigured()) {\n throw new IntegrationError(\n 'Linear integration not configured. Run \"stackmemory linear setup\" first.',\n ErrorCode.LINEAR_AUTH_FAILED\n );\n }\n\n // Initialize sync engine\n const dbPath = join(this.projectRoot, '.stackmemory', 'context.db');\n if (!existsSync(dbPath)) {\n throw new IntegrationError(\n 'StackMemory not initialized. Run \"stackmemory init\" first.',\n ErrorCode.LINEAR_SYNC_FAILED\n );\n }\n\n const db = new Database(dbPath);\n const taskStore = new LinearTaskManager(this.projectRoot, db);\n\n this.syncEngine = new LinearSyncEngine(\n taskStore,\n authManager,\n this.config\n );\n\n // Test connection before starting\n const token = await authManager.getValidToken();\n if (!token) {\n throw new IntegrationError(\n 'Unable to get valid Linear token. Check authentication.',\n ErrorCode.LINEAR_AUTH_FAILED\n );\n }\n\n this.isRunning = true;\n this.scheduleNextSync();\n\n logger.info('Linear auto-sync service started', {\n interval: this.config.interval,\n direction: this.config.direction,\n conflictResolution: this.config.conflictResolution,\n });\n\n // Perform initial sync\n this.performSync();\n } catch (error: unknown) {\n logger.error('Failed to start Linear auto-sync service:', error as Error);\n throw error;\n }\n }\n\n /**\n * Stop the auto-sync service\n */\n stop(): void {\n if (this.intervalId) {\n clearTimeout(this.intervalId);\n this.intervalId = undefined;\n }\n\n this.isRunning = false;\n logger.info('Linear auto-sync service stopped');\n }\n\n /**\n * Get service status\n */\n getStatus(): {\n running: boolean;\n lastSyncTime: number;\n nextSyncTime?: number;\n retryCount: number;\n config: AutoSyncConfig;\n } {\n const nextSyncTime = this.intervalId\n ? this.lastSyncTime + this.config.interval * 60 * 1000\n : undefined;\n\n return {\n running: this.isRunning,\n lastSyncTime: this.lastSyncTime,\n nextSyncTime,\n retryCount: this.retryCount,\n config: this.config,\n };\n }\n\n /**\n * Update configuration\n */\n updateConfig(newConfig: Partial<AutoSyncConfig>): void {\n this.config = { ...this.config, ...newConfig };\n\n if (this.isRunning) {\n // Restart with new config\n this.stop();\n this.start();\n }\n\n logger.info('Linear auto-sync config updated', newConfig);\n }\n\n /**\n * Force immediate sync\n */\n async forceSync(): Promise<void> {\n if (!this.syncEngine) {\n throw new IntegrationError(\n 'Sync engine not initialized',\n ErrorCode.LINEAR_SYNC_FAILED\n );\n }\n\n logger.info('Forcing immediate Linear sync');\n await this.performSync();\n }\n\n /**\n * Schedule next sync based on configuration\n */\n private scheduleNextSync(): void {\n if (!this.isRunning) return;\n\n const delay = this.config.interval * 60 * 1000; // Convert minutes to milliseconds\n\n this.intervalId = setTimeout(() => {\n if (this.isRunning) {\n this.performSync();\n }\n }, delay);\n }\n\n /**\n * Perform synchronization with error handling and retries\n */\n private async performSync(): Promise<void> {\n if (!this.syncEngine) {\n logger.error('Sync engine not available');\n return;\n }\n\n // Check quiet hours\n if (this.isInQuietHours()) {\n logger.debug('Skipping sync during quiet hours');\n this.scheduleNextSync();\n return;\n }\n\n try {\n logger.debug('Starting Linear auto-sync');\n\n const result = await this.syncEngine.sync();\n\n if (result.success) {\n this.lastSyncTime = Date.now();\n this.retryCount = 0;\n\n // Log sync results\n const hasChanges =\n result.synced.toLinear > 0 ||\n result.synced.fromLinear > 0 ||\n result.synced.updated > 0;\n\n if (hasChanges) {\n logger.info('Linear auto-sync completed with changes', {\n toLinear: result.synced.toLinear,\n fromLinear: result.synced.fromLinear,\n updated: result.synced.updated,\n conflicts: result.conflicts.length,\n });\n } else {\n logger.debug('Linear auto-sync completed - no changes');\n }\n\n // Handle conflicts\n if (result.conflicts.length > 0) {\n logger.warn('Linear sync conflicts detected', {\n count: result.conflicts.length,\n conflicts: result.conflicts.map((c) => ({\n taskId: c.taskId,\n reason: c.reason,\n })),\n });\n }\n } else {\n throw new IntegrationError(\n `Sync failed: ${result.errors.join(', ')}`,\n ErrorCode.LINEAR_SYNC_FAILED\n );\n }\n } catch (error: unknown) {\n logger.error('Linear auto-sync failed:', error as Error);\n\n this.retryCount++;\n\n if (this.retryCount <= this.config.retryAttempts) {\n logger.info(\n `Retrying Linear sync in ${this.config.retryDelay / 1000}s (attempt ${this.retryCount}/${this.config.retryAttempts})`\n );\n\n // Schedule retry\n setTimeout(() => {\n if (this.isRunning) {\n this.performSync();\n }\n }, this.config.retryDelay);\n\n return; // Don't schedule next sync yet\n } else {\n logger.error(\n `Linear auto-sync failed after ${this.config.retryAttempts} attempts, skipping until next interval`\n );\n this.retryCount = 0;\n }\n }\n\n // Schedule next sync\n this.scheduleNextSync();\n }\n\n /**\n * Check if current time is within quiet hours\n */\n private isInQuietHours(): boolean {\n if (!this.config.quietHours) return false;\n\n const now = new Date();\n const currentHour = now.getHours();\n const { start, end } = this.config.quietHours;\n\n if (start < end) {\n // Quiet hours within same day (e.g., 22:00 - 07:00 next day)\n return currentHour >= start || currentHour < end;\n } else {\n // Quiet hours span midnight (e.g., 10:00 - 18:00)\n return currentHour >= start && currentHour < end;\n }\n }\n}\n\n/**\n * Global auto-sync service instance\n */\nlet autoSyncService: LinearAutoSyncService | null = null;\n\n/**\n * Initialize global auto-sync service\n */\nexport function initializeAutoSync(\n projectRoot: string,\n config?: Partial<AutoSyncConfig>\n): LinearAutoSyncService {\n if (autoSyncService) {\n autoSyncService.stop();\n }\n\n autoSyncService = new LinearAutoSyncService(projectRoot, config);\n return autoSyncService;\n}\n\n/**\n * Get global auto-sync service\n */\nexport function getAutoSyncService(): LinearAutoSyncService | null {\n return autoSyncService;\n}\n\n/**\n * Stop global auto-sync service\n */\nexport function stopAutoSync(): void {\n if (autoSyncService) {\n autoSyncService.stop();\n autoSyncService = null;\n }\n}\n"],
5
+ "mappings": ";;;;AAKA,SAAS,cAAc;AACvB,SAAS,yBAAyB;AAClC,SAAS,yBAAyB;AAClC,SAAS,kBAAkB,2BAAuC;AAClE,SAAS,2BAA2B;AACpC,SAAS,kBAAkB,iBAAiB;AAC5C,OAAO,cAAc;AACrB,SAAS,YAAY;AACrB,SAAS,kBAAkB;AAapB,MAAM,sBAAsB;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AA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path';
3
3
  const __filename = __fileURLToPath(import.meta.url);
4
4
  const __dirname = __pathDirname(__filename);
5
5
  import { logger } from "../../core/monitoring/logger.js";
6
+ import { IntegrationError, ErrorCode } from "../../core/errors/index.js";
6
7
  class LinearClient {
7
8
  config;
8
9
  baseUrl;
@@ -21,7 +22,10 @@ class LinearClient {
21
22
  this.config = config;
22
23
  this.baseUrl = config.baseUrl || "https://api.linear.app";
23
24
  if (!config.apiKey) {
24
- throw new Error("Linear API key is required");
25
+ throw new IntegrationError(
26
+ "Linear API key is required",
27
+ ErrorCode.LINEAR_AUTH_FAILED
28
+ );
25
29
  }
26
30
  }
27
31
  /**
@@ -115,7 +119,11 @@ class LinearClient {
115
119
  await this.sleep(waitTime);
116
120
  return this.graphql(query, variables, retries - 1, allowAuthRefresh);
117
121
  }
118
- throw new Error("Linear API rate limit exceeded after retries");
122
+ throw new IntegrationError(
123
+ "Linear API rate limit exceeded after retries",
124
+ ErrorCode.LINEAR_API_ERROR,
125
+ { retries: 0 }
126
+ );
119
127
  }
120
128
  if (!response.ok) {
121
129
  const errorText = await response.text();
@@ -123,8 +131,14 @@ class LinearClient {
123
131
  "Linear API error response:",
124
132
  new Error(`${response.status}: ${errorText}`)
125
133
  );
126
- throw new Error(
127
- `Linear API error: ${response.status} ${response.statusText} - ${errorText}`
134
+ throw new IntegrationError(
135
+ `Linear API error: ${response.status} ${response.statusText}`,
136
+ ErrorCode.LINEAR_API_ERROR,
137
+ {
138
+ status: response.status,
139
+ statusText: response.statusText,
140
+ body: errorText
141
+ }
128
142
  );
129
143
  }
130
144
  const result = await response.json();
@@ -142,7 +156,11 @@ class LinearClient {
142
156
  return this.graphql(query, variables, retries - 1);
143
157
  }
144
158
  logger.error("Linear GraphQL errors:", { errors: result.errors });
145
- throw new Error(`Linear GraphQL error: ${result.errors[0].message}`);
159
+ throw new IntegrationError(
160
+ `Linear GraphQL error: ${result.errors[0].message}`,
161
+ ErrorCode.LINEAR_API_ERROR,
162
+ { errors: result.errors }
163
+ );
146
164
  }
147
165
  return result.data;
148
166
  }
@@ -186,7 +204,11 @@ class LinearClient {
186
204
  `;
187
205
  const result = await this.graphql(mutation, { input });
188
206
  if (!result.issueCreate.success) {
189
- throw new Error("Failed to create Linear issue");
207
+ throw new IntegrationError(
208
+ "Failed to create Linear issue",
209
+ ErrorCode.LINEAR_API_ERROR,
210
+ { input }
211
+ );
190
212
  }
191
213
  return result.issueCreate.issue;
192
214
  }
@@ -230,7 +252,11 @@ class LinearClient {
230
252
  `;
231
253
  const result = await this.graphql(mutation, { id: issueId, input: updates });
232
254
  if (!result.issueUpdate.success) {
233
- throw new Error(`Failed to update Linear issue ${issueId}`);
255
+ throw new IntegrationError(
256
+ `Failed to update Linear issue ${issueId}`,
257
+ ErrorCode.LINEAR_API_ERROR,
258
+ { issueId, updates }
259
+ );
234
260
  }
235
261
  return result.issueUpdate.issue;
236
262
  }
@@ -344,13 +370,20 @@ class LinearClient {
344
370
  if (teamId) {
345
371
  const result = await this.graphql(query, { id: teamId });
346
372
  if (!result.team) {
347
- throw new Error(`Team ${teamId} not found`);
373
+ throw new IntegrationError(
374
+ `Team ${teamId} not found`,
375
+ ErrorCode.LINEAR_API_ERROR,
376
+ { teamId }
377
+ );
348
378
  }
349
379
  return result.team;
350
380
  } else {
351
381
  const result = await this.graphql(query);
352
382
  if (result.teams.nodes.length === 0) {
353
- throw new Error("No teams found");
383
+ throw new IntegrationError(
384
+ "No teams found",
385
+ ErrorCode.LINEAR_API_ERROR
386
+ );
354
387
  }
355
388
  return result.teams.nodes[0];
356
389
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/integrations/linear/client.ts"],
4
- "sourcesContent": ["/**\n * Linear API Client for StackMemory\n * Handles bi-directional sync with Linear's GraphQL API\n */\n\nimport { logger } from '../../core/monitoring/logger.js';\n\nexport interface LinearConfig {\n apiKey: string;\n teamId?: string;\n webhookSecret?: string;\n baseUrl?: string;\n // If true, send Authorization header as `Bearer <apiKey>` (OAuth access token)\n useBearer?: boolean;\n // Optional callback to refresh token on 401 and return the new access token\n onUnauthorized?: () => Promise<string>;\n}\n\nexport interface LinearIssue {\n id: string;\n identifier: string; // Like \"SM-123\"\n title: string;\n description?: string;\n state: {\n id: string;\n name: string;\n type: 'backlog' | 'unstarted' | 'started' | 'completed' | 'cancelled';\n };\n priority: number; // 0-4 (0=none, 1=urgent, 2=high, 3=medium, 4=low)\n assignee?: {\n id: string;\n name: string;\n email: string;\n };\n estimate?: number; // Story points\n labels: Array<{\n id: string;\n name: string;\n }>;\n createdAt: string;\n updatedAt: string;\n url: string;\n}\n\nexport interface LinearCreateIssueInput {\n title: string;\n description?: string;\n teamId: string;\n priority?: number;\n estimate?: number;\n labelIds?: string[];\n}\n\ninterface RateLimitState {\n remaining: number;\n resetAt: number;\n retryAfter: number;\n}\n\nexport class LinearClient {\n private config: LinearConfig;\n private baseUrl: string;\n private rateLimitState: RateLimitState = {\n remaining: 1500, // Linear's default limit\n resetAt: Date.now() + 3600000,\n retryAfter: 0,\n };\n private requestQueue: Array<() => Promise<void>> = [];\n private isProcessingQueue = false;\n private minRequestInterval = 100; // Minimum ms between requests\n private lastRequestTime = 0;\n\n constructor(config: LinearConfig) {\n this.config = config;\n this.baseUrl = config.baseUrl || 'https://api.linear.app';\n\n if (!config.apiKey) {\n throw new Error('Linear API key is required');\n }\n }\n\n /**\n * Wait for rate limit to reset if needed\n */\n private async waitForRateLimit(): Promise<void> {\n const now = Date.now();\n\n // Check if we're in a retry-after period\n if (this.rateLimitState.retryAfter > now) {\n const waitTime = this.rateLimitState.retryAfter - now;\n logger.warn(`Rate limited, waiting ${Math.ceil(waitTime / 1000)}s`);\n await this.sleep(waitTime);\n }\n\n // Check if we've exhausted our rate limit\n if (this.rateLimitState.remaining <= 5) {\n if (this.rateLimitState.resetAt > now) {\n const waitTime = this.rateLimitState.resetAt - now;\n logger.warn(\n `Rate limit nearly exhausted, waiting ${Math.ceil(waitTime / 1000)}s for reset`\n );\n await this.sleep(Math.min(waitTime, 60000)); // Max 60s wait\n }\n }\n\n // Ensure minimum interval between requests\n const timeSinceLastRequest = now - this.lastRequestTime;\n if (timeSinceLastRequest < this.minRequestInterval) {\n await this.sleep(this.minRequestInterval - timeSinceLastRequest);\n }\n }\n\n private sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n\n /**\n * Update rate limit state from response headers\n */\n private updateRateLimitState(response: Response): void {\n const remaining = response.headers.get('x-ratelimit-remaining');\n const reset = response.headers.get('x-ratelimit-reset');\n const retryAfter = response.headers.get('retry-after');\n\n if (remaining !== null) {\n this.rateLimitState.remaining = parseInt(remaining, 10);\n }\n if (reset !== null) {\n this.rateLimitState.resetAt = parseInt(reset, 10) * 1000;\n }\n if (retryAfter !== null) {\n this.rateLimitState.retryAfter =\n Date.now() + parseInt(retryAfter, 10) * 1000;\n }\n }\n\n /**\n * Execute GraphQL query against Linear API with rate limiting\n */\n private async graphql<T>(\n query: string,\n variables?: Record<string, unknown>,\n retries = 3,\n allowAuthRefresh = true\n ): Promise<T> {\n // Wait for rate limit before making request\n await this.waitForRateLimit();\n\n this.lastRequestTime = Date.now();\n\n const authHeader = this.config.useBearer\n ? `Bearer ${this.config.apiKey}`\n : this.config.apiKey;\n\n let response = await fetch(`${this.baseUrl}/graphql`, {\n method: 'POST',\n headers: {\n Authorization: authHeader,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n query,\n variables,\n }),\n });\n\n // Update rate limit state from response\n this.updateRateLimitState(response);\n\n // Handle unauthorized (e.g., expired OAuth token)\n if (\n response.status === 401 &&\n this.config.onUnauthorized &&\n allowAuthRefresh\n ) {\n try {\n const newToken = await this.config.onUnauthorized();\n // Update local config and retry once without further auth refresh\n this.config.apiKey = newToken;\n const retryHeader = this.config.useBearer\n ? `Bearer ${newToken}`\n : newToken;\n response = await fetch(`${this.baseUrl}/graphql`, {\n method: 'POST',\n headers: {\n Authorization: retryHeader,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({ query, variables }),\n });\n this.updateRateLimitState(response);\n } catch (e: unknown) {\n // Fall through to standard error handling\n }\n }\n\n // Handle rate limiting with exponential backoff\n if (response.status === 429) {\n if (retries > 0) {\n const retryAfter = response.headers.get('retry-after');\n const waitTime = retryAfter ? parseInt(retryAfter, 10) * 1000 : 60000;\n logger.warn(\n `Rate limited (429), retrying in ${waitTime / 1000}s (${retries} retries left)`\n );\n this.rateLimitState.retryAfter = Date.now() + waitTime;\n await this.sleep(waitTime);\n return this.graphql<T>(query, variables, retries - 1, allowAuthRefresh);\n }\n throw new Error('Linear API rate limit exceeded after retries');\n }\n\n if (!response.ok) {\n const errorText = await response.text();\n logger.error(\n 'Linear API error response:',\n new Error(`${response.status}: ${errorText}`)\n );\n throw new Error(\n `Linear API error: ${response.status} ${response.statusText} - ${errorText}`\n );\n }\n\n const result = (await response.json()) as {\n data?: T;\n errors?: Array<{ message: string }>;\n };\n\n if (result.errors) {\n // Check for rate limit errors in GraphQL response\n const rateLimitError = result.errors.find(\n (e) =>\n e.message.toLowerCase().includes('rate limit') ||\n e.message.toLowerCase().includes('usage limit')\n );\n\n if (rateLimitError && retries > 0) {\n const waitTime = 60000; // Default 60s wait for GraphQL rate limit errors\n logger.warn(\n `GraphQL rate limit error, retrying in ${waitTime / 1000}s (${retries} retries left)`\n );\n this.rateLimitState.retryAfter = Date.now() + waitTime;\n await this.sleep(waitTime);\n return this.graphql<T>(query, variables, retries - 1);\n }\n\n logger.error('Linear GraphQL errors:', { errors: result.errors });\n throw new Error(`Linear GraphQL error: ${result.errors[0].message}`);\n }\n\n return result.data as T;\n }\n\n /**\n * Create a new issue in Linear\n */\n async createIssue(input: LinearCreateIssueInput): Promise<LinearIssue> {\n const mutation = `\n mutation CreateIssue($input: IssueCreateInput!) {\n issueCreate(input: $input) {\n success\n issue {\n id\n identifier\n title\n description\n state {\n id\n name\n type\n }\n priority\n assignee {\n id\n name\n email\n }\n estimate\n labels {\n nodes {\n id\n name\n }\n }\n createdAt\n updatedAt\n url\n }\n }\n }\n `;\n\n const result = await this.graphql<{\n issueCreate: {\n success: boolean;\n issue: LinearIssue;\n };\n }>(mutation, { input });\n\n if (!result.issueCreate.success) {\n throw new Error('Failed to create Linear issue');\n }\n\n return result.issueCreate.issue;\n }\n\n /**\n * Update an existing Linear issue\n */\n async updateIssue(\n issueId: string,\n updates: Partial<LinearCreateIssueInput> & { stateId?: string }\n ): Promise<LinearIssue> {\n const mutation = `\n mutation UpdateIssue($id: String!, $input: IssueUpdateInput!) {\n issueUpdate(id: $id, input: $input) {\n success\n issue {\n id\n identifier\n title\n description\n state {\n id\n name\n type\n }\n priority\n assignee {\n id\n name\n email\n }\n estimate\n labels {\n nodes {\n id\n name\n }\n }\n createdAt\n updatedAt\n url\n }\n }\n }\n `;\n\n const result = await this.graphql<{\n issueUpdate: {\n success: boolean;\n issue: LinearIssue;\n };\n }>(mutation, { id: issueId, input: updates });\n\n if (!result.issueUpdate.success) {\n throw new Error(`Failed to update Linear issue ${issueId}`);\n }\n\n return result.issueUpdate.issue;\n }\n\n /**\n * Get issue by ID\n */\n async getIssue(issueId: string): Promise<LinearIssue | null> {\n const query = `\n query GetIssue($id: String!) {\n issue(id: $id) {\n id\n identifier\n title\n description\n state {\n id\n name\n type\n }\n priority\n assignee {\n id\n name\n email\n }\n estimate\n labels {\n nodes {\n id\n name\n }\n }\n createdAt\n updatedAt\n url\n }\n }\n `;\n\n const result = await this.graphql<{\n issue: LinearIssue | null;\n }>(query, { id: issueId });\n\n return result.issue;\n }\n\n /**\n * Search for issues by identifier (e.g., \"SM-123\")\n */\n async findIssueByIdentifier(identifier: string): Promise<LinearIssue | null> {\n const query = `\n query FindIssue($filter: IssueFilter!) {\n issues(filter: $filter, first: 1) {\n nodes {\n id\n identifier\n title\n description\n state {\n id\n name\n type\n }\n priority\n assignee {\n id\n name\n email\n }\n estimate\n labels {\n nodes {\n id\n name\n }\n }\n createdAt\n updatedAt\n url\n }\n }\n }\n `;\n\n const result = await this.graphql<{\n issues: {\n nodes: LinearIssue[];\n };\n }>(query, {\n filter: {\n number: {\n eq: parseInt(identifier.split('-')[1] || '0') || 0,\n },\n },\n });\n\n return result.issues.nodes[0] || null;\n }\n\n /**\n * Get team information\n */\n async getTeam(\n teamId?: string\n ): Promise<{ id: string; name: string; key: string }> {\n const query = teamId\n ? `\n query GetTeam($id: String!) {\n team(id: $id) {\n id\n name\n key\n }\n }\n `\n : `\n query GetTeams {\n teams(first: 1) {\n nodes {\n id\n name\n key\n }\n }\n }\n `;\n\n if (teamId) {\n const result = await this.graphql<{\n team: { id: string; name: string; key: string };\n }>(query, { id: teamId });\n if (!result.team) {\n throw new Error(`Team ${teamId} not found`);\n }\n return result.team;\n } else {\n const result = await this.graphql<{\n teams: {\n nodes: Array<{ id: string; name: string; key: string }>;\n };\n }>(query);\n\n if (result.teams.nodes.length === 0) {\n throw new Error('No teams found');\n }\n\n return result.teams.nodes[0]!;\n }\n }\n\n /**\n * Get workflow states for a team\n */\n async getWorkflowStates(teamId: string): Promise<\n Array<{\n id: string;\n name: string;\n type: 'backlog' | 'unstarted' | 'started' | 'completed' | 'cancelled';\n color: string;\n }>\n > {\n const query = `\n query GetWorkflowStates($teamId: String!) {\n team(id: $teamId) {\n states {\n nodes {\n id\n name\n type\n color\n }\n }\n }\n }\n `;\n\n const result = await this.graphql<{\n team: {\n states: {\n nodes: Array<{\n id: string;\n name: string;\n type:\n | 'backlog'\n | 'unstarted'\n | 'started'\n | 'completed'\n | 'cancelled';\n color: string;\n }>;\n };\n };\n }>(query, { teamId });\n\n return result.team.states.nodes;\n }\n\n /**\n * Get current viewer/user information\n */\n async getViewer(): Promise<{\n id: string;\n name: string;\n email: string;\n }> {\n const query = `\n query GetViewer {\n viewer {\n id\n name\n email\n }\n }\n `;\n\n const result = await this.graphql<{\n viewer: {\n id: string;\n name: string;\n email: string;\n };\n }>(query);\n\n return result.viewer;\n }\n\n /**\n * Get all teams for the organization\n */\n async getTeams(): Promise<\n Array<{\n id: string;\n name: string;\n key: string;\n }>\n > {\n const query = `\n query GetTeams {\n teams(first: 50) {\n nodes {\n id\n name\n key\n }\n }\n }\n `;\n\n const result = await this.graphql<{\n teams: {\n nodes: Array<{\n id: string;\n name: string;\n key: string;\n }>;\n };\n }>(query);\n\n return result.teams.nodes;\n }\n\n /**\n * Get issues with filtering options\n */\n async getIssues(options?: {\n teamId?: string;\n assigneeId?: string;\n stateType?: 'backlog' | 'unstarted' | 'started' | 'completed' | 'cancelled';\n limit?: number;\n }): Promise<LinearIssue[]> {\n const query = `\n query GetIssues($filter: IssueFilter, $first: Int!) {\n issues(filter: $filter, first: $first) {\n nodes {\n id\n identifier\n title\n description\n state {\n id\n name\n type\n }\n priority\n assignee {\n id\n name\n email\n }\n estimate\n labels {\n nodes {\n id\n name\n }\n }\n createdAt\n updatedAt\n url\n }\n }\n }\n `;\n\n const filter: Record<string, unknown> = {};\n\n if (options?.teamId) {\n filter.team = { id: { eq: options.teamId } };\n }\n\n if (options?.assigneeId) {\n filter.assignee = { id: { eq: options.assigneeId } };\n }\n\n if (options?.stateType) {\n filter.state = { type: { eq: options.stateType } };\n }\n\n const result = await this.graphql<{\n issues: {\n nodes: LinearIssue[];\n };\n }>(query, {\n filter: Object.keys(filter).length > 0 ? filter : undefined,\n first: options?.limit || 50,\n });\n\n return result.issues.nodes;\n }\n\n /**\n * Assign an issue to a user\n */\n async assignIssue(\n issueId: string,\n assigneeId: string\n ): Promise<{ success: boolean; issue?: LinearIssue }> {\n const mutation = `\n mutation AssignIssue($issueId: String!, $assigneeId: String!) {\n issueUpdate(id: $issueId, input: { assigneeId: $assigneeId }) {\n success\n issue {\n id\n identifier\n title\n assignee {\n id\n name\n }\n }\n }\n }\n `;\n\n const result = await this.graphql<{\n issueUpdate: {\n success: boolean;\n issue?: LinearIssue;\n };\n }>(mutation, { issueId, assigneeId });\n\n return result.issueUpdate;\n }\n\n /**\n * Update issue state (e.g., move to \"In Progress\")\n */\n async updateIssueState(\n issueId: string,\n stateId: string\n ): Promise<{ success: boolean; issue?: LinearIssue }> {\n const mutation = `\n mutation UpdateIssueState($issueId: String!, $stateId: String!) {\n issueUpdate(id: $issueId, input: { stateId: $stateId }) {\n success\n issue {\n id\n identifier\n title\n state {\n id\n name\n type\n }\n }\n }\n }\n `;\n\n const result = await this.graphql<{\n issueUpdate: {\n success: boolean;\n issue?: LinearIssue;\n };\n }>(mutation, { issueId, stateId });\n\n return result.issueUpdate;\n }\n\n /**\n * Get an issue by ID with team info\n */\n async getIssueById(issueId: string): Promise<LinearIssue | null> {\n const query = `\n query GetIssue($issueId: String!) {\n issue(id: $issueId) {\n id\n identifier\n title\n description\n state {\n id\n name\n type\n }\n priority\n assignee {\n id\n name\n email\n }\n estimate\n labels {\n nodes {\n id\n name\n }\n }\n team {\n id\n name\n }\n createdAt\n updatedAt\n url\n }\n }\n `;\n\n try {\n const result = await this.graphql<{\n issue: LinearIssue & { team: { id: string; name: string } };\n }>(query, { issueId });\n return result.issue;\n } catch {\n return null;\n }\n }\n\n /**\n * Start working on an issue (assign to self and move to In Progress)\n */\n async startIssue(issueId: string): Promise<{\n success: boolean;\n issue?: LinearIssue;\n error?: string;\n }> {\n try {\n // Get current user\n const user = await this.getViewer();\n\n // Get the issue to find its team\n const issue = await this.getIssueById(issueId);\n if (!issue) {\n return { success: false, error: 'Issue not found' };\n }\n\n // Assign to self\n const assignResult = await this.assignIssue(issueId, user.id);\n if (!assignResult.success) {\n return { success: false, error: 'Failed to assign issue' };\n }\n\n // Find the \"In Progress\" or \"started\" state for this issue's team\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const teamId = (issue as any).team?.id;\n if (teamId) {\n const states = await this.getWorkflowStates(teamId);\n const inProgressState = states.find(\n (s) =>\n s.type === 'started' || s.name.toLowerCase().includes('progress')\n );\n\n if (inProgressState) {\n await this.updateIssueState(issueId, inProgressState.id);\n }\n }\n\n return { success: true, issue: assignResult.issue };\n } catch (error) {\n return {\n success: false,\n error: error instan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ChB,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,WAAW,SAId;AACD,QAAI;AAEF,YAAM,OAAO,MAAM,KAAK,UAAU;AAGlC,YAAM,QAAQ,MAAM,KAAK,aAAa,OAAO;AAC7C,UAAI,CAAC,OAAO;AACV,eAAO,EAAE,SAAS,OAAO,OAAO,kBAAkB;AAAA,MACpD;AAGA,YAAM,eAAe,MAAM,KAAK,YAAY,SAAS,KAAK,EAAE;AAC5D,UAAI,CAAC,aAAa,SAAS;AACzB,eAAO,EAAE,SAAS,OAAO,OAAO,yBAAyB;AAAA,MAC3D;AAIA,YAAM,SAAU,MAAc,MAAM;AACpC,UAAI,QAAQ;AACV,cAAM,SAAS,MAAM,KAAK,kBAAkB,MAAM;AAClD,cAAM,kBAAkB,OAAO;AAAA,UAC7B,CAAC,MACC,EAAE,SAAS,aAAa,EAAE,KAAK,YAAY,EAAE,SAAS,UAAU;AAAA,QACpE;AAEA,YAAI,iBAAiB;AACnB,gBAAM,KAAK,iBAAiB,SAAS,gBAAgB,EAAE;AAAA,QACzD;AAAA,MACF;AAEA,aAAO,EAAE,SAAS,MAAM,OAAO,aAAa,MAAM;AAAA,IACpD,SAAS,OAAO;AACd,aAAO;AAAA,QACL,SAAS;AAAA,QACT,OAAO,iBAAiB,QAAQ,MAAM,UAAU;AAAA,MAClD;AAAA,IACF;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["/**\n * Linear API Client for StackMemory\n * Handles bi-directional sync with Linear's GraphQL API\n */\n\nimport { logger } from '../../core/monitoring/logger.js';\nimport { IntegrationError, ErrorCode } from '../../core/errors/index.js';\n\nexport interface LinearConfig {\n apiKey: string;\n teamId?: string;\n webhookSecret?: string;\n baseUrl?: string;\n // If true, send Authorization header as `Bearer <apiKey>` (OAuth access token)\n useBearer?: boolean;\n // Optional callback to refresh token on 401 and return the new access token\n onUnauthorized?: () => Promise<string>;\n}\n\nexport interface LinearIssue {\n id: string;\n identifier: string; // Like \"SM-123\"\n title: string;\n description?: string;\n state: {\n id: string;\n name: string;\n type: 'backlog' | 'unstarted' | 'started' | 'completed' | 'cancelled';\n };\n priority: number; // 0-4 (0=none, 1=urgent, 2=high, 3=medium, 4=low)\n assignee?: {\n id: string;\n name: string;\n email: string;\n };\n estimate?: number; // Story points\n labels: Array<{\n id: string;\n name: string;\n }>;\n createdAt: string;\n updatedAt: string;\n url: string;\n}\n\nexport interface LinearCreateIssueInput {\n title: string;\n description?: string;\n teamId: string;\n priority?: number;\n estimate?: number;\n labelIds?: string[];\n}\n\ninterface RateLimitState {\n remaining: number;\n resetAt: number;\n retryAfter: number;\n}\n\nexport class LinearClient {\n private config: LinearConfig;\n private baseUrl: string;\n private rateLimitState: RateLimitState = {\n remaining: 1500, // Linear's default limit\n resetAt: Date.now() + 3600000,\n retryAfter: 0,\n };\n private requestQueue: Array<() => Promise<void>> = [];\n private isProcessingQueue = false;\n private minRequestInterval = 100; // Minimum ms between requests\n private lastRequestTime = 0;\n\n constructor(config: LinearConfig) {\n this.config = config;\n this.baseUrl = config.baseUrl || 'https://api.linear.app';\n\n if (!config.apiKey) {\n throw new IntegrationError(\n 'Linear API key is required',\n ErrorCode.LINEAR_AUTH_FAILED\n );\n }\n }\n\n /**\n * Wait for rate limit to reset if needed\n */\n private async waitForRateLimit(): Promise<void> {\n const now = Date.now();\n\n // Check if we're in a retry-after period\n if (this.rateLimitState.retryAfter > now) {\n const waitTime = this.rateLimitState.retryAfter - now;\n logger.warn(`Rate limited, waiting ${Math.ceil(waitTime / 1000)}s`);\n await this.sleep(waitTime);\n }\n\n // Check if we've exhausted our rate limit\n if (this.rateLimitState.remaining <= 5) {\n if (this.rateLimitState.resetAt > now) {\n const waitTime = this.rateLimitState.resetAt - now;\n logger.warn(\n `Rate limit nearly exhausted, waiting ${Math.ceil(waitTime / 1000)}s for reset`\n );\n await this.sleep(Math.min(waitTime, 60000)); // Max 60s wait\n }\n }\n\n // Ensure minimum interval between requests\n const timeSinceLastRequest = now - this.lastRequestTime;\n if (timeSinceLastRequest < this.minRequestInterval) {\n await this.sleep(this.minRequestInterval - timeSinceLastRequest);\n }\n }\n\n private sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n\n /**\n * Update rate limit state from response headers\n */\n private updateRateLimitState(response: Response): void {\n const remaining = response.headers.get('x-ratelimit-remaining');\n const reset = response.headers.get('x-ratelimit-reset');\n const retryAfter = response.headers.get('retry-after');\n\n if (remaining !== null) {\n this.rateLimitState.remaining = parseInt(remaining, 10);\n }\n if (reset !== null) {\n this.rateLimitState.resetAt = parseInt(reset, 10) * 1000;\n }\n if (retryAfter !== null) {\n this.rateLimitState.retryAfter =\n Date.now() + parseInt(retryAfter, 10) * 1000;\n }\n }\n\n /**\n * Execute GraphQL query against Linear API with rate limiting\n */\n private async graphql<T>(\n query: string,\n variables?: Record<string, unknown>,\n retries = 3,\n allowAuthRefresh = true\n ): Promise<T> {\n // Wait for rate limit before making request\n await this.waitForRateLimit();\n\n this.lastRequestTime = Date.now();\n\n const authHeader = this.config.useBearer\n ? `Bearer ${this.config.apiKey}`\n : this.config.apiKey;\n\n let response = await fetch(`${this.baseUrl}/graphql`, {\n method: 'POST',\n headers: {\n Authorization: authHeader,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n query,\n variables,\n }),\n });\n\n // Update rate limit state from response\n this.updateRateLimitState(response);\n\n // Handle unauthorized (e.g., expired OAuth token)\n if (\n response.status === 401 &&\n this.config.onUnauthorized &&\n allowAuthRefresh\n ) {\n try {\n const newToken = await this.config.onUnauthorized();\n // Update local config and retry once without further auth refresh\n this.config.apiKey = newToken;\n const retryHeader = this.config.useBearer\n ? `Bearer ${newToken}`\n : newToken;\n response = await fetch(`${this.baseUrl}/graphql`, {\n method: 'POST',\n headers: {\n Authorization: retryHeader,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({ query, variables }),\n });\n this.updateRateLimitState(response);\n } catch (e: unknown) {\n // Fall through to standard error handling\n }\n }\n\n // Handle rate limiting with exponential backoff\n if (response.status === 429) {\n if (retries > 0) {\n const retryAfter = response.headers.get('retry-after');\n const waitTime = retryAfter ? parseInt(retryAfter, 10) * 1000 : 60000;\n logger.warn(\n `Rate limited (429), retrying in ${waitTime / 1000}s (${retries} retries left)`\n );\n this.rateLimitState.retryAfter = Date.now() + waitTime;\n await this.sleep(waitTime);\n return this.graphql<T>(query, variables, retries - 1, allowAuthRefresh);\n }\n throw new IntegrationError(\n 'Linear API rate limit exceeded after retries',\n ErrorCode.LINEAR_API_ERROR,\n { retries: 0 }\n );\n }\n\n if (!response.ok) {\n const errorText = await response.text();\n logger.error(\n 'Linear API error response:',\n new Error(`${response.status}: ${errorText}`)\n );\n throw new IntegrationError(\n `Linear API error: ${response.status} ${response.statusText}`,\n ErrorCode.LINEAR_API_ERROR,\n {\n status: response.status,\n statusText: response.statusText,\n body: errorText,\n }\n );\n }\n\n const result = (await response.json()) as {\n data?: T;\n errors?: Array<{ message: string }>;\n };\n\n if (result.errors) {\n // Check for rate limit errors in GraphQL response\n const rateLimitError = result.errors.find(\n (e) =>\n e.message.toLowerCase().includes('rate limit') ||\n e.message.toLowerCase().includes('usage limit')\n );\n\n if (rateLimitError && retries > 0) {\n const waitTime = 60000; // Default 60s wait for GraphQL rate limit errors\n logger.warn(\n `GraphQL rate limit error, retrying in ${waitTime / 1000}s (${retries} retries left)`\n );\n this.rateLimitState.retryAfter = Date.now() + waitTime;\n await this.sleep(waitTime);\n return this.graphql<T>(query, variables, retries - 1);\n }\n\n logger.error('Linear GraphQL errors:', { errors: result.errors });\n throw new IntegrationError(\n `Linear GraphQL error: ${result.errors[0].message}`,\n ErrorCode.LINEAR_API_ERROR,\n { errors: result.errors }\n );\n }\n\n return result.data as T;\n }\n\n /**\n * Create a new issue in Linear\n */\n async createIssue(input: LinearCreateIssueInput): Promise<LinearIssue> {\n const mutation = `\n mutation CreateIssue($input: IssueCreateInput!) {\n issueCreate(input: $input) {\n success\n issue {\n id\n identifier\n title\n description\n state {\n id\n name\n type\n }\n priority\n assignee {\n id\n name\n email\n }\n estimate\n labels {\n nodes {\n id\n name\n }\n }\n createdAt\n updatedAt\n url\n }\n }\n }\n `;\n\n const result = await this.graphql<{\n issueCreate: {\n success: boolean;\n issue: LinearIssue;\n };\n }>(mutation, { input });\n\n if (!result.issueCreate.success) {\n throw new IntegrationError(\n 'Failed to create Linear issue',\n ErrorCode.LINEAR_API_ERROR,\n { input }\n );\n }\n\n return result.issueCreate.issue;\n }\n\n /**\n * Update an existing Linear issue\n */\n async updateIssue(\n issueId: string,\n updates: Partial<LinearCreateIssueInput> & { stateId?: string }\n ): Promise<LinearIssue> {\n const mutation = `\n mutation UpdateIssue($id: String!, $input: IssueUpdateInput!) {\n issueUpdate(id: $id, input: $input) {\n success\n issue {\n id\n identifier\n title\n description\n state {\n id\n name\n type\n }\n priority\n assignee {\n id\n name\n email\n }\n estimate\n labels {\n nodes {\n id\n name\n }\n }\n createdAt\n updatedAt\n url\n }\n }\n }\n `;\n\n const result = await this.graphql<{\n issueUpdate: {\n success: boolean;\n issue: LinearIssue;\n };\n }>(mutation, { id: issueId, input: updates });\n\n if (!result.issueUpdate.success) {\n throw new IntegrationError(\n `Failed to update Linear issue ${issueId}`,\n ErrorCode.LINEAR_API_ERROR,\n { issueId, updates }\n );\n }\n\n return result.issueUpdate.issue;\n }\n\n /**\n * Get issue by ID\n */\n async getIssue(issueId: string): Promise<LinearIssue | null> {\n const query = `\n query GetIssue($id: String!) {\n issue(id: $id) {\n id\n identifier\n title\n description\n state {\n id\n name\n type\n }\n priority\n assignee {\n id\n name\n email\n }\n estimate\n labels {\n nodes {\n id\n name\n }\n }\n createdAt\n updatedAt\n url\n }\n }\n `;\n\n const result = await this.graphql<{\n issue: LinearIssue | null;\n }>(query, { id: issueId });\n\n return result.issue;\n }\n\n /**\n * Search for issues by identifier (e.g., \"SM-123\")\n */\n async findIssueByIdentifier(identifier: string): Promise<LinearIssue | null> {\n const query = `\n query FindIssue($filter: IssueFilter!) {\n issues(filter: $filter, first: 1) {\n nodes {\n id\n identifier\n title\n description\n state {\n id\n name\n type\n }\n priority\n assignee {\n id\n name\n email\n }\n estimate\n labels {\n nodes {\n id\n name\n }\n }\n createdAt\n updatedAt\n url\n }\n }\n }\n `;\n\n const result = await this.graphql<{\n issues: {\n nodes: LinearIssue[];\n };\n }>(query, {\n filter: {\n number: {\n eq: parseInt(identifier.split('-')[1] || '0') || 0,\n },\n },\n });\n\n return result.issues.nodes[0] || null;\n }\n\n /**\n * Get team information\n */\n async getTeam(\n teamId?: string\n ): Promise<{ id: string; name: string; key: string }> {\n const query = teamId\n ? `\n query GetTeam($id: String!) {\n team(id: $id) {\n id\n name\n key\n }\n }\n `\n : `\n query GetTeams {\n teams(first: 1) {\n nodes {\n id\n name\n key\n }\n }\n }\n `;\n\n if (teamId) {\n const result = await this.graphql<{\n team: { id: string; name: string; key: string };\n }>(query, { id: teamId });\n if (!result.team) {\n throw new IntegrationError(\n `Team ${teamId} not found`,\n ErrorCode.LINEAR_API_ERROR,\n { teamId }\n );\n }\n return result.team;\n } else {\n const result = await this.graphql<{\n teams: {\n nodes: Array<{ id: string; name: string; key: string }>;\n };\n }>(query);\n\n if (result.teams.nodes.length === 0) {\n throw new IntegrationError(\n 'No teams found',\n ErrorCode.LINEAR_API_ERROR\n );\n }\n\n return result.teams.nodes[0]!;\n }\n }\n\n /**\n * Get workflow states for a team\n */\n async getWorkflowStates(teamId: string): Promise<\n Array<{\n id: string;\n name: string;\n type: 'backlog' | 'unstarted' | 'started' | 'completed' | 'cancelled';\n color: string;\n }>\n > {\n const query = `\n query GetWorkflowStates($teamId: String!) {\n team(id: $teamId) {\n states {\n nodes {\n id\n name\n type\n color\n }\n }\n }\n }\n `;\n\n const result = await this.graphql<{\n team: {\n states: {\n nodes: Array<{\n id: string;\n name: string;\n type:\n | 'backlog'\n | 'unstarted'\n | 'started'\n | 'completed'\n | 'cancelled';\n color: string;\n }>;\n };\n };\n }>(query, { teamId });\n\n return result.team.states.nodes;\n }\n\n /**\n * Get current viewer/user information\n */\n async getViewer(): Promise<{\n id: string;\n name: string;\n email: string;\n }> {\n const query = `\n query GetViewer {\n viewer {\n id\n name\n email\n }\n }\n `;\n\n const result = await this.graphql<{\n viewer: {\n id: string;\n name: string;\n email: string;\n };\n }>(query);\n\n return result.viewer;\n }\n\n /**\n * Get all teams for the organization\n */\n async getTeams(): Promise<\n Array<{\n id: string;\n name: string;\n key: string;\n }>\n > {\n const query = `\n query GetTeams {\n teams(first: 50) {\n nodes {\n id\n name\n key\n }\n }\n }\n `;\n\n const result = await this.graphql<{\n teams: {\n nodes: Array<{\n id: string;\n name: string;\n key: string;\n }>;\n };\n }>(query);\n\n return result.teams.nodes;\n }\n\n /**\n * Get issues with filtering options\n */\n async getIssues(options?: {\n teamId?: string;\n assigneeId?: string;\n stateType?: 'backlog' | 'unstarted' | 'started' | 'completed' | 'cancelled';\n limit?: number;\n }): Promise<LinearIssue[]> {\n const query = `\n query GetIssues($filter: IssueFilter, $first: Int!) {\n issues(filter: $filter, first: $first) {\n nodes {\n id\n identifier\n title\n description\n state {\n id\n name\n type\n }\n priority\n assignee {\n id\n name\n email\n }\n estimate\n labels {\n nodes {\n id\n name\n }\n }\n createdAt\n updatedAt\n url\n }\n }\n }\n `;\n\n const filter: Record<string, unknown> = {};\n\n if (options?.teamId) {\n filter.team = { id: { eq: options.teamId } };\n }\n\n if (options?.assigneeId) {\n filter.assignee = { id: { eq: options.assigneeId } };\n }\n\n if (options?.stateType) {\n filter.state = { type: { eq: options.stateType } };\n }\n\n const result = await this.graphql<{\n issues: {\n nodes: LinearIssue[];\n };\n }>(query, {\n filter: Object.keys(filter).length > 0 ? filter : undefined,\n first: options?.limit || 50,\n });\n\n return result.issues.nodes;\n }\n\n /**\n * Assign an issue to a user\n */\n async assignIssue(\n issueId: string,\n assigneeId: string\n ): Promise<{ success: boolean; issue?: LinearIssue }> {\n const mutation = `\n mutation AssignIssue($issueId: String!, $assigneeId: String!) {\n issueUpdate(id: $issueId, input: { assigneeId: $assigneeId }) {\n success\n issue {\n id\n identifier\n title\n assignee {\n id\n name\n }\n }\n }\n }\n `;\n\n const result = await this.graphql<{\n issueUpdate: {\n success: boolean;\n issue?: LinearIssue;\n };\n }>(mutation, { issueId, assigneeId });\n\n return result.issueUpdate;\n }\n\n /**\n * Update issue state (e.g., move to \"In Progress\")\n */\n async updateIssueState(\n issueId: string,\n stateId: string\n ): Promise<{ success: boolean; issue?: LinearIssue }> {\n const mutation = `\n mutation UpdateIssueState($issueId: String!, $stateId: String!) {\n issueUpdate(id: $issueId, input: { stateId: $stateId }) {\n success\n issue {\n id\n identifier\n title\n state {\n id\n name\n type\n }\n }\n }\n }\n `;\n\n const result = await this.graphql<{\n issueUpdate: {\n success: boolean;\n issue?: LinearIssue;\n };\n }>(mutation, { issueId, stateId });\n\n return result.issueUpdate;\n }\n\n /**\n * Get an issue by ID with team info\n */\n async getIssueById(issueId: string): Promise<LinearIssue | null> {\n const query = `\n query GetIssue($issueId: String!) {\n issue(id: $issueId) {\n id\n identifier\n title\n description\n state {\n id\n name\n type\n }\n priority\n assignee {\n id\n name\n email\n }\n estimate\n labels {\n nodes {\n id\n name\n }\n }\n team {\n id\n name\n }\n createdAt\n updatedAt\n url\n }\n }\n `;\n\n try {\n const result = await this.graphql<{\n issue: LinearIssue & { team: { id: string; name: string } };\n }>(query, { issueId });\n return result.issue;\n } catch {\n return null;\n }\n }\n\n /**\n * Start working on an issue (assign to self and move to In Progress)\n */\n async startIssue(issueId: string): Promise<{\n success: boolean;\n issue?: LinearIssue;\n error?: string;\n }> {\n try {\n // Get current user\n const user = await this.getViewer();\n\n // Get the issue to find its team\n const issue = await this.getIssueById(issueId);\n if (!issue) {\n return { success: false, error: 'Issue not found' };\n }\n\n // Assign to self\n const assignResult = await this.assignIssue(issueId, user.id);\n if (!assignResult.success) {\n return { success: false, error: 'Failed to assign issue' };\n }\n\n // Find the \"In Progress\" or \"started\" state for this issue's team\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const teamId = (issue as any).team?.id;\n if (teamId) {\n const states = await this.getWorkflowStates(teamId);\n const inProgressState = states.find(\n (s) =>\n s.type === 'started' || s.name.toLowerCase().includes('progress')\n );\n\n if (inProgressState) {\n await this.updateIssueState(issueId, inProgressState.id);\n }\n }\n\n return { success: true, issue: assignResult.issue };\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error',\n };\n }\n }\n}\n"],
5
+ "mappings": ";;;;AAKA,SAAS,cAAc;AACvB,SAAS,kBAAkB,iBAAiB;AAsDrC,MAAM,aAAa;AAAA,EAChB;AAAA,EACA;AAAA,EACA,iBAAiC;AAAA,IACvC,WAAW;AAAA;AAAA,IACX,SAAS,KAAK,IAAI,IAAI;AAAA,IACtB,YAAY;AAAA,EACd;AAAA,EACQ,eAA2C,CAAC;AAAA,EAC5C,oBAAoB;AAAA,EACpB,qBAAqB;AAAA;AAAA,EACrB,kBAAkB;AAAA,EAE1B,YAAY,QAAsB;AAChC,SAAK,SAAS;AACd,SAAK,UAAU,OAAO,WAAW;AAEjC,QAAI,CAAC,OAAO,QAAQ;AAClB,YAAM,IAAI;AAAA,QACR;AAAA,QACA,UAAU;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAc,mBAAkC;AAC9C,UAAM,MAAM,KAAK,IAAI;AAGrB,QAAI,KAAK,eAAe,aAAa,KAAK;AACxC,YAAM,WAAW,KAAK,eAAe,aAAa;AAClD,aAAO,KAAK,yBAAyB,KAAK,KAAK,WAAW,GAAI,CAAC,GAAG;AAClE,YAAM,KAAK,MAAM,QAAQ;AAAA,IAC3B;AAGA,QAAI,KAAK,eAAe,aAAa,GAAG;AACtC,UAAI,KAAK,eAAe,UAAU,KAAK;AACrC,cAAM,WAAW,KAAK,eAAe,UAAU;AAC/C,eAAO;AAAA,UACL,wCAAwC,KAAK,KAAK,WAAW,GAAI,C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O;AAAA,UAC7B,CAAC,MACC,EAAE,SAAS,aAAa,EAAE,KAAK,YAAY,EAAE,SAAS,UAAU;AAAA,QACpE;AAEA,YAAI,iBAAiB;AACnB,gBAAM,KAAK,iBAAiB,SAAS,gBAAgB,EAAE;AAAA,QACzD;AAAA,MACF;AAEA,aAAO,EAAE,SAAS,MAAM,OAAO,aAAa,MAAM;AAAA,IACpD,SAAS,OAAO;AACd,aAAO;AAAA,QACL,SAAS;AAAA,QACT,OAAO,iBAAiB,QAAQ,MAAM,UAAU;AAAA,MAClD;AAAA,IACF;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
@@ -4,6 +4,7 @@ const __filename = __fileURLToPath(import.meta.url);
4
4
  const __dirname = __pathDirname(__filename);
5
5
  import { LinearRestClient } from "./rest-client.js";
6
6
  import { logger } from "../../core/monitoring/logger.js";
7
+ import { IntegrationError, ErrorCode } from "../../core/errors/index.js";
7
8
  import chalk from "chalk";
8
9
  class LinearMigrator {
9
10
  sourceClient;
@@ -71,26 +72,37 @@ class LinearMigrator {
71
72
  taskMappings: []
72
73
  };
73
74
  try {
74
- console.log(chalk.yellow("\u{1F504} Starting Linear workspace migration..."));
75
+ console.log(chalk.yellow("Starting Linear workspace migration..."));
75
76
  const sourceTasks = await this.sourceClient.getAllTasks(true);
76
77
  result.totalTasks = sourceTasks.length;
77
- console.log(chalk.cyan(`\u{1F4CB} Found ${sourceTasks.length} tasks in source workspace`));
78
+ console.log(
79
+ chalk.cyan(`Found ${sourceTasks.length} tasks in source workspace`)
80
+ );
78
81
  let tasksToMigrate = sourceTasks;
79
82
  if (this.config.taskPrefix) {
80
83
  tasksToMigrate = sourceTasks.filter(
81
84
  (task) => task.identifier.startsWith(this.config.taskPrefix)
82
85
  );
83
- console.log(chalk.cyan(`\u{1F4CB} Filtered to ${tasksToMigrate.length} tasks with prefix "${this.config.taskPrefix}"`));
86
+ console.log(
87
+ chalk.cyan(
88
+ `Filtered to ${tasksToMigrate.length} tasks with prefix "${this.config.taskPrefix}"`
89
+ )
90
+ );
84
91
  }
85
92
  if (this.config.includeStates?.length) {
86
93
  tasksToMigrate = tasksToMigrate.filter(
87
94
  (task) => this.config.includeStates.includes(task.state.type)
88
95
  );
89
- console.log(chalk.cyan(`\u{1F4CB} Further filtered to ${tasksToMigrate.length} tasks matching states: ${this.config.includeStates.join(", ")}`));
96
+ const stateStr = this.config.includeStates.join(", ");
97
+ console.log(
98
+ chalk.cyan(
99
+ `Further filtered to ${tasksToMigrate.length} tasks matching states: ${stateStr}`
100
+ )
101
+ );
90
102
  }
91
103
  result.exported = tasksToMigrate.length;
92
104
  if (this.config.dryRun) {
93
- console.log(chalk.yellow("\u{1F50D} DRY RUN - No tasks will be created"));
105
+ console.log(chalk.yellow("DRY RUN - No tasks will be created"));
94
106
  tasksToMigrate.forEach((task) => {
95
107
  result.taskMappings.push({
96
108
  sourceId: task.id,
@@ -103,12 +115,18 @@ class LinearMigrator {
103
115
  return result;
104
116
  }
105
117
  const targetTeam = await this.targetClient.getTeam();
106
- console.log(chalk.cyan(`\u{1F3AF} Target team: ${targetTeam.name} (${targetTeam.key})`));
118
+ console.log(
119
+ chalk.cyan(`Target team: ${targetTeam.name} (${targetTeam.key})`)
120
+ );
107
121
  const batchSize = this.config.batchSize || 5;
108
122
  const delayMs = this.config.delayMs || 2e3;
109
123
  for (let i = 0; i < tasksToMigrate.length; i += batchSize) {
110
124
  const batch = tasksToMigrate.slice(i, i + batchSize);
111
- console.log(chalk.yellow(`\u{1F4E6} Processing batch ${Math.floor(i / batchSize) + 1}/${Math.ceil(tasksToMigrate.length / batchSize)}`));
125
+ console.log(
126
+ chalk.yellow(
127
+ `Processing batch ${Math.floor(i / batchSize) + 1}/${Math.ceil(tasksToMigrate.length / batchSize)}`
128
+ )
129
+ );
112
130
  for (const task of batch) {
113
131
  try {
114
132
  const newTask = await this.migrateTask(task, targetTeam.id);
@@ -120,17 +138,29 @@ class LinearMigrator {
120
138
  deleted: false
121
139
  };
122
140
  result.imported++;
123
- console.log(chalk.green(`\u2705 ${task.identifier} \u2192 ${newTask.identifier}: ${task.title}`));
141
+ console.log(
142
+ chalk.green(
143
+ `${task.identifier} \u2192 ${newTask.identifier}: ${task.title}`
144
+ )
145
+ );
124
146
  if (this.config.deleteFromSource) {
125
147
  try {
126
148
  await this.deleteTask(task.id);
127
149
  mapping.deleted = true;
128
150
  result.deleted++;
129
- console.log(chalk.gray(`\u{1F5D1}\uFE0F Deleted ${task.identifier} from source`));
151
+ console.log(
152
+ chalk.gray(`Deleted ${task.identifier} from source`)
153
+ );
130
154
  } catch (deleteError) {
131
155
  result.deleteFailed++;
132
- result.errors.push(`Delete failed for ${task.identifier}: ${deleteError.message}`);
133
- console.log(chalk.yellow(`\u26A0\uFE0F Failed to delete ${task.identifier} from source: ${deleteError.message}`));
156
+ result.errors.push(
157
+ `Delete failed for ${task.identifier}: ${deleteError.message}`
158
+ );
159
+ console.log(
160
+ chalk.yellow(
161
+ `Failed to delete ${task.identifier} from source: ${deleteError.message}`
162
+ )
163
+ );
134
164
  }
135
165
  }
136
166
  result.taskMappings.push(mapping);
@@ -143,11 +173,11 @@ class LinearMigrator {
143
173
  error: errorMsg
144
174
  });
145
175
  result.failed++;
146
- console.log(chalk.red(`\u274C ${task.identifier}: ${errorMsg}`));
176
+ console.log(chalk.red(`${task.identifier}: ${errorMsg}`));
147
177
  }
148
178
  }
149
179
  if (i + batchSize < tasksToMigrate.length) {
150
- console.log(chalk.gray(`\u23F3 Waiting ${delayMs}ms before next batch...`));
180
+ console.log(chalk.gray(`Waiting ${delayMs}ms before next batch...`));
151
181
  await this.delay(delayMs);
152
182
  }
153
183
  }
@@ -162,11 +192,11 @@ class LinearMigrator {
162
192
  */
163
193
  async migrateTask(sourceTask, targetTeamId) {
164
194
  const stateMapping = {
165
- "backlog": "backlog",
166
- "unstarted": "unstarted",
167
- "started": "started",
168
- "completed": "completed",
169
- "canceled": "canceled"
195
+ backlog: "backlog",
196
+ unstarted: "unstarted",
197
+ started: "started",
198
+ completed: "completed",
199
+ canceled: "canceled"
170
200
  };
171
201
  const createTaskQuery = `
172
202
  mutation CreateIssue($input: IssueCreateInput!) {
@@ -198,7 +228,11 @@ class LinearMigrator {
198
228
  };
199
229
  const response = await this.targetClient.makeRequest(createTaskQuery, { input: taskInput });
200
230
  if (!response.data?.issueCreate?.success) {
201
- throw new Error("Failed to create task in target workspace");
231
+ throw new IntegrationError(
232
+ "Failed to create task in target workspace",
233
+ ErrorCode.LINEAR_SYNC_FAILED,
234
+ { sourceTaskId: sourceTask.id, sourceIdentifier: sourceTask.identifier }
235
+ );
202
236
  }
203
237
  return response.data.issueCreate.issue;
204
238
  }
@@ -245,9 +279,15 @@ class LinearMigrator {
245
279
  }
246
280
  }
247
281
  `;
248
- const response = await this.sourceClient.makeRequest(deleteQuery, { id: taskId });
282
+ const response = await this.sourceClient.makeRequest(deleteQuery, {
283
+ id: taskId
284
+ });
249
285
  if (!response.data?.issueDelete?.success) {
250
- throw new Error("Failed to delete task from source workspace");
286
+ throw new IntegrationError(
287
+ "Failed to delete task from source workspace",
288
+ ErrorCode.LINEAR_SYNC_FAILED,
289
+ { taskId }
290
+ );
251
291
  }
252
292
  }
253
293
  /**
@@ -259,40 +299,58 @@ class LinearMigrator {
259
299
  }
260
300
  async function runMigration(config) {
261
301
  const migrator = new LinearMigrator(config);
262
- console.log(chalk.blue("\u{1F50D} Testing connections..."));
302
+ console.log(chalk.blue("Testing connections..."));
263
303
  const connectionTest = await migrator.testConnections();
264
304
  if (!connectionTest.source.success) {
265
- console.error(chalk.red(`\u274C Source connection failed: ${connectionTest.source.error}`));
305
+ console.error(
306
+ chalk.red(`Source connection failed: ${connectionTest.source.error}`)
307
+ );
266
308
  return;
267
309
  }
268
310
  if (!connectionTest.target.success) {
269
- console.error(chalk.red(`\u274C Target connection failed: ${connectionTest.target.error}`));
311
+ console.error(
312
+ chalk.red(`Target connection failed: ${connectionTest.target.error}`)
313
+ );
270
314
  return;
271
315
  }
272
- console.log(chalk.green("\u2705 Both connections successful"));
273
- console.log(chalk.cyan(`\u{1F4E4} Source: ${connectionTest.source.info.user.name} @ ${connectionTest.source.info.team.name}`));
274
- console.log(chalk.cyan(`\u{1F4E5} Target: ${connectionTest.target.info.user.name} @ ${connectionTest.target.info.team.name}`));
316
+ console.log(chalk.green("Both connections successful"));
317
+ console.log(
318
+ chalk.cyan(
319
+ `Source: ${connectionTest.source.info.user.name} @ ${connectionTest.source.info.team.name}`
320
+ )
321
+ );
322
+ console.log(
323
+ chalk.cyan(
324
+ `Target: ${connectionTest.target.info.user.name} @ ${connectionTest.target.info.team.name}`
325
+ )
326
+ );
275
327
  const result = await migrator.migrate();
276
- console.log(chalk.blue("\n\u{1F4CA} Migration Summary:"));
328
+ console.log(chalk.blue("\nMigration Summary:"));
277
329
  console.log(` Total tasks: ${result.totalTasks}`);
278
330
  console.log(` Exported: ${result.exported}`);
279
- console.log(chalk.green(` \u2705 Imported: ${result.imported}`));
280
- console.log(chalk.red(` \u274C Failed: ${result.failed}`));
331
+ console.log(chalk.green(` Imported: ${result.imported}`));
332
+ console.log(chalk.red(` Failed: ${result.failed}`));
281
333
  if (config.deleteFromSource) {
282
- console.log(chalk.gray(` \u{1F5D1}\uFE0F Deleted: ${result.deleted}`));
334
+ console.log(chalk.gray(` Deleted: ${result.deleted}`));
283
335
  if (result.deleteFailed > 0) {
284
- console.log(chalk.yellow(` \u26A0\uFE0F Delete failed: ${result.deleteFailed}`));
336
+ console.log(chalk.yellow(` Delete failed: ${result.deleteFailed}`));
285
337
  }
286
338
  }
287
339
  if (result.errors.length > 0) {
288
- console.log(chalk.red("\n\u274C Errors:"));
340
+ console.log(chalk.red("\nErrors:"));
289
341
  result.errors.forEach((error) => console.log(chalk.red(` - ${error}`)));
290
342
  }
291
343
  if (result.imported > 0) {
292
- console.log(chalk.green(`
293
- \u{1F389} Migration completed! ${result.imported} tasks migrated successfully.`));
344
+ console.log(
345
+ chalk.green(
346
+ `
347
+ Migration completed! ${result.imported} tasks migrated successfully.`
348
+ )
349
+ );
294
350
  if (config.deleteFromSource && result.deleted > 0) {
295
- console.log(chalk.gray(` ${result.deleted} tasks deleted from source workspace.`));
351
+ console.log(
352
+ chalk.gray(` ${result.deleted} tasks deleted from source workspace.`)
353
+ );
296
354
  }
297
355
  }
298
356
  }