lastlight-core 0.25.8 → 0.26.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.
Files changed (172) hide show
  1. package/config/default.yaml +31 -6
  2. package/dist/admin/chat-session-reader.d.ts +3 -3
  3. package/dist/admin/chat-session-reader.js +8 -8
  4. package/dist/admin/chat-session-reader.js.map +1 -1
  5. package/dist/admin/routes.js +119 -124
  6. package/dist/admin/routes.js.map +1 -1
  7. package/dist/admin/sessions.d.ts +7 -7
  8. package/dist/admin/sessions.js +6 -4
  9. package/dist/admin/sessions.js.map +1 -1
  10. package/dist/config/config.d.ts +21 -2
  11. package/dist/config/config.js +33 -0
  12. package/dist/config/config.js.map +1 -1
  13. package/dist/config/repo-config.js +6 -7
  14. package/dist/config/repo-config.js.map +1 -1
  15. package/dist/connectors/messaging/base.js +2 -2
  16. package/dist/connectors/messaging/base.js.map +1 -1
  17. package/dist/connectors/messaging/session-manager.d.ts +29 -31
  18. package/dist/connectors/messaging/session-manager.js +156 -189
  19. package/dist/connectors/messaging/session-manager.js.map +1 -1
  20. package/dist/connectors/messaging/thread-transcript.d.ts +2 -2
  21. package/dist/connectors/messaging/thread-transcript.js +14 -8
  22. package/dist/connectors/messaging/thread-transcript.js.map +1 -1
  23. package/dist/connectors/slack/connector.js +5 -5
  24. package/dist/connectors/slack/connector.js.map +1 -1
  25. package/dist/connectors/slack/mrkdwn.d.ts +4 -0
  26. package/dist/connectors/slack/mrkdwn.js +2 -2
  27. package/dist/connectors/slack/mrkdwn.js.map +1 -1
  28. package/dist/cron/feedback-poll.js +6 -6
  29. package/dist/cron/feedback-poll.js.map +1 -1
  30. package/dist/cron/handlers.d.ts +16 -8
  31. package/dist/cron/handlers.js +49 -31
  32. package/dist/cron/handlers.js.map +1 -1
  33. package/dist/cron/jobs.d.ts +1 -1
  34. package/dist/cron/jobs.js +5 -2
  35. package/dist/cron/jobs.js.map +1 -1
  36. package/dist/cron/repo-digest.d.ts +54 -7
  37. package/dist/cron/repo-digest.js +236 -23
  38. package/dist/cron/repo-digest.js.map +1 -1
  39. package/dist/cron/runner.d.ts +59 -0
  40. package/dist/cron/runner.js +224 -0
  41. package/dist/cron/runner.js.map +1 -0
  42. package/dist/cron/scheduler.js +19 -9
  43. package/dist/cron/scheduler.js.map +1 -1
  44. package/dist/engine/chat/chat-prompt.d.ts +11 -4
  45. package/dist/engine/chat/chat-prompt.js.map +1 -1
  46. package/dist/engine/chat/chat-runner.d.ts +3 -2
  47. package/dist/engine/chat/chat-runner.js +9 -7
  48. package/dist/engine/chat/chat-runner.js.map +1 -1
  49. package/dist/engine/dispatcher.js +29 -25
  50. package/dist/engine/dispatcher.js.map +1 -1
  51. package/dist/engine/executors/orchestrator.d.ts +28 -0
  52. package/dist/engine/executors/orchestrator.js +70 -1
  53. package/dist/engine/executors/orchestrator.js.map +1 -1
  54. package/dist/engine/feedback/ingest.d.ts +4 -4
  55. package/dist/engine/feedback/ingest.js +13 -13
  56. package/dist/engine/feedback/ingest.js.map +1 -1
  57. package/dist/engine/feedback/slack.d.ts +2 -2
  58. package/dist/engine/feedback/slack.js +6 -6
  59. package/dist/engine/feedback/slack.js.map +1 -1
  60. package/dist/engine/fix-harvest.d.ts +1 -1
  61. package/dist/engine/fix-harvest.js +3 -3
  62. package/dist/engine/fix-harvest.js.map +1 -1
  63. package/dist/engine/github/github.d.ts +79 -0
  64. package/dist/engine/github/github.js +111 -0
  65. package/dist/engine/github/github.js.map +1 -1
  66. package/dist/engine/github/team-visibility.js +7 -7
  67. package/dist/engine/github/team-visibility.js.map +1 -1
  68. package/dist/engine/pr-escalation.js +7 -7
  69. package/dist/engine/pr-escalation.js.map +1 -1
  70. package/dist/engine/pr-state.d.ts +1 -1
  71. package/dist/engine/pr-state.js +12 -10
  72. package/dist/engine/pr-state.js.map +1 -1
  73. package/dist/engine/review-check.d.ts +1 -1
  74. package/dist/engine/review-check.js +5 -5
  75. package/dist/engine/review-check.js.map +1 -1
  76. package/dist/engine/router.js +3 -3
  77. package/dist/engine/router.js.map +1 -1
  78. package/dist/index.js +115 -152
  79. package/dist/index.js.map +1 -1
  80. package/dist/notify/digest-blocks.d.ts +61 -0
  81. package/dist/notify/digest-blocks.js +150 -22
  82. package/dist/notify/digest-blocks.js.map +1 -1
  83. package/dist/sandbox/docker.d.ts +33 -1
  84. package/dist/sandbox/docker.js +95 -1
  85. package/dist/sandbox/docker.js.map +1 -1
  86. package/dist/sandbox/k8s/kubernetes-sandbox.d.ts +3 -0
  87. package/dist/sandbox/k8s/kubernetes-sandbox.js +9 -0
  88. package/dist/sandbox/k8s/kubernetes-sandbox.js.map +1 -1
  89. package/dist/sandbox/k8s/pod.d.ts +11 -0
  90. package/dist/sandbox/k8s/pod.js +11 -6
  91. package/dist/sandbox/k8s/pod.js.map +1 -1
  92. package/dist/sandbox/k8s/service-containers.d.ts +43 -0
  93. package/dist/sandbox/k8s/service-containers.js +87 -0
  94. package/dist/sandbox/k8s/service-containers.js.map +1 -0
  95. package/dist/sandbox/reap.d.ts +9 -0
  96. package/dist/sandbox/reap.js +36 -0
  97. package/dist/sandbox/reap.js.map +1 -1
  98. package/dist/sandbox/sandbox.d.ts +14 -0
  99. package/dist/sandbox/sandbox.js +9 -0
  100. package/dist/sandbox/sandbox.js.map +1 -1
  101. package/dist/sandbox/service-containers-docker.d.ts +45 -0
  102. package/dist/sandbox/service-containers-docker.js +78 -0
  103. package/dist/sandbox/service-containers-docker.js.map +1 -0
  104. package/dist/state/approval-store.d.ts +23 -14
  105. package/dist/state/approval-store.js +137 -86
  106. package/dist/state/approval-store.js.map +1 -1
  107. package/dist/state/client.d.ts +105 -0
  108. package/dist/state/client.js +68 -0
  109. package/dist/state/client.js.map +1 -0
  110. package/dist/state/cron-run-store.d.ts +108 -0
  111. package/dist/state/cron-run-store.js +173 -0
  112. package/dist/state/cron-run-store.js.map +1 -0
  113. package/dist/state/db.d.ts +70 -23
  114. package/dist/state/db.js +179 -104
  115. package/dist/state/db.js.map +1 -1
  116. package/dist/state/dialect.d.ts +77 -0
  117. package/dist/state/dialect.js +129 -0
  118. package/dist/state/dialect.js.map +1 -0
  119. package/dist/state/execution-store.d.ts +124 -103
  120. package/dist/state/execution-store.js +569 -374
  121. package/dist/state/execution-store.js.map +1 -1
  122. package/dist/state/feedback-store.d.ts +20 -20
  123. package/dist/state/feedback-store.js +241 -187
  124. package/dist/state/feedback-store.js.map +1 -1
  125. package/dist/state/legacy-sqlite.d.ts +15 -0
  126. package/dist/state/legacy-sqlite.js +131 -0
  127. package/dist/state/legacy-sqlite.js.map +1 -0
  128. package/dist/state/repo-ref.d.ts +9 -4
  129. package/dist/state/repo-ref.js +12 -6
  130. package/dist/state/repo-ref.js.map +1 -1
  131. package/dist/state/schema/pg.d.ts +2788 -0
  132. package/dist/state/schema/pg.js +301 -0
  133. package/dist/state/schema/pg.js.map +1 -0
  134. package/dist/state/schema/sqlite.d.ts +3063 -0
  135. package/dist/state/schema/sqlite.js +391 -0
  136. package/dist/state/schema/sqlite.js.map +1 -0
  137. package/dist/state/team-store.d.ts +26 -13
  138. package/dist/state/team-store.js +140 -93
  139. package/dist/state/team-store.js.map +1 -1
  140. package/dist/state/user-store.d.ts +31 -13
  141. package/dist/state/user-store.js +180 -80
  142. package/dist/state/user-store.js.map +1 -1
  143. package/dist/state/workflow-run-store.d.ts +95 -56
  144. package/dist/state/workflow-run-store.js +419 -314
  145. package/dist/state/workflow-run-store.js.map +1 -1
  146. package/dist/telemetry/index.d.ts +8 -0
  147. package/dist/telemetry/index.js +11 -0
  148. package/dist/telemetry/index.js.map +1 -1
  149. package/dist/workflows/admission.d.ts +4 -3
  150. package/dist/workflows/admission.js +34 -10
  151. package/dist/workflows/admission.js.map +1 -1
  152. package/dist/workflows/handlers/post-review.js +3 -3
  153. package/dist/workflows/handlers/post-review.js.map +1 -1
  154. package/dist/workflows/resume.js +22 -15
  155. package/dist/workflows/resume.js.map +1 -1
  156. package/dist/workflows/runner.js +27 -12
  157. package/dist/workflows/runner.js.map +1 -1
  158. package/dist/workflows/simple.d.ts +23 -0
  159. package/dist/workflows/simple.js +40 -16
  160. package/dist/workflows/simple.js.map +1 -1
  161. package/drizzle/pg/0000_init.sql +235 -0
  162. package/drizzle/pg/meta/0000_snapshot.json +1751 -0
  163. package/drizzle/pg/meta/_journal.json +13 -0
  164. package/drizzle/sqlite/0000_baseline.sql +257 -0
  165. package/drizzle/sqlite/0001_backfill_repo_refs.sql +74 -0
  166. package/drizzle/sqlite/meta/0000_snapshot.json +1593 -0
  167. package/drizzle/sqlite/meta/0001_snapshot.json +1593 -0
  168. package/drizzle/sqlite/meta/_journal.json +20 -0
  169. package/package.json +15 -9
  170. package/dist/state/migrate.d.ts +0 -15
  171. package/dist/state/migrate.js +0 -493
  172. package/dist/state/migrate.js.map +0 -1
@@ -1,4 +1,6 @@
1
- import type Database from "better-sqlite3";
1
+ import { type SQL } from "drizzle-orm";
2
+ import type { ExtensionStatusMap, SkillsStatus } from "lastlight-workflow-engine";
3
+ import { type StateClient, type StateTables } from "./client.js";
2
4
  import type { TriggerActorType } from "./user-store.js";
3
5
  export interface ExecutionRecord {
4
6
  id: string;
@@ -48,16 +50,17 @@ export interface ExecutionRecord {
48
50
  /** Result subtype, e.g. "success" or "error_max_turns". */
49
51
  stopReason?: string;
50
52
  /**
51
- * JSON-serialized {@link ExtensionStatusMap} — which agentic-pi extensions
52
- * (file-search / github / web-search) were active for this execution.
53
+ * Which agentic-pi extensions (file-search / github / web-search) were active
54
+ * for this execution. A real JSON column, so this travels as an OBJECT in
55
+ * both directions and nothing on either side stringifies it.
53
56
  */
54
- extensionStatus?: string;
57
+ extensionStatus?: ExtensionStatusMap;
55
58
  /**
56
- * JSON-serialized {@link SkillsStatus} — agentic-pi's skill-loading status
57
- * for this execution (which skills were discovered/available). Null when
58
- * the run reported no skills.
59
+ * agentic-pi's skill-loading status for this execution (which skills were
60
+ * discovered/available). A real JSON column, like {@link extensionStatus}.
61
+ * Absent when the run reported no skills.
59
62
  */
60
- skillsStatus?: string;
63
+ skillsStatus?: SkillsStatus;
61
64
  /**
62
65
  * Workflow run that owns this execution. Scopes dedup: a fresh re-trigger
63
66
  * creates a new workflow_run_id, so `shouldRunPhase` won't find matching
@@ -77,10 +80,10 @@ export interface ExecutionOutcomeCounts {
77
80
  * selects (issue #325).
78
81
  *
79
82
  * `executions.success` is not a health signal and must not be read as one.
80
- * Two paths write `success = 0` deliberately, having failed at nothing:
83
+ * Two paths write `success = false` deliberately, having failed at nothing:
81
84
  *
82
85
  * - **`skipped`** — {@link ExecutionStore.recordSkippedPhase}. Stored
83
- * `success = 0` so {@link ExecutionStore.shouldRunPhase} re-evaluates the
86
+ * `success = false` so {@link ExecutionStore.shouldRunPhase} re-evaluates the
84
87
  * node on resume. The phase never ran.
85
88
  * - **`error_quota`** — the k8s `ResourceQuota` rejected the pod. The runner
86
89
  * treats it as an ordinary phase failure precisely so the run REQUEUES
@@ -98,17 +101,52 @@ export interface ExecutionOutcomeCounts {
98
101
  *
99
102
  * `success IS NULL` (still in flight) matches no bucket on purpose: it counts
100
103
  * toward `COUNT(*)` and toward nothing else, so a stacked bar can legitimately
101
- * be shorter than the execution total.
104
+ * be shorter than the execution total. That is why every arm goes through
105
+ * {@link sumTrue} — a `CASE WHEN <predicate>` where NULL falls to the ELSE in
106
+ * both dialects — and why the three that test for failure compare against a
107
+ * BOUND `${false}` rather than a literal `0`, which Postgres rejects outright
108
+ * (`operator does not exist: boolean = integer`).
102
109
  *
103
110
  * Note `condition_not_met` — a generic-loop `until_bash` check that ran and
104
- * came back red — is stored `success = 1` and therefore lands in `succeeded`.
105
- * It really executed and really cost tokens; only its per-row rendering is
106
- * muted (`execMark`, `packages/cli/src/cli-format.ts`).
111
+ * came back red — is stored `success = true` and therefore lands in
112
+ * `succeeded`. It really executed and really cost tokens; only its per-row
113
+ * rendering is muted (`execMark`, `packages/cli/src/cli-format.ts`).
107
114
  */
108
- export declare const EXECUTION_OUTCOME_COLUMNS = "\n SUM(CASE WHEN success = 1 THEN 1 ELSE 0 END) AS succeeded,\n SUM(CASE WHEN success = 0 AND stop_reason = 'skipped' THEN 1 ELSE 0 END) AS skipped,\n SUM(CASE WHEN success = 0 AND stop_reason = 'error_quota' THEN 1 ELSE 0 END) AS deferred,\n SUM(CASE WHEN success = 0\n AND (stop_reason IS NULL OR stop_reason NOT IN ('skipped', 'error_quota'))\n THEN 1 ELSE 0 END) AS failed";
115
+ export declare const executionOutcomeColumns: ({ executions }: StateTables) => SQL;
116
+ /** One aggregated chat thread — the shape both thread reads return. */
117
+ interface ChatThreadSummary {
118
+ triggerId: string;
119
+ agentSessionId: string | null;
120
+ platform: string | null;
121
+ firstStartedAt: string;
122
+ lastActivityAt: string;
123
+ turnCount: number;
124
+ totalCost: number;
125
+ inputTokens: number;
126
+ outputTokens: number;
127
+ cacheReadTokens: number;
128
+ lastAssistantContent: string | null;
129
+ repo: string | null;
130
+ }
131
+ /** The per-bucket shape {@link ExecutionStore.dailyStats} / `hourlyStats` return. */
132
+ type BucketStats = ExecutionOutcomeCounts & {
133
+ date: string;
134
+ executions: number;
135
+ totalTokens: number;
136
+ inputTokens: number;
137
+ outputTokens: number;
138
+ cacheReadTokens: number;
139
+ costUsd: number;
140
+ };
109
141
  export declare class ExecutionStore {
110
- private db;
111
- constructor(db: Database.Database);
142
+ private client;
143
+ /**
144
+ * Table objects for THIS client's dialect. Every method destructures what it
145
+ * needs off this instead of importing from `schema/sqlite.js` — see
146
+ * `client.ts` → {@link tablesOf} for why the cast alone cannot do it.
147
+ */
148
+ private readonly t;
149
+ constructor(client: StateClient);
112
150
  /**
113
151
  * Append a started phase to the ledger.
114
152
  *
@@ -118,13 +156,13 @@ export declare class ExecutionStore {
118
156
  * qualified value from anywhere else is normalized rather than stored as a
119
157
  * second shape.
120
158
  */
121
- recordStart(record: Omit<ExecutionRecord, "finishedAt" | "success" | "error" | "turns" | "durationMs">): void;
159
+ recordStart(record: Omit<ExecutionRecord, "finishedAt" | "success" | "error" | "turns" | "durationMs">): Promise<void>;
122
160
  /**
123
161
  * Mid-run update: persist the agent session id as soon as the executor sees
124
162
  * the stream-json `system/init` line. Lets the dashboard surface the live
125
163
  * session log for an in-flight phase, not just for completed ones.
126
164
  */
127
- recordSessionId(id: string, sessionId: string): void;
165
+ recordSessionId(id: string, sessionId: string): Promise<void>;
128
166
  /**
129
167
  * Persist the final assistant text for a loop-iteration execution.
130
168
  * Used by the runner when a scratch slot would otherwise inline the
@@ -132,16 +170,16 @@ export declare class ExecutionStore {
132
170
  * stores `lastOutputExecutionId` and resolves the text through
133
171
  * `getExecutionOutput` on read.
134
172
  */
135
- recordOutputText(id: string, output: string): void;
173
+ recordOutputText(id: string, output: string): Promise<void>;
136
174
  /** Read the persisted output text for an execution, or null if none. */
137
- getExecutionOutput(id: string): string | null;
175
+ getExecutionOutput(id: string): Promise<string | null>;
138
176
  /**
139
177
  * Most recent finished execution's `output_text` for a phase (`skill`), or
140
178
  * null. Used by the reviewer loop on resume to re-derive a completed review's
141
179
  * verdict from its persisted output (a dedup-`done` review must not be
142
180
  * assumed APPROVED — it may have requested changes).
143
181
  */
144
- getPhaseOutput(skill: string, triggerId: string, workflowRunId?: string): string | null;
182
+ getPhaseOutput(skill: string, triggerId: string, workflowRunId?: string): Promise<string | null>;
145
183
  recordFinish(id: string, result: {
146
184
  success: boolean;
147
185
  error?: string;
@@ -155,21 +193,21 @@ export declare class ExecutionStore {
155
193
  outputTokens?: number;
156
194
  apiDurationMs?: number;
157
195
  stopReason?: string;
158
- /** JSON-serialized ExtensionStatusMap (extensions active this run). */
159
- extensionStatus?: string;
160
- /** JSON-serialized SkillsStatus (skills available this run). */
161
- skillsStatus?: string;
162
- }): void;
196
+ /** Extensions active this run. An OBJECT — the column is real JSON. */
197
+ extensionStatus?: ExtensionStatusMap;
198
+ /** Skills available this run. An OBJECT — the column is real JSON. */
199
+ skillsStatus?: SkillsStatus;
200
+ }): Promise<void>;
163
201
  /**
164
202
  * Record a phase that the scheduler skipped because its trigger rule was
165
203
  * not satisfied (a failed/skipped upstream cascaded down a chain). The
166
204
  * executions ledger is the single source of truth the dashboard derives
167
205
  * phase status from, so skips are written here too — as a finished,
168
- * non-successful row (`success = 0`, `stop_reason = 'skipped'`). Because it
169
- * is not `success = 1`, `shouldRunPhase` re-evaluates it on resume (the node
170
- * will simply be re-skipped if the upstream is still failed).
206
+ * non-successful row (`success = false`, `stop_reason = 'skipped'`). Because
207
+ * it is not `success = true`, `shouldRunPhase` re-evaluates it on resume (the
208
+ * node will simply be re-skipped if the upstream is still failed).
171
209
  */
172
- recordSkippedPhase(skill: string, triggerId: string, workflowRunId?: string, repo?: string, owner?: string): void;
210
+ recordSkippedPhase(skill: string, triggerId: string, workflowRunId?: string, repo?: string, owner?: string): Promise<void>;
173
211
  /**
174
212
  * List chat threads aggregated from the executions table.
175
213
  *
@@ -180,35 +218,9 @@ export declare class ExecutionStore {
180
218
  * the on-disk jsonl when streaming messages) and with `messaging_messages`
181
219
  * for the most recent assistant text (preview snippet).
182
220
  */
183
- listChatThreads(limit: number): {
184
- triggerId: string;
185
- agentSessionId: string | null;
186
- platform: string | null;
187
- firstStartedAt: string;
188
- lastActivityAt: string;
189
- turnCount: number;
190
- totalCost: number;
191
- inputTokens: number;
192
- outputTokens: number;
193
- cacheReadTokens: number;
194
- lastAssistantContent: string | null;
195
- repo: string | null;
196
- }[];
221
+ listChatThreads(limit: number): Promise<ChatThreadSummary[]>;
197
222
  /** Look up a single chat thread by its messaging session id (= trigger_id). */
198
- getChatThread(triggerId: string): {
199
- triggerId: string;
200
- agentSessionId: string | null;
201
- platform: string | null;
202
- firstStartedAt: string;
203
- lastActivityAt: string;
204
- turnCount: number;
205
- totalCost: number;
206
- inputTokens: number;
207
- outputTokens: number;
208
- cacheReadTokens: number;
209
- lastAssistantContent: string | null;
210
- repo: string | null;
211
- } | null;
223
+ getChatThread(triggerId: string): Promise<ChatThreadSummary | null>;
212
224
  /**
213
225
  * The repo a sandbox session ran against, resolved from the `executions`
214
226
  * ledger by its `session_id` (issue #169).
@@ -218,9 +230,9 @@ export declare class ExecutionStore {
218
230
  * session list by the same allowed-repo set as everything else. Returns null
219
231
  * for a session we have no execution row for — those stay visible.
220
232
  */
221
- repoForSessionId(sessionId: string): string | null;
233
+ repoForSessionId(sessionId: string): Promise<string | null>;
222
234
  /** Check if a skill is currently running for a given trigger */
223
- isRunning(skill: string, triggerId: string): boolean;
235
+ isRunning(skill: string, triggerId: string): Promise<boolean>;
224
236
  /**
225
237
  * Total USD spent by every execution belonging to a run of one of
226
238
  * `workflowNames` for this trigger — the cumulative per-PR cost the
@@ -236,7 +248,7 @@ export declare class ExecutionStore {
236
248
  * OAuth/subscription run) contribute 0 — the brake must never be tripped by
237
249
  * missing data.
238
250
  */
239
- costForTriggerWorkflows(triggerId: string, workflowNames: string[]): number;
251
+ costForTriggerWorkflows(triggerId: string, workflowNames: string[]): Promise<number>;
240
252
  /**
241
253
  * Did `workflowRunId` complete phase `phaseName` successfully?
242
254
  *
@@ -247,9 +259,9 @@ export declare class ExecutionStore {
247
259
  * `on_output.requires_marker: DIAGNOSIS_COMPLETE`, so a succeeded row for it
248
260
  * is equivalent to the marker having been emitted.
249
261
  */
250
- phaseSucceededInRun(workflowRunId: string, phaseName: string): boolean;
262
+ phaseSucceededInRun(workflowRunId: string, phaseName: string): Promise<boolean>;
251
263
  /** Check if a skill has already completed successfully for a given trigger */
252
- isCompleted(skill: string, triggerId: string): boolean;
264
+ isCompleted(skill: string, triggerId: string): Promise<boolean>;
253
265
  /**
254
266
  * Check if a phase should run: not currently running AND not already
255
267
  * succeeded. When `workflowRunId` is provided, scopes the check to that
@@ -258,43 +270,61 @@ export declare class ExecutionStore {
258
270
  * for the same trigger exists. Omit `workflowRunId` for legacy callers
259
271
  * (e.g. chat/status-report dedup) that want the old trigger-wide scope.
260
272
  */
261
- shouldRunPhase(skill: string, triggerId: string, workflowRunId?: string): "run" | "running" | "done";
273
+ shouldRunPhase(skill: string, triggerId: string, workflowRunId?: string): Promise<"run" | "running" | "done">;
262
274
  /** Mark all stale "running" executions for a skill/trigger as failed.
263
275
  * Called when we detect no matching Docker container is alive. */
264
- markStaleAsFailed(skill: string, triggerId: string, workflowRunId?: string): number;
276
+ markStaleAsFailed(skill: string, triggerId: string, workflowRunId?: string): Promise<number>;
265
277
  /**
266
278
  * Mark every unfinished execution row for a trigger as failed, regardless
267
279
  * of skill. Used by the boot-time recovery sweep to clear out phases that
268
280
  * were running when the harness crashed/restarted, so the runner's dedup
269
281
  * logic doesn't think they're still in flight.
270
282
  */
271
- markAllStaleForTrigger(triggerId: string, reason: string): number;
283
+ markAllStaleForTrigger(triggerId: string, reason: string): Promise<number>;
272
284
  /**
273
285
  * Mark the most recent execution for a skill/trigger as failed.
274
286
  * Used when the agent SDK reported success but the orchestrator decided
275
287
  * the business outcome was a failure (e.g. guardrails BLOCKED, reviewer
276
288
  * REQUEST_CHANGES). Without this, runPhase would skip the phase on the
277
- * next run because the DB still says success=1.
289
+ * next run because the DB still says success=true.
290
+ *
291
+ * Raw because of the "newest row wins" correlated subquery. Note the two
292
+ * shapes it needs: the SET column is written UNQUALIFIED (`SET
293
+ * "executions"."success" = …` is not legal SQL in either dialect), and the
294
+ * false is a BOUND param — libsql binds it as 0 and Postgres as a real
295
+ * boolean, where a literal `= 0` would throw `operator does not exist:
296
+ * boolean = integer`.
278
297
  */
279
- markLatestAsFailed(skill: string, triggerId: string, reason: string, workflowRunId?: string): number;
298
+ markLatestAsFailed(skill: string, triggerId: string, reason: string, workflowRunId?: string): Promise<number>;
280
299
  /** Get recent executions for a skill */
281
- recentExecutions(skill: string, limit?: number): ExecutionRecord[];
282
- /** Count consecutive failures for a skill (for cron failure tracking) */
283
- consecutiveFailures(skill: string): number;
300
+ recentExecutions(skill: string, limit?: number): Promise<ExecutionRecord[]>;
301
+ /**
302
+ * Count consecutive failures for a skill (for cron failure tracking).
303
+ *
304
+ * The compare is `=== false`, not `=== 0`: `success` is a boolean-mode
305
+ * column, so an integer compare is never true and this would report a
306
+ * permanent zero — silently disarming the cron failure alert.
307
+ */
308
+ consecutiveFailures(skill: string): Promise<number>;
284
309
  /** Get all executions with pagination */
285
- allExecutions(limit?: number, offset?: number): ExecutionRecord[];
310
+ allExecutions(limit?: number, offset?: number): Promise<ExecutionRecord[]>;
286
311
  /**
287
312
  * Free-text search across the `executions` ledger — matches `error`, `skill`,
288
- * or `repo` against a substring (case-insensitive via SQLite's LIKE). Used by
289
- * the `/admin/api/log-search` endpoint and the `lastlight logs search` CLI to
290
- * find failing/relevant phases without SSHing to the box. Parameterized; the
291
- * pattern is escaped so user input can't smuggle LIKE wildcards.
313
+ * or `repo` against a substring. Used by the `/admin/api/log-search` endpoint
314
+ * and the `lastlight logs search` CLI to find failing/relevant phases without
315
+ * SSHing to the box. Parameterized; the pattern is escaped so user input
316
+ * can't smuggle LIKE wildcards.
317
+ *
318
+ * Raw, because `LIKE … ESCAPE '\'` has no query-builder spelling. Both sides
319
+ * are `lower()`ed rather than leaning on SQLite's case-insensitive LIKE,
320
+ * which Postgres does not share — the case-insensitivity is the feature here,
321
+ * not an accident of the dialect.
292
322
  *
293
323
  * Matches and returns the QUALIFIED repo, because that is what somebody types
294
324
  * (issue #279) — searching `nearform/lastlight` against the bare column found
295
325
  * no phase row at all.
296
326
  */
297
- searchErrors(query: string, limit?: number): Array<{
327
+ searchErrors(query: string, limit?: number): Promise<Array<{
298
328
  id: string;
299
329
  skill: string;
300
330
  repo?: string;
@@ -305,7 +335,7 @@ export declare class ExecutionStore {
305
335
  sessionId?: string;
306
336
  workflowRunId?: string;
307
337
  triggerId: string;
308
- }>;
338
+ }>>;
309
339
  /**
310
340
  * Get every execution recorded for a workflow run, with camelCase fields
311
341
  * ready for the dashboard. Ordered by start time ascending so phases
@@ -314,11 +344,11 @@ export declare class ExecutionStore {
314
344
  * falls back to the legacy trigger-wide scope for rows written before the
315
345
  * workflow_run_id column existed.
316
346
  */
317
- getExecutionsForWorkflowRun(workflowRunId: string, triggerId: string, workflowName?: string): ExecutionRecord[];
347
+ getExecutionsForWorkflowRun(workflowRunId: string, triggerId: string, workflowName?: string): Promise<ExecutionRecord[]>;
318
348
  /** Get currently running executions (no finished_at) */
319
- runningExecutions(): ExecutionRecord[];
349
+ runningExecutions(): Promise<ExecutionRecord[]>;
320
350
  /** Aggregate execution stats */
321
- executionStats(): {
351
+ executionStats(): Promise<{
322
352
  total_executions: number;
323
353
  today_count: number;
324
354
  by_skill: Record<string, ExecutionOutcomeCounts & {
@@ -326,7 +356,7 @@ export declare class ExecutionStore {
326
356
  }>;
327
357
  by_trigger: Record<string, number>;
328
358
  running: number;
329
- };
359
+ }>;
330
360
  /**
331
361
  * What ONE repo's agent work cost since `sinceIso`. The spend line of the
332
362
  * weekly digest.
@@ -335,28 +365,19 @@ export declare class ExecutionStore {
335
365
  * phase, carry no cost — so this sums with a COALESCE and reports the phase
336
366
  * count separately rather than implying the two are the same denominator.
337
367
  */
338
- repoCostSince(owner: string, repo: string, sinceIso: string): {
368
+ repoCostSince(owner: string, repo: string, sinceIso: string): Promise<{
339
369
  costUsd: number;
340
370
  phases: number;
341
- };
371
+ }>;
342
372
  /** Daily aggregated stats for the last N days */
343
- dailyStats(days: number): (ExecutionOutcomeCounts & {
344
- date: string;
345
- executions: number;
346
- totalTokens: number;
347
- inputTokens: number;
348
- outputTokens: number;
349
- cacheReadTokens: number;
350
- costUsd: number;
351
- })[];
373
+ dailyStats(days: number): Promise<BucketStats[]>;
352
374
  /** Hourly aggregated stats for the last N hours (UTC). Bucket key is `YYYY-MM-DDTHH`. */
353
- hourlyStats(hours: number): (ExecutionOutcomeCounts & {
354
- date: string;
355
- executions: number;
356
- totalTokens: number;
357
- inputTokens: number;
358
- outputTokens: number;
359
- cacheReadTokens: number;
360
- costUsd: number;
361
- })[];
375
+ hourlyStats(hours: number): Promise<BucketStats[]>;
376
+ /**
377
+ * The run-vs-trigger scope shared by the five methods that accept an optional
378
+ * `workflowRunId`: prefer the run when the caller knows it, fall back to the
379
+ * trigger-wide scope for legacy callers and pre-`workflow_run_id` rows.
380
+ */
381
+ private scope;
362
382
  }
383
+ export {};