@codyswann/lisa 4.110.2 → 4.111.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 (153) hide show
  1. package/all/copy-overwrite/scripts/lib/completion-proof-github.mjs +242 -62
  2. package/all/copy-overwrite/scripts/lib/completion-proof-publisher.mjs +195 -82
  3. package/all/copy-overwrite/scripts/lib/evidence-release-capacity.mjs +20 -29
  4. package/all/copy-overwrite/scripts/npm-updater-helper-graph.json +3 -3
  5. package/dist/core/lisa-owned-hash-ledger.d.ts.map +1 -1
  6. package/dist/core/lisa-owned-hash-ledger.js +22 -0
  7. package/dist/core/lisa-owned-hash-ledger.js.map +1 -1
  8. package/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
  9. package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
  10. package/dist/core/upstream-evidence-manifest.js +80 -10
  11. package/dist/core/upstream-evidence-manifest.js.map +1 -1
  12. package/package.json +4 -4
  13. package/plugins/lisa/.claude-plugin/plugin.json +1 -1
  14. package/plugins/lisa/.codex-plugin/plugin.json +1 -1
  15. package/plugins/lisa/.codex-plugin/scripts/human-gate-lift.mjs +148 -0
  16. package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/SKILL.md +69 -4
  17. package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/references/runbook-template.md +3 -0
  18. package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/cli-cycle.mjs +16 -0
  19. package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/cli-orphans.mjs +162 -0
  20. package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/cli-usage.mjs +40 -0
  21. package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/ledger.mjs +15 -3
  22. package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/orphan-buckets.mjs +233 -0
  23. package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/orphan-holds.mjs +252 -0
  24. package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/orphan-sweep.mjs +335 -0
  25. package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/session-manager.mjs +12 -1
  26. package/plugins/lisa/skills/lisa-session-manager/SKILL.md +69 -4
  27. package/plugins/lisa/skills/lisa-session-manager/references/runbook-template.md +3 -0
  28. package/plugins/lisa/skills/lisa-session-manager/scripts/cli-cycle.mjs +16 -0
  29. package/plugins/lisa/skills/lisa-session-manager/scripts/cli-orphans.mjs +162 -0
  30. package/plugins/lisa/skills/lisa-session-manager/scripts/cli-usage.mjs +40 -0
  31. package/plugins/lisa/skills/lisa-session-manager/scripts/ledger.mjs +15 -3
  32. package/plugins/lisa/skills/lisa-session-manager/scripts/orphan-buckets.mjs +233 -0
  33. package/plugins/lisa/skills/lisa-session-manager/scripts/orphan-holds.mjs +252 -0
  34. package/plugins/lisa/skills/lisa-session-manager/scripts/orphan-sweep.mjs +335 -0
  35. package/plugins/lisa/skills/lisa-session-manager/scripts/session-manager.mjs +12 -1
  36. package/plugins/lisa-agy/plugin.json +1 -1
  37. package/plugins/lisa-agy/skills/lisa-session-manager/SKILL.md +69 -4
  38. package/plugins/lisa-agy/skills/lisa-session-manager/references/runbook-template.md +3 -0
  39. package/plugins/lisa-agy/skills/lisa-session-manager/scripts/cli-cycle.mjs +16 -0
  40. package/plugins/lisa-agy/skills/lisa-session-manager/scripts/cli-orphans.mjs +162 -0
  41. package/plugins/lisa-agy/skills/lisa-session-manager/scripts/cli-usage.mjs +40 -0
  42. package/plugins/lisa-agy/skills/lisa-session-manager/scripts/ledger.mjs +15 -3
  43. package/plugins/lisa-agy/skills/lisa-session-manager/scripts/orphan-buckets.mjs +233 -0
  44. package/plugins/lisa-agy/skills/lisa-session-manager/scripts/orphan-holds.mjs +252 -0
  45. package/plugins/lisa-agy/skills/lisa-session-manager/scripts/orphan-sweep.mjs +335 -0
  46. package/plugins/lisa-agy/skills/lisa-session-manager/scripts/session-manager.mjs +12 -1
  47. package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
  48. package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
  49. package/plugins/lisa-cdk-agy/plugin.json +1 -1
  50. package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
  51. package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
  52. package/plugins/lisa-cdk-devin/.claude-plugin/plugin.json +1 -1
  53. package/plugins/lisa-cdk-devin/.devin-plugin/plugin.json +1 -1
  54. package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
  55. package/plugins/lisa-copilot/skills/lisa-session-manager/SKILL.md +69 -4
  56. package/plugins/lisa-copilot/skills/lisa-session-manager/references/runbook-template.md +3 -0
  57. package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/cli-cycle.mjs +16 -0
  58. package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/cli-orphans.mjs +162 -0
  59. package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/cli-usage.mjs +40 -0
  60. package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/ledger.mjs +15 -3
  61. package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/orphan-buckets.mjs +233 -0
  62. package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/orphan-holds.mjs +252 -0
  63. package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/orphan-sweep.mjs +335 -0
  64. package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/session-manager.mjs +12 -1
  65. package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
  66. package/plugins/lisa-cursor/skills/lisa-session-manager/SKILL.md +69 -4
  67. package/plugins/lisa-cursor/skills/lisa-session-manager/references/runbook-template.md +3 -0
  68. package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/cli-cycle.mjs +16 -0
  69. package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/cli-orphans.mjs +162 -0
  70. package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/cli-usage.mjs +40 -0
  71. package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/ledger.mjs +15 -3
  72. package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/orphan-buckets.mjs +233 -0
  73. package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/orphan-holds.mjs +252 -0
  74. package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/orphan-sweep.mjs +335 -0
  75. package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/session-manager.mjs +12 -1
  76. package/plugins/lisa-devin/.claude-plugin/plugin.json +1 -1
  77. package/plugins/lisa-devin/.devin-plugin/plugin.json +1 -1
  78. package/plugins/lisa-devin/skills/lisa-session-manager/SKILL.md +69 -4
  79. package/plugins/lisa-devin/skills/lisa-session-manager/references/runbook-template.md +3 -0
  80. package/plugins/lisa-devin/skills/lisa-session-manager/scripts/cli-cycle.mjs +16 -0
  81. package/plugins/lisa-devin/skills/lisa-session-manager/scripts/cli-orphans.mjs +162 -0
  82. package/plugins/lisa-devin/skills/lisa-session-manager/scripts/cli-usage.mjs +40 -0
  83. package/plugins/lisa-devin/skills/lisa-session-manager/scripts/ledger.mjs +15 -3
  84. package/plugins/lisa-devin/skills/lisa-session-manager/scripts/orphan-buckets.mjs +233 -0
  85. package/plugins/lisa-devin/skills/lisa-session-manager/scripts/orphan-holds.mjs +252 -0
  86. package/plugins/lisa-devin/skills/lisa-session-manager/scripts/orphan-sweep.mjs +335 -0
  87. package/plugins/lisa-devin/skills/lisa-session-manager/scripts/session-manager.mjs +12 -1
  88. package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
  89. package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
  90. package/plugins/lisa-expo-agy/plugin.json +1 -1
  91. package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
  92. package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
  93. package/plugins/lisa-expo-devin/.claude-plugin/plugin.json +1 -1
  94. package/plugins/lisa-expo-devin/.devin-plugin/plugin.json +1 -1
  95. package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
  96. package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
  97. package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
  98. package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
  99. package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
  100. package/plugins/lisa-harper-fabric-devin/.claude-plugin/plugin.json +1 -1
  101. package/plugins/lisa-harper-fabric-devin/.devin-plugin/plugin.json +1 -1
  102. package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
  103. package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
  104. package/plugins/lisa-nestjs-agy/plugin.json +1 -1
  105. package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
  106. package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
  107. package/plugins/lisa-nestjs-devin/.claude-plugin/plugin.json +1 -1
  108. package/plugins/lisa-nestjs-devin/.devin-plugin/plugin.json +1 -1
  109. package/plugins/lisa-openclaw/.claude-plugin/plugin.json +1 -1
  110. package/plugins/lisa-openclaw/.codex-plugin/plugin.json +1 -1
  111. package/plugins/lisa-openclaw-agy/plugin.json +1 -1
  112. package/plugins/lisa-openclaw-copilot/.claude-plugin/plugin.json +1 -1
  113. package/plugins/lisa-openclaw-cursor/.claude-plugin/plugin.json +1 -1
  114. package/plugins/lisa-openclaw-devin/.claude-plugin/plugin.json +1 -1
  115. package/plugins/lisa-openclaw-devin/.devin-plugin/plugin.json +1 -1
  116. package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
  117. package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
  118. package/plugins/lisa-phaser-agy/plugin.json +1 -1
  119. package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
  120. package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
  121. package/plugins/lisa-phaser-devin/.claude-plugin/plugin.json +1 -1
  122. package/plugins/lisa-phaser-devin/.devin-plugin/plugin.json +1 -1
  123. package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
  124. package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
  125. package/plugins/lisa-rails-agy/plugin.json +1 -1
  126. package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
  127. package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
  128. package/plugins/lisa-rails-devin/.claude-plugin/plugin.json +1 -1
  129. package/plugins/lisa-rails-devin/.devin-plugin/plugin.json +1 -1
  130. package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
  131. package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
  132. package/plugins/lisa-typescript-agy/plugin.json +1 -1
  133. package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
  134. package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
  135. package/plugins/lisa-typescript-devin/.claude-plugin/plugin.json +1 -1
  136. package/plugins/lisa-typescript-devin/.devin-plugin/plugin.json +1 -1
  137. package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
  138. package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
  139. package/plugins/lisa-wiki-agy/plugin.json +1 -1
  140. package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
  141. package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
  142. package/plugins/lisa-wiki-devin/.claude-plugin/plugin.json +1 -1
  143. package/plugins/lisa-wiki-devin/.devin-plugin/plugin.json +1 -1
  144. package/plugins/src/base/skills/lisa-session-manager/SKILL.md +69 -4
  145. package/plugins/src/base/skills/lisa-session-manager/references/runbook-template.md +3 -0
  146. package/plugins/src/base/skills/lisa-session-manager/scripts/cli-cycle.mjs +16 -0
  147. package/plugins/src/base/skills/lisa-session-manager/scripts/cli-orphans.mjs +162 -0
  148. package/plugins/src/base/skills/lisa-session-manager/scripts/cli-usage.mjs +40 -0
  149. package/plugins/src/base/skills/lisa-session-manager/scripts/ledger.mjs +15 -3
  150. package/plugins/src/base/skills/lisa-session-manager/scripts/orphan-buckets.mjs +233 -0
  151. package/plugins/src/base/skills/lisa-session-manager/scripts/orphan-holds.mjs +252 -0
  152. package/plugins/src/base/skills/lisa-session-manager/scripts/orphan-sweep.mjs +335 -0
  153. package/plugins/src/base/skills/lisa-session-manager/scripts/session-manager.mjs +12 -1
@@ -0,0 +1,162 @@
1
+ /**
2
+ * `orphan-plan`: the session manager's per-cycle "Orphans and holds" sweep
3
+ * (CodySwannGT/lisa#4722). The plan writes nothing: the manager finishes,
4
+ * returns, re-dispatches or parks each orphan and lifts or keeps each hold
5
+ * through `lisa-tracker-write`, as the skill says.
6
+ *
7
+ * Who the manager is and who may release a hold come from the ledger and
8
+ * config only, never from the input: the input is assembled from items'
9
+ * own (untrusted) bodies and comments, so ids carried beside them would let
10
+ * an item vouch for itself, and a live ref an input could drop would let the
11
+ * sweep return an item a worker is still on.
12
+ *
13
+ * Item bodies and comments arrive on stdin or in a file, never in argv.
14
+ * @module session-manager/cli-orphans
15
+ */
16
+ import {
17
+ readPath,
18
+ resolveRole,
19
+ } from "../../../scripts/resolve-lifecycle-role.mjs";
20
+ import {
21
+ CliError,
22
+ asSetupError,
23
+ humanNeededLabel,
24
+ intFlag,
25
+ loadProject,
26
+ stdinText,
27
+ validOrAbsent,
28
+ } from "./cli-runtime.mjs";
29
+ import { parseJson, readJsonFile } from "./json-input.mjs";
30
+ import { readLedger } from "./ledger.mjs";
31
+ import { planOrphanSweep } from "./orphan-sweep.mjs";
32
+
33
+ /** The roles whose labels count as "in a lane" for a hold release. */
34
+ const LANE_ROLES = ["ready", "claimed", "blocked", "review", "human_needed"];
35
+
36
+ /** Ledger statuses that mean a worker is on the item, or a person is asked. */
37
+ const LIVE_STATUSES = new Set(["running", "question"]);
38
+
39
+ /**
40
+ * The tracker this project uses.
41
+ * @param {ReturnType<typeof loadProject>} project - Loaded project
42
+ * @returns {string | undefined} `github`, `jira` or `linear`
43
+ */
44
+ const trackerOf = project => project.local?.tracker ?? project.global?.tracker;
45
+
46
+ /**
47
+ * One lifecycle role's configured value, empty when unset.
48
+ * @param {ReturnType<typeof loadProject>} project - Loaded project
49
+ * @param {string} name - Role name
50
+ * @returns {string} Label or state
51
+ */
52
+ function roleValue(project, name) {
53
+ return resolveRole({
54
+ role: name,
55
+ vendor: trackerOf(project),
56
+ local: project.local,
57
+ global: project.global,
58
+ }).value;
59
+ }
60
+
61
+ /**
62
+ * Every configured `done` value: the env-keyed map's values, or one string.
63
+ * @param {ReturnType<typeof loadProject>} project - Loaded project
64
+ * @returns {string[]} Done labels or states
65
+ */
66
+ function doneValues(project) {
67
+ const roots = { jira: "jira.workflow", linear: "linear.workflow" };
68
+ const root = roots[trackerOf(project)] ?? "github.labels.build";
69
+ for (const config of [project.local, project.global]) {
70
+ const done = readPath(config, `${root}.done`);
71
+ if (typeof done === "string" && done !== "") return [done];
72
+ if (done && typeof done === "object") {
73
+ return Object.values(done).filter(value => typeof value === "string");
74
+ }
75
+ }
76
+ return [];
77
+ }
78
+
79
+ /**
80
+ * The hold policy from config: labels, lanes and human-only classes.
81
+ * @param {ReturnType<typeof loadProject>} project - Loaded project
82
+ * @returns {object} Policy fields for planOrphanSweep
83
+ */
84
+ function holdPolicy(project) {
85
+ const humanOnly =
86
+ readPath(project.local, "humanGate.humanOnly") ??
87
+ readPath(project.global, "humanGate.humanOnly");
88
+ return {
89
+ humanNeededLabel: humanNeededLabel(project, undefined),
90
+ humanOnly,
91
+ readyLabel: roleValue(project, "ready"),
92
+ // A hold's role is its lane: on Jira and Linear the lane is a state, so
93
+ // the lift's lane check reads it as one more label.
94
+ roleLabels: {
95
+ ...Object.fromEntries(
96
+ LANE_ROLES.map(name => [name, roleValue(project, name)]).filter(
97
+ ([, value]) => value !== ""
98
+ )
99
+ ),
100
+ done: doneValues(project),
101
+ },
102
+ // Where roles are states, a hold with no known lane is lifted but never
103
+ // re-laned (fail closed).
104
+ rolesAreStates: trackerOf(project) !== "github",
105
+ lifecycleLabels: [
106
+ ...LANE_ROLES.map(name => roleValue(project, name)),
107
+ ...doneValues(project),
108
+ ].filter(value => value !== ""),
109
+ };
110
+ }
111
+
112
+ /**
113
+ * Read the envelope and refuse one not paged to completion.
114
+ * @param {object} ctx - CLI context
115
+ * @returns {{items: unknown, holds: unknown}} The listed items and holds
116
+ */
117
+ function readEnvelope(ctx) {
118
+ const envelope = ctx.values.input
119
+ ? readJsonFile(ctx.values.input)
120
+ : parseJson(stdinText(ctx, "orphan JSON"), "stdin");
121
+ if (envelope?.complete !== true) {
122
+ throw new CliError(
123
+ "The orphan listing was not paged to completion (complete !== true); " +
124
+ "refusing to plan from a partial list.",
125
+ 2
126
+ );
127
+ }
128
+ return { items: envelope.items, holds: envelope.holds };
129
+ }
130
+
131
+ /**
132
+ * `orphan-plan [--input <file>] [--max <n>] [--stale-hours <n>]` (stdin
133
+ * without --input: `{"complete":true,"items":[...],"holds":[...]}`).
134
+ * @param {object} ctx - CLI context
135
+ * @returns {Promise<{ json: object }>} The plan from planOrphanSweep
136
+ */
137
+ export async function orphanPlan(ctx) {
138
+ const input = readEnvelope(ctx);
139
+ const max = intFlag(ctx.values.max, "--max");
140
+ const staleHours = intFlag(ctx.values["stale-hours"], "--stale-hours");
141
+ const project = loadProject(ctx.root);
142
+ const config = validOrAbsent(project);
143
+ const ledger = await readLedger(ctx.root);
144
+ const liveRefs = Object.entries(ledger.items)
145
+ .filter(([, item]) => LIVE_STATUSES.has(item.status))
146
+ .map(([ref]) => ref);
147
+ return {
148
+ json: asSetupError(() =>
149
+ planOrphanSweep(input, {
150
+ liveRefs,
151
+ me: ledger.control.me ?? null,
152
+ operatorIds: config?.operatorIds ?? [],
153
+ trustedAuthorIds: config?.trustedAuthorIds ?? [],
154
+ now: new Date(),
155
+ ...(max === undefined ? {} : { max }),
156
+ ...(staleHours === undefined ? {} : { staleHours }),
157
+ previousDigest: ledger.control.holdDigest ?? null,
158
+ ...holdPolicy(project),
159
+ })
160
+ ),
161
+ };
162
+ }
@@ -257,6 +257,10 @@ Per cycle
257
257
  control.setupGapsClearedAt, so classify never re-records the gap from
258
258
  a worker that started before the clear. stdout {repo,cleared}.
259
259
  ledger control [--paused true|false] [--max-workers <n>|none] [--me <id>|none]
260
+ [--hold-digest <fingerprint>|none]
261
+ --hold-digest records the orphan-plan holds.digest.fingerprint the
262
+ operator was last sent (a sha256, else exit 2), so the same hold list
263
+ is sent once; orphan-plan reports holds.digest.changed against it.
260
264
  route [--reply-to <telegram message id>] [--owner <name>] STDIN: message
261
265
  stdout {kind:"answer",ref,body[,message]} | {kind:"command",name,...}
262
266
  | {kind:"invalid-command",reason} | {kind:"ambiguous",candidates}.
@@ -307,6 +311,42 @@ Per cycle
307
311
  wrongly-escalated, hold and release evidence, a draft
308
312
  Planning (filing) rule); comment is the marker to post afterwards.
309
313
  --max caps captures per cycle (default 3); the rest are deferred.
314
+ orphan-plan [--input <file>] [--max <n>] [--stale-hours <n>]
315
+ STDIN (without --input): JSON
316
+ {complete:true,items:[{ref,role,labels,body,comments,assignees,
317
+ updatedAt,pr}],holds:[{ref,role,labels,body,comments,assignees,
318
+ updatedAt}]}. Plans the
319
+ "Orphans and holds" sweep; writes nothing. items are the claimed (and
320
+ review) role; pr is omitted when not looked up, null when none was
321
+ found, else {url,state:open|merged|closed}. holds carry the
322
+ human-needed label or a [lisa-human-gate] marker; a hold's role
323
+ (ready, claimed, review, blocked, done) counts as its lane, so a lift
324
+ never moves an item that is in a lane back to ready, and on jira and
325
+ linear a hold with no known role is lifted but never re-laned. Live refs (ledger
326
+ status running or question), me (ledger control.me), operatorIds,
327
+ trustedAuthorIds and the hold labels come from the ledger and config;
328
+ the same keys in the input are ignored. Skips live, foreign (assigned
329
+ to neither me nor an operator), fresh (updated within --stale-hours,
330
+ default 6) and undated items. Live and foreign holds are skipped; a
331
+ fresh or undated hold is not lifted (skipped fresh or undated) but its
332
+ kept reasons still reach holds.keep and the digest. A lift left with
333
+ nothing to write is skipped as nothing-to-write; decision is null for
334
+ a lift with no newly lifted reason. A review-role
335
+ item with an open pull request, and a merged item whose comments hold
336
+ a line starting "[lisa-session-manager] Cannot complete:" posted
337
+ within 24 hours (or undated: send each comment's createdAt), are parked with reasonOnItem true; only the claimed role is re-dispatched. A
338
+ partial lift also appears in holds.keep with the reasons still left
339
+ for a person. stdout {doneReady:[{ref,prUrl,reason}],
340
+ return:[{ref,reason,comment}],redispatch:[{ref,prUrl,reason}],
341
+ parked:[{ref,reason,reasonOnItem[,comment]}],lookup:[{ref,reason}],
342
+ skipped:[{ref,reason}],holds:{lift:[{ref,reason,comments,actions,
343
+ decision}],keep:[{ref,reason}],digest:{fingerprint,text,changed}},
344
+ deferred:[{ref,bucket}]}. --max (default 10) caps the writes, spent in
345
+ order doneReady, return, redispatch, parked, holds.lift (a parked item
346
+ that already says why costs none; every kept hold is listed), and caps
347
+ lookup separately; the rest are deferred. Every comment starts with
348
+ [lisa-session-manager]. Exit 2 when complete is not true, the input
349
+ is not JSON, or a flag is bad.
310
350
  answer <ref> STDIN: the answer
311
351
  Queues an operator's answer (source "cli") for the next cycle to
312
352
  deliver to the worker, or record on the item when the worker has
@@ -110,6 +110,7 @@ const FINISH_STATUSES = new Set(["DONE", "FAILED"]);
110
110
  * @property {number} version - Shape version
111
111
  * @property {Record<string, LedgerItem>} items - Items keyed by ref
112
112
  * @property {{paused: boolean, maxWorkers: number|null, me: string|null,
113
+ * holdDigest?: string|null,
113
114
  * setupGaps: Record<string, import("./ledger-setup-gaps.mjs").SetupGap>,
114
115
  * setupGapsClearedAt?: Record<string, string>}}
115
116
  * control - Operator controls; `setupGaps` holds the repos `spawn` refuses
@@ -475,7 +476,8 @@ export function clearValidationFailure(projectRoot, { ref }, seams) {
475
476
 
476
477
  /**
477
478
  * Check a control patch before it is written.
478
- * @param {{paused?: unknown, maxWorkers?: unknown, me?: unknown}} patch - Patch
479
+ * @param {{paused?: unknown, maxWorkers?: unknown, me?: unknown,
480
+ * holdDigest?: unknown}} patch - Patch
479
481
  */
480
482
  function assertControlPatch(patch) {
481
483
  if ("paused" in patch && typeof patch.paused !== "boolean") {
@@ -497,15 +499,25 @@ function assertControlPatch(patch) {
497
499
  if ("me" in patch && patch.me !== null && typeof patch.me !== "string") {
498
500
  throw new Error("control.me must be a string or null");
499
501
  }
502
+ if (
503
+ "holdDigest" in patch &&
504
+ patch.holdDigest !== null &&
505
+ typeof patch.holdDigest !== "string"
506
+ ) {
507
+ throw new Error("control.holdDigest must be a string or null");
508
+ }
500
509
  }
501
510
 
502
511
  /**
503
512
  * Merge operator controls into the ledger: `paused`, the `maxWorkers`
504
- * override (null clears it) and `me`, the resolved tracker identity. The
513
+ * override (null clears it), `me`, the resolved tracker identity, and
514
+ * `holdDigest`, the fingerprint of the hold list last sent to the operator
515
+ * (#4722; `orphan-plan` reports `changed` against it). The
505
516
  * block also carries `setupGaps` (and `setupGapsClearedAt` once a gap was
506
517
  * cleared); this never changes them — only ledger-setup-gaps.mjs writes them.
507
518
  * @param {string} projectRoot - Absolute project root
508
- * @param {{paused?: boolean, maxWorkers?: number|null, me?: string|null}} patch - Fields to set
519
+ * @param {{paused?: boolean, maxWorkers?: number|null, me?: string|null,
520
+ * holdDigest?: string|null}} patch - Fields to set
509
521
  * @param {LedgerSeams} [seams] - Injected seams
510
522
  * @returns {Promise<Ledger["control"]>} New control block, setup gaps included
511
523
  */
@@ -0,0 +1,233 @@
1
+ /**
2
+ * Classify one orphaned item for the "Orphans and holds" sweep
3
+ * (CodySwannGT/lisa#4722), and word the comments the manager posts on it.
4
+ * Pure: the clock arrives in the policy.
5
+ *
6
+ * Every comment starts with `[lisa-session-manager]`: `item-answer` ignores
7
+ * machine comments by that tag, so a sweep comment is never read as a
8
+ * person's answer.
9
+ * @module session-manager/orphan-buckets
10
+ */
11
+ import {
12
+ HUMAN_GATE_MARKER,
13
+ humanGateHolds,
14
+ humanGateVerdict,
15
+ normalizeProviderMarkdown,
16
+ } from "../../../scripts/intake-blocker-reprobe.mjs";
17
+ import { QUESTION_MARKER } from "./human-needed.mjs";
18
+
19
+ /** The tag every comment the manager posts starts with. */
20
+ export const SWEEP_COMMENT_PREFIX = "[lisa-session-manager]";
21
+
22
+ /**
23
+ * How the comment the manager posts when `lisa-work-item.mjs finish`
24
+ * refuses an item begins. A later cycle that sees a recent one parks the
25
+ * item instead of trying to finish it again every cycle.
26
+ */
27
+ export const FINISH_REFUSED_PREFIX = `${SWEEP_COMMENT_PREFIX} Cannot complete:`;
28
+
29
+ /**
30
+ * How long a refusal parks an item. After that, finishing is retried: the
31
+ * refusal's cause (a missing deploy, a slow check) is often fixed by then,
32
+ * and a park with no end would strand a merged item for good.
33
+ */
34
+ export const FINISH_RETRY_HOURS = 24;
35
+
36
+ /** Words in a manager comment that show it explains a hold. */
37
+ const HOLD_WORDS = /\b(?:parked|held|hold|waiting on a person)\b/iu;
38
+
39
+ /**
40
+ * The comment bodies of an item.
41
+ * @param {unknown} comments - Comments as strings or `{body}` objects
42
+ * @returns {string[]} Bodies, provider escaping undone
43
+ */
44
+ function bodies(comments) {
45
+ return (Array.isArray(comments) ? comments : [])
46
+ .map(entry => (typeof entry === "string" ? entry : entry?.body))
47
+ .filter(body => typeof body === "string")
48
+ .map(normalizeProviderMarkdown);
49
+ }
50
+
51
+ /**
52
+ * Whether a body has a line starting with `marker`, after leading space and
53
+ * an optional HTML comment opener.
54
+ * @param {string} body - Comment body
55
+ * @param {string} marker - Marker text
56
+ * @returns {boolean} True when a line declares it
57
+ */
58
+ function declares(body, marker) {
59
+ return body
60
+ .split("\n")
61
+ .some(line => line.replace(/^\s*(?:<!--\s*)?/u, "").startsWith(marker));
62
+ }
63
+
64
+ /**
65
+ * Whether the item already says why it is held: a `[lisa-human-gate]` body
66
+ * marker or comment, the manager's question comment, or a
67
+ * `[lisa-session-manager]` comment naming the hold.
68
+ * @param {{body?: unknown, comments?: unknown}} item - The item
69
+ * @returns {boolean} True when a reader can see the reason
70
+ */
71
+ export function holdReasonOnItem(item) {
72
+ if (humanGateHolds(item.body).length > 0) return true;
73
+ return bodies(item.comments).some(
74
+ body =>
75
+ declares(body, HUMAN_GATE_MARKER) ||
76
+ declares(body, QUESTION_MARKER) ||
77
+ (declares(body, SWEEP_COMMENT_PREFIX) && HOLD_WORDS.test(body))
78
+ );
79
+ }
80
+
81
+ /**
82
+ * How long ago an item was last touched, in words: hours under two days.
83
+ * @param {number} ms - Elapsed milliseconds
84
+ * @returns {string} e.g. `for 9 hours`, `for 3 days`
85
+ */
86
+ export function ageInWords(ms) {
87
+ const hours = Math.max(0, Math.floor(ms / 3_600_000));
88
+ if (hours < 48) return `for ${hours} ${hours === 1 ? "hour" : "hours"}`;
89
+ return `for ${Math.floor(hours / 24)} days`;
90
+ }
91
+
92
+ /**
93
+ * The parked entry: the reason, and a comment only when the item lacks one.
94
+ * @param {{ref: string, labels?: unknown, body?: unknown, comments?: unknown}} item - Item
95
+ * @param {object} policy - Resolved policy
96
+ * @returns {object} Parked entry
97
+ */
98
+ function parkedEntry(item, policy) {
99
+ const label = policy.humanNeededLabel ?? "human-needed";
100
+ const reason = "held for a person, with no live worker";
101
+ if (holdReasonOnItem(item)) {
102
+ return { ref: item.ref, reason, reasonOnItem: true };
103
+ }
104
+ return {
105
+ ref: item.ref,
106
+ reason,
107
+ reasonOnItem: false,
108
+ comment:
109
+ `${SWEEP_COMMENT_PREFIX} Parked: this item carries the \`${label}\` ` +
110
+ "label, so it is waiting on a person, and no worker is on it. It stays " +
111
+ "where it is until a person acts or releases the hold.",
112
+ };
113
+ }
114
+
115
+ /**
116
+ * Whether an orphan is held: the human-needed label, or the shared hold
117
+ * verdict (a declared body hold not yet released or lifted).
118
+ * @param {object} item - Item
119
+ * @param {object} policy - Resolved policy
120
+ * @returns {boolean} True when held
121
+ */
122
+ function isHeld(item, policy) {
123
+ const verdict = humanGateVerdict({
124
+ labels: item.labels,
125
+ body: item.body,
126
+ comments: item.comments,
127
+ trustedHumanActorIds: policy.trustedHumanActorIds,
128
+ humanNeededLabel: policy.humanNeededLabel,
129
+ humanOnly: policy.humanOnly,
130
+ });
131
+ return verdict.held || verdict.labelPresent;
132
+ }
133
+
134
+ /**
135
+ * When a refusal comment was posted, as epoch ms; NaN when it carries no
136
+ * readable date.
137
+ * @param {unknown} comment - A structured comment
138
+ * @returns {number} Posting time
139
+ */
140
+ function postedAt(comment) {
141
+ const raw = comment?.createdAt ?? comment?.created_at ?? comment?.created;
142
+ return new Date(raw ?? Number.NaN).getTime();
143
+ }
144
+
145
+ /**
146
+ * Whether a refusal still parks the item: some comment line starts
147
+ * {@link FINISH_REFUSED_PREFIX} and that comment is younger than the retry
148
+ * window, or has no readable date (which fails closed: stay parked).
149
+ * @param {{comments?: unknown}} item - Item
150
+ * @param {{now: number, finishRetryMs: number}} policy - Resolved policy
151
+ * @returns {boolean} True while a refusal holds the item
152
+ */
153
+ function completionRefused(item, policy) {
154
+ const comments = Array.isArray(item.comments) ? item.comments : [];
155
+ return comments.some(comment => {
156
+ const text = typeof comment === "string" ? comment : comment?.body;
157
+ if (typeof text !== "string") return false;
158
+ if (!declares(normalizeProviderMarkdown(text), FINISH_REFUSED_PREFIX)) {
159
+ return false;
160
+ }
161
+ const at = postedAt(comment);
162
+ return !Number.isFinite(at) || policy.now - at < policy.finishRetryMs;
163
+ });
164
+ }
165
+
166
+ /**
167
+ * The bucket for a merged item: finish it, unless completion was already
168
+ * refused within the retry window, in which case it waits for whatever the
169
+ * refusal named.
170
+ * @param {{ref: string, pr: {url?: string}, comments?: unknown}} item - Item
171
+ * @param {{now: number, finishRetryMs: number}} policy - Resolved policy
172
+ * @returns {{bucket: string, entry: object}} Bucket and its entry
173
+ */
174
+ function mergedBucket(item, policy) {
175
+ const { ref, pr } = item;
176
+ if (completionRefused(item, policy)) {
177
+ const reason =
178
+ "its pull request merged but completion was refused; the refusal on the item says why";
179
+ return { bucket: "parked", entry: { ref, reason, reasonOnItem: true } };
180
+ }
181
+ const reason = "its pull request merged; only completion is missing";
182
+ return { bucket: "doneReady", entry: { ref, prUrl: pr.url, reason } };
183
+ }
184
+
185
+ /**
186
+ * The bucket for an item with an open pull request: only the `claimed` role
187
+ * re-dispatches; an item in the `review` role waits on review or merge.
188
+ * @param {{ref: string, role?: unknown, pr: {url?: string}}} item - Item
189
+ * @returns {{bucket: string, entry: object}} Bucket and its entry
190
+ */
191
+ function openBucket(item) {
192
+ const { ref, pr } = item;
193
+ if (item.role === "review") {
194
+ const reason =
195
+ "in review: waiting on review or merge of its open pull request";
196
+ return { bucket: "parked", entry: { ref, reason, reasonOnItem: true } };
197
+ }
198
+ const reason = "an open pull request with no live worker";
199
+ return { bucket: "redispatch", entry: { ref, prUrl: pr.url, reason } };
200
+ }
201
+
202
+ /**
203
+ * Bucket one orphan that passed the live, foreign and fresh checks. A merged
204
+ * pull request wins over a hold: the work is done, only completion is left.
205
+ * @param {{ref: string, role?: unknown, pr?: unknown, updatedAt?: unknown,
206
+ * comments?: unknown}} item - Item
207
+ * @param {{now: number}} policy - Resolved policy
208
+ * @returns {{bucket: string, entry: object}} Bucket and its entry
209
+ */
210
+ export function classifyOrphan(item, policy) {
211
+ const { ref, pr } = item;
212
+ if (pr === undefined) {
213
+ return {
214
+ bucket: "lookup",
215
+ entry: { ref, reason: "its pull request has not been looked up yet" },
216
+ };
217
+ }
218
+ const state = pr === null ? null : String(pr.state ?? "").toLowerCase();
219
+ if (state === "merged") return mergedBucket(item, policy);
220
+ if (isHeld(item, policy)) {
221
+ return { bucket: "parked", entry: parkedEntry(item, policy) };
222
+ }
223
+ if (state === "open") return openBucket(item);
224
+ const age = ageInWords(policy.now - new Date(item.updatedAt).getTime());
225
+ return {
226
+ bucket: "return",
227
+ entry: {
228
+ ref,
229
+ reason: "no live worker and no open or merged pull request",
230
+ comment: `${SWEEP_COMMENT_PREFIX} Returned to Ready: claimed ${age} with no live worker and no open or merged pull request.`,
231
+ },
232
+ };
233
+ }