@cleocode/core 2026.6.9 → 2026.6.11

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.
@@ -14555,7 +14555,7 @@ var init_sql = __esm({
14555
14555
  return new SQL([new StringChunk(str)]);
14556
14556
  }
14557
14557
  _sql.raw = raw;
14558
- function join22(chunks, separator) {
14558
+ function join23(chunks, separator) {
14559
14559
  const result = [];
14560
14560
  for (const [i, chunk] of chunks.entries()) {
14561
14561
  if (i > 0 && separator !== void 0) result.push(separator);
@@ -14563,7 +14563,7 @@ var init_sql = __esm({
14563
14563
  }
14564
14564
  return new SQL(result);
14565
14565
  }
14566
- _sql.join = join22;
14566
+ _sql.join = join23;
14567
14567
  function identifier(value) {
14568
14568
  return new Name(value);
14569
14569
  }
@@ -16950,7 +16950,7 @@ var init_select2 = __esm({
16950
16950
  const baseTableName = this.tableName;
16951
16951
  const tableName = getTableLikeName(table);
16952
16952
  for (const item of extractUsedTable(table)) this.usedTables.add(item);
16953
- if (typeof tableName === "string" && this.config.joins?.some((join22) => join22.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
16953
+ if (typeof tableName === "string" && this.config.joins?.some((join23) => join23.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
16954
16954
  if (!this.isPartialSelect) {
16955
16955
  if (Object.keys(this.joinsNotNullableMap).length === 1 && typeof baseTableName === "string") this.config.fields = { [baseTableName]: this.config.fields };
16956
16956
  if (typeof tableName === "string" && !is(table, SQL)) {
@@ -20760,7 +20760,7 @@ var init_dialect = __esm({
20760
20760
  if (!joins2) return;
20761
20761
  const withEntries = Object.entries(joins2).filter(([_, v]) => v);
20762
20762
  if (!withEntries.length) return;
20763
- return sql.join(withEntries.map(([k, join22]) => {
20763
+ return sql.join(withEntries.map(([k, join23]) => {
20764
20764
  const relation = tableConfig.relations[k];
20765
20765
  const isSingle2 = is(relation, One);
20766
20766
  const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
@@ -20771,7 +20771,7 @@ var init_dialect = __esm({
20771
20771
  table: targetTable,
20772
20772
  mode: isSingle2 ? "first" : "many",
20773
20773
  schema,
20774
- queryConfig: join22,
20774
+ queryConfig: join23,
20775
20775
  tableConfig: schema[relation.targetTableName],
20776
20776
  relationWhere: filter,
20777
20777
  isNested: true,
@@ -20785,7 +20785,7 @@ var init_dialect = __esm({
20785
20785
  key: k,
20786
20786
  selection: innerQuery.selection,
20787
20787
  isArray: !isSingle2,
20788
- isOptional: (relation.optional ?? false) || join22 !== true && !!join22.where
20788
+ isOptional: (relation.optional ?? false) || join23 !== true && !!join23.where
20789
20789
  });
20790
20790
  const jsonColumns = sql.join(innerQuery.selection.map((s) => {
20791
20791
  return sql`${sql.raw(this.escapeString(s.key))}, ${s.selection ? sql`${jsonb3}(${sql.identifier(s.key)})` : sql.identifier(s.key)}`;
@@ -21606,7 +21606,7 @@ var init_update = __esm({
21606
21606
  createJoin(joinType) {
21607
21607
  return ((table, on) => {
21608
21608
  const tableName = getTableLikeName(table);
21609
- if (typeof tableName === "string" && this.config.joins.some((join22) => join22.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
21609
+ if (typeof tableName === "string" && this.config.joins.some((join23) => join23.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
21610
21610
  if (typeof on === "function") {
21611
21611
  const from = this.config.from ? is(table, SQLiteTable) ? table[Table.Symbol.Columns] : is(table, Subquery) ? table._.selectedFields : is(table, SQLiteViewBase) ? table[ViewBaseConfig].selectedFields : void 0 : void 0;
21612
21612
  on = on(new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
@@ -22596,6 +22596,66 @@ var init_with_retry = __esm({
22596
22596
 
22597
22597
  // packages/core/src/store/migration-manager.ts
22598
22598
  import { copyFileSync, existsSync as existsSync2 } from "node:fs";
22599
+ import { dirname, join as join3 } from "node:path";
22600
+ function stripSqlComments(sql39) {
22601
+ return sql39.replace(/--[^\n]*/g, "").replace(/\/\*[\s\S]*?\*\//g, "");
22602
+ }
22603
+ function computeEliminatedTables(migrations) {
22604
+ const createTableRegex = /CREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?[`"]?(\w+)[`"]?/i;
22605
+ const dropTableRegex = /DROP\s+TABLE\s+(?:IF\s+EXISTS\s+)?[`"]?(\w+)[`"]?/i;
22606
+ const renameRegex = /ALTER\s+TABLE\s+[`"]?(\w+)[`"]?\s+RENAME\s+TO\s+[`"]?(\w+)[`"]?/i;
22607
+ const disposition = /* @__PURE__ */ new Map();
22608
+ const ordered = [...migrations].sort((a, b) => a.folderMillis - b.folderMillis);
22609
+ for (const migration of ordered) {
22610
+ const statements = Array.isArray(migration.sql) ? migration.sql : [migration.sql ?? ""];
22611
+ for (const rawStatement of statements) {
22612
+ const stripped = stripSqlComments(rawStatement);
22613
+ for (const clause of stripped.split(";")) {
22614
+ const create = createTableRegex.exec(clause);
22615
+ if (create) {
22616
+ disposition.set(create[1], true);
22617
+ continue;
22618
+ }
22619
+ const rename2 = renameRegex.exec(clause);
22620
+ if (rename2) {
22621
+ disposition.set(rename2[2], true);
22622
+ continue;
22623
+ }
22624
+ const drop = dropTableRegex.exec(clause);
22625
+ if (drop) {
22626
+ disposition.set(drop[1], false);
22627
+ }
22628
+ }
22629
+ }
22630
+ }
22631
+ const eliminated = /* @__PURE__ */ new Set();
22632
+ for (const [table, present] of disposition) {
22633
+ if (!present) eliminated.add(table);
22634
+ }
22635
+ return eliminated;
22636
+ }
22637
+ function resolveConsolidationCutoverPrefix(migrationsFolder) {
22638
+ const parent = dirname(migrationsFolder);
22639
+ for (const setName of ["drizzle-cleo-project", "drizzle-cleo-global"]) {
22640
+ const folder = join3(parent, setName);
22641
+ if (!existsSync2(folder)) continue;
22642
+ try {
22643
+ const consolidation = readMigrationFiles({ migrationsFolder: folder }).find(
22644
+ (m) => /-consolidation-cleo-/.test(m.name ?? "")
22645
+ );
22646
+ if (consolidation?.name) {
22647
+ return consolidation.name.slice(0, MIGRATION_TIMESTAMP_PREFIX_LEN);
22648
+ }
22649
+ } catch {
22650
+ }
22651
+ }
22652
+ return CONSOLIDATION_CUTOVER_PREFIX;
22653
+ }
22654
+ function isAtOrBeforeCutover(migrationName, cutoverPrefix) {
22655
+ const prefix = (migrationName ?? "").slice(0, MIGRATION_TIMESTAMP_PREFIX_LEN);
22656
+ if (prefix.length < MIGRATION_TIMESTAMP_PREFIX_LEN) return true;
22657
+ return prefix <= cutoverPrefix;
22658
+ }
22599
22659
  function tableExists(nativeDb, tableName) {
22600
22660
  const result = nativeDb.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name=?").get(tableName);
22601
22661
  return !!result;
@@ -22622,9 +22682,9 @@ function insertJournalEntry(nativeDb, hash, createdAt, name2) {
22622
22682
  `INSERT OR IGNORE INTO "__drizzle_migrations" ("hash", "created_at", "name") VALUES ('${hash}', ${createdAt}, '${name2}')`
22623
22683
  );
22624
22684
  }
22625
- function probeAndMarkApplied(nativeDb, migration, logSubsystem) {
22685
+ function probeAndMarkApplied(nativeDb, migration, logSubsystem, eliminatedTables = /* @__PURE__ */ new Set(), consolidationCutoverPrefix = CONSOLIDATION_CUTOVER_PREFIX) {
22626
22686
  const sqlStatements = Array.isArray(migration.sql) ? migration.sql : [migration.sql ?? ""];
22627
- const fullSql = sqlStatements.join("\n");
22687
+ const fullSql = stripSqlComments(sqlStatements.join("\n"));
22628
22688
  const alterColumnRegex = /ALTER\s+TABLE\s+[`"]?(\w+)[`"]?\s+ADD\s+COLUMN\s+[`"]?(\w+)[`"]?/gi;
22629
22689
  const createTableRegex = /CREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?[`"]?(\w+)[`"]?/gi;
22630
22690
  const createIndexRegex = /CREATE\s+(?:UNIQUE\s+)?INDEX\s+(?:IF\s+NOT\s+EXISTS\s+)?[`"]?(\w+)[`"]?/gi;
@@ -22651,10 +22711,17 @@ function probeAndMarkApplied(nativeDb, migration, logSubsystem) {
22651
22711
  }
22652
22712
  const isRebuildOnlyMigration = allCreatedTablesAreRenamed && tableTargets.length > 0 && alterTargets.length === 0;
22653
22713
  const performsTableRebuild = renameMap.size > 0;
22714
+ const createIndexWithTableRegex = /CREATE\s+(?:UNIQUE\s+)?INDEX\s+(?:IF\s+NOT\s+EXISTS\s+)?[`"]?(\w+)[`"]?\s+ON\s+[`"]?(\w+)[`"]?/gi;
22715
+ const indexOnTable = /* @__PURE__ */ new Map();
22716
+ for (const m of fullSql.matchAll(createIndexWithTableRegex)) {
22717
+ indexOnTable.set(m[1], m[2]);
22718
+ }
22654
22719
  const indexTargets = [];
22655
22720
  if (!isRebuildOnlyMigration && !performsTableRebuild) {
22656
22721
  for (const m of fullSql.matchAll(createIndexRegex)) {
22657
- indexTargets.push(m[1]);
22722
+ const idx = m[1];
22723
+ if (eliminatedTables.has(indexOnTable.get(idx) ?? "")) continue;
22724
+ indexTargets.push(idx);
22658
22725
  }
22659
22726
  }
22660
22727
  const triggerTargets = [];
@@ -22663,6 +22730,14 @@ function probeAndMarkApplied(nativeDb, migration, logSubsystem) {
22663
22730
  }
22664
22731
  const totalTargets = alterTargets.length + tableTargets.length + indexTargets.length + triggerTargets.length;
22665
22732
  if (totalTargets === 0) {
22733
+ if (isAtOrBeforeCutover(migration.name, consolidationCutoverPrefix)) {
22734
+ insertJournalEntry(nativeDb, migration.hash, migration.folderMillis, migration.name ?? "");
22735
+ getLogger(logSubsystem).debug(
22736
+ { migration: migration.name },
22737
+ `Zero-DDL pre-consolidation migration ${migration.name} stamped applied (subsumed; not re-run).`
22738
+ );
22739
+ return true;
22740
+ }
22666
22741
  return false;
22667
22742
  }
22668
22743
  const allAltersPresent = alterTargets.every(({ table, column }) => {
@@ -22670,7 +22745,9 @@ function probeAndMarkApplied(nativeDb, migration, logSubsystem) {
22670
22745
  const cols = nativeDb.prepare(`PRAGMA table_info(${table})`).all();
22671
22746
  return cols.some((c) => c.name === column);
22672
22747
  });
22673
- const allTablesPresent = tableTargets.every((t) => tableExists(nativeDb, t));
22748
+ const allTablesPresent = tableTargets.every(
22749
+ (t) => tableExists(nativeDb, t) || eliminatedTables.has(t)
22750
+ );
22674
22751
  const allIndexesPresent = indexTargets.every((idx) => {
22675
22752
  const rows = nativeDb.prepare(`SELECT name FROM sqlite_master WHERE type='index' AND name=?`).all(idx);
22676
22753
  return rows.length > 0;
@@ -22696,7 +22773,28 @@ function probeAndMarkApplied(nativeDb, migration, logSubsystem) {
22696
22773
  }
22697
22774
  return false;
22698
22775
  }
22699
- function reconcileJournal(nativeDb, migrationsFolder, existenceTable2, logSubsystem) {
22776
+ function readSiblingMigrationHashes(siblingFolder) {
22777
+ try {
22778
+ return new Set(readMigrationFiles({ migrationsFolder: siblingFolder }).map((m) => m.hash));
22779
+ } catch {
22780
+ return /* @__PURE__ */ new Set();
22781
+ }
22782
+ }
22783
+ function ensureJournalHashUnique(nativeDb) {
22784
+ if (!tableExists(nativeDb, "__drizzle_migrations")) return;
22785
+ try {
22786
+ nativeDb.exec(
22787
+ 'DELETE FROM "__drizzle_migrations" WHERE id NOT IN (SELECT MIN(id) FROM "__drizzle_migrations" GROUP BY hash)'
22788
+ );
22789
+ nativeDb.exec(
22790
+ 'CREATE UNIQUE INDEX IF NOT EXISTS "idx_drizzle_migrations_hash" ON "__drizzle_migrations" ("hash")'
22791
+ );
22792
+ } catch {
22793
+ }
22794
+ }
22795
+ function reconcileJournal(nativeDb, migrationsFolder, existenceTable2, logSubsystem, siblingMigrationsFolders = []) {
22796
+ const eliminatedTables = computeEliminatedTables(readMigrationFiles({ migrationsFolder }));
22797
+ const cutoverPrefix = resolveConsolidationCutoverPrefix(migrationsFolder);
22700
22798
  if (tableExists(nativeDb, existenceTable2) && !tableExists(nativeDb, "__drizzle_migrations")) {
22701
22799
  const migrations = readMigrationFiles({ migrationsFolder });
22702
22800
  const baseline = migrations[0];
@@ -22713,11 +22811,19 @@ function reconcileJournal(nativeDb, migrationsFolder, existenceTable2, logSubsys
22713
22811
  insertJournalEntry(nativeDb, baseline.hash, baseline.folderMillis, baseline.name ?? "");
22714
22812
  }
22715
22813
  }
22814
+ ensureJournalHashUnique(nativeDb);
22716
22815
  if (tableExists(nativeDb, "__drizzle_migrations") && tableExists(nativeDb, existenceTable2)) {
22717
22816
  const localMigrations = readMigrationFiles({ migrationsFolder });
22718
22817
  const localHashes = new Set(localMigrations.map((m) => m.hash));
22818
+ const knownHashes = new Set(localHashes);
22819
+ for (const siblingFolder of siblingMigrationsFolders) {
22820
+ if (siblingFolder === migrationsFolder) continue;
22821
+ for (const m of readSiblingMigrationHashes(siblingFolder)) {
22822
+ knownHashes.add(m);
22823
+ }
22824
+ }
22719
22825
  const dbEntries = nativeDb.prepare('SELECT id, hash FROM "__drizzle_migrations"').all();
22720
- const orphanedEntries = dbEntries.filter((e) => !localHashes.has(e.hash));
22826
+ const orphanedEntries = dbEntries.filter((e) => !knownHashes.has(e.hash));
22721
22827
  const hasOrphanedEntries = orphanedEntries.length > 0;
22722
22828
  if (hasOrphanedEntries) {
22723
22829
  const dbHashes = new Set(dbEntries.map((e) => e.hash));
@@ -22740,7 +22846,7 @@ function reconcileJournal(nativeDb, migrationsFolder, existenceTable2, logSubsys
22740
22846
  );
22741
22847
  for (const m of localMigrations) {
22742
22848
  if (journaledHashesAfter.has(m.hash)) continue;
22743
- probeAndMarkApplied(nativeDb, m, logSubsystem);
22849
+ probeAndMarkApplied(nativeDb, m, logSubsystem, eliminatedTables, cutoverPrefix);
22744
22850
  }
22745
22851
  }
22746
22852
  }
@@ -22763,7 +22869,7 @@ function reconcileJournal(nativeDb, migrationsFolder, existenceTable2, logSubsys
22763
22869
  });
22764
22870
  }
22765
22871
  if (alterMatches.length === 0) {
22766
- const stripped = fullSql.replace(/--[^\n]*/g, "").replace(/\/\*[\s\S]*?\*\//g, "").trim();
22872
+ const stripped = stripSqlComments(fullSql).trim();
22767
22873
  if (stripped === "") {
22768
22874
  const log10 = getLogger(logSubsystem);
22769
22875
  log10.debug(
@@ -22782,9 +22888,11 @@ function reconcileJournal(nativeDb, migrationsFolder, existenceTable2, logSubsys
22782
22888
  const createTableRe = /CREATE\s+TABLE/i;
22783
22889
  const createTriggerRe = /CREATE\s+TRIGGER/i;
22784
22890
  if (renameRe.test(fullSql) && createTableRe.test(fullSql)) {
22785
- probeAndMarkApplied(nativeDb, migration, logSubsystem);
22891
+ probeAndMarkApplied(nativeDb, migration, logSubsystem, eliminatedTables, cutoverPrefix);
22786
22892
  } else if (createTableRe.test(fullSql) || createTriggerRe.test(fullSql)) {
22787
- probeAndMarkApplied(nativeDb, migration, logSubsystem);
22893
+ probeAndMarkApplied(nativeDb, migration, logSubsystem, eliminatedTables, cutoverPrefix);
22894
+ } else {
22895
+ probeAndMarkApplied(nativeDb, migration, logSubsystem, eliminatedTables, cutoverPrefix);
22788
22896
  }
22789
22897
  continue;
22790
22898
  }
@@ -22875,6 +22983,7 @@ function reconcileBrainMigrationsForConsolidatedDb(nativeDb, migrationsFolder) {
22875
22983
  const existingHashes = new Set(
22876
22984
  nativeDb.prepare('SELECT hash FROM "__drizzle_migrations"').all().map((r) => r.hash)
22877
22985
  );
22986
+ const eliminatedTables = computeEliminatedTables(localMigrations);
22878
22987
  const createTableRegex = /CREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?[`"]?(\w+)[`"]?/gi;
22879
22988
  const renameRegex = /ALTER\s+TABLE\s+[`"]?(\w+)[`"]?\s+RENAME\s+TO\s+[`"]?(\w+)[`"]?/gi;
22880
22989
  const addColumnRegex = /ALTER\s+TABLE\s+[`"]?(\w+)[`"]?\s+ADD\s+COLUMN\s+[`"]?(\w+)[`"]?/gi;
@@ -22883,7 +22992,6 @@ function reconcileBrainMigrationsForConsolidatedDb(nativeDb, migrationsFolder) {
22883
22992
  const cols = nativeDb.prepare(`PRAGMA table_info("${table}")`).all();
22884
22993
  return cols.some((c) => c.name === column);
22885
22994
  };
22886
- const stripSqlComments = (sql39) => sql39.replace(/--[^\n]*/g, "").replace(/\/\*[\s\S]*?\*\//g, "");
22887
22995
  let marked = 0;
22888
22996
  let applied = 0;
22889
22997
  for (const m of localMigrations) {
@@ -22904,7 +23012,7 @@ function reconcileBrainMigrationsForConsolidatedDb(nativeDb, migrationsFolder) {
22904
23012
  for (const match of fullSql.matchAll(addColumnRegex)) {
22905
23013
  addColumns.push({ table: match[1], column: match[2] });
22906
23014
  }
22907
- const tablesSatisfied = resultTables.size > 0 && [...resultTables].every((t) => tableExists(nativeDb, t));
23015
+ const tablesSatisfied = resultTables.size > 0 && [...resultTables].every((t) => tableExists(nativeDb, t) || eliminatedTables.has(t));
22908
23016
  const altersSatisfied = resultTables.size === 0 && addColumns.length > 0 && addColumns.every(({ table, column }) => columnExists(table, column));
22909
23017
  if (tablesSatisfied || altersSatisfied) {
22910
23018
  for (const statement of m.sql) {
@@ -22927,13 +23035,22 @@ function reconcileBrainMigrationsForConsolidatedDb(nativeDb, migrationsFolder) {
22927
23035
  }
22928
23036
  return { marked, applied };
22929
23037
  }
23038
+ function collectErrorMessages(err) {
23039
+ const messages = [];
23040
+ let current = err;
23041
+ for (let depth = 0; current instanceof Error && depth < 16; depth++) {
23042
+ messages.push(current.message);
23043
+ current = current.cause;
23044
+ }
23045
+ return messages.join("\n");
23046
+ }
22930
23047
  function isDuplicateColumnError(err) {
22931
23048
  if (!(err instanceof Error)) return false;
22932
- return /duplicate column name/i.test(err.message);
23049
+ return /duplicate column name/i.test(collectErrorMessages(err));
22933
23050
  }
22934
23051
  function isTableAlreadyExistsError(err) {
22935
23052
  if (!(err instanceof Error)) return false;
22936
- return /table .+ already exists/i.test(err.message);
23053
+ return /table .+ already exists/i.test(collectErrorMessages(err));
22937
23054
  }
22938
23055
  function isExecutableStatement(stmt) {
22939
23056
  if (stmt.trim() === "") return false;
@@ -23004,7 +23121,7 @@ function ensureColumns(nativeDb, tableName, requiredColumns, logSubsystem, conte
23004
23121
  }
23005
23122
  }
23006
23123
  }
23007
- var MAX_MIGRATION_RETRIES, MIGRATION_RETRY_BASE_DELAY_MS, MIGRATION_RETRY_MAX_DELAY_MS;
23124
+ var MAX_MIGRATION_RETRIES, MIGRATION_RETRY_BASE_DELAY_MS, MIGRATION_RETRY_MAX_DELAY_MS, CONSOLIDATION_CUTOVER_PREFIX, MIGRATION_TIMESTAMP_PREFIX_LEN;
23008
23125
  var init_migration_manager = __esm({
23009
23126
  "packages/core/src/store/migration-manager.ts"() {
23010
23127
  "use strict";
@@ -23014,36 +23131,55 @@ var init_migration_manager = __esm({
23014
23131
  MAX_MIGRATION_RETRIES = 5;
23015
23132
  MIGRATION_RETRY_BASE_DELAY_MS = 100;
23016
23133
  MIGRATION_RETRY_MAX_DELAY_MS = 2e3;
23134
+ CONSOLIDATION_CUTOVER_PREFIX = "20260531000001";
23135
+ MIGRATION_TIMESTAMP_PREFIX_LEN = 14;
23017
23136
  }
23018
23137
  });
23019
23138
 
23020
23139
  // packages/core/src/store/resolve-migrations-folder.ts
23021
23140
  import { createRequire } from "node:module";
23022
- import { dirname, join as join3 } from "node:path";
23141
+ import { dirname as dirname2, join as join4 } from "node:path";
23023
23142
  import { fileURLToPath } from "node:url";
23024
23143
  function coreRootFromEntry(entryPath) {
23025
- return dirname(dirname(entryPath));
23144
+ return dirname2(dirname2(entryPath));
23145
+ }
23146
+ function resolveConsolidatedJournalSiblings(ownSetName) {
23147
+ return CONSOLIDATED_JOURNAL_LINEAGES.filter((name2) => name2 !== ownSetName).map(
23148
+ (name2) => resolveCorePackageMigrationsFolder(name2)
23149
+ );
23026
23150
  }
23027
23151
  function resolveCorePackageMigrationsFolder(setName) {
23028
23152
  try {
23029
23153
  const resolved = import.meta.resolve("@cleocode/core", import.meta.url);
23030
23154
  const entryPath = fileURLToPath(resolved);
23031
- return join3(coreRootFromEntry(entryPath), "migrations", setName);
23155
+ return join4(coreRootFromEntry(entryPath), "migrations", setName);
23032
23156
  } catch {
23033
23157
  }
23034
23158
  const _require6 = createRequire(import.meta.url);
23035
23159
  try {
23036
23160
  const entryPath = _require6.resolve("@cleocode/core");
23037
- return join3(coreRootFromEntry(entryPath), "migrations", setName);
23161
+ return join4(coreRootFromEntry(entryPath), "migrations", setName);
23038
23162
  } catch (err) {
23039
23163
  throw new Error(
23040
23164
  `resolveCorePackageMigrationsFolder("${setName}"): cannot locate @cleocode/core from "${import.meta.url}". Ensure @cleocode/core is installed (workspace or npm). Original error: ${err.message}`
23041
23165
  );
23042
23166
  }
23043
23167
  }
23168
+ var CONSOLIDATED_JOURNAL_LINEAGES;
23044
23169
  var init_resolve_migrations_folder = __esm({
23045
23170
  "packages/core/src/store/resolve-migrations-folder.ts"() {
23046
23171
  "use strict";
23172
+ CONSOLIDATED_JOURNAL_LINEAGES = [
23173
+ "drizzle-tasks",
23174
+ "drizzle-cleo-project",
23175
+ "drizzle-nexus",
23176
+ "drizzle-brain",
23177
+ "drizzle-conduit",
23178
+ "drizzle-cleo-global",
23179
+ "drizzle-agent-registry",
23180
+ "drizzle-skills",
23181
+ "drizzle-telemetry"
23182
+ ];
23047
23183
  }
23048
23184
  });
23049
23185
 
@@ -31225,11 +31361,11 @@ var init_lock = __esm({
31225
31361
 
31226
31362
  // packages/core/src/store/atomic.ts
31227
31363
  import { mkdir, readFile as readFile2, rename, unlink } from "node:fs/promises";
31228
- import { dirname as dirname2 } from "node:path";
31364
+ import { dirname as dirname3 } from "node:path";
31229
31365
  import writeFileAtomic from "write-file-atomic";
31230
31366
  async function atomicWrite(filePath, data, options) {
31231
31367
  try {
31232
- await mkdir(dirname2(filePath), { recursive: true });
31368
+ await mkdir(dirname3(filePath), { recursive: true });
31233
31369
  await writeFileAtomic(filePath, data, {
31234
31370
  encoding: options?.encoding ?? "utf8",
31235
31371
  mode: options?.mode
@@ -31262,7 +31398,7 @@ var init_atomic = __esm({
31262
31398
 
31263
31399
  // packages/core/src/store/backup.ts
31264
31400
  import { copyFile, rename as fsRename, mkdir as mkdir2, readdir, stat, unlink as unlink2 } from "node:fs/promises";
31265
- import { basename, join as join4 } from "node:path";
31401
+ import { basename, join as join5 } from "node:path";
31266
31402
  async function createBackup(filePath, backupDir, maxBackups = DEFAULT_MAX_BACKUPS) {
31267
31403
  try {
31268
31404
  await mkdir2(backupDir, { recursive: true });
@@ -31273,14 +31409,14 @@ async function createBackup(filePath, backupDir, maxBackups = DEFAULT_MAX_BACKUP
31273
31409
  throw new CleoError(3 /* FILE_ERROR */, `Cannot backup: source file not found: ${filePath}`);
31274
31410
  }
31275
31411
  for (let i = maxBackups; i >= 1; i--) {
31276
- const current = join4(backupDir, `${fileName}.${i}`);
31412
+ const current = join5(backupDir, `${fileName}.${i}`);
31277
31413
  if (i === maxBackups) {
31278
31414
  try {
31279
31415
  await unlink2(current);
31280
31416
  } catch {
31281
31417
  }
31282
31418
  } else {
31283
- const next = join4(backupDir, `${fileName}.${i + 1}`);
31419
+ const next = join5(backupDir, `${fileName}.${i + 1}`);
31284
31420
  try {
31285
31421
  await stat(current);
31286
31422
  await fsRename(current, next);
@@ -31288,7 +31424,7 @@ async function createBackup(filePath, backupDir, maxBackups = DEFAULT_MAX_BACKUP
31288
31424
  }
31289
31425
  }
31290
31426
  }
31291
- const backupPath = join4(backupDir, `${fileName}.1`);
31427
+ const backupPath = join5(backupDir, `${fileName}.1`);
31292
31428
  await copyFile(filePath, backupPath);
31293
31429
  return backupPath;
31294
31430
  } catch (err) {
@@ -31568,15 +31704,15 @@ var init_json2 = __esm({
31568
31704
 
31569
31705
  // packages/core/src/scaffold/ensure-config.ts
31570
31706
  import { existsSync as existsSync3, readFileSync } from "node:fs";
31571
- import { basename as basename2, dirname as dirname3, join as join5, resolve as resolve2 } from "node:path";
31707
+ import { basename as basename2, dirname as dirname4, join as join6, resolve as resolve2 } from "node:path";
31572
31708
  import { fileURLToPath as fileURLToPath2 } from "node:url";
31573
31709
  function getPackageRoot() {
31574
31710
  const thisFile = fileURLToPath2(import.meta.url);
31575
- return resolve2(dirname3(thisFile), "..", "..");
31711
+ return resolve2(dirname4(thisFile), "..", "..");
31576
31712
  }
31577
31713
  function getCleoVersion() {
31578
31714
  try {
31579
- const pkgPath = join5(getPackageRoot(), "package.json");
31715
+ const pkgPath = join6(getPackageRoot(), "package.json");
31580
31716
  const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
31581
31717
  return pkg.version ?? "0.0.0";
31582
31718
  } catch {
@@ -31601,15 +31737,15 @@ import {
31601
31737
  unlinkSync,
31602
31738
  writeFileSync
31603
31739
  } from "node:fs";
31604
- import { basename as basename3, join as join6 } from "node:path";
31740
+ import { basename as basename3, join as join7 } from "node:path";
31605
31741
  function scopeBaseDir(scope, cwd) {
31606
31742
  return scope === "project" ? resolveCleoDir(cwd) : getCleoHome();
31607
31743
  }
31608
31744
  function exodusArchiveDir(scope, cwd) {
31609
- return join6(scopeBaseDir(scope, cwd), ARCHIVE_DIR_NAME);
31745
+ return join7(scopeBaseDir(scope, cwd), ARCHIVE_DIR_NAME);
31610
31746
  }
31611
31747
  function exodusMarkerPath(scope, cwd) {
31612
- return join6(scopeBaseDir(scope, cwd), MARKER_FILENAME_BY_SCOPE[scope]);
31748
+ return join7(scopeBaseDir(scope, cwd), MARKER_FILENAME_BY_SCOPE[scope]);
31613
31749
  }
31614
31750
  function hasExodusCompleteMarker(scope, cwd) {
31615
31751
  try {
@@ -31637,10 +31773,10 @@ function writeExodusCompleteMarker(scope, archivedSources, cwd) {
31637
31773
  }
31638
31774
  function moveFileInto(srcPath, destDir) {
31639
31775
  mkdirSync(destDir, { recursive: true });
31640
- let dest = join6(destDir, basename3(srcPath));
31776
+ let dest = join7(destDir, basename3(srcPath));
31641
31777
  if (existsSync4(dest)) {
31642
31778
  const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "").replace(/Z$/, "Z");
31643
- dest = join6(destDir, `${basename3(srcPath)}.${stamp}`);
31779
+ dest = join7(destDir, `${basename3(srcPath)}.${stamp}`);
31644
31780
  }
31645
31781
  try {
31646
31782
  renameSync(srcPath, dest);
@@ -31739,11 +31875,11 @@ var init_archive2 = __esm({
31739
31875
 
31740
31876
  // packages/core/src/project-info.ts
31741
31877
  import { existsSync as existsSync5, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "node:fs";
31742
- import { join as join7 } from "node:path";
31878
+ import { join as join8 } from "node:path";
31743
31879
  function getProjectInfoSync(cwd) {
31744
31880
  const projectRoot = resolveOrCwd(cwd);
31745
31881
  const cleoDir = getCleoDirAbsolute(projectRoot);
31746
- const infoPath = join7(cleoDir, "project-info.json");
31882
+ const infoPath = join8(cleoDir, "project-info.json");
31747
31883
  if (!existsSync5(infoPath)) return null;
31748
31884
  try {
31749
31885
  const raw = readFileSync2(infoPath, "utf-8");
@@ -31772,7 +31908,7 @@ var init_project_info = __esm({
31772
31908
 
31773
31909
  // packages/core/src/store/worktree-isolation-guard.ts
31774
31910
  import { existsSync as existsSync6, statSync } from "node:fs";
31775
- import { dirname as dirname4, join as join8 } from "node:path";
31911
+ import { dirname as dirname5, join as join9 } from "node:path";
31776
31912
  function assertDbPathIsNotWorktreeResident(role, cwd) {
31777
31913
  let cleoDir;
31778
31914
  try {
@@ -31780,8 +31916,8 @@ function assertDbPathIsNotWorktreeResident(role, cwd) {
31780
31916
  } catch {
31781
31917
  return;
31782
31918
  }
31783
- const projectRoot = dirname4(cleoDir);
31784
- const projectGit = join8(projectRoot, ".git");
31919
+ const projectRoot = dirname5(cleoDir);
31920
+ const projectGit = join9(projectRoot, ".git");
31785
31921
  let isWorktreeGitlink = false;
31786
31922
  try {
31787
31923
  isWorktreeGitlink = existsSync6(projectGit) && statSync(projectGit).isFile();
@@ -32336,7 +32472,7 @@ var init_count_parity = __esm({
32336
32472
 
32337
32473
  // packages/core/src/store/exodus/plan.ts
32338
32474
  import { existsSync as existsSync8, readdirSync as readdirSync2, statfsSync, statSync as statSync2 } from "node:fs";
32339
- import { join as join9 } from "node:path";
32475
+ import { join as join10 } from "node:path";
32340
32476
  function computeRequiredBytes(totalSourceBytes, largestSourceBytes) {
32341
32477
  return Math.ceil(STAGING_HEADROOM_FACTOR * largestSourceBytes) + totalSourceBytes;
32342
32478
  }
@@ -32347,33 +32483,33 @@ function buildSourceDescriptors(cwd) {
32347
32483
  // Project-tier — go into consolidated project-scope cleo.db
32348
32484
  {
32349
32485
  name: "tasks",
32350
- path: join9(cleoDir, "tasks.db"),
32486
+ path: join10(cleoDir, "tasks.db"),
32351
32487
  targetScope: "project"
32352
32488
  },
32353
32489
  {
32354
32490
  name: "brain (project)",
32355
- path: join9(cleoDir, "brain.db"),
32491
+ path: join10(cleoDir, "brain.db"),
32356
32492
  targetScope: "project"
32357
32493
  },
32358
32494
  {
32359
32495
  name: "conduit",
32360
- path: join9(cleoDir, "conduit.db"),
32496
+ path: join10(cleoDir, "conduit.db"),
32361
32497
  targetScope: "project"
32362
32498
  },
32363
32499
  // Global-tier — go into consolidated global-scope cleo.db
32364
32500
  {
32365
32501
  name: "nexus",
32366
- path: join9(cleoHome, "nexus.db"),
32502
+ path: join10(cleoHome, "nexus.db"),
32367
32503
  targetScope: "global"
32368
32504
  },
32369
32505
  {
32370
32506
  name: "signaldock",
32371
- path: join9(cleoHome, "signaldock.db"),
32507
+ path: join10(cleoHome, "signaldock.db"),
32372
32508
  targetScope: "global"
32373
32509
  },
32374
32510
  {
32375
32511
  name: "skills",
32376
- path: join9(cleoHome, "skills.db"),
32512
+ path: join10(cleoHome, "skills.db"),
32377
32513
  targetScope: "global"
32378
32514
  }
32379
32515
  ];
@@ -32402,7 +32538,7 @@ function findExistingStaging(cleoDir) {
32402
32538
  const entries = readdirSync2(cleoDir, { withFileTypes: true });
32403
32539
  const stagingDirs = entries.filter((e) => e.isDirectory() && e.name.startsWith("exodus-staging-")).map((e) => e.name).sort().reverse();
32404
32540
  if (stagingDirs.length > 0) {
32405
- return join9(cleoDir, stagingDirs[0]);
32541
+ return join10(cleoDir, stagingDirs[0]);
32406
32542
  }
32407
32543
  } catch {
32408
32544
  }
@@ -32418,7 +32554,7 @@ function buildExodusPlan(cwd) {
32418
32554
  const availableBytes = getAvailableBytes(cleoDir);
32419
32555
  const diskPreflight = totalSourceBytes === 0 || availableBytes >= requiredBytes;
32420
32556
  const existingStaging = findExistingStaging(cleoDir);
32421
- const stagingDir = existingStaging ?? join9(cleoDir, deriveStagingDirName());
32557
+ const stagingDir = existingStaging ?? join10(cleoDir, deriveStagingDirName());
32422
32558
  const resumeFromStaging = existingStaging !== null;
32423
32559
  const projectDbPath = resolveDualScopeDbPath("project", cwd);
32424
32560
  const globalDbPath = resolveDualScopeDbPath("global");
@@ -32737,7 +32873,7 @@ import {
32737
32873
  unlinkSync as unlinkSync2,
32738
32874
  writeFileSync as writeFileSync3
32739
32875
  } from "node:fs";
32740
- import { join as join10 } from "node:path";
32876
+ import { join as join11 } from "node:path";
32741
32877
  function getSqliteVersion(db) {
32742
32878
  try {
32743
32879
  const row = db.prepare("SELECT sqlite_version() AS v").get();
@@ -32753,13 +32889,13 @@ function listTables2(db) {
32753
32889
  return rows.map((r) => r.name);
32754
32890
  }
32755
32891
  function writeJournal(stagingDir, journal) {
32756
- const journalPath = join10(stagingDir, JOURNAL_FILENAME);
32892
+ const journalPath = join11(stagingDir, JOURNAL_FILENAME);
32757
32893
  const tmpPath = `${journalPath}.tmp`;
32758
32894
  writeFileSync3(tmpPath, JSON.stringify(journal, null, 2) + "\n", "utf8");
32759
32895
  renameSync2(tmpPath, journalPath);
32760
32896
  }
32761
32897
  function readJournal(stagingDir) {
32762
- const journalPath = join10(stagingDir, JOURNAL_FILENAME);
32898
+ const journalPath = join11(stagingDir, JOURNAL_FILENAME);
32763
32899
  if (!existsSync10(journalPath)) return null;
32764
32900
  try {
32765
32901
  return JSON.parse(readFileSync3(journalPath, "utf8"));
@@ -32768,7 +32904,7 @@ function readJournal(stagingDir) {
32768
32904
  }
32769
32905
  }
32770
32906
  function clearExodusJournal(stagingDir) {
32771
- const journalPath = join10(stagingDir, JOURNAL_FILENAME);
32907
+ const journalPath = join11(stagingDir, JOURNAL_FILENAME);
32772
32908
  try {
32773
32909
  if (!existsSync10(journalPath)) return false;
32774
32910
  unlinkSync2(journalPath);
@@ -33077,7 +33213,7 @@ async function runExodusMigrate(plan, forceCrossVersion = false, onProgress) {
33077
33213
  var extractNativeDb = extractNativeDb2;
33078
33214
  for (const src of sources) {
33079
33215
  if (!existsSync10(src.path)) continue;
33080
- const backupDest = join10(stagingDir, `${src.name.replace(/[^a-z0-9-]/g, "_")}-backup.db`);
33216
+ const backupDest = join11(stagingDir, `${src.name.replace(/[^a-z0-9-]/g, "_")}-backup.db`);
33081
33217
  const srcBytes = safeStatBytes(src.path);
33082
33218
  const skipStagingCopy = srcBytes > plan.stagingCopyThresholdBytes;
33083
33219
  if (skipStagingCopy) {
@@ -33379,9 +33515,9 @@ var init_seal = __esm({
33379
33515
 
33380
33516
  // packages/core/src/store/exodus/status.ts
33381
33517
  import { existsSync as existsSync11, readdirSync as readdirSync3, readFileSync as readFileSync4, statSync as statSync5 } from "node:fs";
33382
- import { join as join11 } from "node:path";
33518
+ import { join as join12 } from "node:path";
33383
33519
  function readJournal2(stagingDir) {
33384
- const p = join11(stagingDir, JOURNAL_FILENAME2);
33520
+ const p = join12(stagingDir, JOURNAL_FILENAME2);
33385
33521
  if (!existsSync11(p)) return null;
33386
33522
  try {
33387
33523
  return JSON.parse(readFileSync4(p, "utf8"));
@@ -33391,7 +33527,7 @@ function readJournal2(stagingDir) {
33391
33527
  }
33392
33528
  function findStagingDirs(cleoDir) {
33393
33529
  try {
33394
- return readdirSync3(cleoDir, { withFileTypes: true }).filter((e) => e.isDirectory() && e.name.startsWith("exodus-staging-")).map((e) => join11(cleoDir, e.name)).sort().reverse();
33530
+ return readdirSync3(cleoDir, { withFileTypes: true }).filter((e) => e.isDirectory() && e.name.startsWith("exodus-staging-")).map((e) => join12(cleoDir, e.name)).sort().reverse();
33395
33531
  } catch {
33396
33532
  return [];
33397
33533
  }
@@ -34243,7 +34379,7 @@ __export(dual_scope_db_exports, {
34243
34379
  });
34244
34380
  import { existsSync as existsSync14, mkdirSync as mkdirSync3 } from "node:fs";
34245
34381
  import { createRequire as createRequire4 } from "node:module";
34246
- import { dirname as dirname5, join as join12 } from "node:path";
34382
+ import { dirname as dirname6, join as join13 } from "node:path";
34247
34383
  function assertWriteDurable(handle) {
34248
34384
  if (handle.exodusAbort) {
34249
34385
  throw new ExodusAbortWriteUnsafeError(handle.exodusAbort);
@@ -34260,9 +34396,9 @@ function cacheKey(scope, dbPath) {
34260
34396
  }
34261
34397
  function resolveDualScopeDbPath(scope, cwd) {
34262
34398
  if (scope === "project") {
34263
- return join12(resolveCleoDir(cwd), "cleo.db");
34399
+ return join13(resolveCleoDir(cwd), "cleo.db");
34264
34400
  }
34265
- return join12(getCleoHome(), "cleo.db");
34401
+ return join13(getCleoHome(), "cleo.db");
34266
34402
  }
34267
34403
  function migrationsSetName(scope) {
34268
34404
  return scope === "project" ? "drizzle-cleo-project" : "drizzle-cleo-global";
@@ -34296,24 +34432,35 @@ async function loadGlobalSchema() {
34296
34432
  function existenceTable(scope) {
34297
34433
  return scope === "project" ? "tasks_tasks" : "nexus_project_registry";
34298
34434
  }
34435
+ function memoryBoundedPragmaOverrides() {
34436
+ if (process.env.CLEO_SENTIENT_DAEMON === "1") return {};
34437
+ if (process.env.CLEO_DB_FULL_MEM === "1") return {};
34438
+ return { mmapSizeBytes: 0, cacheSizeKb: 8e3 };
34439
+ }
34299
34440
  async function openDualScopeDb(scope, cwd) {
34300
34441
  const dbPath = resolveDualScopeDbPath(scope, cwd);
34301
34442
  return scope === "project" ? openDualScopeDbAtPath("project", dbPath, cwd) : openDualScopeDbAtPath("global", dbPath, cwd);
34302
34443
  }
34303
34444
  async function openDedicatedDualScopeDb(scope, dbPath, log10) {
34304
34445
  log10.debug({ scope, dbPath }, "opening DEDICATED (non-cached) dual-scope cleo.db (T11782 FIX D)");
34305
- const dir = dirname5(dbPath);
34446
+ const dir = dirname6(dbPath);
34306
34447
  if (!existsSync14(dir)) {
34307
34448
  mkdirSync3(dir, { recursive: true });
34308
34449
  }
34309
34450
  const DatabaseSyncCtor = getDatabaseSyncCtor();
34310
34451
  const nativeDb = new DatabaseSyncCtor(dbPath, { allowExtension: true });
34311
- applyPerfPragmas(nativeDb);
34452
+ applyPerfPragmas(nativeDb, memoryBoundedPragmaOverrides());
34312
34453
  const schema = scope === "project" ? await loadProjectSchema() : await loadGlobalSchema();
34313
34454
  const drizzle2 = getDrizzle();
34314
34455
  const db = drizzle2({ client: nativeDb, schema });
34315
34456
  const migrationsFolder = resolveCorePackageMigrationsFolder(migrationsSetName(scope));
34316
- reconcileJournal(nativeDb, migrationsFolder, existenceTable(scope), `dual-scope-db[${scope}]`);
34457
+ reconcileJournal(
34458
+ nativeDb,
34459
+ migrationsFolder,
34460
+ existenceTable(scope),
34461
+ `dual-scope-db[${scope}]`,
34462
+ resolveConsolidatedJournalSiblings(migrationsSetName(scope))
34463
+ );
34317
34464
  migrateWithRetry(
34318
34465
  db,
34319
34466
  migrationsFolder,
@@ -34352,18 +34499,24 @@ async function openDualScopeDbAtPath(scope, dbPath, exodusCwd, options) {
34352
34499
  }
34353
34500
  const initPromise = (async () => {
34354
34501
  log10.debug({ scope, dbPath }, "opening dual-scope cleo.db");
34355
- const dir = dirname5(dbPath);
34502
+ const dir = dirname6(dbPath);
34356
34503
  if (!existsSync14(dir)) {
34357
34504
  mkdirSync3(dir, { recursive: true });
34358
34505
  }
34359
34506
  const DatabaseSyncCtor = getDatabaseSyncCtor();
34360
34507
  const nativeDb = new DatabaseSyncCtor(dbPath, { allowExtension: true });
34361
- applyPerfPragmas(nativeDb);
34508
+ applyPerfPragmas(nativeDb, memoryBoundedPragmaOverrides());
34362
34509
  const schema = scope === "project" ? await loadProjectSchema() : await loadGlobalSchema();
34363
34510
  const drizzle2 = getDrizzle();
34364
34511
  const db = drizzle2({ client: nativeDb, schema });
34365
34512
  const migrationsFolder = resolveCorePackageMigrationsFolder(migrationsSetName(scope));
34366
- reconcileJournal(nativeDb, migrationsFolder, existenceTable(scope), `dual-scope-db[${scope}]`);
34513
+ reconcileJournal(
34514
+ nativeDb,
34515
+ migrationsFolder,
34516
+ existenceTable(scope),
34517
+ `dual-scope-db[${scope}]`,
34518
+ resolveConsolidatedJournalSiblings(migrationsSetName(scope))
34519
+ );
34367
34520
  migrateWithRetry(
34368
34521
  db,
34369
34522
  migrationsFolder,
@@ -34431,6 +34584,12 @@ async function openDualScopeDbAtPath(scope, dbPath, exodusCwd, options) {
34431
34584
  nativeDb: null,
34432
34585
  initPromise
34433
34586
  });
34587
+ initPromise.catch(() => {
34588
+ const entry = _cache.get(key);
34589
+ if (entry && entry.initPromise === initPromise) {
34590
+ _cache.delete(key);
34591
+ }
34592
+ });
34434
34593
  return initPromise;
34435
34594
  }
34436
34595
  function _resetDualScopeDbCache(scope) {
@@ -35022,7 +35181,7 @@ __export(nexus_sqlite_exports, {
35022
35181
  resolveNexusMigrationsFolder: () => resolveNexusMigrationsFolder
35023
35182
  });
35024
35183
  import { copyFileSync as copyFileSync4, existsSync as existsSync15 } from "node:fs";
35025
- import { join as join13 } from "node:path";
35184
+ import { join as join14 } from "node:path";
35026
35185
  function getNexusDbPath(cwd) {
35027
35186
  return resolveDualScopeDbPath("project", cwd);
35028
35187
  }
@@ -35054,7 +35213,7 @@ function resolveNexusMigrationsFolder() {
35054
35213
  return resolveCorePackageMigrationsFolder("drizzle-nexus");
35055
35214
  }
35056
35215
  function getNestedNexusSentinelPath() {
35057
- return join13(getCleoHome(), "nexus", NESTED_NEXUS_SENTINEL);
35216
+ return join14(getCleoHome(), "nexus", NESTED_NEXUS_SENTINEL);
35058
35217
  }
35059
35218
  function detectAndWarnOnNestedNexus() {
35060
35219
  let nestedPath;
@@ -35229,7 +35388,13 @@ function runNexusMigrations(nativeDb, db) {
35229
35388
  }
35230
35389
  }
35231
35390
  }
35232
- reconcileJournal(nativeDb, migrationsFolder, "_nexus_meta", "nexus");
35391
+ reconcileJournal(
35392
+ nativeDb,
35393
+ migrationsFolder,
35394
+ "_nexus_meta",
35395
+ "nexus",
35396
+ resolveConsolidatedJournalSiblings("drizzle-nexus")
35397
+ );
35233
35398
  const MAX_RETRIES = 5;
35234
35399
  const BASE_DELAY_MS = 100;
35235
35400
  const MAX_DELAY_MS = 2e3;
@@ -35357,7 +35522,7 @@ import { AsyncLocalStorage } from "node:async_hooks";
35357
35522
  import { existsSync as existsSync16, readFileSync as readFileSync5, statSync as statSync6 } from "node:fs";
35358
35523
  import { createRequire as createRequire5 } from "node:module";
35359
35524
  import { homedir } from "node:os";
35360
- import { basename as basename4, dirname as dirname6, join as join14, resolve as resolve3 } from "node:path";
35525
+ import { basename as basename4, dirname as dirname7, join as join15, resolve as resolve3 } from "node:path";
35361
35526
  import {
35362
35527
  computeCanonicalProjectId as _computeCanonicalProjectId,
35363
35528
  getCanonicalTemplatesTildePath as _getCanonicalTemplatesTildePath,
@@ -35447,7 +35612,7 @@ function getCleoDirAbsolute(cwd, opts) {
35447
35612
  function _resolveProjectByCwdFromNexus(cwd) {
35448
35613
  try {
35449
35614
  const cleoHome = getCleoHome();
35450
- const globalDbPath = join14(cleoHome, "cleo.db");
35615
+ const globalDbPath = join15(cleoHome, "cleo.db");
35451
35616
  if (!existsSync16(globalDbPath)) return null;
35452
35617
  const start = resolve3(cwd ?? process.cwd());
35453
35618
  let current = start;
@@ -35462,7 +35627,7 @@ function _resolveProjectByCwdFromNexus(cwd) {
35462
35627
  if (row && typeof row.project_id === "string" && row.project_id.length > 0) {
35463
35628
  return row.project_id;
35464
35629
  }
35465
- const parent = dirname6(current);
35630
+ const parent = dirname7(current);
35466
35631
  if (parent === current) break;
35467
35632
  current = parent;
35468
35633
  }
@@ -35487,13 +35652,13 @@ function _findCleoDirRoot(cwd) {
35487
35652
  const isDangerousRoot = current === homeRoot || current === "/" || current === "";
35488
35653
  if (!isDangerousRoot) {
35489
35654
  try {
35490
- if (statSync6(join14(current, ".cleo")).isDirectory()) {
35655
+ if (statSync6(join15(current, ".cleo")).isDirectory()) {
35491
35656
  return current;
35492
35657
  }
35493
35658
  } catch {
35494
35659
  }
35495
35660
  }
35496
- const parent = dirname6(current);
35661
+ const parent = dirname7(current);
35497
35662
  if (parent === current) break;
35498
35663
  current = parent;
35499
35664
  }
@@ -35502,7 +35667,7 @@ function _findCleoDirRoot(cwd) {
35502
35667
  function resolveCleoDir(cwd) {
35503
35668
  const scope = worktreeScope.getStore();
35504
35669
  if (scope !== void 0) {
35505
- return join14(scope.worktreeRoot, ".cleo");
35670
+ return join15(scope.worktreeRoot, ".cleo");
35506
35671
  }
35507
35672
  const override = _cleoDirEnvOverride();
35508
35673
  if (override !== null) {
@@ -35510,16 +35675,16 @@ function resolveCleoDir(cwd) {
35510
35675
  }
35511
35676
  const root = _findCleoDirRoot(cwd);
35512
35677
  if (root !== null) {
35513
- return join14(root, ".cleo");
35678
+ return join15(root, ".cleo");
35514
35679
  }
35515
35680
  const start = resolve3(cwd ?? process.cwd());
35516
35681
  let current = start;
35517
35682
  while (true) {
35518
35683
  const mainRepo = _resolveMainRepoFromGitlink(current);
35519
35684
  if (mainRepo !== null) {
35520
- return join14(mainRepo, ".cleo");
35685
+ return join15(mainRepo, ".cleo");
35521
35686
  }
35522
- const parent = dirname6(current);
35687
+ const parent = dirname7(current);
35523
35688
  if (parent === current) {
35524
35689
  break;
35525
35690
  }
@@ -35559,21 +35724,21 @@ function _cwdHasGitAncestor(cwd) {
35559
35724
  const start = resolve3(cwd ?? process.cwd());
35560
35725
  let current = start;
35561
35726
  while (true) {
35562
- const gitMarker = join14(current, ".git");
35727
+ const gitMarker = join15(current, ".git");
35563
35728
  try {
35564
35729
  if (existsSync16(gitMarker)) {
35565
35730
  return true;
35566
35731
  }
35567
35732
  } catch {
35568
35733
  }
35569
- const parent = dirname6(current);
35734
+ const parent = dirname7(current);
35570
35735
  if (parent === current) return false;
35571
35736
  current = parent;
35572
35737
  }
35573
35738
  }
35574
35739
  function _resolveMainRepoFromGitlink(gitlinkDir) {
35575
35740
  try {
35576
- const gitLinkPath = join14(gitlinkDir, ".git");
35741
+ const gitLinkPath = join15(gitlinkDir, ".git");
35577
35742
  if (!existsSync16(gitLinkPath)) return null;
35578
35743
  const stat2 = statSync6(gitLinkPath);
35579
35744
  if (!stat2.isFile()) return null;
@@ -35581,8 +35746,8 @@ function _resolveMainRepoFromGitlink(gitlinkDir) {
35581
35746
  const match = gitLinkContent.match(/^gitdir:\s*(.+)$/m);
35582
35747
  if (!match) return null;
35583
35748
  const gitdir = match[1].trim();
35584
- const mainRepo = dirname6(dirname6(dirname6(gitdir)));
35585
- if (existsSync16(join14(mainRepo, ".cleo")) && validateProjectRoot(mainRepo)) {
35749
+ const mainRepo = dirname7(dirname7(dirname7(gitdir)));
35750
+ if (existsSync16(join15(mainRepo, ".cleo")) && validateProjectRoot(mainRepo)) {
35586
35751
  return mainRepo;
35587
35752
  }
35588
35753
  } catch {
@@ -35590,17 +35755,17 @@ function _resolveMainRepoFromGitlink(gitlinkDir) {
35590
35755
  return null;
35591
35756
  }
35592
35757
  function validateProjectRoot(candidate) {
35593
- const cleoDir = join14(candidate, ".cleo");
35758
+ const cleoDir = join15(candidate, ".cleo");
35594
35759
  if (!existsSync16(cleoDir)) {
35595
35760
  return false;
35596
35761
  }
35597
- const projectInfoPath = join14(cleoDir, "project-info.json");
35762
+ const projectInfoPath = join15(cleoDir, "project-info.json");
35598
35763
  if (existsSync16(projectInfoPath)) {
35599
35764
  try {
35600
35765
  const raw = readFileSync5(projectInfoPath, "utf-8");
35601
35766
  const parsed = JSON.parse(raw);
35602
35767
  if (typeof parsed === "object" && parsed !== null && "projectId" in parsed && typeof parsed["projectId"] === "string" && parsed["projectId"] !== "") {
35603
- const gitMarker = join14(candidate, ".git");
35768
+ const gitMarker = join15(candidate, ".git");
35604
35769
  if (existsSync16(gitMarker)) {
35605
35770
  try {
35606
35771
  if (!statSync6(gitMarker).isDirectory()) {
@@ -35615,7 +35780,7 @@ function validateProjectRoot(candidate) {
35615
35780
  } catch {
35616
35781
  }
35617
35782
  }
35618
- const gitDir = join14(candidate, ".git");
35783
+ const gitDir = join15(candidate, ".git");
35619
35784
  if (existsSync16(gitDir)) {
35620
35785
  let isRealGitDir = false;
35621
35786
  try {
@@ -35652,7 +35817,7 @@ function getProjectRoot(cwd) {
35652
35817
  const cleoDirEnv = process.env["CLEO_DIR"];
35653
35818
  if (cleoDirEnv && isAbsolutePath(cleoDirEnv)) {
35654
35819
  if (cleoDirEnv.endsWith("/.cleo") || cleoDirEnv.endsWith("\\.cleo")) {
35655
- return dirname6(cleoDirEnv);
35820
+ return dirname7(cleoDirEnv);
35656
35821
  }
35657
35822
  return cleoDirEnv;
35658
35823
  }
@@ -35663,8 +35828,8 @@ function getProjectRoot(cwd) {
35663
35828
  const homeRoot = homedir();
35664
35829
  const skippedCleoDirs = [];
35665
35830
  while (true) {
35666
- const cleoDir = join14(current, ".cleo");
35667
- const gitDir = join14(current, ".git");
35831
+ const cleoDir = join15(current, ".cleo");
35832
+ const gitDir = join15(current, ".git");
35668
35833
  const isDangerousRoot = current === homeRoot || current === "/" || current === "";
35669
35834
  if (existsSync16(cleoDir) && !isDangerousRoot) {
35670
35835
  if (validateProjectRoot(current)) {
@@ -35687,7 +35852,7 @@ function getProjectRoot(cwd) {
35687
35852
  const mainRepoFromWalk = _resolveMainRepoFromGitlink(current);
35688
35853
  if (mainRepoFromWalk !== null) return mainRepoFromWalk;
35689
35854
  }
35690
- const parent = dirname6(current);
35855
+ const parent = dirname7(current);
35691
35856
  if (parent === current) {
35692
35857
  break;
35693
35858
  }
@@ -35717,17 +35882,17 @@ function resolveOrCwd(maybeRoot) {
35717
35882
  return getProjectRoot();
35718
35883
  }
35719
35884
  function getConfigPath(cwd) {
35720
- return join14(_resolveCleoDir(cwd), "config.json");
35885
+ return join15(_resolveCleoDir(cwd), "config.json");
35721
35886
  }
35722
35887
  function getGlobalConfigPath() {
35723
- return join14(getCleoHome(), "config.json");
35888
+ return join15(getCleoHome(), "config.json");
35724
35889
  }
35725
35890
  function isAbsolutePath(path2) {
35726
35891
  return _isAbsolutePath(path2);
35727
35892
  }
35728
35893
  function _readProjectNameFromInfo(projectRoot) {
35729
35894
  try {
35730
- const infoPath = join14(projectRoot, ".cleo", "project-info.json");
35895
+ const infoPath = join15(projectRoot, ".cleo", "project-info.json");
35731
35896
  if (!existsSync16(infoPath)) return void 0;
35732
35897
  const raw = readFileSync5(infoPath, "utf-8");
35733
35898
  const data = JSON.parse(raw);
@@ -35754,8 +35919,8 @@ async function registerProjectOnEncounter(projectRoot, infoProjectId) {
35754
35919
  if (existingRows.length > 0) {
35755
35920
  const existingPath = existingRows[0].projectPath;
35756
35921
  if (existingPath !== resolvedPath) {
35757
- const newBrainDbPath = join14(resolvedPath, ".cleo", "brain.db");
35758
- const newTasksDbPath = join14(resolvedPath, ".cleo", "tasks.db");
35922
+ const newBrainDbPath = join15(resolvedPath, ".cleo", "brain.db");
35923
+ const newTasksDbPath = join15(resolvedPath, ".cleo", "tasks.db");
35759
35924
  await db.update(projectRegistry2).set({
35760
35925
  projectPath: resolvedPath,
35761
35926
  projectHash: generateProjectHash2(resolvedPath),
@@ -35786,8 +35951,8 @@ async function registerProjectOnEncounter(projectRoot, infoProjectId) {
35786
35951
  lastSync: now,
35787
35952
  taskCount: 0,
35788
35953
  labelsJson: "[]",
35789
- brainDbPath: join14(resolvedPath, ".cleo", "brain.db"),
35790
- tasksDbPath: join14(resolvedPath, ".cleo", "tasks.db"),
35954
+ brainDbPath: join15(resolvedPath, ".cleo", "brain.db"),
35955
+ tasksDbPath: join15(resolvedPath, ".cleo", "tasks.db"),
35791
35956
  statsJson: "{}"
35792
35957
  }).onConflictDoNothing();
35793
35958
  const aliases = canonicalResult.legacyAliases ?? [];
@@ -36004,7 +36169,7 @@ __export(config_exports, {
36004
36169
  });
36005
36170
  import { existsSync as existsSync17 } from "node:fs";
36006
36171
  import { mkdir as mkdir3, writeFile } from "node:fs/promises";
36007
- import { dirname as dirname7 } from "node:path";
36172
+ import { dirname as dirname8 } from "node:path";
36008
36173
  function getNestedValue(obj, path2) {
36009
36174
  const parts = path2.split(".");
36010
36175
  let current = obj;
@@ -36127,7 +36292,7 @@ function parseConfigValue(value) {
36127
36292
  async function setConfigValue(key, value, cwd, opts) {
36128
36293
  const configPath = opts?.global ? getGlobalConfigPath() : getConfigPath(cwd);
36129
36294
  if (!existsSync17(configPath)) {
36130
- const dir = dirname7(configPath);
36295
+ const dir = dirname8(configPath);
36131
36296
  await mkdir3(dir, { recursive: true });
36132
36297
  await writeFile(configPath, "{}", "utf-8");
36133
36298
  }
@@ -36141,7 +36306,7 @@ async function applyStrictnessPreset(preset, cwd, opts) {
36141
36306
  const definition = STRICTNESS_PRESETS[preset];
36142
36307
  const configPath = opts?.global ? getGlobalConfigPath() : getConfigPath(cwd);
36143
36308
  if (!existsSync17(configPath)) {
36144
- const dir = dirname7(configPath);
36309
+ const dir = dirname8(configPath);
36145
36310
  await mkdir3(dir, { recursive: true });
36146
36311
  await writeFile(configPath, "{}", "utf-8");
36147
36312
  }
@@ -37316,9 +37481,9 @@ var init_telemetry_schema = __esm({
37316
37481
 
37317
37482
  // packages/core/src/telemetry/sqlite.ts
37318
37483
  import { mkdirSync as mkdirSync4 } from "node:fs";
37319
- import { dirname as dirname8, join as join15 } from "node:path";
37484
+ import { dirname as dirname9, join as join16 } from "node:path";
37320
37485
  function getTelemetryDbPath() {
37321
- return join15(getCleoHome(), DB_FILENAME);
37486
+ return join16(getCleoHome(), DB_FILENAME);
37322
37487
  }
37323
37488
  function resolveTelemetryMigrationsFolder() {
37324
37489
  return resolveCorePackageMigrationsFolder("drizzle-telemetry");
@@ -37366,7 +37531,7 @@ async function getTelemetryDb() {
37366
37531
  _initPromise2 = (async () => {
37367
37532
  const dbPath = requestedPath;
37368
37533
  _dbPath2 = dbPath;
37369
- mkdirSync4(dirname8(dbPath), { recursive: true });
37534
+ mkdirSync4(dirname9(dbPath), { recursive: true });
37370
37535
  const nativeDb = openNativeDatabase(dbPath);
37371
37536
  _nativeDb2 = nativeDb;
37372
37537
  const db = drizzle({ client: nativeDb, schema: telemetry_schema_exports });
@@ -37400,10 +37565,10 @@ var init_sqlite2 = __esm({
37400
37565
 
37401
37566
  // packages/core/src/store/agent-registry-store.ts
37402
37567
  import { existsSync as existsSync18 } from "node:fs";
37403
- import { join as join16 } from "node:path";
37568
+ import { join as join17 } from "node:path";
37404
37569
  function getGlobalAgentRegistryDbPath() {
37405
37570
  const cleoHome = getCleoHome();
37406
- const dbPath = join16(cleoHome, "cleo.db");
37571
+ const dbPath = join17(cleoHome, "cleo.db");
37407
37572
  if (!dbPath.startsWith(cleoHome)) {
37408
37573
  throw new Error(
37409
37574
  `BUG: getGlobalAgentRegistryDbPath() resolved to "${dbPath}" which is NOT under getCleoHome() ("${cleoHome}"). The Agent Registry is global-only per ADR-037. This indicates a code path that bypasses path resolution \u2014 fix the caller, do not suppress this error.`
@@ -37416,7 +37581,13 @@ function resolveAgentRegistryMigrationsFolder() {
37416
37581
  }
37417
37582
  function runAgentRegistryMigrations(nativeDb) {
37418
37583
  const migrationsFolder = resolveAgentRegistryMigrationsFolder();
37419
- reconcileJournal(nativeDb, migrationsFolder, "_agent_registry_meta", "agent-registry");
37584
+ reconcileJournal(
37585
+ nativeDb,
37586
+ migrationsFolder,
37587
+ "_agent_registry_meta",
37588
+ "agent-registry",
37589
+ resolveConsolidatedJournalSiblings("drizzle-agent-registry")
37590
+ );
37420
37591
  const db = drizzle({ client: nativeDb, schema: agent_registry_exports });
37421
37592
  migrateSanitized(db, { migrationsFolder });
37422
37593
  }
@@ -37510,7 +37681,13 @@ function resolveConduitMigrationsFolder() {
37510
37681
  }
37511
37682
  function runConduitMigrations(nativeDb) {
37512
37683
  const migrationsFolder = resolveConduitMigrationsFolder();
37513
- reconcileJournal(nativeDb, migrationsFolder, "_conduit_meta", "conduit");
37684
+ reconcileJournal(
37685
+ nativeDb,
37686
+ migrationsFolder,
37687
+ "_conduit_meta",
37688
+ "conduit",
37689
+ resolveConsolidatedJournalSiblings("drizzle-conduit")
37690
+ );
37514
37691
  const db = _getDrizzle2()({ client: nativeDb, schema: conduit_exports });
37515
37692
  migrateSanitized(db, { migrationsFolder });
37516
37693
  }
@@ -37744,11 +37921,11 @@ var init_skills_schema = __esm({
37744
37921
  });
37745
37922
 
37746
37923
  // packages/core/src/store/skills-db.ts
37747
- import { join as join17 } from "node:path";
37924
+ import { join as join18 } from "node:path";
37748
37925
  import { and as and3, eq as eq4 } from "drizzle-orm";
37749
37926
  function getDefaultSkillsDbPath() {
37750
37927
  const cleoHome = getCleoHome();
37751
- const dbPath = join17(cleoHome, "cleo.db");
37928
+ const dbPath = join18(cleoHome, "cleo.db");
37752
37929
  if (!dbPath.startsWith(cleoHome)) {
37753
37930
  throw new Error(
37754
37931
  `BUG: getDefaultSkillsDbPath() resolved to "${dbPath}" which is NOT under getCleoHome() ("${cleoHome}"). The skills registry is global-only per SG-CLEO-SKILLS-architecture-v3.md \xA74. Fix the caller, do not suppress.`
@@ -37824,7 +38001,7 @@ import {
37824
38001
  statSync as statSync7,
37825
38002
  unlinkSync as unlinkSync3
37826
38003
  } from "node:fs";
37827
- import { join as join18 } from "node:path";
38004
+ import { join as join19 } from "node:path";
37828
38005
  function resolveInventoryPath(entry, cwd) {
37829
38006
  try {
37830
38007
  if (entry.tier === "global") {
@@ -37859,7 +38036,7 @@ async function openAgentRegistryDbForSnapshot() {
37859
38036
  }
37860
38037
  async function openTelemetryDbForSnapshot() {
37861
38038
  try {
37862
- const path2 = join18(getCleoHome(), "telemetry.db");
38039
+ const path2 = join19(getCleoHome(), "telemetry.db");
37863
38040
  if (!existsSync20(path2)) return null;
37864
38041
  } catch {
37865
38042
  return null;
@@ -37965,8 +38142,8 @@ function rotateSnapshots(backupDir, prefix) {
37965
38142
  const pattern = snapshotPattern(prefix);
37966
38143
  const files = readdirSync4(backupDir).filter((f) => pattern.test(f)).map((f) => ({
37967
38144
  name: f,
37968
- path: join18(backupDir, f),
37969
- mtimeMs: statSync7(join18(backupDir, f)).mtimeMs
38145
+ path: join19(backupDir, f),
38146
+ mtimeMs: statSync7(join19(backupDir, f)).mtimeMs
37970
38147
  })).sort((a, b) => a.mtimeMs - b.mtimeMs);
37971
38148
  while (files.length >= MAX_SNAPSHOTS) {
37972
38149
  const oldest = files.shift();
@@ -37991,7 +38168,7 @@ async function snapshotOne(target, backupDir, now, cwd) {
37991
38168
  if (!db) return;
37992
38169
  opened = db;
37993
38170
  }
37994
- const dest = join18(backupDir, `${target.prefix}-${formatTimestamp(now)}.db`);
38171
+ const dest = join19(backupDir, `${target.prefix}-${formatTimestamp(now)}.db`);
37995
38172
  try {
37996
38173
  db.exec("PRAGMA wal_checkpoint(TRUNCATE)");
37997
38174
  rotateSnapshots(backupDir, target.prefix);
@@ -38012,7 +38189,7 @@ async function vacuumIntoBackup(opts = {}) {
38012
38189
  }
38013
38190
  try {
38014
38191
  const cleoDir = getCleoDir(opts.cwd);
38015
- const backupDir = join18(cleoDir, "backups", "sqlite");
38192
+ const backupDir = join19(cleoDir, "backups", "sqlite");
38016
38193
  mkdirSync5(backupDir, { recursive: true });
38017
38194
  const target = SNAPSHOT_TARGETS.find((t) => t.prefix === prefix);
38018
38195
  if (!target) return;
@@ -38024,13 +38201,13 @@ async function vacuumIntoBackup(opts = {}) {
38024
38201
  function listSqliteBackupsForPrefix(prefix, cwd) {
38025
38202
  try {
38026
38203
  const cleoDir = getCleoDir(cwd);
38027
- const backupDir = join18(cleoDir, "backups", "sqlite");
38204
+ const backupDir = join19(cleoDir, "backups", "sqlite");
38028
38205
  if (!existsSync20(backupDir)) return [];
38029
38206
  const pattern = snapshotPattern(prefix);
38030
38207
  return readdirSync4(backupDir).filter((f) => pattern.test(f)).map((f) => ({
38031
38208
  name: f,
38032
- path: join18(backupDir, f),
38033
- mtimeMs: statSync7(join18(backupDir, f)).mtimeMs
38209
+ path: join19(backupDir, f),
38210
+ mtimeMs: statSync7(join19(backupDir, f)).mtimeMs
38034
38211
  })).sort((a, b) => b.mtimeMs - a.mtimeMs);
38035
38212
  } catch {
38036
38213
  return [];
@@ -38086,7 +38263,7 @@ __export(sqlite_native_exports, {
38086
38263
  import { realpathSync } from "node:fs";
38087
38264
  import { createRequire as createRequire8 } from "node:module";
38088
38265
  import { tmpdir } from "node:os";
38089
- import { delimiter, dirname as dirname9, isAbsolute, join as join19, resolve as resolve4, sep } from "node:path";
38266
+ import { delimiter, dirname as dirname10, isAbsolute, join as join20, resolve as resolve4, sep } from "node:path";
38090
38267
  function getDbSyncConstructor() {
38091
38268
  if (_ctor === null) {
38092
38269
  const mod = _require5("node:sqlite");
@@ -38102,12 +38279,12 @@ function resolveAbsoluteSafe(p) {
38102
38279
  const missingParts = [];
38103
38280
  let cursor = abs;
38104
38281
  while (true) {
38105
- const parent = dirname9(cursor);
38282
+ const parent = dirname10(cursor);
38106
38283
  if (parent === cursor) return abs;
38107
38284
  missingParts.unshift(cursor.slice(parent.length + (parent.endsWith(sep) ? 0 : 1)));
38108
38285
  cursor = parent;
38109
38286
  try {
38110
- return join19(realpathSync(cursor), ...missingParts);
38287
+ return join20(realpathSync(cursor), ...missingParts);
38111
38288
  } catch {
38112
38289
  }
38113
38290
  }
@@ -38374,7 +38551,13 @@ function runMigrations(nativeDb, db) {
38374
38551
  if (tableExists(nativeDb, "tasks") && _dbPath3) {
38375
38552
  createSafetyBackup(_dbPath3);
38376
38553
  }
38377
- reconcileJournal(nativeDb, migrationsFolder, "tasks", "sqlite");
38554
+ reconcileJournal(
38555
+ nativeDb,
38556
+ migrationsFolder,
38557
+ "tasks",
38558
+ "sqlite",
38559
+ resolveConsolidatedJournalSiblings("drizzle-tasks")
38560
+ );
38378
38561
  ensureColumns(nativeDb, "sessions", REQUIRED_SESSION_COLUMNS, "sqlite");
38379
38562
  migrateWithRetry(db, migrationsFolder, nativeDb, "tasks", "sqlite");
38380
38563
  ensureColumns(nativeDb, "tasks", REQUIRED_TASK_COLUMNS, "sqlite");
@@ -39613,12 +39796,12 @@ var init_sqlite_data_accessor = __esm({
39613
39796
 
39614
39797
  // packages/core/src/sequence/index.ts
39615
39798
  import { existsSync as existsSync22, readFileSync as readFileSync6, renameSync as renameSync4 } from "node:fs";
39616
- import { join as join20 } from "node:path";
39799
+ import { join as join21 } from "node:path";
39617
39800
  function getLegacySequenceJsonPath(cwd) {
39618
- return join20(resolveOrCwd(cwd), ".cleo", ".sequence.json");
39801
+ return join21(resolveOrCwd(cwd), ".cleo", ".sequence.json");
39619
39802
  }
39620
39803
  function getLegacySequencePath(cwd) {
39621
- return join20(resolveOrCwd(cwd), ".cleo", ".sequence");
39804
+ return join21(resolveOrCwd(cwd), ".cleo", ".sequence");
39622
39805
  }
39623
39806
  function isValidSequenceState(value) {
39624
39807
  if (!value || typeof value !== "object") return false;
@@ -39806,13 +39989,13 @@ var init_sequence = __esm({
39806
39989
  import { execFile as execFile2 } from "node:child_process";
39807
39990
  import { existsSync as existsSync23 } from "node:fs";
39808
39991
  import { readFile as readFile3, writeFile as writeFile2 } from "node:fs/promises";
39809
- import { join as join21, resolve as resolve5 } from "node:path";
39992
+ import { join as join22, resolve as resolve5 } from "node:path";
39810
39993
  import { promisify as promisify2 } from "node:util";
39811
39994
  function makeCleoGitEnv(cleoDir) {
39812
39995
  const abs = resolve5(cleoDir);
39813
39996
  return {
39814
39997
  ...process.env,
39815
- GIT_DIR: join21(abs, ".git"),
39998
+ GIT_DIR: join22(abs, ".git"),
39816
39999
  GIT_WORK_TREE: abs
39817
40000
  };
39818
40001
  }
@@ -39830,7 +40013,7 @@ async function cleoGitCommand(args, cleoDir) {
39830
40013
  }
39831
40014
  }
39832
40015
  function isCleoGitInitialized(cleoDir) {
39833
- return existsSync23(join21(cleoDir, ".git", "HEAD"));
40016
+ return existsSync23(join22(cleoDir, ".git", "HEAD"));
39834
40017
  }
39835
40018
  async function loadStateFileAllowlist(cwd) {
39836
40019
  try {
@@ -39874,25 +40057,25 @@ async function isCleoGitRepo(cleoDir) {
39874
40057
  return result.success && (result.stdout === "true" || isCleoGitInitialized(cleoDir));
39875
40058
  }
39876
40059
  function isMergeInProgress(cleoDir) {
39877
- return existsSync23(join21(cleoDir, ".git", "MERGE_HEAD"));
40060
+ return existsSync23(join22(cleoDir, ".git", "MERGE_HEAD"));
39878
40061
  }
39879
40062
  async function isDetachedHead(cleoDir) {
39880
40063
  const result = await cleoGitCommand(["symbolic-ref", "HEAD"], cleoDir);
39881
40064
  return !result.success;
39882
40065
  }
39883
40066
  function isRebaseInProgress(cleoDir) {
39884
- return existsSync23(join21(cleoDir, ".git", "rebase-merge")) || existsSync23(join21(cleoDir, ".git", "rebase-apply"));
40067
+ return existsSync23(join22(cleoDir, ".git", "rebase-merge")) || existsSync23(join22(cleoDir, ".git", "rebase-apply"));
39885
40068
  }
39886
40069
  async function recordCheckpointTime(cleoDir) {
39887
40070
  try {
39888
- const stateFile = join21(cleoDir, CHECKPOINT_STATE_FILE);
40071
+ const stateFile = join22(cleoDir, CHECKPOINT_STATE_FILE);
39889
40072
  await writeFile2(stateFile, String(Math.floor(Date.now() / 1e3)));
39890
40073
  } catch {
39891
40074
  }
39892
40075
  }
39893
40076
  async function getLastCheckpointTime(cleoDir) {
39894
40077
  try {
39895
- const stateFile = join21(cleoDir, CHECKPOINT_STATE_FILE);
40078
+ const stateFile = join22(cleoDir, CHECKPOINT_STATE_FILE);
39896
40079
  const content = await readFile3(stateFile, "utf-8");
39897
40080
  const epoch = parseInt(content.trim(), 10);
39898
40081
  return Number.isNaN(epoch) ? 0 : epoch;
@@ -39904,7 +40087,7 @@ async function getChangedStateFiles(cleoDir, cwd) {
39904
40087
  const changed = [];
39905
40088
  const allStateFiles = await getAllStateFiles(cwd);
39906
40089
  for (const stateFile of allStateFiles) {
39907
- const fullPath = join21(cleoDir, stateFile);
40090
+ const fullPath = join22(cleoDir, stateFile);
39908
40091
  if (!existsSync23(fullPath)) continue;
39909
40092
  const diffResult = await cleoGitCommand(["diff", "--quiet", "--", stateFile], cleoDir);
39910
40093
  const cachedResult = await cleoGitCommand(