@codyswann/lisa 5.5.0 → 5.6.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.
Files changed (100) hide show
  1. package/all/copy-overwrite/scripts/lib/automation-provenance-local.mjs +26 -2
  2. package/all/copy-overwrite/scripts/lib/github-attestation-provider.mjs +68 -0
  3. package/all/copy-overwrite/scripts/lib/github-attestation-recovery.mjs +25 -10
  4. package/all/copy-overwrite/scripts/lib/github-attestation-verifier.mjs +4 -1
  5. package/all/copy-overwrite/scripts/lib/npm-update-allocate.mjs +1 -6
  6. package/all/copy-overwrite/scripts/lib/npm-update-authorization.mjs +25 -14
  7. package/all/copy-overwrite/scripts/lib/npm-update-cancel-origin.mjs +45 -11
  8. package/all/copy-overwrite/scripts/lib/npm-update-cancellation-proof.mjs +22 -11
  9. package/all/copy-overwrite/scripts/lib/npm-update-cancellation.mjs +29 -17
  10. package/all/copy-overwrite/scripts/lib/npm-update-controller-factory.mjs +19 -1
  11. package/all/copy-overwrite/scripts/lib/npm-update-gate.mjs +5 -0
  12. package/all/copy-overwrite/scripts/lib/npm-update-gh-requests.mjs +57 -30
  13. package/all/copy-overwrite/scripts/lib/npm-update-helper-inventory.mjs +1 -0
  14. package/all/copy-overwrite/scripts/lib/npm-update-leaf.mjs +6 -1
  15. package/all/copy-overwrite/scripts/lib/npm-update-policy.mjs +38 -0
  16. package/all/copy-overwrite/scripts/lib/npm-update-publication.mjs +21 -3
  17. package/all/copy-overwrite/scripts/lib/npm-update-publish.mjs +13 -1
  18. package/all/copy-overwrite/scripts/lib/npm-update-recovery.mjs +29 -4
  19. package/all/copy-overwrite/scripts/lib/npm-update-supersession.mjs +21 -7
  20. package/all/copy-overwrite/scripts/lib/npm-update-tracker-cancel.mjs +139 -0
  21. package/all/copy-overwrite/scripts/lib/npm-update-tracker-jira.mjs +149 -19
  22. package/all/copy-overwrite/scripts/lib/npm-update-tracker-linear.mjs +72 -17
  23. package/all/copy-overwrite/scripts/lib/npm-update-tracker-wire.mjs +102 -12
  24. package/all/copy-overwrite/scripts/lib/npm-update-tracker.mjs +91 -13
  25. package/all/copy-overwrite/scripts/lisa-automation-provenance.mjs +35 -8
  26. package/all/copy-overwrite/scripts/lisa-npm-updater.mjs +8 -5
  27. package/all/copy-overwrite/scripts/npm-updater-helper-graph.json +45 -26
  28. package/dist/core/lisa-owned-hash-ledger.d.ts.map +1 -1
  29. package/dist/core/lisa-owned-hash-ledger.js +122 -0
  30. package/dist/core/lisa-owned-hash-ledger.js.map +1 -1
  31. package/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
  32. package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
  33. package/dist/core/upstream-evidence-manifest.js +42 -28
  34. package/dist/core/upstream-evidence-manifest.js.map +1 -1
  35. package/package.json +4 -4
  36. package/plugins/lisa/.claude-plugin/plugin.json +1 -1
  37. package/plugins/lisa/.codex-plugin/plugin.json +1 -1
  38. package/plugins/lisa-agy/plugin.json +1 -1
  39. package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
  40. package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
  41. package/plugins/lisa-cdk-agy/plugin.json +1 -1
  42. package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
  43. package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
  44. package/plugins/lisa-cdk-devin/.claude-plugin/plugin.json +1 -1
  45. package/plugins/lisa-cdk-devin/.devin-plugin/plugin.json +1 -1
  46. package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
  47. package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
  48. package/plugins/lisa-devin/.claude-plugin/plugin.json +1 -1
  49. package/plugins/lisa-devin/.devin-plugin/plugin.json +1 -1
  50. package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
  51. package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
  52. package/plugins/lisa-expo-agy/plugin.json +1 -1
  53. package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
  54. package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
  55. package/plugins/lisa-expo-devin/.claude-plugin/plugin.json +1 -1
  56. package/plugins/lisa-expo-devin/.devin-plugin/plugin.json +1 -1
  57. package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
  58. package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
  59. package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
  60. package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
  61. package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
  62. package/plugins/lisa-harper-fabric-devin/.claude-plugin/plugin.json +1 -1
  63. package/plugins/lisa-harper-fabric-devin/.devin-plugin/plugin.json +1 -1
  64. package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
  65. package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
  66. package/plugins/lisa-nestjs-agy/plugin.json +1 -1
  67. package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
  68. package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
  69. package/plugins/lisa-nestjs-devin/.claude-plugin/plugin.json +1 -1
  70. package/plugins/lisa-nestjs-devin/.devin-plugin/plugin.json +1 -1
  71. package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
  72. package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
  73. package/plugins/lisa-phaser-agy/plugin.json +1 -1
  74. package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
  75. package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
  76. package/plugins/lisa-phaser-devin/.claude-plugin/plugin.json +1 -1
  77. package/plugins/lisa-phaser-devin/.devin-plugin/plugin.json +1 -1
  78. package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
  79. package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
  80. package/plugins/lisa-rails-agy/plugin.json +1 -1
  81. package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
  82. package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
  83. package/plugins/lisa-rails-devin/.claude-plugin/plugin.json +1 -1
  84. package/plugins/lisa-rails-devin/.devin-plugin/plugin.json +1 -1
  85. package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
  86. package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
  87. package/plugins/lisa-typescript-agy/plugin.json +1 -1
  88. package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
  89. package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
  90. package/plugins/lisa-typescript-devin/.claude-plugin/plugin.json +1 -1
  91. package/plugins/lisa-typescript-devin/.devin-plugin/plugin.json +1 -1
  92. package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
  93. package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
  94. package/plugins/lisa-wiki-agy/plugin.json +1 -1
  95. package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
  96. package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
  97. package/plugins/lisa-wiki-devin/.claude-plugin/plugin.json +1 -1
  98. package/plugins/lisa-wiki-devin/.devin-plugin/plugin.json +1 -1
  99. package/scripts/two-channel-couplings.json +1 -1
  100. package/typescript/copy-overwrite/.prettierignore +1 -0
@@ -22,9 +22,19 @@ import {
22
22
  withinJiraLimit,
23
23
  strandedRefusal,
24
24
  vendorLabels,
25
+ declaredActor,
26
+ assertDeclaredActor,
27
+ assertClaimAuthor,
25
28
  } from "./npm-update-tracker-wire.mjs";
29
+ import {
30
+ canceledName,
31
+ isoTime,
32
+ jiraCancel,
33
+ jiraAssertCancelled,
34
+ } from "./npm-update-tracker-cancel.mjs";
26
35
 
27
36
  const API = "/rest/api/3";
37
+ const CLAIM_DIFFERS = "current tracker claim differs";
28
38
  const FIELDS =
29
39
  "summary,description,status,issuetype,priority,labels,assignee,subtasks,issuelinks";
30
40
 
@@ -52,24 +62,29 @@ function commentRecord(comment) {
52
62
  id: comment.author?.accountId,
53
63
  type: comment.author?.accountType === "app" ? "Bot" : "User",
54
64
  },
65
+ // Origin transport chronology reads these, as it reads GitHub's (#4873).
66
+ created_at: isoTime(comment.created),
67
+ updated_at: isoTime(comment.updated),
55
68
  };
56
69
  }
57
70
 
58
71
  export class JiraTracker {
59
72
  constructor(config, env, transport = globalThis.fetch) {
60
73
  const credentials = trackerCredentials(config, env);
74
+ this.actor = declaredActor(config);
61
75
  this.provider = "jira";
62
76
  this.key = config.jira.project.trim().toUpperCase();
63
77
  this.lifecycle = trackerContract(config).lifecycle;
78
+ this.canceled = canceledName(config);
64
79
  this.baseUrl = credentials.baseUrl;
65
80
  this.authorization = credentials.authorization;
66
81
  this.transport = transport;
67
82
  }
68
- call(path, purpose, method = "GET", body) {
83
+ call(path, purpose, method = "GET", body, missing = false) {
69
84
  return jsonCall(
70
85
  this.transport,
71
86
  `${this.baseUrl}${API}${path}`,
72
- { method, body, authorization: this.authorization },
87
+ { method, body, missing, authorization: this.authorization },
73
88
  purpose
74
89
  );
75
90
  }
@@ -82,12 +97,12 @@ export class JiraTracker {
82
97
  required(match, "tracker search reply differs");
83
98
  return Number(match[1]);
84
99
  }
100
+ /** The credential's own account, which must be the declared automation identity. */
85
101
  async myself() {
86
- this.accountId ??= (await this.call("/myself", "unclassified"))?.accountId;
87
- required(
88
- typeof this.accountId === "string",
89
- "tracker identity unavailable"
90
- );
102
+ if (this.accountId) return this.accountId;
103
+ const id = (await this.call("/myself", "unclassified"))?.accountId;
104
+ required(typeof id === "string", "tracker identity unavailable");
105
+ this.accountId = assertDeclaredActor("jira", id, this.actor);
91
106
  return this.accountId;
92
107
  }
93
108
  async issue(number) {
@@ -106,6 +121,13 @@ export class JiraTracker {
106
121
  title: fields.summary,
107
122
  body: adfText(fields.description),
108
123
  state: stateOf(fields.status),
124
+ // Only the configured canceled status is an explicit cancellation (#4873).
125
+ state_reason:
126
+ stateOf(fields.status) === "closed"
127
+ ? fields.status?.name?.toLowerCase() === this.canceled.toLowerCase()
128
+ ? "not_planned"
129
+ : "completed"
130
+ : null,
109
131
  labels: [
110
132
  lifecycleName(this.lifecycle, fields.status?.name),
111
133
  ...typeLabels(fields),
@@ -143,11 +165,12 @@ export class JiraTracker {
143
165
  }
144
166
  throw new Error("npm updater: provider pagination exceeded bound");
145
167
  }
146
- async search(jql) {
168
+ async search(jql, reconcileIssues) {
147
169
  const reply = await this.call("/search/jql", "issue-search", "POST", {
148
170
  jql,
149
171
  fields: ["status"],
150
172
  maxResults: 100,
173
+ ...(reconcileIssues ? { reconcileIssues } : {}),
151
174
  });
152
175
  required(Array.isArray(reply?.issues), "tracker search reply differs");
153
176
  return {
@@ -159,11 +182,82 @@ export class JiraTracker {
159
182
  })),
160
183
  };
161
184
  }
162
- /** The exact selection label, not full-text ranking, finds a prior proposal. */
163
- searchPrior(proposal) {
164
- return this.search(
165
- `project = "${this.key}" AND labels = "lisa-npm-${proposal.selectionKey}"`
185
+ /**
186
+ * The automation account's own user property for one selection. Jira entity
187
+ * properties read back consistently, unlike the search index, and the calling
188
+ * account may write its own without an admin permission.
189
+ */
190
+ async rememberedPath(proposal) {
191
+ const account = encodeURIComponent(await this.myself());
192
+ return `/user/properties/lisa-npm-${proposal.selectionKey}?accountId=${account}`;
193
+ }
194
+ /**
195
+ * The ticket this automation last created for the selection, or undefined.
196
+ * Best effort by design: an unreadable record leaves search exactly as it
197
+ * was before #4873, where a duplicate still stops safely for a person.
198
+ */
199
+ async remembered(proposal) {
200
+ // Identity is proved first and never swallowed: a credential that signs in
201
+ // as another account must stop the run before anything is created.
202
+ const path = await this.rememberedPath(proposal);
203
+ try {
204
+ const record = await this.call(
205
+ path,
206
+ "unclassified",
207
+ "GET",
208
+ undefined,
209
+ true
210
+ );
211
+ const id = Number(record?.value?.id);
212
+ return Number.isSafeInteger(id) && id > 0 ? [id] : undefined;
213
+ } catch {
214
+ return undefined;
215
+ }
216
+ }
217
+ /**
218
+ * The exact selection label, not full-text ranking, finds a prior proposal.
219
+ * Jira's search index can miss a ticket created moments ago, so the ticket
220
+ * this automation remembered creating is reconciled into the result (#4873).
221
+ */
222
+ async searchPrior(proposal) {
223
+ const jql = `project = "${this.key}" AND labels = "lisa-npm-${proposal.selectionKey}"`;
224
+ const remembered = await this.remembered(proposal);
225
+ if (!remembered) return this.search(jql);
226
+ try {
227
+ return await this.search(jql, remembered);
228
+ } catch {
229
+ return this.searchWithout(jql, remembered[0], proposal);
230
+ }
231
+ }
232
+ /**
233
+ * A refused reconcile must neither block allocation nor lose the remembered
234
+ * ticket to a still-lagging index (#4873 review): the ticket is read directly
235
+ * and kept in the result while it exists with this selection's label. Only a
236
+ * 404, a deleted ticket, lets the plain search stand alone; any other failed
237
+ * read throws, so nothing is created on an unknown answer.
238
+ */
239
+ async searchWithout(jql, id, proposal) {
240
+ const ticket = await this.call(
241
+ `/issue/${id}?fields=status,labels`,
242
+ "issue",
243
+ "GET",
244
+ undefined,
245
+ true
166
246
  );
247
+ const found = await this.search(jql);
248
+ const label = `lisa-npm-${proposal.selectionKey}`;
249
+ if (ticket === null || !(ticket.fields?.labels ?? []).includes(label))
250
+ return found;
251
+ const number = this.numberOf(ticket.key);
252
+ if (found.items.some(item => item.number === number)) return found;
253
+ return {
254
+ ...found,
255
+ total_count: found.total_count + 1,
256
+ items: [
257
+ ...found.items,
258
+ { number, state: stateOf(ticket.fields?.status) },
259
+ ],
260
+ };
167
261
  }
168
262
  async relationships() {
169
263
  const query = `project = "${this.key}" AND (summary ~ "npm" OR description ~ "npm")`;
@@ -194,6 +288,8 @@ export class JiraTracker {
194
288
  throw vocabularyRefusal("Jira");
195
289
  }
196
290
  async createLeaf(draft, proposal) {
291
+ // The declared automation identity is proved before the create, never after it.
292
+ const remember = await this.rememberedPath(proposal);
197
293
  const fields = {
198
294
  project: { key: this.key },
199
295
  issuetype: { name: "Task" },
@@ -205,6 +301,12 @@ export class JiraTracker {
205
301
  };
206
302
  const created = await this.call("/issue", "issue", "POST", { fields });
207
303
  const number = this.numberOf(created?.key);
304
+ // Remembered first, so a retry inside the index window finds this ticket.
305
+ // Best effort, like the read: a refused write must not strand the ticket.
306
+ await this.call(remember, "unclassified", "PUT", {
307
+ id: String(created.id),
308
+ key: created.key,
309
+ }).catch(() => undefined);
208
310
  try {
209
311
  await this.moveTo(number, this.lifecycle.ready);
210
312
  } catch {
@@ -214,6 +316,7 @@ export class JiraTracker {
214
316
  }
215
317
  /** Exactly one workflow transition must reach the named status; none is ever guessed. */
216
318
  async moveTo(number, name) {
319
+ await this.myself();
217
320
  const current = await this.call(
218
321
  `/issue/${this.ref(number)}?fields=status`,
219
322
  "issue"
@@ -244,6 +347,8 @@ export class JiraTracker {
244
347
  );
245
348
  }
246
349
  async assign(number, accountId) {
350
+ // Every write proves the declared automation identity first (#4873 review).
351
+ await this.myself();
247
352
  await this.call(`/issue/${this.ref(number)}/assignee`, "issue", "PUT", {
248
353
  accountId,
249
354
  });
@@ -251,12 +356,14 @@ export class JiraTracker {
251
356
  async transition(issue, roles) {
252
357
  await this.moveTo(issue.number, roles.claimed);
253
358
  }
254
- async comment(number, text) {
359
+ /** Managed records are one ADF code block; a backlink is the plain paragraph the PR check reads. */
360
+ async comment(number, text, document = adfCodeBlock(withinJiraLimit(text))) {
361
+ await this.myself();
255
362
  const created = await this.call(
256
363
  `/issue/${this.ref(number)}/comment`,
257
364
  "issue-comments",
258
365
  "POST",
259
- { body: adfCodeBlock(withinJiraLimit(text)) }
366
+ { body: document }
260
367
  );
261
368
  required(
262
369
  /^[1-9]\d*$/.test(String(created?.id)) && adfText(created.body) === text,
@@ -264,6 +371,13 @@ export class JiraTracker {
264
371
  );
265
372
  return created;
266
373
  }
374
+ backlinkComment(number, text) {
375
+ return this.comment(number, text, {
376
+ type: "doc",
377
+ version: 1,
378
+ content: [{ type: "paragraph", content: [{ type: "text", text }] }],
379
+ });
380
+ }
267
381
  /** The issue-scoped comment path is itself the scope proof: Jira answers 404 elsewhere. */
268
382
  async durableComment(number, text) {
269
383
  const created = await this.comment(number, text);
@@ -276,6 +390,16 @@ export class JiraTracker {
276
390
  "checkpoint immediate readback differs"
277
391
  );
278
392
  }
393
+ /** The declared automation account the credential signs in as. */
394
+ actorId() {
395
+ return this.myself();
396
+ }
397
+ cancel(number) {
398
+ return jiraCancel(this, number);
399
+ }
400
+ assertCancelled(number) {
401
+ return jiraAssertCancelled(this, number);
402
+ }
279
403
  /** The credential's own account, whether a person or an app/service account. */
280
404
  async isManagedActor(user) {
281
405
  return typeof user?.id === "string" && user.id === (await this.myself());
@@ -284,17 +408,23 @@ export class JiraTracker {
284
408
  const number = this.numberOf(descriptor.workItem);
285
409
  required(
286
410
  /^[1-9]\d*$/.test(String(descriptor.claimCommentId)),
287
- "current tracker claim differs"
411
+ CLAIM_DIFFERS
288
412
  );
289
413
  const comment = await this.call(
290
414
  `/issue/${this.ref(number)}/comment/${descriptor.claimCommentId}`,
291
415
  "issue-comment"
292
416
  );
417
+ required(String(comment?.id) === descriptor.claimCommentId, CLAIM_DIFFERS);
418
+ assertClaimAuthor(
419
+ "jira",
420
+ descriptor.workItem,
421
+ comment.author?.accountId,
422
+ await this.myself()
423
+ );
293
424
  required(
294
- String(comment?.id) === descriptor.claimCommentId &&
295
- comment.author?.accountId === (await this.myself()) &&
296
- sha256(adfText(comment.body)) === descriptor.claimSha256,
297
- "current tracker claim differs"
425
+ sha256(adfText(comment.body)) === descriptor.claimSha256,
426
+ CLAIM_DIFFERS
298
427
  );
428
+ return { created_at: isoTime(comment.created) };
299
429
  }
300
430
  }
@@ -22,7 +22,16 @@ import {
22
22
  linearClosed as closed,
23
23
  linearSearchResult as searchResult,
24
24
  completeLinearConnections as completeConnections,
25
+ LINEAR_CONNECTIONS,
26
+ declaredActor,
27
+ assertDeclaredActor,
28
+ assertClaimAuthor,
25
29
  } from "./npm-update-tracker-wire.mjs";
30
+ import {
31
+ canceledName,
32
+ linearCancel,
33
+ linearAssertCancelled,
34
+ } from "./npm-update-tracker-cancel.mjs";
26
35
 
27
36
  const VIEWER = "query LisaNpmViewer { viewer { id } }";
28
37
  const TEAM =
@@ -31,12 +40,18 @@ const MEMBER =
31
40
  "query LisaNpmMember($id: String!, $key: String!) { user(id: $id) { id active teams(filter: { key: { eq: $key } }) { nodes { id } } } }";
32
41
  const ISSUES =
33
42
  "query LisaNpmIssues($filter: IssueFilter!) { issues(filter: $filter, first: 100, includeArchived: true) { nodes { number archivedAt state { type } } pageInfo { hasNextPage } } }";
34
- const ISSUE =
35
- "query LisaNpmIssue($id: String!) { issue(id: $id) { id identifier number title description priority archivedAt state { name type } assignee { id } labels(first: 100) { nodes { name } pageInfo { hasNextPage } } children(first: 100) { nodes { id } pageInfo { hasNextPage } } inverseRelations(first: 100) { nodes { type issue { state { type } archivedAt } } pageInfo { hasNextPage } } } }";
43
+ const ISSUE = `query LisaNpmIssue($id: String!) { issue(id: $id) { id identifier number title description priority archivedAt state { name type } assignee { id } ${Object.entries(
44
+ LINEAR_CONNECTIONS
45
+ )
46
+ .map(
47
+ ([name, fields]) =>
48
+ `${name}(first: 100) { nodes { ${fields} } pageInfo { hasNextPage endCursor } }`
49
+ )
50
+ .join(" ")} } }`;
36
51
  const COMMENTS =
37
- "query LisaNpmComments($id: String!, $after: String) { issue(id: $id) { comments(first: 100, after: $after) { nodes { id body user { id } botActor { id } } pageInfo { hasNextPage endCursor } } } }";
52
+ "query LisaNpmComments($id: String!, $after: String) { issue(id: $id) { comments(first: 100, after: $after) { nodes { id body createdAt editedAt user { id } botActor { id } } pageInfo { hasNextPage endCursor } } } }";
38
53
  const COMMENT =
39
- "query LisaNpmComment($id: String!) { comment(id: $id) { id body user { id } issue { identifier } } }";
54
+ "query LisaNpmComment($id: String!) { comment(id: $id) { id body createdAt user { id } issue { identifier } } }";
40
55
  const CREATE =
41
56
  "mutation LisaNpmIssueCreate($input: IssueCreateInput!) { issueCreate(input: $input) { success issue { number identifier } } }";
42
57
  const UPDATE =
@@ -56,15 +71,20 @@ function commentRecord(node) {
56
71
  user: node.user
57
72
  ? { id: node.user.id, type: "User" }
58
73
  : { id: node.botActor?.id, type: "Bot" },
74
+ // An edited comment reports its edit time, so an edit is never mistaken for the original.
75
+ created_at: node.createdAt,
76
+ updated_at: node.editedAt ?? node.createdAt,
59
77
  };
60
78
  }
61
79
 
62
80
  export class LinearTracker {
63
81
  constructor(config, env, transport = globalThis.fetch) {
64
82
  const credentials = trackerCredentials(config, env);
83
+ this.actor = declaredActor(config);
65
84
  this.provider = "linear";
66
85
  this.key = config.linear.teamKey.trim().toUpperCase();
67
86
  this.lifecycle = trackerContract(config).lifecycle;
87
+ this.canceled = canceledName(config);
68
88
  this.url = credentials.baseUrl;
69
89
  this.authorization = credentials.authorization;
70
90
  this.transport = transport;
@@ -94,11 +114,12 @@ export class LinearTracker {
94
114
  ref(number) {
95
115
  return `${this.key}-${number}`;
96
116
  }
117
+ /** The API key's own user, which must be the declared automation identity. */
97
118
  async viewer() {
98
- this.viewerId ??= (
99
- await this.graphql(VIEWER, {}, "unclassified")
100
- ).viewer?.id;
101
- required(typeof this.viewerId === "string", "tracker identity unavailable");
119
+ if (this.viewerId) return this.viewerId;
120
+ const id = (await this.graphql(VIEWER, {}, "unclassified")).viewer?.id;
121
+ required(typeof id === "string", "tracker identity unavailable");
122
+ this.viewerId = assertDeclaredActor("linear", id, this.actor);
102
123
  return this.viewerId;
103
124
  }
104
125
  async team() {
@@ -129,19 +150,27 @@ export class LinearTracker {
129
150
  Number.isSafeInteger(number) && number > 0,
130
151
  "invalid live issue number"
131
152
  );
132
- const node = (await this.graphql(ISSUE, { id: this.ref(number) }, "issue"))
153
+ const first = (await this.graphql(ISSUE, { id: this.ref(number) }, "issue"))
133
154
  .issue;
134
155
  required(
135
- node?.identifier === this.ref(number) && node.number === number,
156
+ first?.identifier === this.ref(number) && first.number === number,
136
157
  "live issue scope differs"
137
158
  );
138
- completeConnections(node);
159
+ const node = await completeConnections(first, (query, variables) =>
160
+ this.graphql(query, variables, "issue")
161
+ );
139
162
  this.ids.set(number, node.id);
140
163
  return {
141
164
  number,
142
165
  title: node.title,
143
166
  body: unfence(node.description),
144
167
  state: closed(node) ? "closed" : "open",
168
+ // Only a canceled-type state is an explicit cancellation (#4873).
169
+ state_reason: !closed(node)
170
+ ? null
171
+ : node.state?.type === "canceled" && !node.archivedAt
172
+ ? "not_planned"
173
+ : "completed",
145
174
  labels: [
146
175
  lifecycleName(this.lifecycle, node.state?.name),
147
176
  "type:Task",
@@ -218,6 +247,8 @@ export class LinearTracker {
218
247
  throw vocabularyRefusal("Linear");
219
248
  }
220
249
  async createLeaf(draft) {
250
+ // Every write proves the declared automation identity first (#4873 review).
251
+ await this.viewer();
221
252
  const input = {
222
253
  teamId: (await this.team()).id,
223
254
  title: draft.title,
@@ -251,6 +282,7 @@ export class LinearTracker {
251
282
  );
252
283
  }
253
284
  async update(number, input) {
285
+ await this.viewer();
254
286
  const id = await this.issueId(number);
255
287
  const reply = await this.graphql(UPDATE, { id, input }, "issue");
256
288
  required(reply.issueUpdate?.success === true, "tracker update refused");
@@ -263,19 +295,24 @@ export class LinearTracker {
263
295
  stateId: await this.stateId(roles.claimed),
264
296
  });
265
297
  }
266
- async comment(number, text) {
267
- const input = { issueId: await this.issueId(number), body: fence(text) };
298
+ /** Managed records sit in one exact fence; a backlink is the plain line the PR check reads. */
299
+ async comment(number, text, stored = fence(text)) {
300
+ await this.viewer();
301
+ const input = { issueId: await this.issueId(number), body: stored };
268
302
  const created = (
269
303
  await this.graphql(COMMENT_CREATE, { input }, "issue-comments")
270
304
  ).commentCreate;
271
305
  required(
272
306
  created?.success === true &&
273
307
  created.comment?.issue?.identifier === this.ref(number) &&
274
- created.comment.body === fence(text),
308
+ created.comment.body === stored,
275
309
  "checkpoint write readback differs"
276
310
  );
277
311
  return created.comment;
278
312
  }
313
+ backlinkComment(number, text) {
314
+ return this.comment(number, text, text);
315
+ }
279
316
  async durableComment(number, text) {
280
317
  const created = await this.comment(number, text);
281
318
  const read = await this.field(COMMENT, { id: created.id }, "comment");
@@ -286,6 +323,15 @@ export class LinearTracker {
286
323
  "checkpoint immediate readback differs"
287
324
  );
288
325
  }
326
+ actorId() {
327
+ return this.viewer();
328
+ }
329
+ cancel(number) {
330
+ return linearCancel(this, number);
331
+ }
332
+ assertCancelled(number) {
333
+ return linearAssertCancelled(this, number);
334
+ }
289
335
  async isManagedActor(user) {
290
336
  return user?.type === "User" && user.id === (await this.viewer());
291
337
  }
@@ -294,11 +340,20 @@ export class LinearTracker {
294
340
  const comment = await this.field(COMMENT, { id }, "comment");
295
341
  required(
296
342
  comment?.id === descriptor.claimCommentId &&
297
- comment.issue?.identifier === descriptor.workItem &&
298
- comment.user?.id === (await this.viewer()) &&
299
- typeof comment.body === "string" &&
343
+ comment.issue?.identifier === descriptor.workItem,
344
+ "current tracker claim differs"
345
+ );
346
+ assertClaimAuthor(
347
+ "linear",
348
+ descriptor.workItem,
349
+ comment.user?.id,
350
+ await this.viewer()
351
+ );
352
+ required(
353
+ typeof comment.body === "string" &&
300
354
  sha256(unfence(comment.body)) === descriptor.claimSha256,
301
355
  "current tracker claim differs"
302
356
  );
357
+ return { created_at: comment.createdAt };
303
358
  }
304
359
  }
@@ -59,6 +59,49 @@ function linearCredentials(config, env) {
59
59
  return { baseUrl: "https://api.linear.app/graphql", authorization: key };
60
60
  }
61
61
 
62
+ /** A Jira accountId or a Linear user id, the same grammar the policy maintainer uses. */
63
+ const ACTOR = {
64
+ jira: /^[A-Za-z0-9][A-Za-z0-9:-]{0,127}$/,
65
+ linear: /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,
66
+ };
67
+ const ACTOR_NAME = { jira: "Jira accountId", linear: "Linear user id" };
68
+ const ACTOR_CREDENTIAL = { jira: "JIRA_API_TOKEN", linear: "LINEAR_API_KEY" };
69
+
70
+ /**
71
+ * The automation identity the project declares for its tracker (#4873). A claim,
72
+ * checkpoint or closure counts as the updater's own only when this account wrote
73
+ * it, so an absent or malformed declaration refuses before any provider call.
74
+ */
75
+ export function declaredActor(config) {
76
+ const tracker = config.tracker;
77
+ const value = config[tracker]?.claimActorRef;
78
+ if (typeof value !== "string" || !ACTOR[tracker]?.test(value))
79
+ throw operatorRefusal(
80
+ "tracker automation identity is not declared",
81
+ `${tracker}.claimActorRef is not set in .lisa.config.json, so the npm updater cannot tell its own claims from anyone else's. Set it to the ${ACTOR_NAME[tracker]} of the account its ${ACTOR_CREDENTIAL[tracker]} signs in as. Nothing was created.`
82
+ );
83
+ return value;
84
+ }
85
+
86
+ /** The credential must sign in as the declared identity; any other account fails closed. */
87
+ export function assertDeclaredActor(tracker, actual, declared) {
88
+ if (actual !== declared)
89
+ throw operatorRefusal(
90
+ "tracker credential is not the declared automation identity",
91
+ `The ${ACTOR_CREDENTIAL[tracker]} signs in as a different account than ${tracker}.claimActorRef, so the npm updater cannot prove its claims were made by the automation. Use the automation account's credential or correct ${tracker}.claimActorRef. Nothing was changed.`
92
+ );
93
+ return actual;
94
+ }
95
+
96
+ /** A claim written by any account but the declared automation identity never authorizes (#4873). */
97
+ export function assertClaimAuthor(tracker, ref, author, declared) {
98
+ if (author !== declared)
99
+ throw operatorRefusal(
100
+ "tracker claim author differs",
101
+ `The claim on ${ref} was not made by the npm updater's automation account (${tracker}.claimActorRef), so nothing was published or changed. Remove that claim and let the updater claim the item again.`
102
+ );
103
+ }
104
+
62
105
  /** Resolved before any provider call, so a gap can never follow a partial write. */
63
106
  export function trackerCredentials(config, env) {
64
107
  required(
@@ -94,7 +137,10 @@ async function boundedText(response) {
94
137
  );
95
138
  }
96
139
 
97
- /** One bounded JSON request; a refused status is opaque, never echoed. */
140
+ /**
141
+ * One bounded JSON request; a refused status is opaque, never echoed. Only a
142
+ * caller that sets `missing: true` reads a 404 as an absent record (null).
143
+ */
98
144
  export async function jsonCall(transport, url, request, purpose) {
99
145
  const method = request.method ?? "GET";
100
146
  return withProviderOperation(purpose, method, async () => {
@@ -113,6 +159,7 @@ export async function jsonCall(transport, url, request, purpose) {
113
159
  signal: AbortSignal.timeout(30_000),
114
160
  });
115
161
  const text = await boundedText(response);
162
+ if (request.missing === true && response.status === 404) return null;
116
163
  required(response.ok, "tracker provider refused request");
117
164
  return text ? JSON.parse(text) : null;
118
165
  });
@@ -166,7 +213,9 @@ function proseOf(node) {
166
213
  mark => mark?.type === "code"
167
214
  )
168
215
  ? `\`${inert(node.text).replace(/\n/g, " ")}\``
169
- : String(node.text ?? "");
216
+ : // A stray plain-text backtick would pair with a projected code boundary
217
+ // and move the hold classifier's view of what is code (#4873).
218
+ inert(node.text);
170
219
  if (node.type === "hardBreak") return "\n";
171
220
  const inline = node.type === "paragraph" || node.type === "heading";
172
221
  return (Array.isArray(node.content) ? node.content : [])
@@ -260,19 +309,60 @@ export function vendorLabels(lifecycle, names) {
260
309
 
261
310
  // Linear connection helpers, shared here to keep the Linear adapter within its size budget.
262
311
 
312
+ /** The node selection each issue connection reads; the issue query and its page queries share it. */
313
+ export const LINEAR_CONNECTIONS = {
314
+ labels: "name",
315
+ children: "id",
316
+ inverseRelations: "type issue { state { type } archivedAt }",
317
+ };
318
+ /** Pages per connection, 100 nodes each, before the inventory is called unbounded. */
319
+ const LINEAR_CONNECTION_PAGES = 10;
320
+
321
+ /** One connection's next page, addressed by the issue identifier and an opaque cursor. */
322
+ function connectionPageQuery(name) {
323
+ const operation = `LisaNpmIssue${name[0].toUpperCase()}${name.slice(1)}`;
324
+ return `query ${operation}($id: String!, $after: String) { issue(id: $id) { ${name}(first: 100, after: $after) { nodes { ${LINEAR_CONNECTIONS[name]} } pageInfo { hasNextPage endCursor } } } }`;
325
+ }
326
+
263
327
  /**
264
328
  * Labels, sub-issues and relations decide holds and blockers, so a partial
265
- * page is never read as the whole inventory: one more page refuses.
329
+ * page is never read as the whole inventory: each connection is read to its
330
+ * end by cursor, and one past the fixed bound refuses, naming the issue
331
+ * (CodySwannGT/lisa#4873).
332
+ * @param {object} node - The issue node, its connections on their first page.
333
+ * @param {(query: string, variables: object) => Promise<object>} graphql - Data-returning call.
334
+ * @returns {Promise<object>} The node with every connection's complete node list.
266
335
  */
267
- export function completeLinearConnections(node) {
268
- const partial = ["labels", "children", "inverseRelations"].some(
269
- name => node[name]?.pageInfo?.hasNextPage !== false
270
- );
271
- if (partial)
272
- throw operatorRefusal(
273
- "issue connection is incomplete",
274
- "This Linear issue has more than 100 labels, sub-issues or relations, so the npm updater cannot confirm there is no hold or open blocker. Remove the extra ones or handle this update by hand."
275
- );
336
+ export async function completeLinearConnections(node, graphql) {
337
+ const complete = {};
338
+ for (const name of Object.keys(LINEAR_CONNECTIONS)) {
339
+ let connection = node[name];
340
+ const nodes = [...(connection?.nodes ?? [])];
341
+ for (let page = 1; page <= LINEAR_CONNECTION_PAGES; page++) {
342
+ if (connection?.pageInfo?.hasNextPage === false) break;
343
+ if (
344
+ page === LINEAR_CONNECTION_PAGES ||
345
+ typeof connection?.pageInfo?.endCursor !== "string"
346
+ )
347
+ throw operatorRefusal(
348
+ "issue connection is incomplete",
349
+ `Linear issue ${node.identifier} has more than ${LINEAR_CONNECTION_PAGES * 100} labels, sub-issues or relations, so the npm updater cannot confirm there is no hold or open blocker. Remove the extra ones or handle this update by hand.`
350
+ );
351
+ connection = (
352
+ await graphql(connectionPageQuery(name), {
353
+ id: node.identifier,
354
+ after: connection.pageInfo.endCursor,
355
+ })
356
+ ).issue?.[name];
357
+ required(
358
+ Array.isArray(connection?.nodes),
359
+ "provider page is not an array"
360
+ );
361
+ nodes.push(...connection.nodes);
362
+ }
363
+ complete[name] = { nodes };
364
+ }
365
+ return { ...node, ...complete };
276
366
  }
277
367
 
278
368
  /** Completed, cancelled and archived issues are closed history, never claimable. */