@hasna/conversations 0.2.25 → 0.2.27

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/bin/hook.js CHANGED
@@ -9467,6 +9467,7 @@ function getDb() {
9467
9467
  db.exec(`
9468
9468
  CREATE TABLE IF NOT EXISTS messages (
9469
9469
  id INTEGER PRIMARY KEY AUTOINCREMENT,
9470
+ uuid TEXT NOT NULL DEFAULT (lower(hex(randomblob(16)))),
9470
9471
  session_id TEXT NOT NULL,
9471
9472
  from_agent TEXT NOT NULL,
9472
9473
  to_agent TEXT NOT NULL,
@@ -9633,6 +9634,11 @@ function getDb() {
9633
9634
  db.exec("ALTER TABLE messages ADD COLUMN project_id TEXT");
9634
9635
  db.exec("CREATE INDEX IF NOT EXISTS idx_messages_project ON messages(project_id)");
9635
9636
  }
9637
+ if (!colNames2.includes("uuid")) {
9638
+ db.exec("ALTER TABLE messages ADD COLUMN uuid TEXT");
9639
+ db.exec("UPDATE messages SET uuid = lower(hex(randomblob(16))) WHERE uuid IS NULL");
9640
+ db.exec("CREATE UNIQUE INDEX IF NOT EXISTS idx_messages_uuid ON messages(uuid)");
9641
+ }
9636
9642
  const presenceCols = db.prepare("PRAGMA table_info(agent_presence)").all();
9637
9643
  const presenceColNames = presenceCols.map((c) => c.name);
9638
9644
  if (!presenceColNames.includes("id")) {
@@ -10144,6 +10150,15 @@ function resolveIdentity(explicit) {
10144
10150
  }
10145
10151
 
10146
10152
  // src/hooks/blocker-hook.ts
10153
+ if (process.argv.includes("--help") || process.argv.includes("-h")) {
10154
+ console.log(`conversations-hook: Claude Code PreToolUse hook for blocking messages.
10155
+
10156
+ Usage: conversations-hook
10157
+
10158
+ Reads CONVERSATIONS_AGENT_ID or CLAUDE_AGENT_ID env var to identify the agent.
10159
+ Outputs blocking messages to stdout and exits 0.`);
10160
+ process.exit(0);
10161
+ }
10147
10162
  var agent = resolveIdentity();
10148
10163
  var db2 = getDb();
10149
10164
  var blockers = db2.prepare(`
package/bin/index.js CHANGED
@@ -13382,6 +13382,7 @@ function getDb() {
13382
13382
  db.exec(`
13383
13383
  CREATE TABLE IF NOT EXISTS messages (
13384
13384
  id INTEGER PRIMARY KEY AUTOINCREMENT,
13385
+ uuid TEXT NOT NULL DEFAULT (lower(hex(randomblob(16)))),
13385
13386
  session_id TEXT NOT NULL,
13386
13387
  from_agent TEXT NOT NULL,
13387
13388
  to_agent TEXT NOT NULL,
@@ -13548,6 +13549,11 @@ function getDb() {
13548
13549
  db.exec("ALTER TABLE messages ADD COLUMN project_id TEXT");
13549
13550
  db.exec("CREATE INDEX IF NOT EXISTS idx_messages_project ON messages(project_id)");
13550
13551
  }
13552
+ if (!colNames2.includes("uuid")) {
13553
+ db.exec("ALTER TABLE messages ADD COLUMN uuid TEXT");
13554
+ db.exec("UPDATE messages SET uuid = lower(hex(randomblob(16))) WHERE uuid IS NULL");
13555
+ db.exec("CREATE UNIQUE INDEX IF NOT EXISTS idx_messages_uuid ON messages(uuid)");
13556
+ }
13551
13557
  const presenceCols = db.prepare("PRAGMA table_info(agent_presence)").all();
13552
13558
  const presenceColNames = presenceCols.map((c) => c.name);
13553
13559
  if (!presenceColNames.includes("id")) {
@@ -14089,7 +14095,26 @@ function guessMimeType(name) {
14089
14095
  };
14090
14096
  return mimeMap[ext || ""] || "application/octet-stream";
14091
14097
  }
14098
+ function checkRateLimit(agentId) {
14099
+ const dbPath = process.env.CONVERSATIONS_DB_PATH ?? process.env.HASNA_CONVERSATIONS_DB_PATH ?? "";
14100
+ if (dbPath === ":memory:" || dbPath.includes("test") || dbPath.includes("tmp"))
14101
+ return;
14102
+ const now = Date.now();
14103
+ const entry = _rateLimitCounters.get(agentId);
14104
+ if (!entry || now - entry.windowStart > RATE_LIMIT_WINDOW_MS) {
14105
+ _rateLimitCounters.set(agentId, { count: 1, windowStart: now });
14106
+ return;
14107
+ }
14108
+ entry.count++;
14109
+ if (entry.count > RATE_LIMIT_MAX) {
14110
+ throw new Error(`Rate limit exceeded: ${agentId} may send at most ${RATE_LIMIT_MAX} messages per minute.`);
14111
+ }
14112
+ }
14092
14113
  function sendMessage(opts) {
14114
+ if (Buffer.byteLength(opts.content, "utf8") > MAX_MESSAGE_BYTES) {
14115
+ throw new Error(`Message content exceeds maximum size of ${MAX_MESSAGE_BYTES} bytes (64 KB).`);
14116
+ }
14117
+ checkRateLimit(opts.from);
14093
14118
  const db2 = getDb();
14094
14119
  const explicitSession = opts.session_id && opts.session_id.trim().length > 0 ? opts.session_id : undefined;
14095
14120
  const sessionId = explicitSession ?? (opts.space ? `space:${opts.space}` : `${[opts.from, opts.to].sort().join("-")}-${randomUUID().slice(0, 8)}`);
@@ -14617,9 +14642,11 @@ function getMessageReadStatus(messageId, space) {
14617
14642
  const unread_by = members.map((m) => m.agent).filter((a) => !readers.has(a));
14618
14643
  return { receipts, unread_by };
14619
14644
  }
14645
+ var MAX_MESSAGE_BYTES = 65536, RATE_LIMIT_MAX = 60, RATE_LIMIT_WINDOW_MS = 60000, _rateLimitCounters;
14620
14646
  var init_messages = __esm(() => {
14621
14647
  init_db();
14622
14648
  init_webhooks();
14649
+ _rateLimitCounters = new Map;
14623
14650
  });
14624
14651
 
14625
14652
  // src/lib/poll.ts
@@ -14900,7 +14927,7 @@ var init_presence = __esm(() => {
14900
14927
  var require_package = __commonJS((exports, module) => {
14901
14928
  module.exports = {
14902
14929
  name: "@hasna/conversations",
14903
- version: "0.2.25",
14930
+ version: "0.2.27",
14904
14931
  description: "Real-time CLI messaging for AI agents",
14905
14932
  type: "module",
14906
14933
  bin: {
@@ -14929,7 +14956,7 @@ var require_package = __commonJS((exports, module) => {
14929
14956
  test: "bun test",
14930
14957
  dev: "bun run ./src/cli/index.tsx",
14931
14958
  typecheck: "tsc --noEmit",
14932
- prepublishOnly: "bun run build",
14959
+ prepublishOnly: "bun run build:dashboard && bun run build",
14933
14960
  postinstall: "mkdir -p $HOME/.hasna/conversations $HOME/.hasna/conversations/training 2>/dev/null || true"
14934
14961
  },
14935
14962
  keywords: [
@@ -46272,6 +46299,187 @@ var init_advanced = __esm(() => {
46272
46299
  init_graph();
46273
46300
  });
46274
46301
 
46302
+ // src/lib/pg-migrations.ts
46303
+ var exports_pg_migrations = {};
46304
+ __export(exports_pg_migrations, {
46305
+ PG_MIGRATIONS: () => PG_MIGRATIONS
46306
+ });
46307
+ var PG_MIGRATIONS;
46308
+ var init_pg_migrations = __esm(() => {
46309
+ PG_MIGRATIONS = [
46310
+ `
46311
+ CREATE TABLE IF NOT EXISTS projects (
46312
+ id TEXT PRIMARY KEY,
46313
+ name TEXT NOT NULL UNIQUE,
46314
+ description TEXT,
46315
+ path TEXT,
46316
+ created_by TEXT NOT NULL,
46317
+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
46318
+ metadata TEXT,
46319
+ tags TEXT,
46320
+ status TEXT NOT NULL DEFAULT 'active',
46321
+ repository TEXT,
46322
+ settings TEXT
46323
+ );
46324
+ CREATE INDEX IF NOT EXISTS idx_projects_name ON projects(name);
46325
+ CREATE INDEX IF NOT EXISTS idx_projects_status ON projects(status);
46326
+
46327
+ CREATE TABLE IF NOT EXISTS spaces (
46328
+ name TEXT PRIMARY KEY,
46329
+ description TEXT,
46330
+ parent_id TEXT REFERENCES spaces(name),
46331
+ project_id TEXT REFERENCES projects(id),
46332
+ created_by TEXT NOT NULL,
46333
+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
46334
+ archived_at TEXT,
46335
+ topic TEXT
46336
+ );
46337
+ CREATE INDEX IF NOT EXISTS idx_spaces_parent ON spaces(parent_id);
46338
+ CREATE INDEX IF NOT EXISTS idx_spaces_project ON spaces(project_id);
46339
+
46340
+ CREATE TABLE IF NOT EXISTS space_members (
46341
+ space TEXT NOT NULL REFERENCES spaces(name),
46342
+ agent TEXT NOT NULL,
46343
+ joined_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
46344
+ PRIMARY KEY (space, agent)
46345
+ );
46346
+
46347
+ CREATE TABLE IF NOT EXISTS messages (
46348
+ id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
46349
+ uuid TEXT NOT NULL DEFAULT gen_random_uuid()::text UNIQUE,
46350
+ session_id TEXT NOT NULL,
46351
+ from_agent TEXT NOT NULL,
46352
+ to_agent TEXT NOT NULL,
46353
+ space TEXT,
46354
+ project_id TEXT,
46355
+ content TEXT NOT NULL,
46356
+ priority TEXT NOT NULL DEFAULT 'normal',
46357
+ working_dir TEXT,
46358
+ repository TEXT,
46359
+ branch TEXT,
46360
+ metadata TEXT,
46361
+ edited_at TEXT,
46362
+ pinned_at TEXT,
46363
+ blocking BOOLEAN NOT NULL DEFAULT FALSE,
46364
+ attachments TEXT,
46365
+ reply_to BIGINT,
46366
+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
46367
+ read_at TEXT
46368
+ );
46369
+ CREATE INDEX IF NOT EXISTS idx_messages_session ON messages(session_id);
46370
+ CREATE INDEX IF NOT EXISTS idx_messages_to ON messages(to_agent);
46371
+ CREATE INDEX IF NOT EXISTS idx_messages_created ON messages(created_at);
46372
+ CREATE INDEX IF NOT EXISTS idx_messages_space ON messages(space);
46373
+ CREATE INDEX IF NOT EXISTS idx_messages_pinned ON messages(pinned_at);
46374
+ CREATE INDEX IF NOT EXISTS idx_messages_blocking ON messages(blocking);
46375
+ CREATE INDEX IF NOT EXISTS idx_messages_reply_to ON messages(reply_to);
46376
+ CREATE INDEX IF NOT EXISTS idx_messages_project ON messages(project_id);
46377
+
46378
+ CREATE TABLE IF NOT EXISTS agent_presence (
46379
+ id TEXT NOT NULL DEFAULT '',
46380
+ agent TEXT PRIMARY KEY,
46381
+ session_id TEXT,
46382
+ role TEXT NOT NULL DEFAULT 'agent',
46383
+ project_id TEXT,
46384
+ status TEXT NOT NULL DEFAULT 'online',
46385
+ last_seen_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
46386
+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
46387
+ metadata TEXT
46388
+ );
46389
+
46390
+ CREATE TABLE IF NOT EXISTS resource_locks (
46391
+ resource_type TEXT NOT NULL,
46392
+ resource_id TEXT NOT NULL,
46393
+ agent_id TEXT NOT NULL,
46394
+ lock_type TEXT NOT NULL DEFAULT 'advisory',
46395
+ locked_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
46396
+ expires_at TIMESTAMPTZ NOT NULL,
46397
+ UNIQUE(resource_type, resource_id, lock_type)
46398
+ );
46399
+ CREATE INDEX IF NOT EXISTS idx_locks_resource ON resource_locks(resource_type, resource_id);
46400
+ CREATE INDEX IF NOT EXISTS idx_locks_agent ON resource_locks(agent_id);
46401
+ CREATE INDEX IF NOT EXISTS idx_locks_expires ON resource_locks(expires_at);
46402
+
46403
+ CREATE TABLE IF NOT EXISTS reactions (
46404
+ id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
46405
+ message_id BIGINT NOT NULL REFERENCES messages(id) ON DELETE CASCADE,
46406
+ agent TEXT NOT NULL,
46407
+ emoji TEXT NOT NULL,
46408
+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
46409
+ UNIQUE(message_id, agent, emoji)
46410
+ );
46411
+ CREATE INDEX IF NOT EXISTS idx_reactions_message ON reactions(message_id);
46412
+
46413
+ CREATE TABLE IF NOT EXISTS message_read_receipts (
46414
+ message_id BIGINT NOT NULL REFERENCES messages(id) ON DELETE CASCADE,
46415
+ agent TEXT NOT NULL,
46416
+ read_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
46417
+ PRIMARY KEY (message_id, agent)
46418
+ );
46419
+ CREATE INDEX IF NOT EXISTS idx_read_receipts_message ON message_read_receipts(message_id);
46420
+ CREATE INDEX IF NOT EXISTS idx_read_receipts_agent ON message_read_receipts(agent);
46421
+
46422
+ CREATE TABLE IF NOT EXISTS message_mentions (
46423
+ id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
46424
+ message_id BIGINT NOT NULL REFERENCES messages(id) ON DELETE CASCADE,
46425
+ mentioned_agent TEXT NOT NULL,
46426
+ from_agent TEXT NOT NULL,
46427
+ space TEXT,
46428
+ notified_at TEXT,
46429
+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
46430
+ );
46431
+ CREATE INDEX IF NOT EXISTS idx_mentions_agent ON message_mentions(mentioned_agent);
46432
+ CREATE INDEX IF NOT EXISTS idx_mentions_message ON message_mentions(message_id);
46433
+ CREATE INDEX IF NOT EXISTS idx_mentions_notified ON message_mentions(notified_at);
46434
+
46435
+ -- Full-text search using PostgreSQL tsvector
46436
+ ALTER TABLE messages ADD COLUMN IF NOT EXISTS search_vector tsvector;
46437
+ CREATE INDEX IF NOT EXISTS idx_messages_search ON messages USING GIN(search_vector);
46438
+
46439
+ CREATE OR REPLACE FUNCTION messages_search_vector_update() RETURNS trigger AS $$
46440
+ BEGIN
46441
+ NEW.search_vector :=
46442
+ setweight(to_tsvector('english', COALESCE(NEW.content, '')), 'A') ||
46443
+ setweight(to_tsvector('english', COALESCE(NEW.from_agent, '')), 'B') ||
46444
+ setweight(to_tsvector('english', COALESCE(NEW.to_agent, '')), 'B') ||
46445
+ setweight(to_tsvector('english', COALESCE(NEW.space, '')), 'C');
46446
+ RETURN NEW;
46447
+ END;
46448
+ $$ LANGUAGE plpgsql;
46449
+
46450
+ DROP TRIGGER IF EXISTS messages_search_vector_trigger ON messages;
46451
+ CREATE TRIGGER messages_search_vector_trigger
46452
+ BEFORE INSERT OR UPDATE OF content, from_agent, to_agent, space ON messages
46453
+ FOR EACH ROW EXECUTE FUNCTION messages_search_vector_update();
46454
+
46455
+ -- Backfill existing rows
46456
+ UPDATE messages SET search_vector =
46457
+ setweight(to_tsvector('english', COALESCE(content, '')), 'A') ||
46458
+ setweight(to_tsvector('english', COALESCE(from_agent, '')), 'B') ||
46459
+ setweight(to_tsvector('english', COALESCE(to_agent, '')), 'B') ||
46460
+ setweight(to_tsvector('english', COALESCE(space, '')), 'C')
46461
+ WHERE search_vector IS NULL;
46462
+
46463
+ -- Feedback table
46464
+ CREATE TABLE IF NOT EXISTS feedback (
46465
+ id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
46466
+ message TEXT NOT NULL,
46467
+ email TEXT,
46468
+ category TEXT DEFAULT 'general',
46469
+ version TEXT,
46470
+ machine_id TEXT,
46471
+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
46472
+ );
46473
+
46474
+ CREATE TABLE IF NOT EXISTS _migrations (
46475
+ id INTEGER PRIMARY KEY,
46476
+ applied_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
46477
+ );
46478
+ INSERT INTO _migrations (id) VALUES (1) ON CONFLICT DO NOTHING;
46479
+ `
46480
+ ];
46481
+ });
46482
+
46275
46483
  // src/mcp/tools/cloud.ts
46276
46484
  async function detectAndLogConflicts(local, cloud, table) {
46277
46485
  if (!CONFLICT_TABLES.has(table))
@@ -46355,7 +46563,7 @@ function registerCloudSyncTools(server) {
46355
46563
  const localPath = cloudGetDbPath("conversations");
46356
46564
  const local = new SqliteAdapter2(localPath);
46357
46565
  const cloud = new PgAdapterAsync2(getConnectionString2("conversations"));
46358
- const tableList = tablesStr ? tablesStr.split(",").map((t) => t.trim()) : listSqliteTables2(local).filter((t) => !t.startsWith("_") && !t.endsWith("_fts") && !t.startsWith("messages_fts"));
46566
+ const tableList = tablesStr ? tablesStr.split(",").map((t) => t.trim()) : listSqliteTables2(local).filter((t) => !SYNC_EXCLUDED.has(t));
46359
46567
  let totalConflicts = 0;
46360
46568
  for (const table of tableList) {
46361
46569
  totalConflicts += await detectAndLogConflicts(local, cloud, table);
@@ -46400,7 +46608,7 @@ function registerCloudSyncTools(server) {
46400
46608
  tableList = tablesStr.split(",").map((t) => t.trim());
46401
46609
  } else {
46402
46610
  try {
46403
- tableList = (await listPgTables2(cloud)).filter((t) => !t.startsWith("_"));
46611
+ tableList = (await listPgTables2(cloud)).filter((t) => !SYNC_EXCLUDED.has(t));
46404
46612
  } catch {
46405
46613
  local.close();
46406
46614
  await cloud.close();
@@ -46422,6 +46630,100 @@ function registerCloudSyncTools(server) {
46422
46630
  if (errors4.length > 0)
46423
46631
  lines.push(`Errors: ${errors4.join("; ")}`);
46424
46632
  return { content: [{ type: "text", text: lines.join(`
46633
+ `) }] };
46634
+ } catch (e) {
46635
+ return { content: [{ type: "text", text: formatError2(e) }], isError: true };
46636
+ }
46637
+ });
46638
+ server.tool("conversations_cloud_sync", "Bidirectional cloud sync \u2014 pull remote changes then push local changes. Detects and logs conflicts.", {
46639
+ tables: exports_external2.string().optional().describe("Comma-separated table names (default: all syncable tables)")
46640
+ }, async ({ tables: tablesStr }) => {
46641
+ try {
46642
+ const {
46643
+ getCloudConfig: getCloudConfig2,
46644
+ getConnectionString: getConnectionString2,
46645
+ syncPush: syncPush2,
46646
+ syncPull: syncPull2,
46647
+ listSqliteTables: listSqliteTables2,
46648
+ listPgTables: listPgTables2,
46649
+ SqliteAdapter: SqliteAdapter2,
46650
+ PgAdapterAsync: PgAdapterAsync2,
46651
+ getDbPath: cloudGetDbPath
46652
+ } = await Promise.resolve().then(() => (init_dist(), exports_dist));
46653
+ const config2 = getCloudConfig2();
46654
+ if (config2.mode === "local") {
46655
+ return { content: [{ type: "text", text: "Error: cloud mode not configured." }], isError: true };
46656
+ }
46657
+ const local = new SqliteAdapter2(cloudGetDbPath("conversations"));
46658
+ const cloud = new PgAdapterAsync2(getConnectionString2("conversations"));
46659
+ let tableList;
46660
+ if (tablesStr) {
46661
+ tableList = tablesStr.split(",").map((t) => t.trim());
46662
+ } else {
46663
+ const localTables = new Set(listSqliteTables2(local).filter((t) => !SYNC_EXCLUDED.has(t)));
46664
+ let remoteTables;
46665
+ try {
46666
+ remoteTables = new Set((await listPgTables2(cloud)).filter((t) => !SYNC_EXCLUDED.has(t)));
46667
+ } catch {
46668
+ local.close();
46669
+ await cloud.close();
46670
+ return { content: [{ type: "text", text: "Error: failed to list cloud tables." }], isError: true };
46671
+ }
46672
+ tableList = [...new Set([...localTables, ...remoteTables])];
46673
+ }
46674
+ let totalConflicts = 0;
46675
+ for (const table of tableList) {
46676
+ totalConflicts += await detectAndLogConflicts(local, cloud, table);
46677
+ }
46678
+ const pullResults = await syncPull2(cloud, local, { tables: tableList });
46679
+ const pullTotal = pullResults.reduce((s, r) => s + r.rowsWritten, 0);
46680
+ const pushResults = await syncPush2(local, cloud, { tables: tableList });
46681
+ const pushTotal = pushResults.reduce((s, r) => s + r.rowsWritten, 0);
46682
+ local.close();
46683
+ await cloud.close();
46684
+ const allErrors = [
46685
+ ...pullResults.flatMap((r) => r.errors.map((e) => `pull: ${e}`)),
46686
+ ...pushResults.flatMap((r) => r.errors.map((e) => `push: ${e}`))
46687
+ ];
46688
+ const lines = [
46689
+ `Sync complete: pulled ${pullTotal} rows, pushed ${pushTotal} rows across ${tableList.length} table(s).`
46690
+ ];
46691
+ if (totalConflicts > 0)
46692
+ lines.push(`Conflicts detected: ${totalConflicts} (logged to _sync_conflicts)`);
46693
+ if (allErrors.length > 0)
46694
+ lines.push(`Errors: ${allErrors.join("; ")}`);
46695
+ return { content: [{ type: "text", text: lines.join(`
46696
+ `) }] };
46697
+ } catch (e) {
46698
+ return { content: [{ type: "text", text: formatError2(e) }], isError: true };
46699
+ }
46700
+ });
46701
+ server.tool("conversations_cloud_migrate", "Run PostgreSQL migrations against the configured RDS instance to initialize the cloud schema", {
46702
+ dry_run: exports_external2.boolean().optional().describe("Print SQL without executing")
46703
+ }, async ({ dry_run }) => {
46704
+ try {
46705
+ const { getCloudConfig: getCloudConfig2, getConnectionString: getConnectionString2, PgAdapterAsync: PgAdapterAsync2 } = await Promise.resolve().then(() => (init_dist(), exports_dist));
46706
+ const { PG_MIGRATIONS: PG_MIGRATIONS2 } = await Promise.resolve().then(() => (init_pg_migrations(), exports_pg_migrations));
46707
+ const config2 = getCloudConfig2();
46708
+ if (config2.mode === "local") {
46709
+ return { content: [{ type: "text", text: "Error: cloud mode not configured." }], isError: true };
46710
+ }
46711
+ if (dry_run) {
46712
+ return { content: [{ type: "text", text: PG_MIGRATIONS2.join(`
46713
+
46714
+ ---
46715
+
46716
+ `) }] };
46717
+ }
46718
+ const pg = new PgAdapterAsync2(getConnectionString2("conversations"));
46719
+ const lines = [];
46720
+ for (let i = 0;i < PG_MIGRATIONS2.length; i++) {
46721
+ await pg.run(PG_MIGRATIONS2[i]);
46722
+ lines.push(`Migration ${i + 1}/${PG_MIGRATIONS2.length}: applied`);
46723
+ }
46724
+ await pg.close();
46725
+ lines.push("All migrations applied successfully.");
46726
+ return { content: [{ type: "text", text: lines.join(`
46425
46727
  `) }] };
46426
46728
  } catch (e) {
46427
46729
  return { content: [{ type: "text", text: formatError2(e) }], isError: true };
@@ -46452,10 +46754,19 @@ function formatError2(e) {
46452
46754
  return e.message;
46453
46755
  return String(e);
46454
46756
  }
46455
- var CONFLICT_TABLES;
46757
+ var SYNC_EXCLUDED, CONFLICT_TABLES;
46456
46758
  var init_cloud = __esm(() => {
46457
46759
  init_zod2();
46458
- CONFLICT_TABLES = new Set(["messages", "spaces", "projects", "agent_presence"]);
46760
+ SYNC_EXCLUDED = new Set([
46761
+ "messages",
46762
+ "reactions",
46763
+ "message_read_receipts",
46764
+ "message_mentions",
46765
+ "messages_fts",
46766
+ "_sync_conflicts",
46767
+ "_migrations"
46768
+ ]);
46769
+ CONFLICT_TABLES = new Set(["spaces", "projects", "agent_presence"]);
46459
46770
  });
46460
46771
 
46461
46772
  // src/mcp/index.ts
@@ -49719,6 +50030,40 @@ program2.command("dashboard").description("Start web dashboard").option("--port
49719
50030
  });
49720
50031
  registerBrainsCommand(program2);
49721
50032
  registerCloudCommands(program2, "conversations");
50033
+ {
50034
+ const cloudCmd = program2.commands.find((c) => c.name() === "cloud");
50035
+ if (cloudCmd) {
50036
+ cloudCmd.command("migrate").description("Run PostgreSQL migrations against the configured RDS instance").option("--dry-run", "Print SQL without executing").action(async (opts) => {
50037
+ try {
50038
+ const { getCloudConfig: getCloudConfig2, getConnectionString: getConnectionString2, PgAdapterAsync: PgAdapterAsync2 } = await Promise.resolve().then(() => (init_dist(), exports_dist));
50039
+ const { PG_MIGRATIONS: PG_MIGRATIONS2 } = await Promise.resolve().then(() => (init_pg_migrations(), exports_pg_migrations));
50040
+ const config2 = getCloudConfig2();
50041
+ if (config2.mode === "local") {
50042
+ console.error(chalk9.red("Error: cloud mode not configured. Set RDS credentials first."));
50043
+ process.exit(1);
50044
+ }
50045
+ if (opts.dryRun) {
50046
+ console.log(chalk9.dim(`-- Dry run: SQL that would be executed --
50047
+ `));
50048
+ for (const sql of PG_MIGRATIONS2)
50049
+ console.log(sql);
50050
+ return;
50051
+ }
50052
+ const pg = new PgAdapterAsync2(getConnectionString2("conversations"));
50053
+ for (let i = 0;i < PG_MIGRATIONS2.length; i++) {
50054
+ process.stdout.write(chalk9.dim(`Running migration ${i + 1}/${PG_MIGRATIONS2.length}...`));
50055
+ await pg.run(PG_MIGRATIONS2[i]);
50056
+ console.log(chalk9.green(" done"));
50057
+ }
50058
+ await pg.close();
50059
+ console.log(chalk9.green("\u2713 All migrations applied."));
50060
+ } catch (e) {
50061
+ console.error(chalk9.red(`Migration failed: ${e?.message ?? e}`));
50062
+ process.exit(1);
50063
+ }
50064
+ });
50065
+ }
50066
+ }
49722
50067
  program2.action(() => {
49723
50068
  if (!process.stdin.isTTY) {
49724
50069
  console.error(chalk9.red("Interactive mode requires a TTY terminal."));