@composable-os/cli 0.0.0-stage → 0.1.0-beta.11
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.
- package/LICENSE +109 -0
- package/README.md +24 -2
- package/dist/accounts-UHYLCLEY.js +45 -0
- package/dist/blocks-5IFU25J6.js +233 -0
- package/dist/chunk-2ABSVMGB.js +13 -0
- package/dist/chunk-2IVEVPMY.js +669 -0
- package/dist/chunk-2TWV3SVB.js +349 -0
- package/dist/chunk-2XC5JLBO.js +1931 -0
- package/dist/chunk-324WJXNP.js +320 -0
- package/dist/chunk-5KSXSK7Y.js +47 -0
- package/dist/chunk-6ELZRNUU.js +116 -0
- package/dist/chunk-6UWRT4VM.js +220 -0
- package/dist/chunk-6WGFA2IV.js +643 -0
- package/dist/chunk-6XTU2MTP.js +11278 -0
- package/dist/chunk-7CQGMVDO.js +63 -0
- package/dist/chunk-7D4GKZOX.js +615 -0
- package/dist/chunk-7OGCMQXG.js +284 -0
- package/dist/chunk-DHS2CV2M.js +139 -0
- package/dist/chunk-DU6OIFOU.js +2358 -0
- package/dist/chunk-E4WCYTCT.js +347 -0
- package/dist/chunk-E64SG24J.js +88 -0
- package/dist/chunk-FJIZGS5Q.js +698 -0
- package/dist/chunk-GYTEW66E.js +50 -0
- package/dist/chunk-HDIOVFAZ.js +544 -0
- package/dist/chunk-K34UKWEI.js +298 -0
- package/dist/chunk-KGHA67HG.js +765 -0
- package/dist/chunk-LAAL4YGR.js +365 -0
- package/dist/chunk-LO6WGU5Y.js +26189 -0
- package/dist/chunk-MBIKVRAC.js +1425 -0
- package/dist/chunk-P6UWZ6QQ.js +426 -0
- package/dist/chunk-PDD2ETVF.js +1302 -0
- package/dist/chunk-UB4I2QKR.js +31575 -0
- package/dist/chunk-WHKJGF36.js +2418 -0
- package/dist/chunk-XIDLW3EP.js +15471 -0
- package/dist/chunk-YFTLIEWU.js +504 -0
- package/dist/chunk-YNUZRTPH.js +182 -0
- package/dist/chunk-ZAWES2UD.js +9364 -0
- package/dist/chunk-ZZFWMVJO.js +704 -0
- package/dist/cli-5UNY5G5L.js +136 -0
- package/dist/cli-UYZMVQMR.js +24534 -0
- package/dist/cli.js +25 -0
- package/dist/client-repo-SE4EKG6W.js +55 -0
- package/dist/create.js +25 -0
- package/dist/fields-FTWWMD7N.js +50 -0
- package/dist/grants-LOW6TSWD.js +32 -0
- package/dist/invoke-6KVT6WJI.js +41 -0
- package/dist/moves-E2HKYCTK.js +41 -0
- package/dist/order-U4KZLLSJ.js +19 -0
- package/dist/person-UHLVBVLR.js +67 -0
- package/dist/plan-on-sale-TJPFCNL7.js +26 -0
- package/dist/platform/migrations/0001_init.sql +59 -0
- package/dist/platform/migrations/0002_users_settings.sql +34 -0
- package/dist/platform/migrations/0003_people_organisations.sql +225 -0
- package/dist/platform/migrations/0004_activities_tasks.sql +88 -0
- package/dist/platform/migrations/0005_views_audit.sql +79 -0
- package/dist/platform/migrations/0006_search.sql +223 -0
- package/dist/platform/migrations/0007_crm_views.sql +141 -0
- package/dist/platform/migrations/0008_audit_redaction.sql +116 -0
- package/dist/platform/migrations/0010_approval_queue.sql +90 -0
- package/dist/platform/migrations/0011_connected_apps.sql +36 -0
- package/dist/platform/migrations/0020_extensions.sql +373 -0
- package/dist/platform/migrations/0030_extension_proposals.sql +29 -0
- package/dist/platform/migrations/0050_live_row_indexes.sql +32 -0
- package/dist/platform/migrations/0060_audit_read_counts.sql +31 -0
- package/dist/platform/migrations/0061_audit_retention.sql +95 -0
- package/dist/platform/migrations/0062_run_history_retention.sql +6 -0
- package/dist/platform/migrations/0063_pending_action_compaction.sql +18 -0
- package/dist/platform/migrations/0064_drop_rate_limit.sql +6 -0
- package/dist/platform/migrations/0065_storage_stats.sql +13 -0
- package/dist/platform/migrations/0070_drop_proposals_ext_idx.sql +9 -0
- package/dist/platform/migrations/0080_views_dashboards.sql +46 -0
- package/dist/platform/migrations/0100_stage_history.sql +54 -0
- package/dist/platform/migrations/0110_integrations.sql +103 -0
- package/dist/platform/migrations/0111_email_calendar_sync.sql +137 -0
- package/dist/platform/migrations/0112_sync_item_occurred_at.sql +8 -0
- package/dist/platform/migrations/0130_automations.sql +113 -0
- package/dist/platform/migrations/0131_notifications.sql +29 -0
- package/dist/platform/migrations/0132_automation_runtime.sql +14 -0
- package/dist/platform/migrations/0150_ai_summaries_embeddings.sql +48 -0
- package/dist/platform/migrations/0160_releases.sql +41 -0
- package/dist/platform/migrations/0161_setup_wizard.sql +30 -0
- package/dist/platform/migrations/0170_automation_connections.sql +32 -0
- package/dist/platform/migrations/0171_automation_outbox.sql +23 -0
- package/dist/platform/migrations/0172_notification_delivery.sql +46 -0
- package/dist/platform/migrations/0200_assistant_conversations.sql +25 -0
- package/dist/platform/migrations/0205_policy_adjudicator.sql +61 -0
- package/dist/platform/migrations/0210_daily_digest.sql +33 -0
- package/dist/platform/migrations/0220_entitlements.sql +13 -0
- package/dist/platform/migrations/0221_support_grants.sql +33 -0
- package/dist/platform/migrations/0250_judge.sql +11 -0
- package/dist/platform/migrations/0251_adjudication_judgement.sql +8 -0
- package/dist/platform/migrations/0252_judge_usage.sql +14 -0
- package/dist/platform/migrations/0255_summary_checks.sql +9 -0
- package/dist/platform/migrations/0256_outbound_check.sql +9 -0
- package/dist/platform/migrations/0260_ai_usage.sql +20 -0
- package/dist/platform/migrations/0270_assistant_conversation_refs.sql +29 -0
- package/dist/platform/migrations/0310_assignment_rules.sql +54 -0
- package/dist/platform/migrations/0320_duplicates.sql +41 -0
- package/dist/platform/migrations/0330_erase_completeness.sql +54 -0
- package/dist/platform/migrations/0350_assistant_thread.sql +38 -0
- package/dist/platform/migrations/0351_assistant_model_roles.sql +26 -0
- package/dist/platform/migrations/0352_assistant_memory.sql +74 -0
- package/dist/platform/migrations/0358_ai_cache_observation.sql +24 -0
- package/dist/platform/migrations/0359_ai_compaction_decision.sql +25 -0
- package/dist/platform/migrations/0360_ai_cache_estimate.sql +35 -0
- package/dist/platform/migrations/0361_voice_preferences.sql +27 -0
- package/dist/platform/migrations/0362_voice_usage.sql +17 -0
- package/dist/platform/migrations/0365_routines.sql +38 -0
- package/dist/platform/migrations/0370_approval_execution.sql +20 -0
- package/dist/platform/migrations/0371_agent_jobs.sql +65 -0
- package/dist/platform/migrations/0380_rec_views.sql +94 -0
- package/dist/platform/migrations/0400_customer_audit_actor.sql +142 -0
- package/dist/platform/migrations/0401_customer_accounts.sql +61 -0
- package/dist/platform/migrations/0402_erase_requests.sql +34 -0
- package/dist/platform/migrations/0410_idempotency_keys.sql +45 -0
- package/dist/platform/migrations/0411_device_sessions.sql +33 -0
- package/dist/platform/migrations/0420_transition_history.sql +100 -0
- package/dist/platform/migrations/0421_orders.sql +134 -0
- package/dist/platform/migrations/0422_order_payments.sql +109 -0
- package/dist/platform/migrations/0440_capacity.sql +100 -0
- package/dist/platform/migrations/0441_capacity_views.sql +40 -0
- package/dist/platform/migrations/0450_order_grants.sql +21 -0
- package/dist/platform/migrations/0451_pack_roles.sql +18 -0
- package/dist/platform/migrations/0460_content.sql +59 -0
- package/dist/platform/migrations/0461_media.sql +52 -0
- package/dist/platform/migrations/0470_publish_versions.sql +36 -0
- package/dist/platform/migrations/0471_permission_grants.sql +18 -0
- package/dist/platform/migrations/0490_staff_invites.sql +40 -0
- package/dist/platform/migrations/0491_sign_in_mail_kind.sql +10 -0
- package/dist/platform/migrations/0492_email_confirmation_and_sign_in_confirm.sql +30 -0
- package/dist/platform/migrations/0500_published_media_field.sql +25 -0
- package/dist/platform/migrations/0501_import_keys.sql +23 -0
- package/dist/platform/migrations/0510_video_and_file_media.sql +109 -0
- package/dist/platform/migrations/0516_order_tax.sql +63 -0
- package/dist/platform/migrations/0520_publish_requests.sql +20 -0
- package/dist/platform/migrations/0530_subscriptions.sql +173 -0
- package/dist/platform/migrations/0531_subscription_trials.sql +56 -0
- package/dist/platform/migrations/0532_subscription_offers.sql +80 -0
- package/dist/platform/migrations/0533_allowances.sql +262 -0
- package/dist/platform/migrations/0560_recurring.sql +75 -0
- package/dist/platform/migrations/0580_subscription_grants.sql +21 -0
- package/dist/platform/migrations/0581_once_per_person.sql +34 -0
- package/dist/platform/migrations/0600_tool_actions_ran_at_queue.sql +22 -0
- package/dist/platform/migrations/0610_waitlists.sql +54 -0
- package/dist/platform/migrations/0630_subscription_changes.sql +122 -0
- package/dist/platform/migrations/0650_person_links.sql +90 -0
- package/dist/platform/migrations/0670_unmoved_guard.sql +52 -0
- package/dist/platform/migrations/0690_sellable_refund_due.sql +98 -0
- package/dist/platform/sdk/allowance.ts +522 -0
- package/dist/platform/sdk/automation-check.ts +534 -0
- package/dist/platform/sdk/automation.ts +743 -0
- package/dist/platform/sdk/behaviour.ts +215 -0
- package/dist/platform/sdk/capacity.ts +303 -0
- package/dist/platform/sdk/contract.ts +909 -0
- package/dist/platform/sdk/document.ts +935 -0
- package/dist/platform/sdk/field-types.ts +111 -0
- package/dist/platform/sdk/formula/ast.ts +72 -0
- package/dist/platform/sdk/formula/compile.ts +454 -0
- package/dist/platform/sdk/formula/index.ts +4 -0
- package/dist/platform/sdk/formula/parser.ts +417 -0
- package/dist/platform/sdk/index.ts +36 -0
- package/dist/platform/sdk/manifest.ts +1785 -0
- package/dist/platform/sdk/media.ts +108 -0
- package/dist/platform/sdk/permissions.ts +60 -0
- package/dist/platform/sdk/recurring.ts +321 -0
- package/dist/platform/sdk/renamed.ts +63 -0
- package/dist/platform/sdk/rich-text-fixture.ts +68 -0
- package/dist/platform/sdk/rich-text.ts +221 -0
- package/dist/platform/sdk/runtime.ts +410 -0
- package/dist/platform/sdk/sellable.ts +1138 -0
- package/dist/platform/sdk/slug.ts +25 -0
- package/dist/platform/sdk/states.ts +598 -0
- package/dist/platform/sdk/testing.ts +847 -0
- package/dist/platform/sdk/unique.ts +81 -0
- package/dist/products-2H5DR232.js +11 -0
- package/dist/run-7P4RQALH.js +648 -0
- package/dist/run-PO3W5BFA.js +508 -0
- package/dist/run-ZCGFMEZF.js +309 -0
- package/dist/src-CRO35DYY.js +46 -0
- package/dist/src-I3IJ4NKC.js +354 -0
- package/dist/token-MOJUA2U6.js +70 -0
- package/dist/token-util-TENRN4V7.js +6 -0
- package/dist/visibility-TVXZ67FD.js +41 -0
- package/package.json +33 -4
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
-- Migration 0172: notification delivery (stage 6b, ADR 0029, ADR 0132, ADR 0172).
|
|
2
|
+
--
|
|
3
|
+
-- In-app notifications (core_notifications) are unchanged. People choose, per notification type,
|
|
4
|
+
-- whether it also goes to them by email or Slack DM, and whether they get a daily digest. Admins
|
|
5
|
+
-- choose the org connections email and Slack go out through, the escalation delay for unread
|
|
6
|
+
-- approvals, and channel routes (deal won → #sales). crm-runner's minute cron delivers.
|
|
7
|
+
|
|
8
|
+
-- One row per person who changed a default. `channels`: JSON { "<type>": ["email", "slack"] }.
|
|
9
|
+
CREATE TABLE core_notification_preference (
|
|
10
|
+
user_id TEXT PRIMARY KEY NOT NULL,
|
|
11
|
+
channels TEXT NOT NULL DEFAULT '{}' CHECK (json_valid(channels)),
|
|
12
|
+
digest INTEGER NOT NULL DEFAULT 0 CHECK (digest IN (0, 1)),
|
|
13
|
+
updated_at TEXT NOT NULL
|
|
14
|
+
) WITHOUT ROWID;
|
|
15
|
+
-- The digest job reads the people who asked for it.
|
|
16
|
+
CREATE INDEX core_notification_preference_digest_idx
|
|
17
|
+
ON core_notification_preference (user_id) WHERE digest = 1;
|
|
18
|
+
|
|
19
|
+
-- Every external delivery attempt, keyed so a repeated cron tick or a redelivered event never
|
|
20
|
+
-- sends twice: `n:<notificationId>:<channel>`, `esc:<notificationId>:<channel>`,
|
|
21
|
+
-- `digest:<date>:<userId>`, `route:<eventId>:<routeId>:<recordId>`.
|
|
22
|
+
CREATE TABLE core_notification_delivery (
|
|
23
|
+
key TEXT PRIMARY KEY NOT NULL,
|
|
24
|
+
kind TEXT NOT NULL CHECK (kind IN ('notification', 'escalation', 'digest', 'route')),
|
|
25
|
+
channel TEXT NOT NULL CHECK (channel IN ('email', 'slack')),
|
|
26
|
+
user_id TEXT,
|
|
27
|
+
-- sending: claimed; sent: applied; pending: waiting for approval as an outbound action;
|
|
28
|
+
-- failed / skipped: not delivered (detail says why).
|
|
29
|
+
status TEXT NOT NULL CHECK (status IN ('sending', 'sent', 'pending', 'failed', 'skipped')),
|
|
30
|
+
detail TEXT,
|
|
31
|
+
created_at TEXT NOT NULL
|
|
32
|
+
) WITHOUT ROWID;
|
|
33
|
+
CREATE INDEX core_notification_delivery_created_idx ON core_notification_delivery (created_at);
|
|
34
|
+
|
|
35
|
+
-- Admin settings: where email and Slack go out, escalation and the digest hour.
|
|
36
|
+
INSERT OR IGNORE INTO core_settings (key, value, updated_at)
|
|
37
|
+
VALUES (
|
|
38
|
+
'notification_delivery',
|
|
39
|
+
'{"email":null,"slack":null,"escalationMinutes":30,"escalationChannels":["email"],"digestHour":8}',
|
|
40
|
+
strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
|
|
41
|
+
);
|
|
42
|
+
-- Admin channel routes: [{ id, label, object, event, channel, enabled }].
|
|
43
|
+
INSERT OR IGNORE INTO core_settings (key, value, updated_at)
|
|
44
|
+
VALUES ('notification_routes', '[]', strftime('%Y-%m-%dT%H:%M:%fZ', 'now'));
|
|
45
|
+
|
|
46
|
+
UPDATE core_meta SET value = '172' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
-- Migration 0200: the in-app assistant's conversation index (stage 7b, ADR 0030, ADR 0200).
|
|
2
|
+
--
|
|
3
|
+
-- Each conversation's history, streaming state and turn bookkeeping live in its own Durable
|
|
4
|
+
-- Object (AssistantConversation, one per conversation, SQLite storage). D1 keeps only the list a
|
|
5
|
+
-- person sees on /assistant: one small row per conversation, written when the conversation starts
|
|
6
|
+
-- and once per finished turn (never per token or per tool call). The id (asc_…) is also the
|
|
7
|
+
-- assistant's MCP session: its pending actions group by it and only it sees them simulated.
|
|
8
|
+
CREATE TABLE core_assistant_conversation (
|
|
9
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
10
|
+
user_id TEXT NOT NULL,
|
|
11
|
+
title TEXT NOT NULL,
|
|
12
|
+
-- Where it was started: JSON { path, record?, selection? } of the first turn, for the list.
|
|
13
|
+
context TEXT CHECK (context IS NULL OR json_valid(context)),
|
|
14
|
+
turns INTEGER NOT NULL DEFAULT 0,
|
|
15
|
+
-- The last reply's first line, for the list.
|
|
16
|
+
preview TEXT,
|
|
17
|
+
created_at TEXT NOT NULL,
|
|
18
|
+
updated_at TEXT NOT NULL,
|
|
19
|
+
deleted_at TEXT
|
|
20
|
+
);
|
|
21
|
+
-- /assistant lists a person's conversations, newest first.
|
|
22
|
+
CREATE INDEX core_assistant_conversation_user_idx
|
|
23
|
+
ON core_assistant_conversation (user_id, updated_at DESC) WHERE deleted_at IS NULL;
|
|
24
|
+
|
|
25
|
+
UPDATE core_meta SET value = '200' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
-- Migration 0205: the policy adjudicator (stage 7b, ADR 0011, ADR 0031, ADR 0204).
|
|
2
|
+
--
|
|
3
|
+
-- The adjudicator judges pending actions the gate routed to `review` against the org's written
|
|
4
|
+
-- policy, using the `review` model role. Its settings (mode off / shadow / active, confidence
|
|
5
|
+
-- threshold) are the core_settings key `adjudicator`; missing means off.
|
|
6
|
+
|
|
7
|
+
-- Why the gate routed a pending action to review, so the adjudicator knows what it may approve:
|
|
8
|
+
-- policy: the org's preset said review.
|
|
9
|
+
-- floor: the deploy-time floor (APPROVAL_FLOOR) pinned it to review. Never auto-approved.
|
|
10
|
+
-- always: the operation always waits for a person (extension installs). Never auto-approved.
|
|
11
|
+
-- dependency: the preset said auto, but it refers to a record still pending creation.
|
|
12
|
+
-- Null for actions queued before this migration and for outbound items: never auto-approved.
|
|
13
|
+
ALTER TABLE core_pending_action ADD COLUMN review_source TEXT
|
|
14
|
+
CHECK (review_source IS NULL OR review_source IN ('policy', 'floor', 'always', 'dependency'));
|
|
15
|
+
|
|
16
|
+
-- The written policy: plain text only human admins can edit (adjudicator.setPolicy). Each edit
|
|
17
|
+
-- adds a version; the highest is in force, and every verdict names the version and hash it
|
|
18
|
+
-- judged against.
|
|
19
|
+
CREATE TABLE core_written_policy (
|
|
20
|
+
version INTEGER PRIMARY KEY NOT NULL,
|
|
21
|
+
text TEXT NOT NULL,
|
|
22
|
+
-- SHA-256 of the text, hex.
|
|
23
|
+
hash TEXT NOT NULL,
|
|
24
|
+
created_at TEXT NOT NULL,
|
|
25
|
+
created_by TEXT NOT NULL
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
-- One verdict per pending action. Visible to human approvers only (never to the actor).
|
|
29
|
+
CREATE TABLE core_adjudication (
|
|
30
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
31
|
+
action_id TEXT NOT NULL,
|
|
32
|
+
judged_at TEXT NOT NULL,
|
|
33
|
+
mode TEXT NOT NULL CHECK (mode IN ('shadow', 'active')),
|
|
34
|
+
verdict TEXT NOT NULL CHECK (verdict IN ('approve', 'deny', 'escalate')),
|
|
35
|
+
confidence REAL NOT NULL CHECK (confidence >= 0 AND confidence <= 1),
|
|
36
|
+
-- The reviewer's reason (or why there is no real verdict: an invalid reply, a model error).
|
|
37
|
+
reason TEXT NOT NULL,
|
|
38
|
+
-- recorded: shadow mode, nothing done. approved: applied as the original actor.
|
|
39
|
+
-- apply_failed: approved, but applying failed (the action is marked failed).
|
|
40
|
+
-- escalated: active mode, left for a person (note says why).
|
|
41
|
+
outcome TEXT NOT NULL CHECK (outcome IN ('recorded', 'approved', 'apply_failed', 'escalated')),
|
|
42
|
+
-- 1 when the adjudicator changed the action (approved or apply_failed).
|
|
43
|
+
acted INTEGER NOT NULL DEFAULT 0 CHECK (acted IN (0, 1)),
|
|
44
|
+
-- Why an active-mode verdict was not acted on: deny, escalate, low_confidence, floor, always,
|
|
45
|
+
-- risk, dependency, unknown_source. Also invalid (no valid reply) and error (the model failed).
|
|
46
|
+
note TEXT,
|
|
47
|
+
provider TEXT,
|
|
48
|
+
model TEXT,
|
|
49
|
+
policy_version INTEGER,
|
|
50
|
+
policy_hash TEXT,
|
|
51
|
+
threshold REAL NOT NULL,
|
|
52
|
+
-- JSON { code, message } when the model failed or replied invalidly.
|
|
53
|
+
error TEXT CHECK (error IS NULL OR json_valid(error)),
|
|
54
|
+
audit_id TEXT NOT NULL
|
|
55
|
+
);
|
|
56
|
+
-- One verdict per action (claims it, so the post-commit run and the cron sweep never both act).
|
|
57
|
+
CREATE UNIQUE INDEX core_adjudication_action_idx ON core_adjudication (action_id);
|
|
58
|
+
-- The agreement-rate view reads verdicts by period.
|
|
59
|
+
CREATE INDEX core_adjudication_judged_idx ON core_adjudication (judged_at);
|
|
60
|
+
|
|
61
|
+
UPDATE core_meta SET value = '205' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
-- Migration 0210: the daily digest in the app (stage 7b, ADR 0206, amends ADR 0172).
|
|
2
|
+
--
|
|
3
|
+
-- The digest now also arrives as an in-app notification (type `digest`), on for everyone unless
|
|
4
|
+
-- they turn it off; the email digest keeps its own preference (`digest`, off by default). Its
|
|
5
|
+
-- content reads indexes that already exist: core_audit_at_idx and core_audit_changes_audit_idx
|
|
6
|
+
-- (changes on my records), core_task_assignee_idx (tasks due) and core_notifications_user_idx.
|
|
7
|
+
|
|
8
|
+
-- A person's in-app digest preference. Rows written before this keep the default: on.
|
|
9
|
+
ALTER TABLE core_notification_preference
|
|
10
|
+
ADD COLUMN digest_in_app INTEGER NOT NULL DEFAULT 1 CHECK (digest_in_app IN (0, 1));
|
|
11
|
+
|
|
12
|
+
-- The digest pass walks every person (by primary key, at most 50 a tick), not only those with the
|
|
13
|
+
-- email digest on, so the partial index on `digest = 1` is never read any more.
|
|
14
|
+
DROP INDEX IF EXISTS core_notification_preference_digest_idx;
|
|
15
|
+
|
|
16
|
+
-- The ledger's channel gains `inApp`: a digest that went to the app only is still claimed under
|
|
17
|
+
-- `digest:<date>:<userId>`, so it is written (and its model overview asked for) at most once.
|
|
18
|
+
CREATE TABLE core_notification_delivery_new (
|
|
19
|
+
key TEXT PRIMARY KEY NOT NULL,
|
|
20
|
+
kind TEXT NOT NULL CHECK (kind IN ('notification', 'escalation', 'digest', 'route')),
|
|
21
|
+
channel TEXT NOT NULL CHECK (channel IN ('email', 'slack', 'inApp')),
|
|
22
|
+
user_id TEXT,
|
|
23
|
+
status TEXT NOT NULL CHECK (status IN ('sending', 'sent', 'pending', 'failed', 'skipped')),
|
|
24
|
+
detail TEXT,
|
|
25
|
+
created_at TEXT NOT NULL
|
|
26
|
+
) WITHOUT ROWID;
|
|
27
|
+
INSERT INTO core_notification_delivery_new (key, kind, channel, user_id, status, detail, created_at)
|
|
28
|
+
SELECT key, kind, channel, user_id, status, detail, created_at FROM core_notification_delivery;
|
|
29
|
+
DROP TABLE core_notification_delivery;
|
|
30
|
+
ALTER TABLE core_notification_delivery_new RENAME TO core_notification_delivery;
|
|
31
|
+
CREATE INDEX core_notification_delivery_created_idx ON core_notification_delivery (created_at);
|
|
32
|
+
|
|
33
|
+
UPDATE core_meta SET value = '210' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
-- Stage 10 (SaaS): plan entitlements (ADR 0211).
|
|
2
|
+
--
|
|
3
|
+
-- One row, key 'plan', written only by the hosted control plane through the D1 REST API. Its value
|
|
4
|
+
-- is JSON { plan, maxUsers, maxRecords, platformAi, updatedAt }. No row (a self-hosted install)
|
|
5
|
+
-- means no limits at all. Nothing in the deployment writes this table: no operation, no UI and no
|
|
6
|
+
-- AI path (identity and policy are not AI-configurable).
|
|
7
|
+
CREATE TABLE core_entitlements (
|
|
8
|
+
key TEXT PRIMARY KEY NOT NULL,
|
|
9
|
+
value TEXT NOT NULL,
|
|
10
|
+
updated_at TEXT NOT NULL
|
|
11
|
+
) WITHOUT ROWID;
|
|
12
|
+
|
|
13
|
+
UPDATE core_meta SET value = '220' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
-- Stage 10 (SaaS): customer-approved, time-limited support access without impersonation
|
|
2
|
+
-- (ADR 0212).
|
|
3
|
+
--
|
|
4
|
+
-- The hosted control plane inserts a grant with status 'requested' (and may set 'revoked'),
|
|
5
|
+
-- everything else happens here through support.grant.* operations, so it is in the audit log.
|
|
6
|
+
-- Approving creates a support user (core_user.support_grant_id = the grant): its own identity,
|
|
7
|
+
-- never a customer's account. Support users never count against the plan's user limit and are
|
|
8
|
+
-- not listed in crm_users.
|
|
9
|
+
CREATE TABLE core_support_grants (
|
|
10
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
11
|
+
staff_email TEXT NOT NULL,
|
|
12
|
+
reason TEXT NOT NULL,
|
|
13
|
+
role TEXT NOT NULL CHECK (role IN ('admin', 'member', 'viewer')),
|
|
14
|
+
requested_minutes INTEGER NOT NULL,
|
|
15
|
+
status TEXT NOT NULL CHECK (status IN ('requested', 'approved', 'denied', 'revoked')),
|
|
16
|
+
requested_at TEXT NOT NULL,
|
|
17
|
+
decided_at TEXT,
|
|
18
|
+
decided_by TEXT,
|
|
19
|
+
expires_at TEXT,
|
|
20
|
+
user_id TEXT
|
|
21
|
+
) WITHOUT ROWID;
|
|
22
|
+
CREATE INDEX core_support_grants_status_idx ON core_support_grants (status);
|
|
23
|
+
|
|
24
|
+
ALTER TABLE core_user ADD COLUMN support_grant_id TEXT;
|
|
25
|
+
|
|
26
|
+
-- Support users are not people of the organisation: keep them out of user lists and pickers.
|
|
27
|
+
DROP VIEW crm_users;
|
|
28
|
+
CREATE VIEW crm_users AS
|
|
29
|
+
SELECT u.id, u.name, u.email, u.role, u.image, u.created_at
|
|
30
|
+
FROM core_user u
|
|
31
|
+
WHERE u.kind = 'human' AND u.support_grant_id IS NULL;
|
|
32
|
+
|
|
33
|
+
UPDATE core_meta SET value = '221' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
-- Stage 11 (Jev as the typed judge, ADR 0230): the authoring.intent check of an extension
|
|
2
|
+
-- proposal, stored with the proposal row in the batch that already writes it (no new write per
|
|
3
|
+
-- judge call). JSON: { status, requestSource, request, automations: [{ id, findings, faults }],
|
|
4
|
+
-- model, checkedAt }, or NULL when nothing was checked (no request, no automation changed, or the
|
|
5
|
+
-- judge is off). Labels and probabilities only, never the judge's evidence beyond the request.
|
|
6
|
+
--
|
|
7
|
+
-- The judge's per-placement switches live in core_settings (key judge_settings) and need no
|
|
8
|
+
-- schema change.
|
|
9
|
+
ALTER TABLE core_extension_proposals ADD COLUMN intent_check TEXT;
|
|
10
|
+
|
|
11
|
+
UPDATE core_meta SET value = '250' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
-- Stage 11, placement adjudicator.policy (ADR 0233): the Jev reviewer's raw answer on the verdict
|
|
2
|
+
-- row, written in the batch that already writes the verdict (no new write per judge call).
|
|
3
|
+
-- JSON: { rules, breaks: { probabilities, p, rule }, allowedBy: { probabilities, p, rule },
|
|
4
|
+
-- thresholds, inputTokens } or { unavailable }. Labels and probabilities only, never the
|
|
5
|
+
-- evidence. NULL for a verdict of the LLM reviewer.
|
|
6
|
+
ALTER TABLE core_adjudication ADD COLUMN judgement TEXT;
|
|
7
|
+
|
|
8
|
+
UPDATE core_meta SET value = '251' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
-- Stage 11, Settings → AI's judge spend (ADR 0234): calls and input tokens per day and placement,
|
|
2
|
+
-- counted by a statement added to the batch a placement already writes (the adjudicator's verdict
|
|
3
|
+
-- batch, the extension proposal batch), never by a write of its own per call. Jev charges for
|
|
4
|
+
-- input tokens only, so spend is input_tokens × JEV_PRICE. Counts only: never a request, an
|
|
5
|
+
-- answer or a key.
|
|
6
|
+
CREATE TABLE core_judge_usage (
|
|
7
|
+
day TEXT NOT NULL,
|
|
8
|
+
placement TEXT NOT NULL,
|
|
9
|
+
calls INTEGER NOT NULL DEFAULT 0,
|
|
10
|
+
input_tokens INTEGER NOT NULL DEFAULT 0,
|
|
11
|
+
PRIMARY KEY (day, placement)
|
|
12
|
+
) WITHOUT ROWID;
|
|
13
|
+
|
|
14
|
+
UPDATE core_meta SET value = '252' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- Stage 11, placement summary.statements (ADR 0237): the judge's check of a generated AI summary,
|
|
2
|
+
-- stored with the cached row in the statement that already writes it (no new write per judge
|
|
3
|
+
-- call). JSON: { status: "checked" | "unchecked", statements, removed: [{ index, verdict, fault }],
|
|
4
|
+
-- faults, reason, model, checkedAt }, or NULL when the judge did not run (no key, switched off, or
|
|
5
|
+
-- generated before stage 11). Labels and numbers only: never the removed statements or the facts.
|
|
6
|
+
-- A cached summary is never checked again, and reading one never asks the judge.
|
|
7
|
+
ALTER TABLE core_ai_summary ADD COLUMN checks TEXT;
|
|
8
|
+
|
|
9
|
+
UPDATE core_meta SET value = '255' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- Stage 11, placement outbound.message (ADR 0238): the judge's check of a model-written outbound
|
|
2
|
+
-- message (email, chat post), stored on its pending action in the batch that already inserts it.
|
|
3
|
+
-- JSON: { status: "checked" | "unchecked", turnedToReview, findings: [{ part, fault, label }],
|
|
4
|
+
-- recipients, reason, model, checkedAt }, or NULL when the message was not checked (a person's own
|
|
5
|
+
-- action, notification delivery, no key, or the placement switched off). Labels, numbers and the
|
|
6
|
+
-- part of the message each finding is about; never the facts the message was checked against.
|
|
7
|
+
ALTER TABLE core_pending_action ADD COLUMN outbound_check TEXT;
|
|
8
|
+
|
|
9
|
+
UPDATE core_meta SET value = '256' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
-- Hosted AI (ADR 0213 amendment): model usage counted in the workspace itself.
|
|
2
|
+
--
|
|
3
|
+
-- On a hosted deployment the customer's own keys are called directly at the provider, not through
|
|
4
|
+
-- any gateway we can read, so the deployment counts every model call here: requests and tokens per
|
|
5
|
+
-- day, role and provider, and whether the call was Platform AI (billed to the plan) or the
|
|
6
|
+
-- customer's own key (never billed). Settings → AI shows it. Never a prompt, a reply or a key.
|
|
7
|
+
-- Self-hosted deployments read usage from their own AI Gateway instead (ADR 0152) and leave this
|
|
8
|
+
-- table empty.
|
|
9
|
+
CREATE TABLE core_ai_usage (
|
|
10
|
+
day TEXT NOT NULL,
|
|
11
|
+
role TEXT NOT NULL,
|
|
12
|
+
provider TEXT NOT NULL,
|
|
13
|
+
billed INTEGER NOT NULL,
|
|
14
|
+
requests INTEGER NOT NULL DEFAULT 0,
|
|
15
|
+
tokens_in INTEGER NOT NULL DEFAULT 0,
|
|
16
|
+
tokens_out INTEGER NOT NULL DEFAULT 0,
|
|
17
|
+
PRIMARY KEY (day, role, provider)
|
|
18
|
+
) WITHOUT ROWID;
|
|
19
|
+
|
|
20
|
+
UPDATE core_meta SET value = '260' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
-- Migration 0270: which records each assistant conversation referenced (ADR 0019 and ADR 0200
|
|
2
|
+
-- amendments, 2026-11-05).
|
|
3
|
+
--
|
|
4
|
+
-- A conversation's history lives in its Durable Object, out of reach of a D1 query, so an erase
|
|
5
|
+
-- could not find the conversations that hold a person's details. This index says which ones do:
|
|
6
|
+
-- one row per conversation and referenced person or organisation id (`per_…`, `org_…`), or email
|
|
7
|
+
-- address as `email:<sha256 of the lower-cased address>`. The conversation object sends a turn's
|
|
8
|
+
-- refs with the once-per-turn `assistant.finishTurn` (no extra D1 request, never per token or tool
|
|
9
|
+
-- call). An erase scrubs the conversations listed for the subject and deletes those rows.
|
|
10
|
+
CREATE TABLE core_assistant_conversation_refs (
|
|
11
|
+
conversation_id TEXT NOT NULL REFERENCES core_assistant_conversation (id),
|
|
12
|
+
ref TEXT NOT NULL,
|
|
13
|
+
PRIMARY KEY (conversation_id, ref)
|
|
14
|
+
) WITHOUT ROWID;
|
|
15
|
+
-- An erase looks conversations up by ref.
|
|
16
|
+
CREATE INDEX core_assistant_conversation_refs_ref_idx
|
|
17
|
+
ON core_assistant_conversation_refs (ref);
|
|
18
|
+
|
|
19
|
+
-- Conversations started before this migration: index the record and selection their context
|
|
20
|
+
-- names now. Their messages are indexed by their next turn (the object sends its whole history's
|
|
21
|
+
-- refs once).
|
|
22
|
+
INSERT OR IGNORE INTO core_assistant_conversation_refs (conversation_id, ref)
|
|
23
|
+
SELECT c.id, t.value
|
|
24
|
+
FROM core_assistant_conversation c, json_tree(c.context) t
|
|
25
|
+
WHERE c.context IS NOT NULL
|
|
26
|
+
AND t.type = 'text'
|
|
27
|
+
AND (t.value GLOB 'per_*' OR t.value GLOB 'org_*');
|
|
28
|
+
|
|
29
|
+
UPDATE core_meta SET value = '270' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
-- Migration 0310: assignment rules (stage 15, ADR 0246) and admin-editable select options.
|
|
2
|
+
--
|
|
3
|
+
-- core_assignment_rule: per object (`person`, `organisation`, or an extension object that
|
|
4
|
+
-- declares an owner field), ordered by position; the first enabled rule whose conditions all
|
|
5
|
+
-- hold sets the owner of a record created without one. `conditions` is a JSON array of
|
|
6
|
+
-- { field, op, value, via? } (via: a relation field, to test the related record's field);
|
|
7
|
+
-- `user_ids` a JSON array of user ids: the rotation for round-robin, or the one user.
|
|
8
|
+
CREATE TABLE core_assignment_rule (
|
|
9
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
10
|
+
object_type TEXT NOT NULL,
|
|
11
|
+
name TEXT NOT NULL,
|
|
12
|
+
position INTEGER NOT NULL,
|
|
13
|
+
enabled INTEGER NOT NULL DEFAULT 1 CHECK (enabled IN (0, 1)),
|
|
14
|
+
conditions TEXT NOT NULL DEFAULT '[]',
|
|
15
|
+
method TEXT NOT NULL CHECK (method IN ('roundRobin', 'user')),
|
|
16
|
+
user_ids TEXT NOT NULL DEFAULT '[]',
|
|
17
|
+
created_at TEXT NOT NULL,
|
|
18
|
+
created_by TEXT NOT NULL,
|
|
19
|
+
updated_at TEXT NOT NULL,
|
|
20
|
+
updated_by TEXT NOT NULL
|
|
21
|
+
);
|
|
22
|
+
CREATE INDEX core_assignment_rule_object_idx ON core_assignment_rule (object_type, position);
|
|
23
|
+
|
|
24
|
+
-- Round-robin state: the rotation index of the next record. A create reads it, picks the owner
|
|
25
|
+
-- and advances it in its own batch, guarded by the value it read: a concurrent create makes the
|
|
26
|
+
-- guard write -1, the CHECK fails the batch and the pipeline retries the call (ADR 0246).
|
|
27
|
+
CREATE TABLE core_assignment_state (
|
|
28
|
+
rule_id TEXT PRIMARY KEY NOT NULL,
|
|
29
|
+
next_index INTEGER NOT NULL DEFAULT 0
|
|
30
|
+
CONSTRAINT core_assignment_state_conflict CHECK (next_index >= 0),
|
|
31
|
+
updated_at TEXT
|
|
32
|
+
) WITHOUT ROWID;
|
|
33
|
+
|
|
34
|
+
-- The owner used when no rule matches, per object. A missing row or a null user: no owner.
|
|
35
|
+
CREATE TABLE core_assignment_fallback (
|
|
36
|
+
object_type TEXT PRIMARY KEY NOT NULL,
|
|
37
|
+
user_id TEXT,
|
|
38
|
+
updated_at TEXT NOT NULL,
|
|
39
|
+
updated_by TEXT NOT NULL
|
|
40
|
+
) WITHOUT ROWID;
|
|
41
|
+
|
|
42
|
+
-- Admin-edited options of extension select fields declared with `editableOptions` (ADR 0246
|
|
43
|
+
-- amendment): replaces the declared options in the field registry. `options` is a JSON array of
|
|
44
|
+
-- { value, label, color? }; options the extension marks `fixed` are always kept.
|
|
45
|
+
CREATE TABLE core_field_options (
|
|
46
|
+
object_type TEXT NOT NULL,
|
|
47
|
+
field TEXT NOT NULL,
|
|
48
|
+
options TEXT NOT NULL,
|
|
49
|
+
updated_at TEXT NOT NULL,
|
|
50
|
+
updated_by TEXT NOT NULL,
|
|
51
|
+
PRIMARY KEY (object_type, field)
|
|
52
|
+
) WITHOUT ROWID;
|
|
53
|
+
|
|
54
|
+
UPDATE core_meta SET value = '310' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
-- Migration 0320: duplicates (stage 16, ADR 0247).
|
|
2
|
+
--
|
|
3
|
+
-- name_key: the normalised name (packages/core/src/duplicates/normalise.ts), written by code on
|
|
4
|
+
-- every write that sets a name. Normalisation (legal forms, diacritics, name order) cannot be done
|
|
5
|
+
-- in SQL, so existing rows are filled by a one-off chunked backfill in ros-runner, tracked in
|
|
6
|
+
-- core_settings ('duplicate_scan'); the scan waits for it.
|
|
7
|
+
ALTER TABLE core_person ADD COLUMN name_key TEXT;
|
|
8
|
+
ALTER TABLE core_organisation ADD COLUMN name_key TEXT;
|
|
9
|
+
CREATE INDEX core_person_name_key_idx ON core_person (name_key, id) WHERE deleted_at IS NULL;
|
|
10
|
+
CREATE INDEX core_organisation_name_key_idx ON core_organisation (name_key, id)
|
|
11
|
+
WHERE deleted_at IS NULL;
|
|
12
|
+
|
|
13
|
+
-- The incremental scan reads records changed since its cursor, so its reads follow the number of
|
|
14
|
+
-- changed records, not the table size. The backfill walks rows without a key by id.
|
|
15
|
+
CREATE INDEX core_person_updated_idx ON core_person (updated_at, id);
|
|
16
|
+
CREATE INDEX core_organisation_updated_idx ON core_organisation (updated_at, id);
|
|
17
|
+
CREATE INDEX core_person_no_name_key_idx ON core_person (id) WHERE name_key IS NULL;
|
|
18
|
+
CREATE INDEX core_organisation_no_name_key_idx ON core_organisation (id) WHERE name_key IS NULL;
|
|
19
|
+
|
|
20
|
+
-- Likely duplicates found by the scan, one row per pair (a_id < b_id). rules is a JSON array of
|
|
21
|
+
-- rule ids; details holds what each rule matched (the organisation, the domain, the number), so
|
|
22
|
+
-- the reason sentence can be shown without reading again. A dismissed pair is never suggested
|
|
23
|
+
-- again; a merged one is closed by the merge.
|
|
24
|
+
CREATE TABLE core_duplicate_pair (
|
|
25
|
+
object TEXT NOT NULL CHECK (object IN ('person', 'organisation')),
|
|
26
|
+
a_id TEXT NOT NULL,
|
|
27
|
+
b_id TEXT NOT NULL,
|
|
28
|
+
rules TEXT NOT NULL CHECK (json_valid(rules)),
|
|
29
|
+
details TEXT NOT NULL DEFAULT '{}' CHECK (json_valid(details)),
|
|
30
|
+
status TEXT NOT NULL DEFAULT 'open' CHECK (status IN ('open', 'dismissed', 'merged')),
|
|
31
|
+
created_at TEXT NOT NULL,
|
|
32
|
+
updated_at TEXT NOT NULL,
|
|
33
|
+
decided_at TEXT,
|
|
34
|
+
decided_by TEXT,
|
|
35
|
+
PRIMARY KEY (object, a_id, b_id),
|
|
36
|
+
CHECK (a_id < b_id)
|
|
37
|
+
) WITHOUT ROWID;
|
|
38
|
+
CREATE INDEX core_duplicate_pair_status_idx ON core_duplicate_pair (object, status, a_id, b_id);
|
|
39
|
+
CREATE INDEX core_duplicate_pair_b_idx ON core_duplicate_pair (object, b_id);
|
|
40
|
+
|
|
41
|
+
UPDATE core_meta SET value = '320' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
-- Migration 0330: erase reaches every store (ADR 0019 amendment 2026-11-05, ADR 0320).
|
|
2
|
+
--
|
|
3
|
+
-- core_erased_address: the addresses of erased people, so mail and calendar sync does not collect
|
|
4
|
+
-- them again. Only `sha256:<hex of the lower-cased, trimmed address>` is stored, never the
|
|
5
|
+
-- address. Sync ingest looks a batch's addresses up here (primary key, one query per batch) and
|
|
6
|
+
-- drops matches from payloads, links, suggestions and signatures. An admin can remove an entry
|
|
7
|
+
-- when the person comes back by consent (`erasure.allowAddress`).
|
|
8
|
+
CREATE TABLE core_erased_address (
|
|
9
|
+
hash TEXT PRIMARY KEY NOT NULL CHECK (hash GLOB 'sha256:*'),
|
|
10
|
+
object_type TEXT NOT NULL CHECK (object_type IN ('person', 'organisation')),
|
|
11
|
+
erased_at TEXT NOT NULL,
|
|
12
|
+
erased_by TEXT
|
|
13
|
+
) WITHOUT ROWID;
|
|
14
|
+
|
|
15
|
+
-- core_blob_deletion: R2 objects (synced email bodies) to delete after a commit. A delete in a
|
|
16
|
+
-- D1 batch cannot reach R2, so rows are queued here in the same batch and drained right after
|
|
17
|
+
-- the commit and by the 10-minute cron, with retries (like core_embedding_queue).
|
|
18
|
+
CREATE TABLE core_blob_deletion (
|
|
19
|
+
key TEXT PRIMARY KEY NOT NULL,
|
|
20
|
+
queued_at TEXT NOT NULL,
|
|
21
|
+
attempts INTEGER NOT NULL DEFAULT 0,
|
|
22
|
+
last_error TEXT
|
|
23
|
+
) WITHOUT ROWID;
|
|
24
|
+
CREATE INDEX core_blob_deletion_due_idx ON core_blob_deletion (attempts, queued_at);
|
|
25
|
+
|
|
26
|
+
-- Any activity that loses its body reference queues the body for deletion: a hard delete (erase,
|
|
27
|
+
-- the Trash purge) or an update that clears or changes `body_ref` (an erase dropping a shared
|
|
28
|
+
-- email's body, sync sending a message to Trash).
|
|
29
|
+
CREATE TRIGGER core_activity_body_ad AFTER DELETE ON core_activity
|
|
30
|
+
WHEN OLD.body_ref IS NOT NULL
|
|
31
|
+
BEGIN
|
|
32
|
+
INSERT OR IGNORE INTO core_blob_deletion (key, queued_at)
|
|
33
|
+
VALUES (OLD.body_ref, strftime('%Y-%m-%dT%H:%M:%fZ', 'now'));
|
|
34
|
+
END;
|
|
35
|
+
|
|
36
|
+
CREATE TRIGGER core_activity_body_au AFTER UPDATE OF body_ref ON core_activity
|
|
37
|
+
WHEN OLD.body_ref IS NOT NULL AND (NEW.body_ref IS NULL OR NEW.body_ref <> OLD.body_ref)
|
|
38
|
+
BEGIN
|
|
39
|
+
INSERT OR IGNORE INTO core_blob_deletion (key, queued_at)
|
|
40
|
+
VALUES (OLD.body_ref, strftime('%Y-%m-%dT%H:%M:%fZ', 'now'));
|
|
41
|
+
END;
|
|
42
|
+
|
|
43
|
+
-- Erase lookups by subject, so they are index reads rather than scans.
|
|
44
|
+
CREATE INDEX core_suggested_contact_person_idx ON core_suggested_contact (person_id)
|
|
45
|
+
WHERE person_id IS NOT NULL;
|
|
46
|
+
CREATE INDEX core_automation_runs_record_idx ON core_automation_runs (record_object, record_id)
|
|
47
|
+
WHERE record_id IS NOT NULL;
|
|
48
|
+
-- An erase takes everything merged into the record with it; merges are rare, so these stay small.
|
|
49
|
+
CREATE INDEX core_person_merged_into_idx ON core_person (merged_into_id)
|
|
50
|
+
WHERE merged_into_id IS NOT NULL;
|
|
51
|
+
CREATE INDEX core_organisation_merged_into_idx ON core_organisation (merged_into_id)
|
|
52
|
+
WHERE merged_into_id IS NOT NULL;
|
|
53
|
+
|
|
54
|
+
UPDATE core_meta SET value = '330' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
-- Migration 0350: one assistant thread per user (stage 17 W1, ADR 0340).
|
|
2
|
+
--
|
|
3
|
+
-- Each person's thread (messages, turns, search index, unread state) lives in their own
|
|
4
|
+
-- AssistantAgent Durable Object (`user:<userId>`). D1 keeps one small row per user, written when
|
|
5
|
+
-- the thread is first used and once per finished turn (never per token or tool call), and the
|
|
6
|
+
-- records each thread referenced, so an erase can find the threads to scrub (ADR 0019, ADR 0320).
|
|
7
|
+
-- The id (ath_…) is also the assistant's MCP session: its pending actions group by it.
|
|
8
|
+
CREATE TABLE core_assistant_thread (
|
|
9
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
10
|
+
user_id TEXT NOT NULL UNIQUE,
|
|
11
|
+
turns INTEGER NOT NULL DEFAULT 0,
|
|
12
|
+
-- Replies and deliveries the person has not seen (the badge on the sidebar toggle and nav).
|
|
13
|
+
unread INTEGER NOT NULL DEFAULT 0,
|
|
14
|
+
-- The last reply's first line.
|
|
15
|
+
preview TEXT,
|
|
16
|
+
-- The compaction state (ADR 0341): JSON, written by the thread when it compacts.
|
|
17
|
+
compaction TEXT CHECK (compaction IS NULL OR json_valid(compaction)),
|
|
18
|
+
last_activity_at TEXT,
|
|
19
|
+
created_at TEXT NOT NULL,
|
|
20
|
+
updated_at TEXT NOT NULL
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
-- Which people and organisations (`per_…`, `org_…`) and email addresses (`email:<sha256>`) a
|
|
24
|
+
-- thread referenced. The thread sends a turn's refs with its once-per-turn `thread.finishTurn`.
|
|
25
|
+
CREATE TABLE core_assistant_thread_refs (
|
|
26
|
+
thread_id TEXT NOT NULL REFERENCES core_assistant_thread (id),
|
|
27
|
+
ref TEXT NOT NULL,
|
|
28
|
+
PRIMARY KEY (thread_id, ref)
|
|
29
|
+
) WITHOUT ROWID;
|
|
30
|
+
CREATE INDEX core_assistant_thread_refs_ref_idx ON core_assistant_thread_refs (ref);
|
|
31
|
+
|
|
32
|
+
-- Conversations are gone (ADR 0340): there are no real users yet, so their history is dropped.
|
|
33
|
+
-- Their objects are deleted with the AssistantConversation class (wrangler.jsonc). The two tables
|
|
34
|
+
-- stay, empty, until a later cleanup migration drops them.
|
|
35
|
+
DELETE FROM core_assistant_conversation_refs;
|
|
36
|
+
DELETE FROM core_assistant_conversation;
|
|
37
|
+
|
|
38
|
+
UPDATE core_meta SET value = '350' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
-- Migration 0351: the `assistant` model role becomes `assistant.core` (ADR 0351, stage 17 W10).
|
|
2
|
+
--
|
|
3
|
+
-- The admin layer of the model registry lives in core_settings under `ai_settings` as JSON
|
|
4
|
+
-- `{ "roles": { "<role>": { … } }, "byok": [ … ] }`. Move an admin override of the old
|
|
5
|
+
-- `assistant` role to `assistant.core`; `assistant.subagent` and `dictation.cleanup` follow it at
|
|
6
|
+
-- resolve time when they are not set themselves. When both names are present, the new one wins
|
|
7
|
+
-- and the old one is dropped. The code still reads the old name with a deprecation warning, so a
|
|
8
|
+
-- value written by an older release during a rollout keeps working.
|
|
9
|
+
UPDATE core_settings
|
|
10
|
+
SET value = json_set(
|
|
11
|
+
json_remove(value, '$.roles.assistant'),
|
|
12
|
+
'$.roles."assistant.core"',
|
|
13
|
+
json(json_extract(value, '$.roles.assistant'))
|
|
14
|
+
)
|
|
15
|
+
WHERE key = 'ai_settings'
|
|
16
|
+
AND json_valid(value)
|
|
17
|
+
AND json_type(value, '$.roles.assistant') = 'object'
|
|
18
|
+
AND json_type(value, '$.roles."assistant.core"') IS NULL;
|
|
19
|
+
|
|
20
|
+
UPDATE core_settings
|
|
21
|
+
SET value = json_remove(value, '$.roles.assistant')
|
|
22
|
+
WHERE key = 'ai_settings'
|
|
23
|
+
AND json_valid(value)
|
|
24
|
+
AND json_type(value, '$.roles.assistant') IS NOT NULL;
|
|
25
|
+
|
|
26
|
+
UPDATE core_meta SET value = '351' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
-- Migration 0352: assistant memory (stage 17 W3, ADR 0342).
|
|
2
|
+
--
|
|
3
|
+
-- What each person's assistant remembers, and what the team's assistants share. Lines are saved
|
|
4
|
+
-- inline from the chat (`memory.propose`, checked by the judge's `memory.write` placement), shown
|
|
5
|
+
-- and edited on "What your assistant remembers", and read by the person's thread and by the agents
|
|
6
|
+
-- it starts. Customer facts never go here: they go on the record as a note.
|
|
7
|
+
--
|
|
8
|
+
-- kind:
|
|
9
|
+
-- personal a preference or fact about the person ("I prefer calls before 10")
|
|
10
|
+
-- shortcut what the person means by a phrase ("the pipeline" = my open deals over $5k)
|
|
11
|
+
-- style a line of the writing-style section ("No exclamation marks in emails")
|
|
12
|
+
-- conditional a line that holds only on records matching `condition` ({ object, filter }, the
|
|
13
|
+
-- filter shape views use), included only when the record in context matches
|
|
14
|
+
-- team a line every assistant in the workspace reads (user_id is null)
|
|
15
|
+
--
|
|
16
|
+
-- status:
|
|
17
|
+
-- active read by the assistant
|
|
18
|
+
-- proposed waiting: for the person to confirm a read-back (a conditional line, or any line
|
|
19
|
+
-- while the judge is off), or for a permitted person to approve a team line
|
|
20
|
+
-- paused kept, but not read
|
|
21
|
+
--
|
|
22
|
+
-- `active_since` is when the line last became what the assistant reads (saved, confirmed,
|
|
23
|
+
-- approved, resumed or edited). The thread compares it with its last fold: lines active since then
|
|
24
|
+
-- ride in the context's tail as pending lines until compaction folds them into the memory block,
|
|
25
|
+
-- so the cached prefix stays byte-stable (ADR 0341, ADR 0342).
|
|
26
|
+
CREATE TABLE core_memory (
|
|
27
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
28
|
+
user_id TEXT REFERENCES core_user (id) ON DELETE CASCADE,
|
|
29
|
+
kind TEXT NOT NULL CHECK (kind IN ('personal', 'shortcut', 'style', 'conditional', 'team')),
|
|
30
|
+
text TEXT NOT NULL CHECK (length(text) BETWEEN 1 AND 1000),
|
|
31
|
+
condition TEXT CHECK (condition IS NULL OR json_valid(condition)),
|
|
32
|
+
-- The condition in words, composed by code from the field registry ("Organisations where
|
|
33
|
+
-- People is more than 500"), for the read-back and the memory page.
|
|
34
|
+
condition_label TEXT,
|
|
35
|
+
status TEXT NOT NULL CHECK (status IN ('active', 'proposed', 'paused')),
|
|
36
|
+
-- The person's message the line came from: deleting that message deletes the line.
|
|
37
|
+
source_thread_id TEXT,
|
|
38
|
+
source_message_seq INTEGER,
|
|
39
|
+
-- What checked it before it was saved (JSON: the judge's labels and probabilities, or the
|
|
40
|
+
-- deterministic checks when the judge was off). Never shown as the judge's own words.
|
|
41
|
+
checked TEXT CHECK (checked IS NULL OR json_valid(checked)),
|
|
42
|
+
author_id TEXT REFERENCES core_user (id) ON DELETE SET NULL,
|
|
43
|
+
-- Team lines: every change, oldest first ([{ at, by, action, text }]).
|
|
44
|
+
history TEXT CHECK (history IS NULL OR json_valid(history)),
|
|
45
|
+
active_since TEXT,
|
|
46
|
+
created_at TEXT NOT NULL,
|
|
47
|
+
updated_at TEXT NOT NULL,
|
|
48
|
+
CHECK ((kind = 'team') = (user_id IS NULL)),
|
|
49
|
+
CHECK ((kind = 'conditional') = (condition IS NOT NULL))
|
|
50
|
+
);
|
|
51
|
+
CREATE INDEX core_memory_user_idx ON core_memory (user_id, kind);
|
|
52
|
+
CREATE INDEX core_memory_team_idx ON core_memory (kind, status) WHERE kind = 'team';
|
|
53
|
+
CREATE INDEX core_memory_source_idx ON core_memory (source_thread_id, source_message_seq)
|
|
54
|
+
WHERE source_thread_id IS NOT NULL;
|
|
55
|
+
|
|
56
|
+
-- Which people and organisations (`per_…`, `org_…`) and email addresses (`email:<sha256>`) a
|
|
57
|
+
-- line names, so an erase finds the lines to remove (ADR 0320, ADR 0342).
|
|
58
|
+
CREATE TABLE core_memory_refs (
|
|
59
|
+
memory_id TEXT NOT NULL REFERENCES core_memory (id) ON DELETE CASCADE,
|
|
60
|
+
ref TEXT NOT NULL,
|
|
61
|
+
PRIMARY KEY (memory_id, ref)
|
|
62
|
+
) WITHOUT ROWID;
|
|
63
|
+
CREATE INDEX core_memory_refs_ref_idx ON core_memory_refs (ref);
|
|
64
|
+
|
|
65
|
+
-- Per person: memory on or paused (on by default: no row).
|
|
66
|
+
CREATE TABLE core_memory_settings (
|
|
67
|
+
user_id TEXT PRIMARY KEY NOT NULL REFERENCES core_user (id) ON DELETE CASCADE,
|
|
68
|
+
paused INTEGER NOT NULL DEFAULT 0 CHECK (paused IN (0, 1)),
|
|
69
|
+
updated_at TEXT NOT NULL
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
-- Guarded: this file lands after 0358-0360 on databases that already have them.
|
|
73
|
+
UPDATE core_meta SET value = '352'
|
|
74
|
+
WHERE key = 'schema_version' AND CAST(value AS INTEGER) < 352;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
-- Migration 0358: cache observations for review (stage 17 W2, ADR 0341, spec "Review data").
|
|
2
|
+
--
|
|
3
|
+
-- One row per model response of the assistant's thread (and its compaction calls): the gap since
|
|
4
|
+
-- the previous request on the same thread, whether the cached prefix (system and tools) was
|
|
5
|
+
-- unchanged, and how many prompt tokens the provider reported cached. The cache-lifetime learner
|
|
6
|
+
-- counts them as they arrive; this table keeps them so the maths can be checked and retuned later
|
|
7
|
+
-- (`ai.cacheReport`, `pnpm ai:replay-cache`). Never a prompt, a reply or anyone's words. Kept 180
|
|
8
|
+
-- days (the daily cron purges older rows).
|
|
9
|
+
CREATE TABLE core_ai_cache_observation (
|
|
10
|
+
id INTEGER PRIMARY KEY,
|
|
11
|
+
at TEXT NOT NULL,
|
|
12
|
+
provider TEXT NOT NULL,
|
|
13
|
+
model TEXT NOT NULL,
|
|
14
|
+
role TEXT NOT NULL,
|
|
15
|
+
gap_seconds REAL NOT NULL,
|
|
16
|
+
prefix_unchanged INTEGER NOT NULL,
|
|
17
|
+
cached_tokens INTEGER NOT NULL,
|
|
18
|
+
prompt_tokens INTEGER NOT NULL,
|
|
19
|
+
-- The previous request's prompt tokens: the part this request could find cached.
|
|
20
|
+
prefix_tokens INTEGER
|
|
21
|
+
);
|
|
22
|
+
CREATE INDEX core_ai_cache_observation_at_idx ON core_ai_cache_observation (at);
|
|
23
|
+
|
|
24
|
+
UPDATE core_meta SET value = '358' WHERE key = 'schema_version';
|