@sentry/junior-linear 0.318.0 → 0.320.0
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.
- package/dist/index.js +203 -86
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -39,6 +39,202 @@ function linearTeamResource(input) {
|
|
|
39
39
|
namespace: "linear"
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
+
// src/inbox-subjects.ts
|
|
43
|
+
/** The subject kinds of Linear objects. */
|
|
44
|
+
const LINEAR_SUBJECT_KINDS = { issue: "issue" };
|
|
45
|
+
/** The registered kinds and labels, for the plugin registration. */
|
|
46
|
+
const linearInboxSubjectKinds = [{
|
|
47
|
+
kind: LINEAR_SUBJECT_KINDS.issue,
|
|
48
|
+
label: "Ticket",
|
|
49
|
+
owner: "annotation"
|
|
50
|
+
}];
|
|
51
|
+
// src/issue-card.ts
|
|
52
|
+
const namedFact = z.union([z.string(), z.object({ name: z.string() })]).nullish();
|
|
53
|
+
const short = (value) => {
|
|
54
|
+
const text = value?.trim();
|
|
55
|
+
return text ? text.length > 64 ? `${text.slice(0, 63)}…` : text : void 0;
|
|
56
|
+
};
|
|
57
|
+
const factName = (value) => short(typeof value === "string" ? value : value?.name);
|
|
58
|
+
const issueIdentifier = z.string().trim().regex(/^[a-z][a-z0-9]*-\d+$/i);
|
|
59
|
+
const issueSchema = z.object({
|
|
60
|
+
identifier: issueIdentifier.optional(),
|
|
61
|
+
id: z.string().optional(),
|
|
62
|
+
uuid: z.uuid().optional(),
|
|
63
|
+
url: z.url(),
|
|
64
|
+
title: z.string().optional(),
|
|
65
|
+
description: z.string().nullish(),
|
|
66
|
+
status: z.string().optional(),
|
|
67
|
+
assignee: namedFact,
|
|
68
|
+
priority: z.union([
|
|
69
|
+
z.string(),
|
|
70
|
+
z.number(),
|
|
71
|
+
z.object({ name: z.string() })
|
|
72
|
+
]).nullish(),
|
|
73
|
+
project: namedFact,
|
|
74
|
+
cycle: namedFact,
|
|
75
|
+
labels: z.array(namedFact).nullish(),
|
|
76
|
+
dueDate: z.iso.date().nullish(),
|
|
77
|
+
updatedAt: z.iso.datetime({ offset: true }).nullish()
|
|
78
|
+
}).transform((issue, ctx) => {
|
|
79
|
+
const identifier = issueIdentifier.safeParse(issue.identifier ?? issue.id);
|
|
80
|
+
if (!identifier.success) {
|
|
81
|
+
ctx.addIssue({
|
|
82
|
+
code: "custom",
|
|
83
|
+
message: "Missing issue identifier"
|
|
84
|
+
});
|
|
85
|
+
return z.NEVER;
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
...issue,
|
|
89
|
+
identifier: identifier.data.toUpperCase()
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
const issueResultSchema = z.union([issueSchema, z.object({ issue: issueSchema }).transform(({ issue }) => issue)]);
|
|
93
|
+
/** Return whether a value looks like a Linear issue key, like `ENG-123`. */
|
|
94
|
+
function isLinearIssueIdentifier(value) {
|
|
95
|
+
return issueIdentifier.safeParse(value).success;
|
|
96
|
+
}
|
|
97
|
+
/** Read Linear's JSON issue result without inferring issue facts from prose. */
|
|
98
|
+
function readLinearIssue(result) {
|
|
99
|
+
if (result.structuredContent !== void 0) return issueResultSchema.safeParse(result.structuredContent);
|
|
100
|
+
for (const part of result.content ?? []) {
|
|
101
|
+
if (part.type !== "text") continue;
|
|
102
|
+
let value;
|
|
103
|
+
try {
|
|
104
|
+
value = JSON.parse(part.text);
|
|
105
|
+
} catch (error) {
|
|
106
|
+
if (error instanceof SyntaxError) continue;
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
const parsed = issueResultSchema.safeParse(value);
|
|
110
|
+
if (parsed.success) return parsed;
|
|
111
|
+
}
|
|
112
|
+
return issueResultSchema.safeParse(void 0);
|
|
113
|
+
}
|
|
114
|
+
/** Return what Junior saves for a Linear issue: subject, title, and link. */
|
|
115
|
+
function linearSavedIssue(issue) {
|
|
116
|
+
const identifier = issue.identifier;
|
|
117
|
+
return {
|
|
118
|
+
kind: "object",
|
|
119
|
+
objectType: "task",
|
|
120
|
+
key: identifier,
|
|
121
|
+
subject: {
|
|
122
|
+
id: issue.uuid ?? identifier,
|
|
123
|
+
kind: LINEAR_SUBJECT_KINDS.issue
|
|
124
|
+
},
|
|
125
|
+
title: (issue.title || identifier).slice(0, 512),
|
|
126
|
+
url: issue.url
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/** Build the live task card of one Linear issue. */
|
|
130
|
+
function linearIssueAnnotation(issue) {
|
|
131
|
+
const identifier = issue.identifier;
|
|
132
|
+
return {
|
|
133
|
+
...linearSavedIssue(issue),
|
|
134
|
+
label: identifier,
|
|
135
|
+
description: issue.description?.slice(0, 4e3),
|
|
136
|
+
status: issue.status,
|
|
137
|
+
displayType: "Issue",
|
|
138
|
+
sourceUpdatedAt: issue.updatedAt ?? void 0,
|
|
139
|
+
facts: {
|
|
140
|
+
type: "task",
|
|
141
|
+
assignees: issue.assignee === void 0 ? void 0 : factName(issue.assignee) ? [factName(issue.assignee)] : [],
|
|
142
|
+
priority: typeof issue.priority === "number" ? [
|
|
143
|
+
"No priority",
|
|
144
|
+
"Urgent",
|
|
145
|
+
"High",
|
|
146
|
+
"Medium",
|
|
147
|
+
"Low"
|
|
148
|
+
][issue.priority] : factName(issue.priority),
|
|
149
|
+
project: factName(issue.project),
|
|
150
|
+
cycle: factName(issue.cycle),
|
|
151
|
+
dueDate: issue.dueDate ?? void 0,
|
|
152
|
+
labels: issue.labels?.slice(0, 5).map((label) => factName(label)).filter(Boolean)
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
// src/links/issues.ts
|
|
157
|
+
const ISSUE_READ_TTL_MS = 3e4;
|
|
158
|
+
/**
|
|
159
|
+
* Read the workspace and identifier of a Linear issue link, such as
|
|
160
|
+
* `https://linear.app/acme/issue/ENG-123/fix-login`.
|
|
161
|
+
*/
|
|
162
|
+
function issueLink(url) {
|
|
163
|
+
const [workspace, kind, identifier] = url.pathname.split("/").slice(1);
|
|
164
|
+
if (!workspace || kind !== "issue" || !identifier) return void 0;
|
|
165
|
+
if (!isLinearIssueIdentifier(identifier)) return void 0;
|
|
166
|
+
return {
|
|
167
|
+
identifier: identifier.toUpperCase(),
|
|
168
|
+
workspace: workspace.toLowerCase()
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
function issueWorkspace(issue) {
|
|
172
|
+
return URL.parse(issue.url)?.pathname.split("/")[1]?.toLowerCase();
|
|
173
|
+
}
|
|
174
|
+
async function fetchIssue(ctx, link) {
|
|
175
|
+
const result = await ctx.viewerMcp.callTool({
|
|
176
|
+
name: "get_issue",
|
|
177
|
+
arguments: { id: link.identifier }
|
|
178
|
+
});
|
|
179
|
+
if (result.status !== "success") return null;
|
|
180
|
+
const issue = readLinearIssue(result).data;
|
|
181
|
+
if (!issue || issueWorkspace(issue) !== link.workspace) return null;
|
|
182
|
+
if (issue.identifier !== link.identifier && !issue.uuid) return null;
|
|
183
|
+
if (issue.uuid) await rekeyTickets(ctx, link, issue.uuid);
|
|
184
|
+
return issue;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Move Tickets that an older release saved by the identifier of the link to
|
|
188
|
+
* Linear's uuid, from this viewer's own read. Only Tickets in the link's
|
|
189
|
+
* workspace move: an identifier is unique only in one workspace. The card
|
|
190
|
+
* does not need it, so a failure only logs.
|
|
191
|
+
*/
|
|
192
|
+
async function rekeyTickets(ctx, link, uuid) {
|
|
193
|
+
try {
|
|
194
|
+
await ctx.replaceSubjectId({
|
|
195
|
+
kind: LINEAR_SUBJECT_KINDS.issue,
|
|
196
|
+
from: link.identifier,
|
|
197
|
+
to: uuid,
|
|
198
|
+
urlPrefix: `https://linear.app/${link.workspace}/`
|
|
199
|
+
});
|
|
200
|
+
} catch (error) {
|
|
201
|
+
ctx.log.error("linear.issue_subject.rekey_failed", {}, error);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Read one issue as the viewer, through the plugin cache. Nothing when the
|
|
206
|
+
* viewer has no Linear login or cannot open the issue.
|
|
207
|
+
*/
|
|
208
|
+
async function readViewerIssue(ctx, url) {
|
|
209
|
+
const link = issueLink(url);
|
|
210
|
+
if (!link) return void 0;
|
|
211
|
+
return await ctx.cache.getOrLoad(`issue:${ctx.viewer.id}:${link.workspace}:${link.identifier}`, async () => ({
|
|
212
|
+
value: await fetchIssue(ctx, link),
|
|
213
|
+
ttlMs: ISSUE_READ_TTL_MS
|
|
214
|
+
})) ?? void 0;
|
|
215
|
+
}
|
|
216
|
+
async function canViewLinearIssue(ctx, url) {
|
|
217
|
+
return !!await readViewerIssue(ctx, url);
|
|
218
|
+
}
|
|
219
|
+
async function resolveLinearIssue(ctx, url) {
|
|
220
|
+
const issue = await readViewerIssue(ctx, url);
|
|
221
|
+
return issue ? linearIssueAnnotation(issue) : void 0;
|
|
222
|
+
}
|
|
223
|
+
/** Linear issue links, with or without a title slug, as task cards. */
|
|
224
|
+
const linearIssueLinks = {
|
|
225
|
+
cacheCards: true,
|
|
226
|
+
filters: [{
|
|
227
|
+
host: "linear.app",
|
|
228
|
+
pathPattern: "/*/issue/*"
|
|
229
|
+
}, {
|
|
230
|
+
host: "linear.app",
|
|
231
|
+
pathPattern: "/*/issue/*/*"
|
|
232
|
+
}],
|
|
233
|
+
canView: canViewLinearIssue,
|
|
234
|
+
label: (url) => issueLink(url)?.identifier,
|
|
235
|
+
objectTypes: ["task"],
|
|
236
|
+
resolve: resolveLinearIssue
|
|
237
|
+
};
|
|
42
238
|
// src/webhooks/events.ts
|
|
43
239
|
const issueWebhookSchema = z.object({
|
|
44
240
|
action: z.string(),
|
|
@@ -168,45 +364,6 @@ function linearWebhookSecret() {
|
|
|
168
364
|
return process.env["LINEAR_WEBHOOK_SECRET"]?.trim() || void 0;
|
|
169
365
|
}
|
|
170
366
|
// src/plugin.ts
|
|
171
|
-
const namedFact = z.union([z.string(), z.object({ name: z.string() })]).nullish();
|
|
172
|
-
const short = (value) => {
|
|
173
|
-
const text = value?.trim();
|
|
174
|
-
return text ? text.length > 64 ? `${text.slice(0, 63)}…` : text : void 0;
|
|
175
|
-
};
|
|
176
|
-
const factName = (value) => short(typeof value === "string" ? value : value?.name);
|
|
177
|
-
const issueIdentifier = z.string().trim().regex(/^[a-z][a-z0-9]*-\d+$/i);
|
|
178
|
-
const savedIssueSchema = z.object({
|
|
179
|
-
identifier: issueIdentifier.optional(),
|
|
180
|
-
id: z.string().optional(),
|
|
181
|
-
url: z.url(),
|
|
182
|
-
title: z.string().optional(),
|
|
183
|
-
description: z.string().nullish(),
|
|
184
|
-
status: z.string().optional(),
|
|
185
|
-
assignee: namedFact,
|
|
186
|
-
priority: z.union([
|
|
187
|
-
z.string(),
|
|
188
|
-
z.number(),
|
|
189
|
-
z.object({ name: z.string() })
|
|
190
|
-
]).nullish(),
|
|
191
|
-
project: namedFact,
|
|
192
|
-
cycle: namedFact,
|
|
193
|
-
labels: z.array(namedFact).nullish(),
|
|
194
|
-
dueDate: z.iso.date().nullish(),
|
|
195
|
-
updatedAt: z.iso.datetime({ offset: true }).nullish()
|
|
196
|
-
}).transform((issue, ctx) => {
|
|
197
|
-
const identifier = issueIdentifier.safeParse(issue.identifier ?? issue.id);
|
|
198
|
-
if (!identifier.success) {
|
|
199
|
-
ctx.addIssue({
|
|
200
|
-
code: "custom",
|
|
201
|
-
message: "Missing issue identifier"
|
|
202
|
-
});
|
|
203
|
-
return z.NEVER;
|
|
204
|
-
}
|
|
205
|
-
return {
|
|
206
|
-
...issue,
|
|
207
|
-
identifier: identifier.data.toUpperCase()
|
|
208
|
-
};
|
|
209
|
-
});
|
|
210
367
|
/** Read-only Linear MCP tools that the optional service account may call. */
|
|
211
368
|
const LINEAR_SERVICE_ACCOUNT_TOOLS = [
|
|
212
369
|
"extract_images",
|
|
@@ -231,61 +388,18 @@ const LINEAR_SERVICE_ACCOUNT_TOOLS = [
|
|
|
231
388
|
"list_users",
|
|
232
389
|
"search_documentation"
|
|
233
390
|
];
|
|
234
|
-
const saveIssueResultSchema = z.union([savedIssueSchema, z.object({ issue: savedIssueSchema }).transform(({ issue }) => issue)]);
|
|
235
|
-
/** Read Linear's JSON result without inferring issue facts from prose. */
|
|
236
|
-
function readSavedIssue(result) {
|
|
237
|
-
if (result.structuredContent !== void 0) return saveIssueResultSchema.safeParse(result.structuredContent);
|
|
238
|
-
for (const part of result.content ?? []) {
|
|
239
|
-
if (part.type !== "text") continue;
|
|
240
|
-
let value;
|
|
241
|
-
try {
|
|
242
|
-
value = JSON.parse(part.text);
|
|
243
|
-
} catch (error) {
|
|
244
|
-
if (error instanceof SyntaxError) continue;
|
|
245
|
-
throw error;
|
|
246
|
-
}
|
|
247
|
-
const parsed = saveIssueResultSchema.safeParse(value);
|
|
248
|
-
if (parsed.success) return parsed;
|
|
249
|
-
}
|
|
250
|
-
return saveIssueResultSchema.safeParse(void 0);
|
|
251
|
-
}
|
|
252
391
|
/** Link created and updated Linear issues to the current Junior conversation. */
|
|
253
392
|
async function annotateSavedIssue(ctx) {
|
|
254
393
|
if (ctx.tool.name !== "save_issue") return;
|
|
255
394
|
if (!ctx.annotations) return;
|
|
256
|
-
const result =
|
|
395
|
+
const result = readLinearIssue(ctx.result);
|
|
257
396
|
if (!result.success) {
|
|
258
397
|
ctx.log.warn("linear.issue_annotation.skipped", { "app.reason": "unexpected_save_response" });
|
|
259
398
|
return;
|
|
260
399
|
}
|
|
261
|
-
const issue = result.data;
|
|
262
|
-
const identifier = issue.identifier;
|
|
263
400
|
return { objectAnnotations: [{
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
key: identifier,
|
|
267
|
-
label: identifier,
|
|
268
|
-
title: (issue.title || identifier).slice(0, 512),
|
|
269
|
-
description: issue.description?.slice(0, 4e3),
|
|
270
|
-
url: issue.url,
|
|
271
|
-
status: issue.status,
|
|
272
|
-
displayType: "Issue",
|
|
273
|
-
sourceUpdatedAt: issue.updatedAt ?? void 0,
|
|
274
|
-
facts: {
|
|
275
|
-
type: "task",
|
|
276
|
-
assignees: issue.assignee === void 0 ? void 0 : factName(issue.assignee) ? [factName(issue.assignee)] : [],
|
|
277
|
-
priority: typeof issue.priority === "number" ? [
|
|
278
|
-
"No priority",
|
|
279
|
-
"Urgent",
|
|
280
|
-
"High",
|
|
281
|
-
"Normal",
|
|
282
|
-
"Low"
|
|
283
|
-
][issue.priority] : factName(issue.priority),
|
|
284
|
-
project: factName(issue.project),
|
|
285
|
-
cycle: factName(issue.cycle),
|
|
286
|
-
dueDate: issue.dueDate ?? void 0,
|
|
287
|
-
labels: issue.labels?.slice(0, 5).map((label) => factName(label)).filter(Boolean)
|
|
288
|
-
}
|
|
401
|
+
action: ctx.tool.arguments["id"] === void 0 ? "created" : "changed",
|
|
402
|
+
...linearSavedIssue(result.data)
|
|
289
403
|
}] };
|
|
290
404
|
}
|
|
291
405
|
/** Register Linear's hosted MCP provider and conversation-link side effects. */
|
|
@@ -308,6 +422,7 @@ function linearPlugin(options = {}) {
|
|
|
308
422
|
isEnabled: () => Boolean(linearWebhookSecret()),
|
|
309
423
|
normalizeIdentifier: (identifier) => identifier.toUpperCase()
|
|
310
424
|
},
|
|
425
|
+
objectLinks: [linearIssueLinks],
|
|
311
426
|
manifest: {
|
|
312
427
|
accounts: { serviceAccount: { tools: [...LINEAR_SERVICE_ACCOUNT_TOOLS] } },
|
|
313
428
|
configKeys: ["team", "project"],
|
|
@@ -316,11 +431,13 @@ function linearPlugin(options = {}) {
|
|
|
316
431
|
envVars: { LINEAR_WEBHOOK_SECRET: {} },
|
|
317
432
|
mcp: {
|
|
318
433
|
transport: "http",
|
|
319
|
-
url: "https://mcp.linear.app/mcp"
|
|
434
|
+
url: "https://mcp.linear.app/mcp",
|
|
435
|
+
viewerTools: ["get_issue"]
|
|
320
436
|
},
|
|
321
437
|
name: "linear",
|
|
322
438
|
...options.reviewContext ? { reviewContext: options.reviewContext } : void 0
|
|
323
439
|
},
|
|
440
|
+
inboxSubjects: linearInboxSubjectKinds,
|
|
324
441
|
hooks: {
|
|
325
442
|
afterMcpTool: annotateSavedIssue,
|
|
326
443
|
routes(ctx) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentry/junior-linear",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.320.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"skills"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@sentry/junior-plugin-api": "0.
|
|
25
|
+
"@sentry/junior-plugin-api": "0.320.0",
|
|
26
26
|
"zod": "^4.6.7"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|