Initial import of streamline

This commit is contained in:
2026-11-16 17:26:44 -08:00
commit 8e4aec1855
1221 changed files with 274256 additions and 0 deletions
+159
View File
@@ -0,0 +1,159 @@
-- RSI 闭环 — the platform measuring, proposing on, and changing its own method.
--
-- Five tables, three of which are the evidmon loop's shape re-pointed at fix
-- quality (snapshot → finding → strategy → approval → measured effect). They are
-- NOT a `domain` column on the evidmon tables: the two loops trend different
-- metrics on different cadences, and sharing a table would make every existing
-- evidmon query filter for a distinction it never cares about.
--
-- Nothing here decides anything on its own. A strategy leaves `proposed` only
-- because a logged-in owner said so, and `effective_at` is stamped at that
-- moment — so a before/after window can never be redrawn afterwards to flatter
-- the result. The analyst that WRITES proposals authenticates with the cluster
-- secret and is structurally unable to approve them.
-- One day's fix-quality metric tree (JSON QualitySnapshot). Written by
-- control-server/src/rsi_daily.ts on a machine timer, never by the analyst: a
-- day nobody analysed must still leave a data point, or the before/after series
-- grows holes exactly where an outage was.
CREATE TABLE IF NOT EXISTS "rsi_metrics_daily" (
"day" text PRIMARY KEY NOT NULL,
"generated_at" bigint NOT NULL,
"metrics" text NOT NULL
);
-- The research log. `clusters` holds the deterministic failure-mode grouping the
-- entry was written on top of, so a finding can always be traced back to the
-- concrete rejections that produced it rather than to a model's recollection.
CREATE TABLE IF NOT EXISTS "rsi_findings" (
"id" text PRIMARY KEY NOT NULL,
"day" text NOT NULL,
"title" text NOT NULL,
"summary" text NOT NULL,
"highlights" text,
"findings" text,
"metrics_snapshot" text,
"deltas" text,
"clusters" text,
"author" text NOT NULL,
"created_at" bigint NOT NULL
);
CREATE INDEX IF NOT EXISTS "rsi_findings_day_idx" ON "rsi_findings" ("day");
-- A proposal and its life. `knob` decides what approval DOES: only 'prompt' is
-- self-executing (it writes an agent_prompts row and re-points the active
-- pointer, live on the next dispatch, no redeploy). 'tool' / 'workflow' /
-- 'capability' become tracked todos — that is code someone has to ship.
CREATE TABLE IF NOT EXISTS "rsi_strategies" (
"id" text PRIMARY KEY NOT NULL,
"finding_id" text,
"day" text NOT NULL,
"code" text NOT NULL,
"title" text NOT NULL,
"rationale" text NOT NULL,
"knob" text NOT NULL,
"metric_key" text NOT NULL,
"baseline_value" double precision,
"target_value" double precision,
"payload" text,
"replay" text,
"status" text NOT NULL,
"decided_by" text,
"decided_at" bigint,
"decision_note" text,
"effective_at" bigint,
"before_value" double precision,
"after_value" double precision,
"prompt_id" text,
"created_at" bigint NOT NULL
);
CREATE INDEX IF NOT EXISTS "rsi_strategies_status_idx" ON "rsi_strategies" ("status");
-- Versioned agent prompts. Only stages the control plane can HAND DOWN belong
-- here (today: eval / regen, which ride with the work item). A stage whose
-- template is still compiled into the satellite bundle would give a library
-- whose active row and running code disagree — worse than no library.
--
-- No `active` column: the pointer lives in settings as `rsiActivePrompt:<stage>`.
-- A boolean here would need a transaction to move and could represent "two
-- actives" as a state; a single settings row cannot.
CREATE TABLE IF NOT EXISTS "agent_prompts" (
"id" text PRIMARY KEY NOT NULL,
"stage" text NOT NULL,
"name" text NOT NULL,
"template" text NOT NULL,
"notes" text,
"parent_id" text,
"strategy_id" text,
"created_by" text,
"created_at" bigint NOT NULL,
"archived" bigint DEFAULT 0 NOT NULL
);
CREATE INDEX IF NOT EXISTS "agent_prompts_stage_idx" ON "agent_prompts" ("stage");
-- One offline replay of a candidate prompt against a historical target, scored
-- against what execution later PROVED on a device (run_conditions), never
-- against another model's opinion. `output` is kept verbatim so every score
-- stays recomputable when the scorer itself changes.
CREATE TABLE IF NOT EXISTS "agent_prompt_runs" (
"id" text PRIMARY KEY NOT NULL,
"batch_id" text,
"prompt_id" text,
"prompt_name" text,
"stage" text NOT NULL,
"target_kind" text NOT NULL,
"target_id" text NOT NULL,
"target_title" text,
"status" text DEFAULT 'running' NOT NULL,
"output" text,
"score" text,
"error" text,
"node_id" text,
"model" text,
"duration_ms" bigint,
"created_by" text,
"created_at" bigint NOT NULL,
"finished_at" bigint
);
CREATE INDEX IF NOT EXISTS "agent_prompt_runs_batch_idx" ON "agent_prompt_runs" ("batch_id");
CREATE INDEX IF NOT EXISTS "agent_prompt_runs_prompt_idx" ON "agent_prompt_runs" ("prompt_id");
-- Repeated hand-rolled command sequences mined from session logs: the queue of
-- things that should stop being prompt instructions and become tools. Keyed by a
-- NORMALISED signature (paths / ids / hashes stripped) so one intent from twenty
-- tasks is one row; `sample` keeps a real command, because nobody can build a
-- tool from a redacted skeleton.
CREATE TABLE IF NOT EXISTS "rsi_tool_gaps" (
"signature" text PRIMARY KEY NOT NULL,
"sample" text NOT NULL,
"category" text,
"runs" bigint DEFAULT 0 NOT NULL,
"targets" bigint DEFAULT 0 NOT NULL,
"nodes" text,
"fail_runs" bigint DEFAULT 0 NOT NULL,
"first_seen_at" bigint NOT NULL,
"last_seen_at" bigint NOT NULL,
"updated_at" bigint NOT NULL,
"status" text DEFAULT 'open' NOT NULL,
"strategy_id" text
);
CREATE INDEX IF NOT EXISTS "rsi_tool_gaps_status_idx" ON "rsi_tool_gaps" ("status");
-- The Fix-Critic's verdict CLASS, alongside the risk score it already stamps.
--
-- `fixed_risk` alone cannot answer "was this a scenario band-aid": the score is
-- a scalar the critic may also default, and until now the class survived only
-- inside prose (failure_reason / a review note) that rsi_metrics has to
-- regex-match. The column makes 根因率 / 场景旁路率 first-class. Nullable and
-- backfill-free on purpose — the metric falls back to parsing for rows written
-- before the nodes carry a bundle that fills it.
ALTER TABLE "tasks" ADD COLUMN IF NOT EXISTS "critic_verdict" text;
-- kb_injections.outcome / evaluated_at already exist (0002_flaky_sprite.sql) and were
-- never written. kb_outcome.ts is what finally closes that loop — no DDL needed,
-- which is the whole reason those columns were reserved up front.