@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,254 @@
1
+ /**
2
+ * After the writes of a stale-link clean-up (CodySwannGT/lisa#5065):
3
+ *
4
+ * - `stale-links-verify` reads the item back and says which planned
5
+ * removals are confirmed. Its comment covers ONLY those, and it records
6
+ * that comment as pending, so a comment that then fails to post is retried
7
+ * on its own instead of being lost with its already-removed link.
8
+ * - `stale-links-pending` lists the comments still owed; `stale-links-posted`
9
+ * settles one after it posts (or, with `--failed`, counts a failed try).
10
+ * - `stale-links-report` builds the cycle's summary from the verified
11
+ * results, never from the plan.
12
+ *
13
+ * `stale-links-verify` also records each item whose planned removals did not
14
+ * happen, so the next plan puts it after every other candidate. It settles
15
+ * the in-flight entry `stale-links-confirm` wrote before the deletes, and
16
+ * only on success: a failed read-back leaves it for `stale-links-pending` to
17
+ * list as unverified, so the next cycle verifies it again. Links it put back
18
+ * (their blocker reopened) are recorded as owed restores until
19
+ * `stale-links-restored` reads them back present; the queue holds those
20
+ * items from dispatch meanwhile. Every record lives in the manager's state
21
+ * directory (`stale-links-state.mjs`).
22
+ * @module session-manager/cli-stale-links-results
23
+ */
24
+ import {
25
+ addPending,
26
+ failedInFlight,
27
+ failedPending,
28
+ recordRemovalResult,
29
+ recordRestores,
30
+ settleInFlight,
31
+ settlePending,
32
+ settleRestores,
33
+ } from "../../../scripts/stale-blocker-pending.mjs";
34
+ import { restoreActions } from "../../../scripts/stale-blocker-restore.mjs";
35
+ import { summarizeVerifiedSweep } from "../../../scripts/stale-blocker-summary.mjs";
36
+ import { normalizeStaleLinkItem } from "../../../scripts/stale-blocker-sweep.mjs";
37
+ import { verifyStaleLinkRemoval } from "../../../scripts/stale-blocker-verify.mjs";
38
+ import { CliError, asSetupError, loadProject } from "./cli-runtime.mjs";
39
+ import { freshItem, judgingContext, trackerOf } from "./cli-stale-links.mjs";
40
+ import { readJsonFile } from "./json-input.mjs";
41
+ import { blockerReader } from "./stale-links-github.mjs";
42
+ import {
43
+ readFailures,
44
+ readInFlight,
45
+ readPending,
46
+ readRestores,
47
+ withStateLock,
48
+ writeFailures,
49
+ writeInFlight,
50
+ writePending,
51
+ writeRestores,
52
+ } from "./stale-links-state.mjs";
53
+
54
+ /**
55
+ * Each planned blocker as read NOW, after the delete. GitHub reads them
56
+ * itself; Jira and Linear take `--blockers <file>`, a `{ref: rawIssue}` map
57
+ * (a ref with no entry, or null, reads as unreadable and its link is put
58
+ * back).
59
+ * @param {object} ctx - CLI context
60
+ * @param {string} tracker
61
+ * @param {{ removed?: string[] }} plan
62
+ * @returns {Record<string, object | null>}
63
+ */
64
+ function removedBlockersNow(ctx, tracker, plan) {
65
+ if (ctx.values.blockers) {
66
+ const map = readJsonFile(ctx.values.blockers);
67
+ if (!map || typeof map !== "object" || Array.isArray(map)) {
68
+ throw new CliError(
69
+ `${ctx.values.blockers}: expected {"<ref>": {...}}.`,
70
+ 2
71
+ );
72
+ }
73
+ return map;
74
+ }
75
+ if (tracker !== "github") {
76
+ throw new CliError(
77
+ `stale-links-verify --tracker ${tracker} needs --blockers <file> with each removed blocker as read now.`,
78
+ 2
79
+ );
80
+ }
81
+ const read = blockerReader(ctx);
82
+ return Object.fromEntries((plan.removed ?? []).map(ref => [ref, read(ref)]));
83
+ }
84
+
85
+ /**
86
+ * `stale-links-verify --tracker <t> --plan <file> [--input <file>]`.
87
+ * @param {object} ctx - CLI context
88
+ * @returns {{ json: object }} The verified result, plus `pending`
89
+ */
90
+ export async function staleLinksVerify(ctx) {
91
+ const project = loadProject(ctx.root);
92
+ const tracker = trackerOf(ctx, project);
93
+ if (!ctx.values.plan) {
94
+ throw new CliError("stale-links-verify needs --plan <file>.", 2);
95
+ }
96
+ const plan = readJsonFile(ctx.values.plan);
97
+ const result = await verifiedOrCounted(ctx, plan, () => {
98
+ const after = freshItem(ctx, tracker, plan);
99
+ const blockersNow = removedBlockersNow(ctx, tracker, plan);
100
+ const context = judgingContext(project, tracker);
101
+ return asSetupError(() =>
102
+ verifyStaleLinkRemoval({ tracker, plan, after, blockersNow, ...context })
103
+ );
104
+ });
105
+ const now = new Date().toISOString();
106
+ await withStateLock(ctx.root, () => {
107
+ writeFailures(
108
+ ctx.root,
109
+ recordRemovalResult(readFailures(ctx.root), result, now)
110
+ );
111
+ writeRestores(
112
+ ctx.root,
113
+ recordRestores(readRestores(ctx.root), result, plan.links ?? [], now)
114
+ );
115
+ if (result.comment !== null) {
116
+ writePending(ctx.root, addPending(readPending(ctx.root), result, now));
117
+ }
118
+ // Last, and only once every record above is written: until then the
119
+ // in-flight plan is the removed links' only recovery record.
120
+ writeInFlight(ctx.root, settleInFlight(readInFlight(ctx.root), plan.ref));
121
+ });
122
+ return { json: { ...result, pending: result.comment !== null } };
123
+ }
124
+
125
+ /**
126
+ * Run the read-back and verdict; when either throws (after the deletes may
127
+ * have run), count the failed try on the item's in-flight entry and
128
+ * rethrow, so the entry stays listed as unverified for the next cycle.
129
+ * @template T
130
+ * @param {object} ctx - CLI context
131
+ * @param {{ ref: string }} plan - The confirmed plan entry
132
+ * @param {() => T} verify
133
+ * @returns {Promise<T>}
134
+ */
135
+ async function verifiedOrCounted(ctx, plan, verify) {
136
+ try {
137
+ return verify();
138
+ } catch (error) {
139
+ await withStateLock(ctx.root, () =>
140
+ writeInFlight(ctx.root, failedInFlight(readInFlight(ctx.root), plan.ref))
141
+ );
142
+ throw error;
143
+ }
144
+ }
145
+
146
+ /**
147
+ * `stale-links-pending`: what earlier writes still owe — comments not yet
148
+ * posted, confirmed plans whose read-back has not succeeded (`unverified`,
149
+ * each with the plan entry to verify again), and links owed back
150
+ * (`restores`, by item ref).
151
+ * @param {object} ctx - CLI context
152
+ * @returns {{ json: object }} `{pending,unverified,restores}`
153
+ */
154
+ export function staleLinksPending(ctx) {
155
+ return {
156
+ json: {
157
+ pending: readPending(ctx.root),
158
+ unverified: Object.values(readInFlight(ctx.root)),
159
+ restores: readRestores(ctx.root),
160
+ },
161
+ };
162
+ }
163
+
164
+ /**
165
+ * `stale-links-restored --ref <ref> [--tracker <t>] [--input <file>]`: read
166
+ * the item back after its restores and settle each owed link now present.
167
+ * GitHub reads the item itself; Jira and Linear take it in `--input`. The
168
+ * links still missing come back with fresh `restore` actions built from
169
+ * this read, to perform before the item can dispatch.
170
+ * @param {object} ctx - CLI context
171
+ * @returns {Promise<{ json: object }>} `{ref,owed,restore}`
172
+ */
173
+ export async function staleLinksRestored(ctx) {
174
+ const ref = ctx.values.ref;
175
+ if (!ref) {
176
+ throw new CliError("stale-links-restored needs --ref <ref>.", 2);
177
+ }
178
+ const tracker = trackerOf(ctx, loadProject(ctx.root));
179
+ const item = normalizeStaleLinkItem(
180
+ tracker,
181
+ freshItem(ctx, tracker, { ref })
182
+ );
183
+ if (item.ref !== ref || !item.relationsRead) {
184
+ // probe-direction: fail-closed — a read of another item, or one without
185
+ // its relation list, cannot show a link is back, so nothing is settled.
186
+ throw new CliError(
187
+ `stale-links-restored: the read of ${ref} must be that item with its blocker links.`,
188
+ 1
189
+ );
190
+ }
191
+ const present = new Set(item.edges.map(edge => edge.blockerRef));
192
+ const left = await withStateLock(ctx.root, () => {
193
+ const updated = settleRestores(readRestores(ctx.root), ref, present);
194
+ writeRestores(ctx.root, updated);
195
+ return updated[ref]?.links ?? [];
196
+ });
197
+ return {
198
+ json: { ref, owed: left, restore: restoreActions(tracker, item, left) },
199
+ };
200
+ }
201
+
202
+ /**
203
+ * `stale-links-posted --ref <ref> [--failed]`.
204
+ * @param {object} ctx - CLI context
205
+ * @returns {{ json: object }} `{ref,pending}` after the update
206
+ */
207
+ export async function staleLinksPosted(ctx) {
208
+ const ref = ctx.values.ref;
209
+ const removed = String(ctx.values.removed ?? "")
210
+ .split(",")
211
+ .map(one => one.trim())
212
+ .filter(Boolean);
213
+ if (!ref || removed.length === 0) {
214
+ throw new CliError(
215
+ "stale-links-posted needs --ref <ref> --removed <blocker,...> (the entry's `removed`).",
216
+ 2
217
+ );
218
+ }
219
+ const next = await withStateLock(ctx.root, () => {
220
+ const current = readPending(ctx.root);
221
+ const updated = ctx.values.failed
222
+ ? failedPending(current, ref, removed)
223
+ : settlePending(current, ref, removed);
224
+ writePending(ctx.root, updated);
225
+ return updated;
226
+ });
227
+ return { json: { ref, removed, pending: next } };
228
+ }
229
+
230
+ /**
231
+ * `stale-links-report --input <file>`: `{report, results, planned?}`, where
232
+ * `report` is the plan's and `results` are the verify outputs.
233
+ * @param {object} ctx - CLI context
234
+ * @returns {{ json: object }} `{summary}`
235
+ */
236
+ export function staleLinksReport(ctx) {
237
+ if (!ctx.values.input) {
238
+ throw new CliError("stale-links-report needs --input <file>.", 2);
239
+ }
240
+ const input = readJsonFile(ctx.values.input);
241
+ if (!input?.report || !Array.isArray(input.results)) {
242
+ throw new CliError(
243
+ `${ctx.values.input}: expected {"report":{...},"results":[...]}.`,
244
+ 2
245
+ );
246
+ }
247
+ return {
248
+ json: {
249
+ summary: summarizeVerifiedSweep(input.report, input.results, {
250
+ planned: input.planned,
251
+ }),
252
+ },
253
+ };
254
+ }
@@ -0,0 +1,243 @@
1
+ /**
2
+ * `stale-links-plan`: the session manager's per-cycle sweep for "blocked by"
3
+ * links whose blocker is already finished (CodySwannGT/lisa#5065). The plan
4
+ * writes nothing; the manager performs each action through the tracker's
5
+ * access layer, reads it back, then posts the plan's comment.
6
+ *
7
+ * The judging lives in the shared `stale-blocker-sweep.mjs`, so any agent's
8
+ * intake can run the same rule without this Claude Code-only manager.
9
+ * @module session-manager/cli-stale-links
10
+ */
11
+ import { resolveRole } from "../../../scripts/resolve-lifecycle-role.mjs";
12
+ import { confirmStaleLinkPlan } from "../../../scripts/stale-blocker-confirm.mjs";
13
+ import {
14
+ landedDoneRoles,
15
+ terminalDoneRoles,
16
+ } from "../../../scripts/stale-blocker-edges.mjs";
17
+ import {
18
+ planStaleLinkSweep,
19
+ summarizeStaleLinkSweep,
20
+ } from "../../../scripts/stale-blocker-sweep.mjs";
21
+ import {
22
+ CliError,
23
+ asSetupError,
24
+ intFlag,
25
+ loadProject,
26
+ } from "./cli-runtime.mjs";
27
+ import { readJsonFile } from "./json-input.mjs";
28
+ import { recordInFlight } from "../../../scripts/stale-blocker-pending.mjs";
29
+ import {
30
+ readFailures,
31
+ readInFlight,
32
+ withStateLock,
33
+ writeInFlight,
34
+ } from "./stale-links-state.mjs";
35
+ import {
36
+ collectGithubStaleLinkInput,
37
+ readGithubStaleLinkItem,
38
+ } from "./stale-links-github.mjs";
39
+
40
+ /**
41
+ * @param {unknown} value
42
+ * @returns {string}
43
+ */
44
+ const text = value => (typeof value === "string" ? value : "");
45
+
46
+ const TRACKERS = new Set(["github", "jira", "linear"]);
47
+ const OWNER_REPO = /^[\w.-]+\/[\w.-]+$/;
48
+
49
+ /**
50
+ * The configured name of one lifecycle role, or "" when unset.
51
+ * @param {ReturnType<typeof loadProject>} project
52
+ * @param {string} tracker
53
+ * @param {string} role
54
+ * @returns {string}
55
+ */
56
+ function roleValue(project, tracker, role) {
57
+ return resolveRole({
58
+ role,
59
+ vendor: tracker,
60
+ intent: "read",
61
+ local: project.local,
62
+ global: project.global,
63
+ }).value;
64
+ }
65
+
66
+ /**
67
+ * The GitHub repo to sweep: `--github-repo`, else github.org/github.repo.
68
+ * @param {object} ctx - CLI context
69
+ * @param {ReturnType<typeof loadProject>} project
70
+ * @returns {string}
71
+ */
72
+ function githubRepo(ctx, project) {
73
+ const merged = { ...project.global?.github, ...project.local?.github };
74
+ const repo =
75
+ ctx.values["github-repo"] ??
76
+ (merged.org && merged.repo ? `${merged.org}/${merged.repo}` : "");
77
+ if (!OWNER_REPO.test(repo)) {
78
+ throw new CliError(
79
+ "No GitHub repo: set github.org and github.repo, or pass --github-repo <owner/repo>.",
80
+ 2
81
+ );
82
+ }
83
+ return repo;
84
+ }
85
+
86
+ /**
87
+ * The raw items to judge: read from GitHub, or from the vendor skill's
88
+ * envelope for Jira and Linear (paged to completion, like `queue`).
89
+ * @param {object} ctx - CLI context
90
+ * @param {string} tracker
91
+ * @param {ReturnType<typeof loadProject>} project
92
+ * @returns {object[]}
93
+ */
94
+ function rawItems(ctx, tracker, project) {
95
+ if (!ctx.values.input) {
96
+ if (tracker === "github") {
97
+ return collectGithubStaleLinkInput(ctx, githubRepo(ctx, project)).items;
98
+ }
99
+ throw new CliError(
100
+ `stale-links-plan --tracker ${tracker} needs --input <file>.`,
101
+ 2
102
+ );
103
+ }
104
+ const envelope = readJsonFile(ctx.values.input);
105
+ if (envelope?.complete !== true || !Array.isArray(envelope.items)) {
106
+ throw new CliError(
107
+ `${ctx.values.input}: expected {"complete":true,"items":[...]} read to the last page.`,
108
+ 2
109
+ );
110
+ }
111
+ return envelope.items;
112
+ }
113
+
114
+ /**
115
+ * The tracker to sweep: `--tracker`, else the project's configured tracker.
116
+ * @param {object} ctx - CLI context
117
+ * @param {ReturnType<typeof loadProject>} project
118
+ * @returns {"github" | "jira" | "linear"}
119
+ */
120
+ export function trackerOf(ctx, project) {
121
+ const tracker =
122
+ ctx.values.tracker ?? project.local?.tracker ?? project.global?.tracker;
123
+ if (!TRACKERS.has(tracker ?? "")) {
124
+ throw new CliError("--tracker must be github, jira or linear.", 2);
125
+ }
126
+ return tracker;
127
+ }
128
+
129
+ /**
130
+ * The configured roles and done names every sweep judges against.
131
+ * @param {ReturnType<typeof loadProject>} project
132
+ * @param {string} tracker
133
+ * @returns {{ doneRoles: string[], landedRoles: string[], roles: { ready: string, blocked: string }, posterName: string }}
134
+ */
135
+ export function judgingContext(project, tracker) {
136
+ const config = { tracker, global: project.global, local: project.local };
137
+ return {
138
+ doneRoles: terminalDoneRoles(config),
139
+ // Intermediate done rungs hold nothing, but their links are never removed.
140
+ landedRoles: landedDoneRoles(config),
141
+ roles: {
142
+ ready: roleValue(project, tracker, "ready"),
143
+ blocked: roleValue(project, tracker, "blocked"),
144
+ },
145
+ // The comment names the configured manager; the prefix stays the marker.
146
+ posterName: text(project.config?.name),
147
+ };
148
+ }
149
+
150
+ /**
151
+ * `stale-links-plan --tracker <t> [--input <file>] [--max <n>]`.
152
+ * @param {object} ctx - CLI context
153
+ * @returns {{ json: object }} `{tracker,doneRoles,plans,deferred,report,summary}`
154
+ */
155
+ export function staleLinksPlan(ctx) {
156
+ const project = loadProject(ctx.root);
157
+ const tracker = trackerOf(ctx, project);
158
+ const max = intFlag(ctx.values.max, "--max");
159
+ const items = rawItems(ctx, tracker, project);
160
+ const failures = readFailures(ctx.root);
161
+ return {
162
+ json: asSetupError(() => {
163
+ const context = judgingContext(project, tracker);
164
+ const plan = planStaleLinkSweep({
165
+ tracker,
166
+ items,
167
+ ...context,
168
+ failures,
169
+ ...(max === undefined ? {} : { max }),
170
+ });
171
+ return {
172
+ tracker,
173
+ doneRoles: context.doneRoles,
174
+ ...plan,
175
+ summary: summarizeStaleLinkSweep(plan.report),
176
+ };
177
+ }),
178
+ };
179
+ }
180
+
181
+ /**
182
+ * The item as it stands now: `--input`, or a fresh GitHub read. Used before
183
+ * the writes (`stale-links-confirm`) and after them (`stale-links-verify`).
184
+ * @param {object} ctx - CLI context
185
+ * @param {string} tracker
186
+ * @param {{ ref?: string }} plan - The plan entry being confirmed
187
+ * @returns {Record<string, any>}
188
+ */
189
+ export function freshItem(ctx, tracker, plan) {
190
+ if (ctx.values.input) return readJsonFile(ctx.values.input);
191
+ if (tracker !== "github") {
192
+ throw new CliError(
193
+ `--tracker ${tracker} needs --input <file> with the item as read now.`,
194
+ 2
195
+ );
196
+ }
197
+ const [repo, number] = String(plan?.ref ?? "").split("#");
198
+ return readGithubStaleLinkItem(ctx, repo, Number(number));
199
+ }
200
+
201
+ /**
202
+ * `stale-links-confirm --tracker <t> --plan <file> [--input <file>]`: rebuild
203
+ * one plan entry from a fresh read of the item and its blockers, right before
204
+ * the writes. GitHub re-reads itself; Jira and Linear take the fresh raw item
205
+ * (with each blocker's current status, and the comments) in `--input`.
206
+ * @param {object} ctx - CLI context
207
+ * @returns {Promise<{ json: object }>} `{tracker,plan,skipped}`; plan is null when
208
+ * nothing is still safe to remove
209
+ */
210
+ export async function staleLinksConfirm(ctx) {
211
+ const project = loadProject(ctx.root);
212
+ const tracker = trackerOf(ctx, project);
213
+ if (!ctx.values.plan) {
214
+ throw new CliError("stale-links-confirm needs --plan <file>.", 2);
215
+ }
216
+ const plan = readJsonFile(ctx.values.plan);
217
+ const fresh = freshItem(ctx, tracker, plan);
218
+ const confirmed = asSetupError(() => ({
219
+ tracker,
220
+ ...confirmStaleLinkPlan({
221
+ tracker,
222
+ plan,
223
+ fresh,
224
+ ...judgingContext(project, tracker),
225
+ }),
226
+ }));
227
+ // Recorded BEFORE any delete runs: until a verify reads the item back,
228
+ // the entry stays in flight, so a read-back that fails after the deletes
229
+ // is retried rather than leaving removed links with no comment and no
230
+ // restore check.
231
+ if (confirmed.plan !== null) {
232
+ const now = new Date().toISOString();
233
+ await withStateLock(ctx.root, () =>
234
+ writeInFlight(
235
+ ctx.root,
236
+ asSetupError(() =>
237
+ recordInFlight(readInFlight(ctx.root), confirmed.plan, now)
238
+ )
239
+ )
240
+ );
241
+ }
242
+ return { json: confirmed };
243
+ }
@@ -319,6 +319,66 @@ Per cycle
319
319
  wrongly-escalated, hold and release evidence, a draft
320
320
  Planning (filing) rule); comment is the marker to post afterwards.
321
321
  --max caps captures per cycle (default 3); the rest are deferred.
322
+ stale-links-plan [--tracker <t>] [--input <file>] [--max <n>]
323
+ [--github-repo <owner/repo>]
324
+ Plans this cycle's clean-up of "blocked by" links whose blocker is
325
+ finished (closed in the tracker, or in the configured terminal done
326
+ role) or cancelled; writes nothing. GitHub reads open issues, native
327
+ blocked_by dependencies and "Blocked by" body lines itself; Jira and
328
+ Linear take --input {complete:true,items:[raw issues with comments]}.
329
+ Open, cross-project and unreadable blockers are kept (unreadable ones
330
+ reported); items in the blocked role are left to the Blocked sweep.
331
+ stdout {tracker,doneRoles,plans:[{ref,actions,body,removed,comment,
332
+ commentAdf,remainingBlockers,becomesClaimable,render}],deferred,report,
333
+ summary}; summary describes the plan ("planned", "would become
334
+ ready"), never a result. A
335
+ comment carries one [lisa-stale-blocker-link] blocker=<ref> marker per
336
+ removed link, so a re-run never comments twice. --max caps items per
337
+ cycle (default 10); the rest are deferred.
338
+ stale-links-confirm [--tracker <t>] --plan <file> [--input <file>]
339
+ Rebuilds one stale-links-plan entry from a fresh read, right before the
340
+ writes; writes nothing. GitHub re-reads the issue, each blocker and the
341
+ comments itself; Jira and Linear take the fresh raw item in --input.
342
+ Only links the plan removes that are still stale are kept; the body is
343
+ rebuilt from the fresh body, so a concurrent edit survives. stdout
344
+ {tracker,plan,skipped:[{blocker,reason}]}; reason is
345
+ blocker-not-resolved, link-already-gone or blocked-role; plan is null
346
+ when nothing is still safe to remove. A non-null plan is recorded in
347
+ .lisa/session-manager/stale-links-inflight.json BEFORE the writes, and
348
+ stays there until stale-links-verify reads the item back (queue holds
349
+ the item meanwhile: removal-unverified). An item that still has an
350
+ unverified entry is refused, never overwritten.
351
+ stale-links-verify [--tracker <t>] --plan <file> [--input <file>]
352
+ [--blockers <file>]
353
+ Reads one item back after its stale-link writes, and each removed
354
+ blocker again (GitHub itself; Jira/Linear from --blockers, a
355
+ {ref: rawIssue} map). stdout {ref,confirmed,stillPresent,restored,
356
+ restore,comment,commentAdf,becameReady,pending}: a removed link whose
357
+ blocker reopened is in restored, with restore the actions that put it
358
+ back; comment covers ONLY the confirmed removals (null when none) and
359
+ is recorded as pending in .lisa/session-manager/stale-links-pending.json
360
+ until posted (never when its marker is already live). Links in
361
+ restored are owed in stale-links-restores.json until
362
+ stale-links-restored reads them back; queue holds those items with
363
+ reason restore-owed. The in-flight entry is settled last, after every
364
+ other record; a failed read-back or write leaves it.
365
+ stale-links-pending
366
+ Lists what earlier stale-link writes still owe. stdout {pending:[...],
367
+ unverified:[{plan,since,attempts}],restores:{ref:{links,...}}}:
368
+ comments not yet posted, confirmed plans to verify again, and links
369
+ owed back.
370
+ stale-links-restored --ref <ref> [--tracker <t>] [--input <file>]
371
+ Reads the item back after its restores (GitHub itself; Jira/Linear from
372
+ --input) and settles each owed link now present. stdout {ref,owed,
373
+ restore}: restore is the fresh actions for the links still missing.
374
+ stale-links-posted --ref <ref> --removed <blocker,...> [--failed]
375
+ Settles the ONE pending comment with that ref and removed set after it
376
+ posts (an item can owe more than one); --failed instead counts one more
377
+ failed try for that comment.
378
+ stale-links-report --input <file>
379
+ {report,results[,planned]} -> {summary}: the cycle's stale-link line,
380
+ built from verified results; planned-but-not-done and deferred items
381
+ are counted separately, never as cleared.
322
382
  orphan-plan [--input <file>] [--max <n>] [--stale-hours <n>]
323
383
  STDIN (without --input): JSON
324
384
  {complete:true,items:[{ref,role,labels,body,comments,assignees,
@@ -6,10 +6,22 @@
6
6
  * command fails, and both run gh with the scrubbed worker env.
7
7
  * @module session-manager/queue-github
8
8
  */
9
- import { normalizeGithubIssue } from "../../../scripts/ready-queue-order.mjs";
9
+ import {
10
+ labelNames,
11
+ normalizeGithubIssue,
12
+ } from "../../../scripts/ready-queue-order.mjs";
10
13
  import { resolveRole } from "../../../scripts/resolve-lifecycle-role.mjs";
14
+ import {
15
+ landedDoneRoles,
16
+ terminalDoneRoles,
17
+ } from "../../../scripts/stale-blocker-edges.mjs";
11
18
  import { CliError, mustRun } from "./cli-runtime.mjs";
12
19
  import { parseJson } from "./json-input.mjs";
20
+ import {
21
+ blockerReader,
22
+ hasBlockers,
23
+ withBlockers,
24
+ } from "./stale-links-github.mjs";
13
25
  import { scrubWorkerEnv } from "./workers.mjs";
14
26
 
15
27
  const OWNER_REPO = /^[\w.-]+\/[\w.-]+$/;
@@ -34,6 +46,55 @@ function githubRepo(ctx, project) {
34
46
  return repo;
35
47
  }
36
48
 
49
+ /**
50
+ * Normalize REST rows with their blockers attached, so the queue judges a
51
+ * blocker by the same rule as intake and the stale-link sweep (#5065).
52
+ * Only rows that name a blocker, and that `keep` retains, cost any extra
53
+ * read: a row the caller will drop anyway is dropped before enrichment.
54
+ * @param {object} ctx - CLI context
55
+ * @param {{global?: object, local?: object}} project - Loaded project
56
+ * @param {string} repo - `owner/repo`
57
+ * @param {object[]} rows - REST issues
58
+ * @param {(row: object) => boolean} [keep] - Raw-row filter, applied first
59
+ * @returns {object[]} Normalized items
60
+ */
61
+ function normalizeRows(ctx, project, repo, rows, keep = () => true) {
62
+ const config = {
63
+ tracker: "github",
64
+ global: project.global,
65
+ local: project.local,
66
+ };
67
+ const doneRoles = terminalDoneRoles(config);
68
+ const landedRoles = landedDoneRoles(config);
69
+ const blocker = blockerReader(ctx);
70
+ return rows
71
+ .filter(row => !row.pull_request && keep(row))
72
+ .map(row =>
73
+ hasBlockers(row, repo) ? enrichOrHold(ctx, repo, row, blocker) : row
74
+ )
75
+ .map(row => normalizeGithubIssue(row, { repo, doneRoles, landedRoles }))
76
+ .filter(Boolean);
77
+ }
78
+
79
+ /**
80
+ * Attach one row's blockers. A failed blocker read holds THAT row only: the
81
+ * rest of the queue is still offered.
82
+ * @param {object} ctx - CLI context
83
+ * @param {string} repo - `owner/repo`
84
+ * @param {Record<string, any>} row - REST issue
85
+ * @param {(ref: string) => object | null} blocker - Body-ref reader
86
+ * @returns {Record<string, any>} The enriched row, or the row marked unreadable
87
+ */
88
+ function enrichOrHold(ctx, repo, row, blocker) {
89
+ try {
90
+ return withBlockers(ctx, repo, row, blocker);
91
+ } catch {
92
+ // probe-direction: fail-closed — an item whose blockers could not be read
93
+ // is held (`blockersUnreadable`), never released as unblocked.
94
+ return { ...row, blockersUnreadable: true };
95
+ }
96
+ }
97
+
37
98
  /**
38
99
  * Every string leaf of an object (label names, including env-keyed `done`).
39
100
  * @param {unknown} value - Config subtree
@@ -87,13 +148,12 @@ export function fetchGithubBacklog(ctx, project) {
87
148
  );
88
149
  const pages = parseJson(stdout, "gh api output");
89
150
  const rows = Array.isArray(pages) ? pages.flat() : [];
151
+ // The lifecycle test reads labels exactly as `normalizeGithubIssue` does,
152
+ // and runs on the raw rows so an excluded issue costs no blocker read.
153
+ const unlabelled = row =>
154
+ !labelNames(row.labels).some(label => lifecycle.has(label.toLowerCase()));
90
155
  return {
91
- items: rows
92
- .map(row => normalizeGithubIssue(row, { repo }))
93
- .filter(Boolean)
94
- .filter(
95
- item => !item.labels.some(label => lifecycle.has(label.toLowerCase()))
96
- ),
156
+ items: normalizeRows(ctx, project, repo, rows, unlabelled),
97
157
  pages: Array.isArray(pages) ? pages.length : 0,
98
158
  };
99
159
  }
@@ -124,7 +184,7 @@ export function fetchGithubQueue(ctx, project) {
124
184
  const pages = parseJson(stdout, "gh api output");
125
185
  const rows = Array.isArray(pages) ? pages.flat() : [];
126
186
  return {
127
- items: rows.map(row => normalizeGithubIssue(row, { repo })).filter(Boolean),
187
+ items: normalizeRows(ctx, project, repo, rows),
128
188
  pages: Array.isArray(pages) ? pages.length : 0,
129
189
  };
130
190
  }