@composable-os/cli 0.0.0-stage → 0.1.0-beta.8
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/blocks-DEELKGDC.js +233 -0
- package/dist/chunk-2ABSVMGB.js +13 -0
- package/dist/chunk-2S7375SC.js +802 -0
- package/dist/chunk-5KSXSK7Y.js +47 -0
- package/dist/chunk-6UWRT4VM.js +220 -0
- package/dist/chunk-E5JLTLRM.js +50 -0
- package/dist/chunk-G3ORKXVP.js +1178 -0
- package/dist/chunk-HDIOVFAZ.js +544 -0
- package/dist/chunk-KGHA67HG.js +765 -0
- package/dist/chunk-KOKYDJ7Z.js +1423 -0
- package/dist/chunk-KTXGEXTY.js +358 -0
- package/dist/chunk-LTQDLCP7.js +16486 -0
- package/dist/chunk-MAXLUQKB.js +1287 -0
- package/dist/chunk-STJZJIRA.js +11378 -0
- package/dist/chunk-X6I2LWB3.js +24319 -0
- package/dist/chunk-XDDBLYKW.js +29154 -0
- package/dist/chunk-ZRWF6QZS.js +2357 -0
- package/dist/cli-BRSACHSG.js +31393 -0
- package/dist/cli-DTMGNDXN.js +121 -0
- package/dist/cli.js +25 -0
- package/dist/client-repo-ZVZ6KW5S.js +55 -0
- package/dist/create.js +25 -0
- package/dist/fields-64BQJA62.js +48 -0
- package/dist/invoke-NHHOLLF6.js +26 -0
- package/dist/person-WMWRF2HV.js +58 -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/0520_publish_requests.sql +20 -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 +112 -0
- package/dist/platform/sdk/contract.ts +766 -0
- package/dist/platform/sdk/document.ts +788 -0
- package/dist/platform/sdk/field-types.ts +106 -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 +33 -0
- package/dist/platform/sdk/manifest.ts +1484 -0
- package/dist/platform/sdk/media.ts +46 -0
- package/dist/platform/sdk/permissions.ts +60 -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 +173 -0
- package/dist/platform/sdk/runtime.ts +410 -0
- package/dist/platform/sdk/sellable.ts +396 -0
- package/dist/platform/sdk/slug.ts +25 -0
- package/dist/platform/sdk/states.ts +162 -0
- package/dist/platform/sdk/testing.ts +836 -0
- package/dist/products-2H5DR232.js +11 -0
- package/dist/run-4JNFLYXV.js +847 -0
- package/dist/src-G6OF5SKW.js +31 -0
- package/dist/src-J27WXNLY.js +270 -0
- package/dist/token-MOJUA2U6.js +70 -0
- package/dist/token-util-TENRN4V7.js +6 -0
- package/package.json +33 -4
|
@@ -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';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
-- Migration 0359: compaction planner decisions for review (stage 17 W2, ADR 0341).
|
|
2
|
+
--
|
|
3
|
+
-- One row per planner run (at the end of a turn, and when the idle alarm fires): the planner's
|
|
4
|
+
-- input verbatim (sizes, prices, the lifetime estimate and its confidence, the person's usage
|
|
5
|
+
-- profile, the rails), its result (both expected costs, the decision and the rule that made it),
|
|
6
|
+
-- and later the actual cost of the turns that followed, so predicted and real cost can be
|
|
7
|
+
-- compared. Sizes, prices and times only; never message content. Kept 180 days.
|
|
8
|
+
CREATE TABLE core_ai_compaction_decision (
|
|
9
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
10
|
+
at TEXT NOT NULL,
|
|
11
|
+
provider TEXT NOT NULL,
|
|
12
|
+
model TEXT NOT NULL,
|
|
13
|
+
role TEXT NOT NULL,
|
|
14
|
+
decision TEXT NOT NULL CHECK (decision IN ('compact', 'continue')),
|
|
15
|
+
rule TEXT NOT NULL,
|
|
16
|
+
input TEXT NOT NULL CHECK (json_valid(input)),
|
|
17
|
+
result TEXT NOT NULL CHECK (json_valid(result)),
|
|
18
|
+
-- Filled in once the horizon's turns have run.
|
|
19
|
+
actual_turns INTEGER,
|
|
20
|
+
actual_cost REAL,
|
|
21
|
+
actual_at TEXT
|
|
22
|
+
);
|
|
23
|
+
CREATE INDEX core_ai_compaction_decision_at_idx ON core_ai_compaction_decision (at);
|
|
24
|
+
|
|
25
|
+
UPDATE core_meta SET value = '359' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
-- Migration 0360: learned cache lifetimes per provider and model, and their history (stage 17
|
|
2
|
+
-- W2, ADR 0341).
|
|
3
|
+
--
|
|
4
|
+
-- `state` is the learner's state (decayed hit and miss counts per gap bucket and the learned
|
|
5
|
+
-- bucket), updated by each finished turn's bookkeeping write. `version` guards the
|
|
6
|
+
-- read-modify-write: an update that lost a race is dropped, and the observations it carried are
|
|
7
|
+
-- still in core_ai_cache_observation for a replay. Settings → AI shows the estimate read-only.
|
|
8
|
+
-- A deployment is one workspace, so rows are keyed by provider and model only.
|
|
9
|
+
CREATE TABLE core_ai_cache_estimate (
|
|
10
|
+
provider TEXT NOT NULL,
|
|
11
|
+
model TEXT NOT NULL,
|
|
12
|
+
state TEXT NOT NULL CHECK (json_valid(state)),
|
|
13
|
+
learned_seconds REAL,
|
|
14
|
+
published_seconds REAL,
|
|
15
|
+
confidence REAL,
|
|
16
|
+
sample_size REAL NOT NULL DEFAULT 0,
|
|
17
|
+
version INTEGER NOT NULL DEFAULT 0,
|
|
18
|
+
updated_at TEXT NOT NULL,
|
|
19
|
+
PRIMARY KEY (provider, model)
|
|
20
|
+
) WITHOUT ROWID;
|
|
21
|
+
|
|
22
|
+
-- Every change of a learned estimate (rise or fall), appended.
|
|
23
|
+
CREATE TABLE core_ai_cache_estimate_history (
|
|
24
|
+
id INTEGER PRIMARY KEY,
|
|
25
|
+
provider TEXT NOT NULL,
|
|
26
|
+
model TEXT NOT NULL,
|
|
27
|
+
at TEXT NOT NULL,
|
|
28
|
+
from_seconds REAL,
|
|
29
|
+
to_seconds REAL,
|
|
30
|
+
reason TEXT NOT NULL CHECK (reason IN ('rise', 'fall')),
|
|
31
|
+
sample_size REAL NOT NULL
|
|
32
|
+
);
|
|
33
|
+
CREATE INDEX core_ai_cache_estimate_history_at_idx ON core_ai_cache_estimate_history (at);
|
|
34
|
+
|
|
35
|
+
UPDATE core_meta SET value = '360' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
-- Migration 0361: voice preferences (stage 17 W9, ADR 0349).
|
|
2
|
+
--
|
|
3
|
+
-- Voice, speed and how much to read out are per person. How someone talks (push to talk or
|
|
4
|
+
-- hands-free) is per device: `default_mode` is what first setup chose and what every new device
|
|
5
|
+
-- starts with; `core_voice_device.mode` is set only when it changes on that device.
|
|
6
|
+
CREATE TABLE core_voice_prefs (
|
|
7
|
+
user_id TEXT PRIMARY KEY NOT NULL REFERENCES core_user (id),
|
|
8
|
+
voice_id TEXT NOT NULL,
|
|
9
|
+
speed REAL NOT NULL DEFAULT 1,
|
|
10
|
+
default_mode TEXT NOT NULL CHECK (default_mode IN ('push_to_talk', 'hands_free')),
|
|
11
|
+
-- When the person can see the screen: a short version, or everything.
|
|
12
|
+
read_out TEXT NOT NULL DEFAULT 'short' CHECK (read_out IN ('short', 'full')),
|
|
13
|
+
created_at TEXT NOT NULL,
|
|
14
|
+
updated_at TEXT NOT NULL
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
CREATE TABLE core_voice_device (
|
|
18
|
+
user_id TEXT NOT NULL REFERENCES core_user (id),
|
|
19
|
+
-- A random id the browser keeps in local storage.
|
|
20
|
+
device_id TEXT NOT NULL,
|
|
21
|
+
label TEXT NOT NULL,
|
|
22
|
+
mode TEXT CHECK (mode IS NULL OR mode IN ('push_to_talk', 'hands_free')),
|
|
23
|
+
last_seen_at TEXT NOT NULL,
|
|
24
|
+
PRIMARY KEY (user_id, device_id)
|
|
25
|
+
) WITHOUT ROWID;
|
|
26
|
+
|
|
27
|
+
UPDATE core_meta SET value = '361' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
-- Migration 0362: speech usage counted in the workspace (stage 17 W9, ADR 0349's amendment).
|
|
2
|
+
--
|
|
3
|
+
-- AssemblyAI's streaming sockets do not go through AI Gateway, so no gateway log sees them. Each
|
|
4
|
+
-- call's usage is counted here per day, person, role and provider, beside core_ai_usage: seconds
|
|
5
|
+
-- of audio in (`transcribe`), characters out (`speak`). Counts only, never words or audio.
|
|
6
|
+
CREATE TABLE core_voice_usage (
|
|
7
|
+
day TEXT NOT NULL,
|
|
8
|
+
user_id TEXT NOT NULL,
|
|
9
|
+
role TEXT NOT NULL,
|
|
10
|
+
provider TEXT NOT NULL,
|
|
11
|
+
requests INTEGER NOT NULL DEFAULT 0,
|
|
12
|
+
audio_seconds REAL NOT NULL DEFAULT 0,
|
|
13
|
+
characters INTEGER NOT NULL DEFAULT 0,
|
|
14
|
+
PRIMARY KEY (day, user_id, role, provider)
|
|
15
|
+
) WITHOUT ROWID;
|
|
16
|
+
|
|
17
|
+
UPDATE core_meta SET value = '362' WHERE key = 'schema_version';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
-- Migration 0365: personal routines (stage 17 W4, ADR 0343).
|
|
2
|
+
--
|
|
3
|
+
-- A routine is a personal automation on the existing engine: a core_automations row with
|
|
4
|
+
-- `scope = 'personal'` and `owner_user_id` set, matched and started by the same dispatcher, under
|
|
5
|
+
-- the same kill switch and rails. Its extension_id is the reserved `routine` (there is no
|
|
6
|
+
-- extension: the Workflow runs its checks and delivery itself). Run history stays in
|
|
7
|
+
-- core_automation_runs. automation.* operations show only `scope = 'org'` rows: a routine belongs
|
|
8
|
+
-- to its owner.
|
|
9
|
+
ALTER TABLE core_automations ADD COLUMN owner_user_id TEXT;
|
|
10
|
+
ALTER TABLE core_automations ADD COLUMN scope TEXT NOT NULL DEFAULT 'org'
|
|
11
|
+
CHECK (scope IN ('org', 'personal'));
|
|
12
|
+
CREATE INDEX core_automations_owner_idx ON core_automations (owner_user_id)
|
|
13
|
+
WHERE owner_user_id IS NOT NULL;
|
|
14
|
+
|
|
15
|
+
-- What only a routine has: the person's words, what it sends and its delivery state. One row per
|
|
16
|
+
-- routine; `definition` is the RoutineDefinition JSON the automation's spec was built from.
|
|
17
|
+
CREATE TABLE core_routine (
|
|
18
|
+
id TEXT PRIMARY KEY NOT NULL CHECK (id GLOB 'rtn_*'),
|
|
19
|
+
automation_id TEXT NOT NULL UNIQUE,
|
|
20
|
+
owner_user_id TEXT NOT NULL,
|
|
21
|
+
name TEXT NOT NULL,
|
|
22
|
+
-- Finishes "I'll …": "send you your open deals with no activity for 14 days".
|
|
23
|
+
what TEXT NOT NULL,
|
|
24
|
+
-- What the person said when they asked for it, and when (the why panel). Null for an offer.
|
|
25
|
+
asked TEXT,
|
|
26
|
+
asked_at TEXT,
|
|
27
|
+
definition TEXT NOT NULL CHECK (json_valid(definition)),
|
|
28
|
+
-- The read-back it came from: pressing Turn on twice makes one routine.
|
|
29
|
+
draft_id TEXT UNIQUE,
|
|
30
|
+
-- Snoozed: runs before this are stopped at their checks.
|
|
31
|
+
paused_until TEXT,
|
|
32
|
+
last_delivered_at TEXT,
|
|
33
|
+
-- The last delivery that failed (the app could not make the message). Cleared by the next one.
|
|
34
|
+
last_error TEXT,
|
|
35
|
+
created_at TEXT NOT NULL,
|
|
36
|
+
updated_at TEXT NOT NULL
|
|
37
|
+
);
|
|
38
|
+
CREATE INDEX core_routine_owner_idx ON core_routine (owner_user_id, created_at);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
-- Migration 0370: approvals by tap, typing or voice (stage 17 W5, ADR 0345).
|
|
2
|
+
--
|
|
3
|
+
-- `execution_id` makes applying idempotent: an approval claims the actions it will apply, in one
|
|
4
|
+
-- statement, before it applies any. A tap and a spoken yes that arrive together both ask, one
|
|
5
|
+
-- claims, and each action applies once. `execution_at` is when it was claimed: a claim left by a
|
|
6
|
+
-- request that died can be taken over after a few minutes, which is safe because each action
|
|
7
|
+
-- applies and changes status in one batch.
|
|
8
|
+
--
|
|
9
|
+
-- `decided_via` is how the person gave the decision. The person's words stay in their thread; they
|
|
10
|
+
-- are not copied here, so an erase has no new place to reach.
|
|
11
|
+
ALTER TABLE core_pending_action ADD COLUMN execution_id TEXT;
|
|
12
|
+
ALTER TABLE core_pending_action ADD COLUMN execution_at TEXT;
|
|
13
|
+
ALTER TABLE core_pending_action ADD COLUMN decided_via TEXT
|
|
14
|
+
CHECK (decided_via IS NULL OR decided_via IN ('tap', 'typed', 'spoken'));
|
|
15
|
+
CREATE INDEX core_pending_action_execution_idx ON core_pending_action (execution_id)
|
|
16
|
+
WHERE execution_id IS NOT NULL;
|
|
17
|
+
|
|
18
|
+
-- Guarded: migrations land out of order (docs/parallel-work.md).
|
|
19
|
+
UPDATE core_meta SET value = '370'
|
|
20
|
+
WHERE key = 'schema_version' AND CAST(value AS INTEGER) < 370;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
-- Migration 0371: agents (stage 17 W5, ADR 0344).
|
|
2
|
+
--
|
|
3
|
+
-- One row per agent the assistant, a routine or a plugin started. In code they are jobs; the
|
|
4
|
+
-- person sees "Agents". The AgentJob Durable Object (`job:<id>`) runs the work and deletes its
|
|
5
|
+
-- storage when it is done; this row is what stays: the card, the limits, the results.
|
|
6
|
+
--
|
|
7
|
+
-- state:
|
|
8
|
+
-- awaiting_confirm the grant is shown to the person first (the judge is off or could not answer)
|
|
9
|
+
-- refused the grant was judged wider than the brief needs
|
|
10
|
+
-- queued waiting for a slot (the per-user and per-workspace limits)
|
|
11
|
+
-- running the object is working
|
|
12
|
+
-- paused stopped at its spend limit, waiting for "Allow $X more"
|
|
13
|
+
-- done, stopped, failed, cancelled finished
|
|
14
|
+
--
|
|
15
|
+
-- `access` is the grant (operations, target, caps, expiry) and `budget` the step, time and spend
|
|
16
|
+
-- limits, both JSON. `spent_microusd` is charged to the starter (`starter_kind`, `starter_id`).
|
|
17
|
+
-- `progress` is what the card shows ({ done, total, now }). `result` is the agent's final words.
|
|
18
|
+
CREATE TABLE core_agent_job (
|
|
19
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
20
|
+
user_id TEXT NOT NULL REFERENCES core_user (id) ON DELETE CASCADE,
|
|
21
|
+
starter_kind TEXT NOT NULL CHECK (starter_kind IN ('user', 'routine', 'plugin')),
|
|
22
|
+
starter_id TEXT NOT NULL,
|
|
23
|
+
profile TEXT,
|
|
24
|
+
role TEXT NOT NULL,
|
|
25
|
+
title TEXT NOT NULL,
|
|
26
|
+
brief TEXT NOT NULL,
|
|
27
|
+
records TEXT NOT NULL CHECK (json_valid(records)),
|
|
28
|
+
access TEXT NOT NULL CHECK (json_valid(access)),
|
|
29
|
+
budget TEXT NOT NULL CHECK (json_valid(budget)),
|
|
30
|
+
mode TEXT NOT NULL CHECK (mode IN ('awaited', 'background')),
|
|
31
|
+
review_everything INTEGER NOT NULL DEFAULT 0,
|
|
32
|
+
state TEXT NOT NULL CHECK (state IN (
|
|
33
|
+
'awaiting_confirm', 'refused', 'queued', 'running', 'paused',
|
|
34
|
+
'done', 'stopped', 'failed', 'cancelled'
|
|
35
|
+
)),
|
|
36
|
+
-- What the judge said about the grant (labels and probabilities), or why it could not.
|
|
37
|
+
judged TEXT CHECK (judged IS NULL OR json_valid(judged)),
|
|
38
|
+
justification TEXT,
|
|
39
|
+
progress TEXT CHECK (progress IS NULL OR json_valid(progress)),
|
|
40
|
+
steps INTEGER NOT NULL DEFAULT 0,
|
|
41
|
+
spent_microusd INTEGER NOT NULL DEFAULT 0,
|
|
42
|
+
fields_filled INTEGER NOT NULL DEFAULT 0,
|
|
43
|
+
result TEXT,
|
|
44
|
+
error TEXT,
|
|
45
|
+
-- The object has been told to start (its alarm owns the work from then on).
|
|
46
|
+
started_at TEXT,
|
|
47
|
+
finished_at TEXT,
|
|
48
|
+
created_at TEXT NOT NULL,
|
|
49
|
+
updated_at TEXT NOT NULL
|
|
50
|
+
);
|
|
51
|
+
CREATE INDEX core_agent_job_user_idx ON core_agent_job (user_id, state, created_at);
|
|
52
|
+
CREATE INDEX core_agent_job_state_idx ON core_agent_job (state, created_at);
|
|
53
|
+
|
|
54
|
+
-- Which people, organisations (`per_…`, `org_…`) and email addresses (`email:<sha256>`) a job's
|
|
55
|
+
-- brief, records, progress and results name, so an erase finds the rows to redact (ADR 0320).
|
|
56
|
+
CREATE TABLE core_agent_job_refs (
|
|
57
|
+
job_id TEXT NOT NULL REFERENCES core_agent_job (id) ON DELETE CASCADE,
|
|
58
|
+
ref TEXT NOT NULL,
|
|
59
|
+
PRIMARY KEY (job_id, ref)
|
|
60
|
+
) WITHOUT ROWID;
|
|
61
|
+
CREATE INDEX core_agent_job_refs_ref_idx ON core_agent_job_refs (ref);
|
|
62
|
+
|
|
63
|
+
-- Guarded: migrations land out of order (docs/parallel-work.md).
|
|
64
|
+
UPDATE core_meta SET value = '371'
|
|
65
|
+
WHERE key = 'schema_version' AND CAST(value AS INTEGER) < 371;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
-- Migration 0380: the read views are named rec_<object> (stage 20, ADR 0400).
|
|
2
|
+
--
|
|
3
|
+
-- The extension contract no longer says `crm`: the views that query.sql, dashboards and extension
|
|
4
|
+
-- code read were `crm_<plural>` and are now `rec_<object>`, named like the object they read, as
|
|
5
|
+
-- extension objects' views already were (`rec_x_<ext>_<object>`):
|
|
6
|
+
--
|
|
7
|
+
-- crm_people rec_person crm_tasks rec_task
|
|
8
|
+
-- crm_organisations rec_organisation crm_task_links rec_task_link
|
|
9
|
+
-- crm_affiliations rec_affiliation crm_record_tags rec_record_tag
|
|
10
|
+
-- crm_activities rec_activity crm_users rec_user
|
|
11
|
+
-- crm_activity_links rec_activity_link crm_stage_history rec_stage_history
|
|
12
|
+
--
|
|
13
|
+
-- The bodies are unchanged: each is the definition the view had (0007, 0020, 0100, 0111, 0221).
|
|
14
|
+
-- The four object views are `SELECT b.* FROM core_base_<x> b` here; the schema reconciler
|
|
15
|
+
-- regenerates them with the extension side tables joined, and names extension objects' views
|
|
16
|
+
-- rec_x_<ext>_<object>, the next time it runs.
|
|
17
|
+
--
|
|
18
|
+
-- No release was installed under the old names (ADR 0400), so nothing reads them afterwards.
|
|
19
|
+
|
|
20
|
+
DROP VIEW crm_people;
|
|
21
|
+
DROP VIEW crm_organisations;
|
|
22
|
+
DROP VIEW crm_affiliations;
|
|
23
|
+
DROP VIEW crm_activities;
|
|
24
|
+
DROP VIEW crm_activity_links;
|
|
25
|
+
DROP VIEW crm_tasks;
|
|
26
|
+
DROP VIEW crm_task_links;
|
|
27
|
+
DROP VIEW crm_record_tags;
|
|
28
|
+
DROP VIEW crm_users;
|
|
29
|
+
DROP VIEW crm_stage_history;
|
|
30
|
+
|
|
31
|
+
CREATE VIEW rec_user AS
|
|
32
|
+
SELECT u.id, u.name, u.email, u.role, u.image, u.created_at
|
|
33
|
+
FROM core_user u
|
|
34
|
+
WHERE u.kind = 'human' AND u.support_grant_id IS NULL;
|
|
35
|
+
|
|
36
|
+
CREATE VIEW rec_person AS SELECT b.* FROM core_base_people b;
|
|
37
|
+
CREATE VIEW rec_organisation AS SELECT b.* FROM core_base_organisations b;
|
|
38
|
+
CREATE VIEW rec_activity AS SELECT b.* FROM core_base_activities b;
|
|
39
|
+
CREATE VIEW rec_task AS SELECT b.* FROM core_base_tasks b;
|
|
40
|
+
|
|
41
|
+
CREATE VIEW rec_affiliation AS
|
|
42
|
+
SELECT
|
|
43
|
+
affiliation.id,
|
|
44
|
+
affiliation.person_id,
|
|
45
|
+
affiliation.organisation_id,
|
|
46
|
+
affiliation.title,
|
|
47
|
+
affiliation.role,
|
|
48
|
+
affiliation.started_on,
|
|
49
|
+
affiliation.ended_on,
|
|
50
|
+
affiliation.is_current,
|
|
51
|
+
affiliation.is_primary,
|
|
52
|
+
affiliation.created_at,
|
|
53
|
+
affiliation.updated_at
|
|
54
|
+
FROM core_affiliation affiliation
|
|
55
|
+
JOIN core_person p ON p.id = affiliation.person_id AND p.deleted_at IS NULL
|
|
56
|
+
JOIN core_organisation o ON o.id = affiliation.organisation_id AND o.deleted_at IS NULL
|
|
57
|
+
WHERE affiliation.deleted_at IS NULL;
|
|
58
|
+
|
|
59
|
+
CREATE VIEW rec_activity_link AS
|
|
60
|
+
SELECT l.activity_id, l.object_type, l.record_id
|
|
61
|
+
FROM core_activity_links l
|
|
62
|
+
JOIN core_activity a ON a.id = l.activity_id AND a.deleted_at IS NULL AND a.private_to IS NULL;
|
|
63
|
+
|
|
64
|
+
CREATE VIEW rec_task_link AS
|
|
65
|
+
SELECT l.task_id, l.object_type, l.record_id
|
|
66
|
+
FROM core_task_links l
|
|
67
|
+
JOIN core_task t ON t.id = l.task_id AND t.deleted_at IS NULL;
|
|
68
|
+
|
|
69
|
+
CREATE VIEW rec_record_tag AS
|
|
70
|
+
SELECT rt.object_type, rt.record_id, tg.id AS tag_id, tg.name AS tag
|
|
71
|
+
FROM core_record_tags rt
|
|
72
|
+
JOIN core_tags tg ON tg.id = rt.tag_id;
|
|
73
|
+
|
|
74
|
+
CREATE VIEW rec_stage_history AS
|
|
75
|
+
SELECT
|
|
76
|
+
id,
|
|
77
|
+
object_type,
|
|
78
|
+
record_id,
|
|
79
|
+
stage_id,
|
|
80
|
+
group_id,
|
|
81
|
+
stage_type,
|
|
82
|
+
entered_at,
|
|
83
|
+
left_at,
|
|
84
|
+
left_at IS NULL AS is_current,
|
|
85
|
+
round(
|
|
86
|
+
julianday(coalesce(left_at, strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))) - julianday(entered_at),
|
|
87
|
+
4
|
|
88
|
+
) AS days_in_stage,
|
|
89
|
+
entered_by
|
|
90
|
+
FROM core_stage_history;
|
|
91
|
+
|
|
92
|
+
-- Guarded: migrations land out of order (docs/parallel-work.md).
|
|
93
|
+
UPDATE core_meta SET value = '380'
|
|
94
|
+
WHERE key = 'schema_version' AND CAST(value AS INTEGER) < 380;
|