Close P8 visual watch automation loop

This commit is contained in:
Codex
2026-05-11 23:37:47 +08:00
parent 48ef7eea77
commit 3dffcbbec4
157 changed files with 26206 additions and 385 deletions
@@ -0,0 +1,14 @@
create table if not exists alert_deliveries (
id bigserial primary key,
alert_id bigint not null references decision_alerts(id) on delete cascade,
channel text not null,
status text not null,
attempted_ts timestamptz not null,
delivered_ts timestamptz,
external_message_id text,
error text,
payload jsonb not null default '{}'::jsonb
);
create index if not exists idx_alert_deliveries_alert_attempted_desc
on alert_deliveries (alert_id, attempted_ts desc, id desc);
@@ -0,0 +1,46 @@
create table if not exists visual_watch_runs (
id bigserial primary key,
trigger_type text not null,
source_name text not null,
instrument_id bigint not null references instruments(id) on delete cascade,
candidate_id bigint references trade_plan_candidates(id) on delete set null,
signal_id bigint references trade_signals(id) on delete set null,
decision_packet_id bigint references decision_packets(id) on delete set null,
symbol text not null,
timeframe text not null,
status text not null,
created_ts timestamptz not null default now(),
completed_ts timestamptz,
payload jsonb not null default '{}'::jsonb
);
create index if not exists idx_visual_watch_runs_lookup
on visual_watch_runs (instrument_id, trigger_type, created_ts desc, id desc);
create table if not exists visual_snapshots (
id bigserial primary key,
watch_run_id bigint not null references visual_watch_runs(id) on delete cascade,
source_name text not null,
image_path text not null,
captured_ts timestamptz not null,
status text not null,
payload jsonb not null default '{}'::jsonb
);
create index if not exists idx_visual_snapshots_watch_captured_desc
on visual_snapshots (watch_run_id, captured_ts desc, id desc);
create table if not exists visual_reviews (
id bigserial primary key,
watch_run_id bigint not null references visual_watch_runs(id) on delete cascade,
snapshot_id bigint references visual_snapshots(id) on delete set null,
visual_state text not null,
visual_confidence numeric(6, 4),
visual_notes text not null default '',
ui_anomalies jsonb not null default '[]'::jsonb,
reviewed_ts timestamptz not null,
payload jsonb not null default '{}'::jsonb
);
create index if not exists idx_visual_reviews_watch_reviewed_desc
on visual_reviews (watch_run_id, reviewed_ts desc, id desc);
@@ -0,0 +1,20 @@
create table if not exists research_council_runs (
id bigserial primary key,
instrument_id bigint not null,
trading_plan_id bigint null,
candidate_id bigint null,
signal_id bigint null,
decision_packet_id bigint null,
status text not null,
timeframe text not null default '1m',
model_code text not null,
committee_confidence double precision not null default 0,
summary_text text not null default '',
payload jsonb not null default '{}'::jsonb,
generated_ts timestamptz not null,
created_at timestamptz not null default now(),
updated_at timestamptz not null default now()
);
create index if not exists idx_research_council_runs_instrument_generated
on research_council_runs (instrument_id, generated_ts desc, id desc);
@@ -0,0 +1,12 @@
create table if not exists research_council_messages (
id bigserial primary key,
run_id bigint not null,
agent_role text not null,
message_type text not null,
payload jsonb not null default '{}'::jsonb,
created_ts timestamptz not null,
created_at timestamptz not null default now()
);
create index if not exists idx_research_council_messages_run
on research_council_messages (run_id, created_ts asc, id asc);
@@ -0,0 +1,13 @@
create table if not exists research_council_links (
id bigserial primary key,
run_id bigint not null,
trading_plan_id bigint null,
candidate_id bigint null,
signal_id bigint null,
decision_packet_id bigint null,
execution_ticket_id bigint null,
created_ts timestamptz not null
);
create index if not exists idx_research_council_links_run
on research_council_links (run_id, created_ts desc, id desc);
@@ -0,0 +1,16 @@
create table if not exists research_council_checkpoints (
id bigserial primary key,
run_id bigint null,
instrument_id bigint not null,
checkpoint_key text not null,
status text not null,
stage text not null,
payload jsonb not null default '{}'::jsonb,
created_ts timestamptz not null,
updated_ts timestamptz not null,
created_at timestamptz not null default now(),
updated_at timestamptz not null default now()
);
create index if not exists idx_research_council_checkpoints_latest
on research_council_checkpoints (instrument_id, checkpoint_key, updated_ts desc, id desc);
@@ -0,0 +1,24 @@
create table if not exists research_council_lessons (
id bigserial primary key,
lesson_key text not null unique,
instrument_id bigint not null,
source_type text not null,
source_ref text not null,
lesson_type text not null,
symbol text null,
session_code text null,
setup_type text null,
model_code text null,
title text not null,
lesson_summary text not null,
tags jsonb not null default '[]'::jsonb,
priority_score double precision not null default 0,
payload jsonb not null default '{}'::jsonb,
created_ts timestamptz not null,
updated_ts timestamptz not null,
created_at timestamptz not null default now(),
updated_at timestamptz not null default now()
);
create index if not exists idx_research_council_lessons_scope
on research_council_lessons (instrument_id, session_code, setup_type, model_code, updated_ts desc, id desc);
@@ -0,0 +1,22 @@
create table if not exists research_council_optimization_cycles (
id bigserial primary key,
cycle_key text not null unique,
instrument_id bigint not null,
status text not null,
timeframe text not null default '1m',
model_code text not null,
replay_file text null,
lesson_summary jsonb not null default '{}'::jsonb,
replay_summary jsonb not null default '{}'::jsonb,
eval_summary jsonb not null default '{}'::jsonb,
arena_summary jsonb not null default '{}'::jsonb,
next_actions jsonb not null default '[]'::jsonb,
payload jsonb not null default '{}'::jsonb,
started_ts timestamptz not null,
finished_ts timestamptz not null,
created_at timestamptz not null default now(),
updated_at timestamptz not null default now()
);
create index if not exists idx_research_council_optimization_cycles_latest
on research_council_optimization_cycles (instrument_id, finished_ts desc, id desc);
+32
View File
@@ -0,0 +1,32 @@
create table if not exists alert_feedback (
id bigserial primary key,
subject_type text not null,
subject_id bigint not null,
alert_id bigint references decision_alerts(id) on delete cascade,
visual_review_id bigint references visual_reviews(id) on delete cascade,
label text not null,
note text not null default '',
created_by text not null default 'local_operator',
created_ts timestamptz not null default now(),
payload jsonb not null default '{}'::jsonb,
constraint chk_alert_feedback_subject check (
(
subject_type = 'alert'
and alert_id is not null
and visual_review_id is null
and subject_id = alert_id
)
or (
subject_type = 'visual_review'
and visual_review_id is not null
and alert_id is null
and subject_id = visual_review_id
)
)
);
create index if not exists idx_alert_feedback_alert_created_desc
on alert_feedback (alert_id, created_ts desc, id desc);
create index if not exists idx_alert_feedback_visual_review_created_desc
on alert_feedback (visual_review_id, created_ts desc, id desc);