@cleocode/core 2026.3.60 → 2026.3.61

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
@@ -11225,16 +11225,33 @@ function runMigrations(nativeDb, db) {
11225
11225
  );
11226
11226
  }
11227
11227
  }
11228
- let lastError;
11228
+ if (tableExists3(nativeDb, "__drizzle_migrations") && tableExists3(nativeDb, "tasks")) {
11229
+ const localMigrations = readMigrationFiles({ migrationsFolder });
11230
+ const localHashes = new Set(localMigrations.map((m) => m.hash));
11231
+ const dbEntries = nativeDb.prepare('SELECT hash FROM "__drizzle_migrations"').all();
11232
+ const hasOrphanedEntries = dbEntries.some((e) => !localHashes.has(e.hash));
11233
+ if (hasOrphanedEntries) {
11234
+ const log9 = getLogger("sqlite");
11235
+ log9.warn(
11236
+ { orphaned: dbEntries.filter((e) => !localHashes.has(e.hash)).length },
11237
+ "Detected stale migration journal entries from a previous CLEO version. Reconciling."
11238
+ );
11239
+ nativeDb.exec('DELETE FROM "__drizzle_migrations"');
11240
+ for (const m of localMigrations) {
11241
+ nativeDb.exec(
11242
+ `INSERT INTO "__drizzle_migrations" ("hash", "created_at") VALUES ('${m.hash}', ${m.folderMillis})`
11243
+ );
11244
+ }
11245
+ }
11246
+ }
11229
11247
  for (let attempt = 1; attempt <= MAX_MIGRATION_RETRIES; attempt++) {
11230
11248
  try {
11231
11249
  migrate(db, { migrationsFolder });
11232
- return;
11250
+ break;
11233
11251
  } catch (err) {
11234
11252
  if (!isSqliteBusy(err) || attempt === MAX_MIGRATION_RETRIES) {
11235
11253
  throw err;
11236
11254
  }
11237
- lastError = err;
11238
11255
  const delay = Math.min(
11239
11256
  MIGRATION_RETRY_BASE_DELAY_MS * 2 ** (attempt - 1) * (1 + Math.random() * 0.5),
11240
11257
  MIGRATION_RETRY_MAX_DELAY_MS
@@ -11242,7 +11259,19 @@ function runMigrations(nativeDb, db) {
11242
11259
  Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, Math.round(delay));
11243
11260
  }
11244
11261
  }
11245
- throw lastError;
11262
+ ensureRequiredColumns(nativeDb);
11263
+ }
11264
+ function ensureRequiredColumns(nativeDb) {
11265
+ if (!tableExists3(nativeDb, "tasks")) return;
11266
+ const columns = nativeDb.prepare("PRAGMA table_info(tasks)").all();
11267
+ const existingCols = new Set(columns.map((c) => c.name));
11268
+ for (const req of REQUIRED_TASK_COLUMNS) {
11269
+ if (!existingCols.has(req.name)) {
11270
+ const log9 = getLogger("sqlite");
11271
+ log9.warn({ column: req.name }, `Adding missing column tasks.${req.name} via ALTER TABLE`);
11272
+ nativeDb.exec(`ALTER TABLE tasks ADD COLUMN ${req.name} ${req.ddl}`);
11273
+ }
11274
+ }
11246
11275
  }
11247
11276
  function closeDb() {
11248
11277
  if (_nativeDb2) {
@@ -11299,7 +11328,7 @@ async function closeAllDatabases() {
11299
11328
  } catch {
11300
11329
  }
11301
11330
  }
11302
- var _require2, DatabaseSync2, DB_FILENAME3, SQLITE_SCHEMA_VERSION, SCHEMA_VERSION, _db2, _nativeDb2, _dbPath2, _initPromise2, _gitTrackingChecked, MIN_BACKUP_TASK_COUNT, MAX_MIGRATION_RETRIES, MIGRATION_RETRY_BASE_DELAY_MS, MIGRATION_RETRY_MAX_DELAY_MS;
11331
+ var _require2, DatabaseSync2, DB_FILENAME3, SQLITE_SCHEMA_VERSION, SCHEMA_VERSION, _db2, _nativeDb2, _dbPath2, _initPromise2, _gitTrackingChecked, MIN_BACKUP_TASK_COUNT, MAX_MIGRATION_RETRIES, MIGRATION_RETRY_BASE_DELAY_MS, MIGRATION_RETRY_MAX_DELAY_MS, REQUIRED_TASK_COLUMNS;
11303
11332
  var init_sqlite2 = __esm({
11304
11333
  "packages/core/src/store/sqlite.ts"() {
11305
11334
  "use strict";
@@ -11324,6 +11353,9 @@ var init_sqlite2 = __esm({
11324
11353
  MAX_MIGRATION_RETRIES = 5;
11325
11354
  MIGRATION_RETRY_BASE_DELAY_MS = 100;
11326
11355
  MIGRATION_RETRY_MAX_DELAY_MS = 2e3;
11356
+ REQUIRED_TASK_COLUMNS = [
11357
+ { name: "pipeline_stage", ddl: "text" }
11358
+ ];
11327
11359
  }
11328
11360
  });
11329
11361