lastlight-core 0.24.1 → 0.24.3
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/config/default.yaml +43 -0
- package/deploy/slack/README.md +15 -0
- package/deploy/slack/slack-manifest.json +4 -1
- package/dist/admin/routes.js +40 -0
- package/dist/admin/routes.js.map +1 -1
- package/dist/config/config.d.ts +42 -0
- package/dist/config/config.js +41 -0
- package/dist/config/config.js.map +1 -1
- package/dist/connectors/index.d.ts +1 -1
- package/dist/connectors/index.js +1 -1
- package/dist/connectors/index.js.map +1 -1
- package/dist/connectors/messaging/base.d.ts +15 -0
- package/dist/connectors/messaging/base.js +29 -1
- package/dist/connectors/messaging/base.js.map +1 -1
- package/dist/connectors/messaging/index.d.ts +1 -0
- package/dist/connectors/messaging/index.js +1 -0
- package/dist/connectors/messaging/index.js.map +1 -1
- package/dist/connectors/messaging/session-manager.d.ts +32 -1
- package/dist/connectors/messaging/session-manager.js +43 -9
- package/dist/connectors/messaging/session-manager.js.map +1 -1
- package/dist/connectors/messaging/thread-transcript.d.ts +57 -0
- package/dist/connectors/messaging/thread-transcript.js +113 -0
- package/dist/connectors/messaging/thread-transcript.js.map +1 -0
- package/dist/connectors/messaging/types.d.ts +25 -0
- package/dist/connectors/slack/connector.d.ts +27 -0
- package/dist/connectors/slack/connector.js +52 -0
- package/dist/connectors/slack/connector.js.map +1 -1
- package/dist/cron/feedback-poll.d.ts +72 -0
- package/dist/cron/feedback-poll.js +161 -0
- package/dist/cron/feedback-poll.js.map +1 -0
- package/dist/engine/dispatcher.d.ts +1 -1
- package/dist/engine/dispatcher.js +28 -3
- package/dist/engine/dispatcher.js.map +1 -1
- package/dist/engine/feedback/ingest.d.ts +61 -0
- package/dist/engine/feedback/ingest.js +150 -0
- package/dist/engine/feedback/ingest.js.map +1 -0
- package/dist/engine/feedback/reactions.d.ts +58 -0
- package/dist/engine/feedback/reactions.js +153 -0
- package/dist/engine/feedback/reactions.js.map +1 -0
- package/dist/engine/feedback/slack.d.ts +61 -0
- package/dist/engine/feedback/slack.js +73 -0
- package/dist/engine/feedback/slack.js.map +1 -0
- package/dist/engine/github/github.d.ts +91 -0
- package/dist/engine/github/github.js +169 -3
- package/dist/engine/github/github.js.map +1 -1
- package/dist/engine/pr-decisions.d.ts +59 -2
- package/dist/engine/pr-decisions.js +147 -2
- package/dist/engine/pr-decisions.js.map +1 -1
- package/dist/engine/pr-state.d.ts +23 -0
- package/dist/engine/pr-state.js +23 -6
- package/dist/engine/pr-state.js.map +1 -1
- package/dist/engine/review-check.d.ts +23 -0
- package/dist/engine/review-check.js +52 -14
- package/dist/engine/review-check.js.map +1 -1
- package/dist/engine/router.js +7 -0
- package/dist/engine/router.js.map +1 -1
- package/dist/index.js +113 -6
- package/dist/index.js.map +1 -1
- package/dist/notify/transports/slack.d.ts +9 -0
- package/dist/notify/transports/slack.js +7 -2
- package/dist/notify/transports/slack.js.map +1 -1
- package/dist/state/db.d.ts +5 -0
- package/dist/state/db.js +5 -0
- package/dist/state/db.js.map +1 -1
- package/dist/state/feedback-store.d.ts +181 -0
- package/dist/state/feedback-store.js +345 -0
- package/dist/state/feedback-store.js.map +1 -0
- package/dist/state/migrate.js +123 -0
- package/dist/state/migrate.js.map +1 -1
- package/dist/state/workflow-run-store.d.ts +37 -9
- package/dist/state/workflow-run-store.js +41 -12
- package/dist/state/workflow-run-store.js.map +1 -1
- package/dist/telemetry/feedback.d.ts +18 -0
- package/dist/telemetry/feedback.js +115 -0
- package/dist/telemetry/feedback.js.map +1 -0
- package/dist/telemetry/index.js +8 -0
- package/dist/telemetry/index.js.map +1 -1
- package/dist/telemetry/openinference.d.ts +7 -0
- package/dist/telemetry/openinference.js +7 -0
- package/dist/telemetry/openinference.js.map +1 -1
- package/dist/workflows/handlers/post-review.d.ts +55 -0
- package/dist/workflows/handlers/post-review.js +104 -9
- package/dist/workflows/handlers/post-review.js.map +1 -1
- package/dist/workflows/runner.js +38 -1
- package/dist/workflows/runner.js.map +1 -1
- package/package.json +4 -4
- package/skills/code-review/SKILL.md +61 -9
- package/skills/pr-review/SKILL.md +69 -7
- package/skills/pr-review/references/findings-schema.md +1 -1
- package/workflows/answer.yaml +24 -3
- package/workflows/prompts/classifier.md +1 -1
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import { randomUUID } from "crypto";
|
|
2
|
+
/** Columns shared by every signal read, aliased snake → camel. */
|
|
3
|
+
const SIGNAL_COLUMNS = `
|
|
4
|
+
id, anchor_id AS anchorId, source, workflow_run_id AS workflowRunId,
|
|
5
|
+
workflow_name AS workflowName, messaging_session_id AS messagingSessionId, owner, repo,
|
|
6
|
+
issue_number AS issueNumber, emoji, score, sentiment, reactor,
|
|
7
|
+
reacted_at AS reactedAt, observed_at AS observedAt, removed_at AS removedAt,
|
|
8
|
+
exported_at AS exportedAt
|
|
9
|
+
`;
|
|
10
|
+
export class FeedbackStore {
|
|
11
|
+
db;
|
|
12
|
+
constructor(db) {
|
|
13
|
+
this.db = db;
|
|
14
|
+
}
|
|
15
|
+
// ── Anchors ────────────────────────────────────────────────────
|
|
16
|
+
/**
|
|
17
|
+
* Register (or re-register) a reactable artefact. Idempotent on
|
|
18
|
+
* `(source, channel, external_id)`: re-posting the same Slack ts, or
|
|
19
|
+
* re-discovering the same GitHub comment on a later tick, updates the
|
|
20
|
+
* attribution in place rather than forking a second anchor — which would
|
|
21
|
+
* split one comment's reactions across two rows.
|
|
22
|
+
*/
|
|
23
|
+
upsertAnchor(input) {
|
|
24
|
+
const now = new Date().toISOString();
|
|
25
|
+
const id = randomUUID();
|
|
26
|
+
this.db
|
|
27
|
+
.prepare(`INSERT INTO feedback_anchors
|
|
28
|
+
(id, source, kind, external_id, node_id, channel, owner, repo, issue_number,
|
|
29
|
+
workflow_run_id, workflow_name, messaging_session_id, created_at)
|
|
30
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
31
|
+
ON CONFLICT(source, channel, external_id) DO UPDATE SET
|
|
32
|
+
node_id = COALESCE(excluded.node_id, feedback_anchors.node_id),
|
|
33
|
+
workflow_run_id = COALESCE(excluded.workflow_run_id, feedback_anchors.workflow_run_id),
|
|
34
|
+
workflow_name = COALESCE(excluded.workflow_name, feedback_anchors.workflow_name),
|
|
35
|
+
messaging_session_id = COALESCE(excluded.messaging_session_id, feedback_anchors.messaging_session_id),
|
|
36
|
+
owner = COALESCE(excluded.owner, feedback_anchors.owner),
|
|
37
|
+
repo = COALESCE(excluded.repo, feedback_anchors.repo),
|
|
38
|
+
issue_number = COALESCE(excluded.issue_number, feedback_anchors.issue_number)`)
|
|
39
|
+
.run(id, input.source, input.kind, input.externalId, input.nodeId ?? null, channelKey(input.channel), input.owner ?? null, input.repo ?? null, input.issueNumber ?? null, input.workflowRunId ?? null, input.workflowName ?? null, input.messagingSessionId ?? null, input.createdAt ?? now);
|
|
40
|
+
// Read back rather than trusting `id`: on the conflict branch the existing
|
|
41
|
+
// row keeps its own id, and callers need the one the signals will point at.
|
|
42
|
+
return this.findAnchor(input.source, input.channel ?? null, input.externalId);
|
|
43
|
+
}
|
|
44
|
+
/** The reverse lookup a reaction hits. */
|
|
45
|
+
findAnchor(source, channel, externalId) {
|
|
46
|
+
const row = this.db
|
|
47
|
+
.prepare(`SELECT * FROM feedback_anchors
|
|
48
|
+
WHERE source = ? AND external_id = ? AND channel = ?`)
|
|
49
|
+
.get(source, externalId, channelKey(channel));
|
|
50
|
+
return row ? this.deserializeAnchor(row) : null;
|
|
51
|
+
}
|
|
52
|
+
getAnchor(id) {
|
|
53
|
+
const row = this.db
|
|
54
|
+
.prepare(`SELECT * FROM feedback_anchors WHERE id = ?`)
|
|
55
|
+
.get(id);
|
|
56
|
+
return row ? this.deserializeAnchor(row) : null;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The GitHub poller's rotation: anchors still inside the reaction window,
|
|
60
|
+
* least-recently-polled first, capped. Bounding it here rather than in the
|
|
61
|
+
* cron is what keeps the API spend a property of the data (a fixed-size
|
|
62
|
+
* working set) instead of of the schedule.
|
|
63
|
+
*/
|
|
64
|
+
anchorsToPoll(opts) {
|
|
65
|
+
const now = opts.now ?? new Date();
|
|
66
|
+
const cutoff = new Date(now.getTime() - opts.windowDays * 86_400_000).toISOString();
|
|
67
|
+
const rows = this.db
|
|
68
|
+
.prepare(`SELECT * FROM feedback_anchors
|
|
69
|
+
WHERE source = 'github' AND node_id IS NOT NULL AND created_at >= ?
|
|
70
|
+
ORDER BY last_polled_at IS NOT NULL, last_polled_at ASC
|
|
71
|
+
LIMIT ?`)
|
|
72
|
+
.all(cutoff, opts.limit);
|
|
73
|
+
return rows.map((r) => this.deserializeAnchor(r));
|
|
74
|
+
}
|
|
75
|
+
markPolled(anchorIds, at = new Date().toISOString()) {
|
|
76
|
+
if (anchorIds.length === 0)
|
|
77
|
+
return;
|
|
78
|
+
const stmt = this.db.prepare(`UPDATE feedback_anchors SET last_polled_at = ? WHERE id = ?`);
|
|
79
|
+
const tx = this.db.transaction((ids) => {
|
|
80
|
+
for (const id of ids)
|
|
81
|
+
stmt.run(at, id);
|
|
82
|
+
});
|
|
83
|
+
tx(anchorIds);
|
|
84
|
+
}
|
|
85
|
+
/** Drop anchors past the retention horizon. Signals are kept — they are the data. */
|
|
86
|
+
pruneAnchors(retentionDays, now = new Date()) {
|
|
87
|
+
const cutoff = new Date(now.getTime() - retentionDays * 86_400_000).toISOString();
|
|
88
|
+
const res = this.db
|
|
89
|
+
.prepare(`DELETE FROM feedback_anchors WHERE created_at < ?`)
|
|
90
|
+
.run(cutoff);
|
|
91
|
+
return res.changes;
|
|
92
|
+
}
|
|
93
|
+
// ── Signals ────────────────────────────────────────────────────
|
|
94
|
+
/**
|
|
95
|
+
* Record one reaction. Returns the signal when it is NEW (or a revival of a
|
|
96
|
+
* retracted one), and null when it was already known — so the caller can emit
|
|
97
|
+
* telemetry exactly once without tracking state itself.
|
|
98
|
+
*/
|
|
99
|
+
recordSignal(input) {
|
|
100
|
+
const { anchor } = input;
|
|
101
|
+
const now = new Date().toISOString();
|
|
102
|
+
const existing = this.db
|
|
103
|
+
.prepare(`SELECT ${SIGNAL_COLUMNS} FROM feedback_signals
|
|
104
|
+
WHERE anchor_id = ? AND reactor IS ? AND emoji = ?`)
|
|
105
|
+
.get(anchor.id, input.reactor ?? null, input.emoji);
|
|
106
|
+
if (existing) {
|
|
107
|
+
// Already live — nothing happened.
|
|
108
|
+
if (!existing.removedAt)
|
|
109
|
+
return null;
|
|
110
|
+
// Reacted, un-reacted, reacted again. Revive the row and let it export
|
|
111
|
+
// again: the person changed their mind twice and both are real events.
|
|
112
|
+
this.db
|
|
113
|
+
.prepare(`UPDATE feedback_signals
|
|
114
|
+
SET removed_at = NULL, observed_at = ?, reacted_at = ?, exported_at = NULL
|
|
115
|
+
WHERE id = ?`)
|
|
116
|
+
.run(now, input.reactedAt ?? now, existing.id);
|
|
117
|
+
return { ...existing, removedAt: null, observedAt: now, exportedAt: null };
|
|
118
|
+
}
|
|
119
|
+
const signal = {
|
|
120
|
+
id: randomUUID(),
|
|
121
|
+
anchorId: anchor.id,
|
|
122
|
+
source: anchor.source,
|
|
123
|
+
workflowRunId: anchor.workflowRunId,
|
|
124
|
+
workflowName: anchor.workflowName,
|
|
125
|
+
messagingSessionId: anchor.messagingSessionId,
|
|
126
|
+
owner: anchor.owner,
|
|
127
|
+
repo: anchor.repo,
|
|
128
|
+
issueNumber: anchor.issueNumber,
|
|
129
|
+
emoji: input.emoji,
|
|
130
|
+
score: input.score,
|
|
131
|
+
sentiment: input.sentiment,
|
|
132
|
+
reactor: input.reactor ?? null,
|
|
133
|
+
reactedAt: input.reactedAt ?? now,
|
|
134
|
+
observedAt: now,
|
|
135
|
+
removedAt: null,
|
|
136
|
+
exportedAt: null,
|
|
137
|
+
};
|
|
138
|
+
this.db
|
|
139
|
+
.prepare(`INSERT INTO feedback_signals
|
|
140
|
+
(id, anchor_id, source, workflow_run_id, workflow_name, messaging_session_id, owner, repo,
|
|
141
|
+
issue_number, emoji, score, sentiment, reactor, reacted_at, observed_at)
|
|
142
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
143
|
+
.run(signal.id, signal.anchorId, signal.source, signal.workflowRunId, signal.workflowName, signal.messagingSessionId, signal.owner, signal.repo, signal.issueNumber, signal.emoji, signal.score, signal.sentiment, signal.reactor, signal.reactedAt, signal.observedAt);
|
|
144
|
+
return signal;
|
|
145
|
+
}
|
|
146
|
+
/** Retract one reaction. Returns true when a live row was actually retracted. */
|
|
147
|
+
removeSignal(anchorId, reactor, emoji, at) {
|
|
148
|
+
const res = this.db
|
|
149
|
+
.prepare(`UPDATE feedback_signals SET removed_at = ?
|
|
150
|
+
WHERE anchor_id = ? AND reactor IS ? AND emoji = ? AND removed_at IS NULL`)
|
|
151
|
+
.run(at ?? new Date().toISOString(), anchorId, reactor, emoji);
|
|
152
|
+
return res.changes > 0;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Retract every live signal on an anchor that is NOT in `keep`. The GitHub
|
|
156
|
+
* poller's reconciliation step: a reaction that has disappeared between two
|
|
157
|
+
* batches has no event to announce it, so absence from the fresh read is the
|
|
158
|
+
* only evidence there is.
|
|
159
|
+
*/
|
|
160
|
+
reconcileAnchor(anchorId, keep) {
|
|
161
|
+
const live = this.db
|
|
162
|
+
.prepare(`SELECT id, reactor, emoji FROM feedback_signals
|
|
163
|
+
WHERE anchor_id = ? AND removed_at IS NULL`)
|
|
164
|
+
.all(anchorId);
|
|
165
|
+
const keepKeys = new Set(keep.map((k) => `${k.reactor ?? ""}${k.emoji}`));
|
|
166
|
+
const stale = live.filter((s) => !keepKeys.has(`${s.reactor ?? ""}${s.emoji}`));
|
|
167
|
+
if (stale.length === 0)
|
|
168
|
+
return 0;
|
|
169
|
+
const now = new Date().toISOString();
|
|
170
|
+
const stmt = this.db.prepare(`UPDATE feedback_signals SET removed_at = ? WHERE id = ?`);
|
|
171
|
+
const tx = this.db.transaction((rows) => {
|
|
172
|
+
for (const r of rows)
|
|
173
|
+
stmt.run(now, r.id);
|
|
174
|
+
});
|
|
175
|
+
tx(stale);
|
|
176
|
+
return stale.length;
|
|
177
|
+
}
|
|
178
|
+
// ── Reads ──────────────────────────────────────────────────────
|
|
179
|
+
list(opts = {}) {
|
|
180
|
+
const where = [];
|
|
181
|
+
const params = [];
|
|
182
|
+
if (!opts.includeRemoved)
|
|
183
|
+
where.push("removed_at IS NULL");
|
|
184
|
+
if (opts.workflowName) {
|
|
185
|
+
where.push("workflow_name = ?");
|
|
186
|
+
params.push(opts.workflowName);
|
|
187
|
+
}
|
|
188
|
+
if (opts.repo) {
|
|
189
|
+
where.push("repo = ?");
|
|
190
|
+
params.push(opts.repo);
|
|
191
|
+
}
|
|
192
|
+
if (opts.source) {
|
|
193
|
+
where.push("source = ?");
|
|
194
|
+
params.push(opts.source);
|
|
195
|
+
}
|
|
196
|
+
if (opts.sinceIso) {
|
|
197
|
+
where.push("observed_at >= ?");
|
|
198
|
+
params.push(opts.sinceIso);
|
|
199
|
+
}
|
|
200
|
+
const clause = where.length ? `WHERE ${where.join(" AND ")}` : "";
|
|
201
|
+
const total = this.db
|
|
202
|
+
.prepare(`SELECT COUNT(*) AS n FROM feedback_signals ${clause}`)
|
|
203
|
+
.get(...params).n;
|
|
204
|
+
const signals = this.db
|
|
205
|
+
.prepare(`SELECT ${SIGNAL_COLUMNS} FROM feedback_signals ${clause}
|
|
206
|
+
ORDER BY observed_at DESC LIMIT ? OFFSET ?`)
|
|
207
|
+
.all(...params, opts.limit ?? 50, opts.offset ?? 0);
|
|
208
|
+
return { signals, total };
|
|
209
|
+
}
|
|
210
|
+
/** Every live signal on one run — powers the run-detail badge. */
|
|
211
|
+
forRun(workflowRunId) {
|
|
212
|
+
return this.db
|
|
213
|
+
.prepare(`SELECT ${SIGNAL_COLUMNS} FROM feedback_signals
|
|
214
|
+
WHERE workflow_run_id = ? AND removed_at IS NULL
|
|
215
|
+
ORDER BY observed_at ASC`)
|
|
216
|
+
.all(workflowRunId);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Per-workflow standing over the last N days.
|
|
220
|
+
*
|
|
221
|
+
* `averageScore` deliberately averages only over SCORED signals (`score != 0`).
|
|
222
|
+
* 👀 is in the vocabulary at 0 so we can see engagement, but letting it into
|
|
223
|
+
* the mean would make a well-received workflow look mediocre purely because
|
|
224
|
+
* people also glanced at it.
|
|
225
|
+
*/
|
|
226
|
+
summaryByWorkflow(days, now = new Date()) {
|
|
227
|
+
const since = new Date(now.getTime() - days * 86_400_000).toISOString();
|
|
228
|
+
const rows = this.db
|
|
229
|
+
.prepare(`SELECT
|
|
230
|
+
workflow_name AS workflowName,
|
|
231
|
+
COUNT(*) AS total,
|
|
232
|
+
SUM(CASE WHEN score > 0 THEN 1 ELSE 0 END) AS positive,
|
|
233
|
+
SUM(CASE WHEN score < 0 THEN 1 ELSE 0 END) AS negative,
|
|
234
|
+
SUM(CASE WHEN score = 0 THEN 1 ELSE 0 END) AS neutral,
|
|
235
|
+
COALESCE(AVG(CASE WHEN score != 0 THEN score END), 0) AS averageScore
|
|
236
|
+
FROM feedback_signals
|
|
237
|
+
WHERE removed_at IS NULL AND observed_at >= ?
|
|
238
|
+
GROUP BY workflow_name
|
|
239
|
+
ORDER BY total DESC`)
|
|
240
|
+
.all(since);
|
|
241
|
+
return rows.map((r) => ({ ...r, averageScore: round2(r.averageScore) }));
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Daily score series, zero-filled across the whole window so a chart shows
|
|
245
|
+
* gaps as gaps rather than closing over them. Same UTC key generation as
|
|
246
|
+
* `ExecutionStore.dailyStats`.
|
|
247
|
+
*/
|
|
248
|
+
dailyScores(days, workflowName, now = new Date()) {
|
|
249
|
+
const startUtc = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() - (days - 1)));
|
|
250
|
+
const dateKeys = [];
|
|
251
|
+
for (let i = 0; i < days; i++) {
|
|
252
|
+
const d = new Date(startUtc);
|
|
253
|
+
d.setUTCDate(startUtc.getUTCDate() + i);
|
|
254
|
+
dateKeys.push(d.toISOString().slice(0, 10));
|
|
255
|
+
}
|
|
256
|
+
const params = [dateKeys[0]];
|
|
257
|
+
let filter = "";
|
|
258
|
+
if (workflowName) {
|
|
259
|
+
filter = " AND workflow_name = ?";
|
|
260
|
+
params.push(workflowName);
|
|
261
|
+
}
|
|
262
|
+
const rows = this.db
|
|
263
|
+
.prepare(`SELECT
|
|
264
|
+
date(observed_at) AS date,
|
|
265
|
+
COUNT(*) AS total,
|
|
266
|
+
SUM(CASE WHEN score > 0 THEN 1 ELSE 0 END) AS positive,
|
|
267
|
+
SUM(CASE WHEN score < 0 THEN 1 ELSE 0 END) AS negative,
|
|
268
|
+
COALESCE(AVG(CASE WHEN score != 0 THEN score END), 0) AS averageScore
|
|
269
|
+
FROM feedback_signals
|
|
270
|
+
WHERE removed_at IS NULL AND date(observed_at) >= ?${filter}
|
|
271
|
+
GROUP BY date(observed_at)`)
|
|
272
|
+
.all(...params);
|
|
273
|
+
const byDate = new Map(rows.map((r) => [r.date, r]));
|
|
274
|
+
return dateKeys.map((date) => {
|
|
275
|
+
const row = byDate.get(date);
|
|
276
|
+
return row
|
|
277
|
+
? { ...row, averageScore: round2(row.averageScore) }
|
|
278
|
+
: { date, total: 0, positive: 0, negative: 0, averageScore: 0 };
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
// ── OTel export watermark ──────────────────────────────────────
|
|
282
|
+
/**
|
|
283
|
+
* Signals not yet exported to OTel, oldest first.
|
|
284
|
+
*
|
|
285
|
+
* **Retracted signals are excluded.** A reaction added and then withdrawn
|
|
286
|
+
* while telemetry was off has no `exported_at` and a `removed_at`; exporting
|
|
287
|
+
* it on the backlog drain would put a +1 the person explicitly took back onto
|
|
288
|
+
* the trace, with nothing to say it was withdrawn. The live path never has
|
|
289
|
+
* this problem (a retraction can't reach `exportSignal`), so the gap was
|
|
290
|
+
* only ever reachable through the backfill.
|
|
291
|
+
*/
|
|
292
|
+
pendingExport(limit = 200) {
|
|
293
|
+
return this.db
|
|
294
|
+
.prepare(`SELECT ${SIGNAL_COLUMNS} FROM feedback_signals
|
|
295
|
+
WHERE exported_at IS NULL AND removed_at IS NULL
|
|
296
|
+
ORDER BY observed_at ASC LIMIT ?`)
|
|
297
|
+
.all(limit);
|
|
298
|
+
}
|
|
299
|
+
markExported(ids, at = new Date().toISOString()) {
|
|
300
|
+
if (ids.length === 0)
|
|
301
|
+
return;
|
|
302
|
+
const stmt = this.db.prepare(`UPDATE feedback_signals SET exported_at = ? WHERE id = ?`);
|
|
303
|
+
const tx = this.db.transaction((rows) => {
|
|
304
|
+
for (const id of rows)
|
|
305
|
+
stmt.run(at, id);
|
|
306
|
+
});
|
|
307
|
+
tx(ids);
|
|
308
|
+
}
|
|
309
|
+
// ── Deserialization ────────────────────────────────────────────
|
|
310
|
+
deserializeAnchor(row) {
|
|
311
|
+
return {
|
|
312
|
+
id: row.id,
|
|
313
|
+
source: row.source,
|
|
314
|
+
kind: row.kind,
|
|
315
|
+
externalId: row.external_id,
|
|
316
|
+
nodeId: row.node_id ?? null,
|
|
317
|
+
channel: row.channel || null,
|
|
318
|
+
owner: row.owner ?? null,
|
|
319
|
+
repo: row.repo ?? null,
|
|
320
|
+
issueNumber: row.issue_number ?? null,
|
|
321
|
+
workflowRunId: row.workflow_run_id ?? null,
|
|
322
|
+
workflowName: row.workflow_name ?? null,
|
|
323
|
+
messagingSessionId: row.messaging_session_id ?? null,
|
|
324
|
+
createdAt: row.created_at,
|
|
325
|
+
lastPolledAt: row.last_polled_at ?? null,
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
function round2(n) {
|
|
330
|
+
return Math.round(n * 100) / 100;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* The stored form of `channel`: '' for a surface that has none (GitHub).
|
|
334
|
+
*
|
|
335
|
+
* SQLite treats NULLs as DISTINCT in a UNIQUE constraint, so a nullable channel
|
|
336
|
+
* makes `UNIQUE(source, channel, external_id)` — and the `ON CONFLICT` that
|
|
337
|
+
* targets it — silently inoperative for every GitHub anchor. Normalizing here
|
|
338
|
+
* keeps that one constraint honest for both surfaces without a second upsert
|
|
339
|
+
* path; {@link FeedbackStore.deserializeAnchor} maps it back to null so the
|
|
340
|
+
* type callers see is still `string | null`.
|
|
341
|
+
*/
|
|
342
|
+
function channelKey(channel) {
|
|
343
|
+
return channel ?? "";
|
|
344
|
+
}
|
|
345
|
+
//# sourceMappingURL=feedback-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feedback-store.js","sourceRoot":"","sources":["../../src/state/feedback-store.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAmHpC,kEAAkE;AAClE,MAAM,cAAc,GAAG;;;;;;CAMtB,CAAC;AAEF,MAAM,OAAO,aAAa;IACJ;IAApB,YAAoB,EAAqB;QAArB,OAAE,GAAF,EAAE,CAAmB;IAAG,CAAC;IAE7C,kEAAkE;IAElE;;;;;;OAMG;IACH,YAAY,CAAC,KAA0B;QACrC,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QACrC,MAAM,EAAE,GAAG,UAAU,EAAE,CAAC;QACxB,IAAI,CAAC,EAAE;aACJ,OAAO,CACN;;;;;;;;;;;yFAWiF,CAClF;aACA,GAAG,CACF,EAAE,EACF,KAAK,CAAC,MAAM,EACZ,KAAK,CAAC,IAAI,EACV,KAAK,CAAC,UAAU,EAChB,KAAK,CAAC,MAAM,IAAI,IAAI,EACpB,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,EACzB,KAAK,CAAC,KAAK,IAAI,IAAI,EACnB,KAAK,CAAC,IAAI,IAAI,IAAI,EAClB,KAAK,CAAC,WAAW,IAAI,IAAI,EACzB,KAAK,CAAC,aAAa,IAAI,IAA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AAkE;IAE1D,iBAAiB,CAAC,GAA4B;QACpD,OAAO;YACL,EAAE,EAAE,GAAG,CAAC,EAAY;YACpB,MAAM,EAAE,GAAG,CAAC,MAAwB;YACpC,IAAI,EAAE,GAAG,CAAC,IAA0B;YACpC,UAAU,EAAE,GAAG,CAAC,WAAqB;YACrC,MAAM,EAAG,GAAG,CAAC,OAAyB,IAAI,IAAI;YAC9C,OAAO,EAAG,GAAG,CAAC,OAAyB,IAAI,IAAI;YAC/C,KAAK,EAAG,GAAG,CAAC,KAAuB,IAAI,IAAI;YAC3C,IAAI,EAAG,GAAG,CAAC,IAAsB,IAAI,IAAI;YACzC,WAAW,EAAG,GAAG,CAAC,YAA8B,IAAI,IAAI;YACxD,aAAa,EAAG,GAAG,CAAC,eAAiC,IAAI,IAAI;YAC7D,YAAY,EAAG,GAAG,CAAC,aAA+B,IAAI,IAAI;YAC1D,kBAAkB,EAAG,GAAG,CAAC,oBAAsC,IAAI,IAAI;YACvE,SAAS,EAAE,GAAG,CAAC,UAAoB;YACnC,YAAY,EAAG,GAAG,CAAC,cAAgC,IAAI,IAAI;SAC5D,CAAC;IACJ,CAAC;CACF;AAED,SAAS,MAAM,CAAC,CAAS;IACvB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;AACnC,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,UAAU,CAAC,OAAkC;IACpD,OAAO,OAAO,IAAI,EAAE,CAAC;AACvB,CAAC"}
|
package/dist/state/migrate.js
CHANGED
|
@@ -108,6 +108,102 @@ export function migrate(db) {
|
|
|
108
108
|
CREATE INDEX IF NOT EXISTS idx_users_login ON users(login);
|
|
109
109
|
CREATE INDEX IF NOT EXISTS idx_users_email ON users(email);
|
|
110
110
|
CREATE INDEX IF NOT EXISTS idx_users_slack ON users(slack_user_id);
|
|
111
|
+
|
|
112
|
+
-- Feedback signals (issue #255) — a 👍/👎 on something the bot wrote, scored
|
|
113
|
+
-- against the run that wrote it. Two tables, because a reaction names a
|
|
114
|
+
-- MESSAGE and we need a run:
|
|
115
|
+
--
|
|
116
|
+
-- feedback_anchors one row per reactable artefact the bot posted, and the
|
|
117
|
+
-- run it came from. Written when we POST (Slack, where
|
|
118
|
+
-- the ts is only ever known at send time) or when a run
|
|
119
|
+
-- finishes (GitHub discovery).
|
|
120
|
+
-- feedback_signals one row per (anchor, reactor, emoji).
|
|
121
|
+
--
|
|
122
|
+
-- Surface-agnostic from the start: \`source\` discriminates slack/github so a
|
|
123
|
+
-- single query averages across both, and the GitHub poller adds rows rather
|
|
124
|
+
-- than columns.
|
|
125
|
+
CREATE TABLE IF NOT EXISTS feedback_anchors (
|
|
126
|
+
id TEXT PRIMARY KEY, -- randomUUID
|
|
127
|
+
source TEXT NOT NULL, -- slack | github
|
|
128
|
+
kind TEXT NOT NULL, -- slack_message | issue_comment | review_comment | issue
|
|
129
|
+
-- Slack message ts, or the GitHub comment/issue id as a string. Kept TEXT
|
|
130
|
+
-- for both: a Slack ts ("1712000000.000100") is not a number, and a
|
|
131
|
+
-- GitHub id read back as a float would lose precision.
|
|
132
|
+
external_id TEXT NOT NULL,
|
|
133
|
+
-- GitHub GraphQL global id. The batched reactions query keys on this, so
|
|
134
|
+
-- the poller never has to re-resolve an id it already saw.
|
|
135
|
+
node_id TEXT,
|
|
136
|
+
-- Slack channel id. GitHub has no channel and stores the empty string
|
|
137
|
+
-- rather than NULL, because **SQLite treats NULLs as DISTINCT in a UNIQUE
|
|
138
|
+
-- constraint** — with NULL here, the UNIQUE below (and the ON CONFLICT
|
|
139
|
+
-- that targets it) is silently inoperative for every GitHub anchor, and
|
|
140
|
+
-- re-discovering the same comment forks a second row. A sentinel keeps
|
|
141
|
+
-- ONE uniqueness rule and ONE upsert path for both surfaces; the store
|
|
142
|
+
-- maps '' back to null at its boundary so callers still see
|
|
143
|
+
-- \`channel: string | null\`.
|
|
144
|
+
channel TEXT NOT NULL DEFAULT '',
|
|
145
|
+
owner TEXT,
|
|
146
|
+
repo TEXT,
|
|
147
|
+
issue_number INTEGER,
|
|
148
|
+
-- The attribution. Null is legal and deliberate: a bot comment we cannot
|
|
149
|
+
-- tie to a run is still worth recording — dropping it would silently lose
|
|
150
|
+
-- the reaction rather than the run.
|
|
151
|
+
workflow_run_id TEXT,
|
|
152
|
+
workflow_name TEXT,
|
|
153
|
+
-- The Slack THREAD's messaging session, for a chat turn — which has no
|
|
154
|
+
-- workflow run. Deliberately not called \`execution_id\`: it is
|
|
155
|
+
-- \`messaging_sessions.id\`, which is what an \`executions\` row for a chat
|
|
156
|
+
-- turn carries as its \`trigger_id\`, NOT an \`executions.id\`.
|
|
157
|
+
messaging_session_id TEXT,
|
|
158
|
+
created_at TEXT NOT NULL, -- when the bot posted it
|
|
159
|
+
last_polled_at TEXT, -- github only; slack arrives live
|
|
160
|
+
UNIQUE(source, channel, external_id)
|
|
161
|
+
);
|
|
162
|
+
-- The reverse lookup a Slack reaction hits: (channel, ts) → anchor.
|
|
163
|
+
CREATE INDEX IF NOT EXISTS idx_feedback_anchors_lookup
|
|
164
|
+
ON feedback_anchors(source, channel, external_id);
|
|
165
|
+
CREATE INDEX IF NOT EXISTS idx_feedback_anchors_run
|
|
166
|
+
ON feedback_anchors(workflow_run_id);
|
|
167
|
+
-- The poller's rotation: least-recently-polled first, within the window.
|
|
168
|
+
CREATE INDEX IF NOT EXISTS idx_feedback_anchors_poll
|
|
169
|
+
ON feedback_anchors(source, created_at, last_polled_at);
|
|
170
|
+
|
|
171
|
+
CREATE TABLE IF NOT EXISTS feedback_signals (
|
|
172
|
+
id TEXT PRIMARY KEY,
|
|
173
|
+
anchor_id TEXT NOT NULL,
|
|
174
|
+
-- Denormalized from the anchor so every analytics query is one table.
|
|
175
|
+
-- These never change for a given anchor, so there is nothing to keep in
|
|
176
|
+
-- sync — the anchor's attribution is fixed the moment it is created.
|
|
177
|
+
source TEXT NOT NULL,
|
|
178
|
+
workflow_run_id TEXT,
|
|
179
|
+
workflow_name TEXT,
|
|
180
|
+
messaging_session_id TEXT,
|
|
181
|
+
owner TEXT,
|
|
182
|
+
repo TEXT,
|
|
183
|
+
issue_number INTEGER,
|
|
184
|
+
emoji TEXT NOT NULL, -- canonical name (see engine/feedback/reactions.ts)
|
|
185
|
+
score INTEGER NOT NULL, -- -2..+2; 0 means "recorded, not scored"
|
|
186
|
+
sentiment TEXT NOT NULL,
|
|
187
|
+
reactor TEXT, -- GitHub login / Slack user id
|
|
188
|
+
reacted_at TEXT, -- when they reacted, when known
|
|
189
|
+
observed_at TEXT NOT NULL, -- when WE saw it
|
|
190
|
+
-- Set when the reaction is taken away. Retracting rather than deleting
|
|
191
|
+
-- keeps "somebody thumbed this and then thought better of it" visible,
|
|
192
|
+
-- which is itself a signal; every score query filters on IS NULL.
|
|
193
|
+
removed_at TEXT,
|
|
194
|
+
-- OTel export watermark. Null means not yet exported, so a restart can't
|
|
195
|
+
-- double-emit and signals recorded while telemetry was off can be
|
|
196
|
+
-- backfilled later.
|
|
197
|
+
exported_at TEXT,
|
|
198
|
+
UNIQUE(anchor_id, reactor, emoji)
|
|
199
|
+
);
|
|
200
|
+
CREATE INDEX IF NOT EXISTS idx_feedback_signals_anchor ON feedback_signals(anchor_id);
|
|
201
|
+
CREATE INDEX IF NOT EXISTS idx_feedback_signals_run ON feedback_signals(workflow_run_id);
|
|
202
|
+
CREATE INDEX IF NOT EXISTS idx_feedback_signals_observed
|
|
203
|
+
ON feedback_signals(observed_at DESC);
|
|
204
|
+
CREATE INDEX IF NOT EXISTS idx_feedback_signals_workflow
|
|
205
|
+
ON feedback_signals(workflow_name, observed_at DESC);
|
|
206
|
+
CREATE INDEX IF NOT EXISTS idx_feedback_signals_export ON feedback_signals(exported_at);
|
|
111
207
|
`);
|
|
112
208
|
// Actor logging (issue #205): who triggered a run and how. Additive on both
|
|
113
209
|
// the append-only `executions` ledger and the `workflow_runs` aggregate. The
|
|
@@ -163,6 +259,33 @@ export function migrate(db) {
|
|
|
163
259
|
catch {
|
|
164
260
|
// Column already exists — ignore
|
|
165
261
|
}
|
|
262
|
+
// `feedback_anchors.channel` moved from nullable to a '' sentinel (issue
|
|
263
|
+
// #255) so its UNIQUE actually binds for GitHub — see the CREATE TABLE above.
|
|
264
|
+
// `CREATE TABLE IF NOT EXISTS` can't restate a column, so backfill any rows
|
|
265
|
+
// written by a build that predates the fix. Guarded like every ALTER here: on
|
|
266
|
+
// a table that already accumulated NULL-channel duplicates the UPDATE trips
|
|
267
|
+
// the constraint, and leaving those rows alone is strictly better than
|
|
268
|
+
// failing boot over a cache of reaction anchors.
|
|
269
|
+
try {
|
|
270
|
+
db.exec(`UPDATE feedback_anchors SET channel = '' WHERE channel IS NULL`);
|
|
271
|
+
}
|
|
272
|
+
catch {
|
|
273
|
+
// Pre-existing duplicates — they age out via `retentionDays`.
|
|
274
|
+
}
|
|
275
|
+
// The run's OTel trace/span context (issue #255). A feedback signal can
|
|
276
|
+
// arrive days after the run finished and its span closed, so the only way to
|
|
277
|
+
// put the score on the trace it grades is to remember where that trace was.
|
|
278
|
+
// Captured by the observability adapter in `src/workflows/runner.ts` when the
|
|
279
|
+
// `lastlight.workflow.run` span opens; null whenever telemetry was disabled,
|
|
280
|
+
// in which case the signal exports as its own root span instead.
|
|
281
|
+
for (const col of ["trace_id TEXT", "span_id TEXT"]) {
|
|
282
|
+
try {
|
|
283
|
+
db.exec(`ALTER TABLE workflow_runs ADD COLUMN ${col}`);
|
|
284
|
+
}
|
|
285
|
+
catch {
|
|
286
|
+
// Column already exists — ignore
|
|
287
|
+
}
|
|
288
|
+
}
|
|
166
289
|
// Gate flavor: 'approve' (explicit approve/reject) vs 'reply' (resolves
|
|
167
290
|
// on any free-form reply in the same thread — used by the socratic
|
|
168
291
|
// explore loop).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrate.js","sourceRoot":"","sources":["../../src/state/migrate.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,OAAO,CAAC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mD,CAAC,CAAC;IAC/D,CAAC;IAAC,MAAM,CAAC;QACP,iCAAiC;IACnC,CAAC;IAED,kEAAkE;IAClE,sEAAsE;IACtE,yEAAyE;IACzE,KAAK,MAAM,GAAG,IAAI;QAChB,eAAe;QACf,sBAAsB;QACtB,qCAAqC;QACrC,iCAAiC;QACjC,uBAAuB;QACvB,yBAAyB;QACzB,kBAAkB;QAClB,gEAAgE;QAChE,kEAAkE;QAClE,gEAAgE;QAChE,oDAAoD;QACpD,sBAAsB;QACtB,iEAAiE;QACjE,+DAA+D;QAC/D,gEAAgE;QAChE,8DAA8D;QAC9D,2DAA2D;QAC3D,kBAAkB;QAClB,8DAA8D;QAC9D,kEAAkE;QAClE,uEAAuE;QACvE,uBAAuB;QACvB,sEAAsE;QACtE,sEAAsE;QACtE,uEAAuE;QACvE,oBAAoB;KACrB,EAAE,CAAC;QACF,IAAI,CAAC;YACH,EAAE,CAAC,IAAI,CAAC,qCAAqC,GAAG,EAAE,CAAC,CAAC;QACtD,CAAC;QAAC,MAAM,CAAC;YACP,iCAAiC;QACnC,CAAC;IACH,CAAC;IACD,IAAI,CAAC;QACH,EAAE,CAAC,IAAI,CACL,8FAA8F,CAC/F,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,gCAAgC;IAClC,CAAC;AACH,CAAC"}
|
|
@@ -47,6 +47,15 @@ export interface WorkflowRun {
|
|
|
47
47
|
startedAt: string;
|
|
48
48
|
updatedAt: string;
|
|
49
49
|
finishedAt?: string;
|
|
50
|
+
/**
|
|
51
|
+
* The OTel trace this run was exported under (issue #255). A feedback signal
|
|
52
|
+
* can land days after the run's span closed, so remembering where the trace
|
|
53
|
+
* was is the only way to hang the score on the trace it grades rather than a
|
|
54
|
+
* disconnected one. Absent whenever telemetry was disabled during the run.
|
|
55
|
+
*/
|
|
56
|
+
traceId?: string;
|
|
57
|
+
/** The `lastlight.workflow.run` span id — the parent a feedback span attaches to. */
|
|
58
|
+
spanId?: string;
|
|
50
59
|
/**
|
|
51
60
|
* Rolled-up totals across the run's executions (SUM of `cost_usd` and
|
|
52
61
|
* input+output+cache-read tokens). Populated only by {@link WorkflowRunStore.list}
|
|
@@ -88,8 +97,13 @@ export interface PhaseMarker {
|
|
|
88
97
|
/**
|
|
89
98
|
* Notified once a run reaches a TERMINAL status, whichever path took it there.
|
|
90
99
|
*
|
|
91
|
-
*
|
|
92
|
-
* (`src/engine/review-check.ts`)
|
|
100
|
+
* There are two consumers: the `last-light/review` check run
|
|
101
|
+
* (`src/engine/review-check.ts`) and the GitHub feedback-anchor discovery of
|
|
102
|
+
* issue #255 — which is why observers are a LIST. They were a single slot
|
|
103
|
+
* originally, and a second `setTerminalObserver` call would have silently
|
|
104
|
+
* displaced the review check rather than failing loudly.
|
|
105
|
+
*
|
|
106
|
+
* 09-state-machine.md → S2 found that check
|
|
93
107
|
* being completed inside a `.then()` chained onto an in-memory promise in
|
|
94
108
|
* `dispatcher.ts` — so it stranded `in_progress` on every server restart
|
|
95
109
|
* mid-review (i.e. **every deploy**), every queued-then-resumed run, every
|
|
@@ -102,22 +116,24 @@ export interface PhaseMarker {
|
|
|
102
116
|
*
|
|
103
117
|
* Contract: **synchronous, never throws, never re-enters the store.** It is
|
|
104
118
|
* called after the row is written (outside any transaction), and an
|
|
105
|
-
* implementation that needs I/O fires it and returns.
|
|
119
|
+
* implementation that needs I/O fires it and returns. One observer throwing
|
|
120
|
+
* does not stop the others.
|
|
106
121
|
*/
|
|
107
122
|
export type TerminalRunObserver = (run: WorkflowRun, status: "succeeded" | "failed" | "cancelled") => void;
|
|
108
123
|
export declare class WorkflowRunStore {
|
|
109
124
|
private db;
|
|
110
125
|
private approvals;
|
|
111
|
-
private
|
|
126
|
+
private terminalObservers;
|
|
112
127
|
constructor(db: Database.Database, deps: {
|
|
113
128
|
approvals: ApprovalStore;
|
|
114
129
|
});
|
|
115
|
-
/**
|
|
116
|
-
|
|
130
|
+
/** Add a {@link TerminalRunObserver}. Wired at boot; order is registration order. */
|
|
131
|
+
addTerminalObserver(fn: TerminalRunObserver): void;
|
|
117
132
|
/**
|
|
118
|
-
* Fire the terminal
|
|
119
|
-
* everything: a terminal transition is already persisted by the
|
|
120
|
-
* here,
|
|
133
|
+
* Fire the terminal observers for a row that has just been written. Swallows
|
|
134
|
+
* everything, per observer: a terminal transition is already persisted by the
|
|
135
|
+
* time we get here, no projection of it may undo that, and one projection
|
|
136
|
+
* failing must not cost the others their notification.
|
|
121
137
|
*/
|
|
122
138
|
private notifyTerminal;
|
|
123
139
|
/** Create a new workflow run record */
|
|
@@ -132,6 +148,18 @@ export declare class WorkflowRunStore {
|
|
|
132
148
|
* makes `JSON.stringify` throw mid-transaction.
|
|
133
149
|
*/
|
|
134
150
|
mergeScratch(id: string, patch: Record<string, unknown>): void;
|
|
151
|
+
/**
|
|
152
|
+
* Remember which OTel trace this run is being exported under (issue #255).
|
|
153
|
+
*
|
|
154
|
+
* Deliberately NOT touching `updated_at`: this is bookkeeping about the run,
|
|
155
|
+
* not activity on it, and the liveness checks that read `updated_at` would
|
|
156
|
+
* otherwise see a heartbeat the run never produced.
|
|
157
|
+
*
|
|
158
|
+
* Write-once in practice (the run span opens exactly once), and harmless if
|
|
159
|
+
* repeated — a resume re-opens a span under a new trace, and the newest trace
|
|
160
|
+
* is the right one for a signal arriving now.
|
|
161
|
+
*/
|
|
162
|
+
setTraceContext(id: string, traceId: string, spanId: string): void;
|
|
135
163
|
/**
|
|
136
164
|
* Update the current phase and append to phase history. This is the single
|
|
137
165
|
* seam through which all phase-history writes flow (issue #97 defers the
|