@cleocode/core 2026.4.53 → 2026.4.55

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/internal.js CHANGED
@@ -11432,6 +11432,54 @@ function insertJournalEntry(nativeDb, hash2, createdAt, name2) {
11432
11432
  `INSERT OR IGNORE INTO "__drizzle_migrations" ("hash", "created_at", "name") VALUES ('${hash2}', ${createdAt}, '${name2}')`
11433
11433
  );
11434
11434
  }
11435
+ function probeAndMarkApplied(nativeDb, migration, logSubsystem) {
11436
+ const sqlStatements = Array.isArray(migration.sql) ? migration.sql : [migration.sql ?? ""];
11437
+ const fullSql = sqlStatements.join("\n");
11438
+ const alterColumnRegex = /ALTER\s+TABLE\s+[`"]?(\w+)[`"]?\s+ADD\s+COLUMN\s+[`"]?(\w+)[`"]?/gi;
11439
+ const createTableRegex = /CREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?[`"]?(\w+)[`"]?/gi;
11440
+ const createIndexRegex = /CREATE\s+(?:UNIQUE\s+)?INDEX\s+(?:IF\s+NOT\s+EXISTS\s+)?[`"]?(\w+)[`"]?/gi;
11441
+ const alterTargets = [];
11442
+ for (const m2 of fullSql.matchAll(alterColumnRegex)) {
11443
+ alterTargets.push({ table: m2[1], column: m2[2] });
11444
+ }
11445
+ const tableTargets = [];
11446
+ for (const m2 of fullSql.matchAll(createTableRegex)) {
11447
+ tableTargets.push(m2[1]);
11448
+ }
11449
+ const indexTargets = [];
11450
+ for (const m2 of fullSql.matchAll(createIndexRegex)) {
11451
+ indexTargets.push(m2[1]);
11452
+ }
11453
+ const totalTargets = alterTargets.length + tableTargets.length + indexTargets.length;
11454
+ if (totalTargets === 0) {
11455
+ return false;
11456
+ }
11457
+ const allAltersPresent = alterTargets.every(({ table, column }) => {
11458
+ if (!tableExists(nativeDb, table)) return false;
11459
+ const cols = nativeDb.prepare(`PRAGMA table_info(${table})`).all();
11460
+ return cols.some((c) => c.name === column);
11461
+ });
11462
+ const allTablesPresent = tableTargets.every((t) => tableExists(nativeDb, t));
11463
+ const allIndexesPresent = indexTargets.every((idx) => {
11464
+ const rows = nativeDb.prepare(`SELECT name FROM sqlite_master WHERE type='index' AND name=?`).all(idx);
11465
+ return rows.length > 0;
11466
+ });
11467
+ if (allAltersPresent && allTablesPresent && allIndexesPresent) {
11468
+ insertJournalEntry(nativeDb, migration.hash, migration.folderMillis, migration.name ?? "");
11469
+ const log12 = getLogger(logSubsystem);
11470
+ log12.debug(
11471
+ {
11472
+ migration: migration.name,
11473
+ alters: alterTargets.length,
11474
+ tables: tableTargets.length,
11475
+ indexes: indexTargets.length
11476
+ },
11477
+ `Migration ${migration.name} DDL already present in schema \u2014 marked applied.`
11478
+ );
11479
+ return true;
11480
+ }
11481
+ return false;
11482
+ }
11435
11483
  function reconcileJournal(nativeDb, migrationsFolder, existenceTable, logSubsystem) {
11436
11484
  if (tableExists(nativeDb, existenceTable) && !tableExists(nativeDb, "__drizzle_migrations")) {
11437
11485
  const migrations = readMigrationFiles({ migrationsFolder });
@@ -11468,11 +11516,11 @@ function reconcileJournal(nativeDb, migrationsFolder, existenceTable, logSubsyst
11468
11516
  const log12 = getLogger(logSubsystem);
11469
11517
  log12.warn(
11470
11518
  { orphaned: orphanedEntries.length },
11471
- `Detected stale migration journal entries from a previous CLEO version. Reconciling.`
11519
+ `Detected stale migration journal entries from a previous CLEO version. Reconciling via DDL probe.`
11472
11520
  );
11473
11521
  nativeDb.exec('DELETE FROM "__drizzle_migrations"');
11474
11522
  for (const m2 of localMigrations) {
11475
- insertJournalEntry(nativeDb, m2.hash, m2.folderMillis, m2.name ?? "");
11523
+ probeAndMarkApplied(nativeDb, m2, logSubsystem);
11476
11524
  }
11477
11525
  }
11478
11526
  }
@@ -14999,7 +15047,6 @@ function runBrainMigrations(nativeDb, db) {
14999
15047
  "brain"
15000
15048
  );
15001
15049
  }
15002
- ensureColumns(nativeDb, "brain_observations", [{ name: "agent", ddl: "text" }], "brain");
15003
15050
  if (tableExists(nativeDb, "brain_page_edges")) {
15004
15051
  nativeDb.prepare(
15005
15052
  `UPDATE brain_page_edges