lastlight-core 0.25.9 → 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 (157) hide show
  1. package/config/default.yaml +20 -1
  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 +97 -99
  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 +15 -0
  11. package/dist/config/config.js +28 -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/cron/feedback-poll.js +6 -6
  26. package/dist/cron/feedback-poll.js.map +1 -1
  27. package/dist/cron/handlers.js +3 -3
  28. package/dist/cron/handlers.js.map +1 -1
  29. package/dist/cron/jobs.d.ts +1 -1
  30. package/dist/cron/jobs.js +2 -2
  31. package/dist/cron/jobs.js.map +1 -1
  32. package/dist/cron/repo-digest.js +4 -4
  33. package/dist/cron/repo-digest.js.map +1 -1
  34. package/dist/cron/runner.js +2 -2
  35. package/dist/cron/runner.js.map +1 -1
  36. package/dist/cron/scheduler.js +1 -1
  37. package/dist/cron/scheduler.js.map +1 -1
  38. package/dist/engine/chat/chat-prompt.d.ts +11 -4
  39. package/dist/engine/chat/chat-prompt.js.map +1 -1
  40. package/dist/engine/chat/chat-runner.d.ts +3 -2
  41. package/dist/engine/chat/chat-runner.js +9 -7
  42. package/dist/engine/chat/chat-runner.js.map +1 -1
  43. package/dist/engine/dispatcher.js +29 -25
  44. package/dist/engine/dispatcher.js.map +1 -1
  45. package/dist/engine/executors/orchestrator.d.ts +28 -0
  46. package/dist/engine/executors/orchestrator.js +70 -1
  47. package/dist/engine/executors/orchestrator.js.map +1 -1
  48. package/dist/engine/feedback/ingest.d.ts +4 -4
  49. package/dist/engine/feedback/ingest.js +13 -13
  50. package/dist/engine/feedback/ingest.js.map +1 -1
  51. package/dist/engine/feedback/slack.d.ts +2 -2
  52. package/dist/engine/feedback/slack.js +6 -6
  53. package/dist/engine/feedback/slack.js.map +1 -1
  54. package/dist/engine/fix-harvest.d.ts +1 -1
  55. package/dist/engine/fix-harvest.js +3 -3
  56. package/dist/engine/fix-harvest.js.map +1 -1
  57. package/dist/engine/github/team-visibility.js +7 -7
  58. package/dist/engine/github/team-visibility.js.map +1 -1
  59. package/dist/engine/pr-escalation.js +7 -7
  60. package/dist/engine/pr-escalation.js.map +1 -1
  61. package/dist/engine/pr-state.d.ts +1 -1
  62. package/dist/engine/pr-state.js +12 -10
  63. package/dist/engine/pr-state.js.map +1 -1
  64. package/dist/engine/review-check.d.ts +1 -1
  65. package/dist/engine/review-check.js +5 -5
  66. package/dist/engine/review-check.js.map +1 -1
  67. package/dist/engine/router.js +3 -3
  68. package/dist/engine/router.js.map +1 -1
  69. package/dist/index.js +108 -65
  70. package/dist/index.js.map +1 -1
  71. package/dist/sandbox/docker.d.ts +33 -1
  72. package/dist/sandbox/docker.js +95 -1
  73. package/dist/sandbox/docker.js.map +1 -1
  74. package/dist/sandbox/k8s/kubernetes-sandbox.d.ts +3 -0
  75. package/dist/sandbox/k8s/kubernetes-sandbox.js +9 -0
  76. package/dist/sandbox/k8s/kubernetes-sandbox.js.map +1 -1
  77. package/dist/sandbox/k8s/pod.d.ts +11 -0
  78. package/dist/sandbox/k8s/pod.js +11 -6
  79. package/dist/sandbox/k8s/pod.js.map +1 -1
  80. package/dist/sandbox/k8s/service-containers.d.ts +43 -0
  81. package/dist/sandbox/k8s/service-containers.js +87 -0
  82. package/dist/sandbox/k8s/service-containers.js.map +1 -0
  83. package/dist/sandbox/reap.d.ts +9 -0
  84. package/dist/sandbox/reap.js +36 -0
  85. package/dist/sandbox/reap.js.map +1 -1
  86. package/dist/sandbox/sandbox.d.ts +14 -0
  87. package/dist/sandbox/sandbox.js +9 -0
  88. package/dist/sandbox/sandbox.js.map +1 -1
  89. package/dist/sandbox/service-containers-docker.d.ts +45 -0
  90. package/dist/sandbox/service-containers-docker.js +78 -0
  91. package/dist/sandbox/service-containers-docker.js.map +1 -0
  92. package/dist/state/approval-store.d.ts +23 -14
  93. package/dist/state/approval-store.js +137 -86
  94. package/dist/state/approval-store.js.map +1 -1
  95. package/dist/state/client.d.ts +105 -0
  96. package/dist/state/client.js +68 -0
  97. package/dist/state/client.js.map +1 -0
  98. package/dist/state/cron-run-store.d.ts +32 -12
  99. package/dist/state/cron-run-store.js +105 -39
  100. package/dist/state/cron-run-store.js.map +1 -1
  101. package/dist/state/db.d.ts +61 -23
  102. package/dist/state/db.js +171 -105
  103. package/dist/state/db.js.map +1 -1
  104. package/dist/state/dialect.d.ts +77 -0
  105. package/dist/state/dialect.js +129 -0
  106. package/dist/state/dialect.js.map +1 -0
  107. package/dist/state/execution-store.d.ts +124 -103
  108. package/dist/state/execution-store.js +569 -374
  109. package/dist/state/execution-store.js.map +1 -1
  110. package/dist/state/feedback-store.d.ts +20 -20
  111. package/dist/state/feedback-store.js +241 -187
  112. package/dist/state/feedback-store.js.map +1 -1
  113. package/dist/state/legacy-sqlite.d.ts +15 -0
  114. package/dist/state/legacy-sqlite.js +131 -0
  115. package/dist/state/legacy-sqlite.js.map +1 -0
  116. package/dist/state/repo-ref.d.ts +9 -4
  117. package/dist/state/repo-ref.js +12 -6
  118. package/dist/state/repo-ref.js.map +1 -1
  119. package/dist/state/schema/pg.d.ts +2788 -0
  120. package/dist/state/schema/pg.js +301 -0
  121. package/dist/state/schema/pg.js.map +1 -0
  122. package/dist/state/schema/sqlite.d.ts +3063 -0
  123. package/dist/state/schema/sqlite.js +391 -0
  124. package/dist/state/schema/sqlite.js.map +1 -0
  125. package/dist/state/team-store.d.ts +26 -13
  126. package/dist/state/team-store.js +140 -93
  127. package/dist/state/team-store.js.map +1 -1
  128. package/dist/state/user-store.d.ts +31 -13
  129. package/dist/state/user-store.js +180 -80
  130. package/dist/state/user-store.js.map +1 -1
  131. package/dist/state/workflow-run-store.d.ts +95 -56
  132. package/dist/state/workflow-run-store.js +419 -314
  133. package/dist/state/workflow-run-store.js.map +1 -1
  134. package/dist/workflows/admission.d.ts +4 -3
  135. package/dist/workflows/admission.js +34 -10
  136. package/dist/workflows/admission.js.map +1 -1
  137. package/dist/workflows/handlers/post-review.js +3 -3
  138. package/dist/workflows/handlers/post-review.js.map +1 -1
  139. package/dist/workflows/resume.js +22 -15
  140. package/dist/workflows/resume.js.map +1 -1
  141. package/dist/workflows/runner.js +27 -12
  142. package/dist/workflows/runner.js.map +1 -1
  143. package/dist/workflows/simple.d.ts +23 -0
  144. package/dist/workflows/simple.js +40 -16
  145. package/dist/workflows/simple.js.map +1 -1
  146. package/drizzle/pg/0000_init.sql +235 -0
  147. package/drizzle/pg/meta/0000_snapshot.json +1751 -0
  148. package/drizzle/pg/meta/_journal.json +13 -0
  149. package/drizzle/sqlite/0000_baseline.sql +257 -0
  150. package/drizzle/sqlite/0001_backfill_repo_refs.sql +74 -0
  151. package/drizzle/sqlite/meta/0000_snapshot.json +1593 -0
  152. package/drizzle/sqlite/meta/0001_snapshot.json +1593 -0
  153. package/drizzle/sqlite/meta/_journal.json +20 -0
  154. package/package.json +12 -6
  155. package/dist/state/migrate.d.ts +0 -15
  156. package/dist/state/migrate.js +0 -518
  157. package/dist/state/migrate.js.map +0 -1
@@ -0,0 +1,391 @@
1
+ /**
2
+ * Drizzle SQLite schema — the single declaration of the harness state DB.
3
+ *
4
+ * Transcribed from the legacy DDL it replaces: `src/state/migrate.ts` (the
5
+ * thirteen state tables, their `CREATE TABLE IF NOT EXISTS` bodies AND every
6
+ * historical `ALTER TABLE ADD COLUMN`) plus
7
+ * `src/connectors/messaging/session-manager.ts` (the two messaging tables,
8
+ * which self-migrated on a second schema owner). 15 tables, 25 named indexes.
9
+ *
10
+ * Three transcription rules, all load-bearing:
11
+ *
12
+ * 1. **Column order matches the FRESH legacy physical order** — CREATE-body
13
+ * columns first, then the ALTER-added ones in the order `migrate.ts` adds
14
+ * them. `tests/state/schema-equivalence.test.ts` compares `PRAGMA
15
+ * table_info` in cid order on the fresh-vs-fresh legs.
16
+ *
17
+ * Caveat, and the reason that test compares a legacy-shaped DB by NAME
18
+ * instead: `owner` is in both the CREATE body AND an `ALTER` for
19
+ * `executions` + `workflow_runs`. On a fresh DB the CREATE wins and the
20
+ * ALTER throws into a `catch {}`, so `owner` sits mid-table; on a DB
21
+ * upgraded from before the CREATE-body change the ALTER genuinely appended
22
+ * it, so it sits at the tail. No schema file can satisfy both, and it does
23
+ * not matter — SQLite and Drizzle both address columns by name.
24
+ *
25
+ * 2. **Index names are exact** — the equivalence test compares
26
+ * `sqlite_master` index rows by name, sql verbatim. sqlite-core has no
27
+ * `.desc()` on index columns (that API is pg-core only), so the five DESC
28
+ * keys use the `sql` expression form.
29
+ *
30
+ * 3. **`{ mode: "json" }` / `{ mode: "boolean" }` change the TypeScript type,
31
+ * not the emitted DDL** (still TEXT / INTEGER), so no data migration and no
32
+ * equivalence impact. Existing rows already hold valid JSON text and 0/1.
33
+ */
34
+ import { sql } from "drizzle-orm";
35
+ import { index, integer, primaryKey, real, sqliteTable, text, unique, uniqueIndex, } from "drizzle-orm/sqlite-core";
36
+ /**
37
+ * The append-only execution ledger — one row per agent invocation (a workflow
38
+ * phase, or a chat turn). Legacy: `migrate.ts` CREATE + the issue-#205 actor
39
+ * ALTERs + `session_id` + the usage-metric loop.
40
+ */
41
+ export const executions = sqliteTable("executions", {
42
+ id: text("id").primaryKey(),
43
+ triggerType: text("trigger_type").notNull(),
44
+ triggerId: text("trigger_id").notNull(),
45
+ skill: text("skill").notNull(),
46
+ // (owner, BARE repo) — see state/repo-ref.ts, the one place that rule is
47
+ // expressed. Present in the CREATE body AND ALTER-added; see rule 1 above.
48
+ owner: text("owner"),
49
+ repo: text("repo"),
50
+ issueNumber: integer("issue_number"),
51
+ startedAt: text("started_at").notNull(),
52
+ finishedAt: text("finished_at"),
53
+ // TRI-STATE: null means still in flight. `ExecutionRecord.success?:
54
+ // boolean` is optional for exactly this reason.
55
+ success: integer("success", { mode: "boolean" }),
56
+ error: text("error"),
57
+ turns: integer("turns"),
58
+ durationMs: integer("duration_ms"),
59
+ // ── historical ALTERs, in migrate.ts order ──
60
+ // issue #205 actor columns — added BEFORE session_id, so they sit right
61
+ // after duration_ms. Plain text: NOT json, NOT boolean.
62
+ triggeredBy: text("triggered_by"),
63
+ triggerActorType: text("trigger_actor_type"),
64
+ sessionId: text("session_id"),
65
+ costUsd: real("cost_usd"),
66
+ inputTokens: integer("input_tokens"),
67
+ cacheCreationInputTokens: integer("cache_creation_input_tokens"),
68
+ cacheReadInputTokens: integer("cache_read_input_tokens"),
69
+ outputTokens: integer("output_tokens"),
70
+ apiDurationMs: integer("api_duration_ms"),
71
+ stopReason: text("stop_reason"),
72
+ workflowRunId: text("workflow_run_id"),
73
+ outputText: text("output_text"),
74
+ extensionStatus: text("extension_status", { mode: "json" }).$type(),
75
+ skillsStatus: text("skills_status", { mode: "json" }).$type(),
76
+ }, (t) => [
77
+ index("idx_executions_trigger").on(t.triggerType, t.triggerId),
78
+ index("idx_executions_skill").on(t.skill, t.startedAt),
79
+ index("idx_executions_workflow_run").on(t.workflowRunId, t.skill),
80
+ ]);
81
+ /**
82
+ * The per-run aggregate a workflow advances phase by phase. Legacy:
83
+ * `migrate.ts` CREATE + the actor ALTERs + `scratch` + `restart_count` +
84
+ * `owner` (which carries a one-time data backfill) + `trace_id`/`span_id`.
85
+ */
86
+ export const workflowRuns = sqliteTable("workflow_runs", {
87
+ id: text("id").primaryKey(),
88
+ workflowName: text("workflow_name").notNull(),
89
+ triggerId: text("trigger_id").notNull(),
90
+ // Same (owner, BARE repo) pair as the executions ledger; same CREATE-plus-
91
+ // ALTER duplication (rule 1).
92
+ owner: text("owner"),
93
+ repo: text("repo"),
94
+ issueNumber: integer("issue_number"),
95
+ currentPhase: text("current_phase").notNull(),
96
+ // list() omits `context`/`scratch` for payload size but DOES select
97
+ // phase_history and parses it unconditionally — so this one stays
98
+ // notNull with the '[]' default, or list() starts throwing.
99
+ phaseHistory: text("phase_history", { mode: "json" })
100
+ .$type()
101
+ .notNull()
102
+ .default(sql `'[]'`),
103
+ status: text("status").notNull().default("running"),
104
+ context: text("context", { mode: "json" }).$type(),
105
+ startedAt: text("started_at").notNull(),
106
+ updatedAt: text("updated_at").notNull(),
107
+ finishedAt: text("finished_at"),
108
+ // ── historical ALTERs, in migrate.ts order ──
109
+ triggeredBy: text("triggered_by"),
110
+ triggerActorType: text("trigger_actor_type"),
111
+ scratch: text("scratch", { mode: "json" }).$type(),
112
+ restartCount: integer("restart_count").notNull().default(0),
113
+ // The run's OTel trace/span context (issue #255) — a feedback signal can
114
+ // arrive days after the span closed, so we remember where the trace was.
115
+ traceId: text("trace_id"),
116
+ spanId: text("span_id"),
117
+ }, (t) => [
118
+ index("idx_workflow_runs_trigger").on(t.triggerId, t.status),
119
+ index("idx_workflow_runs_status").on(t.status),
120
+ // The dashboard's runs list is ORDER BY started_at DESC LIMIT 20 on a 5s
121
+ // poll — the DESC is a covering index, not decoration.
122
+ index("idx_workflow_runs_started_at").on(sql `${t.startedAt} DESC`),
123
+ // Mixed ASC+DESC composite: the one shape SQLite cannot satisfy by a
124
+ // reverse scan, so the DESC here is load-bearing.
125
+ index("idx_workflow_runs_name_started").on(t.workflowName, sql `${t.startedAt} DESC`),
126
+ ]);
127
+ /** Operator on/off + schedule overrides for cron jobs. Legacy: `migrate.ts`. */
128
+ export const cronOverrides = sqliteTable("cron_overrides", {
129
+ name: text("name").primaryKey(),
130
+ enabled: integer("enabled", { mode: "boolean" }).notNull().default(true),
131
+ schedule: text("schedule"),
132
+ updatedAt: text("updated_at").notNull(),
133
+ updatedBy: text("updated_by"),
134
+ });
135
+ /**
136
+ * One row per cron FIRE — scheduled or manual, `workflow:` or `handler:`.
137
+ * A zero-discovery fire dispatches nothing, so this is the only record it ran
138
+ * at all. Keyed on cron_name, never the workflow.
139
+ */
140
+ export const cronRuns = sqliteTable("cron_runs", {
141
+ id: text("id").primaryKey(),
142
+ cronName: text("cron_name").notNull(),
143
+ // A cron declares exactly one of these two — hence both nullable.
144
+ workflow: text("workflow"),
145
+ handler: text("handler"),
146
+ source: text("source").notNull(),
147
+ actor: text("actor"),
148
+ startedAt: text("started_at").notNull(),
149
+ finishedAt: text("finished_at"),
150
+ status: text("status").notNull().default("running"),
151
+ reposEligible: integer("repos_eligible"),
152
+ reposScanned: integer("repos_scanned"),
153
+ discovered: integer("discovered"),
154
+ dispatched: integer("dispatched"),
155
+ failures: integer("failures"),
156
+ error: text("error"),
157
+ }, (t) => [index("idx_cron_runs_name_started").on(t.cronName, sql `${t.startedAt} DESC`)]);
158
+ /** Operator on/off overrides for workflows. Legacy: `migrate.ts`. */
159
+ export const workflowOverrides = sqliteTable("workflow_overrides", {
160
+ name: text("name").primaryKey(),
161
+ enabled: integer("enabled", { mode: "boolean" }).notNull().default(true),
162
+ updatedAt: text("updated_at").notNull(),
163
+ updatedBy: text("updated_by"),
164
+ });
165
+ /** Approval / reply gates a paused run is waiting on. */
166
+ export const workflowApprovals = sqliteTable("workflow_approvals", {
167
+ id: text("id").primaryKey(),
168
+ workflowRunId: text("workflow_run_id").notNull(),
169
+ gate: text("gate").notNull(),
170
+ summary: text("summary").notNull(),
171
+ status: text("status").notNull().default("pending"),
172
+ requestedBy: text("requested_by"),
173
+ respondedBy: text("responded_by"),
174
+ response: text("response"),
175
+ respondedAt: text("responded_at"),
176
+ createdAt: text("created_at").notNull(),
177
+ // ── historical ALTERs ──
178
+ // Gate flavor: 'approve' (explicit approve/reject) vs 'reply' (resolves on
179
+ // any free-form reply in the same thread).
180
+ kind: text("kind").notNull().default("approve"),
181
+ // A handoff-doc FILENAME ('architect-plan.md') — never JSON, and queried
182
+ // with `WHERE artifact = ?`. Plain text on purpose.
183
+ artifact: text("artifact"),
184
+ }, (t) => [
185
+ index("idx_approvals_workflow").on(t.workflowRunId),
186
+ index("idx_approvals_status").on(t.status),
187
+ ]);
188
+ /**
189
+ * First-class user identity (issue #205) — an ADDITIVE enrichment table
190
+ * LEFT-JOINed on `login`. `github_id` / `slack_user_id` are the stable upsert
191
+ * keys; `email` is indexed but deliberately NOT unique (shared mailboxes).
192
+ */
193
+ export const users = sqliteTable("users", {
194
+ id: text("id").primaryKey(),
195
+ githubId: integer("github_id").unique(),
196
+ login: text("login").unique(),
197
+ name: text("name"),
198
+ email: text("email"),
199
+ avatarUrl: text("avatar_url"),
200
+ slackUserId: text("slack_user_id").unique(),
201
+ isBlocked: integer("is_blocked", { mode: "boolean" }).notNull().default(false),
202
+ emailIsPlaceholder: integer("email_is_placeholder", { mode: "boolean" })
203
+ .notNull()
204
+ .default(false),
205
+ createdAt: text("created_at").notNull(),
206
+ updatedAt: text("updated_at").notNull(),
207
+ lastLoginAt: text("last_login_at"),
208
+ }, (t) => [
209
+ // idx_users_login and idx_users_slack duplicate the column-level UNIQUE
210
+ // autoindexes. Declared anyway: omit them and `drizzle-kit generate` emits
211
+ // a DROP INDEX against production.
212
+ index("idx_users_login").on(t.login),
213
+ index("idx_users_email").on(t.email),
214
+ index("idx_users_slack").on(t.slackUserId),
215
+ ]);
216
+ /**
217
+ * One row per reactable artefact the bot posted, and the run it came from
218
+ * (issue #255). Written when we POST (Slack) or when a run finishes (GitHub
219
+ * discovery) — the only moments the association is free.
220
+ */
221
+ export const feedbackAnchors = sqliteTable("feedback_anchors", {
222
+ id: text("id").primaryKey(),
223
+ source: text("source").notNull(),
224
+ kind: text("kind").notNull(),
225
+ // Slack ts or the GitHub comment/issue id. TEXT for both: a Slack ts is
226
+ // not a number, and a GitHub id read back as a float loses precision.
227
+ externalId: text("external_id").notNull(),
228
+ nodeId: text("node_id"),
229
+ // '' is a SENTINEL, not an oversight: SQLite treats NULLs as DISTINCT in a
230
+ // UNIQUE, so a NULL here would make the constraint below (and the
231
+ // ON CONFLICT targeting it) silently inoperative for every GitHub anchor.
232
+ // The store maps '' ↔ null at its boundary.
233
+ channel: text("channel").notNull().default(""),
234
+ owner: text("owner"),
235
+ repo: text("repo"),
236
+ issueNumber: integer("issue_number"),
237
+ // Nullable on purpose: a bot comment we cannot tie to a run is still
238
+ // worth anchoring — dropping it loses the reaction, not just the run.
239
+ workflowRunId: text("workflow_run_id"),
240
+ workflowName: text("workflow_name"),
241
+ messagingSessionId: text("messaging_session_id"),
242
+ createdAt: text("created_at").notNull(),
243
+ lastPolledAt: text("last_polled_at"),
244
+ }, (t) => [
245
+ unique().on(t.source, t.channel, t.externalId),
246
+ // Duplicates the UNIQUE autoindex above — same columns, same order.
247
+ // Declared anyway, for the same DROP INDEX reason as idx_users_login.
248
+ index("idx_feedback_anchors_lookup").on(t.source, t.channel, t.externalId),
249
+ index("idx_feedback_anchors_run").on(t.workflowRunId),
250
+ // The poller's rotation: least-recently-polled first, within the window.
251
+ index("idx_feedback_anchors_poll").on(t.source, t.createdAt, t.lastPolledAt),
252
+ ]);
253
+ /**
254
+ * One row per (anchor, reactor, emoji) — a 👍/👎 scored against the run that
255
+ * wrote the thing reacted to. Attribution columns are denormalized from the
256
+ * anchor because they never change for a given anchor.
257
+ */
258
+ export const feedbackSignals = sqliteTable("feedback_signals", {
259
+ id: text("id").primaryKey(),
260
+ // A logical reference to feedback_anchors.id with NO `REFERENCES` clause
261
+ // in the legacy DDL — keep it a plain column.
262
+ anchorId: text("anchor_id").notNull(),
263
+ source: text("source").notNull(),
264
+ workflowRunId: text("workflow_run_id"),
265
+ workflowName: text("workflow_name"),
266
+ messagingSessionId: text("messaging_session_id"),
267
+ owner: text("owner"),
268
+ repo: text("repo"),
269
+ issueNumber: integer("issue_number"),
270
+ emoji: text("emoji").notNull(),
271
+ // −2..+2; 0 means "recorded, not scored". A real number, NOT a boolean.
272
+ score: integer("score").notNull(),
273
+ sentiment: text("sentiment").notNull(),
274
+ reactor: text("reactor"),
275
+ reactedAt: text("reacted_at"),
276
+ observedAt: text("observed_at").notNull(),
277
+ // Retracting rather than deleting keeps "somebody thumbed this and then
278
+ // thought better of it" visible; every score query filters IS NULL.
279
+ removedAt: text("removed_at"),
280
+ // OTel export watermark — null means not yet exported.
281
+ exportedAt: text("exported_at"),
282
+ }, (t) => [
283
+ // `reactor` is nullable, so unlike the anchors table this does NOT bind
284
+ // for null reactors. Transcribed as-is — do not "fix" it.
285
+ unique().on(t.anchorId, t.reactor, t.emoji),
286
+ index("idx_feedback_signals_anchor").on(t.anchorId),
287
+ index("idx_feedback_signals_run").on(t.workflowRunId),
288
+ index("idx_feedback_signals_observed").on(sql `${t.observedAt} DESC`),
289
+ index("idx_feedback_signals_workflow").on(t.workflowName, sql `${t.observedAt} DESC`),
290
+ index("idx_feedback_signals_export").on(t.exportedAt),
291
+ ]);
292
+ // ── GitHub team-based dashboard visibility (issue #169) ──────────────────────
293
+ // A CACHE, not a mirror of the org: rows appear only for the teams of somebody
294
+ // who actually logged in. Absence means "unknown", never "no access", so every
295
+ // read path fails open. Safe to delete wholesale; it refills.
296
+ /** One row per team we have ever resolved repos for. */
297
+ export const githubTeams = sqliteTable("github_teams", {
298
+ org: text("org").notNull(),
299
+ slug: text("slug").notNull(),
300
+ name: text("name"),
301
+ reposSyncedAt: text("repos_synced_at").notNull(),
302
+ // True when enumeration hit the per-team page budget and stopped early, so
303
+ // github_team_repos is a PREFIX of the real grant — its members must then
304
+ // fail open.
305
+ truncated: integer("truncated", { mode: "boolean" }).notNull().default(false),
306
+ }, (t) => [primaryKey({ columns: [t.org, t.slug] })]);
307
+ /**
308
+ * A team's grant, already intersected with the managed-repo set. `repo` holds
309
+ * the QUALIFIED owner/repo full name — unlike everywhere else post-#279, so
310
+ * the bare-repo rule does not apply here.
311
+ */
312
+ export const githubTeamRepos = sqliteTable("github_team_repos", {
313
+ org: text("org").notNull(),
314
+ // (org, team_slug) logically references github_teams.(org, slug) — note
315
+ // the column-name mismatch and that no FK is declared. Keep it that way.
316
+ teamSlug: text("team_slug").notNull(),
317
+ repo: text("repo").notNull(),
318
+ }, (t) => [primaryKey({ columns: [t.org, t.teamSlug, t.repo] })]);
319
+ /** Membership we have LEARNED, not enumerated. */
320
+ export const githubTeamMembers = sqliteTable("github_team_members", {
321
+ org: text("org").notNull(),
322
+ teamSlug: text("team_slug").notNull(),
323
+ login: text("login").notNull(),
324
+ }, (t) => [
325
+ primaryKey({ columns: [t.org, t.teamSlug, t.login] }),
326
+ // reposForLogin joins membership → team_repos on this column.
327
+ index("idx_github_team_members_login").on(t.login),
328
+ ]);
329
+ /**
330
+ * Per-login freshness + outcome, so a resolution that failed or blew its
331
+ * request budget is remembered for the TTL rather than retried on every poll.
332
+ * status is one of: ok | empty | truncated | error | disabled.
333
+ */
334
+ export const githubVisibilitySync = sqliteTable("github_visibility_sync", {
335
+ login: text("login").primaryKey(),
336
+ syncedAt: text("synced_at").notNull(),
337
+ status: text("status").notNull(),
338
+ detail: text("detail"),
339
+ });
340
+ /**
341
+ * Per-thread messaging conversations. Legacy owner: `SessionManager`, which
342
+ * self-migrated this DDL against the raw handle.
343
+ */
344
+ export const messagingSessions = sqliteTable("messaging_sessions", {
345
+ id: text("id").primaryKey(),
346
+ platform: text("platform").notNull(),
347
+ channelId: text("channel_id").notNull(),
348
+ // Nullable while being a key column of the unique index below, so
349
+ // DM-style sessions with no thread do not collide.
350
+ threadId: text("thread_id"),
351
+ userId: text("user_id").notNull(),
352
+ agentSessionId: text("agent_session_id"),
353
+ createdAt: text("created_at").notNull(),
354
+ lastActivityAt: text("last_activity_at").notNull(),
355
+ // These two are the only DEFAULT-without-NOT-NULL columns in the schema —
356
+ // everything else pairs them. Transcribed as-is. Since `active` is the
357
+ // partial index's predicate, a NULL-active row is exempt from uniqueness.
358
+ messageCount: integer("message_count").default(0),
359
+ active: integer("active", { mode: "boolean" }).default(true),
360
+ }, (t) => [
361
+ index("idx_msg_sessions_lookup").on(t.platform, t.channelId, t.threadId, t.userId),
362
+ // "One ACTIVE session per key". Do NOT restore the table-level
363
+ // UNIQUE(platform, channel_id, thread_id, user_id) this replaced: a
364
+ // deactivated row occupied the key, so a returning user could never start
365
+ // a new session. SessionManager.rebuildWithoutTableUnique() exists purely
366
+ // to strip that constraint from databases still carrying it.
367
+ uniqueIndex("idx_msg_sessions_unique_active")
368
+ .on(t.platform, t.channelId, t.threadId, t.userId)
369
+ .where(sql `active = 1`),
370
+ ]);
371
+ /** Turn-by-turn transcript for a messaging session. */
372
+ export const messagingMessages = sqliteTable("messaging_messages", {
373
+ // The only AUTOINCREMENT in the schema; inserts never supply an id.
374
+ id: integer("id").primaryKey({ autoIncrement: true }),
375
+ // The ONLY declared foreign key in the entire 15-table schema (no ON
376
+ // DELETE), and it is LIVE. Nothing sets `PRAGMA foreign_keys` explicitly,
377
+ // which used to be read as "so it is declared-but-unenforced" — that was
378
+ // wrong: better-sqlite3 and libsql BOTH default it on (verified on
379
+ // @libsql/client 0.17 and better-sqlite3 13 — an orphan insert is rejected
380
+ // by each). So it has always bitten in production, and it still does. The
381
+ // legacy messaging rebuild toggles it off around the table swap precisely
382
+ // because it is enforced (see `state/legacy-sqlite.ts`).
383
+ sessionId: text("session_id")
384
+ .notNull()
385
+ .references(() => messagingSessions.id),
386
+ role: text("role").notNull(),
387
+ content: text("content").notNull(),
388
+ timestamp: text("timestamp").notNull(),
389
+ platformMessageId: text("platform_message_id"),
390
+ }, (t) => [index("idx_msg_messages_session").on(t.sessionId, t.timestamp)]);
391
+ //# sourceMappingURL=sqlite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite.js","sourceRoot":"","sources":["../../../src/state/schema/sqlite.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EACL,KAAK,EACL,OAAO,EACP,UAAU,EACV,IAAI,EACJ,WAAW,EACX,IAAI,EACJ,MAAM,EACN,WAAW,GACZ,MAAM,yBAAyB,CAAC;AAIjC;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,WAAW,CACnC,YAAY,EACZ;IACE,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE;IAC3B,WAAW,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC,OAAO,EAAE;IAC3C,SAAS,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE;IACvC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE;IAC9B,yEAAyE;IACzE,2EAA2E;IAC3E,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC;IACpB,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC;IAClB,WAAW,EAAE,OAAO,CAAC,cAAc,CAAC;IACpC,SAAS,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE;IACvC,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC;IAC/B,oEAAoE;IACpE,gDAAgD;IAChD,OAAO,EAAE,OAAO,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;IAChD,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC;IACpB,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC;IACvB,UAAU,EAAE,OAAO,CAAC,aAAa,CAAC;IAClC,+CAA+C;IAC/C,wEAAwE;IACxE,wDAAwD;IACxD,WAAW,E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ACF,CAAC;AAEF,uDAAuD;AACvD,MAAM,CAAC,MAAM,iBAAiB,GAAG,WAAW,CAC1C,oBAAoB,EACpB;IACE,oEAAoE;IACpE,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;IACrD,qEAAqE;IACrE,0EAA0E;IAC1E,yEAAyE;IACzE,mEAAmE;IACnE,2EAA2E;IAC3E,0EAA0E;IAC1E,0EAA0E;IAC1E,yDAAyD;IACzD,SAAS,EAAE,IAAI,CAAC,YAAY,CAAC;SAC1B,OAAO,EAAE;SACT,UAAU,CAAC,GAAG,EAAE,CAAC,iBAAiB,CAAC,EAAE,CAAC;IACzC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE;IAC5B,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE;IAClC,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE;IACtC,iBAAiB,EAAE,IAAI,CAAC,qBAAqB,CAAC;CAC/C,EACD,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CACxE,CAAC"}
@@ -1,4 +1,4 @@
1
- import type Database from "better-sqlite3";
1
+ import { type OpSerializer, type StateClient } from "./client.js";
2
2
  /**
3
3
  * Outcome of the last visibility resolution for one login.
4
4
  *
@@ -53,12 +53,25 @@ export interface CachedVisibility {
53
53
  * fails open rather than hiding repos.
54
54
  *
55
55
  * Mirrors the other per-table stores ({@link ExecutionStore} /
56
- * {@link UserStore}): constructed from the single shared `Database`, every
57
- * multi-row write wrapped in one transaction.
56
+ * {@link UserStore}): constructed from the single shared Drizzle client, every
57
+ * multi-row write wrapped in one transaction. Those four transactions run
58
+ * through the **connection-scoped** `serialize` mutex, the same instance
59
+ * {@link WorkflowRunStore} uses — a store-scoped chain would leave a team
60
+ * resolution free to overlap a run transaction on this one libsql client, which
61
+ * is exactly the interleaving libsql handles badly.
58
62
  */
59
63
  export declare class TeamStore {
60
- private db;
61
- constructor(db: Database.Database);
64
+ private client;
65
+ private serialize;
66
+ /**
67
+ * Table objects for THIS client's dialect. Every method destructures what it
68
+ * needs off this instead of importing from `schema/sqlite.js` — see
69
+ * `client.ts` → {@link tablesOf} for why the cast alone cannot do it.
70
+ */
71
+ private readonly t;
72
+ constructor(client: StateClient, deps: {
73
+ serialize: OpSerializer;
74
+ });
62
75
  /**
63
76
  * Replace everything known about ONE login in a single transaction: the teams
64
77
  * it belongs to, each of those teams' managed-repo grant, and the freshness
@@ -74,24 +87,24 @@ export declare class TeamStore {
74
87
  status: VisibilitySyncStatus;
75
88
  detail?: string;
76
89
  at?: string;
77
- }): void;
90
+ }): Promise<void>;
78
91
  /** The freshness/outcome row for a login, or null if never resolved. */
79
- getSync(login: string): VisibilitySync | null;
92
+ getSync(login: string): Promise<VisibilitySync | null>;
80
93
  /**
81
94
  * Whether a login's cached answer is still inside `ttlMs`. A missing row is
82
95
  * never fresh; a `synced_at` we can't parse is treated as stale rather than
83
96
  * trusted forever.
84
97
  */
85
- isFresh(login: string, ttlMs: number, now?: number): boolean;
98
+ isFresh(login: string, ttlMs: number, now?: number): Promise<boolean>;
86
99
  /**
87
100
  * Everything the cache knows about a login, joined membership → team_repos.
88
101
  * The caller intersects with the live managed-repo list; this returns what was
89
102
  * stored, which was already intersected at write time (a repo unmanaged since
90
103
  * then must not reappear just because a team still grants it).
91
104
  */
92
- reposForLogin(login: string): CachedVisibility;
105
+ reposForLogin(login: string): Promise<CachedVisibility>;
93
106
  /** Forget one login's answer — it will be re-resolved on the next request. */
94
- invalidateLogin(login: string): void;
107
+ invalidateLogin(login: string): Promise<void>;
95
108
  /**
96
109
  * Forget one team — its grant AND every member's cached answer, because their
97
110
  * visible-repo set was derived from it. Called from the `team` webhook, where
@@ -100,9 +113,9 @@ export declare class TeamStore {
100
113
  * Returns the logins whose answers were dropped, so the caller can log the
101
114
  * blast radius of an org-side change.
102
115
  */
103
- invalidateTeam(org: string, slug: string): string[];
116
+ invalidateTeam(org: string, slug: string): Promise<string[]>;
104
117
  /** Drop the whole cache (admin re-sync, or an `organization` event we can't scope). */
105
- invalidateAll(): void;
118
+ invalidateAll(): Promise<void>;
106
119
  /** Most recent successful resolution across all logins — powers the coarse `synced` flag. */
107
- lastSyncedAt(): string | null;
120
+ lastSyncedAt(): Promise<string | null>;
108
121
  }