@codyswann/lisa 4.110.2 → 4.111.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
- package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
- package/dist/core/upstream-evidence-manifest.js +74 -6
- package/dist/core/upstream-evidence-manifest.js.map +1 -1
- package/package.json +4 -4
- package/plugins/lisa/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa/.codex-plugin/scripts/human-gate-lift.mjs +148 -0
- package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/SKILL.md +69 -4
- package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/references/runbook-template.md +3 -0
- package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/cli-cycle.mjs +16 -0
- package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/cli-orphans.mjs +162 -0
- package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/cli-usage.mjs +40 -0
- package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/ledger.mjs +15 -3
- package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/orphan-buckets.mjs +233 -0
- package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/orphan-holds.mjs +252 -0
- package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/orphan-sweep.mjs +335 -0
- package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/session-manager.mjs +12 -1
- package/plugins/lisa/skills/lisa-session-manager/SKILL.md +69 -4
- package/plugins/lisa/skills/lisa-session-manager/references/runbook-template.md +3 -0
- package/plugins/lisa/skills/lisa-session-manager/scripts/cli-cycle.mjs +16 -0
- package/plugins/lisa/skills/lisa-session-manager/scripts/cli-orphans.mjs +162 -0
- package/plugins/lisa/skills/lisa-session-manager/scripts/cli-usage.mjs +40 -0
- package/plugins/lisa/skills/lisa-session-manager/scripts/ledger.mjs +15 -3
- package/plugins/lisa/skills/lisa-session-manager/scripts/orphan-buckets.mjs +233 -0
- package/plugins/lisa/skills/lisa-session-manager/scripts/orphan-holds.mjs +252 -0
- package/plugins/lisa/skills/lisa-session-manager/scripts/orphan-sweep.mjs +335 -0
- package/plugins/lisa/skills/lisa-session-manager/scripts/session-manager.mjs +12 -1
- package/plugins/lisa-agy/plugin.json +1 -1
- package/plugins/lisa-agy/skills/lisa-session-manager/SKILL.md +69 -4
- package/plugins/lisa-agy/skills/lisa-session-manager/references/runbook-template.md +3 -0
- package/plugins/lisa-agy/skills/lisa-session-manager/scripts/cli-cycle.mjs +16 -0
- package/plugins/lisa-agy/skills/lisa-session-manager/scripts/cli-orphans.mjs +162 -0
- package/plugins/lisa-agy/skills/lisa-session-manager/scripts/cli-usage.mjs +40 -0
- package/plugins/lisa-agy/skills/lisa-session-manager/scripts/ledger.mjs +15 -3
- package/plugins/lisa-agy/skills/lisa-session-manager/scripts/orphan-buckets.mjs +233 -0
- package/plugins/lisa-agy/skills/lisa-session-manager/scripts/orphan-holds.mjs +252 -0
- package/plugins/lisa-agy/skills/lisa-session-manager/scripts/orphan-sweep.mjs +335 -0
- package/plugins/lisa-agy/skills/lisa-session-manager/scripts/session-manager.mjs +12 -1
- package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-agy/plugin.json +1 -1
- package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/skills/lisa-session-manager/SKILL.md +69 -4
- package/plugins/lisa-copilot/skills/lisa-session-manager/references/runbook-template.md +3 -0
- package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/cli-cycle.mjs +16 -0
- package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/cli-orphans.mjs +162 -0
- package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/cli-usage.mjs +40 -0
- package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/ledger.mjs +15 -3
- package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/orphan-buckets.mjs +233 -0
- package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/orphan-holds.mjs +252 -0
- package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/orphan-sweep.mjs +335 -0
- package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/session-manager.mjs +12 -1
- package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cursor/skills/lisa-session-manager/SKILL.md +69 -4
- package/plugins/lisa-cursor/skills/lisa-session-manager/references/runbook-template.md +3 -0
- package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/cli-cycle.mjs +16 -0
- package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/cli-orphans.mjs +162 -0
- package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/cli-usage.mjs +40 -0
- package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/ledger.mjs +15 -3
- package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/orphan-buckets.mjs +233 -0
- package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/orphan-holds.mjs +252 -0
- package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/orphan-sweep.mjs +335 -0
- package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/session-manager.mjs +12 -1
- package/plugins/lisa-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-devin/skills/lisa-session-manager/SKILL.md +69 -4
- package/plugins/lisa-devin/skills/lisa-session-manager/references/runbook-template.md +3 -0
- package/plugins/lisa-devin/skills/lisa-session-manager/scripts/cli-cycle.mjs +16 -0
- package/plugins/lisa-devin/skills/lisa-session-manager/scripts/cli-orphans.mjs +162 -0
- package/plugins/lisa-devin/skills/lisa-session-manager/scripts/cli-usage.mjs +40 -0
- package/plugins/lisa-devin/skills/lisa-session-manager/scripts/ledger.mjs +15 -3
- package/plugins/lisa-devin/skills/lisa-session-manager/scripts/orphan-buckets.mjs +233 -0
- package/plugins/lisa-devin/skills/lisa-session-manager/scripts/orphan-holds.mjs +252 -0
- package/plugins/lisa-devin/skills/lisa-session-manager/scripts/orphan-sweep.mjs +335 -0
- package/plugins/lisa-devin/skills/lisa-session-manager/scripts/session-manager.mjs +12 -1
- package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-agy/plugin.json +1 -1
- package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-agy/plugin.json +1 -1
- package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-agy/plugin.json +1 -1
- package/plugins/lisa-openclaw-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-agy/plugin.json +1 -1
- package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-agy/plugin.json +1 -1
- package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-agy/plugin.json +1 -1
- package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-agy/plugin.json +1 -1
- package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/src/base/skills/lisa-session-manager/SKILL.md +69 -4
- package/plugins/src/base/skills/lisa-session-manager/references/runbook-template.md +3 -0
- package/plugins/src/base/skills/lisa-session-manager/scripts/cli-cycle.mjs +16 -0
- package/plugins/src/base/skills/lisa-session-manager/scripts/cli-orphans.mjs +162 -0
- package/plugins/src/base/skills/lisa-session-manager/scripts/cli-usage.mjs +40 -0
- package/plugins/src/base/skills/lisa-session-manager/scripts/ledger.mjs +15 -3
- package/plugins/src/base/skills/lisa-session-manager/scripts/orphan-buckets.mjs +233 -0
- package/plugins/src/base/skills/lisa-session-manager/scripts/orphan-holds.mjs +252 -0
- package/plugins/src/base/skills/lisa-session-manager/scripts/orphan-sweep.mjs +335 -0
- package/plugins/src/base/skills/lisa-session-manager/scripts/session-manager.mjs +12 -1
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The hold half of the session manager's "Orphans and holds" sweep
|
|
3
|
+
* (CodySwannGT/lisa#4722). Pure: no I/O, no clock, no config reads.
|
|
4
|
+
*
|
|
5
|
+
* Items behind a human gate (the human-needed label or a `[lisa-human-gate]`
|
|
6
|
+
* body marker) used to wait until someone noticed, even when the hold was a
|
|
7
|
+
* decision an agent is allowed to make. Each cycle the manager re-judges every
|
|
8
|
+
* hold with the shared `planHumanGateLift`, so the lift rule lives in one
|
|
9
|
+
* place: a hold it may lift is lifted with a `Decision:` line saying why; a
|
|
10
|
+
* hold only a person can act on goes into ONE consolidated operator list, the
|
|
11
|
+
* digest, sent only when its fingerprint changes.
|
|
12
|
+
* @module session-manager/orphan-holds
|
|
13
|
+
*/
|
|
14
|
+
import { createHash } from "node:crypto";
|
|
15
|
+
|
|
16
|
+
import { planHumanGateLift } from "../../../scripts/human-gate-lift.mjs";
|
|
17
|
+
import {
|
|
18
|
+
classifyHumanGateReason,
|
|
19
|
+
humanGateVerdict,
|
|
20
|
+
} from "../../../scripts/intake-blocker-reprobe.mjs";
|
|
21
|
+
import { findCredentialShape } from "./human-needed.mjs";
|
|
22
|
+
|
|
23
|
+
/** What the digest says for a hold carrying only the label. */
|
|
24
|
+
export const NO_STATED_REASON = "no stated reason";
|
|
25
|
+
|
|
26
|
+
/** Longest reason a digest line carries, so the list fits a phone screen. */
|
|
27
|
+
const REASON_LIMIT = 90;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A hold slug in words: `stripe-api-key` reads as `stripe api key`.
|
|
31
|
+
* @param {string} reason - Normalized hold reason
|
|
32
|
+
* @returns {string} Plain words
|
|
33
|
+
*/
|
|
34
|
+
const words = reason => reason.replaceAll(/[-_]+/gu, " ").trim();
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* One kept reason in plain language: the act a person must perform when the
|
|
38
|
+
* reason names one, the slug in words otherwise.
|
|
39
|
+
* @param {string} reason - Hold reason; empty for a label-only hold
|
|
40
|
+
* @param {unknown} humanOnly - Project-declared human-only classes
|
|
41
|
+
* @returns {string} Plain-language reason
|
|
42
|
+
*/
|
|
43
|
+
function describeKept(reason, humanOnly) {
|
|
44
|
+
if (reason === "") return NO_STATED_REASON;
|
|
45
|
+
if (findCredentialShape(reason) !== null) return "a reason that was withheld";
|
|
46
|
+
const verdict = classifyHumanGateReason(reason, { humanOnly });
|
|
47
|
+
const named = words(reason);
|
|
48
|
+
return verdict.valid && verdict.label
|
|
49
|
+
? `${named} (a person must ${verdict.label})`
|
|
50
|
+
: named;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Cap a digest reason at {@link REASON_LIMIT} characters.
|
|
55
|
+
* @param {string} text - Reason
|
|
56
|
+
* @returns {string} Bounded reason
|
|
57
|
+
*/
|
|
58
|
+
function bounded(text) {
|
|
59
|
+
return text.length > REASON_LIMIT
|
|
60
|
+
? `${text.slice(0, REASON_LIMIT - 1)}…`
|
|
61
|
+
: text;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The Decision line a lift carries: why an agent may decide the hold.
|
|
66
|
+
* @param {string[]} lifted - The reasons lifted
|
|
67
|
+
* @returns {string} One `Decision:` line
|
|
68
|
+
*/
|
|
69
|
+
function decisionLine(lifted) {
|
|
70
|
+
const named = lifted.map(reason => `"${words(reason)}"`).join(", ");
|
|
71
|
+
return (
|
|
72
|
+
`Decision: ${named} is a choice an agent may make under the project's ` +
|
|
73
|
+
"hold policy, since it names nothing only a person can do, so the hold " +
|
|
74
|
+
"is lifted and whoever builds the item makes and records that choice."
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The resolved value(s) of a hold's role: one label or state, or every
|
|
80
|
+
* env-keyed `done` value. Empty when the role is missing or unconfigured.
|
|
81
|
+
* @param {{role?: unknown}} item - Hold
|
|
82
|
+
* @param {Record<string, string | string[]> | undefined} roleLabels - Role
|
|
83
|
+
* to value(s)
|
|
84
|
+
* @returns {string[]} Lane values
|
|
85
|
+
*/
|
|
86
|
+
function laneValues(item, roleLabels) {
|
|
87
|
+
const known = roleLabels ?? {};
|
|
88
|
+
const role = typeof item.role === "string" ? item.role : "";
|
|
89
|
+
const value = Object.hasOwn(known, role) ? known[role] : [];
|
|
90
|
+
return (Array.isArray(value) ? value : [value]).filter(
|
|
91
|
+
entry => typeof entry === "string" && entry !== ""
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The item's labels plus its role's resolved value(s). On Jira and Linear a
|
|
97
|
+
* role is a workflow state, not a label, so without it the lane check would
|
|
98
|
+
* see an item in the `claimed` role as in no lane and move it back to the
|
|
99
|
+
* `ready` role.
|
|
100
|
+
* @param {{role?: unknown, labels?: unknown}} item - Hold
|
|
101
|
+
* @param {Record<string, string | string[]> | undefined} roleLabels - Role
|
|
102
|
+
* to value(s)
|
|
103
|
+
* @returns {unknown[]} Labels the lane check reads
|
|
104
|
+
*/
|
|
105
|
+
function withRoleLabel(item, roleLabels) {
|
|
106
|
+
const labels = Array.isArray(item.labels) ? item.labels : [];
|
|
107
|
+
return [...labels, ...laneValues(item, roleLabels)];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The lift's label writes, failing closed where roles are states: with no
|
|
112
|
+
* known lane for the hold, the lift lifts the hold but never re-lanes it,
|
|
113
|
+
* because "no state we recognize" is not proof the item is in no lane.
|
|
114
|
+
* @param {{role?: unknown}} item - Hold
|
|
115
|
+
* @param {object} policy - Resolved hold policy
|
|
116
|
+
* @param {{removeHumanNeededLabel: boolean, addReadyLabel: string|null}} actions - Planned writes
|
|
117
|
+
* @returns {{removeHumanNeededLabel: boolean, addReadyLabel: string|null}} Writes to apply
|
|
118
|
+
*/
|
|
119
|
+
function laneSafeActions(item, policy, actions) {
|
|
120
|
+
if (!policy.rolesAreStates) return actions;
|
|
121
|
+
if (laneValues(item, policy.roleLabels).length > 0) return actions;
|
|
122
|
+
return { ...actions, addReadyLabel: null };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The lift planner's input for one hold.
|
|
127
|
+
* @param {{labels?: unknown, body?: unknown, comments?: unknown}} item - Hold
|
|
128
|
+
* @param {object} policy - Resolved hold policy
|
|
129
|
+
* @returns {object} planHumanGateLift input
|
|
130
|
+
*/
|
|
131
|
+
function liftInput(item, policy) {
|
|
132
|
+
return {
|
|
133
|
+
labels: withRoleLabel(item, policy.roleLabels),
|
|
134
|
+
body: item.body,
|
|
135
|
+
comments: item.comments,
|
|
136
|
+
trustedHumanActorIds: policy.trustedHumanActorIds,
|
|
137
|
+
humanNeededLabel: policy.humanNeededLabel,
|
|
138
|
+
humanOnly: policy.humanOnly,
|
|
139
|
+
readyLabel: policy.readyLabel,
|
|
140
|
+
lifecycleLabels: policy.lifecycleLabels,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Whether a lift still writes anything once the lane check has run.
|
|
146
|
+
* @param {string[]} comments - Lift comments
|
|
147
|
+
* @param {{removeHumanNeededLabel: boolean, addReadyLabel: string|null}} actions - Lane-safe writes
|
|
148
|
+
* @returns {boolean} True when there is a comment or a label write
|
|
149
|
+
*/
|
|
150
|
+
const writesSomething = (comments, actions) =>
|
|
151
|
+
comments.length > 0 ||
|
|
152
|
+
actions.removeHumanNeededLabel ||
|
|
153
|
+
actions.addReadyLabel !== null;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* The verdict for a lift or partial lift. Classified after the lane check:
|
|
157
|
+
* where roles are states, a lift whose only write was re-laning has nothing
|
|
158
|
+
* left to do, and listing it would spend the cap every cycle.
|
|
159
|
+
* @param {{ref: string}} item - Hold
|
|
160
|
+
* @param {object} policy - Resolved hold policy
|
|
161
|
+
* @param {{lifted: string[], kept: string[], comments: string[], actions: object}} plan - Lift plan
|
|
162
|
+
* @returns {{kind: "lift"|"skip", entry: object, keep?: object}} Verdict
|
|
163
|
+
*/
|
|
164
|
+
function liftVerdict(item, policy, plan) {
|
|
165
|
+
// A re-lane-only lift (an earlier cycle posted the lift) decides nothing.
|
|
166
|
+
const decision = plan.lifted.length > 0 ? decisionLine(plan.lifted) : null;
|
|
167
|
+
const kept = plan.kept.map(reason => describeKept(reason, policy.humanOnly));
|
|
168
|
+
const keep =
|
|
169
|
+
kept.length > 0
|
|
170
|
+
? { keep: { ref: item.ref, reason: bounded(kept.join("; ")) } }
|
|
171
|
+
: {};
|
|
172
|
+
const comments = plan.comments.map(body =>
|
|
173
|
+
decision === null ? body : `${body}\n${decision}`
|
|
174
|
+
);
|
|
175
|
+
const actions = laneSafeActions(item, policy, plan.actions);
|
|
176
|
+
if (!writesSomething(comments, actions)) {
|
|
177
|
+
return {
|
|
178
|
+
...keep,
|
|
179
|
+
kind: "skip",
|
|
180
|
+
entry: { ref: item.ref, reason: "nothing-to-write" },
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
...keep,
|
|
185
|
+
kind: "lift",
|
|
186
|
+
entry: {
|
|
187
|
+
ref: item.ref,
|
|
188
|
+
reason: `the hold names only a decision an agent may make (${plan.lifted.map(words).join(", ")})`,
|
|
189
|
+
comments,
|
|
190
|
+
actions,
|
|
191
|
+
decision,
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Judge one hold: lift it, keep it for a person, or skip it.
|
|
198
|
+
* @param {{ref: string, labels?: unknown, body?: unknown, comments?: unknown}} item - Hold
|
|
199
|
+
* @param {object} policy - Resolved hold policy
|
|
200
|
+
* @returns {{kind: "lift"|"keep"|"skip", entry: object,
|
|
201
|
+
* keep?: {ref: string, reason: string}}} Verdict; a partial lift also
|
|
202
|
+
* carries `keep`, the reasons still left for a person
|
|
203
|
+
*/
|
|
204
|
+
export function judgeHold(item, policy) {
|
|
205
|
+
const input = liftInput(item, policy);
|
|
206
|
+
const plan = planHumanGateLift(input);
|
|
207
|
+
if (plan.reason === "lift" || plan.reason === "partial-lift") {
|
|
208
|
+
return liftVerdict(item, policy, plan);
|
|
209
|
+
}
|
|
210
|
+
if (plan.reason === "already-lifted") {
|
|
211
|
+
return { kind: "skip", entry: { ref: item.ref, reason: "already-lifted" } };
|
|
212
|
+
}
|
|
213
|
+
const verdict = humanGateVerdict(input);
|
|
214
|
+
if (!verdict.held) {
|
|
215
|
+
return { kind: "skip", entry: { ref: item.ref, reason: "released" } };
|
|
216
|
+
}
|
|
217
|
+
const reason = bounded(
|
|
218
|
+
verdict.outstanding
|
|
219
|
+
.map(kept => describeKept(kept, policy.humanOnly))
|
|
220
|
+
.join("; ")
|
|
221
|
+
);
|
|
222
|
+
return { kind: "keep", entry: { ref: item.ref, reason } };
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* The one consolidated operator list of truly-human holds, and its
|
|
227
|
+
* fingerprint. The fingerprint is the sha256 of the sorted `ref\treason`
|
|
228
|
+
* lines, so the order holds arrive in never changes it.
|
|
229
|
+
* @param {{ref: string, reason: string}[]} keep - Kept holds
|
|
230
|
+
* @param {string | null | undefined} previous - Fingerprint last sent
|
|
231
|
+
* @returns {{fingerprint: string | null, text: string, changed: boolean}}
|
|
232
|
+
* Digest; an empty list has a null fingerprint and empty text
|
|
233
|
+
*/
|
|
234
|
+
export function holdDigest(keep, previous) {
|
|
235
|
+
const rows = [...keep].sort((a, b) =>
|
|
236
|
+
a.ref < b.ref ? -1 : Number(a.ref > b.ref)
|
|
237
|
+
);
|
|
238
|
+
const fingerprint =
|
|
239
|
+
rows.length === 0
|
|
240
|
+
? null
|
|
241
|
+
: createHash("sha256")
|
|
242
|
+
.update(rows.map(row => `${row.ref}\t${row.reason}`).join("\n"))
|
|
243
|
+
.digest("hex");
|
|
244
|
+
const text =
|
|
245
|
+
rows.length === 0
|
|
246
|
+
? ""
|
|
247
|
+
: [
|
|
248
|
+
`Waiting on you (${rows.length}): only a person can do these.`,
|
|
249
|
+
...rows.map(row => `${row.ref}: ${row.reason}`),
|
|
250
|
+
].join("\n");
|
|
251
|
+
return { fingerprint, text, changed: fingerprint !== (previous ?? null) };
|
|
252
|
+
}
|