@stackmemoryai/stackmemory 0.5.29 → 0.5.31

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 (42) hide show
  1. package/README.md +53 -32
  2. package/dist/core/database/batch-operations.js +29 -4
  3. package/dist/core/database/batch-operations.js.map +2 -2
  4. package/dist/core/database/connection-pool.js +13 -2
  5. package/dist/core/database/connection-pool.js.map +2 -2
  6. package/dist/core/database/migration-manager.js +130 -34
  7. package/dist/core/database/migration-manager.js.map +2 -2
  8. package/dist/core/database/paradedb-adapter.js +23 -7
  9. package/dist/core/database/paradedb-adapter.js.map +2 -2
  10. package/dist/core/database/query-router.js +8 -3
  11. package/dist/core/database/query-router.js.map +2 -2
  12. package/dist/core/database/sqlite-adapter.js +152 -33
  13. package/dist/core/database/sqlite-adapter.js.map +2 -2
  14. package/dist/integrations/linear/auth.js +34 -20
  15. package/dist/integrations/linear/auth.js.map +2 -2
  16. package/dist/integrations/linear/auto-sync.js +18 -8
  17. package/dist/integrations/linear/auto-sync.js.map +2 -2
  18. package/dist/integrations/linear/client.js +42 -9
  19. package/dist/integrations/linear/client.js.map +2 -2
  20. package/dist/integrations/linear/migration.js +94 -36
  21. package/dist/integrations/linear/migration.js.map +2 -2
  22. package/dist/integrations/linear/oauth-server.js +77 -34
  23. package/dist/integrations/linear/oauth-server.js.map +2 -2
  24. package/dist/integrations/linear/rest-client.js +13 -3
  25. package/dist/integrations/linear/rest-client.js.map +2 -2
  26. package/dist/integrations/linear/sync-service.js +18 -15
  27. package/dist/integrations/linear/sync-service.js.map +2 -2
  28. package/dist/integrations/linear/sync.js +12 -4
  29. package/dist/integrations/linear/sync.js.map +2 -2
  30. package/dist/integrations/linear/unified-sync.js +33 -8
  31. package/dist/integrations/linear/unified-sync.js.map +2 -2
  32. package/dist/integrations/linear/webhook-handler.js +5 -1
  33. package/dist/integrations/linear/webhook-handler.js.map +2 -2
  34. package/dist/integrations/linear/webhook-server.js +7 -7
  35. package/dist/integrations/linear/webhook-server.js.map +2 -2
  36. package/dist/integrations/linear/webhook.js +9 -2
  37. package/dist/integrations/linear/webhook.js.map +2 -2
  38. package/dist/integrations/mcp/schemas.js +147 -0
  39. package/dist/integrations/mcp/schemas.js.map +7 -0
  40. package/dist/integrations/mcp/server.js +19 -3
  41. package/dist/integrations/mcp/server.js.map +2 -2
  42. package/package.json +1 -1
@@ -6,17 +6,7 @@ import { createHash, randomBytes } from "crypto";
6
6
  import { readFileSync, writeFileSync, existsSync } from "fs";
7
7
  import { join } from "path";
8
8
  import { logger } from "../../core/monitoring/logger.js";
9
- function getEnv(key, defaultValue) {
10
- const value = process.env[key];
11
- if (value === void 0) {
12
- if (defaultValue !== void 0) return defaultValue;
13
- throw new Error(`Environment variable ${key} is required`);
14
- }
15
- return value;
16
- }
17
- function getOptionalEnv(key) {
18
- return process.env[key];
19
- }
9
+ import { IntegrationError, ErrorCode } from "../../core/errors/index.js";
20
10
  class LinearAuthManager {
21
11
  configPath;
22
12
  tokensPath;
@@ -61,7 +51,10 @@ class LinearAuthManager {
61
51
  */
62
52
  generateAuthUrl(state) {
63
53
  if (!this.config) {
64
- throw new Error("Linear OAuth configuration not loaded");
54
+ throw new IntegrationError(
55
+ "Linear OAuth configuration not loaded",
56
+ ErrorCode.LINEAR_AUTH_FAILED
57
+ );
65
58
  }
66
59
  const codeVerifier = randomBytes(32).toString("base64url");
67
60
  const codeChallenge = createHash("sha256").update(codeVerifier).digest("base64url");
@@ -86,7 +79,10 @@ class LinearAuthManager {
86
79
  */
87
80
  async exchangeCodeForToken(authCode, codeVerifier) {
88
81
  if (!this.config) {
89
- throw new Error("Linear OAuth configuration not loaded");
82
+ throw new IntegrationError(
83
+ "Linear OAuth configuration not loaded",
84
+ ErrorCode.LINEAR_AUTH_FAILED
85
+ );
90
86
  }
91
87
  const tokenUrl = "https://api.linear.app/oauth/token";
92
88
  const body = new URLSearchParams({
@@ -107,7 +103,11 @@ class LinearAuthManager {
107
103
  });
108
104
  if (!response.ok) {
109
105
  const errorText = await response.text();
110
- throw new Error(`Token exchange failed: ${response.status} ${errorText}`);
106
+ throw new IntegrationError(
107
+ `Token exchange failed: ${response.status}`,
108
+ ErrorCode.LINEAR_AUTH_FAILED,
109
+ { status: response.status, body: errorText }
110
+ );
111
111
  }
112
112
  const result = await response.json();
113
113
  const expiresAt = Date.now() + result.expiresIn * 1e3;
@@ -125,11 +125,17 @@ class LinearAuthManager {
125
125
  */
126
126
  async refreshAccessToken() {
127
127
  if (!this.config) {
128
- throw new Error("Linear OAuth configuration not loaded");
128
+ throw new IntegrationError(
129
+ "Linear OAuth configuration not loaded",
130
+ ErrorCode.LINEAR_AUTH_FAILED
131
+ );
129
132
  }
130
133
  const currentTokens = this.loadTokens();
131
134
  if (!currentTokens?.refreshToken) {
132
- throw new Error("No refresh token available");
135
+ throw new IntegrationError(
136
+ "No refresh token available",
137
+ ErrorCode.LINEAR_AUTH_FAILED
138
+ );
133
139
  }
134
140
  const tokenUrl = "https://api.linear.app/oauth/token";
135
141
  const body = new URLSearchParams({
@@ -148,7 +154,11 @@ class LinearAuthManager {
148
154
  });
149
155
  if (!response.ok) {
150
156
  const errorText = await response.text();
151
- throw new Error(`Token refresh failed: ${response.status} ${errorText}`);
157
+ throw new IntegrationError(
158
+ `Token refresh failed: ${response.status}`,
159
+ ErrorCode.LINEAR_AUTH_FAILED,
160
+ { status: response.status, body: errorText }
161
+ );
152
162
  }
153
163
  const result = await response.json();
154
164
  const tokens = {
@@ -166,7 +176,10 @@ class LinearAuthManager {
166
176
  async getValidToken() {
167
177
  const tokens = this.loadTokens();
168
178
  if (!tokens) {
169
- throw new Error("No Linear tokens found. Please complete OAuth setup.");
179
+ throw new IntegrationError(
180
+ "No Linear tokens found. Please complete OAuth setup.",
181
+ ErrorCode.LINEAR_AUTH_FAILED
182
+ );
170
183
  }
171
184
  const fiveMinutes = 5 * 60 * 1e3;
172
185
  if (tokens.expiresAt - Date.now() < fiveMinutes) {
@@ -270,8 +283,9 @@ class LinearOAuthSetup {
270
283
  try {
271
284
  const codeVerifier = process.env["_LINEAR_CODE_VERIFIER"];
272
285
  if (!codeVerifier) {
273
- throw new Error(
274
- "Code verifier not found. Please restart the setup process."
286
+ throw new IntegrationError(
287
+ "Code verifier not found. Please restart the setup process.",
288
+ ErrorCode.LINEAR_AUTH_FAILED
275
289
  );
276
290
  }
277
291
  await this.authManager.exchangeCodeForToken(authCode, codeVerifier);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/integrations/linear/auth.ts"],
4
- "sourcesContent": ["/**\n * Linear OAuth Authentication Setup\n * Handles initial OAuth flow and token management for Linear integration\n */\n\nimport { createHash, randomBytes } from 'crypto';\nimport { readFileSync, writeFileSync, existsSync } from 'fs';\nimport { join } from 'path';\nimport { logger } from '../../core/monitoring/logger.js';\n// Type-safe environment variable access\nfunction getEnv(key: string, defaultValue?: string): string {\n const value = process.env[key];\n if (value === undefined) {\n if (defaultValue !== undefined) return defaultValue;\n throw new Error(`Environment variable ${key} is required`);\n }\n return value;\n}\n\nfunction getOptionalEnv(key: string): string | undefined {\n return process.env[key];\n}\n\n\nexport interface LinearAuthConfig {\n clientId: string;\n clientSecret: string;\n redirectUri: string;\n scopes: string[];\n}\n\nexport interface LinearTokens {\n accessToken: string;\n refreshToken?: string;\n expiresAt: number; // Unix timestamp\n scope: string[];\n}\n\nexport interface LinearAuthResult {\n accessToken: string;\n refreshToken?: string;\n expiresIn: number;\n scope: string;\n tokenType: string;\n}\n\nexport class LinearAuthManager {\n private configPath: string;\n private tokensPath: string;\n private config?: LinearAuthConfig;\n\n constructor(projectRoot: string) {\n const configDir = join(projectRoot, '.stackmemory');\n this.configPath = join(configDir, 'linear-config.json');\n this.tokensPath = join(configDir, 'linear-tokens.json');\n }\n\n /**\n * Check if Linear integration is configured\n */\n isConfigured(): boolean {\n return existsSync(this.configPath) && existsSync(this.tokensPath);\n }\n\n /**\n * Save OAuth application configuration\n */\n saveConfig(config: LinearAuthConfig): void {\n writeFileSync(this.configPath, JSON.stringify(config, null, 2));\n this.config = config;\n logger.info('Linear OAuth configuration saved');\n }\n\n /**\n * Load OAuth configuration\n */\n loadConfig(): LinearAuthConfig | null {\n if (!existsSync(this.configPath)) {\n return null;\n }\n\n try {\n const configData = readFileSync(this.configPath, 'utf8');\n this.config = JSON.parse(configData);\n return this.config!;\n } catch (error: unknown) {\n logger.error('Failed to load Linear configuration:', error as Error);\n return null;\n }\n }\n\n /**\n * Generate OAuth authorization URL with PKCE\n */\n generateAuthUrl(state?: string): { url: string; codeVerifier: string } {\n if (!this.config) {\n throw new Error('Linear OAuth configuration not loaded');\n }\n\n // Generate PKCE parameters\n const codeVerifier = randomBytes(32).toString('base64url');\n const codeChallenge = createHash('sha256')\n .update(codeVerifier)\n .digest('base64url');\n\n const params = new URLSearchParams({\n client_id: this.config.clientId,\n redirect_uri: this.config.redirectUri,\n response_type: 'code',\n scope: this.config.scopes.join(' '),\n code_challenge: codeChallenge,\n code_challenge_method: 'S256',\n actor: 'app', // Enable actor authorization for service accounts\n });\n\n if (state) {\n params.set('state', state);\n }\n\n const authUrl = `https://linear.app/oauth/authorize?${params.toString()}`;\n\n return { url: authUrl, codeVerifier };\n }\n\n /**\n * Exchange authorization code for access token\n */\n async exchangeCodeForToken(\n authCode: string,\n codeVerifier: string\n ): Promise<LinearTokens> {\n if (!this.config) {\n throw new Error('Linear OAuth configuration not loaded');\n }\n\n const tokenUrl = 'https://api.linear.app/oauth/token';\n\n const body = new URLSearchParams({\n grant_type: 'authorization_code',\n client_id: this.config.clientId,\n client_secret: this.config.clientSecret,\n redirect_uri: this.config.redirectUri,\n code: authCode,\n code_verifier: codeVerifier,\n });\n\n const response = await fetch(tokenUrl, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n Accept: 'application/json',\n },\n body: body.toString(),\n });\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new Error(`Token exchange failed: ${response.status} ${errorText}`);\n }\n\n const result = (await response.json()) as LinearAuthResult;\n\n // Calculate expiration time (tokens expire in 24 hours)\n const expiresAt = Date.now() + result.expiresIn * 1000;\n\n const tokens: LinearTokens = {\n accessToken: result.accessToken,\n refreshToken: result.refreshToken,\n expiresAt,\n scope: result.scope.split(' '),\n };\n\n this.saveTokens(tokens);\n return tokens;\n }\n\n /**\n * Refresh access token using refresh token\n */\n async refreshAccessToken(): Promise<LinearTokens> {\n if (!this.config) {\n throw new Error('Linear OAuth configuration not loaded');\n }\n\n const currentTokens = this.loadTokens();\n if (!currentTokens?.refreshToken) {\n throw new Error('No refresh token available');\n }\n\n const tokenUrl = 'https://api.linear.app/oauth/token';\n\n const body = new URLSearchParams({\n grant_type: 'refresh_token',\n client_id: this.config.clientId,\n client_secret: this.config.clientSecret,\n refresh_token: currentTokens.refreshToken,\n });\n\n const response = await fetch(tokenUrl, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n Accept: 'application/json',\n },\n body: body.toString(),\n });\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new Error(`Token refresh failed: ${response.status} ${errorText}`);\n }\n\n const result = (await response.json()) as LinearAuthResult;\n\n const tokens: LinearTokens = {\n accessToken: result.accessToken,\n refreshToken: result.refreshToken || currentTokens.refreshToken,\n expiresAt: Date.now() + result.expiresIn * 1000,\n scope: result.scope.split(' '),\n };\n\n this.saveTokens(tokens);\n return tokens;\n }\n\n /**\n * Get valid access token (refresh if needed)\n */\n async getValidToken(): Promise<string> {\n const tokens = this.loadTokens();\n if (!tokens) {\n throw new Error('No Linear tokens found. Please complete OAuth setup.');\n }\n\n // Check if token expires in next 5 minutes\n const fiveMinutes = 5 * 60 * 1000;\n if (tokens.expiresAt - Date.now() < fiveMinutes) {\n logger.info('Linear token expiring soon, refreshing...');\n const newTokens = await this.refreshAccessToken();\n return newTokens.accessToken;\n }\n\n return tokens.accessToken;\n }\n\n /**\n * Save tokens to file\n */\n private saveTokens(tokens: LinearTokens): void {\n writeFileSync(this.tokensPath, JSON.stringify(tokens, null, 2));\n logger.info('Linear tokens saved');\n }\n\n /**\n * Load tokens from file\n */\n loadTokens(): LinearTokens | null {\n if (!existsSync(this.tokensPath)) {\n return null;\n }\n\n try {\n const tokensData = readFileSync(this.tokensPath, 'utf8');\n return JSON.parse(tokensData);\n } catch (error: unknown) {\n logger.error('Failed to load Linear tokens:', error as Error);\n return null;\n }\n }\n\n /**\n * Clear stored tokens and config\n */\n clearAuth(): void {\n if (existsSync(this.tokensPath)) {\n writeFileSync(this.tokensPath, '');\n }\n if (existsSync(this.configPath)) {\n writeFileSync(this.configPath, '');\n }\n logger.info('Linear authentication cleared');\n }\n}\n\n/**\n * Default Linear OAuth scopes for task management\n */\nexport const DEFAULT_LINEAR_SCOPES = [\n 'read', // Read issues, projects, teams\n 'write', // Create and update issues\n 'admin', // Manage team settings and workflows\n];\n\n/**\n * Linear OAuth setup helper\n */\nexport class LinearOAuthSetup {\n private authManager: LinearAuthManager;\n\n constructor(projectRoot: string) {\n this.authManager = new LinearAuthManager(projectRoot);\n }\n\n /**\n * Interactive setup for Linear OAuth\n */\n async setupInteractive(): Promise<{\n authUrl: string;\n instructions: string[];\n }> {\n // For now, we'll provide manual setup instructions\n // In a full implementation, this could open a browser or use a local server\n\n const config: LinearAuthConfig = {\n clientId: process.env['LINEAR_CLIENT_ID'] || '',\n clientSecret: process.env['LINEAR_CLIENT_SECRET'] || '',\n redirectUri:\n process.env['LINEAR_REDIRECT_URI'] ||\n 'http://localhost:3456/auth/linear/callback',\n scopes: DEFAULT_LINEAR_SCOPES,\n };\n\n if (!config.clientId || !config.clientSecret) {\n return {\n authUrl: '',\n instructions: [\n '1. Create a Linear OAuth application at https://linear.app/settings/api',\n '2. Set redirect URI to: http://localhost:3456/auth/linear/callback',\n '3. Copy your Client ID and Client Secret',\n '4. Set environment variables:',\n ' export LINEAR_CLIENT_ID=\"your_client_id\"',\n ' export LINEAR_CLIENT_SECRET=\"your_client_secret\"',\n '5. Re-run this setup command',\n ],\n };\n }\n\n this.authManager.saveConfig(config);\n\n const { url, codeVerifier } = this.authManager.generateAuthUrl();\n\n // Store code verifier temporarily (in a real app, this would be in a secure session store)\n process.env['_LINEAR_CODE_VERIFIER'] = codeVerifier;\n\n return {\n authUrl: url,\n instructions: [\n '1. Open this URL in your browser:',\n url,\n '',\n '2. Approve the StackMemory integration',\n '3. Copy the authorization code from the redirect URL',\n '4. Run: stackmemory linear authorize <code>',\n ],\n };\n }\n\n /**\n * Complete OAuth flow with authorization code\n */\n async completeAuth(authCode: string): Promise<boolean> {\n try {\n const codeVerifier = process.env['_LINEAR_CODE_VERIFIER'];\n if (!codeVerifier) {\n throw new Error(\n 'Code verifier not found. Please restart the setup process.'\n );\n }\n\n await this.authManager.exchangeCodeForToken(authCode, codeVerifier);\n delete process.env['_LINEAR_CODE_VERIFIER'];\n\n logger.info('Linear OAuth setup completed successfully!');\n return true;\n } catch (error: unknown) {\n logger.error('Failed to complete Linear OAuth setup:', error as Error);\n return false;\n }\n }\n\n /**\n * Test the Linear connection\n */\n async testConnection(): Promise<boolean> {\n try {\n const token = await this.authManager.getValidToken();\n\n // Test with a simple GraphQL query\n const response = await fetch('https://api.linear.app/graphql', {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${token}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n query: 'query { viewer { id name email } }',\n }),\n });\n\n if (response.ok) {\n const result = (await response.json()) as {\n data?: { viewer?: { id: string; name: string; email: string } };\n };\n if (result.data?.viewer) {\n logger.info(\n `Connected to Linear as: ${result.data.viewer.name} (${result.data.viewer.email})`\n );\n return true;\n }\n }\n\n return false;\n } catch (error: unknown) {\n logger.error('Linear connection test failed:', error as Error);\n return false;\n }\n }\n}\n"],
5
- "mappings": ";;;;AAKA,SAAS,YAAY,mBAAmB;AACxC,SAAS,cAAc,eAAe,kBAAkB;AACxD,SAAS,YAAY;AACrB,SAAS,cAAc;AAEvB,SAAS,OAAO,KAAa,cAA+B;A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S,IAAI;AACf,cAAM,SAAU,MAAM,SAAS,KAAK;AAGpC,YAAI,OAAO,MAAM,QAAQ;AACvB,iBAAO;AAAA,YACL,2BAA2B,OAAO,KAAK,OAAO,IAAI,KAAK,OAAO,KAAK,OAAO,KAAK;AAAA,UACjF;AACA,iBAAO;AAAA,QACT;AAAA,MACF;AAEA,aAAO;AAAA,IACT,SAAS,OAAgB;AACvB,aAAO,MAAM,kCAAkC,KAAc;AAC7D,aAAO;AAAA,IACT;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["/**\n * Linear OAuth Authentication Setup\n * Handles initial OAuth flow and token management for Linear integration\n */\n\nimport { createHash, randomBytes } from 'crypto';\nimport { readFileSync, writeFileSync, existsSync } from 'fs';\nimport { join } from 'path';\nimport { logger } from '../../core/monitoring/logger.js';\nimport { IntegrationError, ErrorCode } from '../../core/errors/index.js';\n\nexport interface LinearAuthConfig {\n clientId: string;\n clientSecret: string;\n redirectUri: string;\n scopes: string[];\n}\n\nexport interface LinearTokens {\n accessToken: string;\n refreshToken?: string;\n expiresAt: number; // Unix timestamp\n scope: string[];\n}\n\nexport interface LinearAuthResult {\n accessToken: string;\n refreshToken?: string;\n expiresIn: number;\n scope: string;\n tokenType: string;\n}\n\nexport class LinearAuthManager {\n private configPath: string;\n private tokensPath: string;\n private config?: LinearAuthConfig;\n\n constructor(projectRoot: string) {\n const configDir = join(projectRoot, '.stackmemory');\n this.configPath = join(configDir, 'linear-config.json');\n this.tokensPath = join(configDir, 'linear-tokens.json');\n }\n\n /**\n * Check if Linear integration is configured\n */\n isConfigured(): boolean {\n return existsSync(this.configPath) && existsSync(this.tokensPath);\n }\n\n /**\n * Save OAuth application configuration\n */\n saveConfig(config: LinearAuthConfig): void {\n writeFileSync(this.configPath, JSON.stringify(config, null, 2));\n this.config = config;\n logger.info('Linear OAuth configuration saved');\n }\n\n /**\n * Load OAuth configuration\n */\n loadConfig(): LinearAuthConfig | null {\n if (!existsSync(this.configPath)) {\n return null;\n }\n\n try {\n const configData = readFileSync(this.configPath, 'utf8');\n this.config = JSON.parse(configData);\n return this.config!;\n } catch (error: unknown) {\n logger.error('Failed to load Linear configuration:', error as Error);\n return null;\n }\n }\n\n /**\n * Generate OAuth authorization URL with PKCE\n */\n generateAuthUrl(state?: string): { url: string; codeVerifier: string } {\n if (!this.config) {\n throw new IntegrationError(\n 'Linear OAuth configuration not loaded',\n ErrorCode.LINEAR_AUTH_FAILED\n );\n }\n\n // Generate PKCE parameters\n const codeVerifier = randomBytes(32).toString('base64url');\n const codeChallenge = createHash('sha256')\n .update(codeVerifier)\n .digest('base64url');\n\n const params = new URLSearchParams({\n client_id: this.config.clientId,\n redirect_uri: this.config.redirectUri,\n response_type: 'code',\n scope: this.config.scopes.join(' '),\n code_challenge: codeChallenge,\n code_challenge_method: 'S256',\n actor: 'app', // Enable actor authorization for service accounts\n });\n\n if (state) {\n params.set('state', state);\n }\n\n const authUrl = `https://linear.app/oauth/authorize?${params.toString()}`;\n\n return { url: authUrl, codeVerifier };\n }\n\n /**\n * Exchange authorization code for access token\n */\n async exchangeCodeForToken(\n authCode: string,\n codeVerifier: string\n ): Promise<LinearTokens> {\n if (!this.config) {\n throw new IntegrationError(\n 'Linear OAuth configuration not loaded',\n ErrorCode.LINEAR_AUTH_FAILED\n );\n }\n\n const tokenUrl = 'https://api.linear.app/oauth/token';\n\n const body = new URLSearchParams({\n grant_type: 'authorization_code',\n client_id: this.config.clientId,\n client_secret: this.config.clientSecret,\n redirect_uri: this.config.redirectUri,\n code: authCode,\n code_verifier: codeVerifier,\n });\n\n const response = await fetch(tokenUrl, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n Accept: 'application/json',\n },\n body: body.toString(),\n });\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new IntegrationError(\n `Token exchange failed: ${response.status}`,\n ErrorCode.LINEAR_AUTH_FAILED,\n { status: response.status, body: errorText }\n );\n }\n\n const result = (await response.json()) as LinearAuthResult;\n\n // Calculate expiration time (tokens expire in 24 hours)\n const expiresAt = Date.now() + result.expiresIn * 1000;\n\n const tokens: LinearTokens = {\n accessToken: result.accessToken,\n refreshToken: result.refreshToken,\n expiresAt,\n scope: result.scope.split(' '),\n };\n\n this.saveTokens(tokens);\n return tokens;\n }\n\n /**\n * Refresh access token using refresh token\n */\n async refreshAccessToken(): Promise<LinearTokens> {\n if (!this.config) {\n throw new IntegrationError(\n 'Linear OAuth configuration not loaded',\n ErrorCode.LINEAR_AUTH_FAILED\n );\n }\n\n const currentTokens = this.loadTokens();\n if (!currentTokens?.refreshToken) {\n throw new IntegrationError(\n 'No refresh token available',\n ErrorCode.LINEAR_AUTH_FAILED\n );\n }\n\n const tokenUrl = 'https://api.linear.app/oauth/token';\n\n const body = new URLSearchParams({\n grant_type: 'refresh_token',\n client_id: this.config.clientId,\n client_secret: this.config.clientSecret,\n refresh_token: currentTokens.refreshToken,\n });\n\n const response = await fetch(tokenUrl, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n Accept: 'application/json',\n },\n body: body.toString(),\n });\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new IntegrationError(\n `Token refresh failed: ${response.status}`,\n ErrorCode.LINEAR_AUTH_FAILED,\n { status: response.status, body: errorText }\n );\n }\n\n const result = (await response.json()) as LinearAuthResult;\n\n const tokens: LinearTokens = {\n accessToken: result.accessToken,\n refreshToken: result.refreshToken || currentTokens.refreshToken,\n expiresAt: Date.now() + result.expiresIn * 1000,\n scope: result.scope.split(' '),\n };\n\n this.saveTokens(tokens);\n return tokens;\n }\n\n /**\n * Get valid access token (refresh if needed)\n */\n async getValidToken(): Promise<string> {\n const tokens = this.loadTokens();\n if (!tokens) {\n throw new IntegrationError(\n 'No Linear tokens found. Please complete OAuth setup.',\n ErrorCode.LINEAR_AUTH_FAILED\n );\n }\n\n // Check if token expires in next 5 minutes\n const fiveMinutes = 5 * 60 * 1000;\n if (tokens.expiresAt - Date.now() < fiveMinutes) {\n logger.info('Linear token expiring soon, refreshing...');\n const newTokens = await this.refreshAccessToken();\n return newTokens.accessToken;\n }\n\n return tokens.accessToken;\n }\n\n /**\n * Save tokens to file\n */\n private saveTokens(tokens: LinearTokens): void {\n writeFileSync(this.tokensPath, JSON.stringify(tokens, null, 2));\n logger.info('Linear tokens saved');\n }\n\n /**\n * Load tokens from file\n */\n loadTokens(): LinearTokens | null {\n if (!existsSync(this.tokensPath)) {\n return null;\n }\n\n try {\n const tokensData = readFileSync(this.tokensPath, 'utf8');\n return JSON.parse(tokensData);\n } catch (error: unknown) {\n logger.error('Failed to load Linear tokens:', error as Error);\n return null;\n }\n }\n\n /**\n * Clear stored tokens and config\n */\n clearAuth(): void {\n if (existsSync(this.tokensPath)) {\n writeFileSync(this.tokensPath, '');\n }\n if (existsSync(this.configPath)) {\n writeFileSync(this.configPath, '');\n }\n logger.info('Linear authentication cleared');\n }\n}\n\n/**\n * Default Linear OAuth scopes for task management\n */\nexport const DEFAULT_LINEAR_SCOPES = [\n 'read', // Read issues, projects, teams\n 'write', // Create and update issues\n 'admin', // Manage team settings and workflows\n];\n\n/**\n * Linear OAuth setup helper\n */\nexport class LinearOAuthSetup {\n private authManager: LinearAuthManager;\n\n constructor(projectRoot: string) {\n this.authManager = new LinearAuthManager(projectRoot);\n }\n\n /**\n * Interactive setup for Linear OAuth\n */\n async setupInteractive(): Promise<{\n authUrl: string;\n instructions: string[];\n }> {\n // For now, we'll provide manual setup instructions\n // In a full implementation, this could open a browser or use a local server\n\n const config: LinearAuthConfig = {\n clientId: process.env['LINEAR_CLIENT_ID'] || '',\n clientSecret: process.env['LINEAR_CLIENT_SECRET'] || '',\n redirectUri:\n process.env['LINEAR_REDIRECT_URI'] ||\n 'http://localhost:3456/auth/linear/callback',\n scopes: DEFAULT_LINEAR_SCOPES,\n };\n\n if (!config.clientId || !config.clientSecret) {\n return {\n authUrl: '',\n instructions: [\n '1. Create a Linear OAuth application at https://linear.app/settings/api',\n '2. Set redirect URI to: http://localhost:3456/auth/linear/callback',\n '3. Copy your Client ID and Client Secret',\n '4. Set environment variables:',\n ' export LINEAR_CLIENT_ID=\"your_client_id\"',\n ' export LINEAR_CLIENT_SECRET=\"your_client_secret\"',\n '5. Re-run this setup command',\n ],\n };\n }\n\n this.authManager.saveConfig(config);\n\n const { url, codeVerifier } = this.authManager.generateAuthUrl();\n\n // Store code verifier temporarily (in a real app, this would be in a secure session store)\n process.env['_LINEAR_CODE_VERIFIER'] = codeVerifier;\n\n return {\n authUrl: url,\n instructions: [\n '1. Open this URL in your browser:',\n url,\n '',\n '2. Approve the StackMemory integration',\n '3. Copy the authorization code from the redirect URL',\n '4. Run: stackmemory linear authorize <code>',\n ],\n };\n }\n\n /**\n * Complete OAuth flow with authorization code\n */\n async completeAuth(authCode: string): Promise<boolean> {\n try {\n const codeVerifier = process.env['_LINEAR_CODE_VERIFIER'];\n if (!codeVerifier) {\n throw new IntegrationError(\n 'Code verifier not found. Please restart the setup process.',\n ErrorCode.LINEAR_AUTH_FAILED\n );\n }\n\n await this.authManager.exchangeCodeForToken(authCode, codeVerifier);\n delete process.env['_LINEAR_CODE_VERIFIER'];\n\n logger.info('Linear OAuth setup completed successfully!');\n return true;\n } catch (error: unknown) {\n logger.error('Failed to complete Linear OAuth setup:', error as Error);\n return false;\n }\n }\n\n /**\n * Test the Linear connection\n */\n async testConnection(): Promise<boolean> {\n try {\n const token = await this.authManager.getValidToken();\n\n // Test with a simple GraphQL query\n const response = await fetch('https://api.linear.app/graphql', {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${token}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n query: 'query { viewer { id name email } }',\n }),\n });\n\n if (response.ok) {\n const result = (await response.json()) as {\n data?: { viewer?: { id: string; name: string; email: string } };\n };\n if (result.data?.viewer) {\n logger.info(\n `Connected to Linear as: ${result.data.viewer.name} (${result.data.viewer.email})`\n );\n return true;\n }\n }\n\n return false;\n } catch (error: unknown) {\n logger.error('Linear connection test failed:', error as Error);\n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kC;AAAA,QAC7D,QAAQ;AAAA,QACR,SAAS;AAAA,UACP,eAAe,UAAU,KAAK;AAAA,UAC9B,gBAAgB;AAAA,QAClB;AAAA,QACA,MAAM,KAAK,UAAU;AAAA,UACnB,OAAO;AAAA,QACT,CAAC;AAAA,MACH,CAAC;AAED,UAAI,SAAS,IAAI;AACf,cAAM,SAAU,MAAM,SAAS,KAAK;AAGpC,YAAI,OAAO,MAAM,QAAQ;AACvB,iBAAO;AAAA,YACL,2BAA2B,OAAO,KAAK,OAAO,IAAI,KAAK,OAAO,KAAK,OAAO,KAAK;AAAA,UACjF;AACA,iBAAO;AAAA,QACT;AAAA,MACF;AAEA,aAAO;AAAA,IACT,SAAS,OAAgB;AACvB,aAAO,MAAM,kCAAkC,KAAc;AAC7D,aAAO;AAAA,IACT;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
@@ -7,6 +7,7 @@ import { LinearTaskManager } from "../../features/tasks/linear-task-manager.js";
7
7
  import { LinearAuthManager } from "./auth.js";
8
8
  import { LinearSyncEngine, DEFAULT_SYNC_CONFIG } from "./sync.js";
9
9
  import { LinearConfigManager } from "./config.js";
10
+ import { IntegrationError, ErrorCode } from "../../core/errors/index.js";
10
11
  import Database from "better-sqlite3";
11
12
  import { join } from "path";
12
13
  import { existsSync } from "fs";
@@ -50,14 +51,16 @@ class LinearAutoSyncService {
50
51
  try {
51
52
  const authManager = new LinearAuthManager(this.projectRoot);
52
53
  if (!authManager.isConfigured()) {
53
- throw new Error(
54
- 'Linear integration not configured. Run "stackmemory linear setup" first.'
54
+ throw new IntegrationError(
55
+ 'Linear integration not configured. Run "stackmemory linear setup" first.',
56
+ ErrorCode.LINEAR_AUTH_FAILED
55
57
  );
56
58
  }
57
59
  const dbPath = join(this.projectRoot, ".stackmemory", "context.db");
58
60
  if (!existsSync(dbPath)) {
59
- throw new Error(
60
- 'StackMemory not initialized. Run "stackmemory init" first.'
61
+ throw new IntegrationError(
62
+ 'StackMemory not initialized. Run "stackmemory init" first.',
63
+ ErrorCode.LINEAR_SYNC_FAILED
61
64
  );
62
65
  }
63
66
  const db = new Database(dbPath);
@@ -69,8 +72,9 @@ class LinearAutoSyncService {
69
72
  );
70
73
  const token = await authManager.getValidToken();
71
74
  if (!token) {
72
- throw new Error(
73
- "Unable to get valid Linear token. Check authentication."
75
+ throw new IntegrationError(
76
+ "Unable to get valid Linear token. Check authentication.",
77
+ ErrorCode.LINEAR_AUTH_FAILED
74
78
  );
75
79
  }
76
80
  this.isRunning = true;
@@ -126,7 +130,10 @@ class LinearAutoSyncService {
126
130
  */
127
131
  async forceSync() {
128
132
  if (!this.syncEngine) {
129
- throw new Error("Sync engine not initialized");
133
+ throw new IntegrationError(
134
+ "Sync engine not initialized",
135
+ ErrorCode.LINEAR_SYNC_FAILED
136
+ );
130
137
  }
131
138
  logger.info("Forcing immediate Linear sync");
132
139
  await this.performSync();
@@ -183,7 +190,10 @@ class LinearAutoSyncService {
183
190
  });
184
191
  }
185
192
  } else {
186
- throw new Error(`Sync failed: ${result.errors.join(", ")}`);
193
+ throw new IntegrationError(
194
+ `Sync failed: ${result.errors.join(", ")}`,
195
+ ErrorCode.LINEAR_SYNC_FAILED
196
+ );
187
197
  }
188
198
  } catch (error) {
189
199
  logger.error("Linear auto-sync failed:", error);
@@ -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,cAAc;AACvB,SAAS,yBAAyB;AAClC,SAAS,yBAAyB;AAClC,SAAS,kBAAkB,2BAAuC;AAClE,SAAS,2BAA2B;AACpC,OAAO,cAAc;AACrB,SAAS,YAAY;AACrB,SAAS,kBAAkB;AAapB,MAAM,sBAAsB;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAY;AAAA,EACZ,eAAe;AAAA,EACf,aAAa;AAAA,EAErB,YAAY,aAAqB,QAAkC;AACjE,SAAK,cAAc;AACnB,SAAK,gBAAgB,IAAI,oBAAoB,WAAW;AAGxD,UAAM,kBAAkB,KAAK,cAAc,WAAW;AACtD,UAAM,aAAa,kBACf,KAAK,cAAc,iBAAiB,eAAe,IACnD;AAAA,MACE,GAAG;AAAA,MACH,SAAS;AAAA,MACT,UAAU;AAAA,MACV,eAAe;AAAA,MACf,YAAY;AAAA,MACZ,UAAU;AAAA,MACV,WAAW;AAAA,MACX,oBAAoB;AAAA,MACpB,YAAY,EAAE,OAAO,IAAI,KAAK,EAAE;AAAA,IAClC;AAEJ,SAAK,SAAS,EAAE,GAAG,YAAY,GAAG,OAAO;AAGzC,QAAI,UAAU,OAAO,KAAK,MAAM,EAAE,SAAS,GAAG;AAC5C,WAAK,cAAc,WAAW,MAAM;AAAA,IACtC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAAu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AQ,KAAK;AAEf,aAAO,eAAe,SAAS,cAAc;AAAA,IAC/C,OAAO;AAEL,aAAO,eAAe,SAAS,cAAc;AAAA,IAC/C;AAAA,EACF;AACF;AAKA,IAAI,kBAAgD;AAK7C,SAAS,mBACd,aACA,QACuB;AACvB,MAAI,iBAAiB;AACnB,oBAAgB,KAAK;AAAA,EACvB;AAEA,oBAAkB,IAAI,sBAAsB,aAAa,MAAM;AAC/D,SAAO;AACT;AAKO,SAAS,qBAAmD;AACjE,SAAO;AACT;AAKO,SAAS,eAAqB;AACnC,MAAI,iBAAiB;AACnB,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;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAY;AAAA,EACZ,eAAe;AAAA,EACf,aAAa;AAAA,EAErB,YAAY,aAAqB,QAAkC;AACjE,SAAK,cAAc;AACnB,SAAK,gBAAgB,IAAI,oBAAoB,WAAW;AAGxD,UAAM,kBAAkB,KAAK,cAAc,WAAW;AACtD,UAAM,aAAa,kBACf,KAAK,cAAc,iBAAiB,eAAe,IACnD;AAAA,MACE,GAAG;AAAA,MACH,SAAS;AAAA,MACT,UAAU;AAAA,MACV,eAAe;AAAA,MACf,YAAY;AAAA,MACZ,UAAU;AAAA,MACV,WAAW;AAAA,MACX,oBAAoB;AAAA,MACpB,YAAY,EAAE,OAAO,IAAI,KAAK,EAAE;AAAA,IAClC;AAEJ,SAAK,SAAS,EAAE,GAAG,YAAY,GAAG,OAAO;AAGzC,QAAI,UAAU,OAAO,KAAK,MAAM,EAAE,SAAS,GAAG;AAC5C,WAAK,cAAc,WAAW,MAAM;AAAA,IACtC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAAuB;AAC3B,QAAI,KAAK,WAAW;AAClB,aAAO,KAAK,6CAA6C;AACzD;AAAA,IACF;AAEA,QAAI;AAEF,YAAM,cAAc,IAAI,kBAAkB,KAAK,WAAW;AAC1D,UAAI,CAAC,YAAY,aAAa,GAAG;AAC/B,cAAM,IAAI;AAAA,UACR;AAAA,UACA,UAAU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A,EACF;AACF;AAKA,IAAI,kBAAgD;AAK7C,SAAS,mBACd,aACA,QACuB;AACvB,MAAI,iBAAiB;AACnB,oBAAgB,KAAK;AAAA,EACvB;AAEA,oBAAkB,IAAI,sBAAsB,aAAa,MAAM;AAC/D,SAAO;AACT;AAKO,SAAS,qBAAmD;AACjE,SAAO;AACT;AAKO,SAAS,eAAqB;AACnC,MAAI,iBAAiB;AACnB,oBAAgB,KAAK;AACrB,sBAAkB;AAAA,EACpB;AACF;",
6
6
  "names": []
7
7
  }
@@ -3,6 +3,7 @@ import { dirname as __pathDirname } from '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 instanceof Error ? error.message : 'Unknown error',\n };\n }\n }\n}\n"],
5
- "mappings": ";;;;AAKA,SAAS,cAAc;AAsDhB,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,MAAM,4BAA4B;AAAA,IAC9C;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,U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,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,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