mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-05 03:47:53 +01:00
Closes the gap Cursor's audit named and Claude's response confirmed:
auto-inject had become 'generic next_best ladder' instead of
'context-aware prompt that drives the product forward.' Thirty commits
of plumbing (status field, queue in DB, daemon heartbeat, /tmp mirror)
didn't change what the model reads when it wakes up. This commit does.
Full reasoning + design in content/thoughts/strategist-and-prompt-quality.md.
Changes (in order of blast radius):
1. /api/control/dispatch — strategist v1 (the meat)
• DispatchAction expands from 'queue | nextbest' to add 'composed'
and 'off'.
• DispatchResult.prompt holds the Groq-composed body when
action='composed'.
• Groq prompt asks for one of three actions + an optional PROMPT:
body. The composer drafts a fresh prompt from handoff.next,
queue tail, recent commits, and outcome streak — concrete verbs,
named files where possible, ≤2000 chars.
• maxTokens 100 → 1500 so the composed body has room.
• Reads auto_inject_mode from beacon_settings and gates:
off → action='off' (suppress), queue_only → queue or off,
next_best → skip Groq + return nextbest, strategist → full chain.
• Strategist now runs even with empty queue — that's when it's
most valuable (smart nudge from session.next + commits alone).
Previously short-circuited to nextbest on empty queue.
2. src/lib/orchestration/renderers.ts — SSOT next_best body
• Adopts the bash hook's shape (the concrete one user has been
pasting every loop turn). Old abstract scan ladder is gone.
• Model-agnostic: avoids assumed tech stack (no hardcoded `git
status` / `npx tsc`). Verifies via 'are there type/lint/compile
errors' phrasing that translates across runtimes.
3. src/hooks/use-project-card-actions.ts — consume composed bodies
• handleAutoInject branches on action='composed' and injects the
returned prompt body as a custom prompt instead of firing
sendIntent('next_best').
• Respects action='off' from mode_gate by returning early.
• Pre-fetch fires whenever ready (not gated on queue.length > 0)
so the strategist can compose even when queue is empty.
4. beacon_settings.auto_inject_mode (drizzle/0011)
• New text column, default 'strategist'. Values: strategist |
queue_only | next_best | off.
• Schema TS + queries plumbed; UI carryover patched in
BeaconSettings.tsx (full UI for the toggle is a follow-up).
5. /api/control/runtime-state — defensive against duplicate keys
• Found two rows for same lowercase project_key ('cockpit' and
'Cockpit', empty queue won iteration order). Sync now groups
by lowercase and prefers the row with the longest queue. The
duplicate row was deleted from Neon as a one-time fix; long-
term a uniqueness-on-lowercase migration is queued.
Migrations applied to Neon prod: 0011 via psql + neonctl. Local PG
is no longer authoritative (.env.local now points cockpit-app at
Neon; verified daemon-token auth resolves to default user b94a359d
and runtime-state sync writes /tmp/agent-queue-cockpit with the real
queue content).
Tests: tsc clean, eslint clean (src/ + home/), npm run test:home
89/89. UI for autoInjectMode toggle is queued.
Co-developed with: prompt-quality audit pass from Cursor Composer
2.5 + Claude synthesis; provenance + design rationale in
content/thoughts/strategist-and-prompt-quality.md.
18 lines
846 B
SQL
18 lines
846 B
SQL
-- Add auto_inject_mode to beacon_settings so users can opt out of the
|
|
-- strategist-composed auto-inject (default new behavior) and pick a
|
|
-- mode that fits their workflow:
|
|
--
|
|
-- strategist — DEFAULT: queue head → COMPOSED body → next_best fallback
|
|
-- queue_only — only fire queue items; never auto-compose or next_best
|
|
-- next_best — legacy: skip strategist call, fire canned template
|
|
-- off — disable auto-inject entirely (user must dispatch by hand)
|
|
--
|
|
-- Default value is 'strategist' for both new and existing users — the
|
|
-- new behavior is the intended product direction; users who prefer the
|
|
-- old ladder can flip this to 'next_best' explicitly.
|
|
--
|
|
-- Idempotent — re-runs without error.
|
|
|
|
ALTER TABLE "beacon_settings"
|
|
ADD COLUMN IF NOT EXISTS "auto_inject_mode" text NOT NULL DEFAULT 'strategist';
|