lastlight-core 0.41.0 → 0.42.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/config/default.yaml +47 -0
- package/dist/admin/board-cache.d.ts +5 -0
- package/dist/admin/board-cache.js +14 -0
- package/dist/admin/board-cache.js.map +1 -1
- package/dist/admin/board-stream.d.ts +5 -7
- package/dist/admin/board-stream.js +2 -5
- package/dist/admin/board-stream.js.map +1 -1
- package/dist/admin/board.d.ts +12 -0
- package/dist/admin/board.js +19 -2
- package/dist/admin/board.js.map +1 -1
- package/dist/admin/change-stream.d.ts +33 -0
- package/dist/admin/change-stream.js +75 -0
- package/dist/admin/change-stream.js.map +1 -0
- package/dist/admin/chat-session-reader.d.ts +2 -2
- package/dist/admin/chat-session-reader.js +28 -28
- package/dist/admin/chat-session-reader.js.map +1 -1
- package/dist/admin/index.js +3 -3
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/routes.js +89 -74
- package/dist/admin/routes.js.map +1 -1
- package/dist/admin/sessions.d.ts +52 -37
- package/dist/admin/sessions.js +101 -182
- package/dist/admin/sessions.js.map +1 -1
- package/dist/admin/transcript-index.d.ts +25 -0
- package/dist/admin/transcript-index.js +26 -0
- package/dist/admin/transcript-index.js.map +1 -0
- package/dist/config/config.d.ts +53 -0
- package/dist/config/config.js +118 -1
- package/dist/config/config.js.map +1 -1
- package/dist/engine/agent-executor.d.ts +2 -2
- package/dist/engine/executors/orchestrator.d.ts +4 -3
- package/dist/engine/executors/orchestrator.js +8 -6
- package/dist/engine/executors/orchestrator.js.map +1 -1
- package/dist/engine/executors/shared.d.ts +15 -1
- package/dist/engine/executors/shared.js +32 -5
- package/dist/engine/executors/shared.js.map +1 -1
- package/dist/engine/jira/adf.d.ts +27 -0
- package/dist/engine/jira/adf.js +225 -0
- package/dist/engine/jira/adf.js.map +1 -0
- package/dist/engine/jira/client.d.ts +99 -0
- package/dist/engine/jira/client.js +245 -0
- package/dist/engine/jira/client.js.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/sandbox/egress-allowlist.d.ts +20 -3
- package/dist/sandbox/egress-allowlist.js +22 -3
- package/dist/sandbox/egress-allowlist.js.map +1 -1
- package/dist/sandbox/sandbox.js +9 -2
- package/dist/sandbox/sandbox.js.map +1 -1
- package/dist/sandbox/smol.d.ts +1 -1
- package/dist/sandbox/smol.js +1 -1
- package/dist/session-log.d.ts +30 -0
- package/dist/session-log.js +67 -5
- package/dist/session-log.js.map +1 -1
- package/dist/state/change-signal.d.ts +17 -0
- package/dist/state/change-signal.js +62 -0
- package/dist/state/change-signal.js.map +1 -0
- package/dist/state/db.d.ts +6 -0
- package/dist/state/db.js +8 -2
- package/dist/state/db.js.map +1 -1
- package/dist/state/execution-store.d.ts +53 -13
- package/dist/state/execution-store.js +130 -22
- package/dist/state/execution-store.js.map +1 -1
- package/dist/state/schema/pg.d.ts +34 -0
- package/dist/state/schema/pg.js +9 -0
- package/dist/state/schema/pg.js.map +1 -1
- package/dist/state/schema/sqlite.d.ts +38 -0
- package/dist/state/schema/sqlite.js +9 -0
- package/dist/state/schema/sqlite.js.map +1 -1
- package/dist/state/workflow-run-store.d.ts +3 -0
- package/dist/state/workflow-run-store.js +26 -0
- package/dist/state/workflow-run-store.js.map +1 -1
- package/dist/workflows/handlers/survey-units.js +6 -3
- package/dist/workflows/handlers/survey-units.js.map +1 -1
- package/docker-compose.yml +3 -2
- package/drizzle/pg/0004_colorful_speed.sql +4 -0
- package/drizzle/pg/meta/0004_snapshot.json +1942 -0
- package/drizzle/pg/meta/_journal.json +7 -0
- package/drizzle/sqlite/0005_cynical_whistler.sql +4 -0
- package/drizzle/sqlite/meta/0005_snapshot.json +1767 -0
- package/drizzle/sqlite/meta/_journal.json +7 -0
- package/package.json +25 -25
package/dist/admin/routes.js
CHANGED
|
@@ -119,8 +119,9 @@ import { fetchRepoLayer, refreshRepoLayer, getCachedRepoLayer, repoConfigPolicy,
|
|
|
119
119
|
import { issueTriggerId } from "../engine/build-decisions.js";
|
|
120
120
|
import { applyBuildDispatchGate } from "../engine/build-gate.js";
|
|
121
121
|
import { buildBoard } from "./board.js";
|
|
122
|
-
import { getBoardItems, invalidateBoard, BOARD_TTL_MS } from "./board-cache.js";
|
|
123
|
-
import { boardSignature,
|
|
122
|
+
import { getBoardItems, invalidateBoard, onBoardRevisionChange, BOARD_TTL_MS } from "./board-cache.js";
|
|
123
|
+
import { boardSignature, BOARD_HEARTBEAT_MS } from "./board-stream.js";
|
|
124
|
+
import { runChangeDrivenStream } from "./change-stream.js";
|
|
124
125
|
import { reapSandboxWorkspace } from "../sandbox/reap.js";
|
|
125
126
|
import { artifactStore } from "../sandbox/artifact-store.js";
|
|
126
127
|
import { reclaimSandbox } from "../sandbox/k8s/reclaim.js";
|
|
@@ -221,13 +222,24 @@ export function rangeResponse(rangeHeader, buf, mime, cacheControl) {
|
|
|
221
222
|
* they keep a non-zero count and remain visible.
|
|
222
223
|
*/
|
|
223
224
|
function hasContent(meta) {
|
|
225
|
+
// A ledger-backed session (it knows `running`) always has a transcript —
|
|
226
|
+
// every row with a session id wrote one — and a command phase legitimately
|
|
227
|
+
// runs zero turns, so its turn count is no measure of content.
|
|
228
|
+
if (meta.running !== undefined)
|
|
229
|
+
return true;
|
|
224
230
|
return meta.message_count > 0;
|
|
225
231
|
}
|
|
226
232
|
function isSessionLive(meta, liveTaskIds) {
|
|
227
|
-
//
|
|
233
|
+
// The ledger knows outright: a finished phase is not live, whatever its age.
|
|
234
|
+
if (meta.running === false)
|
|
235
|
+
return false;
|
|
236
|
+
// A ledger-backed session with `running: true` is mid-phase, however long
|
|
237
|
+
// the phase has been going — its last_message_at is the (still null) finish
|
|
238
|
+
// time, so the recency guard below would wrongly retire a long phase at 5 min.
|
|
239
|
+
// Stale sessions from a source that can't say are never live.
|
|
228
240
|
const lastActivity = meta.last_message_at ?? meta.started_at;
|
|
229
241
|
const fiveMinAgo = Date.now() / 1000 - 300;
|
|
230
|
-
if (lastActivity < fiveMinAgo)
|
|
242
|
+
if (meta.running !== true && lastActivity < fiveMinAgo)
|
|
231
243
|
return false;
|
|
232
244
|
// Fallback-named sessions encode their taskId as `exec-<taskId>`, and that
|
|
233
245
|
// taskId is exactly what listRunningContainers parses from the sandbox
|
|
@@ -247,59 +259,48 @@ function isSessionLive(meta, liveTaskIds) {
|
|
|
247
259
|
* "Sessions" tab (sandbox-scoped reader at `/sessions`) and the chat tab
|
|
248
260
|
* (in-process Agent SDK runs at `/chat-sessions`).
|
|
249
261
|
*/
|
|
250
|
-
function mountSessionRoutes(app, sessions, prefix) {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
listRunningContainers(),
|
|
258
|
-
]);
|
|
262
|
+
function mountSessionRoutes(app, sessions, prefix, subscribe) {
|
|
263
|
+
/** The list as rendered: one source query plus `docker ps`, no file reads. */
|
|
264
|
+
const snapshot = async (limit) => {
|
|
265
|
+
// Over-fetch the candidate pool, as the scan-based list did: the chat source
|
|
266
|
+
// orders by last activity while the list sorts by start, so a pool of
|
|
267
|
+
// exactly `limit` could drop a recently-started but quiet thread.
|
|
268
|
+
const [metas, containers] = await Promise.all([sessions.listSessions(limit * 2), listRunningContainers()]);
|
|
259
269
|
const liveTaskIds = new Set(containers.map((c) => c.taskId).filter(Boolean));
|
|
260
270
|
const valid = metas
|
|
261
|
-
.filter((m) => m !== null)
|
|
262
271
|
.filter(hasContent)
|
|
263
272
|
.sort((a, b) => b.started_at - a.started_at)
|
|
264
273
|
.slice(0, limit)
|
|
265
274
|
.map((m) => ({ ...m, live: liveTaskIds.size > 0 && isSessionLive(m, liveTaskIds) }));
|
|
266
|
-
return
|
|
275
|
+
return { sessions: valid, liveCount: containers.length };
|
|
276
|
+
};
|
|
277
|
+
// Session list — enriched with live container status
|
|
278
|
+
app.get(`${prefix}`, async (c) => {
|
|
279
|
+
const limit = Number(c.req.query("limit") ?? 200);
|
|
280
|
+
return c.json(await snapshot(limit));
|
|
267
281
|
});
|
|
268
|
-
// Session list SSE stream
|
|
282
|
+
// Session list SSE stream — pushed when the ledger changes, not polled.
|
|
269
283
|
app.get(`${prefix}/stream`, (c) => {
|
|
270
284
|
const limit = Number(c.req.query("limit") ?? 200);
|
|
271
285
|
return streamSSE(c, async (stream) => {
|
|
272
286
|
let prevSig = null; // null = nothing sent yet (covers empty-list initial push)
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
sessions
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
const valid = metas
|
|
283
|
-
.filter((m) => m !== null)
|
|
284
|
-
.filter(hasContent)
|
|
285
|
-
.sort((a, b) => b.started_at - a.started_at)
|
|
286
|
-
.slice(0, limit)
|
|
287
|
-
.map((m) => ({ ...m, live: liveTaskIds.size > 0 && isSessionLive(m, liveTaskIds) }));
|
|
288
|
-
const sig = valid
|
|
289
|
-
.map((s) => `${s.id}:${s.last_message_at ?? s.started_at}:${s.message_count}:${s.live}`)
|
|
290
|
-
.join("|");
|
|
291
|
-
if (sig !== prevSig) {
|
|
287
|
+
await runChangeDrivenStream(stream, {
|
|
288
|
+
subscribe,
|
|
289
|
+
refresh: async () => {
|
|
290
|
+
const snap = await snapshot(limit);
|
|
291
|
+
const sig = snap.sessions
|
|
292
|
+
.map((s) => `${s.id}:${s.last_message_at ?? s.started_at}:${s.message_count}:${s.live}`)
|
|
293
|
+
.join("|");
|
|
294
|
+
if (sig === prevSig)
|
|
295
|
+
return false;
|
|
292
296
|
prevSig = sig;
|
|
293
|
-
await stream.writeSSE({ event: "sessions", data: JSON.stringify(
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
break;
|
|
301
|
-
await push();
|
|
302
|
-
}
|
|
297
|
+
await stream.writeSSE({ event: "sessions", data: JSON.stringify(snap) });
|
|
298
|
+
return true;
|
|
299
|
+
},
|
|
300
|
+
// An SSE comment: keeps proxies from closing an idle stream, and an
|
|
301
|
+
// EventSource ignores it.
|
|
302
|
+
heartbeat: () => stream.write(": heartbeat\n\n").then(() => undefined),
|
|
303
|
+
});
|
|
303
304
|
});
|
|
304
305
|
});
|
|
305
306
|
// Single session
|
|
@@ -1063,8 +1064,9 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
|
|
|
1063
1064
|
// Workflow / sandbox sessions and chat (in-process Agent SDK) sessions both
|
|
1064
1065
|
// expose the same five endpoints, just under different prefixes and backed
|
|
1065
1066
|
// by different on-disk slices.
|
|
1066
|
-
|
|
1067
|
-
mountSessionRoutes(app,
|
|
1067
|
+
const onExecutionChange = (listener) => db.changes.subscribe(["executions"], listener);
|
|
1068
|
+
mountSessionRoutes(app, sessions, "/sessions", onExecutionChange);
|
|
1069
|
+
mountSessionRoutes(app, chatSessions, "/chat-sessions", onExecutionChange);
|
|
1068
1070
|
// Stats — running count uses live Docker containers, not stale DB records
|
|
1069
1071
|
app.get("/stats", async (c) => {
|
|
1070
1072
|
const [stats, containers] = await Promise.all([
|
|
@@ -1273,7 +1275,7 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
|
|
|
1273
1275
|
if (scope === "messages" || scope === "all") {
|
|
1274
1276
|
const needle = q.toLowerCase();
|
|
1275
1277
|
const maxSessions = 200; // newest-first cap on transcripts scanned
|
|
1276
|
-
const ids = (await sessions.
|
|
1278
|
+
const ids = (await sessions.listSessions(maxSessions)).map((s) => s.id);
|
|
1277
1279
|
outer: for (const id of ids) {
|
|
1278
1280
|
let msgs;
|
|
1279
1281
|
try {
|
|
@@ -1882,6 +1884,7 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
|
|
|
1882
1884
|
running: stage.running,
|
|
1883
1885
|
on_success: stage.on_success,
|
|
1884
1886
|
on_failure: stage.on_failure,
|
|
1887
|
+
workflow: stageWorkflow(stage),
|
|
1885
1888
|
}));
|
|
1886
1889
|
const managedSet = new Set(getManagedRepos());
|
|
1887
1890
|
// ── The board's universe is the AUTONOMY ALLOW-LIST, not the managed list ──
|
|
@@ -1993,7 +1996,16 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
|
|
|
1993
1996
|
github: config.github,
|
|
1994
1997
|
force: c.req.query("refresh") === "1",
|
|
1995
1998
|
});
|
|
1996
|
-
const
|
|
1999
|
+
const triggerIds = items.map((item) => issueTriggerId(item.repo, item.number));
|
|
2000
|
+
const runs = await db.runs.latestForTriggers(triggerIds);
|
|
2001
|
+
// The latest run of each stage's OWN workflow, so a triage run after a build
|
|
2002
|
+
// does not turn "Rebuild" back into "Start build". Skipped when every
|
|
2003
|
+
// card's latest run already is one.
|
|
2004
|
+
const stageWorkflows = [...new Set(stages.map((stage) => stage.workflow).filter((w) => !!w))];
|
|
2005
|
+
const needStageRuns = [...runs.values()].some((run) => !stageWorkflows.includes(run.workflowName));
|
|
2006
|
+
const stageRuns = stageWorkflows.length > 0 && needStageRuns
|
|
2007
|
+
? await db.runs.latestForTriggers(triggerIds, { workflowNames: stageWorkflows })
|
|
2008
|
+
: undefined;
|
|
1997
2009
|
const pending = await db.approvals.listPending();
|
|
1998
2010
|
// The fourth statement, and only when something failed. `workflow_runs` has
|
|
1999
2011
|
// no error column, so a FAILED card's reason comes from the ledger row of
|
|
@@ -2019,6 +2031,7 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
|
|
|
2019
2031
|
return c.json(buildBoard({
|
|
2020
2032
|
items,
|
|
2021
2033
|
runs,
|
|
2034
|
+
...(stageRuns ? { stageRuns } : {}),
|
|
2022
2035
|
approvals: pending,
|
|
2023
2036
|
...(failures ? { failures } : {}),
|
|
2024
2037
|
...(inFlight ? { inFlight } : {}),
|
|
@@ -2044,35 +2057,37 @@ export function createAdminRoutes(db, sessions, chatSessions, config) {
|
|
|
2044
2057
|
app.get("/board/stream", (c) => {
|
|
2045
2058
|
return streamSSE(c, async (stream) => {
|
|
2046
2059
|
let prev = null; // null = nothing sent yet
|
|
2047
|
-
|
|
2048
|
-
let stopped = false;
|
|
2049
|
-
stream.onAbort(() => {
|
|
2050
|
-
stopped = true;
|
|
2051
|
-
});
|
|
2052
|
-
const push = async () => {
|
|
2053
|
-
const revision = await boardSignature(db);
|
|
2054
|
-
const now = Date.now();
|
|
2055
|
-
const changed = revision !== prev;
|
|
2056
|
-
// The heartbeat is not decoration here — see BOARD_HEARTBEAT_MS.
|
|
2057
|
-
if (!changed && now - lastBeat < BOARD_HEARTBEAT_MS)
|
|
2058
|
-
return;
|
|
2059
|
-
prev = revision;
|
|
2060
|
-
lastBeat = now;
|
|
2060
|
+
const send = async (revision, changed) => {
|
|
2061
2061
|
await stream.writeSSE({
|
|
2062
2062
|
event: "board",
|
|
2063
|
-
data: JSON.stringify({ revision, changed, at: new Date(
|
|
2063
|
+
data: JSON.stringify({ revision, changed, at: new Date().toISOString() }),
|
|
2064
2064
|
});
|
|
2065
2065
|
};
|
|
2066
|
-
//
|
|
2067
|
-
//
|
|
2068
|
-
//
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2066
|
+
// Pushed, not polled: a run or ledger write, or another tab's refetch
|
|
2067
|
+
// moving the GitHub cache revision, wakes the stream. The handshake frame
|
|
2068
|
+
// (`prev` is null, so it always sends) tells the client the stream is
|
|
2069
|
+
// live; the client skips it rather than treating it as news.
|
|
2070
|
+
await runChangeDrivenStream(stream, {
|
|
2071
|
+
subscribe: (listener) => {
|
|
2072
|
+
const offDb = db.changes.subscribe(["runs", "executions"], listener);
|
|
2073
|
+
const offCache = onBoardRevisionChange(listener);
|
|
2074
|
+
return () => {
|
|
2075
|
+
offDb();
|
|
2076
|
+
offCache();
|
|
2077
|
+
};
|
|
2078
|
+
},
|
|
2079
|
+
refresh: async () => {
|
|
2080
|
+
const revision = await boardSignature(db);
|
|
2081
|
+
if (revision === prev)
|
|
2082
|
+
return false;
|
|
2083
|
+
prev = revision;
|
|
2084
|
+
await send(revision, true);
|
|
2085
|
+
return true;
|
|
2086
|
+
},
|
|
2087
|
+
// The heartbeat is not decoration here — see BOARD_HEARTBEAT_MS.
|
|
2088
|
+
heartbeat: () => send(prev ?? "", false),
|
|
2089
|
+
heartbeatMs: BOARD_HEARTBEAT_MS,
|
|
2090
|
+
});
|
|
2076
2091
|
});
|
|
2077
2092
|
});
|
|
2078
2093
|
app.get("/repos", async (c) => {
|