@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,141 @@
|
|
|
1
|
+
-- Migration 0007: crm_* read views (ADR 0010, ADR 0015 amendment 2026-11-04).
|
|
2
|
+
--
|
|
3
|
+
-- D1/SQLite has no schemas, so the `crm.*` read surface is a set of views named `crm_<name>`
|
|
4
|
+
-- (`crm.people` is `crm_people`). They are what dashboard SQL, `query.sql` and list operations
|
|
5
|
+
-- read. Rules:
|
|
6
|
+
-- * Live rows only (deleted_at IS NULL).
|
|
7
|
+
-- * Friendly, stable column names; no secrets (crm_users has no auth columns).
|
|
8
|
+
-- * Each view selects from its core table aliased by the object name, so the stage-3 reconciler
|
|
9
|
+
-- can regenerate it with `LEFT JOIN x_<ext>_<object> USING (id)` for extension side tables
|
|
10
|
+
-- without changing core tables.
|
|
11
|
+
-- * Multi-valued fields are JSON arrays (emails, domains, tags).
|
|
12
|
+
|
|
13
|
+
CREATE VIEW crm_users AS
|
|
14
|
+
SELECT u.id, u.name, u.email, u.role, u.image, u.created_at
|
|
15
|
+
FROM core_user u;
|
|
16
|
+
|
|
17
|
+
CREATE VIEW crm_people AS
|
|
18
|
+
SELECT
|
|
19
|
+
person.id,
|
|
20
|
+
person.display_name,
|
|
21
|
+
person.given_name,
|
|
22
|
+
person.family_name,
|
|
23
|
+
(SELECT e.email FROM core_person_emails e
|
|
24
|
+
WHERE e.person_id = person.id AND e.is_primary = 1) AS primary_email,
|
|
25
|
+
(SELECT json_group_array(e.email) FROM
|
|
26
|
+
(SELECT email FROM core_person_emails WHERE person_id = person.id ORDER BY position) e) AS emails,
|
|
27
|
+
(SELECT ph.number FROM core_person_phones ph
|
|
28
|
+
WHERE ph.person_id = person.id AND ph.is_primary = 1) AS primary_phone,
|
|
29
|
+
aff.id AS primary_affiliation_id,
|
|
30
|
+
aff.title AS job_title,
|
|
31
|
+
aff.organisation_id AS organisation_id,
|
|
32
|
+
org.name AS organisation_name,
|
|
33
|
+
person.location,
|
|
34
|
+
person.timezone,
|
|
35
|
+
person.owner_id,
|
|
36
|
+
person.avatar_key,
|
|
37
|
+
(SELECT json_group_array(t.name) FROM
|
|
38
|
+
(SELECT tg.name FROM core_record_tags rt JOIN core_tags tg ON tg.id = rt.tag_id
|
|
39
|
+
WHERE rt.object_type = 'person' AND rt.record_id = person.id ORDER BY tg.name) t) AS tags,
|
|
40
|
+
person.created_at,
|
|
41
|
+
person.updated_at
|
|
42
|
+
FROM core_person person
|
|
43
|
+
LEFT JOIN core_affiliation aff
|
|
44
|
+
ON aff.person_id = person.id AND aff.is_primary = 1 AND aff.deleted_at IS NULL
|
|
45
|
+
LEFT JOIN core_organisation org
|
|
46
|
+
ON org.id = aff.organisation_id AND org.deleted_at IS NULL
|
|
47
|
+
WHERE person.deleted_at IS NULL;
|
|
48
|
+
|
|
49
|
+
CREATE VIEW crm_organisations AS
|
|
50
|
+
SELECT
|
|
51
|
+
organisation.id,
|
|
52
|
+
organisation.name,
|
|
53
|
+
(SELECT d.domain FROM core_organisation_domains d
|
|
54
|
+
WHERE d.organisation_id = organisation.id AND d.is_primary = 1) AS primary_domain,
|
|
55
|
+
(SELECT json_group_array(d.domain) FROM
|
|
56
|
+
(SELECT domain FROM core_organisation_domains WHERE organisation_id = organisation.id
|
|
57
|
+
ORDER BY position) d) AS domains,
|
|
58
|
+
organisation.website,
|
|
59
|
+
organisation.industry,
|
|
60
|
+
organisation.parent_id,
|
|
61
|
+
parent.name AS parent_name,
|
|
62
|
+
organisation.owner_id,
|
|
63
|
+
organisation.avatar_key,
|
|
64
|
+
(SELECT COUNT(*) FROM core_affiliation a JOIN core_person p ON p.id = a.person_id
|
|
65
|
+
WHERE a.organisation_id = organisation.id AND a.is_current = 1
|
|
66
|
+
AND a.deleted_at IS NULL AND p.deleted_at IS NULL) AS current_people_count,
|
|
67
|
+
(SELECT json_group_array(t.name) FROM
|
|
68
|
+
(SELECT tg.name FROM core_record_tags rt JOIN core_tags tg ON tg.id = rt.tag_id
|
|
69
|
+
WHERE rt.object_type = 'organisation' AND rt.record_id = organisation.id
|
|
70
|
+
ORDER BY tg.name) t) AS tags,
|
|
71
|
+
organisation.created_at,
|
|
72
|
+
organisation.updated_at
|
|
73
|
+
FROM core_organisation organisation
|
|
74
|
+
LEFT JOIN core_organisation parent
|
|
75
|
+
ON parent.id = organisation.parent_id AND parent.deleted_at IS NULL
|
|
76
|
+
WHERE organisation.deleted_at IS NULL;
|
|
77
|
+
|
|
78
|
+
CREATE VIEW crm_affiliations AS
|
|
79
|
+
SELECT
|
|
80
|
+
affiliation.id,
|
|
81
|
+
affiliation.person_id,
|
|
82
|
+
affiliation.organisation_id,
|
|
83
|
+
affiliation.title,
|
|
84
|
+
affiliation.role,
|
|
85
|
+
affiliation.started_on,
|
|
86
|
+
affiliation.ended_on,
|
|
87
|
+
affiliation.is_current,
|
|
88
|
+
affiliation.is_primary,
|
|
89
|
+
affiliation.created_at,
|
|
90
|
+
affiliation.updated_at
|
|
91
|
+
FROM core_affiliation affiliation
|
|
92
|
+
JOIN core_person p ON p.id = affiliation.person_id AND p.deleted_at IS NULL
|
|
93
|
+
JOIN core_organisation o ON o.id = affiliation.organisation_id AND o.deleted_at IS NULL
|
|
94
|
+
WHERE affiliation.deleted_at IS NULL;
|
|
95
|
+
|
|
96
|
+
CREATE VIEW crm_activities AS
|
|
97
|
+
SELECT
|
|
98
|
+
activity.id,
|
|
99
|
+
activity.type,
|
|
100
|
+
activity.subject,
|
|
101
|
+
activity.body,
|
|
102
|
+
activity.payload,
|
|
103
|
+
activity.occurred_at,
|
|
104
|
+
activity.author_user_id,
|
|
105
|
+
activity.author_actor,
|
|
106
|
+
activity.created_at,
|
|
107
|
+
activity.updated_at
|
|
108
|
+
FROM core_activity activity
|
|
109
|
+
WHERE activity.deleted_at IS NULL;
|
|
110
|
+
|
|
111
|
+
CREATE VIEW crm_activity_links AS
|
|
112
|
+
SELECT l.activity_id, l.object_type, l.record_id
|
|
113
|
+
FROM core_activity_links l
|
|
114
|
+
JOIN core_activity a ON a.id = l.activity_id AND a.deleted_at IS NULL;
|
|
115
|
+
|
|
116
|
+
CREATE VIEW crm_tasks AS
|
|
117
|
+
SELECT
|
|
118
|
+
task.id,
|
|
119
|
+
task.title,
|
|
120
|
+
task.notes,
|
|
121
|
+
task.due_at,
|
|
122
|
+
task.status,
|
|
123
|
+
task.completed_at,
|
|
124
|
+
task.assignee_id,
|
|
125
|
+
task.created_by,
|
|
126
|
+
task.created_at,
|
|
127
|
+
task.updated_at
|
|
128
|
+
FROM core_task task
|
|
129
|
+
WHERE task.deleted_at IS NULL;
|
|
130
|
+
|
|
131
|
+
CREATE VIEW crm_task_links AS
|
|
132
|
+
SELECT l.task_id, l.object_type, l.record_id
|
|
133
|
+
FROM core_task_links l
|
|
134
|
+
JOIN core_task t ON t.id = l.task_id AND t.deleted_at IS NULL;
|
|
135
|
+
|
|
136
|
+
CREATE VIEW crm_record_tags AS
|
|
137
|
+
SELECT rt.object_type, rt.record_id, tg.id AS tag_id, tg.name AS tag
|
|
138
|
+
FROM core_record_tags rt
|
|
139
|
+
JOIN core_tags tg ON tg.id = rt.tag_id;
|
|
140
|
+
|
|
141
|
+
UPDATE core_meta SET value = '7' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
-- Migration 0008: sanctioned redaction of personal data in the audit log (ADR 0019).
|
|
2
|
+
--
|
|
3
|
+
-- core_audit and core_audit_changes stay append-only: DELETE is always refused, and UPDATE is
|
|
4
|
+
-- refused unless it is exactly the canonical redaction of a row that has a marker in
|
|
5
|
+
-- core_audit_redactions. Markers are themselves append-only and say which erase removed what,
|
|
6
|
+
-- so a redaction can never be silent.
|
|
7
|
+
--
|
|
8
|
+
-- The only way to redact is to insert a marker; the AFTER INSERT triggers below perform the
|
|
9
|
+
-- canonical UPDATE. A direct UPDATE passes the guard only if it writes the same canonical values
|
|
10
|
+
-- to a marked row, so nothing but "[erased]" can ever be written over audit content.
|
|
11
|
+
--
|
|
12
|
+
-- Canonical redaction:
|
|
13
|
+
-- core_audit: input -> "[erased]"; result -> "[erased]" (if not null);
|
|
14
|
+
-- error -> {"code": <kept>, "message": "[erased]"} (if not null).
|
|
15
|
+
-- Who, when, which operation, risk, actor, origin, gate decision and
|
|
16
|
+
-- outcome are kept.
|
|
17
|
+
-- core_audit_changes: diff keeps its field names; every before/after value becomes
|
|
18
|
+
-- "[erased]". Record, action and time are kept.
|
|
19
|
+
|
|
20
|
+
CREATE TABLE core_audit_redactions (
|
|
21
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
22
|
+
-- Exactly one target: an audit row or a field-change row.
|
|
23
|
+
audit_id TEXT REFERENCES core_audit (id),
|
|
24
|
+
change_id INTEGER REFERENCES core_audit_changes (id),
|
|
25
|
+
-- The erased record (ids carry no personal data).
|
|
26
|
+
object_type TEXT NOT NULL,
|
|
27
|
+
record_id TEXT NOT NULL,
|
|
28
|
+
-- The erase operation that caused it, and who ran it.
|
|
29
|
+
operation TEXT NOT NULL,
|
|
30
|
+
user_id TEXT,
|
|
31
|
+
at TEXT NOT NULL,
|
|
32
|
+
CHECK ((audit_id IS NULL) <> (change_id IS NULL))
|
|
33
|
+
);
|
|
34
|
+
CREATE UNIQUE INDEX core_audit_redactions_audit_uq ON core_audit_redactions (audit_id)
|
|
35
|
+
WHERE audit_id IS NOT NULL;
|
|
36
|
+
CREATE UNIQUE INDEX core_audit_redactions_change_uq ON core_audit_redactions (change_id)
|
|
37
|
+
WHERE change_id IS NOT NULL;
|
|
38
|
+
CREATE INDEX core_audit_redactions_record_idx ON core_audit_redactions (object_type, record_id);
|
|
39
|
+
|
|
40
|
+
CREATE TRIGGER core_audit_redactions_no_update BEFORE UPDATE ON core_audit_redactions
|
|
41
|
+
BEGIN
|
|
42
|
+
SELECT RAISE(ABORT, 'core_audit_redactions is append-only');
|
|
43
|
+
END;
|
|
44
|
+
|
|
45
|
+
CREATE TRIGGER core_audit_redactions_no_delete BEFORE DELETE ON core_audit_redactions
|
|
46
|
+
BEGIN
|
|
47
|
+
SELECT RAISE(ABORT, 'core_audit_redactions is append-only');
|
|
48
|
+
END;
|
|
49
|
+
|
|
50
|
+
-- Guards: replace the unconditional UPDATE refusals from migration 0005. DELETE refusals stay.
|
|
51
|
+
|
|
52
|
+
DROP TRIGGER core_audit_no_update;
|
|
53
|
+
CREATE TRIGGER core_audit_no_update BEFORE UPDATE ON core_audit
|
|
54
|
+
WHEN NOT (
|
|
55
|
+
EXISTS (SELECT 1 FROM core_audit_redactions r WHERE r.audit_id = OLD.id)
|
|
56
|
+
AND NEW.id IS OLD.id
|
|
57
|
+
AND NEW.at IS OLD.at
|
|
58
|
+
AND NEW.operation IS OLD.operation
|
|
59
|
+
AND NEW.risk IS OLD.risk
|
|
60
|
+
AND NEW.actor IS OLD.actor
|
|
61
|
+
AND NEW.user_id IS OLD.user_id
|
|
62
|
+
AND NEW.origin IS OLD.origin
|
|
63
|
+
AND NEW.gate_decision IS OLD.gate_decision
|
|
64
|
+
AND NEW.outcome IS OLD.outcome
|
|
65
|
+
AND NEW.input IS '"[erased]"'
|
|
66
|
+
AND NEW.result IS (CASE WHEN OLD.result IS NULL THEN NULL ELSE '"[erased]"' END)
|
|
67
|
+
AND NEW.error IS (CASE WHEN OLD.error IS NULL THEN NULL
|
|
68
|
+
ELSE json_object('code', json_extract(OLD.error, '$.code'), 'message', '[erased]') END)
|
|
69
|
+
)
|
|
70
|
+
BEGIN
|
|
71
|
+
SELECT RAISE(ABORT, 'core_audit is append-only');
|
|
72
|
+
END;
|
|
73
|
+
|
|
74
|
+
DROP TRIGGER core_audit_changes_no_update;
|
|
75
|
+
CREATE TRIGGER core_audit_changes_no_update BEFORE UPDATE ON core_audit_changes
|
|
76
|
+
WHEN NOT (
|
|
77
|
+
EXISTS (SELECT 1 FROM core_audit_redactions r WHERE r.change_id = OLD.id)
|
|
78
|
+
AND NEW.id IS OLD.id
|
|
79
|
+
AND NEW.audit_id IS OLD.audit_id
|
|
80
|
+
AND NEW.object_type IS OLD.object_type
|
|
81
|
+
AND NEW.record_id IS OLD.record_id
|
|
82
|
+
AND NEW.action IS OLD.action
|
|
83
|
+
AND NEW.at IS OLD.at
|
|
84
|
+
AND NEW.diff IS (
|
|
85
|
+
SELECT coalesce(json_group_object(j.key, json_object('before', '[erased]', 'after', '[erased]')), '{}')
|
|
86
|
+
FROM json_each(OLD.diff) j
|
|
87
|
+
)
|
|
88
|
+
)
|
|
89
|
+
BEGIN
|
|
90
|
+
SELECT RAISE(ABORT, 'core_audit_changes is append-only');
|
|
91
|
+
END;
|
|
92
|
+
|
|
93
|
+
-- Inserting a marker applies the canonical redaction to its target.
|
|
94
|
+
|
|
95
|
+
CREATE TRIGGER core_audit_redactions_apply_audit AFTER INSERT ON core_audit_redactions
|
|
96
|
+
WHEN NEW.audit_id IS NOT NULL
|
|
97
|
+
BEGIN
|
|
98
|
+
UPDATE core_audit SET
|
|
99
|
+
input = '"[erased]"',
|
|
100
|
+
result = CASE WHEN result IS NULL THEN NULL ELSE '"[erased]"' END,
|
|
101
|
+
error = CASE WHEN error IS NULL THEN NULL
|
|
102
|
+
ELSE json_object('code', json_extract(error, '$.code'), 'message', '[erased]') END
|
|
103
|
+
WHERE id = NEW.audit_id;
|
|
104
|
+
END;
|
|
105
|
+
|
|
106
|
+
CREATE TRIGGER core_audit_redactions_apply_change AFTER INSERT ON core_audit_redactions
|
|
107
|
+
WHEN NEW.change_id IS NOT NULL
|
|
108
|
+
BEGIN
|
|
109
|
+
UPDATE core_audit_changes SET diff = (
|
|
110
|
+
SELECT coalesce(json_group_object(j.key, json_object('before', '[erased]', 'after', '[erased]')), '{}')
|
|
111
|
+
FROM json_each(core_audit_changes.diff) j
|
|
112
|
+
)
|
|
113
|
+
WHERE id = NEW.change_id;
|
|
114
|
+
END;
|
|
115
|
+
|
|
116
|
+
UPDATE core_meta SET value = '8' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
-- Migration 0010: the approval queue (ADR 0022). A gate `review` outcome records a pending action
|
|
2
|
+
-- instead of failing. Pending actions group into change sets: one open set per MCP session by
|
|
3
|
+
-- default, or an explicit one (changeset.begin / changeset.commit). They expire after a
|
|
4
|
+
-- configurable period (default 7 days). Approval re-runs each action through the pipeline.
|
|
5
|
+
-- (0009 is intentionally unused: migration numbers were reserved per parallel stage.)
|
|
6
|
+
|
|
7
|
+
CREATE TABLE core_change_set (
|
|
8
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
9
|
+
-- Given by changeset.begin; default (per-session) sets have none.
|
|
10
|
+
title TEXT,
|
|
11
|
+
-- The MCP session (connected app id, cap_…) that queued it, or null for other surfaces.
|
|
12
|
+
session_id TEXT,
|
|
13
|
+
client_id TEXT,
|
|
14
|
+
client_name TEXT,
|
|
15
|
+
user_id TEXT NOT NULL,
|
|
16
|
+
actor TEXT NOT NULL CHECK (actor IN ('human', 'assistant', 'mcp', 'automation')),
|
|
17
|
+
origin TEXT NOT NULL CHECK (json_valid(origin)),
|
|
18
|
+
-- 1 when opened with changeset.begin.
|
|
19
|
+
explicit INTEGER NOT NULL DEFAULT 0 CHECK (explicit IN (0, 1)),
|
|
20
|
+
-- open: accepting new actions. committed: closed by changeset.commit, waiting for review.
|
|
21
|
+
-- closed: a human decided on it; new actions go to a fresh set.
|
|
22
|
+
state TEXT NOT NULL DEFAULT 'open' CHECK (state IN ('open', 'committed', 'closed')),
|
|
23
|
+
created_at TEXT NOT NULL,
|
|
24
|
+
updated_at TEXT NOT NULL,
|
|
25
|
+
committed_at TEXT,
|
|
26
|
+
closed_at TEXT
|
|
27
|
+
);
|
|
28
|
+
CREATE INDEX core_change_set_session_idx ON core_change_set (session_id, state, created_at);
|
|
29
|
+
CREATE INDEX core_change_set_state_idx ON core_change_set (state, created_at);
|
|
30
|
+
CREATE INDEX core_change_set_user_idx ON core_change_set (user_id, created_at);
|
|
31
|
+
|
|
32
|
+
-- One queued operation call. `input` is the caller's input as given (re-validated on apply).
|
|
33
|
+
-- ids are ULIDs, so `ORDER BY id` is queue order.
|
|
34
|
+
CREATE TABLE core_pending_action (
|
|
35
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
36
|
+
change_set_id TEXT NOT NULL REFERENCES core_change_set (id),
|
|
37
|
+
operation TEXT NOT NULL,
|
|
38
|
+
risk TEXT NOT NULL
|
|
39
|
+
CHECK (risk IN ('read', 'write', 'bulk-write', 'destructive', 'schema', 'extension', 'outbound')),
|
|
40
|
+
input TEXT NOT NULL CHECK (json_valid(input)),
|
|
41
|
+
reason TEXT NOT NULL,
|
|
42
|
+
actor TEXT NOT NULL CHECK (actor IN ('human', 'assistant', 'mcp', 'automation')),
|
|
43
|
+
user_id TEXT NOT NULL,
|
|
44
|
+
origin TEXT NOT NULL CHECK (json_valid(origin)),
|
|
45
|
+
-- The permissions the caller's token allowed (role ∩ scopes), or null for no restriction.
|
|
46
|
+
granted_permissions TEXT CHECK (granted_permissions IS NULL OR json_valid(granted_permissions)),
|
|
47
|
+
bulk_size INTEGER NOT NULL DEFAULT 1,
|
|
48
|
+
-- JSON `[{ object, id, action, diff }]`: the computed diff preview.
|
|
49
|
+
preview TEXT NOT NULL CHECK (json_valid(preview)),
|
|
50
|
+
-- JSON `{ output, records: [{ object, id, state, record }] }`: what the session's reads see.
|
|
51
|
+
simulated TEXT NOT NULL CHECK (json_valid(simulated)),
|
|
52
|
+
-- JSON `[{ object, id }]`: provisional ids (…_pending_…) this action creates, in order.
|
|
53
|
+
provisional TEXT NOT NULL DEFAULT '[]' CHECK (json_valid(provisional)),
|
|
54
|
+
-- JSON `[actionId]`: earlier pending actions this one needs applied first.
|
|
55
|
+
depends_on TEXT NOT NULL DEFAULT '[]' CHECK (json_valid(depends_on)),
|
|
56
|
+
status TEXT NOT NULL DEFAULT 'pending'
|
|
57
|
+
CHECK (status IN ('pending', 'applied', 'failed', 'skipped', 'rejected', 'expired')),
|
|
58
|
+
status_reason TEXT,
|
|
59
|
+
error TEXT CHECK (error IS NULL OR json_valid(error)),
|
|
60
|
+
-- JSON `{ "<provisional id>": "<real id>" }`, set when applied.
|
|
61
|
+
bindings TEXT CHECK (bindings IS NULL OR json_valid(bindings)),
|
|
62
|
+
result TEXT CHECK (result IS NULL OR json_valid(result)),
|
|
63
|
+
request_audit_id TEXT,
|
|
64
|
+
applied_audit_id TEXT,
|
|
65
|
+
decided_by TEXT,
|
|
66
|
+
decided_at TEXT,
|
|
67
|
+
created_at TEXT NOT NULL,
|
|
68
|
+
expires_at TEXT NOT NULL
|
|
69
|
+
);
|
|
70
|
+
CREATE INDEX core_pending_action_set_idx ON core_pending_action (change_set_id, id);
|
|
71
|
+
CREATE INDEX core_pending_action_status_idx ON core_pending_action (status, expires_at);
|
|
72
|
+
|
|
73
|
+
-- Records a pending action touches (real or provisional ids): dependencies and record badges.
|
|
74
|
+
CREATE TABLE core_pending_action_records (
|
|
75
|
+
action_id TEXT NOT NULL REFERENCES core_pending_action (id),
|
|
76
|
+
object_type TEXT NOT NULL,
|
|
77
|
+
record_id TEXT NOT NULL,
|
|
78
|
+
-- create | update | delete | restore | erase | merge | reference
|
|
79
|
+
action TEXT NOT NULL,
|
|
80
|
+
PRIMARY KEY (action_id, object_type, record_id)
|
|
81
|
+
);
|
|
82
|
+
CREATE INDEX core_pending_action_records_record_idx
|
|
83
|
+
ON core_pending_action_records (object_type, record_id);
|
|
84
|
+
|
|
85
|
+
-- Links audit rows to the pending action they queued (outcome review) or applied (outcome ok).
|
|
86
|
+
ALTER TABLE core_audit ADD COLUMN pending_action_id TEXT;
|
|
87
|
+
CREATE INDEX core_audit_pending_action_idx ON core_audit (pending_action_id)
|
|
88
|
+
WHERE pending_action_id IS NOT NULL;
|
|
89
|
+
|
|
90
|
+
UPDATE core_meta SET value = '10' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
-- Migration 0011: connected apps (ADR 0021, ADR 0032). One row per OAuth authorization a user
|
|
2
|
+
-- gave an MCP client. Tokens live in the OAuth provider's KV; this row is the authority on
|
|
3
|
+
-- whether the connection may still be used (revocation), what it may do (scopes) and when it was
|
|
4
|
+
-- last used. Its id is the MCP session id.
|
|
5
|
+
|
|
6
|
+
CREATE TABLE core_connected_app (
|
|
7
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
8
|
+
user_id TEXT NOT NULL REFERENCES core_user (id) ON DELETE CASCADE,
|
|
9
|
+
client_id TEXT NOT NULL,
|
|
10
|
+
client_name TEXT NOT NULL,
|
|
11
|
+
client_uri TEXT,
|
|
12
|
+
redirect_host TEXT,
|
|
13
|
+
-- JSON array of granted scopes: read, write, admin.
|
|
14
|
+
scopes TEXT NOT NULL CHECK (json_valid(scopes)),
|
|
15
|
+
-- The OAuth provider's grant id, bound when the authorization code is exchanged.
|
|
16
|
+
grant_id TEXT,
|
|
17
|
+
created_at TEXT NOT NULL,
|
|
18
|
+
last_used_at TEXT,
|
|
19
|
+
revoked_at TEXT,
|
|
20
|
+
revoked_by TEXT,
|
|
21
|
+
-- revoked (by a person) | replaced (the user authorized the same client again)
|
|
22
|
+
revoke_reason TEXT
|
|
23
|
+
);
|
|
24
|
+
CREATE INDEX core_connected_app_user_idx ON core_connected_app (user_id, created_at);
|
|
25
|
+
CREATE INDEX core_connected_app_grant_idx ON core_connected_app (grant_id);
|
|
26
|
+
|
|
27
|
+
-- Fixed one-minute windows per key (`<connected app id>:requests` / `:writes`).
|
|
28
|
+
CREATE TABLE core_rate_limit (
|
|
29
|
+
key TEXT NOT NULL,
|
|
30
|
+
window_start TEXT NOT NULL,
|
|
31
|
+
count INTEGER NOT NULL DEFAULT 0,
|
|
32
|
+
PRIMARY KEY (key, window_start)
|
|
33
|
+
);
|
|
34
|
+
CREATE INDEX core_rate_limit_window_idx ON core_rate_limit (window_start);
|
|
35
|
+
|
|
36
|
+
UPDATE core_meta SET value = '11' WHERE key = 'schema_version';
|