@ouro.bot/cli 0.1.0-alpha.1112 → 0.1.0-alpha.1114
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/changelog.json +12 -0
- package/deploy/unraid/sanctuary.ouro/bundle-meta.json +1 -1
- package/deploy/unraid/sanctuary.xml +1 -1
- package/dist/heart/identity.js +10 -2
- package/dist/senses/app-sessions/issue-drain-state.js +3 -1
- package/dist/senses/app-sessions/issue-drains.js +53 -13
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/changelog.json
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"_note": "This changelog is maintained as part of the PR/version-bump workflow. Agent-curated, not auto-generated. Agents read this file directly via read_file to understand what changed between versions.",
|
|
3
3
|
"versions": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.1.0-alpha.1114",
|
|
6
|
+
"changes": [
|
|
7
|
+
"An issue drain can list `ignoredBodyTrailers` (for example `Active-at`, `Waiting-for`): an edit that changes only those `Key: value` lines of an issue body, such as a lane's hourly beat, no longer wakes the drain. Any other body edit still does, and a drain without the setting behaves as before."
|
|
8
|
+
]
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"version": "0.1.0-alpha.1113",
|
|
12
|
+
"changes": [
|
|
13
|
+
"Issue drains are woken only by changes someone other than the drain made: the drain's own status comment (by marker and revision) and its own `drain:` label changes no longer count as activity, so a drain stops waking on issues that did not change. A new comment, a body or title edit, a reopen or another label still wakes it once; a closed issue the drain handled never wakes it, and its waiting event is dropped."
|
|
14
|
+
]
|
|
15
|
+
},
|
|
4
16
|
{
|
|
5
17
|
"version": "0.1.0-alpha.1112",
|
|
6
18
|
"changes": [
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<?xml version="1.0"?>
|
|
2
2
|
<Container version="2">
|
|
3
3
|
<Name>ouro-butler</Name>
|
|
4
|
-
<Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.
|
|
4
|
+
<Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1114</Repository>
|
|
5
5
|
<Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
|
|
6
6
|
<Network>host</Network>
|
|
7
7
|
<Shell>sh</Shell>
|
package/dist/heart/identity.js
CHANGED
|
@@ -188,17 +188,25 @@ function normalizeIssueDrains(rawSense, configFile) {
|
|
|
188
188
|
const seen = new Set();
|
|
189
189
|
result.issueDrains = issueDrains.map((entry, index) => {
|
|
190
190
|
const item = (entry && typeof entry === "object" ? entry : {});
|
|
191
|
-
const { repo, session, account } = item;
|
|
191
|
+
const { repo, session, account, ignoredBodyTrailers } = item;
|
|
192
192
|
if (typeof repo !== "string" || !/^[\w.-]+\/[\w.-]+$/.test(repo))
|
|
193
193
|
fail(`issueDrains[${index}].repo must be "owner/name"`);
|
|
194
194
|
if (typeof session !== "string" || !session.trim())
|
|
195
195
|
fail(`issueDrains[${index}].session must be a Copilot app session id`);
|
|
196
196
|
if (account !== undefined && (typeof account !== "string" || !account.trim()))
|
|
197
197
|
fail(`issueDrains[${index}].account must be a GitHub login`);
|
|
198
|
+
if (ignoredBodyTrailers !== undefined && (!Array.isArray(ignoredBodyTrailers) || ignoredBodyTrailers.some(key => typeof key !== "string" || !/^[\w][\w -]*$/.test(key.trim())))) {
|
|
199
|
+
fail(`issueDrains[${index}].ignoredBodyTrailers must be an array of trailer keys such as "Active-at"`);
|
|
200
|
+
}
|
|
198
201
|
if (seen.has(repo))
|
|
199
202
|
fail(`issueDrains[${index}].repo ${repo} is listed twice`);
|
|
200
203
|
seen.add(repo);
|
|
201
|
-
return {
|
|
204
|
+
return {
|
|
205
|
+
repo: repo,
|
|
206
|
+
session: session.trim(),
|
|
207
|
+
...(account !== undefined ? { account: account.trim() } : {}),
|
|
208
|
+
...(ignoredBodyTrailers !== undefined ? { ignoredBodyTrailers: ignoredBodyTrailers.map(key => key.trim()) } : {}),
|
|
209
|
+
};
|
|
202
210
|
});
|
|
203
211
|
}
|
|
204
212
|
if (issuePollMinutes !== undefined) {
|
|
@@ -33,11 +33,13 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.drainStateFile = void 0;
|
|
36
|
+
exports.drainStateFile = exports.seenIssue = void 0;
|
|
37
37
|
exports.readDrainStates = readDrainStates;
|
|
38
38
|
exports.drainStatusLines = drainStatusLines;
|
|
39
39
|
const path = __importStar(require("node:path"));
|
|
40
40
|
const store_1 = require("./store");
|
|
41
|
+
const seenIssue = (entry) => typeof entry === "string" ? { updatedAt: entry } : entry;
|
|
42
|
+
exports.seenIssue = seenIssue;
|
|
41
43
|
const drainStateFile = (agentRoot) => path.join((0, store_1.appSessionsStateDir)(agentRoot), "issue-drains.json");
|
|
42
44
|
exports.drainStateFile = drainStateFile;
|
|
43
45
|
function readDrainStates(agentRoot) {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sendWake = exports.connectGithub = exports.DRAIN_STATUS_MARKER = exports.ISSUE_POLL_MS = void 0;
|
|
3
|
+
exports.sendWake = exports.connectGithub = exports.DRAIN_LABEL_PREFIX = exports.DRAIN_STATUS_MARKER = exports.ISSUE_POLL_MS = void 0;
|
|
4
4
|
exports.wakeMessage = wakeMessage;
|
|
5
5
|
exports.pollDrain = pollDrain;
|
|
6
6
|
exports.pollIssueDrains = pollIssueDrains;
|
|
7
|
+
const node_crypto_1 = require("node:crypto");
|
|
7
8
|
const node_child_process_1 = require("node:child_process");
|
|
8
9
|
const account_pool_1 = require("../../heart/providers/account-pool");
|
|
9
10
|
const runtime_1 = require("../../nerves/runtime");
|
|
@@ -15,10 +16,17 @@ const store_1 = require("./store");
|
|
|
15
16
|
* lists each repository's open issues and messages the drain's session when one is new or changed since the last
|
|
16
17
|
* poll. Events are written to disk before anyone is woken, so a crash or a refused message loses nothing; an
|
|
17
18
|
* authentication or network failure is recorded for `ouro status` and leaves every marker where it was.
|
|
19
|
+
*
|
|
20
|
+
* `updated_at` alone is not a revision: the drain's own label edits and status comment move it too. An issue wakes the
|
|
21
|
+
* drain only when something other than the drain changed it since the revision last recorded for that issue.
|
|
18
22
|
*/
|
|
19
23
|
exports.ISSUE_POLL_MS = 5 * 60_000;
|
|
20
24
|
/** A drain's own status comment carries this marker, so its creation and edits do not wake the drain again. */
|
|
21
25
|
exports.DRAIN_STATUS_MARKER = "<!-- ouro-drain-status -->";
|
|
26
|
+
/** The drain moves an issue through labels in this namespace (`drain: triaged`, `drain: in progress`); changing them is not news. */
|
|
27
|
+
exports.DRAIN_LABEL_PREFIX = "drain:";
|
|
28
|
+
/** A closed issue's record is kept this long, so one that comes back unchanged is not mistaken for a new issue. */
|
|
29
|
+
const GONE_MS = 30 * 24 * 3_600_000;
|
|
22
30
|
const MAX_TITLES = 20;
|
|
23
31
|
const PAGE = 100;
|
|
24
32
|
const blank = () => ({ seeded: false, seen: {}, pending: [] });
|
|
@@ -31,10 +39,31 @@ function wakeMessage(repo, events) {
|
|
|
31
39
|
const more = events.length > MAX_TITLES ? `, and ${events.length - MAX_TITLES} more` : "";
|
|
32
40
|
return `New or changed issues in ${repo}: ${shown.join(", ")}${more}. Drain them.`;
|
|
33
41
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
42
|
+
const escapeRegExp = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
43
|
+
/** The body without its ignored trailer lines (`Active-at: …`), so an edit that touches only those lines leaves the digest alone. */
|
|
44
|
+
function bodyWithoutTrailers(body, keys) {
|
|
45
|
+
if (keys.length === 0)
|
|
46
|
+
return body;
|
|
47
|
+
const trailer = new RegExp(`^[ \\t]*(?:${keys.map(escapeRegExp).join("|")})[ \\t]*:.*(?:\\r?\\n|$)`, "gim");
|
|
48
|
+
return body.replace(trailer, "").trimEnd();
|
|
49
|
+
}
|
|
50
|
+
const digestOf = (issue, keys) => (0, node_crypto_1.createHash)("sha1").update(`${issue.title}\n${bodyWithoutTrailers(issue.body ?? "", keys)}`).digest("hex").slice(0, 16);
|
|
51
|
+
/** The drain's own status comment: the marker, written by the polling account. Its creation and every edit are skipped. */
|
|
52
|
+
const ownStatus = (comment, login) => comment.user?.login?.toLowerCase() === login.toLowerCase() && !!comment.body?.includes(exports.DRAIN_STATUS_MARKER);
|
|
53
|
+
/** A reopen, or a label change outside the drain's own namespace. Closes, assignments, mentions and the drain's labels are not news. */
|
|
54
|
+
const newsEvent = (event) => event.event === "reopened" || ((event.event === "labeled" || event.event === "unlabeled") && !event.label?.name?.startsWith(exports.DRAIN_LABEL_PREFIX));
|
|
55
|
+
/** Whether anyone but the drain changed the issue since `before`: a new issue, an edit, another comment, a reopen or a label outside the drain's own. */
|
|
56
|
+
async function changedByOthers(api, repo, issue, before, digest, ignored) {
|
|
57
|
+
if (!before)
|
|
58
|
+
return true;
|
|
59
|
+
if (before.digest && (before.ignored ?? "") === ignored && before.digest !== digest)
|
|
60
|
+
return true;
|
|
61
|
+
const since = before.updatedAt;
|
|
62
|
+
const comments = (await api.comments(repo, issue.number, since)).filter(comment => comment.updated_at > since);
|
|
63
|
+
if (comments.some(comment => !ownStatus(comment, api.login)))
|
|
64
|
+
return true;
|
|
65
|
+
const events = (await api.issueEvents(repo, issue.number)).filter(event => event.created_at > since);
|
|
66
|
+
return events.some(newsEvent);
|
|
38
67
|
}
|
|
39
68
|
/** Poll one drain's repository, record what changed, then wake its session once with the whole batch. */
|
|
40
69
|
async function pollDrain(drain, states, save, deps) {
|
|
@@ -43,20 +72,29 @@ async function pollDrain(drain, states, save, deps) {
|
|
|
43
72
|
try {
|
|
44
73
|
const api = await deps.connect(drain.account);
|
|
45
74
|
const issues = await api.openIssues(drain.repo);
|
|
75
|
+
const trailers = drain.ignoredBodyTrailers ?? [];
|
|
76
|
+
const ignored = trailers.join(",");
|
|
46
77
|
const seen = {};
|
|
47
78
|
const recorded = [];
|
|
48
79
|
for (const issue of issues) {
|
|
49
80
|
const key = String(issue.number);
|
|
50
|
-
const before = state.seen[key];
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (before && ownStatusOnly(issue, (await api.comments(drain.repo, issue.number, before)).filter(comment => comment.updated_at > before), api.login))
|
|
81
|
+
const before = (0, issue_drain_state_1.seenIssue)(state.seen[key]);
|
|
82
|
+
const digest = digestOf(issue, trailers);
|
|
83
|
+
seen[key] = { updatedAt: issue.updated_at, digest, ...(ignored ? { ignored } : {}) };
|
|
84
|
+
if (!state.seeded || before?.updatedAt === issue.updated_at)
|
|
55
85
|
continue;
|
|
56
|
-
|
|
86
|
+
if (await changedByOthers(api, drain.repo, issue, before, digest, ignored))
|
|
87
|
+
recorded.push({ number: issue.number, title: issue.title, updatedAt: issue.updated_at });
|
|
88
|
+
}
|
|
89
|
+
for (const [key, entry] of Object.entries(state.seen)) {
|
|
90
|
+
const gone = (0, issue_drain_state_1.seenIssue)(entry);
|
|
91
|
+
const goneAt = gone.goneAt ?? deps.now;
|
|
92
|
+
if (!(key in seen) && deps.now - goneAt < GONE_MS)
|
|
93
|
+
seen[key] = { ...gone, goneAt };
|
|
57
94
|
}
|
|
95
|
+
const open = new Set(issues.map(issue => issue.number));
|
|
58
96
|
const numbers = new Set(recorded.map(event => event.number));
|
|
59
|
-
state.pending = [...state.pending.filter(event => !numbers.has(event.number)), ...recorded];
|
|
97
|
+
state.pending = [...state.pending.filter(event => open.has(event.number) && !numbers.has(event.number)), ...recorded];
|
|
60
98
|
state.seen = seen;
|
|
61
99
|
state.seeded = true;
|
|
62
100
|
state.openCount = issues.length;
|
|
@@ -112,8 +150,9 @@ const connectGithub = async (account) => {
|
|
|
112
150
|
};
|
|
113
151
|
const all = async (route) => {
|
|
114
152
|
const items = [];
|
|
153
|
+
const join = route.includes("?") ? "&" : "?";
|
|
115
154
|
for (let page = 1;; page++) {
|
|
116
|
-
const { body, next } = await get(`${route}
|
|
155
|
+
const { body, next } = await get(`${route}${join}per_page=${PAGE}&page=${page}`);
|
|
117
156
|
items.push(...body);
|
|
118
157
|
if (!next)
|
|
119
158
|
return items;
|
|
@@ -124,6 +163,7 @@ const connectGithub = async (account) => {
|
|
|
124
163
|
login,
|
|
125
164
|
openIssues: async (repo) => (await all(`/repos/${repo}/issues?state=open&sort=updated&direction=desc`)).filter(issue => !issue.pull_request),
|
|
126
165
|
comments: (repo, issue, since) => all(`/repos/${repo}/issues/${issue}/comments?since=${encodeURIComponent(since)}`),
|
|
166
|
+
issueEvents: (repo, issue) => all(`/repos/${repo}/issues/${issue}/events`),
|
|
127
167
|
};
|
|
128
168
|
};
|
|
129
169
|
exports.connectGithub = connectGithub;
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ouro.bot/cli",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.1114",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@ouro.bot/cli",
|
|
9
|
-
"version": "0.1.0-alpha.
|
|
9
|
+
"version": "0.1.0-alpha.1114",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@anthropic-ai/sdk": "^0.78.0",
|
|
12
12
|
"@ouro.bot/friends": "0.1.0-alpha.18",
|