mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 11:07:40 +01:00
feat(db): add session_status column to project_states (migration 0009)
Completes scope cut #1 from yesterday's 27f31cb commit. The auto-inject
gate now reads status from project_states server-side (not just from
raw session.md content in the beacon), so the cloud /control flow
surfaces the agent's lifecycle state end-to-end.
Plumbing:
• src/db/schema/project-states.ts — sessionStatus column declared
(text, nullable). Position: before sessionDone so the SELECT row
shape reads top-down as status → done → next → ... → health.
• drizzle/0009_project_states_session_status.sql — idempotent
ADD COLUMN IF NOT EXISTS. Apply with drizzle-kit push (no
auto-runner; matches the 0001-0008 pattern).
• src/app/api/control/route.ts — both upsertProjectState callsites
(mtime-advanced + bootstrap) now persist session.status.
• src/app/api/control/stream/route.ts — SSE row construction reads
r.sessionStatus into session.status alongside the other fields.
• src/app/api/project-states/[key]/route.ts — PATCH body schema +
upsert object both accept sessionStatus for the daemon's push.
Migration safety:
• Column is nullable + new — existing rows get NULL.
• The auto-inject gate treats NULL/undefined as suppress (matches
the user's stated default: only fire on explicit 'ready').
• Idempotent SQL — re-applying the migration won't error.
Apply on production: \`DATABASE_URL=<neon> npx drizzle-kit push\` (or
the user's preferred migration runner).
tsc clean, npm run test:home 82/82.
Scope cut #2 remains queued: agent-hook-bridge.sh:emit_worker_finished
including session_status in worker.finished events (user denied prior
edits 3x — happy to ship if they want or leave it for them to land).
This commit is contained in:
5 files changed
+18
-1
No files matched your search
@@ -0,0 +1,13 @@
|
||||
-- Add session_status column to project_states.
|
||||
--
|
||||
-- Mirrors the new 'status' field in the canonical handoff format
|
||||
-- (src/lib/orchestration/contract.ts:ORCHESTRATION_TASK_SUMMARY_FIELDS).
|
||||
-- Value space: 'ready' | 'working' | NULL. The auto-inject gates in
|
||||
-- src/hooks/use-project-card-actions.ts and src/app/beacon/[id]/BeaconClient.tsx
|
||||
-- only fire when status === 'ready'; anything else (NULL included) suppresses.
|
||||
--
|
||||
-- Idempotent — `ADD COLUMN IF NOT EXISTS` lets the migration run more than
|
||||
-- once without erroring if the column already exists on a partially-migrated
|
||||
-- environment.
|
||||
|
||||
ALTER TABLE "project_states" ADD COLUMN IF NOT EXISTS "session_status" text;
|
||||
@@ -275,6 +275,7 @@ export async function GET() {
|
||||
projectId,
|
||||
userId: ownerUserId,
|
||||
tabName: liveTab,
|
||||
sessionStatus: session.status,
|
||||
sessionDone: session.done,
|
||||
sessionNext: session.next,
|
||||
sessionTests: session.tests,
|
||||
|
||||
@@ -35,7 +35,7 @@ function dbToFastState(
|
||||
tabOpen: r.tabOpen,
|
||||
activeAgents: r.activeAgents,
|
||||
session: r.sessionDone || r.sessionNext
|
||||
? { done: r.sessionDone ?? "", next: r.sessionNext ?? "", tests: r.sessionTests ?? "", todos: r.sessionTodos ?? "", health: r.sessionHealth ?? "", mtime: r.sessionUpdatedAt?.getTime() ?? 0 }
|
||||
? { status: r.sessionStatus ?? "", done: r.sessionDone ?? "", next: r.sessionNext ?? "", tests: r.sessionTests ?? "", todos: r.sessionTodos ?? "", health: r.sessionHealth ?? "", mtime: r.sessionUpdatedAt?.getTime() ?? 0 }
|
||||
: null,
|
||||
currentPrompt: r.currentPromptKey
|
||||
? { key: r.currentPromptKey, label: r.currentPromptLabel ?? r.currentPromptKey, startedAt: r.currentPromptStartedAt ? Math.floor(r.currentPromptStartedAt.getTime() / 1000) : 0, source: "inject" as const }
|
||||
|
||||
@@ -8,6 +8,7 @@ const PatchBody = z.object({
|
||||
readyAt: z.string().datetime().optional(),
|
||||
closingAt: z.string().datetime().optional(),
|
||||
closedAt: z.string().datetime().optional(),
|
||||
sessionStatus: z.string().optional(),
|
||||
sessionDone: z.string().optional(),
|
||||
sessionNext: z.string().optional(),
|
||||
sessionTests: z.string().optional(),
|
||||
@@ -40,6 +41,7 @@ export async function PATCH(
|
||||
readyAt: d.readyAt ? new Date(d.readyAt) : undefined,
|
||||
closingAt: d.closingAt ? new Date(d.closingAt) : undefined,
|
||||
closedAt: d.closedAt ? new Date(d.closedAt) : undefined,
|
||||
sessionStatus: d.sessionStatus,
|
||||
sessionDone: d.sessionDone,
|
||||
sessionNext: d.sessionNext,
|
||||
sessionTests: d.sessionTests,
|
||||
|
||||
@@ -14,6 +14,7 @@ export const projectStates = pgTable("project_states", {
|
||||
lockAt: timestamp("lock_at", { withTimezone: true }),
|
||||
closingAt: timestamp("closing_at", { withTimezone: true }),
|
||||
closedAt: timestamp("closed_at", { withTimezone: true }),
|
||||
sessionStatus: text("session_status"), // 'ready' | 'working' | null. Drives auto-inject gating — only 'ready' fires.
|
||||
sessionDone: text("session_done"),
|
||||
sessionNext: text("session_next"),
|
||||
sessionTests: text("session_tests"),
|
||||
|
||||
Reference in new issue
Block a user