feat(WP-0013): IHF Phase 12 — Platform Memory and Continuous Learning

Closes the long-range feedback loop: outcome signals now enrich the full
traceability chain and feed back into routing, triage, and AI proposals.

Schema (T01):
- outcome_correlations (CHECK correlation_type)
- pattern_performance_records
- adaptive_threshold_configs
- institutional_knowledge_entries (GIN tsvector FTS)
- learning_insights (CHECK insight_type)
- ALTER TABLE decision_records + requirement_candidates: outcome_summary JSONB
- AFTER INSERT trigger trg_enrich_lineage on outcome_signals
- contracts/core/ updated (outcome-summary-columns-v1, append-only addendum)

Correlation engine (T02):
- Application/Helper/CorrelationEngine.hs: pure annotation→outcome SQL
- Web/Controller/OutcomeCorrelations.hs: ComputeCorrelationsAction + index

Pattern performance (T03):
- Web/Controller/PatternPerformance.hs: ComputePatternPerformanceAction

Adaptive thresholds (T04):
- Web/Controller/AdaptiveThresholds.hs: CalibrateThresholdsAction
- Application/Helper/FrictionScore.hs: applyAdaptiveWeights

Institutional knowledge (T05):
- DistilDecisionAction in DecisionRecords controller
- Web/Controller/InstitutionalKnowledge.hs: QueryKnowledgeBaseAction

Lineage enrichment (T06):
- Web/Controller/LineageEnrichment.hs: EnrichLineageAction (batch backfill)
- enrich_lineage_on_outcome_batch() PL/pgSQL helper in migration

Learning dashboard (T07):
- Web/Controller/LearningDashboard.hs: 5-panel autoRefresh view
- "Learning" nav link in FrontController

API v2 learning endpoints (T08):
- GET /api/v2/outcome-correlations, /pattern-performance, /knowledge-base/{id}
- OpenAPI schemas: OutcomeCorrelation, PatternPerformanceRecord, InstitutionalKnowledgeEntry

GAAF scorecard + docs (T09):
- Core 3.8→3.9, Functional 3.6→3.8, overall 3.61→3.68
- CLAUDE.md: IHF v0.2 complete, no active workplan

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-01 23:14:15 +00:00
parent 9643173618
commit 0f505feb2d
28 changed files with 1574 additions and 17 deletions

View File

@@ -1005,3 +1005,98 @@ ALTER TABLE agent_proposals
ADD COLUMN tokens_out INTEGER;
CREATE INDEX agent_proposals_agent_registration_idx ON agent_proposals (agent_registration_id);
-- ============================================================
-- Phase 12 — Platform Memory and Continuous Learning
-- ============================================================
-- outcome_correlations: links annotation signals to downstream outcome quality
-- GAAF: correlation_type CHECK constraint
CREATE TABLE outcome_correlations (
id UUID DEFAULT uuid_generate_v4() PRIMARY KEY NOT NULL,
hub_id UUID NOT NULL REFERENCES hubs(id),
annotation_category TEXT NOT NULL REFERENCES annotation_category_registry(name),
correlation_type TEXT NOT NULL DEFAULT 'annotation_predictor',
correlation_score DOUBLE PRECISION NOT NULL,
sample_count INTEGER NOT NULL DEFAULT 0,
computed_at TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL,
CHECK (correlation_type IN ('annotation_predictor', 'routing_quality', 'pattern_quality'))
);
CREATE INDEX outcome_correlations_hub_idx ON outcome_correlations (hub_id);
CREATE INDEX outcome_correlations_score_idx ON outcome_correlations (correlation_score DESC);
-- pattern_performance_records: per-pattern historical outcome quality
CREATE TABLE pattern_performance_records (
id UUID DEFAULT uuid_generate_v4() PRIMARY KEY NOT NULL,
widget_pattern_id UUID NOT NULL REFERENCES widget_patterns(id),
hub_id UUID NOT NULL REFERENCES hubs(id),
adoption_count INTEGER NOT NULL DEFAULT 0,
positive_outcome_count INTEGER NOT NULL DEFAULT 0,
total_outcome_count INTEGER NOT NULL DEFAULT 0,
mean_outcome_value DOUBLE PRECISION,
outcome_rank INTEGER,
calibrated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL,
UNIQUE (widget_pattern_id, hub_id)
);
CREATE INDEX pattern_performance_pattern_idx ON pattern_performance_records (widget_pattern_id);
CREATE INDEX pattern_performance_rank_idx ON pattern_performance_records (hub_id, outcome_rank);
-- adaptive_threshold_configs: per-hub friction weight overrides
CREATE TABLE adaptive_threshold_configs (
id UUID DEFAULT uuid_generate_v4() PRIMARY KEY NOT NULL,
hub_id UUID NOT NULL REFERENCES hubs(id) UNIQUE,
weight_overrides JSONB NOT NULL DEFAULT '{}',
bottleneck_threshold_override DOUBLE PRECISION,
calibration_date TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL,
notes TEXT
);
CREATE INDEX adaptive_threshold_hub_idx ON adaptive_threshold_configs (hub_id);
-- institutional_knowledge_entries: distilled decision summaries
-- GIN index for full-text search (PostgreSQL tsvector, no extension needed)
CREATE TABLE institutional_knowledge_entries (
id UUID DEFAULT uuid_generate_v4() PRIMARY KEY NOT NULL,
hub_id UUID NOT NULL REFERENCES hubs(id),
decision_record_id UUID REFERENCES decision_records(id),
summary TEXT NOT NULL,
summary_tsv TSVECTOR GENERATED ALWAYS AS (to_tsvector('english', summary)) STORED,
tags JSONB NOT NULL DEFAULT '[]',
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL
);
CREATE INDEX institutional_knowledge_hub_idx ON institutional_knowledge_entries (hub_id);
CREATE INDEX institutional_knowledge_fts_idx ON institutional_knowledge_entries USING GIN (summary_tsv);
-- learning_insights: platform-level insights with evidence links
-- GAAF: insight_type CHECK constraint
CREATE TABLE learning_insights (
id UUID DEFAULT uuid_generate_v4() PRIMARY KEY NOT NULL,
hub_id UUID NOT NULL REFERENCES hubs(id),
insight_type TEXT NOT NULL,
title TEXT NOT NULL,
body TEXT NOT NULL,
evidence_links JSONB NOT NULL DEFAULT '[]',
is_actioned BOOLEAN NOT NULL DEFAULT FALSE,
computed_at TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL,
CHECK (insight_type IN (
'annotation_predictor',
'threshold_calibration',
'pattern_ranking',
'routing_improvement'
))
);
CREATE INDEX learning_insights_hub_idx ON learning_insights (hub_id);
CREATE INDEX learning_insights_type_idx ON learning_insights (insight_type);
-- Extend core tables with outcome_summary (retroactive lineage enrichment)
-- GAAF rule 3: /contracts/core/ updated in T01/T06
ALTER TABLE decision_records
ADD COLUMN outcome_summary JSONB NULL;
ALTER TABLE requirement_candidates
ADD COLUMN outcome_summary JSONB NULL;