@codyswann/lisa 8.1.1 → 8.2.1

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 (228) hide show
  1. package/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
  2. package/dist/core/upstream-evidence-manifest.json +146 -11
  3. package/package.json +4 -4
  4. package/plugins/lisa/.claude-plugin/plugin.json +1 -1
  5. package/plugins/lisa/.codex-plugin/plugin.json +1 -1
  6. package/plugins/lisa/.codex-plugin/scripts/queue-contract-resolution.mjs +583 -0
  7. package/plugins/lisa/.codex-plugin/scripts/ready-queue-order.mjs +99 -25
  8. package/plugins/lisa/.codex-plugin/scripts/stale-blocker-comment.mjs +185 -0
  9. package/plugins/lisa/.codex-plugin/scripts/stale-blocker-confirm.mjs +130 -0
  10. package/plugins/lisa/.codex-plugin/scripts/stale-blocker-edges.mjs +466 -0
  11. package/plugins/lisa/.codex-plugin/scripts/stale-blocker-pending.mjs +257 -0
  12. package/plugins/lisa/.codex-plugin/scripts/stale-blocker-restore.mjs +180 -0
  13. package/plugins/lisa/.codex-plugin/scripts/stale-blocker-summary.mjs +239 -0
  14. package/plugins/lisa/.codex-plugin/scripts/stale-blocker-sweep.mjs +397 -0
  15. package/plugins/lisa/.codex-plugin/scripts/stale-blocker-verify.mjs +194 -0
  16. package/plugins/lisa/.codex-plugin/skills/lisa-atlassian-access/SKILL.md +1 -0
  17. package/plugins/lisa/.codex-plugin/skills/lisa-github-build-intake/SKILL.md +2 -7
  18. package/plugins/lisa/.codex-plugin/skills/lisa-jira-build-intake/SKILL.md +2 -0
  19. package/plugins/lisa/.codex-plugin/skills/lisa-linear-access/SKILL.md +44 -0
  20. package/plugins/lisa/.codex-plugin/skills/lisa-linear-build-intake/SKILL.md +2 -0
  21. package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/SKILL.md +127 -2
  22. package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/cli-queue.mjs +90 -20
  23. package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/cli-stale-links-results.mjs +254 -0
  24. package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/cli-stale-links.mjs +243 -0
  25. package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/cli-usage.mjs +60 -0
  26. package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/queue-github.mjs +68 -8
  27. package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/session-manager.mjs +49 -0
  28. package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/stale-links-github.mjs +196 -0
  29. package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/stale-links-state.mjs +173 -0
  30. package/plugins/lisa/scripts/ready-queue-order.mjs +99 -25
  31. package/plugins/lisa/scripts/stale-blocker-comment.mjs +185 -0
  32. package/plugins/lisa/scripts/stale-blocker-confirm.mjs +130 -0
  33. package/plugins/lisa/scripts/stale-blocker-edges.mjs +466 -0
  34. package/plugins/lisa/scripts/stale-blocker-pending.mjs +257 -0
  35. package/plugins/lisa/scripts/stale-blocker-restore.mjs +180 -0
  36. package/plugins/lisa/scripts/stale-blocker-summary.mjs +239 -0
  37. package/plugins/lisa/scripts/stale-blocker-sweep.mjs +397 -0
  38. package/plugins/lisa/scripts/stale-blocker-verify.mjs +194 -0
  39. package/plugins/lisa/skills/lisa-atlassian-access/SKILL.md +1 -0
  40. package/plugins/lisa/skills/lisa-github-build-intake/SKILL.md +2 -7
  41. package/plugins/lisa/skills/lisa-jira-build-intake/SKILL.md +2 -0
  42. package/plugins/lisa/skills/lisa-linear-access/SKILL.md +44 -0
  43. package/plugins/lisa/skills/lisa-linear-build-intake/SKILL.md +2 -0
  44. package/plugins/lisa/skills/lisa-session-manager/SKILL.md +127 -2
  45. package/plugins/lisa/skills/lisa-session-manager/scripts/cli-queue.mjs +90 -20
  46. package/plugins/lisa/skills/lisa-session-manager/scripts/cli-stale-links-results.mjs +254 -0
  47. package/plugins/lisa/skills/lisa-session-manager/scripts/cli-stale-links.mjs +243 -0
  48. package/plugins/lisa/skills/lisa-session-manager/scripts/cli-usage.mjs +60 -0
  49. package/plugins/lisa/skills/lisa-session-manager/scripts/queue-github.mjs +68 -8
  50. package/plugins/lisa/skills/lisa-session-manager/scripts/session-manager.mjs +49 -0
  51. package/plugins/lisa/skills/lisa-session-manager/scripts/stale-links-github.mjs +196 -0
  52. package/plugins/lisa/skills/lisa-session-manager/scripts/stale-links-state.mjs +173 -0
  53. package/plugins/lisa-agy/plugin.json +1 -1
  54. package/plugins/lisa-agy/scripts/ready-queue-order.mjs +99 -25
  55. package/plugins/lisa-agy/scripts/stale-blocker-comment.mjs +185 -0
  56. package/plugins/lisa-agy/scripts/stale-blocker-confirm.mjs +130 -0
  57. package/plugins/lisa-agy/scripts/stale-blocker-edges.mjs +466 -0
  58. package/plugins/lisa-agy/scripts/stale-blocker-pending.mjs +257 -0
  59. package/plugins/lisa-agy/scripts/stale-blocker-restore.mjs +180 -0
  60. package/plugins/lisa-agy/scripts/stale-blocker-summary.mjs +239 -0
  61. package/plugins/lisa-agy/scripts/stale-blocker-sweep.mjs +397 -0
  62. package/plugins/lisa-agy/scripts/stale-blocker-verify.mjs +194 -0
  63. package/plugins/lisa-agy/skills/lisa-atlassian-access/SKILL.md +1 -0
  64. package/plugins/lisa-agy/skills/lisa-github-build-intake/SKILL.md +2 -7
  65. package/plugins/lisa-agy/skills/lisa-jira-build-intake/SKILL.md +2 -0
  66. package/plugins/lisa-agy/skills/lisa-linear-access/SKILL.md +44 -0
  67. package/plugins/lisa-agy/skills/lisa-linear-build-intake/SKILL.md +2 -0
  68. package/plugins/lisa-agy/skills/lisa-session-manager/SKILL.md +127 -2
  69. package/plugins/lisa-agy/skills/lisa-session-manager/scripts/cli-queue.mjs +90 -20
  70. package/plugins/lisa-agy/skills/lisa-session-manager/scripts/cli-stale-links-results.mjs +254 -0
  71. package/plugins/lisa-agy/skills/lisa-session-manager/scripts/cli-stale-links.mjs +243 -0
  72. package/plugins/lisa-agy/skills/lisa-session-manager/scripts/cli-usage.mjs +60 -0
  73. package/plugins/lisa-agy/skills/lisa-session-manager/scripts/queue-github.mjs +68 -8
  74. package/plugins/lisa-agy/skills/lisa-session-manager/scripts/session-manager.mjs +49 -0
  75. package/plugins/lisa-agy/skills/lisa-session-manager/scripts/stale-links-github.mjs +196 -0
  76. package/plugins/lisa-agy/skills/lisa-session-manager/scripts/stale-links-state.mjs +173 -0
  77. package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
  78. package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
  79. package/plugins/lisa-cdk-agy/plugin.json +1 -1
  80. package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
  81. package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
  82. package/plugins/lisa-cdk-devin/.claude-plugin/plugin.json +1 -1
  83. package/plugins/lisa-cdk-devin/.devin-plugin/plugin.json +1 -1
  84. package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
  85. package/plugins/lisa-copilot/scripts/ready-queue-order.mjs +99 -25
  86. package/plugins/lisa-copilot/scripts/stale-blocker-comment.mjs +185 -0
  87. package/plugins/lisa-copilot/scripts/stale-blocker-confirm.mjs +130 -0
  88. package/plugins/lisa-copilot/scripts/stale-blocker-edges.mjs +466 -0
  89. package/plugins/lisa-copilot/scripts/stale-blocker-pending.mjs +257 -0
  90. package/plugins/lisa-copilot/scripts/stale-blocker-restore.mjs +180 -0
  91. package/plugins/lisa-copilot/scripts/stale-blocker-summary.mjs +239 -0
  92. package/plugins/lisa-copilot/scripts/stale-blocker-sweep.mjs +397 -0
  93. package/plugins/lisa-copilot/scripts/stale-blocker-verify.mjs +194 -0
  94. package/plugins/lisa-copilot/skills/lisa-atlassian-access/SKILL.md +1 -0
  95. package/plugins/lisa-copilot/skills/lisa-github-build-intake/SKILL.md +2 -7
  96. package/plugins/lisa-copilot/skills/lisa-jira-build-intake/SKILL.md +2 -0
  97. package/plugins/lisa-copilot/skills/lisa-linear-access/SKILL.md +44 -0
  98. package/plugins/lisa-copilot/skills/lisa-linear-build-intake/SKILL.md +2 -0
  99. package/plugins/lisa-copilot/skills/lisa-session-manager/SKILL.md +127 -2
  100. package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/cli-queue.mjs +90 -20
  101. package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/cli-stale-links-results.mjs +254 -0
  102. package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/cli-stale-links.mjs +243 -0
  103. package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/cli-usage.mjs +60 -0
  104. package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/queue-github.mjs +68 -8
  105. package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/session-manager.mjs +49 -0
  106. package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/stale-links-github.mjs +196 -0
  107. package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/stale-links-state.mjs +173 -0
  108. package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
  109. package/plugins/lisa-cursor/scripts/ready-queue-order.mjs +99 -25
  110. package/plugins/lisa-cursor/scripts/stale-blocker-comment.mjs +185 -0
  111. package/plugins/lisa-cursor/scripts/stale-blocker-confirm.mjs +130 -0
  112. package/plugins/lisa-cursor/scripts/stale-blocker-edges.mjs +466 -0
  113. package/plugins/lisa-cursor/scripts/stale-blocker-pending.mjs +257 -0
  114. package/plugins/lisa-cursor/scripts/stale-blocker-restore.mjs +180 -0
  115. package/plugins/lisa-cursor/scripts/stale-blocker-summary.mjs +239 -0
  116. package/plugins/lisa-cursor/scripts/stale-blocker-sweep.mjs +397 -0
  117. package/plugins/lisa-cursor/scripts/stale-blocker-verify.mjs +194 -0
  118. package/plugins/lisa-cursor/skills/lisa-atlassian-access/SKILL.md +1 -0
  119. package/plugins/lisa-cursor/skills/lisa-github-build-intake/SKILL.md +2 -7
  120. package/plugins/lisa-cursor/skills/lisa-jira-build-intake/SKILL.md +2 -0
  121. package/plugins/lisa-cursor/skills/lisa-linear-access/SKILL.md +44 -0
  122. package/plugins/lisa-cursor/skills/lisa-linear-build-intake/SKILL.md +2 -0
  123. package/plugins/lisa-cursor/skills/lisa-session-manager/SKILL.md +127 -2
  124. package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/cli-queue.mjs +90 -20
  125. package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/cli-stale-links-results.mjs +254 -0
  126. package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/cli-stale-links.mjs +243 -0
  127. package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/cli-usage.mjs +60 -0
  128. package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/queue-github.mjs +68 -8
  129. package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/session-manager.mjs +49 -0
  130. package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/stale-links-github.mjs +196 -0
  131. package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/stale-links-state.mjs +173 -0
  132. package/plugins/lisa-devin/.claude-plugin/plugin.json +1 -1
  133. package/plugins/lisa-devin/.devin-plugin/plugin.json +1 -1
  134. package/plugins/lisa-devin/scripts/ready-queue-order.mjs +99 -25
  135. package/plugins/lisa-devin/scripts/stale-blocker-comment.mjs +185 -0
  136. package/plugins/lisa-devin/scripts/stale-blocker-confirm.mjs +130 -0
  137. package/plugins/lisa-devin/scripts/stale-blocker-edges.mjs +466 -0
  138. package/plugins/lisa-devin/scripts/stale-blocker-pending.mjs +257 -0
  139. package/plugins/lisa-devin/scripts/stale-blocker-restore.mjs +180 -0
  140. package/plugins/lisa-devin/scripts/stale-blocker-summary.mjs +239 -0
  141. package/plugins/lisa-devin/scripts/stale-blocker-sweep.mjs +397 -0
  142. package/plugins/lisa-devin/scripts/stale-blocker-verify.mjs +194 -0
  143. package/plugins/lisa-devin/skills/lisa-atlassian-access/SKILL.md +1 -0
  144. package/plugins/lisa-devin/skills/lisa-github-build-intake/SKILL.md +2 -7
  145. package/plugins/lisa-devin/skills/lisa-jira-build-intake/SKILL.md +2 -0
  146. package/plugins/lisa-devin/skills/lisa-linear-access/SKILL.md +44 -0
  147. package/plugins/lisa-devin/skills/lisa-linear-build-intake/SKILL.md +2 -0
  148. package/plugins/lisa-devin/skills/lisa-session-manager/SKILL.md +127 -2
  149. package/plugins/lisa-devin/skills/lisa-session-manager/scripts/cli-queue.mjs +90 -20
  150. package/plugins/lisa-devin/skills/lisa-session-manager/scripts/cli-stale-links-results.mjs +254 -0
  151. package/plugins/lisa-devin/skills/lisa-session-manager/scripts/cli-stale-links.mjs +243 -0
  152. package/plugins/lisa-devin/skills/lisa-session-manager/scripts/cli-usage.mjs +60 -0
  153. package/plugins/lisa-devin/skills/lisa-session-manager/scripts/queue-github.mjs +68 -8
  154. package/plugins/lisa-devin/skills/lisa-session-manager/scripts/session-manager.mjs +49 -0
  155. package/plugins/lisa-devin/skills/lisa-session-manager/scripts/stale-links-github.mjs +196 -0
  156. package/plugins/lisa-devin/skills/lisa-session-manager/scripts/stale-links-state.mjs +173 -0
  157. package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
  158. package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
  159. package/plugins/lisa-expo-agy/plugin.json +1 -1
  160. package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
  161. package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
  162. package/plugins/lisa-expo-devin/.claude-plugin/plugin.json +1 -1
  163. package/plugins/lisa-expo-devin/.devin-plugin/plugin.json +1 -1
  164. package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
  165. package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
  166. package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
  167. package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
  168. package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
  169. package/plugins/lisa-harper-fabric-devin/.claude-plugin/plugin.json +1 -1
  170. package/plugins/lisa-harper-fabric-devin/.devin-plugin/plugin.json +1 -1
  171. package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
  172. package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
  173. package/plugins/lisa-nestjs-agy/plugin.json +1 -1
  174. package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
  175. package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
  176. package/plugins/lisa-nestjs-devin/.claude-plugin/plugin.json +1 -1
  177. package/plugins/lisa-nestjs-devin/.devin-plugin/plugin.json +1 -1
  178. package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
  179. package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
  180. package/plugins/lisa-phaser-agy/plugin.json +1 -1
  181. package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
  182. package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
  183. package/plugins/lisa-phaser-devin/.claude-plugin/plugin.json +1 -1
  184. package/plugins/lisa-phaser-devin/.devin-plugin/plugin.json +1 -1
  185. package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
  186. package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
  187. package/plugins/lisa-rails-agy/plugin.json +1 -1
  188. package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
  189. package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
  190. package/plugins/lisa-rails-devin/.claude-plugin/plugin.json +1 -1
  191. package/plugins/lisa-rails-devin/.devin-plugin/plugin.json +1 -1
  192. package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
  193. package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
  194. package/plugins/lisa-typescript-agy/plugin.json +1 -1
  195. package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
  196. package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
  197. package/plugins/lisa-typescript-devin/.claude-plugin/plugin.json +1 -1
  198. package/plugins/lisa-typescript-devin/.devin-plugin/plugin.json +1 -1
  199. package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
  200. package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
  201. package/plugins/lisa-wiki-agy/plugin.json +1 -1
  202. package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
  203. package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
  204. package/plugins/lisa-wiki-devin/.claude-plugin/plugin.json +1 -1
  205. package/plugins/lisa-wiki-devin/.devin-plugin/plugin.json +1 -1
  206. package/plugins/src/base/scripts/ready-queue-order.mjs +99 -25
  207. package/plugins/src/base/scripts/stale-blocker-comment.mjs +185 -0
  208. package/plugins/src/base/scripts/stale-blocker-confirm.mjs +130 -0
  209. package/plugins/src/base/scripts/stale-blocker-edges.mjs +466 -0
  210. package/plugins/src/base/scripts/stale-blocker-pending.mjs +257 -0
  211. package/plugins/src/base/scripts/stale-blocker-restore.mjs +180 -0
  212. package/plugins/src/base/scripts/stale-blocker-summary.mjs +239 -0
  213. package/plugins/src/base/scripts/stale-blocker-sweep.mjs +397 -0
  214. package/plugins/src/base/scripts/stale-blocker-verify.mjs +194 -0
  215. package/plugins/src/base/skills/lisa-atlassian-access/SKILL.md +1 -0
  216. package/plugins/src/base/skills/lisa-github-build-intake/SKILL.md +2 -7
  217. package/plugins/src/base/skills/lisa-jira-build-intake/SKILL.md +2 -0
  218. package/plugins/src/base/skills/lisa-linear-access/SKILL.md +44 -0
  219. package/plugins/src/base/skills/lisa-linear-build-intake/SKILL.md +2 -0
  220. package/plugins/src/base/skills/lisa-session-manager/SKILL.md +127 -2
  221. package/plugins/src/base/skills/lisa-session-manager/scripts/cli-queue.mjs +90 -20
  222. package/plugins/src/base/skills/lisa-session-manager/scripts/cli-stale-links-results.mjs +254 -0
  223. package/plugins/src/base/skills/lisa-session-manager/scripts/cli-stale-links.mjs +243 -0
  224. package/plugins/src/base/skills/lisa-session-manager/scripts/cli-usage.mjs +60 -0
  225. package/plugins/src/base/skills/lisa-session-manager/scripts/queue-github.mjs +68 -8
  226. package/plugins/src/base/skills/lisa-session-manager/scripts/session-manager.mjs +49 -0
  227. package/plugins/src/base/skills/lisa-session-manager/scripts/stale-links-github.mjs +196 -0
  228. package/plugins/src/base/skills/lisa-session-manager/scripts/stale-links-state.mjs +173 -0
@@ -0,0 +1,257 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Comments owed for stale-link removals that are already confirmed
4
+ * (CodySwannGT/lisa#5065).
5
+ *
6
+ * Once a removal reads back as done, its link is gone and no later plan will
7
+ * see it again. If posting the comment then fails, or the writer is stopped
8
+ * before it posts, the operator would never learn why the link went. So each
9
+ * confirmed removal is recorded here as pending until its comment is posted,
10
+ * and pending comments are retried on their own, separately from any new
11
+ * plan. The record is plain JSON so any agent can keep it in its state
12
+ * directory; the functions here are pure and do no I/O.
13
+ *
14
+ * The same directory keeps a second record: the items whose planned
15
+ * removals did NOT happen. Their links are still there, so every cycle plans
16
+ * them again; without the record, items that keep failing and sort first
17
+ * would spend the per-cycle cap every time and starve later items. The
18
+ * planner puts a recorded item after every other candidate
19
+ * (`planStaleLinkSweep({failures})`), and a removal that later succeeds
20
+ * clears its record, so it returns to the normal order.
21
+ * @module stale-blocker-pending
22
+ */
23
+
24
+ /**
25
+ * One comment still owed.
26
+ * @typedef {object} PendingComment
27
+ * @property {string} ref - The item
28
+ * @property {string[]} removed - Its confirmed removals
29
+ * @property {string} comment - The comment to post
30
+ * @property {object | null} commentAdf - The same as ADF for Jira, else null
31
+ * @property {string} since - When the removal was confirmed (ISO time)
32
+ * @property {number} attempts - Failed posts so far
33
+ */
34
+
35
+ /**
36
+ * @param {{ ref: string, removed: readonly string[] }} entry
37
+ * @returns {string} Identity of a pending comment
38
+ */
39
+ const keyOf = entry =>
40
+ `${entry.ref}|${[...(entry.removed ?? [])].sort().join(",")}`;
41
+
42
+ /**
43
+ * Record the comment owed for one verified result. A result with nothing
44
+ * confirmed owes nothing; recording the same removals twice keeps one entry.
45
+ * @param {readonly PendingComment[]} pending
46
+ * @param {Pick<import("./stale-blocker-verify.mjs").StaleLinkResult, "ref" | "confirmed" | "comment"> & { commentAdf?: object | null }} result - A verify result
47
+ * @param {string} now - ISO time
48
+ * @returns {PendingComment[]}
49
+ */
50
+ export function addPending(pending, result, now) {
51
+ const list = Array.isArray(pending) ? [...pending] : [];
52
+ if (!result?.comment || result.confirmed.length === 0) return list;
53
+ const entry = {
54
+ ref: result.ref,
55
+ removed: [...result.confirmed],
56
+ comment: result.comment,
57
+ commentAdf: result.commentAdf ?? null,
58
+ since: now,
59
+ attempts: 0,
60
+ };
61
+ return list.some(one => keyOf(one) === keyOf(entry))
62
+ ? list
63
+ : [...list, entry];
64
+ }
65
+
66
+ /**
67
+ * Drop the ONE comment that just posted: an item can owe more than one (a
68
+ * post failed, then a later cycle confirmed other removals), and each is
69
+ * identified by its item and its removed set, as {@link addPending} keys it.
70
+ * @param {readonly PendingComment[]} pending
71
+ * @param {string} ref
72
+ * @param {readonly string[]} removed - The posted comment's `removed`
73
+ * @returns {PendingComment[]}
74
+ */
75
+ export const settlePending = (pending, ref, removed) => {
76
+ const key = keyOf({ ref, removed });
77
+ return (Array.isArray(pending) ? pending : []).filter(
78
+ one => keyOf(one) !== key
79
+ );
80
+ };
81
+
82
+ /**
83
+ * Count one more failed post for that one comment.
84
+ * @param {readonly PendingComment[]} pending
85
+ * @param {string} ref
86
+ * @param {readonly string[]} removed - The comment's `removed`
87
+ * @returns {PendingComment[]}
88
+ */
89
+ export const failedPending = (pending, ref, removed) => {
90
+ const key = keyOf({ ref, removed });
91
+ return (Array.isArray(pending) ? pending : []).map(one =>
92
+ keyOf(one) === key
93
+ ? { ...one, attempts: Number(one.attempts ?? 0) + 1 }
94
+ : one
95
+ );
96
+ };
97
+
98
+ /**
99
+ * Items whose planned removals did not happen, by ref.
100
+ * @typedef {Record<string, { attempts: number, since: string, stillPresent: string[] }>} RemovalFailures
101
+ */
102
+
103
+ /**
104
+ * Update the failure record from one verified result: a planned removal
105
+ * still on the item counts one more failure; none left clears the record.
106
+ * @param {RemovalFailures | undefined} failures
107
+ * @param {{ ref: string, stillPresent: readonly string[] }} result
108
+ * @param {string} now - ISO time
109
+ * @returns {RemovalFailures}
110
+ */
111
+ export function recordRemovalResult(failures, result, now) {
112
+ const current =
113
+ failures && typeof failures === "object" && !Array.isArray(failures)
114
+ ? failures
115
+ : {};
116
+ const { [result.ref]: previous, ...rest } = current;
117
+ if (result.stillPresent.length === 0) return rest;
118
+ return {
119
+ ...rest,
120
+ [result.ref]: {
121
+ attempts: Number(previous?.attempts ?? 0) + 1,
122
+ since: previous?.since ?? now,
123
+ stillPresent: [...result.stillPresent],
124
+ },
125
+ };
126
+ }
127
+
128
+ /**
129
+ * Confirmed plan entries whose writes are about to run, by item ref. A
130
+ * confirm records its entry here BEFORE any delete, and only a verify that
131
+ * read the item back settles it. So a read-back that fails after the
132
+ * deletes ran (or a writer stopped in between) leaves the removals
133
+ * recoverable: the entry is verified again on the next cycle instead of its
134
+ * links vanishing with no comment and no restore check.
135
+ * @typedef {Record<string, { plan: object, since: string, attempts: number }>} InFlight
136
+ */
137
+
138
+ /**
139
+ * @param {unknown} value
140
+ * @returns {Record<string, any>}
141
+ */
142
+ const recordOf = value =>
143
+ value && typeof value === "object" && !Array.isArray(value) ? value : {};
144
+
145
+ /**
146
+ * Record one confirmed plan entry as in flight. An item that still has an
147
+ * unsettled entry is refused, never overwritten: that entry may hold links
148
+ * already removed whose read-back failed, and it is their only recovery
149
+ * record. Verify it first (`stale-links-pending` lists it as unverified).
150
+ * @param {InFlight | undefined} inflight
151
+ * @param {{ ref: string }} plan - The confirmed plan entry
152
+ * @param {string} now - ISO time
153
+ * @returns {InFlight}
154
+ */
155
+ export function recordInFlight(inflight, plan, now) {
156
+ const current = recordOf(inflight);
157
+ if (Object.hasOwn(current, plan.ref)) {
158
+ throw new Error(
159
+ `${plan.ref} still has an earlier stale-link plan whose read-back has not succeeded; verify that one first (stale-links-pending lists it under unverified), then plan again.`
160
+ );
161
+ }
162
+ return { ...current, [plan.ref]: { plan, since: now, attempts: 0 } };
163
+ }
164
+
165
+ /**
166
+ * Settle an item's in-flight entry after a verify read it back.
167
+ * @param {InFlight | undefined} inflight
168
+ * @param {string} ref
169
+ * @returns {InFlight}
170
+ */
171
+ export function settleInFlight(inflight, ref) {
172
+ const { [ref]: _settled, ...rest } = recordOf(inflight);
173
+ return rest;
174
+ }
175
+
176
+ /**
177
+ * Count one more failed verify for an item's in-flight entry.
178
+ * @param {InFlight | undefined} inflight
179
+ * @param {string} ref
180
+ * @returns {InFlight}
181
+ */
182
+ export function failedInFlight(inflight, ref) {
183
+ const current = recordOf(inflight);
184
+ if (!Object.hasOwn(current, ref)) return current;
185
+ return {
186
+ ...current,
187
+ [ref]: {
188
+ ...current[ref],
189
+ attempts: Number(current[ref].attempts ?? 0) + 1,
190
+ },
191
+ };
192
+ }
193
+
194
+ /**
195
+ * Links owed back to an item, by ref: removed links whose blocker reopened
196
+ * before the delete. Each stays owed until a read-back shows it present
197
+ * again, and the queue holds its item from dispatch meanwhile, because the
198
+ * item would otherwise look unblocked while its blocker is open.
199
+ * Only the links are kept: the actions that put them back are computed from
200
+ * a fresh read each time (`restoreActions`), so a re-added `Blocked by` line
201
+ * never overwrites a body edited since.
202
+ * @typedef {Record<string, { links: { blockerRef: string, source: string, actionId: string, linkType?: string }[], since: string, attempts: number }>} OwedRestores
203
+ */
204
+
205
+ /**
206
+ * Record the restores one verify result owes (merging with any already owed
207
+ * for the item).
208
+ * @param {OwedRestores | undefined} owed
209
+ * @param {{ ref: string, restored: readonly { blockerRef: string }[] }} result
210
+ * @param {readonly { blockerRef: string, source: string, actionId: string, linkType?: string }[]} links - The plan's links
211
+ * @param {string} now - ISO time
212
+ * @returns {OwedRestores}
213
+ */
214
+ export function recordRestores(owed, result, links, now) {
215
+ const current = recordOf(owed);
216
+ if ((result.restored ?? []).length === 0) return current;
217
+ const back = new Set(result.restored.map(one => one.blockerRef));
218
+ const previous = current[result.ref];
219
+ const merged = [
220
+ ...(previous?.links ?? []).filter(link => !back.has(link.blockerRef)),
221
+ ...links.filter(link => back.has(link.blockerRef)),
222
+ ];
223
+ return {
224
+ ...current,
225
+ [result.ref]: {
226
+ links: merged,
227
+ since: previous?.since ?? now,
228
+ attempts: Number(previous?.attempts ?? 0),
229
+ },
230
+ };
231
+ }
232
+
233
+ /**
234
+ * Settle the owed restores a read-back shows done: each owed link whose
235
+ * blocker is linked again is dropped; the item's entry goes once none is
236
+ * left, and otherwise counts one more failed try.
237
+ * @param {OwedRestores | undefined} owed
238
+ * @param {string} ref
239
+ * @param {ReadonlySet<string>} present - Blocker refs linked on the item now
240
+ * @returns {OwedRestores}
241
+ */
242
+ export function settleRestores(owed, ref, present) {
243
+ const current = recordOf(owed);
244
+ const entry = current[ref];
245
+ if (!entry) return current;
246
+ const { [ref]: _entry, ...rest } = current;
247
+ const left = entry.links.filter(link => !present.has(link.blockerRef));
248
+ if (left.length === 0) return rest;
249
+ return {
250
+ ...rest,
251
+ [ref]: {
252
+ ...entry,
253
+ links: left,
254
+ attempts: Number(entry.attempts ?? 0) + 1,
255
+ },
256
+ };
257
+ }
@@ -0,0 +1,180 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Put back a link whose blocker reopened between the confirm and the delete
4
+ * (CodySwannGT/lisa#5065).
5
+ *
6
+ * No tracker offers a conditional delete ("remove this link only while its
7
+ * blocker is still finished"), so the confirm re-read leaves a window of
8
+ * seconds in which a person can reopen the blocker. After the delete, the
9
+ * writer reads each removed blocker again. A blocker that is no longer safe
10
+ * to delete (reopened, moved back to an intermediate done rung, or unreadable)
11
+ * gets its link recreated, no marker, and a line in the report; only the
12
+ * removals whose blocker is still finished are confirmed.
13
+ *
14
+ * Pure: it judges and returns the vendor actions, and the writer performs
15
+ * them through the access layers.
16
+ * @module stale-blocker-restore
17
+ */
18
+
19
+ import {
20
+ blockerResolution,
21
+ githubBlockerEdges,
22
+ isRemovable,
23
+ jiraBlockerEdges,
24
+ linearBlockerEdges,
25
+ } from "./stale-blocker-edges.mjs";
26
+
27
+ /**
28
+ * @param {unknown} value
29
+ * @returns {string}
30
+ */
31
+ const text = value => (typeof value === "string" ? value : "");
32
+
33
+ /**
34
+ * The verdict for one removed blocker as read NOW. A blocker with no read is
35
+ * inaccessible, which is never safe to delete.
36
+ * @param {string} tracker
37
+ * @param {{ ref: string, project: string, repo: string }} item
38
+ * @param {string} ref - The blocker
39
+ * @param {Record<string, any> | null | undefined} raw - The blocker as read now
40
+ * @param {{ doneRoles: readonly string[], landedRoles?: readonly string[] }} roles
41
+ * @returns {string} Verdict
42
+ */
43
+ export function verdictNow(tracker, item, ref, raw, roles) {
44
+ const [edge] =
45
+ tracker === "github"
46
+ ? githubBlockerEdges({
47
+ repo: item.repo,
48
+ body: `Blocked by ${ref}`,
49
+ bodyBlockers: raw ? { [ref]: raw } : {},
50
+ })
51
+ : tracker === "jira"
52
+ ? jiraBlockerEdges({
53
+ fields: {
54
+ issuelinks: [
55
+ {
56
+ id: "now",
57
+ type: { inward: "is blocked by" },
58
+ inwardIssue: raw ?? { key: ref },
59
+ },
60
+ ],
61
+ },
62
+ })
63
+ : linearBlockerEdges({
64
+ inverseRelations: [
65
+ { id: "now", type: "blocks", issue: raw ?? { identifier: ref } },
66
+ ],
67
+ });
68
+ return blockerResolution(
69
+ edge,
70
+ roles.doneRoles,
71
+ item.project,
72
+ roles.landedRoles
73
+ );
74
+ }
75
+
76
+ /**
77
+ * The `Blocked by` line that names these refs again, short where local. It
78
+ * goes FIRST: the top of a body is always outside any code fence, while the
79
+ * end may sit inside an unclosed one, where the line would be literal text
80
+ * and the relationship would not come back. The existing body is kept as is.
81
+ * @param {string} body - The body as read back
82
+ * @param {readonly string[]} refs - Canonical refs
83
+ * @param {string} repo - The item's own repo
84
+ * @returns {string}
85
+ */
86
+ function bodyWithRefs(body, refs, repo) {
87
+ const own = `${repo}#`;
88
+ const line = `Blocked by ${refs
89
+ .map(ref => (ref.startsWith(own) ? `#${ref.slice(own.length)}` : ref))
90
+ .join(", ")}`;
91
+ return body.trim() === "" ? line : `${line}\n\n${body}`;
92
+ }
93
+
94
+ /**
95
+ * The vendor actions that recreate these links.
96
+ * @param {string} tracker
97
+ * @param {{ ref: string, repo: string, body: string }} item - As read back
98
+ * @param {readonly { blockerRef: string, source: string, actionId: string, linkType?: string }[]} links
99
+ * @returns {object[]}
100
+ */
101
+ export function restoreActions(tracker, item, links) {
102
+ if (tracker === "jira") {
103
+ return links.map(link => ({
104
+ op: "link",
105
+ from: link.blockerRef,
106
+ to: item.ref,
107
+ type: link.linkType || "Blocks",
108
+ }));
109
+ }
110
+ if (tracker === "linear") {
111
+ return links.map(link => ({
112
+ op: "create-relation",
113
+ issue: link.blockerRef,
114
+ relatedIssue: item.ref,
115
+ type: "blocks",
116
+ }));
117
+ }
118
+ const number = item.ref.split("#")[1];
119
+ const native = links
120
+ .filter(link => link.source === "github-native")
121
+ .map(link => ({
122
+ op: "add-dependency",
123
+ endpoint: `repos/${item.repo}/issues/${number}/dependencies/blocked_by`,
124
+ issueId: link.actionId,
125
+ }));
126
+ const bodyRefs = links
127
+ .filter(link => link.source === "github-body")
128
+ .map(link => link.blockerRef);
129
+ return bodyRefs.length === 0
130
+ ? native
131
+ : [
132
+ ...native,
133
+ { op: "body", body: bodyWithRefs(item.body, bodyRefs, item.repo) },
134
+ ];
135
+ }
136
+
137
+ /**
138
+ * Split the removals the read-back shows gone into those whose blocker is
139
+ * still finished (confirmed) and those to put back.
140
+ * @param {{
141
+ * tracker: "github" | "jira" | "linear",
142
+ * item: { ref: string, project: string, repo: string, body: string },
143
+ * gone: readonly string[],
144
+ * links: readonly { blockerRef: string, source: string, actionId: string, linkType?: string }[],
145
+ * blockersNow: Record<string, Record<string, any> | null>,
146
+ * doneRoles: readonly string[],
147
+ * landedRoles?: readonly string[],
148
+ * }} input - `blockersNow` holds each removed blocker as read after the delete
149
+ * @returns {{ confirmed: string[], restored: { blockerRef: string, verdict: string }[], restore: object[] }}
150
+ */
151
+ export function splitReopened(input) {
152
+ const verdicts = new Map(
153
+ input.gone.map(ref => [
154
+ ref,
155
+ verdictNow(
156
+ input.tracker,
157
+ input.item,
158
+ ref,
159
+ input.blockersNow?.[ref] ?? null,
160
+ input
161
+ ),
162
+ ])
163
+ );
164
+ const reopened = input.gone.filter(
165
+ ref => !isRemovable(text(verdicts.get(ref)))
166
+ );
167
+ const back = new Set(reopened);
168
+ return {
169
+ confirmed: input.gone.filter(ref => !back.has(ref)),
170
+ restored: reopened.map(ref => ({
171
+ blockerRef: ref,
172
+ verdict: text(verdicts.get(ref)),
173
+ })),
174
+ restore: restoreActions(
175
+ input.tracker,
176
+ input.item,
177
+ input.links.filter(link => back.has(link.blockerRef))
178
+ ),
179
+ };
180
+ }
@@ -0,0 +1,239 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Counts and the one-line cycle summary for the stale-link sweep
4
+ * (CodySwannGT/lisa#5065), split from `stale-blocker-sweep.mjs` to keep each
5
+ * file within its line budget. The summary is what the session manager's
6
+ * cycle status line says: how many stale links it cleared and how many real
7
+ * blockers remain, in words an operator can act on.
8
+ * @module stale-blocker-summary
9
+ */
10
+
11
+ import { isResolved } from "./stale-blocker-edges.mjs";
12
+
13
+ /**
14
+ * What one sweep found.
15
+ * @typedef {object} StaleLinkReport
16
+ * @property {number} scanned - Items read
17
+ * @property {number} skippedBlockedRole - Items left to the Blocked sweep
18
+ * @property {string[]} unknownStatus - Items left alone because their own status was not read
19
+ * @property {number} cleared - Links planned for removal
20
+ * @property {number} itemsCleared - Items with a planned removal
21
+ * @property {string[]} claimable - Ready items nothing holds any more
22
+ * @property {string[]} deferred - Items left for the next cycle
23
+ * @property {number} realBlockers - Links that still hold their item: an
24
+ * open blocker in this project or in another one
25
+ * @property {number} itemsWithRealBlockers - Items with one
26
+ * @property {number} crossProject - Links to another project, left alone
27
+ * @property {{ ref: string, blocker: string }[]} inaccessible - Blockers that could not be read
28
+ * @property {{ ref: string, blocker: string }[]} keptByPerson - Links a person put back
29
+ * @property {number} [landed] - Links kept to work merged but not yet in production (they hold nothing)
30
+ */
31
+
32
+ /**
33
+ * @param {readonly object[]} list
34
+ * @returns {number}
35
+ */
36
+ const size = list => list.length;
37
+
38
+ /**
39
+ * Pairs of item and blocker refs, for the report.
40
+ * @param {string} ref
41
+ * @param {readonly { blockerRef: string }[]} edges
42
+ * @returns {{ ref: string, blocker: string }[]}
43
+ */
44
+ const pairs = (ref, edges) =>
45
+ edges.map(edge => ({ ref, blocker: edge.blockerRef }));
46
+
47
+ /**
48
+ * The links that hold an item as real blockers: every open one in this
49
+ * project, and every open one in another project. A cross-project link the
50
+ * sweep keeps because it cannot touch another project still holds the item
51
+ * while its blocker is open, so it is counted; a finished one holds nothing.
52
+ * @param {{ real?: readonly object[], crossProject?: readonly { verdict: string }[] }} groups
53
+ * @returns {object[]}
54
+ */
55
+ export const holdingReal = groups => [
56
+ ...(groups.real ?? []),
57
+ ...(groups.crossProject ?? []).filter(edge => !isResolved(edge.verdict)),
58
+ ];
59
+
60
+ /** How an item whose own blocker list could not be read is reported. */
61
+ export const UNREAD_LIST = "its blocker list";
62
+
63
+ /**
64
+ * Tally the sweep over every judged item.
65
+ * @param {readonly { item: { ref: string, statusKnown?: boolean, relationsRead?: boolean }, inBlocked: boolean, sorted: Record<string, object[]> }[]} judged
66
+ * @param {readonly { removed: string[], becomesClaimable: boolean, ref: string }[]} plans
67
+ * @param {readonly string[]} deferred
68
+ * @returns {StaleLinkReport}
69
+ */
70
+ export function tallySweep(judged, plans, deferred) {
71
+ const known = judged.filter(entry => entry.item.statusKnown !== false);
72
+ const open = known.filter(entry => !entry.inBlocked);
73
+ return {
74
+ scanned: judged.length,
75
+ skippedBlockedRole: known.length - open.length,
76
+ unknownStatus: judged
77
+ .filter(entry => entry.item.statusKnown === false)
78
+ .map(entry => entry.item.ref),
79
+ cleared: plans.reduce((sum, plan) => sum + plan.removed.length, 0),
80
+ itemsCleared: plans.length,
81
+ claimable: plans
82
+ .filter(plan => plan.becomesClaimable)
83
+ .map(plan => plan.ref),
84
+ deferred: [...deferred],
85
+ realBlockers: open.reduce((sum, e) => sum + size(holdingReal(e.sorted)), 0),
86
+ itemsWithRealBlockers: open.filter(e => size(holdingReal(e.sorted)) > 0)
87
+ .length,
88
+ crossProject: open.reduce((sum, e) => sum + size(e.sorted.crossProject), 0),
89
+ inaccessible: [
90
+ ...open
91
+ .filter(e => e.item.relationsRead === false)
92
+ .map(e => ({ ref: e.item.ref, blocker: UNREAD_LIST })),
93
+ ...open.flatMap(e => pairs(e.item.ref, e.sorted.inaccessible)),
94
+ ],
95
+ keptByPerson: open.flatMap(e => pairs(e.item.ref, e.sorted.keptByPerson)),
96
+ landed: open.reduce((sum, e) => sum + size(e.sorted.landed ?? []), 0),
97
+ };
98
+ }
99
+
100
+ /**
101
+ * @param {number} count
102
+ * @param {string} one
103
+ * @param {string} many
104
+ * @returns {string}
105
+ */
106
+ const plural = (count, one, many) => `${count} ${count === 1 ? one : many}`;
107
+
108
+ /**
109
+ * The parts every summary line shares: what is left for the next cycle, the
110
+ * real blockers, and the blockers that could not be opened.
111
+ * @param {StaleLinkReport} report
112
+ * @returns {string[]}
113
+ */
114
+ function tail(report) {
115
+ const parts = [];
116
+ if (report.deferred.length > 0) {
117
+ parts.push(
118
+ `${plural(report.deferred.length, "item", "items")} left for the next cycle`
119
+ );
120
+ }
121
+ parts.push(
122
+ `${plural(report.realBlockers, "real blocker remains", "real blockers remain")} on ${plural(report.itemsWithRealBlockers, "item", "items")}`
123
+ );
124
+ if (report.inaccessible.length > 0) {
125
+ const list = report.inaccessible
126
+ .map(pair => `${pair.blocker} (on ${pair.ref})`)
127
+ .join(", ");
128
+ parts.push(`could not open ${list}`);
129
+ }
130
+ const landed = report.landed ?? 0;
131
+ if (landed > 0) {
132
+ parts.push(
133
+ `kept ${plural(landed, "link", "links")} to work merged but not yet in production (not holding anything)`
134
+ );
135
+ }
136
+ const unknown = report.unknownStatus ?? [];
137
+ if (unknown.length > 0) {
138
+ parts.push(
139
+ `left ${unknown.join(", ")} alone because ${unknown.length === 1 ? "its" : "their"} status could not be read`
140
+ );
141
+ }
142
+ return parts;
143
+ }
144
+
145
+ /**
146
+ * One plain line describing the PLAN. Nothing has been written yet, so it
147
+ * says "planned" and "would become ready", never "cleared".
148
+ * @param {StaleLinkReport} report
149
+ * @returns {string}
150
+ */
151
+ export function summarizeStaleLinkSweep(report) {
152
+ const parts = [
153
+ `planned removal of ${plural(report.cleared, "stale blocker link", "stale blocker links")} on ${plural(report.itemsCleared, "item", "items")}`,
154
+ ];
155
+ if (report.claimable.length > 0) {
156
+ parts.push(`${report.claimable.length} would become ready to start`);
157
+ }
158
+ return `stale links (plan): ${[...parts, ...tail(report)].join("; ")}.`;
159
+ }
160
+
161
+ /**
162
+ * One plain line for the cycle summary, built from what the read-backs
163
+ * confirmed. Planned removals that did not happen and items deferred to the
164
+ * next cycle are counted separately, never as cleared.
165
+ * @param {StaleLinkReport} report - The plan's report
166
+ * @param {readonly { ref?: string, confirmed: string[], stillPresent: string[], becameReady: boolean, restored?: readonly object[], blockersBefore?: { real: number, inaccessible: string[] }, blockersAfter?: { real: number, inaccessible: string[] } }[]} results - One per item acted on
167
+ * @param {{ planned?: number }} [counts] - Planned removals, when they differ
168
+ * from the report (a plan entry confirmed down to fewer links)
169
+ * @returns {string}
170
+ */
171
+ export function summarizeVerifiedSweep(report, results, counts = {}) {
172
+ const cleared = results.reduce((sum, r) => sum + r.confirmed.length, 0);
173
+ const items = results.filter(r => r.confirmed.length > 0).length;
174
+ const ready = results.filter(r => r.becameReady).length;
175
+ const putBack = results.reduce(
176
+ (sum, r) => sum + (r.restored?.length ?? 0),
177
+ 0
178
+ );
179
+ const planned = counts.planned ?? report.cleared;
180
+ const notDone = Math.max(0, planned - cleared - putBack);
181
+ const parts = [
182
+ `cleared ${plural(cleared, "stale blocker link", "stale blocker links")} on ${plural(items, "item", "items")}`,
183
+ ];
184
+ if (ready > 0) parts.push(`${ready} now ready to start`);
185
+ if (putBack > 0) {
186
+ parts.push(
187
+ // Verify only records these as owed; nothing has put them back yet
188
+ // (`stale-links-restored` confirms that, and the item is held until
189
+ // then), so the line never claims a restore that may not have run.
190
+ `${plural(putBack, "link", "links")} awaiting restoration (blocker reopened)`
191
+ );
192
+ }
193
+ if (notDone > 0) {
194
+ parts.push(
195
+ `${plural(notDone, "planned removal", "planned removals")} not done (retried next cycle)`
196
+ );
197
+ }
198
+ return `stale links: ${[...parts, ...tail(refreshed(report, results))].join("; ")}.`;
199
+ }
200
+
201
+ /**
202
+ * The plan's report with each acted-on item's blocker totals replaced by its
203
+ * read-back's (`blockersBefore` -> `blockersAfter`): a blocker that finished,
204
+ * or reopened, since the plan is counted as it is now. Items with no newer
205
+ * observation keep their planning-time contribution.
206
+ * @param {StaleLinkReport} report
207
+ * @param {readonly { ref?: string, blockersBefore?: { real: number, inaccessible: string[] }, blockersAfter?: { real: number, inaccessible: string[] } }[]} results
208
+ * @returns {StaleLinkReport}
209
+ */
210
+ function refreshed(report, results) {
211
+ const seen = results.filter(
212
+ r => r.ref && r.blockersBefore && r.blockersAfter
213
+ );
214
+ if (seen.length === 0) return report;
215
+ const acted = new Set(seen.map(r => r.ref));
216
+ const sum = (pick, list) => list.reduce((total, r) => total + pick(r), 0);
217
+ const holds = side => r => (r[side].real > 0 ? 1 : 0);
218
+ return {
219
+ ...report,
220
+ realBlockers: Math.max(
221
+ 0,
222
+ report.realBlockers -
223
+ sum(r => r.blockersBefore.real, seen) +
224
+ sum(r => r.blockersAfter.real, seen)
225
+ ),
226
+ itemsWithRealBlockers: Math.max(
227
+ 0,
228
+ report.itemsWithRealBlockers -
229
+ sum(holds("blockersBefore"), seen) +
230
+ sum(holds("blockersAfter"), seen)
231
+ ),
232
+ inaccessible: [
233
+ ...report.inaccessible.filter(pair => !acted.has(pair.ref)),
234
+ ...seen.flatMap(r =>
235
+ r.blockersAfter.inaccessible.map(blocker => ({ ref: r.ref, blocker }))
236
+ ),
237
+ ],
238
+ };
239
+ }