Feature 09: AI harness and skills framework (#62)
Co-authored-by: dev_agent <dev_agent@cubecraftlabs.com>
This commit was merged in pull request #62.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
-- 0006_ai_runs_status: ai_runs.status becomes the harness run outcome:
|
||||
-- ok the first reply was usable
|
||||
-- repaired the first reply was not, the repair turn's was
|
||||
-- bad_output neither reply was usable, or post-processing failed
|
||||
-- provider_error the provider failed on either turn
|
||||
-- A run's row is written once, when it ends, so there is no running state.
|
||||
-- Nothing wrote ai_runs before the harness did, so no row holds the old
|
||||
-- running or error values; if one does, the copy back fails the CHECK and
|
||||
-- the migration stops rather than guess its outcome. created_at gains an
|
||||
-- index for the 30-day purge. The rebuild is 0005's: copy the rows aside,
|
||||
-- drop the table, create it again, copy the rows back and drop the copy.
|
||||
--
|
||||
-- suggestion_batches.ai_run_id and week_plans.ai_run_id reference ai_runs,
|
||||
-- so foreign keys are deferred until commit, after the ai_runs rows are
|
||||
-- back. The pragma lasts only for this migration's transaction.
|
||||
|
||||
PRAGMA defer_foreign_keys = ON;
|
||||
|
||||
CREATE TABLE ai_runs_copy AS SELECT * FROM ai_runs;
|
||||
|
||||
DROP TABLE ai_runs;
|
||||
|
||||
CREATE TABLE ai_runs (
|
||||
id TEXT NOT NULL PRIMARY KEY,
|
||||
skill TEXT NOT NULL,
|
||||
skill_version TEXT NOT NULL,
|
||||
provider TEXT NOT NULL CHECK (provider IN ('openai_compatible', 'anthropic', 'ollama', 'openai', 'openrouter', 'xai')),
|
||||
model TEXT NOT NULL,
|
||||
temperature REAL NOT NULL,
|
||||
status TEXT NOT NULL CHECK (status IN ('ok', 'repaired', 'bad_output', 'provider_error')),
|
||||
latency_ms INTEGER,
|
||||
tokens_in INTEGER,
|
||||
tokens_out INTEGER,
|
||||
error TEXT,
|
||||
request_redacted TEXT NOT NULL,
|
||||
response_redacted TEXT,
|
||||
created_at TEXT NOT NULL,
|
||||
updated_at TEXT NOT NULL
|
||||
);
|
||||
|
||||
INSERT INTO ai_runs (id, skill, skill_version, provider, model, temperature, status, latency_ms, tokens_in, tokens_out, error, request_redacted, response_redacted, created_at, updated_at)
|
||||
SELECT id, skill, skill_version, provider, model, temperature, status, latency_ms, tokens_in, tokens_out, error, request_redacted, response_redacted, created_at, updated_at
|
||||
FROM ai_runs_copy;
|
||||
|
||||
DROP TABLE ai_runs_copy;
|
||||
|
||||
CREATE INDEX ai_runs_created_at ON ai_runs (created_at);
|
||||
@@ -0,0 +1,28 @@
|
||||
-- name: CreateAIRun :exec
|
||||
INSERT INTO ai_runs (
|
||||
id, skill, skill_version, provider, model, temperature, status,
|
||||
latency_ms, tokens_in, tokens_out, error, request_redacted,
|
||||
response_redacted, created_at, updated_at
|
||||
) VALUES (
|
||||
?, ?, ?, ?, ?, ?, ?,
|
||||
?, ?, ?, ?, ?,
|
||||
?, ?, ?
|
||||
);
|
||||
|
||||
-- name: ClearSuggestionBatchAIRunsBefore :execrows
|
||||
-- Drops references to the runs created before the cutoff, so the purge
|
||||
-- can delete them.
|
||||
UPDATE suggestion_batches
|
||||
SET ai_run_id = NULL
|
||||
WHERE ai_run_id IN (SELECT ai_runs.id FROM ai_runs WHERE ai_runs.created_at < sqlc.arg(cutoff));
|
||||
|
||||
-- name: ClearWeekPlanAIRunsBefore :execrows
|
||||
-- Drops references to the runs created before the cutoff, so the purge
|
||||
-- can delete them.
|
||||
UPDATE week_plans
|
||||
SET ai_run_id = NULL
|
||||
WHERE ai_run_id IN (SELECT ai_runs.id FROM ai_runs WHERE ai_runs.created_at < sqlc.arg(cutoff));
|
||||
|
||||
-- name: DeleteAIRunsBefore :execrows
|
||||
DELETE FROM ai_runs
|
||||
WHERE created_at < sqlc.arg(cutoff);
|
||||
@@ -0,0 +1,19 @@
|
||||
-- Reads for the AI household context block (internal/ai/harness).
|
||||
|
||||
-- name: ListRecentDeclinedNames :many
|
||||
-- The names of the most recently declined suggestions, newest first.
|
||||
SELECT dinners.name
|
||||
FROM suggestions
|
||||
JOIN dinners ON dinners.id = suggestions.dinner_id
|
||||
WHERE suggestions.status = 'declined'
|
||||
ORDER BY suggestions.decided_at DESC, suggestions.id DESC
|
||||
LIMIT ?;
|
||||
|
||||
-- name: ListPlannedDinners :many
|
||||
-- The planned dinners dated from from_date up to but not including
|
||||
-- to_date, oldest first. Days with no dinner are left out.
|
||||
SELECT plan_days.date, dinners.name
|
||||
FROM plan_days
|
||||
JOIN dinners ON dinners.id = plan_days.dinner_id
|
||||
WHERE plan_days.date >= sqlc.arg(from_date) AND plan_days.date < sqlc.arg(to_date)
|
||||
ORDER BY plan_days.date, plan_days.id;
|
||||
Reference in New Issue
Block a user