-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathschema.sql
More file actions
6376 lines (4309 loc) · 188 KB
/
Copy pathschema.sql
File metadata and controls
6376 lines (4309 loc) · 188 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--
-- PostgreSQL database dump
--
-- Dumped from database version 16.13 (Ubuntu 16.13-0ubuntu0.24.04.1)
-- Dumped by pg_dump version 16.15 (Ubuntu 16.15-0ubuntu0.24.04.1)
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'SQL_ASCII';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
--
-- Name: core; Type: SCHEMA; Schema: -; Owner: -
--
CREATE SCHEMA core;
--
-- Name: SCHEMA core; Type: COMMENT; Schema: -; Owner: -
--
COMMENT ON SCHEMA core IS '
DECORATOR METADATA MIGRATION PATH:
Phase 1 (CURRENT): Decorators in source, policies in .intent/
- CORE can detect violations, suggest fixes
- Cannot autonomously generate new decorated functions
Phase 2 (NEXT): Enhanced policies added
- Add decorator_governance.yaml to .intent/charter/policies/
- CORE can now autonomously generate correct decorators
- Still requires source modification for changes
Phase 3 (FUTURE): Run this SQL migration
- Decorator metadata stored in DB
- CORE queries DB for decorator requirements
- Decorator rules updatable without code changes
Phase 4 (AUTONOMOUS): CORE.NG generates all code from DB
- Full autonomous code generation
- "Last programmer you''ll ever need"
USAGE EXAMPLES:
-- Check which symbols need decorators:
SELECT * FROM core.v_symbols_missing_decorators;
-- Get decorator stack for a symbol:
SELECT * FROM core.v_symbol_decorator_stack WHERE symbol_path = ''body.cli.check:audit'';
-- Generate decorator code:
SELECT core.generate_decorator_code(''symbol-uuid-here'');
-- Add decorator manually:
INSERT INTO core.symbol_decorators (symbol_id, decorator_id, order_index, parameters, source, reasoning)
SELECT
s.id,
dr.id,
1,
''{"dangerous": false}''::jsonb,
''manual'',
''CLI command requires constitutional governance''
FROM core.symbols s, core.decorator_registry dr
WHERE s.symbol_path = ''body.cli.check:audit''
AND dr.decorator_name = ''core_command'';
';
--
-- Name: core_archive; Type: SCHEMA; Schema: -; Owner: -
--
CREATE SCHEMA core_archive;
--
-- Name: btree_gist; Type: EXTENSION; Schema: -; Owner: -
--
CREATE EXTENSION IF NOT EXISTS btree_gist WITH SCHEMA public;
--
-- Name: EXTENSION btree_gist; Type: COMMENT; Schema: -; Owner: -
--
COMMENT ON EXTENSION btree_gist IS 'support for indexing common datatypes in GiST';
--
-- Name: pgcrypto; Type: EXTENSION; Schema: -; Owner: -
--
CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA public;
--
-- Name: EXTENSION pgcrypto; Type: COMMENT; Schema: -; Owner: -
--
COMMENT ON EXTENSION pgcrypto IS 'cryptographic functions';
--
-- Name: auth_method; Type: TYPE; Schema: core; Owner: -
--
CREATE TYPE core.auth_method AS ENUM (
'email',
'google'
);
--
-- Name: non_empty_text; Type: DOMAIN; Schema: core; Owner: -
--
CREATE DOMAIN core.non_empty_text AS text
CONSTRAINT non_empty_text_check CHECK ((TRIM(BOTH FROM VALUE) <> ''::text));
--
-- Name: probability; Type: DOMAIN; Schema: core; Owner: -
--
CREATE DOMAIN core.probability AS numeric(3,2)
CONSTRAINT probability_check CHECK (((VALUE >= (0)::numeric) AND (VALUE <= (1)::numeric)));
--
-- Name: semantic_version; Type: DOMAIN; Schema: core; Owner: -
--
CREATE DOMAIN core.semantic_version AS text;
--
-- Name: severity_level; Type: TYPE; Schema: core; Owner: -
--
CREATE TYPE core.severity_level AS ENUM (
'info',
'warning',
'error',
'critical'
);
--
-- Name: symbol_kind; Type: TYPE; Schema: core; Owner: -
--
CREATE TYPE core.symbol_kind AS ENUM (
'function',
'class',
'method',
'module'
);
--
-- Name: task_status; Type: TYPE; Schema: core; Owner: -
--
CREATE TYPE core.task_status AS ENUM (
'pending',
'planning',
'executing',
'validating',
'completed',
'failed',
'blocked'
);
--
-- Name: user_role; Type: TYPE; Schema: core; Owner: -
--
CREATE TYPE core.user_role AS ENUM (
'visitor',
'analyst',
'auditor',
'org_admin',
'platform_admin'
);
--
-- Name: analyze_index_usage(); Type: FUNCTION; Schema: core; Owner: -
--
CREATE FUNCTION core.analyze_index_usage() RETURNS TABLE(tablename text, indexname text, index_size text, idx_scan bigint, idx_tup_read bigint, idx_tup_fetch bigint, usage_ratio numeric)
LANGUAGE sql SECURITY DEFINER
AS $$
SELECT
schemaname || '.' || relname as tablename,
indexrelname as indexname,
pg_size_pretty(pg_relation_size(indexrelid)) as index_size,
idx_scan,
idx_tup_read,
idx_tup_fetch,
CASE WHEN idx_scan > 0
THEN round((idx_tup_fetch::numeric / NULLIF(idx_scan, 0)), 2)
ELSE 0
END as usage_ratio
FROM pg_stat_user_indexes
WHERE schemaname = 'core'
ORDER BY idx_scan DESC, relname;
$$;
--
-- Name: audit_symbols_changes(); Type: FUNCTION; Schema: core; Owner: -
--
CREATE FUNCTION core.audit_symbols_changes() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
IF TG_OP = 'INSERT' THEN
INSERT INTO core.symbols_audit (operation, symbol_id, new_data)
VALUES ('I', NEW.id, to_jsonb(NEW));
ELSIF TG_OP = 'UPDATE' THEN
INSERT INTO core.symbols_audit (operation, symbol_id, old_data, new_data)
VALUES ('U', NEW.id, to_jsonb(OLD), to_jsonb(NEW));
ELSIF TG_OP = 'DELETE' THEN
INSERT INTO core.symbols_audit (operation, symbol_id, old_data)
VALUES ('D', OLD.id, to_jsonb(OLD));
END IF;
RETURN NULL;
END;
$$;
--
-- Name: cleanup_observability_logs(); Type: FUNCTION; Schema: core; Owner: -
--
CREATE FUNCTION core.cleanup_observability_logs() RETURNS void
LANGUAGE plpgsql
AS $$
DECLARE
deleted_count INTEGER;
BEGIN
DELETE FROM core.observability_logs
WHERE timestamp < NOW() - INTERVAL '90 days';
GET DIAGNOSTICS deleted_count = ROW_COUNT;
RAISE NOTICE 'Cleaned up % logs older than 90 days', deleted_count;
END;
$$;
--
-- Name: FUNCTION cleanup_observability_logs(); Type: COMMENT; Schema: core; Owner: -
--
COMMENT ON FUNCTION core.cleanup_observability_logs() IS 'Delete logs older than 90 days per observability policy';
--
-- Name: cleanup_observability_metrics(); Type: FUNCTION; Schema: core; Owner: -
--
CREATE FUNCTION core.cleanup_observability_metrics() RETURNS void
LANGUAGE plpgsql
AS $$
DECLARE
deleted_count INTEGER;
BEGIN
DELETE FROM core.observability_metrics
WHERE timestamp < NOW() - INTERVAL '1 year';
GET DIAGNOSTICS deleted_count = ROW_COUNT;
RAISE NOTICE 'Cleaned up % metrics older than 1 year', deleted_count;
END;
$$;
--
-- Name: FUNCTION cleanup_observability_metrics(); Type: COMMENT; Schema: core; Owner: -
--
COMMENT ON FUNCTION core.cleanup_observability_metrics() IS 'Delete metrics older than 1 year per observability policy';
--
-- Name: generate_decorator_code(uuid); Type: FUNCTION; Schema: core; Owner: -
--
CREATE FUNCTION core.generate_decorator_code(p_symbol_id uuid) RETURNS text
LANGUAGE plpgsql STABLE
AS $$
DECLARE
decorator_code text := '';
rec record;
BEGIN
FOR rec IN
SELECT
dr.decorator_name,
sd.parameters,
sd.order_index
FROM core.symbol_decorators sd
JOIN core.decorator_registry dr ON dr.id = sd.decorator_id
WHERE sd.symbol_id = p_symbol_id
AND sd.is_active = true
AND dr.is_active = true
ORDER BY sd.order_index
LOOP
-- Build decorator line
decorator_code := decorator_code || '@' || rec.decorator_name;
-- Add parameters if any
IF rec.parameters IS NOT NULL AND rec.parameters != '{}'::jsonb THEN
decorator_code := decorator_code || '(' ||
(SELECT string_agg(
key || '=' ||
CASE
WHEN jsonb_typeof(value) = 'string' THEN '"' || value::text || '"'
WHEN jsonb_typeof(value) = 'boolean' THEN value::text
WHEN jsonb_typeof(value) = 'number' THEN value::text
ELSE value::text
END,
', '
)
FROM jsonb_each(rec.parameters)) ||
')';
END IF;
decorator_code := decorator_code || E'\n';
END LOOP;
RETURN decorator_code;
END;
$$;
--
-- Name: FUNCTION generate_decorator_code(p_symbol_id uuid); Type: COMMENT; Schema: core; Owner: -
--
COMMENT ON FUNCTION core.generate_decorator_code(p_symbol_id uuid) IS 'Generate Python decorator code for a symbol. Usage: SELECT core.generate_decorator_code(symbol_id);';
--
-- Name: get_symbol_id(text); Type: FUNCTION; Schema: core; Owner: -
--
CREATE FUNCTION core.get_symbol_id(path text) RETURNS uuid
LANGUAGE sql STABLE
AS $$
SELECT id FROM core.symbols WHERE symbol_path = path;
$$;
--
-- Name: FUNCTION get_symbol_id(path text); Type: COMMENT; Schema: core; Owner: -
--
COMMENT ON FUNCTION core.get_symbol_id(path text) IS 'Helper to look up symbol UUID by its natural key (symbol_path). Usage: get_symbol_id(''my.module:MyClass'')';
--
-- Name: refresh_materialized_view(text); Type: FUNCTION; Schema: core; Owner: -
--
CREATE FUNCTION core.refresh_materialized_view(view_name text) RETURNS TABLE(duration_ms integer, rows_affected integer)
LANGUAGE plpgsql
AS $$
DECLARE
start_time timestamptz := now();
rows_count integer;
duration integer;
BEGIN
INSERT INTO core.mv_refresh_log (view_name, last_refresh_started, triggered_by)
VALUES (view_name, start_time, current_user)
ON CONFLICT (view_name)
DO UPDATE SET last_refresh_started = start_time, triggered_by = current_user;
EXECUTE format('REFRESH MATERIALIZED VIEW CONCURRENTLY %I', view_name);
EXECUTE format('SELECT COUNT(*) FROM %I', view_name) INTO rows_count;
duration := EXTRACT(EPOCH FROM (now() - start_time)) * 1000;
UPDATE core.mv_refresh_log
SET last_refresh_completed = now(),
last_refresh_duration_ms = duration,
rows_affected = rows_count
WHERE mv_refresh_log.view_name = refresh_materialized_view.view_name;
RETURN QUERY SELECT duration, rows_count;
END;
$$;
--
-- Name: FUNCTION refresh_materialized_view(view_name text); Type: COMMENT; Schema: core; Owner: -
--
COMMENT ON FUNCTION core.refresh_materialized_view(view_name text) IS 'Refresh a materialized view with logging. Usage: SELECT * FROM core.refresh_materialized_view(''core.mv_symbol_usage_patterns'');';
--
-- Name: set_updated_at(); Type: FUNCTION; Schema: core; Owner: -
--
CREATE FUNCTION core.set_updated_at() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
NEW.updated_at = NOW();
RETURN NEW;
END;
$$;
--
-- Name: touch_blackboard_updated_at(); Type: FUNCTION; Schema: core; Owner: -
--
CREATE FUNCTION core.touch_blackboard_updated_at() RETURNS trigger
LANGUAGE plpgsql
AS $$
begin
new.updated_at = now();
return new;
end;
$$;
--
-- Name: validate_symbol_array(); Type: FUNCTION; Schema: core; Owner: -
--
CREATE FUNCTION core.validate_symbol_array() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
-- Validate that all UUIDs in relevant_symbols array exist in symbols table
IF NEW.relevant_symbols IS NOT NULL AND array_length(NEW.relevant_symbols, 1) > 0 THEN
IF EXISTS (
SELECT 1
FROM unnest(NEW.relevant_symbols) AS sym_id
LEFT JOIN core.symbols s ON s.id = sym_id
WHERE s.id IS NULL
) THEN
RAISE EXCEPTION 'Invalid symbol UUID found in relevant_symbols array';
END IF;
END IF;
RETURN NEW;
END;
$$;
SET default_tablespace = '';
SET default_table_access_method = heap;
--
-- Name: _backup_symbol_vector_links; Type: TABLE; Schema: core; Owner: -
--
CREATE TABLE core._backup_symbol_vector_links (
symbol_id uuid,
vector_id uuid,
embedding_model text,
embedding_version integer,
created_at timestamp with time zone
);
--
-- Name: _backup_symbols; Type: TABLE; Schema: core; Owner: -
--
CREATE TABLE core._backup_symbols (
id uuid,
symbol_path text,
module text,
qualname text,
kind text,
ast_signature text,
fingerprint text,
state text,
health_status text,
is_public boolean,
previous_paths text[],
key text,
intent text,
embedding_model text,
last_embedded timestamp with time zone,
first_seen timestamp with time zone,
last_seen timestamp with time zone,
last_modified timestamp with time zone,
created_at timestamp with time zone,
updated_at timestamp with time zone
);
--
-- Name: _migrations; Type: TABLE; Schema: core; Owner: -
--
CREATE TABLE core._migrations (
id text NOT NULL,
applied_at timestamp with time zone DEFAULT now() NOT NULL
);
--
-- Name: _staging_core_symbols; Type: TABLE; Schema: core; Owner: -
--
CREATE TABLE core._staging_core_symbols (
uuid text,
symbol_path text,
file_path text,
structural_hash text,
is_public boolean DEFAULT true
);
--
-- Name: action_results; Type: TABLE; Schema: core; Owner: -
--
CREATE TABLE core.action_results (
id uuid DEFAULT gen_random_uuid() NOT NULL,
action_type character varying(100) NOT NULL,
ok boolean NOT NULL,
file_path character varying(500),
error_message text,
action_metadata jsonb,
agent_id character varying(100),
duration_ms integer,
created_at timestamp with time zone DEFAULT now() NOT NULL
);
--
-- Name: actions; Type: TABLE; Schema: core; Owner: -
--
CREATE TABLE core.actions (
id uuid DEFAULT gen_random_uuid() NOT NULL,
task_id uuid NOT NULL,
action_type text NOT NULL,
target text,
payload jsonb,
result jsonb,
success boolean NOT NULL,
cognitive_role text NOT NULL,
reasoning text,
duration_ms integer,
created_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT actions_action_type_check CHECK ((action_type = ANY (ARRAY['file_read'::text, 'file_write'::text, 'symbol_analysis'::text, 'llm_call'::text, 'shell_command'::text, 'validation'::text, 'vector_search'::text, 'test_run'::text])))
);
--
-- Name: agent_decisions; Type: TABLE; Schema: core; Owner: -
--
CREATE TABLE core.agent_decisions (
id uuid DEFAULT gen_random_uuid() NOT NULL,
task_id uuid NOT NULL,
decision_point text NOT NULL,
options_considered jsonb NOT NULL,
chosen_option text NOT NULL,
reasoning text NOT NULL,
confidence core.probability NOT NULL,
was_correct boolean,
decided_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT agent_decisions_confidence_check CHECK ((((confidence)::numeric >= (0)::numeric) AND ((confidence)::numeric <= (1)::numeric)))
);
--
-- Name: agent_memory; Type: TABLE; Schema: core; Owner: -
--
CREATE TABLE core.agent_memory (
id uuid DEFAULT gen_random_uuid() NOT NULL,
cognitive_role text,
memory_type text NOT NULL,
content text NOT NULL,
related_task_id uuid,
relevance_score core.probability DEFAULT 1.0,
expires_at timestamp with time zone,
created_at timestamp with time zone DEFAULT now() NOT NULL,
resource_name text,
CONSTRAINT agent_memory_memory_type_check CHECK ((memory_type = ANY (ARRAY['fact'::text, 'observation'::text, 'decision'::text, 'pattern'::text, 'error'::text]))),
CONSTRAINT agent_memory_relevance_score_check CHECK ((((relevance_score)::numeric >= (0)::numeric) AND ((relevance_score)::numeric <= (1)::numeric)))
);
--
-- Name: COLUMN agent_memory.resource_name; Type: COMMENT; Schema: core; Owner: -
--
COMMENT ON COLUMN core.agent_memory.resource_name IS 'Free-text identifier of the access source for resource-context audit events (e.g. llm_resources.name like ''deepseek_chat''). Distinct from cognitive_role which carries cognitive_roles.role values via FK. Exactly one of (cognitive_role, resource_name) should be non-NULL per row.';
--
-- Name: api_keys; Type: TABLE; Schema: core; Owner: -
--
CREATE TABLE core.api_keys (
id uuid DEFAULT gen_random_uuid() NOT NULL,
organisation_id uuid NOT NULL,
created_by uuid NOT NULL,
key_hash text NOT NULL,
label text NOT NULL,
last_used_at timestamp with time zone,
expires_at timestamp with time zone,
revoked boolean DEFAULT false NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL
);
--
-- Name: TABLE api_keys; Type: COMMENT; Schema: core; Owner: -
--
COMMENT ON TABLE core.api_keys IS 'Long-lived API keys for programmatic/integration access. Stored hashed; raw key shown once at creation. (ADR-124)';
--
-- Name: artifact_symbol_links; Type: TABLE; Schema: core; Owner: -
--
CREATE TABLE core.artifact_symbol_links (
id uuid DEFAULT gen_random_uuid() NOT NULL,
artifact_id uuid NOT NULL,
symbol_id uuid NOT NULL,
link_kind text NOT NULL,
confidence core.probability DEFAULT 1.0 NOT NULL,
source text NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT artifact_symbol_links_kind_check CHECK ((link_kind = ANY (ARRAY['documents'::text, 'tests'::text, 'references'::text, 'configures'::text, 'governs'::text]))),
CONSTRAINT artifact_symbol_links_source_check CHECK ((source = ANY (ARRAY['ast_import'::text, 'name_match'::text, 'llm_inferred'::text, 'manual'::text])))
);
--
-- Name: TABLE artifact_symbol_links; Type: COMMENT; Schema: core; Owner: -
--
COMMENT ON TABLE core.artifact_symbol_links IS 'Cross-reference between repo artifacts (docs, tests, prompts, intent) and symbols. Primary query surface for: "what docs cover this symbol?", "what tests exercise this capability?", "which policies govern this module?". ProposalService uses this to compute documentation and test blast-radius alongside structural blast-radius.';
--
-- Name: COLUMN artifact_symbol_links.link_kind; Type: COMMENT; Schema: core; Owner: -
--
COMMENT ON COLUMN core.artifact_symbol_links.link_kind IS 'documents: narrative explanation; tests: executable verification; references: mention/import; configures: intent YAML or infra SQL that controls behavior; governs: policy/pattern that applies.';
--
-- Name: COLUMN artifact_symbol_links.confidence; Type: COMMENT; Schema: core; Owner: -
--
COMMENT ON COLUMN core.artifact_symbol_links.confidence IS 'Probability [0,1]. ast_import and name_match are typically 1.0; llm_inferred may be lower.';
--
-- Name: COLUMN artifact_symbol_links.source; Type: COMMENT; Schema: core; Owner: -
--
COMMENT ON COLUMN core.artifact_symbol_links.source IS 'How this link was established. Governs trust level and whether it can be auto-removed on recrawl.';
--
-- Name: audit_findings; Type: TABLE; Schema: core; Owner: -
--
CREATE TABLE core.audit_findings (
id uuid DEFAULT gen_random_uuid() NOT NULL,
check_id text NOT NULL,
severity text NOT NULL,
message text NOT NULL,
file_path text,
line_number integer,
context jsonb,
created_at timestamp with time zone DEFAULT now() NOT NULL,
run_id uuid NOT NULL
);
--
-- Name: audit_remediation_runs; Type: TABLE; Schema: core; Owner: -
--
CREATE TABLE core.audit_remediation_runs (
id uuid DEFAULT gen_random_uuid() NOT NULL,
audit_run_id uuid,
mode text NOT NULL,
write boolean DEFAULT false NOT NULL,
status text DEFAULT 'pending'::text NOT NULL,
requested_by text NOT NULL,
requested_at timestamp with time zone DEFAULT now() NOT NULL,
started_at timestamp with time zone,
finished_at timestamp with time zone,
result jsonb,
error text
);
--
-- Name: audit_run_resources; Type: TABLE; Schema: core; Owner: -
--
CREATE TABLE core.audit_run_resources (
run_id uuid DEFAULT gen_random_uuid() NOT NULL,
verdict text NOT NULL,
finding_count integer NOT NULL,
blocking_count integer NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
completed_at timestamp with time zone,
status text DEFAULT 'pending'::text NOT NULL
);
--
-- Name: audit_runs; Type: TABLE; Schema: core; Owner: -
--
CREATE TABLE core.audit_runs (
source text NOT NULL,
commit_sha character(40),
score numeric(4,3),
started_at timestamp with time zone DEFAULT now() NOT NULL,
finished_at timestamp with time zone,
run_id uuid DEFAULT gen_random_uuid() NOT NULL,
verdict text DEFAULT 'pending'::text NOT NULL,
status text DEFAULT 'completed'::text NOT NULL,
finding_count integer DEFAULT 0 NOT NULL,
blocking_count integer DEFAULT 0 NOT NULL,
findings jsonb
);
--
-- Name: auth_events; Type: TABLE; Schema: core; Owner: -
--
CREATE TABLE core.auth_events (
id uuid DEFAULT gen_random_uuid() NOT NULL,
user_id uuid,
event_type text NOT NULL,
actor_id uuid,
ip_address text,
user_agent text,
metadata jsonb DEFAULT '{}'::jsonb NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL
);
--
-- Name: TABLE auth_events; Type: COMMENT; Schema: core; Owner: -
--
COMMENT ON TABLE core.auth_events IS 'Immutable auth audit trail — logins, promotions, suspensions, resets. (ADR-124)';
--
-- Name: autonomous_proposals; Type: TABLE; Schema: core; Owner: -
--
CREATE TABLE core.autonomous_proposals (
id uuid DEFAULT gen_random_uuid() NOT NULL,
proposal_id text NOT NULL,
goal text NOT NULL,
status text DEFAULT 'draft'::text NOT NULL,
actions jsonb NOT NULL,
scope jsonb DEFAULT '{}'::jsonb NOT NULL,
risk jsonb,
created_at timestamp with time zone DEFAULT now() NOT NULL,
created_by text DEFAULT 'autonomous'::text NOT NULL,
validation_checks jsonb DEFAULT '[]'::jsonb NOT NULL,
validation_results jsonb DEFAULT '{}'::jsonb NOT NULL,
execution_started_at timestamp with time zone,
execution_completed_at timestamp with time zone,
execution_results jsonb DEFAULT '{}'::jsonb NOT NULL,
constitutional_constraints jsonb DEFAULT '{}'::jsonb NOT NULL,
approval_required boolean DEFAULT false NOT NULL,
approved_by text,
approved_at timestamp with time zone,
failure_reason text,
version integer DEFAULT 0 NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
approval_authority text,
claimed_by uuid,
consequence_recorded_at timestamp with time zone,
CONSTRAINT approval_authority_required_when_approved CHECK (((status <> ALL (ARRAY['approved'::text, 'executing'::text, 'finalizing'::text, 'completed'::text])) OR (approval_authority IS NOT NULL) OR (created_at < '2026-04-27 00:00:00+00'::timestamp with time zone))),
CONSTRAINT autonomous_proposals_approval_authority_value_check CHECK (((approval_authority IS NULL) OR (approval_authority = ANY (ARRAY['risk_classification.safe_auto_approval'::text, 'principal.governor'::text])))),
CONSTRAINT autonomous_proposals_status_check CHECK ((status = ANY (ARRAY['draft'::text, 'pending'::text, 'approved'::text, 'executing'::text, 'finalizing'::text, 'completed'::text, 'failed'::text, 'rejected'::text])))
);
--
-- Name: TABLE autonomous_proposals; Type: COMMENT; Schema: core; Owner: -
--
COMMENT ON TABLE core.autonomous_proposals IS 'A3 Autonomous Proposals - Registry-based action plans with constitutional governance';
--
-- Name: COLUMN autonomous_proposals.proposal_id; Type: COMMENT; Schema: core; Owner: -
--
COMMENT ON COLUMN core.autonomous_proposals.proposal_id IS 'Human-readable proposal identifier';
--
-- Name: COLUMN autonomous_proposals.goal; Type: COMMENT; Schema: core; Owner: -
--
COMMENT ON COLUMN core.autonomous_proposals.goal IS 'Strategic intent - what this proposal aims to achieve';
--
-- Name: COLUMN autonomous_proposals.status; Type: COMMENT; Schema: core; Owner: -
--
COMMENT ON COLUMN core.autonomous_proposals.status IS 'Lifecycle: draft->pending->approved->executing->finalizing->completed/failed/rejected';
--
-- Name: COLUMN autonomous_proposals.actions; Type: COMMENT; Schema: core; Owner: -
--
COMMENT ON COLUMN core.autonomous_proposals.actions IS 'Array of actions from action_registry to execute';
--
-- Name: COLUMN autonomous_proposals.scope; Type: COMMENT; Schema: core; Owner: -
--
COMMENT ON COLUMN core.autonomous_proposals.scope IS 'Files, modules, symbols, and policies affected by this proposal';
--
-- Name: COLUMN autonomous_proposals.risk; Type: COMMENT; Schema: core; Owner: -
--
COMMENT ON COLUMN core.autonomous_proposals.risk IS 'Risk assessment computed from action impact levels';
--
-- Name: COLUMN autonomous_proposals.approval_required; Type: COMMENT; Schema: core; Owner: -
--
COMMENT ON COLUMN core.autonomous_proposals.approval_required IS 'Whether human approval needed (moderate/dangerous actions)';
--
-- Name: blackboard_entries; Type: TABLE; Schema: core; Owner: -
--
CREATE TABLE core.blackboard_entries (
id uuid DEFAULT gen_random_uuid() NOT NULL,
worker_uuid uuid NOT NULL,
entry_type text NOT NULL,
phase text NOT NULL,
status text DEFAULT 'open'::text NOT NULL,
subject text NOT NULL,
payload jsonb DEFAULT '{}'::jsonb NOT NULL,
claimed_by uuid,
claimed_at timestamp with time zone,
resolved_at timestamp with time zone,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
resolution_mechanism text,
orphan_release_count integer DEFAULT 0 NOT NULL,
occurrence_count integer DEFAULT 1 NOT NULL,
first_payload jsonb,
last_seen_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT blackboard_entry_resolution_mechanism_closed_set CHECK ((((entry_type = 'finding'::text) AND (resolution_mechanism IS NOT NULL) AND (resolution_mechanism = ANY (ARRAY['reaudit'::text, 'self_resolve'::text, 'human'::text]))) OR ((entry_type <> 'finding'::text) AND (resolution_mechanism IS NULL)))),
CONSTRAINT blackboard_entry_status_closed_set CHECK ((status = ANY (ARRAY['open'::text, 'claimed'::text, 'awaiting_reaudit'::text, 'resolved'::text, 'abandoned'::text, 'deferred_to_proposal'::text, 'dry_run_complete'::text, 'indeterminate'::text, 'suppressed'::text])))
);
--
-- Name: TABLE blackboard_entries; Type: COMMENT; Schema: core; Owner: -
--
COMMENT ON TABLE core.blackboard_entries IS 'Constitutional coordination ledger. Workers read and write here. Every decision must be recorded \u2014 silence is a constitutional violation.';
--
-- Name: COLUMN blackboard_entries.occurrence_count; Type: COMMENT; Schema: core; Owner: -
--
COMMENT ON COLUMN core.blackboard_entries.occurrence_count IS 'Number of times this standing finding was observed (dedup upsert increments). first observation = 1.';
--
-- Name: COLUMN blackboard_entries.first_payload; Type: COMMENT; Schema: core; Owner: -
--
COMMENT ON COLUMN core.blackboard_entries.first_payload IS 'Payload captured at first observation; retained across dedup updates (original history). NULL for pre-migration rows and non-findings.';
--
-- Name: COLUMN blackboard_entries.last_seen_at; Type: COMMENT; Schema: core; Owner: -
--
COMMENT ON COLUMN core.blackboard_entries.last_seen_at IS 'Last OBSERVATION time (sensor (re)post). Set only by the dedup upsert, never by the updated_at touch trigger. Staleness and recovered-target logic key on this, not updated_at (which is generic mutation time).';
--
-- Name: capabilities; Type: TABLE; Schema: core; Owner: -
--
CREATE TABLE core.capabilities (
id uuid DEFAULT gen_random_uuid() NOT NULL,
name text NOT NULL,
domain text DEFAULT 'general'::text NOT NULL,
title text NOT NULL,
objective text,
owner text NOT NULL,
dependencies jsonb DEFAULT '[]'::jsonb,
test_coverage numeric(5,2),
tags jsonb DEFAULT '[]'::jsonb NOT NULL,
status text DEFAULT 'Active'::text,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
key_suffix text,
CONSTRAINT capabilities_status_check CHECK ((status = ANY (ARRAY['Active'::text, 'Draft'::text, 'Deprecated'::text]))),
CONSTRAINT capabilities_tags_check CHECK ((jsonb_typeof(tags) = 'array'::text)),
CONSTRAINT chk_test_coverage_range CHECK (((test_coverage >= (0)::numeric) AND (test_coverage <= (100)::numeric)))
);
--
-- Name: capability_alignment_tests; Type: TABLE; Schema: core; Owner: -
--
CREATE TABLE core.capability_alignment_tests (
id uuid DEFAULT gen_random_uuid() NOT NULL,
name text NOT NULL,
capability text NOT NULL,
expected_behavior text NOT NULL,
scoring_rubric jsonb DEFAULT '{}'::jsonb NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL
);
--
-- Name: capability_cli_links; Type: TABLE; Schema: core; Owner: -
--
CREATE TABLE core.capability_cli_links (
capability_id uuid NOT NULL,
cli_command_name text NOT NULL
);
--
-- Name: census_runs; Type: TABLE; Schema: core; Owner: -
--
CREATE TABLE core.census_runs (
id uuid DEFAULT gen_random_uuid() NOT NULL,
snapshot boolean DEFAULT false NOT NULL,
baseline_name text,
status text DEFAULT 'pending'::text NOT NULL,
requested_by text NOT NULL,
requested_at timestamp with time zone DEFAULT now() NOT NULL,
started_at timestamp with time zone,
finished_at timestamp with time zone,
result jsonb,
error text
);
--
-- Name: cli_commands; Type: TABLE; Schema: core; Owner: -
--
CREATE TABLE core.cli_commands (
name text NOT NULL,
module text NOT NULL,
entrypoint text NOT NULL,
summary text,
category text,