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
+147
View File
@@ -0,0 +1,147 @@
-- 「验证」独立成第五条 track(见 docs/verify.md)。
--
-- 之前它是 `features.deliverable = 'report'` 的 feature:共用表、id、状态机、执行模板,
-- 只在报告生成处分叉。代价是它把 Feature 的口径一路污染下去 —— 每日创建 / 完成数、
-- 周报、KB 效果、证据指标全都把走查算成 Feature;执行 prompt 是 Feature 模板再在末尾
-- 追加一段「前面的规矩这轮不适用」,Feature 模板每次改版都顺带改了验证线的行为。
--
-- 这份迁移:
-- 1. 建 verifications / verification_notes;
-- 2. 把现存的验证行(features.deliverable = 'report')连同 audit_report / verify_spec /
-- audit_notes 搬过去,id 不变(节点上的工作区 ~/taskLog/<id>/ 和证据路径都按 id 找);
-- 3. 把辅表里挂在这些 id 上的 kind / target_type 从 feature 改成 verify / verification;
-- 4. 从 features 删掉这些行。
--
-- 对还在跑的旧进程无害:这里只新建表、搬行、删行,不删 features 的列、不动 audit_notes
-- 表结构 —— 旧代码 SELECT 的列都还在。旧列与旧表在新代码上线后由 0037 清掉。
--
-- 状态映射(feature → verification):
-- initializing / info_required / pending_confirmation / awaiting_implementation → awaiting_verify
-- implementing → verifying (迁移时若正在跑,该轮结束后由新卫星接不上旧回调 ——
-- 见 docs/verify.md「迁移」;线上迁移时两条都在 manual_review)
-- manual_review → report_ready
-- completed → accepted
-- implementation_failed → verify_failed
-- archived / cancelled → 同名
CREATE TABLE IF NOT EXISTS "verifications" (
"product_profile" text,
"id" text PRIMARY KEY NOT NULL,
"title" text NOT NULL,
"description" text DEFAULT '' NOT NULL,
"platform" text NOT NULL,
"base_ref" text,
"remark" text,
"attachments" text,
"verify_spec" text,
"audit_report" text,
"review_feedback" text,
"review_history" text,
"workspace_path" text,
"pinned" bigint DEFAULT 0 NOT NULL,
"status" text DEFAULT 'awaiting_verify' NOT NULL,
"priority_key" double precision NOT NULL,
"watchers" text,
"creator_email" text,
"created_at" bigint NOT NULL,
"started_at" bigint,
"finished_at" bigint,
"duration_ms" bigint,
"total_duration_ms" bigint,
"log_path" text,
"failure_reason" text,
"attempts" bigint DEFAULT 0 NOT NULL,
"executor_node_id" text,
"status_changed_at" bigint,
"clusters" text,
"ttkb_packages" text,
"lang" text,
"baseline" text,
"readable_report_html" text,
"readable_report_generated_at" bigint,
"readable_report_round" bigint,
"readable_report_error" text,
"readable_report_prompt_id" text,
"readable_report_prompt_name" text,
"readable_report_alt_html" text,
"readable_report_alt_lang" text,
"readable_report_alt_generated_at" bigint,
"readable_report_alt_error" text
);
CREATE INDEX IF NOT EXISTS "verifications_status_idx" ON "verifications" ("status");
CREATE TABLE IF NOT EXISTS "verification_notes" (
"verification_id" text NOT NULL REFERENCES "verifications"("id") ON DELETE CASCADE,
"page_id" text NOT NULL,
"issue_n" bigint NOT NULL,
"lang" text NOT NULL,
"note" text,
"filed_task_id" text,
"author" text,
"updated_at" bigint NOT NULL,
PRIMARY KEY ("verification_id", "page_id", "issue_n", "lang")
);
-- ── 搬存量 ──────────────────────────────────────────────────────────────────
INSERT INTO "verifications" (
"product_profile", "id", "title", "description", "platform", "base_ref", "remark", "attachments",
"verify_spec", "audit_report", "review_feedback", "review_history", "workspace_path", "pinned",
"status", "priority_key", "watchers", "creator_email", "created_at", "started_at", "finished_at",
"duration_ms", "total_duration_ms", "log_path", "failure_reason", "attempts", "executor_node_id",
"status_changed_at", "clusters", "ttkb_packages", "lang",
"readable_report_html", "readable_report_generated_at", "readable_report_round", "readable_report_error",
"readable_report_prompt_id", "readable_report_prompt_name",
"readable_report_alt_html", "readable_report_alt_lang", "readable_report_alt_generated_at", "readable_report_alt_error"
)
SELECT
"product_profile", "id", "title", "description", "platform", "base_ref", "remark", "attachments",
"verify_spec", "audit_report", "review_feedback", "review_history", "workspace_path", "pinned",
CASE "status"
WHEN 'implementing' THEN 'verifying'
WHEN 'manual_review' THEN 'report_ready'
WHEN 'completed' THEN 'accepted'
WHEN 'implementation_failed' THEN 'verify_failed'
WHEN 'archived' THEN 'archived'
WHEN 'cancelled' THEN 'cancelled'
ELSE 'awaiting_verify'
END,
"priority_key", "watchers", "creator_email", "created_at", "started_at", "finished_at",
"duration_ms", "total_duration_ms", "log_path", "failure_reason", "attempts", "executor_node_id",
"status_changed_at", "clusters", "ttkb_packages", "lang",
"readable_report_html", "readable_report_generated_at", "readable_report_round", "readable_report_error",
"readable_report_prompt_id", "readable_report_prompt_name",
"readable_report_alt_html", "readable_report_alt_lang", "readable_report_alt_generated_at", "readable_report_alt_error"
FROM "features"
WHERE "deliverable" = 'report'
ON CONFLICT ("id") DO NOTHING;
INSERT INTO "verification_notes" ("verification_id", "page_id", "issue_n", "lang", "note", "filed_task_id", "author", "updated_at")
SELECT n."feature_id", n."page_id", n."issue_n", n."lang", n."note", n."filed_task_id", n."author", n."updated_at"
FROM "audit_notes" n
JOIN "verifications" v ON v."id" = n."feature_id"
ON CONFLICT DO NOTHING;
-- ── 辅表改挂 ────────────────────────────────────────────────────────────────
-- 按 target_type / kind 分表的辅表:可读性报告运行记录与来源、状态流转账本、每轮摘要、
-- 证据采集事件、证据 TOS 镜像、执行条件。
UPDATE "readable_report_runs" SET "target_type" = 'verification' WHERE "target_type" = 'feature' AND "target_id" IN (SELECT "id" FROM "verifications");
UPDATE "readable_sources" SET "target_type" = 'verification' WHERE "target_type" = 'feature' AND "target_id" IN (SELECT "id" FROM "verifications");
UPDATE "task_transitions" SET "kind" = 'verify' WHERE "kind" = 'feature' AND "target_id" IN (SELECT "id" FROM "verifications");
UPDATE "round_digests" SET "kind" = 'verify' WHERE "kind" = 'feature' AND "target_id" IN (SELECT "id" FROM "verifications");
-- 这张表的主键是 "<target_type>:<target_id>:<captureId>:<event>:<ts>",前缀要一起改,
-- 否则下次摄取按新前缀算主键,同一事件会重复入库。
UPDATE "evidence_capture_events"
SET "target_type" = 'verification', "id" = 'verification' || substr("id", length('feature') + 1)
WHERE "target_type" = 'feature' AND "id" LIKE 'feature:%' AND "target_id" IN (SELECT "id" FROM "verifications");
UPDATE "evidence_media" SET "owner_kind" = 'verify' WHERE "owner_kind" = 'feature' AND "owner_id" IN (SELECT "id" FROM "verifications");
-- run_conditions 的主键里嵌着 kind("<targetKind>:<targetId>:<entry.id>"),改 kind 会让
-- 主键与内容不一致;走查不产出 Conditions,直接删掉挂在这些 id 上的行。
DELETE FROM "run_conditions" WHERE "target_kind" = 'feature' AND "target_id" IN (SELECT "id" FROM "verifications");
-- ── 从 features 移走 ─────────────────────────────────────────────────────────
-- impl_report_versions 以 ON DELETE CASCADE 跟着走:验证线没有 ImplReport,那几版是
-- 借 Feature 管道时的副产物。
DELETE FROM "features" WHERE "deliverable" = 'report' AND "id" IN (SELECT "id" FROM "verifications");