@cleocode/core 2026.4.53 → 2026.4.54

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/dist/index.js CHANGED
@@ -11406,6 +11406,54 @@ function insertJournalEntry(nativeDb, hash2, createdAt, name2) {
11406
11406
  `INSERT OR IGNORE INTO "__drizzle_migrations" ("hash", "created_at", "name") VALUES ('${hash2}', ${createdAt}, '${name2}')`
11407
11407
  );
11408
11408
  }
11409
+ function probeAndMarkApplied(nativeDb, migration, logSubsystem) {
11410
+ const sqlStatements = Array.isArray(migration.sql) ? migration.sql : [migration.sql ?? ""];
11411
+ const fullSql = sqlStatements.join("\n");
11412
+ const alterColumnRegex = /ALTER\s+TABLE\s+[`"]?(\w+)[`"]?\s+ADD\s+COLUMN\s+[`"]?(\w+)[`"]?/gi;
11413
+ const createTableRegex = /CREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?[`"]?(\w+)[`"]?/gi;
11414
+ const createIndexRegex = /CREATE\s+(?:UNIQUE\s+)?INDEX\s+(?:IF\s+NOT\s+EXISTS\s+)?[`"]?(\w+)[`"]?/gi;
11415
+ const alterTargets = [];
11416
+ for (const m of fullSql.matchAll(alterColumnRegex)) {
11417
+ alterTargets.push({ table: m[1], column: m[2] });
11418
+ }
11419
+ const tableTargets = [];
11420
+ for (const m of fullSql.matchAll(createTableRegex)) {
11421
+ tableTargets.push(m[1]);
11422
+ }
11423
+ const indexTargets = [];
11424
+ for (const m of fullSql.matchAll(createIndexRegex)) {
11425
+ indexTargets.push(m[1]);
11426
+ }
11427
+ const totalTargets = alterTargets.length + tableTargets.length + indexTargets.length;
11428
+ if (totalTargets === 0) {
11429
+ return false;
11430
+ }
11431
+ const allAltersPresent = alterTargets.every(({ table, column }) => {
11432
+ if (!tableExists(nativeDb, table)) return false;
11433
+ const cols = nativeDb.prepare(`PRAGMA table_info(${table})`).all();
11434
+ return cols.some((c) => c.name === column);
11435
+ });
11436
+ const allTablesPresent = tableTargets.every((t) => tableExists(nativeDb, t));
11437
+ const allIndexesPresent = indexTargets.every((idx) => {
11438
+ const rows = nativeDb.prepare(`SELECT name FROM sqlite_master WHERE type='index' AND name=?`).all(idx);
11439
+ return rows.length > 0;
11440
+ });
11441
+ if (allAltersPresent && allTablesPresent && allIndexesPresent) {
11442
+ insertJournalEntry(nativeDb, migration.hash, migration.folderMillis, migration.name ?? "");
11443
+ const log11 = getLogger(logSubsystem);
11444
+ log11.debug(
11445
+ {
11446
+ migration: migration.name,
11447
+ alters: alterTargets.length,
11448
+ tables: tableTargets.length,
11449
+ indexes: indexTargets.length
11450
+ },
11451
+ `Migration ${migration.name} DDL already present in schema \u2014 marked applied.`
11452
+ );
11453
+ return true;
11454
+ }
11455
+ return false;
11456
+ }
11409
11457
  function reconcileJournal(nativeDb, migrationsFolder, existenceTable, logSubsystem) {
11410
11458
  if (tableExists(nativeDb, existenceTable) && !tableExists(nativeDb, "__drizzle_migrations")) {
11411
11459
  const migrations = readMigrationFiles({ migrationsFolder });
@@ -11442,11 +11490,11 @@ function reconcileJournal(nativeDb, migrationsFolder, existenceTable, logSubsyst
11442
11490
  const log11 = getLogger(logSubsystem);
11443
11491
  log11.warn(
11444
11492
  { orphaned: orphanedEntries.length },
11445
- `Detected stale migration journal entries from a previous CLEO version. Reconciling.`
11493
+ `Detected stale migration journal entries from a previous CLEO version. Reconciling via DDL probe.`
11446
11494
  );
11447
11495
  nativeDb.exec('DELETE FROM "__drizzle_migrations"');
11448
11496
  for (const m of localMigrations) {
11449
- insertJournalEntry(nativeDb, m.hash, m.folderMillis, m.name ?? "");
11497
+ probeAndMarkApplied(nativeDb, m, logSubsystem);
11450
11498
  }
11451
11499
  }
11452
11500
  }
@@ -14428,7 +14476,6 @@ function runBrainMigrations(nativeDb, db) {
14428
14476
  "brain"
14429
14477
  );
14430
14478
  }
14431
- ensureColumns(nativeDb, "brain_observations", [{ name: "agent", ddl: "text" }], "brain");
14432
14479
  if (tableExists(nativeDb, "brain_page_edges")) {
14433
14480
  nativeDb.prepare(
14434
14481
  `UPDATE brain_page_edges