sessionyard 0.7.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agent_chat/001_core.sql +172 -0
- agent_chat/002_coordination.sql +63 -0
- agent_chat/003_harness_admission.sql +10 -0
- agent_chat/004_session_titles.sql +3 -0
- agent_chat/005_viewer.sql +9 -0
- agent_chat/006_quotas.sql +6 -0
- agent_chat/007_sender_receipts.sql +20 -0
- agent_chat/008_direct_threads.sql +49 -0
- agent_chat/009_pm_mark.sql +23 -0
- agent_chat/010_quota_backfill.sql +12 -0
- agent_chat/011_roles_and_work.sql +31 -0
- agent_chat/__init__.py +1 -0
- agent_chat/adapter.py +414 -0
- agent_chat/admin.py +524 -0
- agent_chat/api.py +641 -0
- agent_chat/auth.py +226 -0
- agent_chat/browser.py +118 -0
- agent_chat/browser_verify.py +487 -0
- agent_chat/browser_verify_artifacts.py +280 -0
- agent_chat/browser_verify_checks.py +236 -0
- agent_chat/browser_verify_run.py +523 -0
- agent_chat/cli.py +532 -0
- agent_chat/client.py +272 -0
- agent_chat/deliveries.py +555 -0
- agent_chat/events.py +48 -0
- agent_chat/feed.py +193 -0
- agent_chat/http_boundary.py +154 -0
- agent_chat/instance_client.py +349 -0
- agent_chat/instance_file.py +207 -0
- agent_chat/instance_worker.py +326 -0
- agent_chat/mcp/__init__.py +5 -0
- agent_chat/mcp/__main__.py +39 -0
- agent_chat/mcp/app.py +183 -0
- agent_chat/mcp/auth.py +67 -0
- agent_chat/mcp/config.py +55 -0
- agent_chat/mcp/tools.py +295 -0
- agent_chat/metrics.py +60 -0
- agent_chat/models.py +430 -0
- agent_chat/openapi.py +322 -0
- agent_chat/producer.py +208 -0
- agent_chat/protocol.py +71 -0
- agent_chat/publication.py +252 -0
- agent_chat/receipts.py +225 -0
- agent_chat/retention.py +154 -0
- agent_chat/roles.py +153 -0
- agent_chat/rooms.py +179 -0
- agent_chat/sessions.py +340 -0
- agent_chat/skills/agent-chat/SKILL.md +64 -0
- agent_chat/state.py +144 -0
- agent_chat/storage.py +110 -0
- agent_chat/threads.py +50 -0
- agent_chat/web/Manrope-OFL.txt +93 -0
- agent_chat/web/Manrope-Variable.ttf +0 -0
- agent_chat/web/chat.css +936 -0
- agent_chat/web/chat.js +1922 -0
- agent_chat/web/i18n.js +340 -0
- agent_chat/web/index.html +264 -0
- sessionyard-0.7.0.dist-info/METADATA +314 -0
- sessionyard-0.7.0.dist-info/RECORD +62 -0
- sessionyard-0.7.0.dist-info/WHEEL +4 -0
- sessionyard-0.7.0.dist-info/entry_points.txt +3 -0
- sessionyard-0.7.0.dist-info/licenses/LICENSE +661 -0
agent_chat/001_core.sql
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
-- The complete schema. Delivery admissions hold IDs and outcomes only; native execution stays outside PostgreSQL.
|
|
2
|
+
CREATE TABLE agent_chat.principals (
|
|
3
|
+
id uuid PRIMARY KEY,
|
|
4
|
+
kind text NOT NULL CHECK (kind IN ('operator', 'agent')),
|
|
5
|
+
credential_hash text NOT NULL UNIQUE CHECK (credential_hash ~ '^[0-9a-f]{64}$'),
|
|
6
|
+
revoked boolean NOT NULL DEFAULT false,
|
|
7
|
+
host text,
|
|
8
|
+
harness text,
|
|
9
|
+
CHECK ((kind = 'operator' AND host IS NULL AND harness IS NULL)
|
|
10
|
+
OR (kind = 'agent' AND host IS NOT NULL AND harness IS NOT NULL AND harness IN ('claude', 'pi', 'codex')))
|
|
11
|
+
);
|
|
12
|
+
CREATE TABLE agent_chat.rooms (
|
|
13
|
+
id uuid PRIMARY KEY,
|
|
14
|
+
slug text NOT NULL UNIQUE CHECK (slug ~ '^[a-z0-9][a-z0-9-]{0,62}$'),
|
|
15
|
+
label text NOT NULL
|
|
16
|
+
);
|
|
17
|
+
INSERT INTO agent_chat.rooms VALUES
|
|
18
|
+
('00000000-0000-4000-8000-000000000001', 'homelab', 'Homelab');
|
|
19
|
+
CREATE TABLE agent_chat.principal_rooms (
|
|
20
|
+
principal_id uuid NOT NULL REFERENCES agent_chat.principals(id),
|
|
21
|
+
room_id uuid NOT NULL REFERENCES agent_chat.rooms(id),
|
|
22
|
+
PRIMARY KEY (principal_id, room_id)
|
|
23
|
+
);
|
|
24
|
+
CREATE TABLE agent_chat.sessions (
|
|
25
|
+
id uuid PRIMARY KEY,
|
|
26
|
+
principal_id uuid NOT NULL REFERENCES agent_chat.principals(id),
|
|
27
|
+
native_session_id text NOT NULL,
|
|
28
|
+
label text NOT NULL,
|
|
29
|
+
muted boolean NOT NULL DEFAULT false,
|
|
30
|
+
UNIQUE (principal_id, native_session_id)
|
|
31
|
+
);
|
|
32
|
+
CREATE TABLE agent_chat.memberships (
|
|
33
|
+
room_id uuid NOT NULL REFERENCES agent_chat.rooms(id),
|
|
34
|
+
session_id uuid NOT NULL REFERENCES agent_chat.sessions(id),
|
|
35
|
+
PRIMARY KEY (room_id, session_id)
|
|
36
|
+
);
|
|
37
|
+
CREATE TABLE agent_chat.instances (
|
|
38
|
+
id uuid PRIMARY KEY,
|
|
39
|
+
session_id uuid NOT NULL REFERENCES agent_chat.sessions(id),
|
|
40
|
+
boot_id uuid NOT NULL,
|
|
41
|
+
token_hash text NOT NULL UNIQUE CHECK (token_hash ~ '^[0-9a-f]{64}$'),
|
|
42
|
+
heartbeat_at timestamptz NOT NULL DEFAULT clock_timestamp(),
|
|
43
|
+
ended_at timestamptz,
|
|
44
|
+
native_state text NOT NULL DEFAULT 'unknown' CHECK (native_state IN ('idle', 'busy', 'unknown')),
|
|
45
|
+
stopped boolean NOT NULL DEFAULT true,
|
|
46
|
+
plan_mode boolean NOT NULL DEFAULT true,
|
|
47
|
+
UNIQUE (session_id, boot_id)
|
|
48
|
+
);
|
|
49
|
+
CREATE UNIQUE INDEX one_current_instance ON agent_chat.instances(session_id) WHERE ended_at IS NULL;
|
|
50
|
+
CREATE TABLE agent_chat.threads (
|
|
51
|
+
id uuid PRIMARY KEY,
|
|
52
|
+
room_id uuid NOT NULL REFERENCES agent_chat.rooms(id),
|
|
53
|
+
root_message_id uuid NOT NULL,
|
|
54
|
+
agent_replies integer NOT NULL DEFAULT 0 CHECK (agent_replies BETWEEN 0 AND 6),
|
|
55
|
+
UNIQUE (id, room_id)
|
|
56
|
+
);
|
|
57
|
+
CREATE TABLE agent_chat.messages (
|
|
58
|
+
id uuid PRIMARY KEY,
|
|
59
|
+
room_id uuid NOT NULL REFERENCES agent_chat.rooms(id),
|
|
60
|
+
thread_id uuid NOT NULL,
|
|
61
|
+
reply_to uuid,
|
|
62
|
+
sender_principal_id uuid NOT NULL REFERENCES agent_chat.principals(id),
|
|
63
|
+
sender_session_id uuid REFERENCES agent_chat.sessions(id),
|
|
64
|
+
kind text NOT NULL CHECK (kind IN ('message', 'status', 'question', 'consultation', 'reply')),
|
|
65
|
+
-- NULL is a redacted parent tombstone; publication always supplies nonempty text.
|
|
66
|
+
body text CHECK (octet_length(body) BETWEEN 1 AND 16384),
|
|
67
|
+
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
|
|
68
|
+
expires_at timestamptz NOT NULL DEFAULT (clock_timestamp() + interval '720 hours'),
|
|
69
|
+
UNIQUE (id, room_id, thread_id),
|
|
70
|
+
FOREIGN KEY (thread_id, room_id) REFERENCES agent_chat.threads(id, room_id),
|
|
71
|
+
FOREIGN KEY (reply_to, room_id, thread_id) REFERENCES agent_chat.messages(id, room_id, thread_id),
|
|
72
|
+
CHECK ((kind = 'reply') = (reply_to IS NOT NULL))
|
|
73
|
+
);
|
|
74
|
+
-- Foreign-key delete checks and retention pruning look messages up by the message or thread they point at.
|
|
75
|
+
CREATE INDEX messages_reply_to ON agent_chat.messages(reply_to);
|
|
76
|
+
CREATE INDEX messages_thread ON agent_chat.messages(thread_id);
|
|
77
|
+
ALTER TABLE agent_chat.threads ADD CONSTRAINT root_in_thread
|
|
78
|
+
FOREIGN KEY (root_message_id, room_id, id)
|
|
79
|
+
REFERENCES agent_chat.messages(id, room_id, thread_id) DEFERRABLE INITIALLY DEFERRED;
|
|
80
|
+
CREATE TABLE agent_chat.delivery_batches (
|
|
81
|
+
id uuid PRIMARY KEY,
|
|
82
|
+
session_id uuid NOT NULL REFERENCES agent_chat.sessions(id),
|
|
83
|
+
message_ids uuid[] NOT NULL CHECK (cardinality(message_ids) BETWEEN 1 AND 16),
|
|
84
|
+
UNIQUE (id, session_id)
|
|
85
|
+
);
|
|
86
|
+
CREATE TABLE agent_chat.recipients (
|
|
87
|
+
message_id uuid NOT NULL REFERENCES agent_chat.messages(id),
|
|
88
|
+
session_id uuid NOT NULL REFERENCES agent_chat.sessions(id),
|
|
89
|
+
stored_at timestamptz NOT NULL DEFAULT clock_timestamp(),
|
|
90
|
+
handed_at timestamptz,
|
|
91
|
+
acknowledged_at timestamptz,
|
|
92
|
+
replying_message_id uuid REFERENCES agent_chat.messages(id),
|
|
93
|
+
uncertainty_reason text,
|
|
94
|
+
delivery_batch_id uuid,
|
|
95
|
+
PRIMARY KEY (message_id, session_id),
|
|
96
|
+
CONSTRAINT delivery_for_recipient_session
|
|
97
|
+
FOREIGN KEY (delivery_batch_id, session_id) REFERENCES agent_chat.delivery_batches(id, session_id)
|
|
98
|
+
);
|
|
99
|
+
CREATE INDEX recipients_session_message ON agent_chat.recipients(session_id, message_id);
|
|
100
|
+
CREATE INDEX recipients_delivery_batch ON agent_chat.recipients(delivery_batch_id)
|
|
101
|
+
WHERE delivery_batch_id IS NOT NULL;
|
|
102
|
+
-- Foreign-key delete checks and retention pruning look recipients up by the reply that answered them.
|
|
103
|
+
CREATE INDEX recipients_replying_message ON agent_chat.recipients(replying_message_id);
|
|
104
|
+
-- The singleton row serializes allocation through commit, unlike a sequence.
|
|
105
|
+
CREATE TABLE agent_chat.event_clock (
|
|
106
|
+
singleton boolean PRIMARY KEY DEFAULT true CHECK (singleton),
|
|
107
|
+
position bigint NOT NULL DEFAULT 0 CHECK (position >= 0),
|
|
108
|
+
retained_floor bigint NOT NULL DEFAULT 0 CHECK (retained_floor BETWEEN 0 AND position)
|
|
109
|
+
);
|
|
110
|
+
INSERT INTO agent_chat.event_clock DEFAULT VALUES;
|
|
111
|
+
CREATE TABLE agent_chat.events (
|
|
112
|
+
position bigint PRIMARY KEY,
|
|
113
|
+
room_id uuid NOT NULL REFERENCES agent_chat.rooms(id),
|
|
114
|
+
kind text NOT NULL CHECK (kind IN ('message', 'receipt', 'control')),
|
|
115
|
+
message_id uuid REFERENCES agent_chat.messages(id),
|
|
116
|
+
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
|
|
117
|
+
-- Events invalidate a room's view; receipt and session tables remain the state owners.
|
|
118
|
+
session_id uuid REFERENCES agent_chat.sessions(id)
|
|
119
|
+
);
|
|
120
|
+
CREATE INDEX events_room_position ON agent_chat.events(room_id, position);
|
|
121
|
+
CREATE INDEX events_message ON agent_chat.events(message_id);
|
|
122
|
+
CREATE INDEX messages_expiry ON agent_chat.messages(expires_at);
|
|
123
|
+
CREATE TABLE agent_chat.requests (
|
|
124
|
+
principal_id uuid NOT NULL REFERENCES agent_chat.principals(id),
|
|
125
|
+
scope_id uuid NOT NULL,
|
|
126
|
+
key uuid NOT NULL,
|
|
127
|
+
digest text NOT NULL CHECK (digest ~ '^[0-9a-f]{64}$'),
|
|
128
|
+
message_id uuid NOT NULL REFERENCES agent_chat.messages(id),
|
|
129
|
+
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
|
|
130
|
+
PRIMARY KEY (principal_id, scope_id, key)
|
|
131
|
+
);
|
|
132
|
+
CREATE INDEX requests_message ON agent_chat.requests(message_id);
|
|
133
|
+
|
|
134
|
+
CREATE TABLE agent_chat.browser_sessions (
|
|
135
|
+
token_hash text PRIMARY KEY CHECK (token_hash ~ '^[0-9a-f]{64}$'),
|
|
136
|
+
principal_id uuid NOT NULL REFERENCES agent_chat.principals(id),
|
|
137
|
+
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
|
|
138
|
+
expires_at timestamptz NOT NULL DEFAULT (clock_timestamp() + interval '8 hours')
|
|
139
|
+
);
|
|
140
|
+
CREATE INDEX ON agent_chat.browser_sessions(expires_at);
|
|
141
|
+
|
|
142
|
+
-- A service-wide failure budget avoids trusting proxy/client address headers.
|
|
143
|
+
CREATE TABLE agent_chat.login_guard (
|
|
144
|
+
singleton boolean PRIMARY KEY DEFAULT true CHECK (singleton),
|
|
145
|
+
failures timestamptz[] NOT NULL DEFAULT '{}' CHECK (cardinality(failures) <= 10)
|
|
146
|
+
);
|
|
147
|
+
INSERT INTO agent_chat.login_guard(singleton) VALUES (true);
|
|
148
|
+
|
|
149
|
+
-- Delivery admissions and attempts. Reservations contain IDs and outcomes only.
|
|
150
|
+
CREATE TABLE agent_chat.delivery_attempts (
|
|
151
|
+
id uuid PRIMARY KEY,
|
|
152
|
+
batch_id uuid NOT NULL,
|
|
153
|
+
session_id uuid NOT NULL,
|
|
154
|
+
instance_id uuid NOT NULL REFERENCES agent_chat.instances(id),
|
|
155
|
+
request_key uuid NOT NULL,
|
|
156
|
+
ordinal integer NOT NULL CHECK (ordinal BETWEEN 1 AND 3),
|
|
157
|
+
admitted_at timestamptz NOT NULL,
|
|
158
|
+
expires_at timestamptz NOT NULL,
|
|
159
|
+
outcome text CHECK (outcome IN ('handed', 'failed', 'deferred', 'uncertain')),
|
|
160
|
+
reason text CHECK (reason IN ('busy', 'muted', 'stopped', 'plan', 'unknown',
|
|
161
|
+
'offline', 'stale_binding', 'native_unavailable', 'transport_ambiguous', 'claim_expired')),
|
|
162
|
+
completed_at timestamptz,
|
|
163
|
+
FOREIGN KEY (batch_id, session_id) REFERENCES agent_chat.delivery_batches(id, session_id) ON DELETE CASCADE,
|
|
164
|
+
UNIQUE (session_id, request_key),
|
|
165
|
+
UNIQUE (batch_id, ordinal),
|
|
166
|
+
CHECK (expires_at > admitted_at),
|
|
167
|
+
CHECK ((outcome IS NULL) = (completed_at IS NULL)),
|
|
168
|
+
CHECK ((outcome IS NULL OR outcome = 'handed') = (reason IS NULL))
|
|
169
|
+
);
|
|
170
|
+
CREATE UNIQUE INDEX one_inflight_delivery ON agent_chat.delivery_attempts(session_id) WHERE outcome IS NULL;
|
|
171
|
+
CREATE INDEX delivery_wake_window ON agent_chat.delivery_attempts(session_id, admitted_at);
|
|
172
|
+
CREATE INDEX delivery_expiry ON agent_chat.delivery_attempts(expires_at) WHERE outcome IS NULL;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
-- Coordination state: more message kinds, entity-keyed threads with resolution, an advisory lane on the live
|
|
2
|
+
-- instance, a producer principal and room state. Everything here is untrusted, advisory material: no delivery,
|
|
3
|
+
-- admission or authorization query reads it. 001 created the CHECKs below unnamed, so PostgreSQL generated their
|
|
4
|
+
-- names; DROP has no IF EXISTS, so a wrong name aborts the single migrate transaction.
|
|
5
|
+
|
|
6
|
+
-- Coordination kinds. They are never selected for delivery (deliveries.pending lists its kinds explicitly).
|
|
7
|
+
ALTER TABLE agent_chat.messages DROP CONSTRAINT messages_kind_check,
|
|
8
|
+
ADD CONSTRAINT message_kind CHECK (kind IN ('message', 'status', 'question', 'consultation', 'reply',
|
|
9
|
+
'heads_up', 'blocked_on', 'decision_needed', 'intent'));
|
|
10
|
+
|
|
11
|
+
-- Entity-keyed threads and their resolution. The database checks the coarse shape only;
|
|
12
|
+
-- models.REF_KEY_PATTERN is the one exact grammar.
|
|
13
|
+
ALTER TABLE agent_chat.threads
|
|
14
|
+
ADD COLUMN ref_key text CONSTRAINT thread_ref_key_shape
|
|
15
|
+
CHECK (ref_key ~ '^(pr|lane|resource):[A-Za-z0-9_./:#-]{1,180}$'),
|
|
16
|
+
ADD COLUMN resolved_at timestamptz,
|
|
17
|
+
ADD COLUMN resolved_by_principal_id uuid REFERENCES agent_chat.principals(id),
|
|
18
|
+
ADD CONSTRAINT thread_resolution CHECK ((resolved_at IS NULL) = (resolved_by_principal_id IS NULL));
|
|
19
|
+
CREATE UNIQUE INDEX thread_ref_key ON agent_chat.threads(room_id, ref_key) WHERE ref_key IS NOT NULL;
|
|
20
|
+
|
|
21
|
+
-- Advisory lane on the live instance. The database bounds the text only.
|
|
22
|
+
ALTER TABLE agent_chat.instances
|
|
23
|
+
ADD COLUMN lane text CONSTRAINT instance_lane_shape CHECK (lane ~ '^[A-Za-z0-9_./:-]{1,120}$'),
|
|
24
|
+
ADD COLUMN lane_since timestamptz,
|
|
25
|
+
ADD CONSTRAINT instance_lane_since CHECK ((lane IS NULL) = (lane_since IS NULL));
|
|
26
|
+
|
|
27
|
+
-- Producer principal: an authenticated machine writer of room state, with no harness, session or membership.
|
|
28
|
+
ALTER TABLE agent_chat.principals DROP CONSTRAINT principals_kind_check, DROP CONSTRAINT principals_check,
|
|
29
|
+
ADD COLUMN producer text,
|
|
30
|
+
ADD CONSTRAINT principal_kind CHECK (kind IN ('operator', 'agent', 'producer')),
|
|
31
|
+
ADD CONSTRAINT principal_shape CHECK (
|
|
32
|
+
(kind = 'operator' AND host IS NULL AND harness IS NULL AND producer IS NULL)
|
|
33
|
+
OR (kind = 'agent' AND host IS NOT NULL AND harness IS NOT NULL AND harness IN ('claude', 'pi', 'codex')
|
|
34
|
+
AND producer IS NULL)
|
|
35
|
+
OR (kind = 'producer' AND harness IS NULL AND host IS NOT NULL AND producer IS NOT NULL
|
|
36
|
+
AND host ~ '^[a-z0-9][a-z0-9-]{0,62}$' AND producer ~ '^[a-z0-9][a-z0-9-]{0,62}$'));
|
|
37
|
+
|
|
38
|
+
-- Room state: the latest value per key. This table is the only owner of the value; events only invalidate.
|
|
39
|
+
CREATE TABLE agent_chat.room_state (
|
|
40
|
+
room_id uuid NOT NULL REFERENCES agent_chat.rooms(id),
|
|
41
|
+
state_key text NOT NULL
|
|
42
|
+
CHECK (state_key ~ '^[a-z0-9][a-z0-9-]{0,62}:[a-z0-9][a-z0-9-]{0,62}:[a-z0-9][a-z0-9.-]{0,62}$'),
|
|
43
|
+
ref_key text CHECK (ref_key ~ '^resource:[a-z0-9][a-z0-9-]{0,62}:[a-z0-9][a-z0-9-]{0,62}$'),
|
|
44
|
+
value jsonb NOT NULL CHECK (jsonb_typeof(value) = 'object' AND octet_length(value::text) <= 4096),
|
|
45
|
+
producer_principal_id uuid NOT NULL REFERENCES agent_chat.principals(id),
|
|
46
|
+
-- Server clock at the last change of value or ref_key.
|
|
47
|
+
changed_at timestamptz NOT NULL,
|
|
48
|
+
-- Server clock at the last accepted upsert.
|
|
49
|
+
observed_at timestamptz NOT NULL,
|
|
50
|
+
expires_at timestamptz NOT NULL,
|
|
51
|
+
PRIMARY KEY (room_id, state_key),
|
|
52
|
+
CHECK (changed_at <= observed_at AND expires_at > observed_at
|
|
53
|
+
AND expires_at <= observed_at + interval '3600 seconds')
|
|
54
|
+
);
|
|
55
|
+
CREATE INDEX room_state_producer ON agent_chat.room_state(producer_principal_id);
|
|
56
|
+
CREATE INDEX room_state_expiry ON agent_chat.room_state(expires_at);
|
|
57
|
+
|
|
58
|
+
-- Replay events. There is no FK to room_state, because state rows are pruned independently of events.
|
|
59
|
+
ALTER TABLE agent_chat.events DROP CONSTRAINT events_kind_check,
|
|
60
|
+
ADD COLUMN state_key text,
|
|
61
|
+
ADD CONSTRAINT event_kind CHECK (kind IN ('message', 'receipt', 'control', 'state', 'thread')),
|
|
62
|
+
ADD CONSTRAINT event_state_key CHECK ((kind = 'state') = (state_key IS NOT NULL)),
|
|
63
|
+
ADD CONSTRAINT event_thread_root CHECK (kind <> 'thread' OR message_id IS NOT NULL);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
-- Harness admission: deepseek and opencode join claude, pi and codex. Admission alone grants nothing;
|
|
2
|
+
-- a principal still needs an operator-created credential. Only the harness set changes; the shape is 002's.
|
|
3
|
+
ALTER TABLE agent_chat.principals DROP CONSTRAINT IF EXISTS principal_shape,
|
|
4
|
+
ADD CONSTRAINT principal_shape CHECK (
|
|
5
|
+
(kind = 'operator' AND host IS NULL AND harness IS NULL AND producer IS NULL)
|
|
6
|
+
OR (kind = 'agent' AND host IS NOT NULL AND harness IS NOT NULL
|
|
7
|
+
AND harness IN ('claude', 'pi', 'codex', 'deepseek', 'opencode')
|
|
8
|
+
AND producer IS NULL)
|
|
9
|
+
OR (kind = 'producer' AND harness IS NULL AND host IS NOT NULL AND producer IS NOT NULL
|
|
10
|
+
AND host ~ '^[a-z0-9][a-z0-9-]{0,62}$' AND producer ~ '^[a-z0-9][a-z0-9-]{0,62}$'));
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- Viewers have only explicit principal_rooms grants and browser authentication, never a native identity.
|
|
2
|
+
ALTER TABLE agent_chat.principals DROP CONSTRAINT principal_kind, DROP CONSTRAINT principal_shape,
|
|
3
|
+
ADD CONSTRAINT principal_kind CHECK (kind IN ('operator', 'agent', 'producer', 'viewer')),
|
|
4
|
+
ADD CONSTRAINT principal_shape CHECK (
|
|
5
|
+
(kind IN ('operator', 'viewer') AND host IS NULL AND harness IS NULL AND producer IS NULL)
|
|
6
|
+
OR (kind = 'agent' AND host IS NOT NULL AND harness IS NOT NULL
|
|
7
|
+
AND harness IN ('claude', 'pi', 'codex', 'deepseek', 'opencode') AND producer IS NULL)
|
|
8
|
+
OR (kind = 'producer' AND harness IS NULL AND host IS NOT NULL AND producer IS NOT NULL
|
|
9
|
+
AND host ~ '^[a-z0-9][a-z0-9-]{0,62}$' AND producer ~ '^[a-z0-9][a-z0-9-]{0,62}$'));
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
-- Volume quotas count registrations and agent publications in a rolling hour (sessions.register, publication.publish).
|
|
2
|
+
-- Existing instances take the migration time, so they count once toward their principal's first hour.
|
|
3
|
+
ALTER TABLE agent_chat.instances ADD COLUMN created_at timestamptz NOT NULL DEFAULT clock_timestamp();
|
|
4
|
+
CREATE INDEX instances_created ON agent_chat.instances(created_at);
|
|
5
|
+
CREATE INDEX messages_sender_window ON agent_chat.messages(sender_session_id, created_at)
|
|
6
|
+
WHERE sender_session_id IS NOT NULL;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
-- Sender receipts: a non-waking ledger that tells the sending session its message was handed to or acknowledged
|
|
2
|
+
-- by a recipient (receipts.record, receipts.eligible owns the policy). A `replied` receipt is the reply message
|
|
3
|
+
-- itself and has no row here. Nothing here wakes a model, charges a wake budget or writes a replay event.
|
|
4
|
+
-- The sender opts in per message; the policy ignores the flag for kinds that never carry receipts.
|
|
5
|
+
ALTER TABLE agent_chat.messages ADD COLUMN receipts_requested boolean NOT NULL DEFAULT false;
|
|
6
|
+
-- At most one row per message, recipient and state: an addressed message can have several recipients.
|
|
7
|
+
-- Retention collects a message row and its receipts together (ON DELETE CASCADE).
|
|
8
|
+
CREATE TABLE agent_chat.sender_receipts (
|
|
9
|
+
id uuid PRIMARY KEY,
|
|
10
|
+
message_id uuid NOT NULL REFERENCES agent_chat.messages(id) ON DELETE CASCADE,
|
|
11
|
+
sender_session_id uuid NOT NULL REFERENCES agent_chat.sessions(id),
|
|
12
|
+
state text NOT NULL CHECK (state IN ('handed', 'acked')),
|
|
13
|
+
recipient_session_id uuid NOT NULL REFERENCES agent_chat.sessions(id),
|
|
14
|
+
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
|
|
15
|
+
delivered_at timestamptz,
|
|
16
|
+
UNIQUE (message_id, recipient_session_id, state)
|
|
17
|
+
);
|
|
18
|
+
-- The sender feed reads its own undelivered rows oldest first.
|
|
19
|
+
CREATE INDEX sender_receipts_undelivered ON agent_chat.sender_receipts(sender_session_id, created_at, id)
|
|
20
|
+
WHERE delivered_at IS NULL;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
-- Direct 1:1 threads: higher reply and wake limits for a thread between exactly two sessions, with a loop detector.
|
|
2
|
+
-- The thread row holds the state: publication writes it under the event clock and the thread lock, so no verdict
|
|
3
|
+
-- depends on message history, which retention prunes while the thread lives. The functions below are the one
|
|
4
|
+
-- definition of each term; publication, pending and claim all call them. models.py owns the numbers.
|
|
5
|
+
|
|
6
|
+
-- The direct reply limit (models.DIRECT_REPLY_LIMIT) exceeds the CHECK of 001, which PostgreSQL named.
|
|
7
|
+
ALTER TABLE agent_chat.threads DROP CONSTRAINT threads_agent_replies_check,
|
|
8
|
+
ADD CONSTRAINT thread_agent_replies CHECK (agent_replies BETWEEN 0 AND 20);
|
|
9
|
+
|
|
10
|
+
-- Each admission is charged to one per-session allowance. Admissions before this migration count as 'other'.
|
|
11
|
+
ALTER TABLE agent_chat.delivery_attempts ADD COLUMN allowance text NOT NULL DEFAULT 'other'
|
|
12
|
+
CONSTRAINT delivery_allowance CHECK (allowance IN ('direct', 'other'));
|
|
13
|
+
|
|
14
|
+
-- `participants`: every session that sent or received any message in the thread since this migration, kept after
|
|
15
|
+
-- those messages expire. An operator has no session, so an operator sender adds none; the sessions an operator
|
|
16
|
+
-- message addresses join.
|
|
17
|
+
-- `participants_complete`: whether `participants` names every session that ever took part. A thread that exists
|
|
18
|
+
-- when this migration runs is incomplete for good: retention may already have removed the messages and recipient
|
|
19
|
+
-- rows that named some of its sessions, and nothing stored shows whether it has, so no history is read back. Such a
|
|
20
|
+
-- thread is never direct and keeps the limits it had before. The ADD COLUMN default `false` is what the existing
|
|
21
|
+
-- rows take; the default is then changed to `true`, which every thread created from now on takes.
|
|
22
|
+
-- `loop_stamps`: the clock time of each counted reply since the last operator reset, in publication order. The
|
|
23
|
+
-- reset clears them with the reply count, so a stamp never outlives its reply. Replies counted before this
|
|
24
|
+
-- migration carry no stamp, so the detector sees only replies published after it.
|
|
25
|
+
ALTER TABLE agent_chat.threads
|
|
26
|
+
ADD COLUMN participants uuid[] NOT NULL DEFAULT '{}',
|
|
27
|
+
ADD COLUMN participants_complete boolean NOT NULL DEFAULT false,
|
|
28
|
+
ADD COLUMN loop_stamps timestamptz[] NOT NULL DEFAULT '{}',
|
|
29
|
+
ADD CONSTRAINT thread_loop_stamps CHECK (cardinality(loop_stamps) <= agent_replies);
|
|
30
|
+
ALTER TABLE agent_chat.threads ALTER COLUMN participants_complete SET DEFAULT true;
|
|
31
|
+
|
|
32
|
+
-- Direct: complete participants that are exactly two sessions, counting the sessions a message being published
|
|
33
|
+
-- would add (`joining`). A thread whose participants are not complete is never direct.
|
|
34
|
+
CREATE FUNCTION agent_chat.thread_direct(complete boolean, participants uuid[], joining uuid[]) RETURNS boolean
|
|
35
|
+
LANGUAGE sql IMMUTABLE AS $$
|
|
36
|
+
SELECT complete AND (SELECT count(DISTINCT member) = 2 FROM unnest(participants || joining) AS member)
|
|
37
|
+
$$;
|
|
38
|
+
|
|
39
|
+
-- Loop detector: some `replies` consecutive stamps span at most `window_seconds`. The stamps are wall-clock readings,
|
|
40
|
+
-- so a clock stepped back can shorten a span and trip the detector early, which fails closed. An operator message
|
|
41
|
+
-- of a counted kind clears the stamps.
|
|
42
|
+
CREATE FUNCTION agent_chat.thread_loop_tripped(stamps timestamptz[], replies integer, window_seconds integer)
|
|
43
|
+
RETURNS boolean
|
|
44
|
+
LANGUAGE sql IMMUTABLE AS $$
|
|
45
|
+
SELECT EXISTS (
|
|
46
|
+
SELECT 1 FROM generate_subscripts(stamps, 1) AS earliest
|
|
47
|
+
WHERE stamps[earliest + replies - 1] - stamps[earliest] <= make_interval(secs => window_seconds)
|
|
48
|
+
)
|
|
49
|
+
$$;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
-- PM mark: at most one session per room is marked as the project manager, and the service stamps the role
|
|
2
|
+
-- on the messages that session publishes while the mark is live. Only the operator sets or clears the mark, through
|
|
3
|
+
-- an HTTP route; nothing here grants any authority. models.py owns the expiry (PM_EXPIRY_HOURS).
|
|
4
|
+
|
|
5
|
+
-- `room_pm`: one row per room. The primary key is the one-mark rule and the target of the atomic swap, so a new
|
|
6
|
+
-- holder replaces the old one in one statement. A row is live only while `last_activity_at` is younger than the
|
|
7
|
+
-- expiry and its session is still a current member of the room with a principal that is not revoked; pm.py holds
|
|
8
|
+
-- that one test. No timer runs and no row is swept: a lapsed row counts as absent until the next set replaces it.
|
|
9
|
+
-- `set_at` is the clock time of the operator's set. `last_activity_at` starts equal to it and moves only when the
|
|
10
|
+
-- holder publishes or acknowledges, in the transaction of that action.
|
|
11
|
+
CREATE TABLE agent_chat.room_pm (
|
|
12
|
+
room_id uuid PRIMARY KEY REFERENCES agent_chat.rooms(id),
|
|
13
|
+
session_id uuid NOT NULL REFERENCES agent_chat.sessions(id),
|
|
14
|
+
set_at timestamptz NOT NULL,
|
|
15
|
+
last_activity_at timestamptz NOT NULL
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
-- `sender_role`: written by the service at publication when the sender is the live holder, never by a client.
|
|
19
|
+
-- Every message that exists when this migration runs takes NULL. The stamp is historical: it stays on a message
|
|
20
|
+
-- after the mark moves, is cleared or lapses. The CHECK closes the set of roles to `pm`; a further role needs a
|
|
21
|
+
-- further migration.
|
|
22
|
+
ALTER TABLE agent_chat.messages ADD COLUMN sender_role text
|
|
23
|
+
CONSTRAINT message_sender_role CHECK (sender_role = 'pm');
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
-- Migration 006 stamps every instance that existed at apply time with the migration
|
|
2
|
+
-- clock, so a database upgraded from 005 counts a principal's whole registration
|
|
3
|
+
-- history against its first rolling hour and refuses every new registration until
|
|
4
|
+
-- that hour passes. Move only the rows 006 stamped, bounded by the recorded
|
|
5
|
+
-- version-006 applied_at: a genuine registration made afterwards keeps its real
|
|
6
|
+
-- created_at and its share of the hourly quota.
|
|
7
|
+
UPDATE agent_chat.instances
|
|
8
|
+
SET created_at = clock_timestamp() - make_interval(secs => 3601)
|
|
9
|
+
WHERE created_at > clock_timestamp() - make_interval(secs => 3600)
|
|
10
|
+
AND created_at <= (
|
|
11
|
+
SELECT applied_at FROM agent_chat.schema_migrations WHERE version = 6
|
|
12
|
+
);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
-- Room role marks and the per-instance work declaration.
|
|
2
|
+
--
|
|
3
|
+
-- The single PM mark becomes the pm mark. Its wire stamp stays `pm`, so historical
|
|
4
|
+
-- messages, `--from pm` and the existing skills keep their meaning; github_pm and delivery_manager stamp their
|
|
5
|
+
-- own values. One live role per session is enforced by roles.assign under the event clock, not by a unique
|
|
6
|
+
-- index: liveness is clock-dependent and a partial index predicate must be immutable.
|
|
7
|
+
CREATE TABLE agent_chat.room_roles (
|
|
8
|
+
room_id uuid NOT NULL REFERENCES agent_chat.rooms(id),
|
|
9
|
+
role text NOT NULL CONSTRAINT room_role
|
|
10
|
+
CHECK (role IN ('pm', 'github_pm', 'delivery_manager')),
|
|
11
|
+
session_id uuid NOT NULL REFERENCES agent_chat.sessions(id),
|
|
12
|
+
set_at timestamptz NOT NULL,
|
|
13
|
+
last_activity_at timestamptz NOT NULL,
|
|
14
|
+
PRIMARY KEY (room_id, role)
|
|
15
|
+
);
|
|
16
|
+
CREATE INDEX room_roles_session ON agent_chat.room_roles(session_id);
|
|
17
|
+
|
|
18
|
+
INSERT INTO agent_chat.room_roles (room_id, role, session_id, set_at, last_activity_at)
|
|
19
|
+
SELECT room_id, 'pm', session_id, set_at, last_activity_at FROM agent_chat.room_pm;
|
|
20
|
+
DROP TABLE agent_chat.room_pm;
|
|
21
|
+
|
|
22
|
+
ALTER TABLE agent_chat.messages DROP CONSTRAINT message_sender_role;
|
|
23
|
+
ALTER TABLE agent_chat.messages ADD CONSTRAINT message_sender_role
|
|
24
|
+
CHECK (sender_role IN ('pm', 'github_pm', 'delivery_manager'));
|
|
25
|
+
|
|
26
|
+
-- A JSON object from forge to repository names. models.WorkDeclaration owns the element grammar and the
|
|
27
|
+
-- count; this CHECK bounds the stored shape and text.
|
|
28
|
+
ALTER TABLE agent_chat.instances ADD COLUMN repositories jsonb NOT NULL DEFAULT '{}'::jsonb
|
|
29
|
+
CONSTRAINT instance_repositories_shape CHECK (
|
|
30
|
+
jsonb_typeof(repositories) = 'object' AND octet_length(repositories::text) <= 4096
|
|
31
|
+
);
|
agent_chat/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Agent Chat storage; no server or harness activation on import."""
|