mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 18:07:52 +01:00
Pre-v2.1 the prompt library was 41 templates baked into
src/config/prompt-library.ts. Users couldn't add their own, pin to a
project, or capture successful ad-hoc dispatches. v2.1 is the
structural fix — each user can now create their own prompts that
merge with the FC defaults on /prompts.
Multi-disciplinary design (product · UX · engineer · prompt engineer):
- Product: prompts are repeatable work units; users need their own +
per-project recipes. Library grows with use.
- UX: user-owned section above FC defaults; +New button opens an
inline form (modal in v2.2 if needed); edit/delete on each card;
scope toggle global vs project.
- Engineer: new prompts table (user_id, scope, project_id nullable,
body, variables JSONB, tags, source, run_count, success_count).
Migration applied to Hetzner.
- Prompt engineer: body supports {{name}} and {{name|default}}
placeholders; parsed once at insert time into a variables[] array
so v2.2's variables-at-run modal doesn't re-parse.
Shipped:
+ drizzle/0025_prompts.sql (applied to Hetzner)
+ src/db/schema/prompts.ts
+ src/db/queries/prompts.ts — parsePromptVariables, renderPromptBody,
CRUD helpers, listPromptsForUser, listPromptsForProject
+ src/app/api/prompts/route.ts (GET list, POST create)
+ src/app/api/prompts/[id]/route.ts (GET, PATCH, DELETE soft)
+ src/components/prompts/UserPromptsSection.tsx — list + inline
create / edit form with scope picker, tags, body textarea,
variable-syntax hint
~ src/components/prompts/PromptLibraryClient.tsx — accepts
optional userPrompts prop; renders UserPromptsSection above the
FC-defaults grid
~ src/app/(app)/prompts/page.tsx — fetches user prompts via
listPromptsForUser and passes to the client component
Roadmap noted in comments:
- v2.2: variables-at-run modal (quick-fill {{name}} placeholders
before sending)
- v2.3: "Save as prompt" capture from /history rows
- v2.3: success-rate analytics from orchestration_runs.outcome
- v2.4: scheduled prompts (cron, integrates with the autonomous
scheduler shipped in Change 5)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
37 lines
1.6 KiB
SQL
37 lines
1.6 KiB
SQL
-- User-owned prompt library — Prompt Library v2.1.
|
|
--
|
|
-- The 41 FleetCrown default prompts stay in src/config/prompt-library.ts.
|
|
-- This table is for user-created and project-/org-scoped prompts. The
|
|
-- /prompts page merges both sources at render time.
|
|
--
|
|
-- Variables: bodies use {{name}} or {{name|default}} placeholders. The
|
|
-- variables JSONB column is the declared SSOT — run-time UI renders inputs
|
|
-- per entry without re-parsing the body.
|
|
--
|
|
-- Mirrors src/db/schema/prompts.ts.
|
|
|
|
CREATE TABLE IF NOT EXISTS prompts (
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
name TEXT NOT NULL,
|
|
description TEXT,
|
|
body TEXT NOT NULL,
|
|
scope TEXT NOT NULL DEFAULT 'global',
|
|
project_id UUID REFERENCES entities(id) ON DELETE CASCADE,
|
|
org_id UUID REFERENCES orgs(id) ON DELETE CASCADE,
|
|
tags JSONB NOT NULL DEFAULT '[]'::jsonb,
|
|
variables JSONB NOT NULL DEFAULT '[]'::jsonb,
|
|
source TEXT NOT NULL DEFAULT 'user',
|
|
forked_from_key TEXT,
|
|
run_count INTEGER NOT NULL DEFAULT 0,
|
|
success_count INTEGER NOT NULL DEFAULT 0,
|
|
is_active BOOLEAN NOT NULL DEFAULT true,
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_prompts_user_id ON prompts (user_id);
|
|
CREATE INDEX IF NOT EXISTS idx_prompts_project_id ON prompts (project_id);
|
|
CREATE INDEX IF NOT EXISTS idx_prompts_scope ON prompts (scope);
|
|
CREATE INDEX IF NOT EXISTS idx_prompts_active ON prompts (user_id, is_active);
|