@stackmemoryai/stackmemory 0.5.41 → 0.5.42
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.
|
@@ -131,7 +131,10 @@ async function pickNextLinearTask(options = {}) {
|
|
|
131
131
|
score: best.score
|
|
132
132
|
};
|
|
133
133
|
} catch (error) {
|
|
134
|
-
|
|
134
|
+
const isAuthError = error instanceof Error && (error.message.includes("401") || error.message.includes("403"));
|
|
135
|
+
if (!isAuthError) {
|
|
136
|
+
console.error("[linear-task-picker] Error fetching tasks:", error);
|
|
137
|
+
}
|
|
135
138
|
return null;
|
|
136
139
|
}
|
|
137
140
|
}
|
|
@@ -169,7 +172,10 @@ async function getTopTaskSuggestions(options = {}, count = 3) {
|
|
|
169
172
|
};
|
|
170
173
|
});
|
|
171
174
|
} catch (error) {
|
|
172
|
-
|
|
175
|
+
const isAuthError = error instanceof Error && (error.message.includes("401") || error.message.includes("403"));
|
|
176
|
+
if (!isAuthError) {
|
|
177
|
+
console.error("[linear-task-picker] Error fetching tasks:", error);
|
|
178
|
+
}
|
|
173
179
|
return [];
|
|
174
180
|
}
|
|
175
181
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hooks/linear-task-picker.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Linear Task Picker\n * Picks the next best task from Linear queue, prioritizing tasks with test/validation requirements\n */\n\nimport { LinearClient, LinearIssue } from '../integrations/linear/client.js';\nimport { LinearAuthManager } from '../integrations/linear/auth.js';\n\nexport interface TaskSuggestion {\n id: string;\n identifier: string; // e.g., \"STA-123\"\n title: string;\n priority: number;\n hasTestRequirements: boolean;\n estimatedPoints?: number;\n url: string;\n score: number;\n}\n\nexport interface PickerOptions {\n teamId?: string;\n preferTestTasks?: boolean;\n limit?: number;\n}\n\n// Keywords indicating test/validation requirements\nconst TEST_KEYWORDS = [\n 'test',\n 'spec',\n 'unit test',\n 'integration test',\n 'e2e',\n 'end-to-end',\n 'jest',\n 'vitest',\n 'mocha',\n];\n\nconst VALIDATION_KEYWORDS = [\n 'validate',\n 'verify',\n 'verification',\n 'acceptance criteria',\n 'ac:',\n 'acceptance:',\n 'given when then',\n 'criteria:',\n];\n\nconst QA_KEYWORDS = ['qa', 'quality', 'regression', 'coverage', 'assertion'];\n\n// Labels that indicate test requirements\nconst TEST_LABELS = [\n 'needs-tests',\n 'test-required',\n 'qa-review',\n 'has-ac',\n 'acceptance-criteria',\n 'tdd',\n 'testing',\n];\n\n/**\n * Check if text contains any of the keywords (case-insensitive)\n */\nfunction containsKeywords(text: string, keywords: string[]): boolean {\n const lowerText = text.toLowerCase();\n return keywords.some((kw) => lowerText.includes(kw.toLowerCase()));\n}\n\n/**\n * Score a task based on test/validation requirements\n */\nfunction scoreTask(issue: LinearIssue, preferTestTasks: boolean): number {\n let score = 0;\n const description = issue.description || '';\n const title = issue.title || '';\n const fullText = `${title} ${description}`;\n\n // +10 if has test/validation keywords in description\n if (containsKeywords(fullText, TEST_KEYWORDS)) {\n score += preferTestTasks ? 10 : 5;\n }\n\n if (containsKeywords(fullText, VALIDATION_KEYWORDS)) {\n score += preferTestTasks ? 8 : 4;\n }\n\n if (containsKeywords(fullText, QA_KEYWORDS)) {\n score += preferTestTasks ? 5 : 2;\n }\n\n // +5 if has test-related labels\n const labelNames =\n issue.labels?.nodes?.map((l: { name: string }) => l.name.toLowerCase()) ||\n [];\n const hasTestLabel = TEST_LABELS.some((tl) =>\n labelNames.some((ln: string) => ln.includes(tl))\n );\n if (hasTestLabel) {\n score += preferTestTasks ? 5 : 3;\n }\n\n // +3 for higher priority (urgent=1, high=2)\n if (issue.priority === 1) {\n score += 5; // Urgent\n } else if (issue.priority === 2) {\n score += 3; // High\n } else if (issue.priority === 3) {\n score += 1; // Medium\n }\n\n // +2 if has acceptance criteria pattern\n if (\n description.includes('## Acceptance') ||\n description.includes('### AC') ||\n description.includes('- [ ]')\n ) {\n score += 2;\n }\n\n // +1 if has estimate (indicates well-scoped)\n if (issue.estimate) {\n score += 1;\n }\n\n return score;\n}\n\n/**\n * Get Linear client instance\n * Returns null if credentials are missing or invalid\n */\nfunction getLinearClient(): LinearClient | null {\n // Try API key first - must be valid format (lin_api_*)\n const apiKey = process.env['LINEAR_API_KEY'];\n if (apiKey && apiKey.startsWith('lin_api_')) {\n return new LinearClient({ apiKey });\n }\n\n // Fall back to OAuth\n try {\n const authManager = new LinearAuthManager();\n const tokens = authManager.loadTokens();\n if (tokens?.accessToken) {\n return new LinearClient({ accessToken: tokens.accessToken });\n }\n } catch {\n // Auth not available\n }\n\n return null;\n}\n\n/**\n * Pick the next best task from Linear\n */\nexport async function pickNextLinearTask(\n options: PickerOptions = {}\n): Promise<TaskSuggestion | null> {\n const client = getLinearClient();\n if (!client) {\n return null;\n }\n\n const { teamId, preferTestTasks = true, limit = 20 } = options;\n\n try {\n // Fetch backlog and unstarted issues\n const [backlogIssues, unstartedIssues] = await Promise.all([\n client.getIssues({ teamId, stateType: 'backlog', limit }),\n client.getIssues({ teamId, stateType: 'unstarted', limit }),\n ]);\n\n const allIssues = [...backlogIssues, ...unstartedIssues];\n\n // Filter out assigned issues (we want unassigned ones)\n const unassignedIssues = allIssues.filter((issue) => !issue.assignee);\n\n if (unassignedIssues.length === 0) {\n // If no unassigned, consider all\n if (allIssues.length === 0) {\n return null;\n }\n }\n\n const issuesToScore =\n unassignedIssues.length > 0 ? unassignedIssues : allIssues;\n\n // Score and sort\n const scoredIssues = issuesToScore.map((issue) => ({\n issue,\n score: scoreTask(issue, preferTestTasks),\n }));\n\n scoredIssues.sort((a, b) => b.score - a.score);\n\n const best = scoredIssues[0];\n if (!best) {\n return null;\n }\n\n const description = best.issue.description || '';\n const hasTestRequirements =\n containsKeywords(description, TEST_KEYWORDS) ||\n containsKeywords(description, VALIDATION_KEYWORDS);\n\n return {\n id: best.issue.id,\n identifier: best.issue.identifier,\n title: best.issue.title,\n priority: best.issue.priority,\n hasTestRequirements,\n estimatedPoints: best.issue.estimate,\n url: best.issue.url,\n score: best.score,\n };\n } catch (error) {\n console.error('[linear-task-picker] Error fetching tasks:', error);\n return null;\n }\n}\n\n/**\n * Get multiple task suggestions (for showing options)\n */\nexport async function getTopTaskSuggestions(\n options: PickerOptions = {},\n count: number = 3\n): Promise<TaskSuggestion[]> {\n const client = getLinearClient();\n if (!client) {\n return [];\n }\n\n const { teamId, preferTestTasks = true, limit = 30 } = options;\n\n try {\n const [backlogIssues, unstartedIssues] = await Promise.all([\n client.getIssues({ teamId, stateType: 'backlog', limit }),\n client.getIssues({ teamId, stateType: 'unstarted', limit }),\n ]);\n\n const allIssues = [...backlogIssues, ...unstartedIssues];\n const unassignedIssues = allIssues.filter((issue) => !issue.assignee);\n const issuesToScore =\n unassignedIssues.length > 0 ? unassignedIssues : allIssues;\n\n const scoredIssues = issuesToScore.map((issue) => ({\n issue,\n score: scoreTask(issue, preferTestTasks),\n }));\n\n scoredIssues.sort((a, b) => b.score - a.score);\n\n return scoredIssues.slice(0, count).map(({ issue, score }) => {\n const description = issue.description || '';\n const hasTestRequirements =\n containsKeywords(description, TEST_KEYWORDS) ||\n containsKeywords(description, VALIDATION_KEYWORDS);\n\n return {\n id: issue.id,\n identifier: issue.identifier,\n title: issue.title,\n priority: issue.priority,\n hasTestRequirements,\n estimatedPoints: issue.estimate,\n url: issue.url,\n score,\n };\n });\n } catch (error) {\n console.error('[linear-task-picker] Error fetching tasks:', error);\n return [];\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;AAKA,SAAS,oBAAiC;AAC1C,SAAS,yBAAyB;AAoBlC,MAAM,gBAAgB;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,sBAAsB;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,E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AE7C,UAAM,OAAO,aAAa,CAAC;AAC3B,QAAI,CAAC,MAAM;AACT,aAAO;AAAA,IACT;AAEA,UAAM,cAAc,KAAK,MAAM,eAAe;AAC9C,UAAM,sBACJ,iBAAiB,aAAa,aAAa,KAC3C,iBAAiB,aAAa,mBAAmB;AAEnD,WAAO;AAAA,MACL,IAAI,KAAK,MAAM;AAAA,MACf,YAAY,KAAK,MAAM;AAAA,MACvB,OAAO,KAAK,MAAM;AAAA,MAClB,UAAU,KAAK,MAAM;AAAA,MACrB;AAAA,MACA,iBAAiB,KAAK,MAAM;AAAA,MAC5B,KAAK,KAAK,MAAM;AAAA,MAChB,OAAO,KAAK;AAAA,IACd;AAAA,EACF,SAAS,OAAO;
|
|
4
|
+
"sourcesContent": ["/**\n * Linear Task Picker\n * Picks the next best task from Linear queue, prioritizing tasks with test/validation requirements\n */\n\nimport { LinearClient, LinearIssue } from '../integrations/linear/client.js';\nimport { LinearAuthManager } from '../integrations/linear/auth.js';\n\nexport interface TaskSuggestion {\n id: string;\n identifier: string; // e.g., \"STA-123\"\n title: string;\n priority: number;\n hasTestRequirements: boolean;\n estimatedPoints?: number;\n url: string;\n score: number;\n}\n\nexport interface PickerOptions {\n teamId?: string;\n preferTestTasks?: boolean;\n limit?: number;\n}\n\n// Keywords indicating test/validation requirements\nconst TEST_KEYWORDS = [\n 'test',\n 'spec',\n 'unit test',\n 'integration test',\n 'e2e',\n 'end-to-end',\n 'jest',\n 'vitest',\n 'mocha',\n];\n\nconst VALIDATION_KEYWORDS = [\n 'validate',\n 'verify',\n 'verification',\n 'acceptance criteria',\n 'ac:',\n 'acceptance:',\n 'given when then',\n 'criteria:',\n];\n\nconst QA_KEYWORDS = ['qa', 'quality', 'regression', 'coverage', 'assertion'];\n\n// Labels that indicate test requirements\nconst TEST_LABELS = [\n 'needs-tests',\n 'test-required',\n 'qa-review',\n 'has-ac',\n 'acceptance-criteria',\n 'tdd',\n 'testing',\n];\n\n/**\n * Check if text contains any of the keywords (case-insensitive)\n */\nfunction containsKeywords(text: string, keywords: string[]): boolean {\n const lowerText = text.toLowerCase();\n return keywords.some((kw) => lowerText.includes(kw.toLowerCase()));\n}\n\n/**\n * Score a task based on test/validation requirements\n */\nfunction scoreTask(issue: LinearIssue, preferTestTasks: boolean): number {\n let score = 0;\n const description = issue.description || '';\n const title = issue.title || '';\n const fullText = `${title} ${description}`;\n\n // +10 if has test/validation keywords in description\n if (containsKeywords(fullText, TEST_KEYWORDS)) {\n score += preferTestTasks ? 10 : 5;\n }\n\n if (containsKeywords(fullText, VALIDATION_KEYWORDS)) {\n score += preferTestTasks ? 8 : 4;\n }\n\n if (containsKeywords(fullText, QA_KEYWORDS)) {\n score += preferTestTasks ? 5 : 2;\n }\n\n // +5 if has test-related labels\n const labelNames =\n issue.labels?.nodes?.map((l: { name: string }) => l.name.toLowerCase()) ||\n [];\n const hasTestLabel = TEST_LABELS.some((tl) =>\n labelNames.some((ln: string) => ln.includes(tl))\n );\n if (hasTestLabel) {\n score += preferTestTasks ? 5 : 3;\n }\n\n // +3 for higher priority (urgent=1, high=2)\n if (issue.priority === 1) {\n score += 5; // Urgent\n } else if (issue.priority === 2) {\n score += 3; // High\n } else if (issue.priority === 3) {\n score += 1; // Medium\n }\n\n // +2 if has acceptance criteria pattern\n if (\n description.includes('## Acceptance') ||\n description.includes('### AC') ||\n description.includes('- [ ]')\n ) {\n score += 2;\n }\n\n // +1 if has estimate (indicates well-scoped)\n if (issue.estimate) {\n score += 1;\n }\n\n return score;\n}\n\n/**\n * Get Linear client instance\n * Returns null if credentials are missing or invalid\n */\nfunction getLinearClient(): LinearClient | null {\n // Try API key first - must be valid format (lin_api_*)\n const apiKey = process.env['LINEAR_API_KEY'];\n if (apiKey && apiKey.startsWith('lin_api_')) {\n return new LinearClient({ apiKey });\n }\n\n // Fall back to OAuth\n try {\n const authManager = new LinearAuthManager();\n const tokens = authManager.loadTokens();\n if (tokens?.accessToken) {\n return new LinearClient({ accessToken: tokens.accessToken });\n }\n } catch {\n // Auth not available\n }\n\n return null;\n}\n\n/**\n * Pick the next best task from Linear\n */\nexport async function pickNextLinearTask(\n options: PickerOptions = {}\n): Promise<TaskSuggestion | null> {\n const client = getLinearClient();\n if (!client) {\n return null;\n }\n\n const { teamId, preferTestTasks = true, limit = 20 } = options;\n\n try {\n // Fetch backlog and unstarted issues\n const [backlogIssues, unstartedIssues] = await Promise.all([\n client.getIssues({ teamId, stateType: 'backlog', limit }),\n client.getIssues({ teamId, stateType: 'unstarted', limit }),\n ]);\n\n const allIssues = [...backlogIssues, ...unstartedIssues];\n\n // Filter out assigned issues (we want unassigned ones)\n const unassignedIssues = allIssues.filter((issue) => !issue.assignee);\n\n if (unassignedIssues.length === 0) {\n // If no unassigned, consider all\n if (allIssues.length === 0) {\n return null;\n }\n }\n\n const issuesToScore =\n unassignedIssues.length > 0 ? unassignedIssues : allIssues;\n\n // Score and sort\n const scoredIssues = issuesToScore.map((issue) => ({\n issue,\n score: scoreTask(issue, preferTestTasks),\n }));\n\n scoredIssues.sort((a, b) => b.score - a.score);\n\n const best = scoredIssues[0];\n if (!best) {\n return null;\n }\n\n const description = best.issue.description || '';\n const hasTestRequirements =\n containsKeywords(description, TEST_KEYWORDS) ||\n containsKeywords(description, VALIDATION_KEYWORDS);\n\n return {\n id: best.issue.id,\n identifier: best.issue.identifier,\n title: best.issue.title,\n priority: best.issue.priority,\n hasTestRequirements,\n estimatedPoints: best.issue.estimate,\n url: best.issue.url,\n score: best.score,\n };\n } catch (error) {\n // Silent fail for auth errors (401/403) - expected when not configured\n const isAuthError =\n error instanceof Error &&\n (error.message.includes('401') || error.message.includes('403'));\n if (!isAuthError) {\n console.error('[linear-task-picker] Error fetching tasks:', error);\n }\n return null;\n }\n}\n\n/**\n * Get multiple task suggestions (for showing options)\n */\nexport async function getTopTaskSuggestions(\n options: PickerOptions = {},\n count: number = 3\n): Promise<TaskSuggestion[]> {\n const client = getLinearClient();\n if (!client) {\n return [];\n }\n\n const { teamId, preferTestTasks = true, limit = 30 } = options;\n\n try {\n const [backlogIssues, unstartedIssues] = await Promise.all([\n client.getIssues({ teamId, stateType: 'backlog', limit }),\n client.getIssues({ teamId, stateType: 'unstarted', limit }),\n ]);\n\n const allIssues = [...backlogIssues, ...unstartedIssues];\n const unassignedIssues = allIssues.filter((issue) => !issue.assignee);\n const issuesToScore =\n unassignedIssues.length > 0 ? unassignedIssues : allIssues;\n\n const scoredIssues = issuesToScore.map((issue) => ({\n issue,\n score: scoreTask(issue, preferTestTasks),\n }));\n\n scoredIssues.sort((a, b) => b.score - a.score);\n\n return scoredIssues.slice(0, count).map(({ issue, score }) => {\n const description = issue.description || '';\n const hasTestRequirements =\n containsKeywords(description, TEST_KEYWORDS) ||\n containsKeywords(description, VALIDATION_KEYWORDS);\n\n return {\n id: issue.id,\n identifier: issue.identifier,\n title: issue.title,\n priority: issue.priority,\n hasTestRequirements,\n estimatedPoints: issue.estimate,\n url: issue.url,\n score,\n };\n });\n } catch (error) {\n // Silent fail for auth errors (401/403) - expected when not configured\n const isAuthError =\n error instanceof Error &&\n (error.message.includes('401') || error.message.includes('403'));\n if (!isAuthError) {\n console.error('[linear-task-picker] Error fetching tasks:', error);\n }\n return [];\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;AAKA,SAAS,oBAAiC;AAC1C,SAAS,yBAAyB;AAoBlC,MAAM,gBAAgB;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,sBAAsB;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,cAAc,CAAC,MAAM,WAAW,cAAc,YAAY,WAAW;AAG3E,MAAM,cAAc;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAKA,SAAS,iBAA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I,CAAC,EAAE,OAAO,MAAM,MAAM;AAC5D,YAAM,cAAc,MAAM,eAAe;AACzC,YAAM,sBACJ,iBAAiB,aAAa,aAAa,KAC3C,iBAAiB,aAAa,mBAAmB;AAEnD,aAAO;AAAA,QACL,IAAI,MAAM;AAAA,QACV,YAAY,MAAM;AAAA,QAClB,OAAO,MAAM;AAAA,QACb,UAAU,MAAM;AAAA,QAChB;AAAA,QACA,iBAAiB,MAAM;AAAA,QACvB,KAAK,MAAM;AAAA,QACX;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH,SAAS,OAAO;AAEd,UAAM,cACJ,iBAAiB,UAChB,MAAM,QAAQ,SAAS,KAAK,KAAK,MAAM,QAAQ,SAAS,KAAK;AAChE,QAAI,CAAC,aAAa;AAChB,cAAQ,MAAM,8CAA8C,KAAK;AAAA,IACnE;AACA,WAAO,CAAC;AAAA,EACV;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -127,10 +127,12 @@ class LinearClient {
|
|
|
127
127
|
}
|
|
128
128
|
if (!response.ok) {
|
|
129
129
|
const errorText = await response.text();
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
130
|
+
if (response.status !== 401 && response.status !== 403) {
|
|
131
|
+
logger.error(
|
|
132
|
+
"Linear API error response:",
|
|
133
|
+
new Error(`${response.status}: ${errorText}`)
|
|
134
|
+
);
|
|
135
|
+
}
|
|
134
136
|
throw new IntegrationError(
|
|
135
137
|
`Linear API error: ${response.status} ${response.statusText}`,
|
|
136
138
|
ErrorCode.LINEAR_API_ERROR,
|
|
@@ -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';\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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
|
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 // Don't log 401/403 - expected when not authenticated\n if (response.status !== 401 && response.status !== 403) {\n logger.error(\n 'Linear API error response:',\n new Error(`${response.status}: ${errorText}`)\n );\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;A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A;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;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackmemoryai/stackmemory",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.42",
|
|
4
4
|
"description": "Lossless memory runtime for AI coding tools - organizes context as a call stack instead of linear chat logs, with team collaboration and infinite retention",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=20.0.0",
|