@jungjaehoon/mama-core 1.7.0 → 1.9.0

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.
@@ -0,0 +1,57 @@
1
+ CREATE TABLE IF NOT EXISTS vnext_operator_cursors (
2
+ cursor_name TEXT PRIMARY KEY,
3
+ last_change_seq INTEGER NOT NULL DEFAULT 0 CHECK (last_change_seq >= 0),
4
+ last_idempotency_key TEXT,
5
+ updated_at_ms INTEGER NOT NULL CHECK (updated_at_ms >= 0)
6
+ );
7
+
8
+ CREATE TABLE IF NOT EXISTS vnext_operator_commits (
9
+ commit_id TEXT PRIMARY KEY,
10
+ cursor_name TEXT NOT NULL,
11
+ idempotency_key TEXT NOT NULL UNIQUE,
12
+ first_change_seq INTEGER NOT NULL CHECK (first_change_seq >= 0),
13
+ last_change_seq INTEGER NOT NULL CHECK (last_change_seq >= first_change_seq),
14
+ status TEXT NOT NULL CHECK (status IN ('changed', 'no_update')),
15
+ changed_refs_json TEXT NOT NULL CHECK (json_valid(changed_refs_json)),
16
+ source_refs_json TEXT NOT NULL CHECK (json_valid(source_refs_json)),
17
+ created_at_ms INTEGER NOT NULL CHECK (created_at_ms >= 0),
18
+ FOREIGN KEY (cursor_name) REFERENCES vnext_operator_cursors(cursor_name)
19
+ );
20
+
21
+ CREATE INDEX IF NOT EXISTS idx_vnext_operator_commits_cursor_seq
22
+ ON vnext_operator_commits(cursor_name, last_change_seq);
23
+
24
+ CREATE TABLE IF NOT EXISTS operator_no_updates (
25
+ no_update_id TEXT PRIMARY KEY,
26
+ scope_key TEXT NOT NULL,
27
+ reason TEXT NOT NULL,
28
+ source_refs_json TEXT NOT NULL CHECK (json_valid(source_refs_json)),
29
+ idempotency_key TEXT NOT NULL UNIQUE,
30
+ created_at_ms INTEGER NOT NULL CHECK (created_at_ms >= 0)
31
+ );
32
+
33
+ CREATE INDEX IF NOT EXISTS idx_operator_no_updates_scope_created
34
+ ON operator_no_updates(scope_key, created_at_ms DESC);
35
+
36
+ CREATE TABLE IF NOT EXISTS worker_proposals (
37
+ proposal_id TEXT PRIMARY KEY,
38
+ worker_id TEXT NOT NULL,
39
+ kind TEXT NOT NULL,
40
+ payload_json TEXT NOT NULL CHECK (json_valid(payload_json)),
41
+ source_refs_json TEXT NOT NULL CHECK (json_valid(source_refs_json)),
42
+ confidence REAL NOT NULL CHECK (confidence >= 0 AND confidence <= 1),
43
+ status TEXT NOT NULL CHECK (status IN ('proposed', 'accepted', 'rejected', 'superseded')),
44
+ created_at_ms INTEGER NOT NULL CHECK (created_at_ms >= 0),
45
+ accepted_at_ms INTEGER CHECK (
46
+ (status = 'proposed' AND accepted_at_ms IS NULL) OR
47
+ (status = 'accepted' AND accepted_at_ms IS NOT NULL AND accepted_at_ms >= created_at_ms) OR
48
+ (status = 'rejected' AND accepted_at_ms IS NULL) OR
49
+ (status = 'superseded' AND (accepted_at_ms IS NULL OR accepted_at_ms >= created_at_ms))
50
+ )
51
+ );
52
+
53
+ CREATE INDEX IF NOT EXISTS idx_worker_proposals_status_kind
54
+ ON worker_proposals(status, kind, created_at_ms);
55
+
56
+ INSERT OR IGNORE INTO schema_version (version, description)
57
+ VALUES (38, 'Create vNext operator contracts');
@@ -0,0 +1,96 @@
1
+ ALTER TABLE connector_event_index
2
+ ADD COLUMN operator_ingest_seq INTEGER CHECK (
3
+ operator_ingest_seq IS NULL OR operator_ingest_seq >= 1
4
+ );
5
+
6
+ CREATE TABLE IF NOT EXISTS connector_event_index_operator_seq_cursors (
7
+ source_connector TEXT NOT NULL,
8
+ channel TEXT NOT NULL DEFAULT '',
9
+ next_seq INTEGER NOT NULL CHECK (next_seq >= 1),
10
+ PRIMARY KEY (source_connector, channel)
11
+ );
12
+
13
+ WITH ranked_events AS (
14
+ SELECT
15
+ event_index_id,
16
+ ROW_NUMBER() OVER (
17
+ PARTITION BY source_connector, COALESCE(channel, '')
18
+ ORDER BY rowid ASC
19
+ ) AS operator_seq
20
+ FROM connector_event_index
21
+ )
22
+ UPDATE connector_event_index
23
+ SET operator_ingest_seq = (
24
+ SELECT operator_seq
25
+ FROM ranked_events
26
+ WHERE ranked_events.event_index_id = connector_event_index.event_index_id
27
+ )
28
+ WHERE operator_ingest_seq IS NULL;
29
+
30
+ INSERT OR IGNORE INTO connector_event_index_operator_seq_cursors (
31
+ source_connector,
32
+ channel,
33
+ next_seq
34
+ )
35
+ SELECT
36
+ source_connector,
37
+ COALESCE(channel, ''),
38
+ COALESCE(MAX(operator_ingest_seq), 0) + 1
39
+ FROM connector_event_index
40
+ GROUP BY source_connector, COALESCE(channel, '');
41
+
42
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_connector_event_index_operator_scope_seq
43
+ ON connector_event_index(source_connector, COALESCE(channel, ''), operator_ingest_seq)
44
+ WHERE operator_ingest_seq IS NOT NULL;
45
+
46
+ CREATE INDEX IF NOT EXISTS idx_connector_event_index_operator_cursor_order
47
+ ON connector_event_index(source_connector, channel, operator_ingest_seq);
48
+
49
+ CREATE TRIGGER IF NOT EXISTS trg_connector_event_index_operator_ingest_seq_ai
50
+ AFTER INSERT ON connector_event_index
51
+ WHEN NEW.operator_ingest_seq IS NULL
52
+ BEGIN
53
+ INSERT OR IGNORE INTO connector_event_index_operator_seq_cursors (
54
+ source_connector,
55
+ channel,
56
+ next_seq
57
+ )
58
+ VALUES (NEW.source_connector, COALESCE(NEW.channel, ''), 1);
59
+
60
+ UPDATE connector_event_index
61
+ SET operator_ingest_seq = (
62
+ SELECT next_seq
63
+ FROM connector_event_index_operator_seq_cursors
64
+ WHERE source_connector = NEW.source_connector
65
+ AND channel = COALESCE(NEW.channel, '')
66
+ )
67
+ WHERE event_index_id = NEW.event_index_id;
68
+
69
+ UPDATE connector_event_index_operator_seq_cursors
70
+ SET next_seq = next_seq + 1
71
+ WHERE source_connector = NEW.source_connector
72
+ AND channel = COALESCE(NEW.channel, '');
73
+ END;
74
+
75
+ CREATE TRIGGER IF NOT EXISTS trg_connector_event_index_operator_ingest_seq_explicit_ai
76
+ AFTER INSERT ON connector_event_index
77
+ WHEN NEW.operator_ingest_seq IS NOT NULL
78
+ BEGIN
79
+ INSERT OR IGNORE INTO connector_event_index_operator_seq_cursors (
80
+ source_connector,
81
+ channel,
82
+ next_seq
83
+ )
84
+ VALUES (NEW.source_connector, COALESCE(NEW.channel, ''), 1);
85
+
86
+ UPDATE connector_event_index_operator_seq_cursors
87
+ SET next_seq = CASE
88
+ WHEN next_seq <= NEW.operator_ingest_seq THEN NEW.operator_ingest_seq + 1
89
+ ELSE next_seq
90
+ END
91
+ WHERE source_connector = NEW.source_connector
92
+ AND channel = COALESCE(NEW.channel, '');
93
+ END;
94
+
95
+ INSERT OR IGNORE INTO schema_version (version, description)
96
+ VALUES (39, 'Add connector event operator ingest sequence');
@@ -0,0 +1,19 @@
1
+ CREATE TABLE IF NOT EXISTS operator_memory_commit_intents (
2
+ intent_id TEXT PRIMARY KEY,
3
+ cursor_name TEXT NOT NULL,
4
+ idempotency_key TEXT NOT NULL UNIQUE,
5
+ expected_memory_count INTEGER NOT NULL CHECK (expected_memory_count > 0),
6
+ memory_payload_hash TEXT NOT NULL CHECK (memory_payload_hash LIKE 'sha256:%'),
7
+ memory_ids_json TEXT NOT NULL CHECK (json_valid(memory_ids_json)),
8
+ source_refs_json TEXT NOT NULL CHECK (json_valid(source_refs_json)),
9
+ status TEXT NOT NULL CHECK (status IN ('pending', 'saving', 'saved', 'promoted')),
10
+ claim_token TEXT,
11
+ created_at_ms INTEGER NOT NULL CHECK (created_at_ms >= 0),
12
+ updated_at_ms INTEGER NOT NULL CHECK (updated_at_ms >= created_at_ms)
13
+ );
14
+
15
+ CREATE INDEX IF NOT EXISTS idx_operator_memory_commit_intents_cursor_created
16
+ ON operator_memory_commit_intents(cursor_name, created_at_ms DESC);
17
+
18
+ INSERT OR IGNORE INTO schema_version (version, description)
19
+ VALUES (40, 'Create operator memory commit intents');
@@ -0,0 +1,74 @@
1
+ CREATE TABLE IF NOT EXISTS operator_memory_commit_intents (
2
+ intent_id TEXT PRIMARY KEY,
3
+ cursor_name TEXT NOT NULL,
4
+ idempotency_key TEXT NOT NULL UNIQUE,
5
+ expected_memory_count INTEGER NOT NULL CHECK (expected_memory_count > 0),
6
+ memory_payload_hash TEXT NOT NULL CHECK (memory_payload_hash LIKE 'sha256:%'),
7
+ memory_ids_json TEXT NOT NULL CHECK (json_valid(memory_ids_json)),
8
+ source_refs_json TEXT NOT NULL CHECK (json_valid(source_refs_json)),
9
+ status TEXT NOT NULL CHECK (status IN ('pending', 'saving', 'saved', 'promoted')),
10
+ claim_token TEXT,
11
+ created_at_ms INTEGER NOT NULL CHECK (created_at_ms >= 0),
12
+ updated_at_ms INTEGER NOT NULL CHECK (updated_at_ms >= created_at_ms)
13
+ );
14
+
15
+ DROP TABLE IF EXISTS operator_memory_commit_intents_v041;
16
+
17
+ CREATE TABLE operator_memory_commit_intents_v041 (
18
+ intent_id TEXT PRIMARY KEY,
19
+ cursor_name TEXT NOT NULL,
20
+ idempotency_key TEXT NOT NULL UNIQUE,
21
+ expected_memory_count INTEGER NOT NULL CHECK (expected_memory_count > 0),
22
+ memory_payload_hash TEXT NOT NULL CHECK (memory_payload_hash LIKE 'sha256:%'),
23
+ memory_ids_json TEXT NOT NULL CHECK (json_valid(memory_ids_json)),
24
+ source_refs_json TEXT NOT NULL CHECK (json_valid(source_refs_json)),
25
+ status TEXT NOT NULL CHECK (status IN ('pending', 'saving', 'saved', 'promoted')),
26
+ claim_token TEXT CHECK (
27
+ (status = 'saving' AND claim_token IS NOT NULL) OR
28
+ (status != 'saving' AND claim_token IS NULL)
29
+ ),
30
+ created_at_ms INTEGER NOT NULL CHECK (created_at_ms >= 0),
31
+ updated_at_ms INTEGER NOT NULL CHECK (updated_at_ms >= created_at_ms)
32
+ );
33
+
34
+ INSERT INTO operator_memory_commit_intents_v041 (
35
+ intent_id,
36
+ cursor_name,
37
+ idempotency_key,
38
+ expected_memory_count,
39
+ memory_payload_hash,
40
+ memory_ids_json,
41
+ source_refs_json,
42
+ status,
43
+ claim_token,
44
+ created_at_ms,
45
+ updated_at_ms
46
+ )
47
+ SELECT
48
+ intent_id,
49
+ cursor_name,
50
+ idempotency_key,
51
+ expected_memory_count,
52
+ memory_payload_hash,
53
+ memory_ids_json,
54
+ source_refs_json,
55
+ CASE
56
+ WHEN status = 'saving' AND claim_token IS NULL THEN 'pending'
57
+ ELSE status
58
+ END,
59
+ CASE
60
+ WHEN status = 'saving' AND claim_token IS NOT NULL THEN claim_token
61
+ ELSE NULL
62
+ END,
63
+ created_at_ms,
64
+ updated_at_ms
65
+ FROM operator_memory_commit_intents;
66
+
67
+ DROP TABLE operator_memory_commit_intents;
68
+ ALTER TABLE operator_memory_commit_intents_v041 RENAME TO operator_memory_commit_intents;
69
+
70
+ CREATE INDEX IF NOT EXISTS idx_operator_memory_commit_intents_cursor_created
71
+ ON operator_memory_commit_intents(cursor_name, created_at_ms DESC);
72
+
73
+ INSERT OR IGNORE INTO schema_version (version, description)
74
+ VALUES (41, 'Enforce operator memory commit claim invariant');
@@ -0,0 +1,46 @@
1
+ -- Migration 042: track the embedding instruction-prefix scheme (e5 query/passage).
2
+ -- Fresh DB (no stored vectors) starts current; an upgraded DB with pre-existing
3
+ -- unprefixed vectors (in EITHER vector store) is marked legacy so the runtime guard
4
+ -- forces a re-embed.
5
+ --
6
+ -- Robustness: a SQLite statement that references a missing table fails at prepare
7
+ -- time, so a sqlite_master-gated WHERE clause alone cannot protect a reference to an
8
+ -- absent table. Some legacy-recovery paths reach 042 with a partial schema (e.g. a DB
9
+ -- whose schema_version was fast-forwarded past migration 030, so wiki_page_embeddings
10
+ -- does not exist yet). We therefore CREATE IF NOT EXISTS both vector-store tables with
11
+ -- the exact shapes of migrations 013/030 (no-op on any normally-migrated DB, empty
12
+ -- shells on partial ones) before the marker statement references them. The runtime
13
+ -- guard in db-manager (assertEmbeddingSchemeCurrent) independently counts both tables
14
+ -- (try/catch-wrapped), so the two layers agree.
15
+
16
+ CREATE TABLE IF NOT EXISTS embedding_meta (
17
+ key TEXT PRIMARY KEY,
18
+ value TEXT NOT NULL,
19
+ updated_at INTEGER NOT NULL DEFAULT (unixepoch() * 1000)
20
+ );
21
+
22
+ -- Shape of migration 013 (embeddings) - no-op unless the schema is partial.
23
+ CREATE TABLE IF NOT EXISTS embeddings (
24
+ rowid INTEGER PRIMARY KEY,
25
+ embedding BLOB NOT NULL
26
+ );
27
+
28
+ -- Shape of migration 030 (wiki_page_embeddings) - no-op unless the schema is partial.
29
+ -- The FK to wiki_page_index resolves lazily in SQLite, so this is safe even when
30
+ -- wiki_page_index itself is absent.
31
+ CREATE TABLE IF NOT EXISTS wiki_page_embeddings (
32
+ page_id TEXT PRIMARY KEY REFERENCES wiki_page_index(page_id) ON DELETE CASCADE,
33
+ embedding BLOB NOT NULL
34
+ );
35
+
36
+ INSERT OR IGNORE INTO embedding_meta (key, value)
37
+ SELECT 'embedding_prefix_scheme',
38
+ CASE
39
+ WHEN EXISTS (SELECT 1 FROM embeddings)
40
+ OR EXISTS (SELECT 1 FROM wiki_page_embeddings)
41
+ THEN 'legacy-unprefixed'
42
+ ELSE 'e5-prefixed-v1'
43
+ END;
44
+
45
+ INSERT OR IGNORE INTO schema_version (version, description)
46
+ VALUES (42, 'Track embedding prefix scheme (e5 query/passage)');
@@ -40,30 +40,43 @@ export declare class NodeSQLiteAdapter extends DatabaseAdapter {
40
40
  private _vectorSearchEnabled;
41
41
  private vectorCache;
42
42
  private topicCache;
43
+ private statusCache;
44
+ private decisionsHasStatusColumns;
45
+ private decisionsColumnInfoChecked;
43
46
  constructor(config?: SQLiteAdapterConfig);
44
47
  get vectorSearchEnabled(): boolean;
45
48
  getDbPath(): string;
46
49
  connect(): NodeSQLiteConnection;
47
50
  reloadVectorCache(): void;
51
+ refreshDecisionStatusCache(rowid: number): void;
52
+ private refreshDecisionColumnInfo;
48
53
  private loadVectorCache;
49
54
  disconnect(): void;
50
55
  isConnected(): boolean;
51
56
  prepare(sql: string): Statement;
52
57
  exec(sql: string): void;
53
58
  transaction<T>(fn: () => T): T;
54
- vectorSearch(embedding: Float32Array | number[], limit?: number, topicPrefix?: string): VectorSearchResult[] | null;
59
+ vectorSearch(embedding: Float32Array | number[], limit?: number, topicPrefix?: string, excludeStatuses?: readonly string[]): VectorSearchResult[] | null;
55
60
  insertEmbedding(rowid: number, embedding: Float32Array | number[]): RunResult | null;
56
61
  getLastInsertRowid(): number;
57
62
  runMigrations(migrationsDir: string): void;
58
63
  private repairSkippedFeatureMigrations;
59
64
  private applyRepairMigration;
65
+ private operatorMemoryCommitIntentTableSql;
66
+ private hasOperatorMemoryCommitIntentClaimInvariant;
67
+ private assertMigration040BaseComplete;
68
+ private assertMigration041Complete;
60
69
  private recoverMemoryProvenanceMigration032;
61
70
  private assertMigration032Complete;
62
71
  private recoverConnectorEventScopeMigration034;
63
72
  private assertMigration034Complete;
73
+ private recoverConnectorEventOperatorSeqMigration039;
74
+ private assertMigration039Complete;
64
75
  private tableColumns;
65
76
  private tableExists;
66
77
  private indexExists;
78
+ private triggerExists;
79
+ private schemaVersionExists;
67
80
  private migrateFromVssMemories;
68
81
  }
69
82
  export default NodeSQLiteAdapter;