oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1-- Generated by rastrillo migration generate; DO NOT EDIT.
2-- The schema every migration in this directory adds up to.
3
4CREATE TABLE accounts (id integer PRIMARY KEY AUTOINCREMENT, label text, revision integer);
5
6CREATE TABLE actions (
7 id INTEGER PRIMARY KEY,
8 job_id INTEGER NOT NULL REFERENCES jobs(id),
9 step_id INTEGER NOT NULL,
10 attempt_id INTEGER NOT NULL,
11 fence INTEGER NOT NULL,
12 key TEXT NOT NULL,
13 operation TEXT NOT NULL,
14 class TEXT NOT NULL,
15 payload_hash TEXT NOT NULL,
16 payload BLOB NOT NULL,
17 state TEXT NOT NULL,
18 reservation_id INTEGER NOT NULL,
19 grant_ref TEXT NOT NULL,
20 grant_version INTEGER NOT NULL,
21 grant_epoch INTEGER NOT NULL,
22 admitted_at TEXT NOT NULL,
23 admission_ends TEXT NOT NULL,
24 receipt TEXT NOT NULL,
25 last_error TEXT NOT NULL,
26 created_at TEXT NOT NULL,
27 updated_at TEXT NOT NULL,
28 admitted_incarnation INTEGER NOT NULL DEFAULT 0,
29 UNIQUE(job_id, key)
30);
31
32CREATE TABLE artifacts (
33 id INTEGER PRIMARY KEY,
34 job_id INTEGER NOT NULL REFERENCES jobs(id),
35 step_id INTEGER NOT NULL,
36 attempt_id INTEGER NOT NULL,
37 fence INTEGER NOT NULL,
38 role TEXT NOT NULL,
39 hash TEXT NOT NULL,
40 media_type TEXT NOT NULL,
41 size INTEGER NOT NULL,
42 provenance TEXT NOT NULL,
43 payload BLOB NOT NULL,
44 created_at TEXT NOT NULL
45);
46
47CREATE TABLE attempts (
48 id INTEGER PRIMARY KEY,
49 job_id INTEGER NOT NULL REFERENCES jobs(id),
50 step_id INTEGER NOT NULL REFERENCES steps(id),
51 number INTEGER NOT NULL,
52 runner TEXT NOT NULL,
53 workspace TEXT NOT NULL,
54 fence INTEGER NOT NULL,
55 lease_deadline TEXT NOT NULL,
56 state TEXT NOT NULL,
57 containment TEXT NOT NULL,
58 stop_requested TEXT NOT NULL,
59 stop_acked TEXT NOT NULL,
60 provider TEXT NOT NULL,
61 model TEXT NOT NULL,
62 effort TEXT NOT NULL,
63 outcome TEXT NOT NULL,
64 created_at TEXT NOT NULL,
65 updated_at TEXT NOT NULL,
66 UNIQUE(job_id, workspace)
67);
68
69CREATE TABLE audit_events (id integer PRIMARY KEY AUTOINCREMENT, actor text, kind text, record_id text, at datetime);
70
71CREATE TABLE budget_records (team_id text, revision integer, config text, PRIMARY KEY (team_id));
72
73CREATE TABLE decision_owners (project_id integer, decision text, address text, PRIMARY KEY (project_id, decision));
74
75CREATE TABLE events (
76 job_id INTEGER NOT NULL REFERENCES jobs(id),
77 seq INTEGER NOT NULL,
78 type TEXT NOT NULL,
79 actor TEXT NOT NULL,
80 payload BLOB NOT NULL,
81 source_at TEXT NOT NULL,
82 PRIMARY KEY(job_id, seq)
83);
84
85CREATE TABLE jobs (
86 request_key TEXT NOT NULL DEFAULT "",
87 request_hash TEXT NOT NULL DEFAULT "",
88 grant_stale INTEGER NOT NULL DEFAULT 0,
89 id INTEGER PRIMARY KEY,
90 account TEXT NOT NULL,
91 parent INTEGER NOT NULL,
92 depth INTEGER NOT NULL,
93 requester TEXT NOT NULL,
94 target TEXT NOT NULL,
95 evidence TEXT NOT NULL,
96 policy_version INTEGER NOT NULL,
97 policy TEXT NOT NULL,
98 grant_ref TEXT NOT NULL,
99 grant_version INTEGER NOT NULL,
100 grant_epoch INTEGER NOT NULL,
101 grant_observed_at TEXT NOT NULL,
102 state TEXT NOT NULL,
103 wait TEXT NOT NULL,
104 revision INTEGER NOT NULL,
105 outcome TEXT NOT NULL,
106 created_at TEXT NOT NULL,
107 updated_at TEXT NOT NULL
108, project_id INTEGER NOT NULL DEFAULT 0);
109
110CREATE TABLE members (address text, role text, revision integer, active numeric, session_epoch integer, PRIMARY KEY (address));
111
112CREATE TABLE period_budgets (
113 content_hash TEXT NOT NULL DEFAULT "",
114 account TEXT PRIMARY KEY, revision INTEGER NOT NULL, config TEXT NOT NULL
115);
116
117CREATE TABLE project_requests (actor text, operation text, request_id text, input_hash text, result text, PRIMARY KEY (actor, operation, request_id));
118
119CREATE TABLE projects (
120 grant_version INTEGER NOT NULL DEFAULT 1,id integer PRIMARY KEY AUTOINCREMENT, account_id integer, name text, repository text NOT NULL, app_name text NOT NULL, default_branch text, kind text, revision integer);
121
122CREATE TABLE reservations (
123 project_id INTEGER NOT NULL DEFAULT 0,
124 period TEXT NOT NULL DEFAULT "",
125 cost_unavailable INTEGER NOT NULL DEFAULT 0,
126 s_cached INTEGER NOT NULL DEFAULT 0,
127 id INTEGER PRIMARY KEY,
128 account TEXT NOT NULL,
129 job_id INTEGER NOT NULL REFERENCES jobs(id),
130 step_id INTEGER NOT NULL,
131 attempt_id INTEGER NOT NULL,
132 action_id INTEGER NOT NULL,
133 r_calls INTEGER NOT NULL, r_input INTEGER NOT NULL, r_output INTEGER NOT NULL, r_cost INTEGER NOT NULL,
134 s_calls INTEGER NOT NULL, s_input INTEGER NOT NULL, s_output INTEGER NOT NULL, s_cost INTEGER NOT NULL,
135 state TEXT NOT NULL,
136 receipt_id TEXT NOT NULL,
137 settled_by TEXT NOT NULL,
138 created_at TEXT NOT NULL,
139 settled_at TEXT NOT NULL
140);
141
142CREATE TABLE service (
143 release_required INTEGER NOT NULL DEFAULT 0,
144 recovery_revision INTEGER NOT NULL DEFAULT 0,
145 reconciled_revision INTEGER NOT NULL DEFAULT -1,
146 clock_high_water TEXT NOT NULL DEFAULT "",
147 id INTEGER PRIMARY KEY CHECK (id = 1),
148 schema_version INTEGER NOT NULL,
149 incarnation INTEGER NOT NULL,
150 revision INTEGER NOT NULL DEFAULT 0,
151 restore_uncertain INTEGER NOT NULL DEFAULT 0,
152 admission_paused INTEGER NOT NULL,
153 quarantine INTEGER NOT NULL,
154 quarantine_why TEXT NOT NULL
155);
156
157CREATE TABLE specialists (key text, model_selection text, provider text, model_family text, model text, standing_instructions text, max_concurrent integer, revision integer, team_id text NOT NULL DEFAULT "",creator text NOT NULL DEFAULT "",name text NOT NULL DEFAULT "",icon text NOT NULL DEFAULT "",role text NOT NULL DEFAULT "",required numeric NOT NULL DEFAULT false,archived numeric NOT NULL DEFAULT false,allowed_models text NOT NULL DEFAULT "[]",tools text NOT NULL DEFAULT "[]",project_ids text NOT NULL DEFAULT "[]",template_id text NOT NULL DEFAULT "",template_version integer NOT NULL DEFAULT 0,template_base text NOT NULL DEFAULT "{}", PRIMARY KEY (key));
158
159CREATE TABLE steps (
160 id INTEGER PRIMARY KEY,
161 job_id INTEGER NOT NULL REFERENCES jobs(id),
162 key TEXT NOT NULL,
163 capability TEXT NOT NULL,
164 version INTEGER NOT NULL,
165 depends_on TEXT NOT NULL,
166 state TEXT NOT NULL,
167 fence INTEGER NOT NULL,
168 holder INTEGER NOT NULL,
169 attempts INTEGER NOT NULL,
170 UNIQUE(job_id, key)
171);
172
173CREATE TABLE teams (id text, name text, roster_epoch integer, PRIMARY KEY (id));
174
175CREATE TABLE time_reservations (
176 elapsed_unknown INTEGER NOT NULL DEFAULT 0,
177 attempt_id INTEGER PRIMARY KEY REFERENCES attempts(id),
178 account TEXT NOT NULL, project_id INTEGER NOT NULL,
179 job_id INTEGER NOT NULL REFERENCES jobs(id), period TEXT NOT NULL,
180 reserved_seconds INTEGER NOT NULL, settled_seconds INTEGER NOT NULL,
181 state TEXT NOT NULL, settled_at TEXT NOT NULL
182);
183
184CREATE UNIQUE INDEX account_label ON accounts(lower(trim(label)));
185
186CREATE INDEX actions_state ON actions(state);
187
188CREATE INDEX artifacts_job ON artifacts(job_id, role);
189
190CREATE INDEX attempts_job ON attempts(job_id, containment);
191
192CREATE UNIQUE INDEX attempts_one_live ON attempts(step_id) WHERE containment = 'pending';
193
194CREATE INDEX idx_decision_owners_address ON decision_owners(address);
195
196CREATE INDEX jobs_account ON jobs(account, state);
197
198CREATE UNIQUE INDEX project_binding ON projects(repository, app_name);
199
200CREATE INDEX reservations_account ON reservations(account, state);
201
202CREATE INDEX reservations_job ON reservations(job_id, state);
203
204CREATE INDEX time_reservations_account ON time_reservations(account, project_id, state, period);
205
206CREATE TABLE grant_fences (ref TEXT PRIMARY KEY, version INTEGER NOT NULL, epoch INTEGER NOT NULL);
207CREATE TABLE recovery_charges (key TEXT PRIMARY KEY, account TEXT NOT NULL, project_id INTEGER NOT NULL, reserved TEXT NOT NULL, actor TEXT NOT NULL, reason TEXT NOT NULL, incarnation INTEGER NOT NULL, created_at TEXT NOT NULL);
208CREATE TABLE recovery_events (revision INTEGER PRIMARY KEY, kind TEXT NOT NULL, actor TEXT NOT NULL, reason TEXT NOT NULL, snapshot_hash TEXT NOT NULL);
209
210CREATE INDEX reservations_period_account ON reservations(account,state,period);
211CREATE INDEX reservations_period_project ON reservations(account,project_id,state,period);
212CREATE INDEX time_period_account ON time_reservations(account,state,period);
213CREATE INDEX time_period_project ON time_reservations(account,project_id,state,period);
214CREATE INDEX recovery_charges_scope ON recovery_charges(account,project_id);
215CREATE TABLE runners (
216 id text PRIMARY KEY,
217 person text,
218 machine_key_hash text,
219 label text,
220 revision integer,
221 revoked_at datetime,
222 instance_id text,
223 role text,
224 removing_at datetime,
225 tainted_at datetime
226);
227CREATE INDEX runner_person ON runners(person);
228CREATE TABLE runner_enrolments (
229 id text PRIMARY KEY,
230 instance_id text,
231 audience text,
232 machine_public_key text,
233 machine_key_hash text,
234 label text,
235 device_secret_hash text,
236 user_code_hash text,
237 challenge text,
238 expires_at datetime,
239 next_poll_at datetime,
240 person text,
241 runner_id text,
242 approved_at datetime,
243 consumed_at datetime,
244 revoked_at datetime
245);
246CREATE UNIQUE INDEX runner_device_secret ON runner_enrolments(device_secret_hash);
247CREATE UNIQUE INDEX runner_user_code ON runner_enrolments(user_code_hash);
248CREATE TABLE runner_credentials (
249 id text PRIMARY KEY,
250 runner_id text,
251 instance_id text,
252 audience text,
253 person text,
254 machine_key_hash text,
255 token_hash text,
256 expires_at datetime,
257 rotated_at datetime,
258 revoked_at datetime
259);
260CREATE INDEX runner_credential_runner ON runner_credentials(runner_id);
261CREATE UNIQUE INDEX runner_token ON runner_credentials(token_hash);
262CREATE TABLE runner_rates (
263 key text PRIMARY KEY,
264 window_start datetime,
265 count integer
266);
267CREATE TABLE connections (
268 label text,
269 revoked_at datetime,
270 id text PRIMARY KEY,
271 runner_id text,
272 person text,
273 local_id text,
274 revision integer,
275 last_seen datetime,
276 reports_json text,
277 security_hash text
278);
279CREATE UNIQUE INDEX connection_local ON connections(runner_id, local_id);
280CREATE INDEX connection_person ON connections(person);
281CREATE TABLE connection_choices (
282 person text,
283 project_id integer,
284 revision integer,
285 connection_ids_json text,
286 pinned_id text, mode text NOT NULL DEFAULT "best_fit",
287 PRIMARY KEY(person, project_id)
288);
289CREATE TABLE isolation_acknowledgements (
290 id text PRIMARY KEY,
291 connection_id text,
292 owner text,
293 provider text,
294 provider_version text,
295 paseo_version text,
296 isolation_config_hash text,
297 acknowledged_at datetime,
298 connection_revision integer,
299 owner_revision integer,
300 revoked_at datetime
301);
302CREATE INDEX connection_ack ON isolation_acknowledgements(connection_id);
303CREATE TABLE connection_invalidations (
304 id integer PRIMARY KEY AUTOINCREMENT,
305 connection_id text,
306 revision integer,
307 reason text,
308 at datetime
309);
310CREATE INDEX connection_invalidation ON connection_invalidations(connection_id);
311
312CREATE TABLE tasks (id text, requester text, description text, request_id text, project_id integer, revision integer, job_id integer, state text, wait_code text, base_commit text, review_ref text, check_definition_hash text, team_id text, merge_owner text, baseline_test_set_hash text, PRIMARY KEY (id));
313CREATE UNIQUE INDEX task_request ON tasks(requester, request_id);
314CREATE TABLE task_outboxes (task_id text, state text, project_revision integer, budget_revision integer, engineering text, review text, prepared text, job_spec text, PRIMARY KEY (task_id));
315CREATE UNIQUE INDEX jobs_request ON jobs(account, requester, request_key) WHERE request_key <> '';
316
317
318CREATE TABLE admission_tickets (
319 action_id INTEGER PRIMARY KEY REFERENCES actions(id),
320 job_id INTEGER NOT NULL REFERENCES jobs(id),
321 request_id TEXT NOT NULL,
322 attempt_id INTEGER NOT NULL REFERENCES attempts(id),
323 fence INTEGER NOT NULL,
324 runner TEXT NOT NULL,
325 dispatch TEXT NOT NULL,
326 expires_at TEXT NOT NULL,
327 incarnation INTEGER NOT NULL,
328 UNIQUE(job_id, request_id)
329);
330
331
332CREATE TABLE runner_assignments (id text, task_id text, step_key text, workspace_key text, team_id text, runner_id text, person text, selection text, isolation text, kind text, state text, revision integer, job_id integer, attempt_id integer, fence integer, claim_request text, brief text, lease_deadline datetime, invalidation_id integer, PRIMARY KEY (id));
333CREATE UNIQUE INDEX runner_assignment_step ON runner_assignments(task_id, step_key, revision);
334CREATE TABLE runner_cleanups (id text, assignment_id text, runner_id text, person text, machine_key_hash text, instance_id text, audience text, token_hash text, fence integer, attempt_id integer, expires_at datetime, PRIMARY KEY(id));
335CREATE UNIQUE INDEX runner_cleanup_token ON runner_cleanups(token_hash);
336CREATE TABLE runner_observations (assignment_id text, request_id text, operation text, payload_hash text, payload text, at datetime, PRIMARY KEY(assignment_id, request_id));
337CREATE TABLE runner_rotations (runner_id text, assignment_id text, request_id text, state text, credential_id text, PRIMARY KEY(runner_id));
338CREATE TABLE artifact_blobs (team_id text, job_id integer, digest text, bytes blob, PRIMARY KEY(team_id, job_id, digest));
339CREATE TABLE artifact_blob_uploads (attempt_id integer, digest text, size integer, PRIMARY KEY(attempt_id, digest));
340
341CREATE TABLE runner_events (key text, assignment_id text, stream_key text, epoch text, sequence integer, kind text, content_hash text, body text, isolation text, PRIMARY KEY(key));
342CREATE INDEX runner_event_assignment ON runner_events(assignment_id);
343CREATE INDEX runner_event_timeline ON runner_events(stream_key, epoch, sequence);
344CREATE TABLE runner_event_ids (runner_id text, event_id text, event_key text, PRIMARY KEY(runner_id, event_id));
345CREATE TABLE runner_timelines (stream_key text, assignment_id text, epoch text, high_water integer, blocked numeric, isolation text, PRIMARY KEY(stream_key));
346CREATE INDEX runner_timeline_assignment ON runner_timelines(assignment_id);
347CREATE TABLE runner_artifact_requests (assignment_id text, request_id text, payload_hash text, artifact_id integer, PRIMARY KEY(assignment_id, request_id));
348
349CREATE TABLE questions (id text, assignment_id text, task_id text, server_id text, agent_id text, session_id text, permission_id text, kind text, attempt integer, fence integer, revision integer, raw_request text, input_hash text, state text, answer text, answered_by text, expires_at datetime, PRIMARY KEY(id));
350CREATE INDEX question_assignment ON questions(assignment_id);
351
352CREATE TABLE supervised_trials (id text PRIMARY KEY,runner_id text,owner text,owner_revision integer,acknowledged_at datetime,versions text,revoked_at datetime);
353CREATE INDEX trial_runner ON supervised_trials(runner_id);
354ALTER TABLE runner_assignments ADD COLUMN protocol_version integer NOT NULL DEFAULT 1;
355
356CREATE TABLE conversations (id text PRIMARY KEY, team_id text, person text, revision integer, last_sequence integer);
357CREATE UNIQUE INDEX conversation_person ON conversations(team_id,person);
358CREATE TABLE conversation_threads (id text PRIMARY KEY, task_id text, team_id text, revision integer, last_sequence integer);
359CREATE UNIQUE INDEX conversation_task ON conversation_threads(task_id);
360CREATE TABLE conversation_messages (id text PRIMARY KEY, stream_id text, sequence integer, conversation_id text, thread_id text, author_kind text, author_id text, body text, revision integer, created_at datetime, source_refs text);
361CREATE UNIQUE INDEX conversation_sequence ON conversation_messages(stream_id,sequence);
362CREATE TABLE conversation_cards (id text PRIMARY KEY, stream_id text, kind text, resource_id text, sequence integer, revision integer);
363CREATE INDEX conversation_card_stream ON conversation_cards(stream_id);
364CREATE TABLE conversation_requests (principal text, operation text, resource text, request_id text, input_hash text, result text, PRIMARY KEY(principal,operation,resource,request_id));
365CREATE TABLE conversation_routes (source_id text PRIMARY KEY, task_id text, reply_id text, notice_id text);
366CREATE TABLE conversation_outboxes (message_id text PRIMARY KEY, stream_id text, purpose text);
367CREATE TABLE conversation_cursors (id text PRIMARY KEY, principal text, stream_id text, after integer, through integer, revision integer, expires_at datetime);
368
369ALTER TABLE tasks ADD COLUMN kind text NOT NULL DEFAULT 'bug';
370ALTER TABLE tasks ADD COLUMN plan_revision integer NOT NULL DEFAULT 0;
371ALTER TABLE tasks ADD COLUMN approval_revision integer NOT NULL DEFAULT 0;
372ALTER TABLE tasks ADD COLUMN replacement_id text NOT NULL DEFAULT '';
373ALTER TABLE tasks ADD COLUMN replaces_id text NOT NULL DEFAULT '';
374CREATE TABLE plan_revisions (task_id text, revision integer, plan text, actor_kind text, actor text, changed_keys text, created_at datetime, PRIMARY KEY(task_id,revision));
375CREATE TABLE plan_requests (principal text, operation text, resource text, request_id text, input_hash text, result text, PRIMARY KEY(principal,operation,resource,request_id));
376CREATE TABLE plan_approval_settings (project_id integer, person text, mode text, revision integer, PRIMARY KEY(project_id,person));
377CREATE TABLE coordinator_bindings (id text PRIMARY KEY, person text, runner_id text, connection_id text, revision integer, generation integer, team_id text, person_key text, member_revision integer, connection_revision integer);
378CREATE UNIQUE INDEX coordinator_person ON coordinator_bindings(team_id,person_key);
379CREATE TABLE coordinator_turns (id text PRIMARY KEY, message_id text, request_id text, provider_session_id text, context_hash text, generation integer, revision integer, state text, team_id text, person text, binding_id text, conversation_id text, sequence integer, project_id integer, project_revision integer, member_revision integer, connection_revision integer, claim text, selection text, input_hash text, delivery_hash text, session_id text, job_id integer, attempt_id integer, fence integer);
380CREATE TABLE coordinator_questions (id text PRIMARY KEY, binding_id text, turn_id text, person text, request_id text, state text, payload text, generation integer, revision integer);
381CREATE TABLE IF NOT EXISTS coordinator_limits (
382 account TEXT NOT NULL, person TEXT NOT NULL, revision INTEGER NOT NULL,
383 limits TEXT NOT NULL, content_hash TEXT NOT NULL,
384 PRIMARY KEY(account,person)
385);
386UPDATE service SET schema_version=8 WHERE id=1;
387ALTER TABLE audit_events ADD COLUMN delegating_person text;
388CREATE UNIQUE INDEX coordinator_active ON coordinator_turns(team_id,person) WHERE state='running';
389CREATE TABLE personal_preferences (id text PRIMARY KEY, text text, status text, source_message_id text, revision integer, team_id text, person text, source_revision integer, deleted_at datetime);
390CREATE TABLE personal_settings (team_id text, person text, landing text, revision integer, PRIMARY KEY (team_id,person));
391CREATE TABLE person_api_requests (principal text NOT NULL, operation text NOT NULL, resource text NOT NULL, request_id text NOT NULL, input_hash text NOT NULL, result text NOT NULL, created_at datetime NOT NULL, expires_at datetime NOT NULL, PRIMARY KEY (principal,operation,resource,request_id));
392CREATE INDEX person_api_requests_expiry ON person_api_requests(expires_at);
393CREATE TABLE specialist_requests (team_id text, principal text, operation text, resource text, request_id text, input_hash text, result text, PRIMARY KEY (team_id,principal,operation,resource,request_id));
394CREATE TABLE playbooks (id text, team_id text, creator text, name text, kind text, steps text, project_ids text, template_id text, template_version integer, template_base text, revision integer, archived numeric, PRIMARY KEY (id));
395CREATE TABLE playbook_revisions (id text, revision integer, value text, PRIMARY KEY (id,revision));
396CREATE TABLE playbook_defaults (team_id text, project_id integer, kind text, playbook_id text, revision integer, PRIMARY KEY (team_id,project_id,kind));
397CREATE TABLE playbook_snapshots (task_id text, playbook_id text, plan text, PRIMARY KEY (task_id,playbook_id));
398CREATE TABLE playbook_requests (team_id text, principal text, operation text, resource text, request_id text, input_hash text, result text, PRIMARY KEY (team_id,principal,operation,resource,request_id));
399CREATE TABLE playbook_suggestions (id text, playbook_id text, PRIMARY KEY (id));
400
401CREATE TABLE plan_selections (task_id text,step_key text,plan_revision integer,confirmed numeric,selection text,PRIMARY KEY (task_id,step_key));
402CREATE TABLE invitations (
403 id text PRIMARY KEY,
404 address text,
405 role text,
406 state text,
407 inviter text,
408 secret_hash text,
409 revision integer,
410 target_revision integer,
411 inviter_revision integer,
412 created_at datetime,
413 expires_at datetime,
414 accepted_at datetime
415);
416CREATE INDEX invitation_address ON invitations(address);
417CREATE TABLE invitation_requests (
418 principal text,
419 operation text,
420 resource text,
421 request_id text,
422 input_hash text,
423 result text,
424 PRIMARY KEY(principal, operation, resource, request_id)
425);
426CREATE TABLE onboarding_states (
427 person text PRIMARY KEY,
428 revision integer,
429 provider_choice text,
430 runner_id text,
431 account_setup_id text,
432 completed text
433);
434ALTER TABLE runner_enrolments ADD COLUMN created_at datetime;
435ALTER TABLE runner_enrolments ADD COLUMN worker_only numeric;
436CREATE TABLE account_setups (
437 id text PRIMARY KEY,
438 person text,
439 runner_id text,
440 provider text,
441 label text,
442 state text,
443 mode text,
444 connection_id text,
445 revision integer,
446 runner_revision integer,
447 member_revision integer,
448 created_at datetime,
449 expires_at datetime,
450 challenge text
451);
452CREATE INDEX account_setup_person ON account_setups(person);
453
454CREATE TABLE team_links (
455 id text PRIMARY KEY,
456 person text,
457 origin text,
458 name text,
459 last_signed_in_at datetime,
460 revision integer
461);
462CREATE UNIQUE INDEX team_link_person_origin ON team_links(person, origin);
463CREATE TABLE person_devices (
464 id text PRIMARY KEY,
465 request_hash text,
466 input_hash text,
467 public_key text,
468 label text,
469 secret_hash text,
470 code_hash text,
471 challenge text,
472 instance_id text,
473 person text,
474 session_epoch integer,
475 revision integer,
476 created_at datetime,
477 expires_at datetime,
478 approved_at datetime,
479 exchanged_at datetime,
480 revoked_at datetime,
481 last_poll datetime,
482 token_hash text,
483 token_expires_at datetime,
484 nonce_hash text,
485 begin_cipher text,
486 result_cipher text,
487 result_expires_at datetime
488);
489CREATE UNIQUE INDEX person_device_request ON person_devices(request_hash);
490CREATE INDEX person_device_token ON person_devices(token_hash);
491CREATE TABLE person_device_rates (key text PRIMARY KEY, started_at datetime, count integer);
492
493CREATE TABLE project_rules (project_id integer PRIMARY KEY, text text, revision integer);
494ALTER TABLE person_devices ADD COLUMN last_used_at datetime;
495
496CREATE TABLE notification_outbox (sequence integer PRIMARY KEY AUTOINCREMENT, id text NOT NULL, team_id text NOT NULL, recipient text NOT NULL, event text NOT NULL, resource_id text NOT NULL, resource_revision integer NOT NULL, kind text, resource_type text, deep_link text, state text, created_at datetime, acknowledged_at datetime);
497CREATE UNIQUE INDEX notification_id ON notification_outbox(id);
498CREATE UNIQUE INDEX notification_event ON notification_outbox(team_id,recipient,event,resource_id,resource_revision);
499CREATE TABLE notification_subscriptions (id text PRIMARY KEY, team_id text, person text, device_id text, revision integer, ack_sequence integer, active numeric, created_at datetime, expires_at datetime);
500CREATE INDEX notification_device ON notification_subscriptions(device_id);
501CREATE TABLE notification_deliveries (subscription_id text, sequence integer, delivered_at datetime, acknowledged_at datetime, PRIMARY KEY(subscription_id,sequence));
502CREATE TABLE notification_history (team_id text, person text, pruned_through integer, PRIMARY KEY(team_id,person));
503CREATE TRIGGER notification_clarification_insert AFTER INSERT ON coordinator_questions BEGIN
504UPDATE notification_outbox SET state='superseded' WHERE resource_type='clarification' AND resource_id=NEW.id AND state<>'superseded' AND (resource_revision<>NEW.revision OR NEW.state<>'pending');
505INSERT INTO notification_outbox(id,team_id,recipient,event,resource_id,resource_revision,kind,resource_type,deep_link,state,created_at) SELECT lower(hex(randomblob(16))),b.team_id,NEW.person,'question',NEW.id,NEW.revision,'question','clarification','/conversation','unread',strftime('%Y-%m-%d %H:%M:%f','now') FROM coordinator_bindings b WHERE b.id=NEW.binding_id AND NEW.state='pending' AND EXISTS(SELECT 1 FROM members m WHERE m.address=NEW.person AND m.active=1) ON CONFLICT(team_id,recipient,event,resource_id,resource_revision) DO NOTHING;
506END;
507CREATE TRIGGER notification_question_insert AFTER INSERT ON questions BEGIN
508UPDATE notification_outbox SET state='superseded' WHERE resource_type='question' AND resource_id=NEW.id AND state<>'superseded' AND (resource_revision<>NEW.revision OR NEW.state<>'pending');
509INSERT INTO notification_outbox(id,team_id,recipient,event,resource_id,resource_revision,kind,resource_type,deep_link,state,created_at) SELECT lower(hex(randomblob(16))),t.team_id,t.requester,'question',NEW.id,NEW.revision,'question','question','/tasks/'||t.id||'/questions/'||NEW.id,'unread',strftime('%Y-%m-%d %H:%M:%f','now') FROM tasks t WHERE t.id=NEW.task_id AND NEW.state='pending' AND EXISTS(SELECT 1 FROM members m WHERE m.address=t.requester AND m.active=1) ON CONFLICT(team_id,recipient,event,resource_id,resource_revision) DO NOTHING;
510END;
511CREATE TRIGGER notification_task_insert AFTER INSERT ON tasks BEGIN
512UPDATE notification_outbox SET state='superseded' WHERE resource_type='task' AND resource_id=NEW.id AND state<>'superseded' AND (resource_revision<>NEW.revision OR NEW.state IN ('cancelled','cancel_requested','merged','failed') OR (event='task_ready.plan' AND NOT (NEW.approval_revision<>NEW.plan_revision AND NEW.state NOT IN ('cancelled','cancel_requested','merged','failed','succeeded') AND (NEW.wait_code='plan.awaiting_approval' OR (NEW.state='proposed' AND EXISTS(SELECT 1 FROM plan_revisions p WHERE p.task_id=NEW.id AND p.revision=NEW.plan_revision AND p.actor_kind='coordinator') AND COALESCE(NULLIF((SELECT mode FROM plan_approval_settings WHERE project_id=NEW.project_id AND person=NEW.requester),''),(SELECT mode FROM plan_approval_settings WHERE project_id=NEW.project_id AND person=''),'immediate')='required')))));
513INSERT INTO notification_outbox(id,team_id,recipient,event,resource_id,resource_revision,kind,resource_type,deep_link,state,created_at) SELECT lower(hex(randomblob(16))),NEW.team_id,NEW.requester,'task_ready.plan',NEW.id,NEW.revision,'task_ready','task','/tasks/'||NEW.id,'unread',strftime('%Y-%m-%d %H:%M:%f','now') WHERE NEW.approval_revision<>NEW.plan_revision AND NEW.state NOT IN ('cancelled','cancel_requested','merged','failed','succeeded') AND (NEW.wait_code='plan.awaiting_approval' OR (NEW.state='proposed' AND EXISTS(SELECT 1 FROM plan_revisions p WHERE p.task_id=NEW.id AND p.revision=NEW.plan_revision AND p.actor_kind='coordinator') AND COALESCE(NULLIF((SELECT mode FROM plan_approval_settings WHERE project_id=NEW.project_id AND person=NEW.requester),''),(SELECT mode FROM plan_approval_settings WHERE project_id=NEW.project_id AND person=''),'immediate')='required')) AND EXISTS(SELECT 1 FROM members m WHERE m.address=NEW.requester AND m.active=1) ON CONFLICT(team_id,recipient,event,resource_id,resource_revision) DO NOTHING;
514END;
515CREATE TRIGGER notification_card_insert AFTER INSERT ON conversation_cards BEGIN
516UPDATE notification_outbox SET state='superseded' WHERE resource_type='card' AND resource_id=NEW.id AND state<>'superseded' AND resource_revision<>NEW.revision;
517INSERT INTO notification_outbox(id,team_id,recipient,event,resource_id,resource_revision,kind,resource_type,deep_link,state,created_at) SELECT lower(hex(randomblob(16))),c.team_id,c.person,'card',NEW.id,NEW.revision,'card','card','/conversation','unread',strftime('%Y-%m-%d %H:%M:%f','now') FROM conversations c WHERE c.id=NEW.stream_id AND NEW.kind LIKE 'suggest_%' AND EXISTS(SELECT 1 FROM members m WHERE m.address=c.person AND m.active=1) ON CONFLICT(team_id,recipient,event,resource_id,resource_revision) DO NOTHING;
518END;
519CREATE TRIGGER notification_turn_insert AFTER INSERT ON coordinator_turns BEGIN
520UPDATE notification_outbox SET state='superseded' WHERE resource_type='coordinator' AND resource_id=NEW.id AND state<>'superseded' AND (resource_revision<>NEW.revision OR NEW.state NOT IN ('uncertain','fenced','context_limit','context_unavailable'));
521INSERT INTO notification_outbox(id,team_id,recipient,event,resource_id,resource_revision,kind,resource_type,deep_link,state,created_at) SELECT lower(hex(randomblob(16))),NEW.team_id,NEW.person,'interrupted',NEW.id,NEW.revision,'interrupted','coordinator','/conversation','unread',strftime('%Y-%m-%d %H:%M:%f','now') WHERE NEW.state IN ('uncertain','fenced','context_limit','context_unavailable') AND EXISTS(SELECT 1 FROM members m WHERE m.address=NEW.person AND m.active=1) ON CONFLICT(team_id,recipient,event,resource_id,resource_revision) DO NOTHING;
522END;
523CREATE TRIGGER notification_clarification_update AFTER UPDATE ON coordinator_questions BEGIN
524UPDATE notification_outbox SET state='superseded' WHERE resource_type='clarification' AND resource_id=NEW.id AND state<>'superseded' AND (resource_revision<>NEW.revision OR NEW.state<>'pending');
525INSERT INTO notification_outbox(id,team_id,recipient,event,resource_id,resource_revision,kind,resource_type,deep_link,state,created_at) SELECT lower(hex(randomblob(16))),b.team_id,NEW.person,'question',NEW.id,NEW.revision,'question','clarification','/conversation','unread',strftime('%Y-%m-%d %H:%M:%f','now') FROM coordinator_bindings b WHERE b.id=NEW.binding_id AND NEW.state='pending' AND EXISTS(SELECT 1 FROM members m WHERE m.address=NEW.person AND m.active=1) ON CONFLICT(team_id,recipient,event,resource_id,resource_revision) DO NOTHING;
526END;
527CREATE TRIGGER notification_question_update AFTER UPDATE ON questions BEGIN
528UPDATE notification_outbox SET state='superseded' WHERE resource_type='question' AND resource_id=NEW.id AND state<>'superseded' AND (resource_revision<>NEW.revision OR NEW.state<>'pending');
529INSERT INTO notification_outbox(id,team_id,recipient,event,resource_id,resource_revision,kind,resource_type,deep_link,state,created_at) SELECT lower(hex(randomblob(16))),t.team_id,t.requester,'question',NEW.id,NEW.revision,'question','question','/tasks/'||t.id||'/questions/'||NEW.id,'unread',strftime('%Y-%m-%d %H:%M:%f','now') FROM tasks t WHERE t.id=NEW.task_id AND NEW.state='pending' AND EXISTS(SELECT 1 FROM members m WHERE m.address=t.requester AND m.active=1) ON CONFLICT(team_id,recipient,event,resource_id,resource_revision) DO NOTHING;
530END;
531CREATE TRIGGER notification_task_update AFTER UPDATE ON tasks BEGIN
532UPDATE notification_outbox SET state='superseded' WHERE resource_type='task' AND resource_id=NEW.id AND state<>'superseded' AND (resource_revision<>NEW.revision OR NEW.state IN ('cancelled','cancel_requested','merged','failed') OR (event='task_ready.plan' AND NOT (NEW.approval_revision<>NEW.plan_revision AND NEW.state NOT IN ('cancelled','cancel_requested','merged','failed','succeeded') AND (NEW.wait_code='plan.awaiting_approval' OR (NEW.state='proposed' AND EXISTS(SELECT 1 FROM plan_revisions p WHERE p.task_id=NEW.id AND p.revision=NEW.plan_revision AND p.actor_kind='coordinator') AND COALESCE(NULLIF((SELECT mode FROM plan_approval_settings WHERE project_id=NEW.project_id AND person=NEW.requester),''),(SELECT mode FROM plan_approval_settings WHERE project_id=NEW.project_id AND person=''),'immediate')='required')))));
533INSERT INTO notification_outbox(id,team_id,recipient,event,resource_id,resource_revision,kind,resource_type,deep_link,state,created_at) SELECT lower(hex(randomblob(16))),NEW.team_id,NEW.requester,'task_ready.plan',NEW.id,NEW.revision,'task_ready','task','/tasks/'||NEW.id,'unread',strftime('%Y-%m-%d %H:%M:%f','now') WHERE NEW.approval_revision<>NEW.plan_revision AND NEW.state NOT IN ('cancelled','cancel_requested','merged','failed','succeeded') AND (NEW.wait_code='plan.awaiting_approval' OR (NEW.state='proposed' AND EXISTS(SELECT 1 FROM plan_revisions p WHERE p.task_id=NEW.id AND p.revision=NEW.plan_revision AND p.actor_kind='coordinator') AND COALESCE(NULLIF((SELECT mode FROM plan_approval_settings WHERE project_id=NEW.project_id AND person=NEW.requester),''),(SELECT mode FROM plan_approval_settings WHERE project_id=NEW.project_id AND person=''),'immediate')='required')) AND EXISTS(SELECT 1 FROM members m WHERE m.address=NEW.requester AND m.active=1) ON CONFLICT(team_id,recipient,event,resource_id,resource_revision) DO NOTHING;
534END;
535CREATE TRIGGER notification_card_update AFTER UPDATE ON conversation_cards BEGIN
536UPDATE notification_outbox SET state='superseded' WHERE resource_type='card' AND resource_id=NEW.id AND state<>'superseded' AND resource_revision<>NEW.revision;
537INSERT INTO notification_outbox(id,team_id,recipient,event,resource_id,resource_revision,kind,resource_type,deep_link,state,created_at) SELECT lower(hex(randomblob(16))),c.team_id,c.person,'card',NEW.id,NEW.revision,'card','card','/conversation','unread',strftime('%Y-%m-%d %H:%M:%f','now') FROM conversations c WHERE c.id=NEW.stream_id AND NEW.kind LIKE 'suggest_%' AND EXISTS(SELECT 1 FROM members m WHERE m.address=c.person AND m.active=1) ON CONFLICT(team_id,recipient,event,resource_id,resource_revision) DO NOTHING;
538END;
539CREATE TRIGGER notification_turn_update AFTER UPDATE ON coordinator_turns BEGIN
540UPDATE notification_outbox SET state='superseded' WHERE resource_type='coordinator' AND resource_id=NEW.id AND state<>'superseded' AND (resource_revision<>NEW.revision OR NEW.state NOT IN ('uncertain','fenced','context_limit','context_unavailable'));
541INSERT INTO notification_outbox(id,team_id,recipient,event,resource_id,resource_revision,kind,resource_type,deep_link,state,created_at) SELECT lower(hex(randomblob(16))),NEW.team_id,NEW.person,'interrupted',NEW.id,NEW.revision,'interrupted','coordinator','/conversation','unread',strftime('%Y-%m-%d %H:%M:%f','now') WHERE NEW.state IN ('uncertain','fenced','context_limit','context_unavailable') AND EXISTS(SELECT 1 FROM members m WHERE m.address=NEW.person AND m.active=1) ON CONFLICT(team_id,recipient,event,resource_id,resource_revision) DO NOTHING;
542END;
543CREATE TRIGGER notification_job_ready AFTER UPDATE ON jobs WHEN NEW.state='succeeded' AND OLD.state IS NOT NEW.state BEGIN
544INSERT INTO notification_outbox(id,team_id,recipient,event,resource_id,resource_revision,kind,resource_type,deep_link,state,created_at) SELECT lower(hex(randomblob(16))),t.team_id,r.person,'task_ready.complete',t.id,t.revision,'task_ready','task','/tasks/'||t.id,'unread',strftime('%Y-%m-%d %H:%M:%f','now') FROM tasks t JOIN (SELECT id AS task_id,requester AS person FROM tasks UNION SELECT t.id,o.address FROM tasks t JOIN decision_owners o ON o.project_id=t.project_id) r ON r.task_id=t.id WHERE t.job_id=NEW.id AND t.team_id=NEW.account AND EXISTS(SELECT 1 FROM members m WHERE m.address=r.person AND m.active=1) ON CONFLICT(team_id,recipient,event,resource_id,resource_revision) DO NOTHING;
545END;
546CREATE TRIGGER notification_job_decision AFTER UPDATE ON jobs WHEN NEW.wait='approval' AND (OLD.wait IS NOT NEW.wait OR OLD.revision IS NOT NEW.revision) BEGIN
547INSERT INTO notification_outbox(id,team_id,recipient,event,resource_id,resource_revision,kind,resource_type,deep_link,state,created_at) SELECT lower(hex(randomblob(16))),t.team_id,r.person,'task_ready.decision.'||NEW.revision,t.id,t.revision,'task_ready','task','/tasks/'||t.id,'unread',strftime('%Y-%m-%d %H:%M:%f','now') FROM tasks t JOIN (SELECT id AS task_id,requester AS person FROM tasks UNION SELECT t.id,o.address FROM tasks t JOIN decision_owners o ON o.project_id=t.project_id) r ON r.task_id=t.id WHERE t.job_id=NEW.id AND t.team_id=NEW.account AND EXISTS(SELECT 1 FROM members m WHERE m.address=r.person AND m.active=1) ON CONFLICT(team_id,recipient,event,resource_id,resource_revision) DO NOTHING;
548END;
549CREATE TRIGGER notification_job_interrupted AFTER UPDATE ON jobs WHEN NEW.wait IN ('uncertain_external_outcome','runner_unavailable','connection_unavailable') AND OLD.wait IS NOT NEW.wait BEGIN
550INSERT INTO notification_outbox(id,team_id,recipient,event,resource_id,resource_revision,kind,resource_type,deep_link,state,created_at) SELECT lower(hex(randomblob(16))),t.team_id,t.requester,'interrupted.job.'||NEW.revision,t.id,t.revision,'interrupted','task','/tasks/'||t.id,'unread',strftime('%Y-%m-%d %H:%M:%f','now') FROM tasks t WHERE t.job_id=NEW.id AND t.team_id=NEW.account AND EXISTS(SELECT 1 FROM members m WHERE m.address=t.requester AND m.active=1) ON CONFLICT(team_id,recipient,event,resource_id,resource_revision) DO NOTHING;
551END;
552CREATE TRIGGER notification_device_revoke AFTER UPDATE ON person_devices WHEN NEW.revoked_at IS NOT NULL AND OLD.revoked_at IS NULL BEGIN
553UPDATE notification_subscriptions SET active=0,revision=revision+1 WHERE device_id=NEW.id AND active=1;
554END;
555CREATE TRIGGER notification_member_revoke AFTER UPDATE ON members WHEN NEW.active=0 OR NEW.session_epoch<>OLD.session_epoch BEGIN
556UPDATE notification_subscriptions SET active=0,revision=revision+1 WHERE person=NEW.address AND active=1;
557END;
558CREATE TRIGGER notification_binding_generation AFTER UPDATE ON coordinator_bindings WHEN NEW.generation<>OLD.generation BEGIN
559UPDATE notification_outbox SET state='superseded' WHERE resource_type IN ('clarification','coordinator') AND resource_id IN (SELECT id FROM coordinator_questions WHERE binding_id=NEW.id UNION SELECT id FROM coordinator_turns WHERE binding_id=NEW.id);
560END;
561
562CREATE INDEX notification_feed ON notification_outbox(team_id,recipient,sequence);
563
564CREATE TABLE runner_repositories (runner_id text, repository text, PRIMARY KEY (runner_id, repository));
565CREATE TABLE project_proposals (id text, conversation_id text, binding_id text, person text, repository text, name text, why text, state text, generation integer, revision integer, project_id integer, PRIMARY KEY (id));
566CREATE INDEX project_proposal_person ON project_proposals(person);
567
568ALTER TABLE coordinator_turns ADD COLUMN partial_text text;
569ALTER TABLE coordinator_turns ADD COLUMN partial_sequence integer;
570ALTER TABLE coordinator_turns ADD COLUMN partial_at integer;
571ALTER TABLE coordinator_turns ADD COLUMN reply_message_id text;
572ALTER TABLE coordinator_turns ADD COLUMN superseded_by text;
573
574CREATE TABLE chat_turns (id text PRIMARY KEY, person text, state text, reason text, attempt integer, dispatched numeric, reply_id text, revision integer, created_at datetime, updated_at datetime, dispatched_at datetime, timing text, kind text, yield numeric, connection text, lane text, note text);
575CREATE INDEX chat_turn_person ON chat_turns(person,state);
576CREATE TABLE chat_messages (seq integer PRIMARY KEY, id text, person text, idempotency_key text, body_hash text, role text, text text, turn_id text, revision integer, created_at datetime, switched text, lane text);
577CREATE UNIQUE INDEX chat_message_id ON chat_messages(id);
578CREATE INDEX chat_message_person ON chat_messages(person);
579CREATE UNIQUE INDEX chat_message_key ON chat_messages(person,lane,idempotency_key);
580CREATE INDEX chat_message_turn ON chat_messages(turn_id);
581CREATE TABLE chat_events (id integer PRIMARY KEY, person text, type text, body text, created_at datetime, lane text);
582CREATE INDEX chat_event_person ON chat_events(person);
583CREATE TABLE runner_commands (seq integer PRIMARY KEY, person text, kind text, body text, created_at datetime, acked_at datetime, runner_id text);
584CREATE INDEX runner_command_person ON runner_commands(person);
585CREATE TABLE runner_inbox (runner_id text, frame_id text, seen_at datetime, PRIMARY KEY (runner_id, frame_id));
586CREATE TABLE runner_sessions (runner_id text PRIMARY KEY, generation integer, connected numeric, process text, revision integer, hello text, seen_at datetime, protocol integer);
587CREATE TABLE chat_copy_attempts (id text PRIMARY KEY, task_id text, step_id text, attempt integer, tokens integer, known numeric);
588
589CREATE TABLE chat_copy_feedback (id text PRIMARY KEY, project_id text, owner text, source_id text, key text, before text, after text, reason text, origin text, learned numeric, created_at datetime);
590
591CREATE TABLE chat_copy_reviews (id text PRIMARY KEY, project_id text, task_id text, step_id text, attempt integer, owner text, delegation integer, candidate text, input text, key text, text text, hash text, flag text, created_at datetime);
592CREATE INDEX idx_copy_reviews_task ON chat_copy_reviews(task_id);
593CREATE INDEX idx_copy_reviews_attempt ON chat_copy_reviews(step_id, attempt);
594
595CREATE TABLE chat_projects (id text PRIMARY KEY, repo text, state text, added_by text, revision integer, created_at datetime, updated_at datetime, title text, site_app text, copy_owner text, copy_revision integer);
596CREATE UNIQUE INDEX chat_project_site_app ON chat_projects(site_app);
597CREATE UNIQUE INDEX chat_project_repo ON chat_projects(repo);
598CREATE TABLE chat_cards (id text PRIMARY KEY, person text, kind text, state text, turn_id text, project_id text, question text, options text, choice text, answer_message text, revision integer, created_at datetime, updated_at datetime, undo text, task_id text, name text, action_id text, visible_at datetime, held numeric, lane text, source_card text, links text, result text, handoff_id text, detail text);
599CREATE INDEX chat_card_person ON chat_cards(person);
600CREATE INDEX chat_card_source ON chat_cards(source_card);
601CREATE INDEX chat_card_project ON chat_cards(project_id);
602CREATE INDEX chat_card_answer ON chat_cards(answer_message);
603CREATE TABLE chat_tool_calls (call_id text PRIMARY KEY, person text, turn_id text, name text, result text, created_at datetime, attempt integer, args_hash text, op text, lane text, state text, operation text, ledger_key text, args text);
604CREATE TABLE chat_settings (key text PRIMARY KEY, value text, revision integer, updated_by text, updated_at datetime, unset numeric);
605CREATE TABLE chat_coordinators (person text PRIMARY KEY, state text, turn_id text, revision integer, moved_in_at datetime, updated_at datetime);
606CREATE TABLE chat_notebooks (person text PRIMARY KEY, entries text, revision integer, updated_at datetime);
607CREATE INDEX chat_card_task ON chat_cards(task_id);
608CREATE INDEX chat_card_handoff ON chat_cards(handoff_id);
609CREATE TABLE chat_project_attachments (project_id text, kind text, ref text, name text, created_at datetime, PRIMARY KEY (project_id, kind, ref));
610CREATE TABLE chat_tasks (id text PRIMARY KEY, project_id text, title text, brief text, stage text, branch text, base_sha text, creator text, turn_id text, cancel_requested numeric, revision integer, created_at datetime, updated_at datetime, watching text, moved_from text, branch_head text, merge_asked text, merged_sha text, merged_into text, merge_strategy text, merged_without_checks numeric, merged_at datetime, ready_sha text, merge_eligible text, done_at datetime, duplicate_of text, folded_into text, folded_stage text, folded_at datetime, engineering_runner text, merge_hold text, merge_verified numeric, revert_of text, revert_sha text, kind text, direction_asked text, built_as text, explored_from text, priority text, due_by datetime, priority_set_by text, priority_revision integer, publish_asked text, repair_round integer, copy_hold numeric, copy_recovery text, lane text);
611CREATE INDEX chat_task_project ON chat_tasks(project_id);
612CREATE INDEX chat_task_lane ON chat_tasks(lane);
613CREATE TABLE chat_steps (id text PRIMARY KEY, task_id text, idx integer, specialist text, person text, state text, reason text, attempt integer, base_sha text, candidate_sha text, pushed numeric, terminated numeric, summary text, log_tail text, started_at datetime, finished_at datetime, revision integer, created_at datetime, updated_at datetime, round integer, family text, account text, verdict text, review_label text, findings text, checks text, gate text, exit_code integer, output text, republish numeric, from_attempt integer, askable numeric, rebase numeric, from_base text, from_candidate text, merge_sha text, merge_into text, merge_strategy text, without_checks numeric, activity text, switched text, headline text, runner_id text, needs text, placement text, waiting_since datetime, refused_by text, withdrawn numeric, termination_kind text, publication text, publication_id text, apple numeric, checks_sandbox text, recheck_by text, change_facts text, decided_by text, merge_source text, merge_parents text, hosted_ci text, sandbox_runner text, unsandboxed_by text, unsandboxed_at datetime, unsandboxed_attempt integer, unsandboxed_runner text, has_preview numeric, preview text, kind text, note text, boundary text, question text, request_turn text, sources_card text, sources_hash text, research_grant text, research_grant_revision integer, hold text, housekeeping_attempt integer, held_at datetime, publish text, model text, copy_owner text, copy_revision integer, copy_result text, failure_signature text, ability_held numeric);
614CREATE INDEX chat_step_task ON chat_steps(task_id);
615CREATE TABLE chat_task_entries (id text PRIMARY KEY, task_id text, idempotency_key text, kind text, author text, text text, repo text, path text, line integer, created_at datetime, headline text, folded_from text);
616CREATE INDEX chat_entry_task ON chat_task_entries(task_id);
617CREATE UNIQUE INDEX chat_entry_key ON chat_task_entries(task_id, idempotency_key);
618CREATE TABLE chat_task_distinct (a text, b text, created_at datetime, PRIMARY KEY (a, b));
619CREATE TABLE chat_questions (id text PRIMARY KEY, task_id text, asker text, idempotency_key text, step_id text, specialist text, chosen text, text text, state text, reason text, attempt integer, dispatched numeric, answer text, timing text, revision integer, created_at datetime, updated_at datetime);
620CREATE INDEX chat_question_task ON chat_questions(task_id);
621CREATE UNIQUE INDEX chat_question_key ON chat_questions(task_id, asker, idempotency_key);
622CREATE TABLE chat_connections (id text PRIMARY KEY, person text, runner_id text, local_id text, provider text, kind text, label text, state text, reason text, plan text, headroom text, prompt text, revision integer, created_at datetime, updated_at datetime, expires_at datetime, expires_estimated numeric, stated_email text, harness text, upstream text, billing text, model text, limit_confirmed_at datetime, payg_off_confirmed_at datetime, budget text, budget_applied integer, spend text, models text, models_revision integer, models_applied integer, models_state text, models_listed text);
623CREATE INDEX chat_connection_person ON chat_connections(person);
624CREATE TABLE chat_usage (id integer PRIMARY KEY, person text, connection text, provider text, model text, role text, task_id text, step_id text, turn_id text, attempt integer, outcome text, complete numeric, input_tokens integer, cached_input_tokens integer, cache_write_tokens integer, output_tokens integer, reasoning_output_tokens integer, recorded_at datetime, round integer, turns integer, overcount numeric, cost_micros integer, currency text, price_version text, cost_reported_micros integer, family text, tier text, tier_version text, model_mismatch numeric);
625CREATE INDEX chat_usage_person ON chat_usage(person, recorded_at);
626CREATE UNIQUE INDEX chat_usage_key ON chat_usage(turn_id, step_id, attempt, connection, model);
627CREATE INDEX chat_tool_call_turn ON chat_tool_calls(turn_id, op);
628CREATE INDEX chat_tool_call_state ON chat_tool_calls(state);
629CREATE TABLE chat_housekeeping (id text PRIMARY KEY, team text, person text, detector text, subject_kind text, subject_id text, subject_revision integer, finding_key text, class text, state text, reason text, claimed_at datetime, attempt text, reserved_turns integer, reserved_tokens integer, reserved_retries integer, charged_turns integer, charged_tokens integer, charged_retries integer, charged_complete numeric, releasing numeric, evidence text, result text, visible_at datetime, undo_until datetime, recurrences integer, at datetime, undone_at datetime, revision integer, reserved_rounds integer, charged_rounds integer);
630CREATE UNIQUE INDEX chat_housekeeping_key ON chat_housekeeping(team, person, detector, finding_key);
631CREATE INDEX chat_housekeeping_person ON chat_housekeeping(person, at);
632CREATE INDEX chat_housekeeping_subject ON chat_housekeeping(subject_id);
633CREATE TABLE chat_housekeeping_failures (id integer PRIMARY KEY, person text, detector text, kind text, action_id text, at datetime);
634CREATE INDEX chat_housekeeping_failure_person ON chat_housekeeping_failures(person, detector, at);
635CREATE TABLE chat_housekeeping_settings (person text PRIMARY KEY, paused numeric, disabled text, last_digest_at datetime, last_sweep_at datetime, revision integer, quiet_from integer, quiet_until integer);
636CREATE TABLE chat_attachments (id text PRIMARY KEY, person text, message_id text, position integer, kind text, name text, media_type text, size integer, sha256 text, width integer, height integer, has_preview numeric, revision integer, created_at datetime);
637CREATE INDEX chat_attachment_message ON chat_attachments(message_id);
638CREATE INDEX chat_attachment_person ON chat_attachments(person);
639CREATE TABLE chat_attachment_data (id text PRIMARY KEY, data blob, preview blob);
640CREATE INDEX runner_command_runner ON runner_commands(runner_id);
641CREATE INDEX chat_step_runner ON chat_steps(runner_id);
642CREATE TABLE runner_transfers (id text PRIMARY KEY, person text, from_runner text, to_runner text, repo text, task_id text, step_id text, attempt integer, base_sha text, candidate_sha text, direction text, state text, sha256 text, total integer, received integer, bytes integer, expires_at datetime, created_at datetime);
643CREATE INDEX runner_transfer_step ON runner_transfers(step_id);
644CREATE TABLE chat_merge_policies (project_id text PRIMARY KEY, mode text, mode_reason text, max_lines integer, max_files integer, main_ships text, ships_answered_by text, ships_asked numeric, extra_sensitive text, words text, revision integer, updated_by text, updated_at datetime);
645CREATE TABLE chat_merge_audit (id text PRIMARY KEY, project_id text, task_id text, kind text, at text, candidate_sha text, merge_sha text, class text, stance text, decided_by text, reasons text, inputs text, created_at datetime);
646CREATE INDEX chat_merge_audit_project ON chat_merge_audit(project_id);
647CREATE INDEX chat_merge_audit_task ON chat_merge_audit(task_id);
648CREATE TABLE chat_project_stars (person text, project_id text, starred numeric, set_by text, reason text, n integer, signal_at datetime, told_at datetime, created_at datetime, updated_at datetime, PRIMARY KEY (person, project_id));
649CREATE TABLE chat_specialists (id text PRIMARY KEY, profile text, name text, brief text, model_preference text, state text, revision integer, proposed_by text, proposed_turn text, card_id text, approver text, approved_at datetime, decided_by text, decided_at datetime, revoked_by text, revoked_at datetime, created_at datetime, updated_at datetime);
650CREATE INDEX chat_specialist_profile ON chat_specialists(profile);
651CREATE INDEX chat_specialist_card ON chat_specialists(card_id);
652CREATE TABLE chat_capability_grants (id text PRIMARY KEY, specialist_id text, capability text, revision integer, granted_by text, granted_at datetime, revoked_by text, revoked_at datetime);
653CREATE INDEX chat_capability_grant_specialist ON chat_capability_grants(specialist_id);
654CREATE TABLE chat_specialist_audit (id text PRIMARY KEY, specialist_id text, action text, actor text, revision integer, detail text, at datetime);
655CREATE INDEX chat_specialist_audit_specialist ON chat_specialist_audit(specialist_id);
656CREATE INDEX chat_step_sources_card ON chat_steps(sources_card);
657CREATE TABLE chat_research_sources (step_id text, idx integer, source_id text, url text, origin text, approved numeric, created_at datetime, PRIMARY KEY (step_id, idx));
658CREATE TABLE chat_research_addresses (runner_id text, source text, address text, seen_at datetime, PRIMARY KEY (runner_id, source, address));
659CREATE TABLE chat_research_prefixes (runner_id text, prefix text, confirmed_by text, confirmed_at datetime, card_id text, PRIMARY KEY (runner_id, prefix));
660CREATE TABLE chat_research_inventory (card_id text PRIMARY KEY, runner_id text, addresses text, created_at datetime, updated_at datetime);
661CREATE INDEX chat_research_inventory_runner ON chat_research_inventory(runner_id);
662CREATE TABLE instance_prefixes (prefix text PRIMARY KEY, confirmed_by text, confirmed_at datetime, card_id text);
663CREATE TABLE instance_addresses (address text PRIMARY KEY, seen_at datetime);
664CREATE TABLE chat_instance_inventory (card_id text PRIMARY KEY, prefixes text, addresses text, created_at datetime);
665CREATE TABLE chat_web_search_usage (backend text, month text, used integer NOT NULL DEFAULT 0, PRIMARY KEY (backend, month));
666CREATE TABLE chat_lookups (id text PRIMARY KEY, person text NOT NULL, turn_id text NOT NULL, attempt integer NOT NULL, seq integer NOT NULL, call_id text NOT NULL, state text NOT NULL, queries text, reads text, answer text, sources text, code text, created_at datetime NOT NULL);
667CREATE INDEX chat_lookup_turn ON chat_lookups(turn_id, attempt, seq);
668CREATE INDEX chat_lookup_person ON chat_lookups(person, created_at);
669CREATE TABLE chat_research (step_id text, attempt integer, task_id text, revision integer, findings text, created_at datetime, PRIMARY KEY (step_id, attempt));
670CREATE INDEX chat_research_task ON chat_research(task_id);
671CREATE TABLE chat_research_fetches (step_id text, attempt integer, idx integer, task_id text, source_id text, origin text, parent text, url text, hops text, address text, status integer, type text, bytes integer, sha256 text, millis integer, reason text, PRIMARY KEY (step_id, attempt, idx));
672CREATE TABLE chat_task_files (id text PRIMARY KEY, task_id text, step_id text, attempt integer, runner_id text, image_id text, source_id text, role text, description text, media_type text, size integer, sha256 text, total integer, received integer, bytes integer, width integer, height integer, complete numeric, kept numeric, created_at datetime, updated_at datetime);
673CREATE INDEX chat_task_file_task ON chat_task_files(task_id);
674CREATE INDEX chat_task_file_step ON chat_task_files(step_id);
675CREATE TABLE chat_task_file_data (file_id text, idx integer, data blob, PRIMARY KEY (file_id, idx));
676CREATE TABLE chat_releases (id text PRIMARY KEY, task_id text, step_id text, step_revision integer, person text, runner_id text, created_at datetime);
677CREATE INDEX chat_release_task ON chat_releases(task_id);
678CREATE UNIQUE INDEX chat_release_step ON chat_releases(step_id, step_revision);
679CREATE TABLE chat_advice (id text PRIMARY KEY, person text, key text, kind text, state text, subject text, facts text, text text, act text, dismiss text, card_id text, revision integer, created_at datetime, updated_at datetime, visible_at datetime, shown_at datetime, dismissed_at datetime);
680CREATE INDEX chat_advice_person ON chat_advice(person, key);
681CREATE TABLE chat_assistant_hosts (person text PRIMARY KEY, origin text, token text, revision integer, updated_at datetime, capabilities text);
682CREATE TABLE chat_assistant_abilities (person text, origin text, revision integer, abilities text, admin numeric, ask text, source text, fetch_seq integer, confirmed_at datetime, revoked_at datetime, authoritative_seen numeric, PRIMARY KEY (person, origin));
683CREATE TABLE chat_handoffs (id text PRIMARY KEY, person text, assistant_turn text, message_id text, context text, ledger_key text, state text, digest text, created_at datetime, updated_at datetime, lane text, title text, nudges integer NOT NULL DEFAULT 0, ability_held_at datetime);
684CREATE UNIQUE INDEX chat_handoff_key ON chat_handoffs(ledger_key);
685CREATE INDEX chat_handoff_person ON chat_handoffs(person);
686CREATE INDEX chat_handoff_message ON chat_handoffs(message_id);
687CREATE TABLE chat_handoff_turns (handoff_id text, turn_id text PRIMARY KEY);
688CREATE INDEX chat_handoff_turn_handoff ON chat_handoff_turns(handoff_id);
689CREATE TABLE chat_handoff_tasks (handoff_id text, task_id text, created numeric, PRIMARY KEY (handoff_id, task_id));
690CREATE INDEX chat_handoff_task ON chat_handoff_tasks(task_id);
691CREATE TABLE chat_handoff_actions (ledger_key text PRIMARY KEY, handoff_id text NOT NULL, person text NOT NULL, kind text NOT NULL, context text, message_id text, result text, created_at datetime);
692CREATE INDEX chat_handoff_action_handoff ON chat_handoff_actions(handoff_id);
693CREATE INDEX chat_handoff_action_message ON chat_handoff_actions(message_id);
694ALTER TABLE members ADD COLUMN identity_key text NOT NULL DEFAULT "";
695UPDATE members SET identity_key=lower(hex(randomblob(16)));
696CREATE UNIQUE INDEX members_identity_key ON members(identity_key);
697CREATE TRIGGER equipo_member_identity AFTER INSERT ON members WHEN NEW.identity_key='' BEGIN
698 UPDATE members SET identity_key=lower(hex(randomblob(16))) WHERE address=NEW.address;
699END;
700CREATE TABLE equipo_id_accounts (id INTEGER PRIMARY KEY AUTOINCREMENT, binding TEXT NOT NULL UNIQUE, member_key TEXT NOT NULL UNIQUE, linked_at INTEGER NOT NULL DEFAULT 0);
701CREATE TABLE equipo_id_reauth (id_hash TEXT PRIMARY KEY, account_id INTEGER NOT NULL, session_hash TEXT NOT NULL, started INTEGER NOT NULL, expires INTEGER NOT NULL, purpose TEXT NOT NULL, ready INTEGER NOT NULL DEFAULT 0);
702
703CREATE TABLE chat_card_threads (id text PRIMARY KEY, card_id text, person text, message_id text, turn_id text, step_id text, text text, created_at datetime);
704
705CREATE TABLE chat_card_visibility (person text, card_id text, aside numeric, updated_at datetime, PRIMARY KEY (person, card_id));
706
707CREATE INDEX chat_card_thread_card ON chat_card_threads(card_id);
708
709CREATE INDEX chat_card_thread_message ON chat_card_threads(message_id);
710ALTER TABLE chat_cards ADD COLUMN placement text;
711ALTER TABLE chat_tasks ADD COLUMN move_project text;
712ALTER TABLE chat_tasks ADD COLUMN move_by text;
713ALTER TABLE chat_tasks ADD COLUMN move_restart numeric;
714ALTER TABLE chat_tasks ADD COLUMN move_count integer;
715ALTER TABLE chat_steps ADD COLUMN retired numeric;
716ALTER TABLE chat_messages ADD COLUMN origin text;
717ALTER TABLE chat_turns ADD COLUMN create_repo text;
718ALTER TABLE chat_notebooks ADD COLUMN corrections text;
719CREATE INDEX chat_task_move ON chat_tasks(creator, move_project) WHERE move_project IS NOT NULL AND move_project <> '';
720UPDATE chat_notebooks SET entries = (SELECT json_group_array(json(value)) FROM json_each(chat_notebooks.entries) WHERE NOT (coalesce(json_extract(value, '$.source'), '') = 'own' AND substr(json_extract(value, '$.id'), 1, 2) = 'mv')) WHERE entries IS NOT NULL AND entries <> '';
721CREATE TABLE oficina_connections (person text PRIMARY KEY, refresh text, revision integer, created_at datetime, updated_at datetime);
722ALTER TABLE chat_tasks ADD COLUMN move_abandoned numeric;
723ALTER TABLE chat_cards ADD COLUMN access text;
724CREATE TABLE chat_connect_turns (card_id text PRIMARY KEY, turn_id text, person text, asked_turn text, created_at datetime);
725CREATE UNIQUE INDEX chat_connect_turn ON chat_connect_turns(turn_id);
726
727ALTER TABLE chat_projects ADD COLUMN autonomy text;
728ALTER TABLE chat_projects ADD COLUMN autonomy_owner text;
729ALTER TABLE chat_projects ADD COLUMN autonomy_revision integer;
730ALTER TABLE chat_steps ADD COLUMN base_checks_sha text;
731-- Historical notebook entries have no composer reference. Preserve their text
732-- and IDs, but do not certify the old model-written attribution as person words.
733UPDATE chat_notebooks
734SET entries = (
735 SELECT json_group_array(json(CASE
736 WHEN json_extract(value, '$.source') = 'person'
737 THEN json_set(value, '$.source', 'own') ELSE value END))
738 FROM json_each(chat_notebooks.entries)
739), revision = coalesce(revision, 0) + 1
740WHERE CASE WHEN json_valid(entries) THEN json_type(entries) = 'array' ELSE 0 END
741 AND NOT EXISTS (SELECT 1 FROM json_each(chat_notebooks.entries) WHERE type <> 'object')
742 AND EXISTS (SELECT 1 FROM json_each(chat_notebooks.entries) WHERE json_extract(value, '$.source') = 'person');
743
744ALTER TABLE chat_steps ADD COLUMN base_checks text;
745
746CREATE TABLE chat_turn_carried (turn_id text, message_id text, person text, PRIMARY KEY (turn_id, message_id));
747
748CREATE TABLE push_registrations (credential text PRIMARY KEY, person text, token text, environment text, platform text, start_token text, created_at datetime, updated_at datetime, actions_version integer, binding_id text);
749CREATE INDEX push_registration_person ON push_registrations(person);
750CREATE TABLE push_activities (credential text, task_id text, person text, token text, created_at datetime, PRIMARY KEY (credential, task_id));
751CREATE INDEX push_activity_person ON push_activities(person);
752CREATE TABLE push_outbox (id text PRIMARY KEY, person text, credential text, kind text, target text, task_id text, push_type text, priority integer, collapse_id text, dedupe text, payload text, state text, next_at datetime, attempts integer, lease_until datetime, status integer, reason text, apns_id text, sent_at datetime, created_at datetime, updated_at datetime);
753CREATE INDEX push_outbox_due ON push_outbox(state, next_at);
754CREATE INDEX push_outbox_dedupe ON push_outbox(dedupe);
755CREATE INDEX push_outbox_credential ON push_outbox(credential);
756CREATE INDEX push_outbox_person ON push_outbox(person);
757CREATE TABLE push_tasks (person text, task_id text, title text, tone text, stage text, needs_you text, specialist text, step_id text, activity text, started_at datetime, ended numeric, line_at datetime, updated_at datetime, PRIMARY KEY (person, task_id));
758CREATE TABLE push_once (person text, key text, created_at datetime, PRIMARY KEY (person, key));
759-- Keep CARLOS retry deadlines across drains, newly queued pushes and restarts.
760CREATE TABLE push_holds (id text PRIMARY KEY, until datetime);
761
762ALTER TABLE person_devices ADD COLUMN native_session_hash text;
763CREATE INDEX person_device_native_session ON person_devices(native_session_hash);
764
765ALTER TABLE chat_turns ADD COLUMN retry_of text;
766
767-- Owner metadata is distinct from repository-derived display text.
768ALTER TABLE chat_projects ADD COLUMN metadata_set numeric;
769ALTER TABLE chat_projects ADD COLUMN description text;
770ALTER TABLE chat_messages ADD COLUMN project_id text;
771CREATE TABLE chat_project_names (
772 project_id text,
773 person text,
774 name text,
775 created_at datetime,
776 PRIMARY KEY (project_id, person, name)
777);
778
779-- Preserve existing owner provenance, then track each field independently.
780ALTER TABLE chat_projects ADD COLUMN title_set numeric;
781ALTER TABLE chat_projects ADD COLUMN description_set numeric;
782UPDATE chat_projects SET title_set = metadata_set, description_set = metadata_set;
783
784-- Forge authority belongs to the team; pending setup is a single team slot.
785CREATE TABLE forge_connections (
786 id text PRIMARY KEY, generation integer, state text, login text,
787 account_type text, account_id integer, app_id integer, slug text, app_name text,
788 installation_id integer, selection text, confirmed numeric, active_account integer,
789 sealed_key text, owner text, session text, origin text, manifest_hash text,
790 installation_hash text, started_at datetime, redirect_until datetime,
791 pending_until datetime, uninstalled_at datetime, count integer, count_known numeric,
792 claim text, claim_until datetime, updated_at datetime
793);
794CREATE UNIQUE INDEX forge_active_account ON forge_connections(active_account);
795CREATE TABLE forge_pending (id integer PRIMARY KEY, connection_id text);
796CREATE TABLE chat_person_zones (person text PRIMARY KEY, zone text NOT NULL, source text, updated_at datetime);
797ALTER TABLE chat_cards ADD COLUMN carry_on numeric;
798ALTER TABLE chat_cards ADD COLUMN carry_on_connection text;
799ALTER TABLE chat_releases ADD COLUMN connection text;
800ALTER TABLE chat_steps ADD COLUMN coordinator_attempt integer;
801
802-- Bounded Engineering file-list facts, never merge authority.
803ALTER TABLE chat_steps ADD COLUMN change_files text;
804
805-- Device passes and wrapper-only grants never create a general sign-in session.
806CREATE TABLE preview_passes (
807 hash text PRIMARY KEY, id text, instance text, person text, credential text,
808 task_id text, candidate text, step_id text, fingerprint text,
809 epoch integer, attempt integer, expires_at datetime, grant_expires_at datetime,
810 consumed_at datetime
811);
812CREATE INDEX preview_pass_expiry ON preview_passes(expires_at);
813CREATE TABLE preview_grants (
814 hash text PRIMARY KEY, id text, instance text, person text, credential text,
815 task_id text, candidate text, step_id text, fingerprint text,
816 epoch integer, attempt integer, expires_at datetime
817);
818CREATE INDEX preview_grant_expiry ON preview_grants(expires_at);
819
820-- Replace pending passes and active grants by indexed device/task identity.
821CREATE INDEX idx_preview_passes_device_task ON preview_passes(credential, task_id);
822CREATE INDEX idx_preview_grants_device_task ON preview_grants(credential, task_id);
823
824CREATE TABLE chat_notification_receipts (
825 person text, credential text, operation text, target text, key text,
826 digest text, card_id text, message_id text, turn_id text, attempt integer,
827 expires_at datetime,
828 PRIMARY KEY (person, credential, operation, target, key)
829);
830CREATE INDEX notification_receipt_expiry ON chat_notification_receipts(expires_at);
831CREATE TABLE chat_places (id text PRIMARY KEY, kind text, adapter text, console text, account_sqid text, account_name text, state text, revision integer, proposed_by text, proposed_at datetime, confirmed_by text, confirmed_at datetime, created_at datetime, updated_at datetime);
832CREATE UNIQUE INDEX chat_place_destination ON chat_places(kind, adapter, console, account_sqid);
833CREATE TABLE chat_project_places (id text PRIMARY KEY, project_id text, kind text, place_id text, app text, revision integer, app_created_at datetime, app_created_step text, deploy_name text, deploy_runner text, deploy_minted_by text, deploy_minted_at datetime, deploy_step text, created_at datetime, updated_at datetime);
834CREATE UNIQUE INDEX chat_project_place_kind ON chat_project_places(project_id, kind);
835ALTER TABLE chat_cards ADD COLUMN place text;
836
837-- Display patches are separate from task views and merge evidence.
838CREATE TABLE chat_change_diffs (
839 step_id text, attempt integer, idx integer, task_id text, runner_id text,
840 base text, candidate text, collection text, total integer, path text,
841 patch text, reason text, truncated numeric, accepted numeric, expires_at datetime,
842 PRIMARY KEY (step_id, attempt, idx)
843);
844CREATE INDEX chat_diff_task ON chat_change_diffs(task_id);
845CREATE INDEX chat_diff_expiry ON chat_change_diffs(expires_at);
846
847ALTER TABLE chat_steps ADD COLUMN change_diff_expires_at datetime;
848ALTER TABLE chat_steps ADD COLUMN change_diff_attempt integer;
849
850-- Mac Engineering (slice F, protocol 37). Additive only: an existing row
851-- reads as before (a checks transfer, no Xcode access, no outcome, no
852-- kept session, no frozen question pin).
853ALTER TABLE runner_transfers ADD COLUMN kind text;
854ALTER TABLE runner_transfers ADD COLUMN old_base_sha text;
855ALTER TABLE chat_steps ADD COLUMN xcode_access text;
856ALTER TABLE chat_steps ADD COLUMN outcome_phase text;
857ALTER TABLE chat_steps ADD COLUMN session_id text;
858ALTER TABLE chat_steps ADD COLUMN publication_runner text;
859ALTER TABLE chat_steps ADD COLUMN on_worker numeric;
860ALTER TABLE chat_questions ADD COLUMN eng_attempt integer;
861ALTER TABLE chat_questions ADD COLUMN eng_account text;
862ALTER TABLE chat_questions ADD COLUMN eng_session text;
863ALTER TABLE chat_questions ADD COLUMN runner_id text;
864ALTER TABLE chat_questions ADD COLUMN base_sha text;
865ALTER TABLE chat_questions ADD COLUMN candidate_sha text;
866ALTER TABLE chat_tasks ADD COLUMN mac_needs text;
867ALTER TABLE runners ADD COLUMN credential_held_at datetime;
868ALTER TABLE chat_usage ADD COLUMN runner_id text;
869-- Dynamic specialists slice 1 (protocol 38): Design as a data specialist.
870-- Team records, the same for every member. Nothing an existing row holds
871-- changes meaning: a specialist from before is the team's (project_id ""),
872-- a task has no maker and no Design runs, a step is bound to no data
873-- specialist, and a task file is a Research one.
874ALTER TABLE chat_specialists ADD COLUMN project_id text NOT NULL DEFAULT "";
875-- One open proposal and one active row per profile and scope (the team,
876-- or one project); declined and revoked rows are history.
877CREATE UNIQUE INDEX chat_specialist_open ON chat_specialists(profile, project_id) WHERE state = 'proposed';
878CREATE UNIQUE INDEX chat_specialist_active ON chat_specialists(profile, project_id) WHERE state = 'active';
879-- The data specialist that makes the task's changes ("" is Engineering),
880-- and the Design attempts since the person last acted on the task.
881ALTER TABLE chat_tasks ADD COLUMN maker_specialist_id text NOT NULL DEFAULT "";
882ALTER TABLE chat_tasks ADD COLUMN design_runs integer NOT NULL DEFAULT 0;
883-- The binding a step was dispatched under: the specialist, its revision,
884-- its scope and its granted capabilities (JSON); "" is none.
885ALTER TABLE chat_steps ADD COLUMN specialist_id text NOT NULL DEFAULT "";
886ALTER TABLE chat_steps ADD COLUMN specialist_revision integer NOT NULL DEFAULT 0;
887ALTER TABLE chat_steps ADD COLUMN specialist_project text NOT NULL DEFAULT "";
888ALTER TABLE chat_steps ADD COLUMN specialist_caps text NOT NULL DEFAULT "";
889CREATE INDEX chat_step_specialist ON chat_steps(specialist_id);
890-- A task file is a Research image or a Design render (of one option, at
891-- one tree digest).
892ALTER TABLE chat_task_files ADD COLUMN source text NOT NULL DEFAULT "research";
893ALTER TABLE chat_task_files ADD COLUMN option text NOT NULL DEFAULT "";
894ALTER TABLE chat_task_files ADD COLUMN tree_digest text NOT NULL DEFAULT "";
895
896-- Dynamic specialists slice 1: the coordinator's continuation after an
897-- owner's Add on a specialist card for one project. One turn per card
898-- (the card is the key), bound to that card's specialist and project, the
899-- proposing turn's messages it carries (words, JSON) and the one task it
900-- records (task_id, "" until then). A team record; no existing row
901-- changes.
902CREATE TABLE chat_specialist_turns (card_id text PRIMARY KEY, turn_id text, person text, specialist_id text, project_id text, asked_turn text, words text NOT NULL DEFAULT "", task_id text NOT NULL DEFAULT "", created_at datetime);
903CREATE UNIQUE INDEX chat_specialist_turn ON chat_specialist_turns(turn_id);
904
905-- Dynamic specialists slice 1 (protocol 38): the options a done Design
906-- attempt's final report named, kept with its captures once the report
907-- validated them (JSON: the attempt, and each option's name and capture
908-- ids in the report's order); "" is none. A team record, as its step;
909-- no existing row changes.
910ALTER TABLE chat_steps ADD COLUMN design_options text NOT NULL DEFAULT "";
911
912-- Dynamic specialists slice 1 (protocol 38): a Design attempt's render
913-- records (spec section 4, Audit: each render's counts and timing on the
914-- step), as its reports carried them: one row per step attempt, the
915-- records as JSON (wire.RenderAudit), plain data. A team record, as its
916-- step; no existing row changes.
917CREATE TABLE chat_step_renders (step_id text, attempt integer, renders text NOT NULL DEFAULT "", updated_at datetime, PRIMARY KEY (step_id, attempt));
918