@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.
- package/dist/docs/export-document.js +322 -139
- package/dist/docs/export-document.js.map +2 -2
- package/dist/llm/plugin-facade.js +414 -248
- package/dist/llm/plugin-facade.js.map +2 -2
- package/dist/store/agent-registry-store.d.ts.map +1 -1
- package/dist/store/agent-registry-store.js +4 -2
- package/dist/store/agent-registry-store.js.map +1 -1
- package/dist/store/conduit-sqlite.d.ts.map +1 -1
- package/dist/store/conduit-sqlite.js +4 -2
- package/dist/store/conduit-sqlite.js.map +1 -1
- package/dist/store/dual-scope-db.d.ts.map +1 -1
- package/dist/store/dual-scope-db.js +71 -6
- package/dist/store/dual-scope-db.js.map +1 -1
- package/dist/store/migration-manager.d.ts +125 -1
- package/dist/store/migration-manager.d.ts.map +1 -1
- package/dist/store/migration-manager.js +427 -27
- package/dist/store/migration-manager.js.map +1 -1
- package/dist/store/nexus-sqlite.d.ts.map +1 -1
- package/dist/store/nexus-sqlite.js +4 -2
- package/dist/store/nexus-sqlite.js.map +1 -1
- package/dist/store/resolve-migrations-folder.d.ts +41 -0
- package/dist/store/resolve-migrations-folder.d.ts.map +1 -1
- package/dist/store/resolve-migrations-folder.js +53 -0
- package/dist/store/resolve-migrations-folder.js.map +1 -1
- package/dist/store/sqlite.d.ts.map +1 -1
- package/dist/store/sqlite.js +5 -3
- package/dist/store/sqlite.js.map +1 -1
- package/package.json +12 -12
|
@@ -14656,7 +14656,7 @@ var init_sql = __esm({
|
|
|
14656
14656
|
return new SQL([new StringChunk(str)]);
|
|
14657
14657
|
}
|
|
14658
14658
|
_sql.raw = raw;
|
|
14659
|
-
function
|
|
14659
|
+
function join28(chunks, separator) {
|
|
14660
14660
|
const result = [];
|
|
14661
14661
|
for (const [i, chunk] of chunks.entries()) {
|
|
14662
14662
|
if (i > 0 && separator !== void 0) result.push(separator);
|
|
@@ -14664,7 +14664,7 @@ var init_sql = __esm({
|
|
|
14664
14664
|
}
|
|
14665
14665
|
return new SQL(result);
|
|
14666
14666
|
}
|
|
14667
|
-
_sql.join =
|
|
14667
|
+
_sql.join = join28;
|
|
14668
14668
|
function identifier(value) {
|
|
14669
14669
|
return new Name(value);
|
|
14670
14670
|
}
|
|
@@ -17051,7 +17051,7 @@ var init_select2 = __esm({
|
|
|
17051
17051
|
const baseTableName = this.tableName;
|
|
17052
17052
|
const tableName = getTableLikeName(table);
|
|
17053
17053
|
for (const item of extractUsedTable(table)) this.usedTables.add(item);
|
|
17054
|
-
if (typeof tableName === "string" && this.config.joins?.some((
|
|
17054
|
+
if (typeof tableName === "string" && this.config.joins?.some((join28) => join28.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
|
|
17055
17055
|
if (!this.isPartialSelect) {
|
|
17056
17056
|
if (Object.keys(this.joinsNotNullableMap).length === 1 && typeof baseTableName === "string") this.config.fields = { [baseTableName]: this.config.fields };
|
|
17057
17057
|
if (typeof tableName === "string" && !is(table, SQL)) {
|
|
@@ -20861,7 +20861,7 @@ var init_dialect = __esm({
|
|
|
20861
20861
|
if (!joins2) return;
|
|
20862
20862
|
const withEntries = Object.entries(joins2).filter(([_, v]) => v);
|
|
20863
20863
|
if (!withEntries.length) return;
|
|
20864
|
-
return sql.join(withEntries.map(([k,
|
|
20864
|
+
return sql.join(withEntries.map(([k, join28]) => {
|
|
20865
20865
|
const relation = tableConfig.relations[k];
|
|
20866
20866
|
const isSingle2 = is(relation, One);
|
|
20867
20867
|
const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
|
|
@@ -20872,7 +20872,7 @@ var init_dialect = __esm({
|
|
|
20872
20872
|
table: targetTable,
|
|
20873
20873
|
mode: isSingle2 ? "first" : "many",
|
|
20874
20874
|
schema,
|
|
20875
|
-
queryConfig:
|
|
20875
|
+
queryConfig: join28,
|
|
20876
20876
|
tableConfig: schema[relation.targetTableName],
|
|
20877
20877
|
relationWhere: filter2,
|
|
20878
20878
|
isNested: true,
|
|
@@ -20886,7 +20886,7 @@ var init_dialect = __esm({
|
|
|
20886
20886
|
key: k,
|
|
20887
20887
|
selection: innerQuery.selection,
|
|
20888
20888
|
isArray: !isSingle2,
|
|
20889
|
-
isOptional: (relation.optional ?? false) ||
|
|
20889
|
+
isOptional: (relation.optional ?? false) || join28 !== true && !!join28.where
|
|
20890
20890
|
});
|
|
20891
20891
|
const jsonColumns = sql.join(innerQuery.selection.map((s) => {
|
|
20892
20892
|
return sql`${sql.raw(this.escapeString(s.key))}, ${s.selection ? sql`${jsonb3}(${sql.identifier(s.key)})` : sql.identifier(s.key)}`;
|
|
@@ -21707,7 +21707,7 @@ var init_update = __esm({
|
|
|
21707
21707
|
createJoin(joinType) {
|
|
21708
21708
|
return ((table, on) => {
|
|
21709
21709
|
const tableName = getTableLikeName(table);
|
|
21710
|
-
if (typeof tableName === "string" && this.config.joins.some((
|
|
21710
|
+
if (typeof tableName === "string" && this.config.joins.some((join28) => join28.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
|
|
21711
21711
|
if (typeof on === "function") {
|
|
21712
21712
|
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;
|
|
21713
21713
|
on = on(new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
|
|
@@ -22651,6 +22651,67 @@ var init_with_retry = __esm({
|
|
|
22651
22651
|
});
|
|
22652
22652
|
|
|
22653
22653
|
// packages/core/src/store/migration-manager.ts
|
|
22654
|
+
import { copyFileSync, existsSync as existsSync2 } from "node:fs";
|
|
22655
|
+
import { dirname, join as join3 } from "node:path";
|
|
22656
|
+
function stripSqlComments(sql32) {
|
|
22657
|
+
return sql32.replace(/--[^\n]*/g, "").replace(/\/\*[\s\S]*?\*\//g, "");
|
|
22658
|
+
}
|
|
22659
|
+
function computeEliminatedTables(migrations) {
|
|
22660
|
+
const createTableRegex = /CREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?[`"]?(\w+)[`"]?/i;
|
|
22661
|
+
const dropTableRegex = /DROP\s+TABLE\s+(?:IF\s+EXISTS\s+)?[`"]?(\w+)[`"]?/i;
|
|
22662
|
+
const renameRegex = /ALTER\s+TABLE\s+[`"]?(\w+)[`"]?\s+RENAME\s+TO\s+[`"]?(\w+)[`"]?/i;
|
|
22663
|
+
const disposition = /* @__PURE__ */ new Map();
|
|
22664
|
+
const ordered = [...migrations].sort((a, b) => a.folderMillis - b.folderMillis);
|
|
22665
|
+
for (const migration of ordered) {
|
|
22666
|
+
const statements = Array.isArray(migration.sql) ? migration.sql : [migration.sql ?? ""];
|
|
22667
|
+
for (const rawStatement of statements) {
|
|
22668
|
+
const stripped = stripSqlComments(rawStatement);
|
|
22669
|
+
for (const clause of stripped.split(";")) {
|
|
22670
|
+
const create = createTableRegex.exec(clause);
|
|
22671
|
+
if (create) {
|
|
22672
|
+
disposition.set(create[1], true);
|
|
22673
|
+
continue;
|
|
22674
|
+
}
|
|
22675
|
+
const rename2 = renameRegex.exec(clause);
|
|
22676
|
+
if (rename2) {
|
|
22677
|
+
disposition.set(rename2[2], true);
|
|
22678
|
+
continue;
|
|
22679
|
+
}
|
|
22680
|
+
const drop = dropTableRegex.exec(clause);
|
|
22681
|
+
if (drop) {
|
|
22682
|
+
disposition.set(drop[1], false);
|
|
22683
|
+
}
|
|
22684
|
+
}
|
|
22685
|
+
}
|
|
22686
|
+
}
|
|
22687
|
+
const eliminated = /* @__PURE__ */ new Set();
|
|
22688
|
+
for (const [table, present] of disposition) {
|
|
22689
|
+
if (!present) eliminated.add(table);
|
|
22690
|
+
}
|
|
22691
|
+
return eliminated;
|
|
22692
|
+
}
|
|
22693
|
+
function resolveConsolidationCutoverPrefix(migrationsFolder) {
|
|
22694
|
+
const parent = dirname(migrationsFolder);
|
|
22695
|
+
for (const setName of ["drizzle-cleo-project", "drizzle-cleo-global"]) {
|
|
22696
|
+
const folder = join3(parent, setName);
|
|
22697
|
+
if (!existsSync2(folder)) continue;
|
|
22698
|
+
try {
|
|
22699
|
+
const consolidation = readMigrationFiles({ migrationsFolder: folder }).find(
|
|
22700
|
+
(m) => /-consolidation-cleo-/.test(m.name ?? "")
|
|
22701
|
+
);
|
|
22702
|
+
if (consolidation?.name) {
|
|
22703
|
+
return consolidation.name.slice(0, MIGRATION_TIMESTAMP_PREFIX_LEN);
|
|
22704
|
+
}
|
|
22705
|
+
} catch {
|
|
22706
|
+
}
|
|
22707
|
+
}
|
|
22708
|
+
return CONSOLIDATION_CUTOVER_PREFIX;
|
|
22709
|
+
}
|
|
22710
|
+
function isAtOrBeforeCutover(migrationName, cutoverPrefix) {
|
|
22711
|
+
const prefix = (migrationName ?? "").slice(0, MIGRATION_TIMESTAMP_PREFIX_LEN);
|
|
22712
|
+
if (prefix.length < MIGRATION_TIMESTAMP_PREFIX_LEN) return true;
|
|
22713
|
+
return prefix <= cutoverPrefix;
|
|
22714
|
+
}
|
|
22654
22715
|
function tableExists(nativeDb, tableName) {
|
|
22655
22716
|
const result = nativeDb.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name=?").get(tableName);
|
|
22656
22717
|
return !!result;
|
|
@@ -22668,9 +22729,9 @@ function insertJournalEntry(nativeDb, hash2, createdAt, name15) {
|
|
|
22668
22729
|
`INSERT OR IGNORE INTO "__drizzle_migrations" ("hash", "created_at", "name") VALUES ('${hash2}', ${createdAt}, '${name15}')`
|
|
22669
22730
|
);
|
|
22670
22731
|
}
|
|
22671
|
-
function probeAndMarkApplied(nativeDb, migration, logSubsystem) {
|
|
22732
|
+
function probeAndMarkApplied(nativeDb, migration, logSubsystem, eliminatedTables = /* @__PURE__ */ new Set(), consolidationCutoverPrefix = CONSOLIDATION_CUTOVER_PREFIX) {
|
|
22672
22733
|
const sqlStatements = Array.isArray(migration.sql) ? migration.sql : [migration.sql ?? ""];
|
|
22673
|
-
const fullSql = sqlStatements.join("\n");
|
|
22734
|
+
const fullSql = stripSqlComments(sqlStatements.join("\n"));
|
|
22674
22735
|
const alterColumnRegex = /ALTER\s+TABLE\s+[`"]?(\w+)[`"]?\s+ADD\s+COLUMN\s+[`"]?(\w+)[`"]?/gi;
|
|
22675
22736
|
const createTableRegex = /CREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?[`"]?(\w+)[`"]?/gi;
|
|
22676
22737
|
const createIndexRegex = /CREATE\s+(?:UNIQUE\s+)?INDEX\s+(?:IF\s+NOT\s+EXISTS\s+)?[`"]?(\w+)[`"]?/gi;
|
|
@@ -22697,10 +22758,17 @@ function probeAndMarkApplied(nativeDb, migration, logSubsystem) {
|
|
|
22697
22758
|
}
|
|
22698
22759
|
const isRebuildOnlyMigration = allCreatedTablesAreRenamed && tableTargets.length > 0 && alterTargets.length === 0;
|
|
22699
22760
|
const performsTableRebuild = renameMap.size > 0;
|
|
22761
|
+
const createIndexWithTableRegex = /CREATE\s+(?:UNIQUE\s+)?INDEX\s+(?:IF\s+NOT\s+EXISTS\s+)?[`"]?(\w+)[`"]?\s+ON\s+[`"]?(\w+)[`"]?/gi;
|
|
22762
|
+
const indexOnTable = /* @__PURE__ */ new Map();
|
|
22763
|
+
for (const m of fullSql.matchAll(createIndexWithTableRegex)) {
|
|
22764
|
+
indexOnTable.set(m[1], m[2]);
|
|
22765
|
+
}
|
|
22700
22766
|
const indexTargets = [];
|
|
22701
22767
|
if (!isRebuildOnlyMigration && !performsTableRebuild) {
|
|
22702
22768
|
for (const m of fullSql.matchAll(createIndexRegex)) {
|
|
22703
|
-
|
|
22769
|
+
const idx = m[1];
|
|
22770
|
+
if (eliminatedTables.has(indexOnTable.get(idx) ?? "")) continue;
|
|
22771
|
+
indexTargets.push(idx);
|
|
22704
22772
|
}
|
|
22705
22773
|
}
|
|
22706
22774
|
const triggerTargets = [];
|
|
@@ -22709,6 +22777,14 @@ function probeAndMarkApplied(nativeDb, migration, logSubsystem) {
|
|
|
22709
22777
|
}
|
|
22710
22778
|
const totalTargets = alterTargets.length + tableTargets.length + indexTargets.length + triggerTargets.length;
|
|
22711
22779
|
if (totalTargets === 0) {
|
|
22780
|
+
if (isAtOrBeforeCutover(migration.name, consolidationCutoverPrefix)) {
|
|
22781
|
+
insertJournalEntry(nativeDb, migration.hash, migration.folderMillis, migration.name ?? "");
|
|
22782
|
+
getLogger(logSubsystem).debug(
|
|
22783
|
+
{ migration: migration.name },
|
|
22784
|
+
`Zero-DDL pre-consolidation migration ${migration.name} stamped applied (subsumed; not re-run).`
|
|
22785
|
+
);
|
|
22786
|
+
return true;
|
|
22787
|
+
}
|
|
22712
22788
|
return false;
|
|
22713
22789
|
}
|
|
22714
22790
|
const allAltersPresent = alterTargets.every(({ table, column }) => {
|
|
@@ -22716,7 +22792,9 @@ function probeAndMarkApplied(nativeDb, migration, logSubsystem) {
|
|
|
22716
22792
|
const cols = nativeDb.prepare(`PRAGMA table_info(${table})`).all();
|
|
22717
22793
|
return cols.some((c) => c.name === column);
|
|
22718
22794
|
});
|
|
22719
|
-
const allTablesPresent = tableTargets.every(
|
|
22795
|
+
const allTablesPresent = tableTargets.every(
|
|
22796
|
+
(t) => tableExists(nativeDb, t) || eliminatedTables.has(t)
|
|
22797
|
+
);
|
|
22720
22798
|
const allIndexesPresent = indexTargets.every((idx) => {
|
|
22721
22799
|
const rows = nativeDb.prepare(`SELECT name FROM sqlite_master WHERE type='index' AND name=?`).all(idx);
|
|
22722
22800
|
return rows.length > 0;
|
|
@@ -22742,7 +22820,28 @@ function probeAndMarkApplied(nativeDb, migration, logSubsystem) {
|
|
|
22742
22820
|
}
|
|
22743
22821
|
return false;
|
|
22744
22822
|
}
|
|
22745
|
-
function
|
|
22823
|
+
function readSiblingMigrationHashes(siblingFolder) {
|
|
22824
|
+
try {
|
|
22825
|
+
return new Set(readMigrationFiles({ migrationsFolder: siblingFolder }).map((m) => m.hash));
|
|
22826
|
+
} catch {
|
|
22827
|
+
return /* @__PURE__ */ new Set();
|
|
22828
|
+
}
|
|
22829
|
+
}
|
|
22830
|
+
function ensureJournalHashUnique(nativeDb) {
|
|
22831
|
+
if (!tableExists(nativeDb, "__drizzle_migrations")) return;
|
|
22832
|
+
try {
|
|
22833
|
+
nativeDb.exec(
|
|
22834
|
+
'DELETE FROM "__drizzle_migrations" WHERE id NOT IN (SELECT MIN(id) FROM "__drizzle_migrations" GROUP BY hash)'
|
|
22835
|
+
);
|
|
22836
|
+
nativeDb.exec(
|
|
22837
|
+
'CREATE UNIQUE INDEX IF NOT EXISTS "idx_drizzle_migrations_hash" ON "__drizzle_migrations" ("hash")'
|
|
22838
|
+
);
|
|
22839
|
+
} catch {
|
|
22840
|
+
}
|
|
22841
|
+
}
|
|
22842
|
+
function reconcileJournal(nativeDb, migrationsFolder, existenceTable2, logSubsystem, siblingMigrationsFolders = []) {
|
|
22843
|
+
const eliminatedTables = computeEliminatedTables(readMigrationFiles({ migrationsFolder }));
|
|
22844
|
+
const cutoverPrefix = resolveConsolidationCutoverPrefix(migrationsFolder);
|
|
22746
22845
|
if (tableExists(nativeDb, existenceTable2) && !tableExists(nativeDb, "__drizzle_migrations")) {
|
|
22747
22846
|
const migrations = readMigrationFiles({ migrationsFolder });
|
|
22748
22847
|
const baseline = migrations[0];
|
|
@@ -22759,11 +22858,19 @@ function reconcileJournal(nativeDb, migrationsFolder, existenceTable2, logSubsys
|
|
|
22759
22858
|
insertJournalEntry(nativeDb, baseline.hash, baseline.folderMillis, baseline.name ?? "");
|
|
22760
22859
|
}
|
|
22761
22860
|
}
|
|
22861
|
+
ensureJournalHashUnique(nativeDb);
|
|
22762
22862
|
if (tableExists(nativeDb, "__drizzle_migrations") && tableExists(nativeDb, existenceTable2)) {
|
|
22763
22863
|
const localMigrations = readMigrationFiles({ migrationsFolder });
|
|
22764
22864
|
const localHashes = new Set(localMigrations.map((m) => m.hash));
|
|
22865
|
+
const knownHashes = new Set(localHashes);
|
|
22866
|
+
for (const siblingFolder of siblingMigrationsFolders) {
|
|
22867
|
+
if (siblingFolder === migrationsFolder) continue;
|
|
22868
|
+
for (const m of readSiblingMigrationHashes(siblingFolder)) {
|
|
22869
|
+
knownHashes.add(m);
|
|
22870
|
+
}
|
|
22871
|
+
}
|
|
22765
22872
|
const dbEntries = nativeDb.prepare('SELECT id, hash FROM "__drizzle_migrations"').all();
|
|
22766
|
-
const orphanedEntries = dbEntries.filter((e) => !
|
|
22873
|
+
const orphanedEntries = dbEntries.filter((e) => !knownHashes.has(e.hash));
|
|
22767
22874
|
const hasOrphanedEntries = orphanedEntries.length > 0;
|
|
22768
22875
|
if (hasOrphanedEntries) {
|
|
22769
22876
|
const dbHashes = new Set(dbEntries.map((e) => e.hash));
|
|
@@ -22786,7 +22893,7 @@ function reconcileJournal(nativeDb, migrationsFolder, existenceTable2, logSubsys
|
|
|
22786
22893
|
);
|
|
22787
22894
|
for (const m of localMigrations) {
|
|
22788
22895
|
if (journaledHashesAfter.has(m.hash)) continue;
|
|
22789
|
-
probeAndMarkApplied(nativeDb, m, logSubsystem);
|
|
22896
|
+
probeAndMarkApplied(nativeDb, m, logSubsystem, eliminatedTables, cutoverPrefix);
|
|
22790
22897
|
}
|
|
22791
22898
|
}
|
|
22792
22899
|
}
|
|
@@ -22809,7 +22916,7 @@ function reconcileJournal(nativeDb, migrationsFolder, existenceTable2, logSubsys
|
|
|
22809
22916
|
});
|
|
22810
22917
|
}
|
|
22811
22918
|
if (alterMatches.length === 0) {
|
|
22812
|
-
const stripped = fullSql
|
|
22919
|
+
const stripped = stripSqlComments(fullSql).trim();
|
|
22813
22920
|
if (stripped === "") {
|
|
22814
22921
|
const log7 = getLogger(logSubsystem);
|
|
22815
22922
|
log7.debug(
|
|
@@ -22828,9 +22935,11 @@ function reconcileJournal(nativeDb, migrationsFolder, existenceTable2, logSubsys
|
|
|
22828
22935
|
const createTableRe = /CREATE\s+TABLE/i;
|
|
22829
22936
|
const createTriggerRe = /CREATE\s+TRIGGER/i;
|
|
22830
22937
|
if (renameRe.test(fullSql) && createTableRe.test(fullSql)) {
|
|
22831
|
-
probeAndMarkApplied(nativeDb, migration, logSubsystem);
|
|
22938
|
+
probeAndMarkApplied(nativeDb, migration, logSubsystem, eliminatedTables, cutoverPrefix);
|
|
22832
22939
|
} else if (createTableRe.test(fullSql) || createTriggerRe.test(fullSql)) {
|
|
22833
|
-
probeAndMarkApplied(nativeDb, migration, logSubsystem);
|
|
22940
|
+
probeAndMarkApplied(nativeDb, migration, logSubsystem, eliminatedTables, cutoverPrefix);
|
|
22941
|
+
} else {
|
|
22942
|
+
probeAndMarkApplied(nativeDb, migration, logSubsystem, eliminatedTables, cutoverPrefix);
|
|
22834
22943
|
}
|
|
22835
22944
|
continue;
|
|
22836
22945
|
}
|
|
@@ -22907,13 +23016,22 @@ function reconcileJournal(nativeDb, migrationsFolder, existenceTable2, logSubsys
|
|
|
22907
23016
|
}
|
|
22908
23017
|
}
|
|
22909
23018
|
}
|
|
23019
|
+
function collectErrorMessages(err) {
|
|
23020
|
+
const messages = [];
|
|
23021
|
+
let current = err;
|
|
23022
|
+
for (let depth = 0; current instanceof Error && depth < 16; depth++) {
|
|
23023
|
+
messages.push(current.message);
|
|
23024
|
+
current = current.cause;
|
|
23025
|
+
}
|
|
23026
|
+
return messages.join("\n");
|
|
23027
|
+
}
|
|
22910
23028
|
function isDuplicateColumnError(err) {
|
|
22911
23029
|
if (!(err instanceof Error)) return false;
|
|
22912
|
-
return /duplicate column name/i.test(err
|
|
23030
|
+
return /duplicate column name/i.test(collectErrorMessages(err));
|
|
22913
23031
|
}
|
|
22914
23032
|
function isTableAlreadyExistsError(err) {
|
|
22915
23033
|
if (!(err instanceof Error)) return false;
|
|
22916
|
-
return /table .+ already exists/i.test(err
|
|
23034
|
+
return /table .+ already exists/i.test(collectErrorMessages(err));
|
|
22917
23035
|
}
|
|
22918
23036
|
function isExecutableStatement(stmt) {
|
|
22919
23037
|
if (stmt.trim() === "") return false;
|
|
@@ -22984,7 +23102,7 @@ function ensureColumns(nativeDb, tableName, requiredColumns, logSubsystem, conte
|
|
|
22984
23102
|
}
|
|
22985
23103
|
}
|
|
22986
23104
|
}
|
|
22987
|
-
var MAX_MIGRATION_RETRIES, MIGRATION_RETRY_BASE_DELAY_MS, MIGRATION_RETRY_MAX_DELAY_MS;
|
|
23105
|
+
var MAX_MIGRATION_RETRIES, MIGRATION_RETRY_BASE_DELAY_MS, MIGRATION_RETRY_MAX_DELAY_MS, CONSOLIDATION_CUTOVER_PREFIX, MIGRATION_TIMESTAMP_PREFIX_LEN;
|
|
22988
23106
|
var init_migration_manager = __esm({
|
|
22989
23107
|
"packages/core/src/store/migration-manager.ts"() {
|
|
22990
23108
|
"use strict";
|
|
@@ -22994,36 +23112,55 @@ var init_migration_manager = __esm({
|
|
|
22994
23112
|
MAX_MIGRATION_RETRIES = 5;
|
|
22995
23113
|
MIGRATION_RETRY_BASE_DELAY_MS = 100;
|
|
22996
23114
|
MIGRATION_RETRY_MAX_DELAY_MS = 2e3;
|
|
23115
|
+
CONSOLIDATION_CUTOVER_PREFIX = "20260531000001";
|
|
23116
|
+
MIGRATION_TIMESTAMP_PREFIX_LEN = 14;
|
|
22997
23117
|
}
|
|
22998
23118
|
});
|
|
22999
23119
|
|
|
23000
23120
|
// packages/core/src/store/resolve-migrations-folder.ts
|
|
23001
23121
|
import { createRequire } from "node:module";
|
|
23002
|
-
import { dirname, join as
|
|
23122
|
+
import { dirname as dirname2, join as join4 } from "node:path";
|
|
23003
23123
|
import { fileURLToPath } from "node:url";
|
|
23004
23124
|
function coreRootFromEntry(entryPath) {
|
|
23005
|
-
return
|
|
23125
|
+
return dirname2(dirname2(entryPath));
|
|
23126
|
+
}
|
|
23127
|
+
function resolveConsolidatedJournalSiblings(ownSetName) {
|
|
23128
|
+
return CONSOLIDATED_JOURNAL_LINEAGES.filter((name15) => name15 !== ownSetName).map(
|
|
23129
|
+
(name15) => resolveCorePackageMigrationsFolder(name15)
|
|
23130
|
+
);
|
|
23006
23131
|
}
|
|
23007
23132
|
function resolveCorePackageMigrationsFolder(setName) {
|
|
23008
23133
|
try {
|
|
23009
23134
|
const resolved = import.meta.resolve("@cleocode/core", import.meta.url);
|
|
23010
23135
|
const entryPath = fileURLToPath(resolved);
|
|
23011
|
-
return
|
|
23136
|
+
return join4(coreRootFromEntry(entryPath), "migrations", setName);
|
|
23012
23137
|
} catch {
|
|
23013
23138
|
}
|
|
23014
23139
|
const _require3 = createRequire(import.meta.url);
|
|
23015
23140
|
try {
|
|
23016
23141
|
const entryPath = _require3.resolve("@cleocode/core");
|
|
23017
|
-
return
|
|
23142
|
+
return join4(coreRootFromEntry(entryPath), "migrations", setName);
|
|
23018
23143
|
} catch (err) {
|
|
23019
23144
|
throw new Error(
|
|
23020
23145
|
`resolveCorePackageMigrationsFolder("${setName}"): cannot locate @cleocode/core from "${import.meta.url}". Ensure @cleocode/core is installed (workspace or npm). Original error: ${err.message}`
|
|
23021
23146
|
);
|
|
23022
23147
|
}
|
|
23023
23148
|
}
|
|
23149
|
+
var CONSOLIDATED_JOURNAL_LINEAGES;
|
|
23024
23150
|
var init_resolve_migrations_folder = __esm({
|
|
23025
23151
|
"packages/core/src/store/resolve-migrations-folder.ts"() {
|
|
23026
23152
|
"use strict";
|
|
23153
|
+
CONSOLIDATED_JOURNAL_LINEAGES = [
|
|
23154
|
+
"drizzle-tasks",
|
|
23155
|
+
"drizzle-cleo-project",
|
|
23156
|
+
"drizzle-nexus",
|
|
23157
|
+
"drizzle-brain",
|
|
23158
|
+
"drizzle-conduit",
|
|
23159
|
+
"drizzle-cleo-global",
|
|
23160
|
+
"drizzle-agent-registry",
|
|
23161
|
+
"drizzle-skills",
|
|
23162
|
+
"drizzle-telemetry"
|
|
23163
|
+
];
|
|
23027
23164
|
}
|
|
23028
23165
|
});
|
|
23029
23166
|
|
|
@@ -31094,11 +31231,11 @@ var init_lock = __esm({
|
|
|
31094
31231
|
|
|
31095
31232
|
// packages/core/src/store/atomic.ts
|
|
31096
31233
|
import { mkdir, readFile as readFile2, rename, unlink } from "node:fs/promises";
|
|
31097
|
-
import { dirname as
|
|
31234
|
+
import { dirname as dirname3 } from "node:path";
|
|
31098
31235
|
import writeFileAtomic from "write-file-atomic";
|
|
31099
31236
|
async function atomicWrite(filePath, data, options) {
|
|
31100
31237
|
try {
|
|
31101
|
-
await mkdir(
|
|
31238
|
+
await mkdir(dirname3(filePath), { recursive: true });
|
|
31102
31239
|
await writeFileAtomic(filePath, data, {
|
|
31103
31240
|
encoding: options?.encoding ?? "utf8",
|
|
31104
31241
|
mode: options?.mode
|
|
@@ -31131,7 +31268,7 @@ var init_atomic = __esm({
|
|
|
31131
31268
|
|
|
31132
31269
|
// packages/core/src/store/backup.ts
|
|
31133
31270
|
import { copyFile, rename as fsRename, mkdir as mkdir2, readdir, stat, unlink as unlink2 } from "node:fs/promises";
|
|
31134
|
-
import { basename, join as
|
|
31271
|
+
import { basename, join as join5 } from "node:path";
|
|
31135
31272
|
async function createBackup(filePath, backupDir, maxBackups = DEFAULT_MAX_BACKUPS) {
|
|
31136
31273
|
try {
|
|
31137
31274
|
await mkdir2(backupDir, { recursive: true });
|
|
@@ -31142,14 +31279,14 @@ async function createBackup(filePath, backupDir, maxBackups = DEFAULT_MAX_BACKUP
|
|
|
31142
31279
|
throw new CleoError(3 /* FILE_ERROR */, `Cannot backup: source file not found: ${filePath}`);
|
|
31143
31280
|
}
|
|
31144
31281
|
for (let i = maxBackups; i >= 1; i--) {
|
|
31145
|
-
const current =
|
|
31282
|
+
const current = join5(backupDir, `${fileName}.${i}`);
|
|
31146
31283
|
if (i === maxBackups) {
|
|
31147
31284
|
try {
|
|
31148
31285
|
await unlink2(current);
|
|
31149
31286
|
} catch {
|
|
31150
31287
|
}
|
|
31151
31288
|
} else {
|
|
31152
|
-
const next =
|
|
31289
|
+
const next = join5(backupDir, `${fileName}.${i + 1}`);
|
|
31153
31290
|
try {
|
|
31154
31291
|
await stat(current);
|
|
31155
31292
|
await fsRename(current, next);
|
|
@@ -31157,7 +31294,7 @@ async function createBackup(filePath, backupDir, maxBackups = DEFAULT_MAX_BACKUP
|
|
|
31157
31294
|
}
|
|
31158
31295
|
}
|
|
31159
31296
|
}
|
|
31160
|
-
const backupPath =
|
|
31297
|
+
const backupPath = join5(backupDir, `${fileName}.1`);
|
|
31161
31298
|
await copyFile(filePath, backupPath);
|
|
31162
31299
|
return backupPath;
|
|
31163
31300
|
} catch (err) {
|
|
@@ -31436,16 +31573,16 @@ var init_json2 = __esm({
|
|
|
31436
31573
|
});
|
|
31437
31574
|
|
|
31438
31575
|
// packages/core/src/scaffold/ensure-config.ts
|
|
31439
|
-
import { existsSync as
|
|
31440
|
-
import { basename as basename2, dirname as
|
|
31576
|
+
import { existsSync as existsSync3, readFileSync } from "node:fs";
|
|
31577
|
+
import { basename as basename2, dirname as dirname4, join as join6, resolve as resolve2 } from "node:path";
|
|
31441
31578
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
31442
31579
|
function getPackageRoot() {
|
|
31443
31580
|
const thisFile = fileURLToPath2(import.meta.url);
|
|
31444
|
-
return resolve2(
|
|
31581
|
+
return resolve2(dirname4(thisFile), "..", "..");
|
|
31445
31582
|
}
|
|
31446
31583
|
function getCleoVersion() {
|
|
31447
31584
|
try {
|
|
31448
|
-
const pkgPath =
|
|
31585
|
+
const pkgPath = join6(getPackageRoot(), "package.json");
|
|
31449
31586
|
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
31450
31587
|
return pkg.version ?? "0.0.0";
|
|
31451
31588
|
} catch {
|
|
@@ -31463,26 +31600,26 @@ var init_ensure_config = __esm({
|
|
|
31463
31600
|
|
|
31464
31601
|
// packages/core/src/store/exodus/archive.ts
|
|
31465
31602
|
import {
|
|
31466
|
-
copyFileSync,
|
|
31467
|
-
existsSync as
|
|
31603
|
+
copyFileSync as copyFileSync2,
|
|
31604
|
+
existsSync as existsSync4,
|
|
31468
31605
|
mkdirSync,
|
|
31469
31606
|
renameSync,
|
|
31470
31607
|
unlinkSync,
|
|
31471
31608
|
writeFileSync
|
|
31472
31609
|
} from "node:fs";
|
|
31473
|
-
import { basename as basename3, join as
|
|
31610
|
+
import { basename as basename3, join as join7 } from "node:path";
|
|
31474
31611
|
function scopeBaseDir(scope, cwd) {
|
|
31475
31612
|
return scope === "project" ? resolveCleoDir(cwd) : getCleoHome();
|
|
31476
31613
|
}
|
|
31477
31614
|
function exodusArchiveDir(scope, cwd) {
|
|
31478
|
-
return
|
|
31615
|
+
return join7(scopeBaseDir(scope, cwd), ARCHIVE_DIR_NAME);
|
|
31479
31616
|
}
|
|
31480
31617
|
function exodusMarkerPath(scope, cwd) {
|
|
31481
|
-
return
|
|
31618
|
+
return join7(scopeBaseDir(scope, cwd), MARKER_FILENAME_BY_SCOPE[scope]);
|
|
31482
31619
|
}
|
|
31483
31620
|
function hasExodusCompleteMarker(scope, cwd) {
|
|
31484
31621
|
try {
|
|
31485
|
-
return
|
|
31622
|
+
return existsSync4(exodusMarkerPath(scope, cwd));
|
|
31486
31623
|
} catch {
|
|
31487
31624
|
return false;
|
|
31488
31625
|
}
|
|
@@ -31506,28 +31643,28 @@ function writeExodusCompleteMarker(scope, archivedSources, cwd) {
|
|
|
31506
31643
|
}
|
|
31507
31644
|
function moveFileInto(srcPath, destDir) {
|
|
31508
31645
|
mkdirSync(destDir, { recursive: true });
|
|
31509
|
-
let dest =
|
|
31510
|
-
if (
|
|
31646
|
+
let dest = join7(destDir, basename3(srcPath));
|
|
31647
|
+
if (existsSync4(dest)) {
|
|
31511
31648
|
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "").replace(/Z$/, "Z");
|
|
31512
|
-
dest =
|
|
31649
|
+
dest = join7(destDir, `${basename3(srcPath)}.${stamp}`);
|
|
31513
31650
|
}
|
|
31514
31651
|
try {
|
|
31515
31652
|
renameSync(srcPath, dest);
|
|
31516
31653
|
} catch {
|
|
31517
|
-
|
|
31654
|
+
copyFileSync2(srcPath, dest);
|
|
31518
31655
|
unlinkSync(srcPath);
|
|
31519
31656
|
}
|
|
31520
31657
|
return dest;
|
|
31521
31658
|
}
|
|
31522
31659
|
function archiveSourceDb(source, cwd) {
|
|
31523
|
-
if (!
|
|
31660
|
+
if (!existsSync4(source.path)) {
|
|
31524
31661
|
return { name: source.name, sourcePath: source.path, archivedTo: null, action: "absent" };
|
|
31525
31662
|
}
|
|
31526
31663
|
const destDir = exodusArchiveDir(source.targetScope, cwd);
|
|
31527
31664
|
const archivedTo = moveFileInto(source.path, destDir);
|
|
31528
31665
|
for (const suffix of SIDECAR_SUFFIXES) {
|
|
31529
31666
|
const sidecar = `${source.path}${suffix}`;
|
|
31530
|
-
if (
|
|
31667
|
+
if (existsSync4(sidecar)) {
|
|
31531
31668
|
try {
|
|
31532
31669
|
moveFileInto(sidecar, destDir);
|
|
31533
31670
|
} catch (err) {
|
|
@@ -31573,7 +31710,7 @@ function detectStrandedResidue(sources, cwd) {
|
|
|
31573
31710
|
const stranded = [];
|
|
31574
31711
|
for (const source of sources) {
|
|
31575
31712
|
if (!markedScopes.has(source.targetScope)) continue;
|
|
31576
|
-
if (
|
|
31713
|
+
if (existsSync4(source.path)) {
|
|
31577
31714
|
stranded.push({ name: source.name, path: source.path, scope: source.targetScope });
|
|
31578
31715
|
}
|
|
31579
31716
|
}
|
|
@@ -31990,7 +32127,7 @@ var init_table_name_map = __esm({
|
|
|
31990
32127
|
});
|
|
31991
32128
|
|
|
31992
32129
|
// packages/core/src/store/exodus/count-parity.ts
|
|
31993
|
-
import { existsSync as
|
|
32130
|
+
import { existsSync as existsSync5 } from "node:fs";
|
|
31994
32131
|
function listTables(db) {
|
|
31995
32132
|
return db.prepare(
|
|
31996
32133
|
"SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' AND name NOT LIKE '__drizzle_%' ORDER BY name"
|
|
@@ -32011,14 +32148,14 @@ function rowCount(db, tableName) {
|
|
|
32011
32148
|
function computeCountParity(sources, projectDbPath, globalDbPath) {
|
|
32012
32149
|
const entries = [];
|
|
32013
32150
|
let skipped = 0;
|
|
32014
|
-
if (!
|
|
32151
|
+
if (!existsSync5(projectDbPath) || !existsSync5(globalDbPath)) {
|
|
32015
32152
|
return { ok: false, entries: [], deficits: [], checked: 0, skipped: 0 };
|
|
32016
32153
|
}
|
|
32017
32154
|
const projectSnap = openCleoDbSnapshot(projectDbPath, { readOnly: true });
|
|
32018
32155
|
const globalSnap = openCleoDbSnapshot(globalDbPath, { readOnly: true });
|
|
32019
32156
|
try {
|
|
32020
32157
|
for (const src of sources) {
|
|
32021
|
-
if (!
|
|
32158
|
+
if (!existsSync5(src.path)) continue;
|
|
32022
32159
|
const srcSnap = openCleoDbSnapshot(src.path, { readOnly: true });
|
|
32023
32160
|
try {
|
|
32024
32161
|
for (const legacyTable of listTables(srcSnap.db)) {
|
|
@@ -32076,8 +32213,8 @@ var init_count_parity = __esm({
|
|
|
32076
32213
|
});
|
|
32077
32214
|
|
|
32078
32215
|
// packages/core/src/store/exodus/plan.ts
|
|
32079
|
-
import { existsSync as
|
|
32080
|
-
import { join as
|
|
32216
|
+
import { existsSync as existsSync6, readdirSync as readdirSync2, statfsSync, statSync } from "node:fs";
|
|
32217
|
+
import { join as join8 } from "node:path";
|
|
32081
32218
|
function computeRequiredBytes(totalSourceBytes, largestSourceBytes) {
|
|
32082
32219
|
return Math.ceil(STAGING_HEADROOM_FACTOR * largestSourceBytes) + totalSourceBytes;
|
|
32083
32220
|
}
|
|
@@ -32088,33 +32225,33 @@ function buildSourceDescriptors(cwd) {
|
|
|
32088
32225
|
// Project-tier — go into consolidated project-scope cleo.db
|
|
32089
32226
|
{
|
|
32090
32227
|
name: "tasks",
|
|
32091
|
-
path:
|
|
32228
|
+
path: join8(cleoDir, "tasks.db"),
|
|
32092
32229
|
targetScope: "project"
|
|
32093
32230
|
},
|
|
32094
32231
|
{
|
|
32095
32232
|
name: "brain (project)",
|
|
32096
|
-
path:
|
|
32233
|
+
path: join8(cleoDir, "brain.db"),
|
|
32097
32234
|
targetScope: "project"
|
|
32098
32235
|
},
|
|
32099
32236
|
{
|
|
32100
32237
|
name: "conduit",
|
|
32101
|
-
path:
|
|
32238
|
+
path: join8(cleoDir, "conduit.db"),
|
|
32102
32239
|
targetScope: "project"
|
|
32103
32240
|
},
|
|
32104
32241
|
// Global-tier — go into consolidated global-scope cleo.db
|
|
32105
32242
|
{
|
|
32106
32243
|
name: "nexus",
|
|
32107
|
-
path:
|
|
32244
|
+
path: join8(cleoHome, "nexus.db"),
|
|
32108
32245
|
targetScope: "global"
|
|
32109
32246
|
},
|
|
32110
32247
|
{
|
|
32111
32248
|
name: "signaldock",
|
|
32112
|
-
path:
|
|
32249
|
+
path: join8(cleoHome, "signaldock.db"),
|
|
32113
32250
|
targetScope: "global"
|
|
32114
32251
|
},
|
|
32115
32252
|
{
|
|
32116
32253
|
name: "skills",
|
|
32117
|
-
path:
|
|
32254
|
+
path: join8(cleoHome, "skills.db"),
|
|
32118
32255
|
targetScope: "global"
|
|
32119
32256
|
}
|
|
32120
32257
|
];
|
|
@@ -32143,7 +32280,7 @@ function findExistingStaging(cleoDir) {
|
|
|
32143
32280
|
const entries = readdirSync2(cleoDir, { withFileTypes: true });
|
|
32144
32281
|
const stagingDirs = entries.filter((e) => e.isDirectory() && e.name.startsWith("exodus-staging-")).map((e) => e.name).sort().reverse();
|
|
32145
32282
|
if (stagingDirs.length > 0) {
|
|
32146
|
-
return
|
|
32283
|
+
return join8(cleoDir, stagingDirs[0]);
|
|
32147
32284
|
}
|
|
32148
32285
|
} catch {
|
|
32149
32286
|
}
|
|
@@ -32159,7 +32296,7 @@ function buildExodusPlan(cwd) {
|
|
|
32159
32296
|
const availableBytes = getAvailableBytes(cleoDir);
|
|
32160
32297
|
const diskPreflight = totalSourceBytes === 0 || availableBytes >= requiredBytes;
|
|
32161
32298
|
const existingStaging = findExistingStaging(cleoDir);
|
|
32162
|
-
const stagingDir = existingStaging ??
|
|
32299
|
+
const stagingDir = existingStaging ?? join8(cleoDir, deriveStagingDirName());
|
|
32163
32300
|
const resumeFromStaging = existingStaging !== null;
|
|
32164
32301
|
const projectDbPath = resolveDualScopeDbPath("project", cwd);
|
|
32165
32302
|
const globalDbPath = resolveDualScopeDbPath("global");
|
|
@@ -32178,7 +32315,7 @@ function buildExodusPlan(cwd) {
|
|
|
32178
32315
|
};
|
|
32179
32316
|
}
|
|
32180
32317
|
function sourcesPresent(sources) {
|
|
32181
|
-
return sources.some((s) =>
|
|
32318
|
+
return sources.some((s) => existsSync6(s.path));
|
|
32182
32319
|
}
|
|
32183
32320
|
var STAGING_HEADROOM_FACTOR, STAGING_COPY_SKIP_THRESHOLD_BYTES;
|
|
32184
32321
|
var init_plan2 = __esm({
|
|
@@ -32192,18 +32329,18 @@ var init_plan2 = __esm({
|
|
|
32192
32329
|
});
|
|
32193
32330
|
|
|
32194
32331
|
// packages/core/src/store/exodus/health.ts
|
|
32195
|
-
import { existsSync as
|
|
32332
|
+
import { existsSync as existsSync7, statSync as statSync2 } from "node:fs";
|
|
32196
32333
|
function buildExodusHealth(cwd) {
|
|
32197
32334
|
const plan = buildExodusPlan(cwd);
|
|
32198
|
-
const anyLegacyPresent = plan.sources.some((s) =>
|
|
32335
|
+
const anyLegacyPresent = plan.sources.some((s) => existsSync7(s.path));
|
|
32199
32336
|
const parity = anyLegacyPresent ? computeCountParity(plan.sources, plan.projectDbPath, plan.globalDbPath) : { ok: true, entries: [], deficits: [], checked: 0, skipped: 0 };
|
|
32200
32337
|
const consolidatedExistsByScope = {
|
|
32201
|
-
project:
|
|
32202
|
-
global:
|
|
32338
|
+
project: existsSync7(plan.projectDbPath),
|
|
32339
|
+
global: existsSync7(plan.globalDbPath)
|
|
32203
32340
|
};
|
|
32204
32341
|
const buildScope = (scope) => {
|
|
32205
32342
|
const sources = plan.sources.filter((s) => s.targetScope === scope).map((s) => {
|
|
32206
|
-
const present =
|
|
32343
|
+
const present = existsSync7(s.path);
|
|
32207
32344
|
let bytes = 0;
|
|
32208
32345
|
if (present) {
|
|
32209
32346
|
try {
|
|
@@ -32469,8 +32606,8 @@ var init_types = __esm({
|
|
|
32469
32606
|
|
|
32470
32607
|
// packages/core/src/store/exodus/migrate.ts
|
|
32471
32608
|
import {
|
|
32472
|
-
copyFileSync as
|
|
32473
|
-
existsSync as
|
|
32609
|
+
copyFileSync as copyFileSync3,
|
|
32610
|
+
existsSync as existsSync8,
|
|
32474
32611
|
mkdirSync as mkdirSync2,
|
|
32475
32612
|
readFileSync as readFileSync2,
|
|
32476
32613
|
renameSync as renameSync2,
|
|
@@ -32478,7 +32615,7 @@ import {
|
|
|
32478
32615
|
unlinkSync as unlinkSync2,
|
|
32479
32616
|
writeFileSync as writeFileSync2
|
|
32480
32617
|
} from "node:fs";
|
|
32481
|
-
import { join as
|
|
32618
|
+
import { join as join9 } from "node:path";
|
|
32482
32619
|
function getSqliteVersion(db) {
|
|
32483
32620
|
try {
|
|
32484
32621
|
const row = db.prepare("SELECT sqlite_version() AS v").get();
|
|
@@ -32494,14 +32631,14 @@ function listTables2(db) {
|
|
|
32494
32631
|
return rows.map((r) => r.name);
|
|
32495
32632
|
}
|
|
32496
32633
|
function writeJournal(stagingDir, journal) {
|
|
32497
|
-
const journalPath =
|
|
32634
|
+
const journalPath = join9(stagingDir, JOURNAL_FILENAME);
|
|
32498
32635
|
const tmpPath = `${journalPath}.tmp`;
|
|
32499
32636
|
writeFileSync2(tmpPath, JSON.stringify(journal, null, 2) + "\n", "utf8");
|
|
32500
32637
|
renameSync2(tmpPath, journalPath);
|
|
32501
32638
|
}
|
|
32502
32639
|
function readJournal(stagingDir) {
|
|
32503
|
-
const journalPath =
|
|
32504
|
-
if (!
|
|
32640
|
+
const journalPath = join9(stagingDir, JOURNAL_FILENAME);
|
|
32641
|
+
if (!existsSync8(journalPath)) return null;
|
|
32505
32642
|
try {
|
|
32506
32643
|
return JSON.parse(readFileSync2(journalPath, "utf8"));
|
|
32507
32644
|
} catch {
|
|
@@ -32509,9 +32646,9 @@ function readJournal(stagingDir) {
|
|
|
32509
32646
|
}
|
|
32510
32647
|
}
|
|
32511
32648
|
function clearExodusJournal(stagingDir) {
|
|
32512
|
-
const journalPath =
|
|
32649
|
+
const journalPath = join9(stagingDir, JOURNAL_FILENAME);
|
|
32513
32650
|
try {
|
|
32514
|
-
if (!
|
|
32651
|
+
if (!existsSync8(journalPath)) return false;
|
|
32515
32652
|
unlinkSync2(journalPath);
|
|
32516
32653
|
log3.info(
|
|
32517
32654
|
{ stagingDir },
|
|
@@ -32776,7 +32913,7 @@ async function runExodusMigrate(plan, forceCrossVersion = false, onProgress) {
|
|
|
32776
32913
|
mkdirSync2(stagingDir, { recursive: true });
|
|
32777
32914
|
let sqliteVersion = "unknown";
|
|
32778
32915
|
for (const src of sources) {
|
|
32779
|
-
if (
|
|
32916
|
+
if (existsSync8(src.path)) {
|
|
32780
32917
|
const snap = openCleoDbSnapshot(src.path, { readOnly: true });
|
|
32781
32918
|
sqliteVersion = getSqliteVersion(snap.db);
|
|
32782
32919
|
snap.close();
|
|
@@ -32817,17 +32954,17 @@ async function runExodusMigrate(plan, forceCrossVersion = false, onProgress) {
|
|
|
32817
32954
|
};
|
|
32818
32955
|
var extractNativeDb = extractNativeDb2;
|
|
32819
32956
|
for (const src of sources) {
|
|
32820
|
-
if (!
|
|
32821
|
-
const backupDest =
|
|
32957
|
+
if (!existsSync8(src.path)) continue;
|
|
32958
|
+
const backupDest = join9(stagingDir, `${src.name.replace(/[^a-z0-9-]/g, "_")}-backup.db`);
|
|
32822
32959
|
const srcBytes = safeStatBytes(src.path);
|
|
32823
32960
|
const skipStagingCopy = srcBytes > plan.stagingCopyThresholdBytes;
|
|
32824
32961
|
if (skipStagingCopy) {
|
|
32825
32962
|
onProgress?.(
|
|
32826
32963
|
`Skipping full staging copy of ${src.name} (${srcBytes} bytes > ${plan.stagingCopyThresholdBytes} threshold) \u2014 source is archived, not deleted, on success.`
|
|
32827
32964
|
);
|
|
32828
|
-
} else if (!
|
|
32965
|
+
} else if (!existsSync8(backupDest)) {
|
|
32829
32966
|
onProgress?.(`Backing up ${src.name} \u2192 staging dir\u2026`);
|
|
32830
|
-
|
|
32967
|
+
copyFileSync3(src.path, backupDest);
|
|
32831
32968
|
backupPaths.push(backupDest);
|
|
32832
32969
|
}
|
|
32833
32970
|
acquireAdvisoryLock(src.path);
|
|
@@ -32843,8 +32980,8 @@ async function runExodusMigrate(plan, forceCrossVersion = false, onProgress) {
|
|
|
32843
32980
|
});
|
|
32844
32981
|
const projectNative = extractNativeDb2(projectHandle);
|
|
32845
32982
|
const globalNative = extractNativeDb2(globalHandle);
|
|
32846
|
-
const projectSources = sources.filter((s) => s.targetScope === "project" &&
|
|
32847
|
-
const globalSources = sources.filter((s) => s.targetScope === "global" &&
|
|
32983
|
+
const projectSources = sources.filter((s) => s.targetScope === "project" && existsSync8(s.path));
|
|
32984
|
+
const globalSources = sources.filter((s) => s.targetScope === "global" && existsSync8(s.path));
|
|
32848
32985
|
await migrateScope(
|
|
32849
32986
|
"project",
|
|
32850
32987
|
projectSources,
|
|
@@ -33119,11 +33256,11 @@ var init_seal = __esm({
|
|
|
33119
33256
|
});
|
|
33120
33257
|
|
|
33121
33258
|
// packages/core/src/store/exodus/status.ts
|
|
33122
|
-
import { existsSync as
|
|
33123
|
-
import { join as
|
|
33259
|
+
import { existsSync as existsSync9, readdirSync as readdirSync3, readFileSync as readFileSync3, statSync as statSync4 } from "node:fs";
|
|
33260
|
+
import { join as join10 } from "node:path";
|
|
33124
33261
|
function readJournal2(stagingDir) {
|
|
33125
|
-
const p =
|
|
33126
|
-
if (!
|
|
33262
|
+
const p = join10(stagingDir, JOURNAL_FILENAME2);
|
|
33263
|
+
if (!existsSync9(p)) return null;
|
|
33127
33264
|
try {
|
|
33128
33265
|
return JSON.parse(readFileSync3(p, "utf8"));
|
|
33129
33266
|
} catch {
|
|
@@ -33132,7 +33269,7 @@ function readJournal2(stagingDir) {
|
|
|
33132
33269
|
}
|
|
33133
33270
|
function findStagingDirs(cleoDir) {
|
|
33134
33271
|
try {
|
|
33135
|
-
return readdirSync3(cleoDir, { withFileTypes: true }).filter((e) => e.isDirectory() && e.name.startsWith("exodus-staging-")).map((e) =>
|
|
33272
|
+
return readdirSync3(cleoDir, { withFileTypes: true }).filter((e) => e.isDirectory() && e.name.startsWith("exodus-staging-")).map((e) => join10(cleoDir, e.name)).sort().reverse();
|
|
33136
33273
|
} catch {
|
|
33137
33274
|
return [];
|
|
33138
33275
|
}
|
|
@@ -33155,15 +33292,15 @@ function runExodusStatus(cwd) {
|
|
|
33155
33292
|
const sourcesInfo = plan.sources.map((s) => ({
|
|
33156
33293
|
name: s.name,
|
|
33157
33294
|
path: s.path,
|
|
33158
|
-
exists:
|
|
33295
|
+
exists: existsSync9(s.path),
|
|
33159
33296
|
bytes: safeBytes(s.path)
|
|
33160
33297
|
}));
|
|
33161
33298
|
return {
|
|
33162
33299
|
hasStaging: latestStaging !== null,
|
|
33163
33300
|
stagingDir: latestStaging,
|
|
33164
33301
|
journal,
|
|
33165
|
-
projectDbExists:
|
|
33166
|
-
globalDbExists:
|
|
33302
|
+
projectDbExists: existsSync9(projectDbPath),
|
|
33303
|
+
globalDbExists: existsSync9(globalDbPath),
|
|
33167
33304
|
sourcesPresent: sourcesInfo.some((s) => s.exists),
|
|
33168
33305
|
sources: sourcesInfo
|
|
33169
33306
|
};
|
|
@@ -33180,7 +33317,7 @@ var init_status = __esm({
|
|
|
33180
33317
|
});
|
|
33181
33318
|
|
|
33182
33319
|
// packages/core/src/store/exodus/verify-migration.ts
|
|
33183
|
-
import { existsSync as
|
|
33320
|
+
import { existsSync as existsSync10 } from "node:fs";
|
|
33184
33321
|
import { createRequire as createRequire3 } from "node:module";
|
|
33185
33322
|
function orderByClause(db, tableName) {
|
|
33186
33323
|
try {
|
|
@@ -33428,7 +33565,7 @@ function verifyMigration(sources, projectDbPath, globalDbPath, onProgress) {
|
|
|
33428
33565
|
const preExistingForeignKeyViolations = [];
|
|
33429
33566
|
const failureLines = [];
|
|
33430
33567
|
const sourceOrphanSigs = /* @__PURE__ */ new Set();
|
|
33431
|
-
if (!
|
|
33568
|
+
if (!existsSync10(projectDbPath)) {
|
|
33432
33569
|
return {
|
|
33433
33570
|
ok: false,
|
|
33434
33571
|
tables: [],
|
|
@@ -33439,7 +33576,7 @@ function verifyMigration(sources, projectDbPath, globalDbPath, onProgress) {
|
|
|
33439
33576
|
error: `Consolidated project cleo.db not found at ${projectDbPath}. Run 'cleo exodus migrate' first.`
|
|
33440
33577
|
};
|
|
33441
33578
|
}
|
|
33442
|
-
if (!
|
|
33579
|
+
if (!existsSync10(globalDbPath)) {
|
|
33443
33580
|
return {
|
|
33444
33581
|
ok: false,
|
|
33445
33582
|
tables: [],
|
|
@@ -33454,7 +33591,7 @@ function verifyMigration(sources, projectDbPath, globalDbPath, onProgress) {
|
|
|
33454
33591
|
const globalSnap = openCleoDbSnapshot(globalDbPath, { readOnly: true });
|
|
33455
33592
|
try {
|
|
33456
33593
|
for (const src of sources) {
|
|
33457
|
-
if (!
|
|
33594
|
+
if (!existsSync10(src.path)) {
|
|
33458
33595
|
onProgress?.(`Skipping ${src.name} (not present)`);
|
|
33459
33596
|
continue;
|
|
33460
33597
|
}
|
|
@@ -33737,7 +33874,7 @@ __export(on_open_exports, {
|
|
|
33737
33874
|
isDataContinuityOk: () => isDataContinuityOk,
|
|
33738
33875
|
maybeRunExodusOnOpen: () => maybeRunExodusOnOpen
|
|
33739
33876
|
});
|
|
33740
|
-
import { existsSync as
|
|
33877
|
+
import { existsSync as existsSync11 } from "node:fs";
|
|
33741
33878
|
function isDisabledByEnv() {
|
|
33742
33879
|
const v = process.env.CLEO_DISABLE_EXODUS_ON_OPEN;
|
|
33743
33880
|
return v === "1" || v === "true";
|
|
@@ -33852,7 +33989,7 @@ async function maybeRunExodusOnOpen(scope, dbPath, nativeDb, cwd) {
|
|
|
33852
33989
|
const { buildExodusPlan: buildExodusPlan2, runExodusMigrate: runExodusMigrate2, verifyMigration: verifyMigration2, clearExodusJournal: clearExodusJournal2 } = await Promise.resolve().then(() => (init_exodus(), exodus_exports));
|
|
33853
33990
|
const plan = buildExodusPlan2(cwd);
|
|
33854
33991
|
const scopeSources = plan.sources.filter((s) => s.targetScope === scope);
|
|
33855
|
-
if (!scopeSources.some((s) =>
|
|
33992
|
+
if (!scopeSources.some((s) => existsSync11(s.path))) {
|
|
33856
33993
|
return {
|
|
33857
33994
|
outcome: "skipped",
|
|
33858
33995
|
reason: `no legacy ${scope}-scope source DBs present (fresh install or cross-scope-only)`
|
|
@@ -33869,7 +34006,7 @@ async function maybeRunExodusOnOpen(scope, dbPath, nativeDb, cwd) {
|
|
|
33869
34006
|
{
|
|
33870
34007
|
scope,
|
|
33871
34008
|
dbPath,
|
|
33872
|
-
sources: plan.sources.filter((s) =>
|
|
34009
|
+
sources: plan.sources.filter((s) => existsSync11(s.path)).map((s) => s.name)
|
|
33873
34010
|
},
|
|
33874
34011
|
"exodus-on-open: consolidated cleo.db is empty and legacy data present \u2014 auto-migrating"
|
|
33875
34012
|
);
|
|
@@ -33925,7 +34062,7 @@ async function maybeRunExodusOnOpen(scope, dbPath, nativeDb, cwd) {
|
|
|
33925
34062
|
"exodus-on-open: parity verified \u2014 legacy data migrated into consolidated cleo.db"
|
|
33926
34063
|
);
|
|
33927
34064
|
try {
|
|
33928
|
-
const consumed = plan.sources.filter((s) =>
|
|
34065
|
+
const consumed = plan.sources.filter((s) => existsSync11(s.path));
|
|
33929
34066
|
const archiveResult = archiveMigratedSources(consumed, cwd);
|
|
33930
34067
|
log6.info(
|
|
33931
34068
|
{
|
|
@@ -33982,9 +34119,9 @@ __export(dual_scope_db_exports, {
|
|
|
33982
34119
|
resolveDualScopeDbPath: () => resolveDualScopeDbPath,
|
|
33983
34120
|
upsertIdempotent: () => upsertIdempotent
|
|
33984
34121
|
});
|
|
33985
|
-
import { existsSync as
|
|
34122
|
+
import { existsSync as existsSync12, mkdirSync as mkdirSync3 } from "node:fs";
|
|
33986
34123
|
import { createRequire as createRequire4 } from "node:module";
|
|
33987
|
-
import { dirname as
|
|
34124
|
+
import { dirname as dirname5, join as join11 } from "node:path";
|
|
33988
34125
|
function assertWriteDurable(handle) {
|
|
33989
34126
|
if (handle.exodusAbort) {
|
|
33990
34127
|
throw new ExodusAbortWriteUnsafeError(handle.exodusAbort);
|
|
@@ -34001,9 +34138,9 @@ function cacheKey(scope, dbPath) {
|
|
|
34001
34138
|
}
|
|
34002
34139
|
function resolveDualScopeDbPath(scope, cwd) {
|
|
34003
34140
|
if (scope === "project") {
|
|
34004
|
-
return
|
|
34141
|
+
return join11(resolveCleoDir(cwd), "cleo.db");
|
|
34005
34142
|
}
|
|
34006
|
-
return
|
|
34143
|
+
return join11(getCleoHome(), "cleo.db");
|
|
34007
34144
|
}
|
|
34008
34145
|
function migrationsSetName(scope) {
|
|
34009
34146
|
return scope === "project" ? "drizzle-cleo-project" : "drizzle-cleo-global";
|
|
@@ -34037,24 +34174,35 @@ async function loadGlobalSchema() {
|
|
|
34037
34174
|
function existenceTable(scope) {
|
|
34038
34175
|
return scope === "project" ? "tasks_tasks" : "nexus_project_registry";
|
|
34039
34176
|
}
|
|
34177
|
+
function memoryBoundedPragmaOverrides() {
|
|
34178
|
+
if (process.env.CLEO_SENTIENT_DAEMON === "1") return {};
|
|
34179
|
+
if (process.env.CLEO_DB_FULL_MEM === "1") return {};
|
|
34180
|
+
return { mmapSizeBytes: 0, cacheSizeKb: 8e3 };
|
|
34181
|
+
}
|
|
34040
34182
|
async function openDualScopeDb(scope, cwd) {
|
|
34041
34183
|
const dbPath = resolveDualScopeDbPath(scope, cwd);
|
|
34042
34184
|
return scope === "project" ? openDualScopeDbAtPath("project", dbPath, cwd) : openDualScopeDbAtPath("global", dbPath, cwd);
|
|
34043
34185
|
}
|
|
34044
34186
|
async function openDedicatedDualScopeDb(scope, dbPath, log7) {
|
|
34045
34187
|
log7.debug({ scope, dbPath }, "opening DEDICATED (non-cached) dual-scope cleo.db (T11782 FIX D)");
|
|
34046
|
-
const dir =
|
|
34047
|
-
if (!
|
|
34188
|
+
const dir = dirname5(dbPath);
|
|
34189
|
+
if (!existsSync12(dir)) {
|
|
34048
34190
|
mkdirSync3(dir, { recursive: true });
|
|
34049
34191
|
}
|
|
34050
34192
|
const DatabaseSyncCtor = getDatabaseSyncCtor();
|
|
34051
34193
|
const nativeDb = new DatabaseSyncCtor(dbPath, { allowExtension: true });
|
|
34052
|
-
applyPerfPragmas(nativeDb);
|
|
34194
|
+
applyPerfPragmas(nativeDb, memoryBoundedPragmaOverrides());
|
|
34053
34195
|
const schema = scope === "project" ? await loadProjectSchema() : await loadGlobalSchema();
|
|
34054
34196
|
const drizzle2 = getDrizzle();
|
|
34055
34197
|
const db = drizzle2({ client: nativeDb, schema });
|
|
34056
34198
|
const migrationsFolder = resolveCorePackageMigrationsFolder(migrationsSetName(scope));
|
|
34057
|
-
reconcileJournal(
|
|
34199
|
+
reconcileJournal(
|
|
34200
|
+
nativeDb,
|
|
34201
|
+
migrationsFolder,
|
|
34202
|
+
existenceTable(scope),
|
|
34203
|
+
`dual-scope-db[${scope}]`,
|
|
34204
|
+
resolveConsolidatedJournalSiblings(migrationsSetName(scope))
|
|
34205
|
+
);
|
|
34058
34206
|
migrateWithRetry(
|
|
34059
34207
|
db,
|
|
34060
34208
|
migrationsFolder,
|
|
@@ -34093,18 +34241,24 @@ async function openDualScopeDbAtPath(scope, dbPath, exodusCwd, options) {
|
|
|
34093
34241
|
}
|
|
34094
34242
|
const initPromise = (async () => {
|
|
34095
34243
|
log7.debug({ scope, dbPath }, "opening dual-scope cleo.db");
|
|
34096
|
-
const dir =
|
|
34097
|
-
if (!
|
|
34244
|
+
const dir = dirname5(dbPath);
|
|
34245
|
+
if (!existsSync12(dir)) {
|
|
34098
34246
|
mkdirSync3(dir, { recursive: true });
|
|
34099
34247
|
}
|
|
34100
34248
|
const DatabaseSyncCtor = getDatabaseSyncCtor();
|
|
34101
34249
|
const nativeDb = new DatabaseSyncCtor(dbPath, { allowExtension: true });
|
|
34102
|
-
applyPerfPragmas(nativeDb);
|
|
34250
|
+
applyPerfPragmas(nativeDb, memoryBoundedPragmaOverrides());
|
|
34103
34251
|
const schema = scope === "project" ? await loadProjectSchema() : await loadGlobalSchema();
|
|
34104
34252
|
const drizzle2 = getDrizzle();
|
|
34105
34253
|
const db = drizzle2({ client: nativeDb, schema });
|
|
34106
34254
|
const migrationsFolder = resolveCorePackageMigrationsFolder(migrationsSetName(scope));
|
|
34107
|
-
reconcileJournal(
|
|
34255
|
+
reconcileJournal(
|
|
34256
|
+
nativeDb,
|
|
34257
|
+
migrationsFolder,
|
|
34258
|
+
existenceTable(scope),
|
|
34259
|
+
`dual-scope-db[${scope}]`,
|
|
34260
|
+
resolveConsolidatedJournalSiblings(migrationsSetName(scope))
|
|
34261
|
+
);
|
|
34108
34262
|
migrateWithRetry(
|
|
34109
34263
|
db,
|
|
34110
34264
|
migrationsFolder,
|
|
@@ -34172,6 +34326,12 @@ async function openDualScopeDbAtPath(scope, dbPath, exodusCwd, options) {
|
|
|
34172
34326
|
nativeDb: null,
|
|
34173
34327
|
initPromise
|
|
34174
34328
|
});
|
|
34329
|
+
initPromise.catch(() => {
|
|
34330
|
+
const entry = _cache.get(key);
|
|
34331
|
+
if (entry && entry.initPromise === initPromise) {
|
|
34332
|
+
_cache.delete(key);
|
|
34333
|
+
}
|
|
34334
|
+
});
|
|
34175
34335
|
return initPromise;
|
|
34176
34336
|
}
|
|
34177
34337
|
function _resetDualScopeDbCache(scope) {
|
|
@@ -34762,8 +34922,8 @@ __export(nexus_sqlite_exports, {
|
|
|
34762
34922
|
resetNexusDbState: () => resetNexusDbState,
|
|
34763
34923
|
resolveNexusMigrationsFolder: () => resolveNexusMigrationsFolder
|
|
34764
34924
|
});
|
|
34765
|
-
import { copyFileSync as
|
|
34766
|
-
import { join as
|
|
34925
|
+
import { copyFileSync as copyFileSync4, existsSync as existsSync13 } from "node:fs";
|
|
34926
|
+
import { join as join12 } from "node:path";
|
|
34767
34927
|
function getNexusDbPath(cwd) {
|
|
34768
34928
|
return resolveDualScopeDbPath("project", cwd);
|
|
34769
34929
|
}
|
|
@@ -34795,7 +34955,7 @@ function resolveNexusMigrationsFolder() {
|
|
|
34795
34955
|
return resolveCorePackageMigrationsFolder("drizzle-nexus");
|
|
34796
34956
|
}
|
|
34797
34957
|
function getNestedNexusSentinelPath() {
|
|
34798
|
-
return
|
|
34958
|
+
return join12(getCleoHome(), "nexus", NESTED_NEXUS_SENTINEL);
|
|
34799
34959
|
}
|
|
34800
34960
|
function detectAndWarnOnNestedNexus() {
|
|
34801
34961
|
let nestedPath;
|
|
@@ -34804,7 +34964,7 @@ function detectAndWarnOnNestedNexus() {
|
|
|
34804
34964
|
} catch {
|
|
34805
34965
|
return false;
|
|
34806
34966
|
}
|
|
34807
|
-
if (!
|
|
34967
|
+
if (!existsSync13(nestedPath)) return false;
|
|
34808
34968
|
if (_warnedNestedPaths.has(nestedPath)) return false;
|
|
34809
34969
|
_warnedNestedPaths.add(nestedPath);
|
|
34810
34970
|
const canonicalPath = getNexusDbPath();
|
|
@@ -34963,14 +35123,20 @@ function runNexusMigrations(nativeDb, db) {
|
|
|
34963
35123
|
const migrationsFolder = resolveNexusMigrationsFolder();
|
|
34964
35124
|
if (tableExists4(nativeDb, "nexus_nodes") && _nexusDbPath) {
|
|
34965
35125
|
const backupPath = _nexusDbPath.replace(/\.db$/, "-pre-cleo.db.bak");
|
|
34966
|
-
if (!
|
|
35126
|
+
if (!existsSync13(backupPath)) {
|
|
34967
35127
|
try {
|
|
34968
|
-
|
|
35128
|
+
copyFileSync4(_nexusDbPath, backupPath);
|
|
34969
35129
|
} catch {
|
|
34970
35130
|
}
|
|
34971
35131
|
}
|
|
34972
35132
|
}
|
|
34973
|
-
reconcileJournal(
|
|
35133
|
+
reconcileJournal(
|
|
35134
|
+
nativeDb,
|
|
35135
|
+
migrationsFolder,
|
|
35136
|
+
"_nexus_meta",
|
|
35137
|
+
"nexus",
|
|
35138
|
+
resolveConsolidatedJournalSiblings("drizzle-nexus")
|
|
35139
|
+
);
|
|
34974
35140
|
const MAX_RETRIES2 = 5;
|
|
34975
35141
|
const BASE_DELAY_MS = 100;
|
|
34976
35142
|
const MAX_DELAY_MS = 2e3;
|
|
@@ -35095,10 +35261,10 @@ var init_nexus_sqlite = __esm({
|
|
|
35095
35261
|
|
|
35096
35262
|
// packages/core/src/paths.ts
|
|
35097
35263
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
35098
|
-
import { existsSync as
|
|
35264
|
+
import { existsSync as existsSync14, readFileSync as readFileSync4, statSync as statSync5 } from "node:fs";
|
|
35099
35265
|
import { createRequire as createRequire5 } from "node:module";
|
|
35100
35266
|
import { homedir } from "node:os";
|
|
35101
|
-
import { basename as basename4, dirname as
|
|
35267
|
+
import { basename as basename4, dirname as dirname6, join as join13, resolve as resolve3 } from "node:path";
|
|
35102
35268
|
import {
|
|
35103
35269
|
computeCanonicalProjectId as _computeCanonicalProjectId,
|
|
35104
35270
|
getCanonicalTemplatesTildePath as _getCanonicalTemplatesTildePath,
|
|
@@ -35188,8 +35354,8 @@ function getCleoDirAbsolute(cwd, opts) {
|
|
|
35188
35354
|
function _resolveProjectByCwdFromNexus(cwd) {
|
|
35189
35355
|
try {
|
|
35190
35356
|
const cleoHome = getCleoHome();
|
|
35191
|
-
const globalDbPath =
|
|
35192
|
-
if (!
|
|
35357
|
+
const globalDbPath = join13(cleoHome, "cleo.db");
|
|
35358
|
+
if (!existsSync14(globalDbPath)) return null;
|
|
35193
35359
|
const start = resolve3(cwd ?? process.cwd());
|
|
35194
35360
|
let current = start;
|
|
35195
35361
|
const DatabaseSync2 = _getDatabaseSyncCtor();
|
|
@@ -35203,7 +35369,7 @@ function _resolveProjectByCwdFromNexus(cwd) {
|
|
|
35203
35369
|
if (row && typeof row.project_id === "string" && row.project_id.length > 0) {
|
|
35204
35370
|
return row.project_id;
|
|
35205
35371
|
}
|
|
35206
|
-
const parent =
|
|
35372
|
+
const parent = dirname6(current);
|
|
35207
35373
|
if (parent === current) break;
|
|
35208
35374
|
current = parent;
|
|
35209
35375
|
}
|
|
@@ -35228,13 +35394,13 @@ function _findCleoDirRoot(cwd) {
|
|
|
35228
35394
|
const isDangerousRoot = current === homeRoot || current === "/" || current === "";
|
|
35229
35395
|
if (!isDangerousRoot) {
|
|
35230
35396
|
try {
|
|
35231
|
-
if (statSync5(
|
|
35397
|
+
if (statSync5(join13(current, ".cleo")).isDirectory()) {
|
|
35232
35398
|
return current;
|
|
35233
35399
|
}
|
|
35234
35400
|
} catch {
|
|
35235
35401
|
}
|
|
35236
35402
|
}
|
|
35237
|
-
const parent =
|
|
35403
|
+
const parent = dirname6(current);
|
|
35238
35404
|
if (parent === current) break;
|
|
35239
35405
|
current = parent;
|
|
35240
35406
|
}
|
|
@@ -35243,7 +35409,7 @@ function _findCleoDirRoot(cwd) {
|
|
|
35243
35409
|
function resolveCleoDir(cwd) {
|
|
35244
35410
|
const scope = worktreeScope.getStore();
|
|
35245
35411
|
if (scope !== void 0) {
|
|
35246
|
-
return
|
|
35412
|
+
return join13(scope.worktreeRoot, ".cleo");
|
|
35247
35413
|
}
|
|
35248
35414
|
const override = _cleoDirEnvOverride();
|
|
35249
35415
|
if (override !== null) {
|
|
@@ -35251,16 +35417,16 @@ function resolveCleoDir(cwd) {
|
|
|
35251
35417
|
}
|
|
35252
35418
|
const root = _findCleoDirRoot(cwd);
|
|
35253
35419
|
if (root !== null) {
|
|
35254
|
-
return
|
|
35420
|
+
return join13(root, ".cleo");
|
|
35255
35421
|
}
|
|
35256
35422
|
const start = resolve3(cwd ?? process.cwd());
|
|
35257
35423
|
let current = start;
|
|
35258
35424
|
while (true) {
|
|
35259
35425
|
const mainRepo = _resolveMainRepoFromGitlink(current);
|
|
35260
35426
|
if (mainRepo !== null) {
|
|
35261
|
-
return
|
|
35427
|
+
return join13(mainRepo, ".cleo");
|
|
35262
35428
|
}
|
|
35263
|
-
const parent =
|
|
35429
|
+
const parent = dirname6(current);
|
|
35264
35430
|
if (parent === current) {
|
|
35265
35431
|
break;
|
|
35266
35432
|
}
|
|
@@ -35300,30 +35466,30 @@ function _cwdHasGitAncestor(cwd) {
|
|
|
35300
35466
|
const start = resolve3(cwd ?? process.cwd());
|
|
35301
35467
|
let current = start;
|
|
35302
35468
|
while (true) {
|
|
35303
|
-
const gitMarker =
|
|
35469
|
+
const gitMarker = join13(current, ".git");
|
|
35304
35470
|
try {
|
|
35305
|
-
if (
|
|
35471
|
+
if (existsSync14(gitMarker)) {
|
|
35306
35472
|
return true;
|
|
35307
35473
|
}
|
|
35308
35474
|
} catch {
|
|
35309
35475
|
}
|
|
35310
|
-
const parent =
|
|
35476
|
+
const parent = dirname6(current);
|
|
35311
35477
|
if (parent === current) return false;
|
|
35312
35478
|
current = parent;
|
|
35313
35479
|
}
|
|
35314
35480
|
}
|
|
35315
35481
|
function _resolveMainRepoFromGitlink(gitlinkDir) {
|
|
35316
35482
|
try {
|
|
35317
|
-
const gitLinkPath =
|
|
35318
|
-
if (!
|
|
35483
|
+
const gitLinkPath = join13(gitlinkDir, ".git");
|
|
35484
|
+
if (!existsSync14(gitLinkPath)) return null;
|
|
35319
35485
|
const stat2 = statSync5(gitLinkPath);
|
|
35320
35486
|
if (!stat2.isFile()) return null;
|
|
35321
35487
|
const gitLinkContent = readFileSync4(gitLinkPath, "utf-8").trim();
|
|
35322
35488
|
const match = gitLinkContent.match(/^gitdir:\s*(.+)$/m);
|
|
35323
35489
|
if (!match) return null;
|
|
35324
35490
|
const gitdir = match[1].trim();
|
|
35325
|
-
const mainRepo =
|
|
35326
|
-
if (
|
|
35491
|
+
const mainRepo = dirname6(dirname6(dirname6(gitdir)));
|
|
35492
|
+
if (existsSync14(join13(mainRepo, ".cleo")) && validateProjectRoot(mainRepo)) {
|
|
35327
35493
|
return mainRepo;
|
|
35328
35494
|
}
|
|
35329
35495
|
} catch {
|
|
@@ -35331,18 +35497,18 @@ function _resolveMainRepoFromGitlink(gitlinkDir) {
|
|
|
35331
35497
|
return null;
|
|
35332
35498
|
}
|
|
35333
35499
|
function validateProjectRoot(candidate) {
|
|
35334
|
-
const cleoDir =
|
|
35335
|
-
if (!
|
|
35500
|
+
const cleoDir = join13(candidate, ".cleo");
|
|
35501
|
+
if (!existsSync14(cleoDir)) {
|
|
35336
35502
|
return false;
|
|
35337
35503
|
}
|
|
35338
|
-
const projectInfoPath =
|
|
35339
|
-
if (
|
|
35504
|
+
const projectInfoPath = join13(cleoDir, "project-info.json");
|
|
35505
|
+
if (existsSync14(projectInfoPath)) {
|
|
35340
35506
|
try {
|
|
35341
35507
|
const raw = readFileSync4(projectInfoPath, "utf-8");
|
|
35342
35508
|
const parsed = JSON.parse(raw);
|
|
35343
35509
|
if (typeof parsed === "object" && parsed !== null && "projectId" in parsed && typeof parsed["projectId"] === "string" && parsed["projectId"] !== "") {
|
|
35344
|
-
const gitMarker =
|
|
35345
|
-
if (
|
|
35510
|
+
const gitMarker = join13(candidate, ".git");
|
|
35511
|
+
if (existsSync14(gitMarker)) {
|
|
35346
35512
|
try {
|
|
35347
35513
|
if (!statSync5(gitMarker).isDirectory()) {
|
|
35348
35514
|
return false;
|
|
@@ -35356,8 +35522,8 @@ function validateProjectRoot(candidate) {
|
|
|
35356
35522
|
} catch {
|
|
35357
35523
|
}
|
|
35358
35524
|
}
|
|
35359
|
-
const gitDir =
|
|
35360
|
-
if (
|
|
35525
|
+
const gitDir = join13(candidate, ".git");
|
|
35526
|
+
if (existsSync14(gitDir)) {
|
|
35361
35527
|
let isRealGitDir = false;
|
|
35362
35528
|
try {
|
|
35363
35529
|
const stat2 = statSync5(gitDir);
|
|
@@ -35393,7 +35559,7 @@ function getProjectRoot(cwd) {
|
|
|
35393
35559
|
const cleoDirEnv = process.env["CLEO_DIR"];
|
|
35394
35560
|
if (cleoDirEnv && isAbsolutePath(cleoDirEnv)) {
|
|
35395
35561
|
if (cleoDirEnv.endsWith("/.cleo") || cleoDirEnv.endsWith("\\.cleo")) {
|
|
35396
|
-
return
|
|
35562
|
+
return dirname6(cleoDirEnv);
|
|
35397
35563
|
}
|
|
35398
35564
|
return cleoDirEnv;
|
|
35399
35565
|
}
|
|
@@ -35404,16 +35570,16 @@ function getProjectRoot(cwd) {
|
|
|
35404
35570
|
const homeRoot = homedir();
|
|
35405
35571
|
const skippedCleoDirs = [];
|
|
35406
35572
|
while (true) {
|
|
35407
|
-
const cleoDir =
|
|
35408
|
-
const gitDir =
|
|
35573
|
+
const cleoDir = join13(current, ".cleo");
|
|
35574
|
+
const gitDir = join13(current, ".git");
|
|
35409
35575
|
const isDangerousRoot = current === homeRoot || current === "/" || current === "";
|
|
35410
|
-
if (
|
|
35576
|
+
if (existsSync14(cleoDir) && !isDangerousRoot) {
|
|
35411
35577
|
if (validateProjectRoot(current)) {
|
|
35412
35578
|
return current;
|
|
35413
35579
|
}
|
|
35414
35580
|
skippedCleoDirs.push(current);
|
|
35415
35581
|
}
|
|
35416
|
-
if (
|
|
35582
|
+
if (existsSync14(gitDir) && !isDangerousRoot) {
|
|
35417
35583
|
let isRealGitDir = false;
|
|
35418
35584
|
try {
|
|
35419
35585
|
isRealGitDir = statSync5(gitDir).isDirectory();
|
|
@@ -35428,7 +35594,7 @@ function getProjectRoot(cwd) {
|
|
|
35428
35594
|
const mainRepoFromWalk = _resolveMainRepoFromGitlink(current);
|
|
35429
35595
|
if (mainRepoFromWalk !== null) return mainRepoFromWalk;
|
|
35430
35596
|
}
|
|
35431
|
-
const parent =
|
|
35597
|
+
const parent = dirname6(current);
|
|
35432
35598
|
if (parent === current) {
|
|
35433
35599
|
break;
|
|
35434
35600
|
}
|
|
@@ -35458,18 +35624,18 @@ function resolveOrCwd(maybeRoot) {
|
|
|
35458
35624
|
return getProjectRoot();
|
|
35459
35625
|
}
|
|
35460
35626
|
function getConfigPath(cwd) {
|
|
35461
|
-
return
|
|
35627
|
+
return join13(_resolveCleoDir(cwd), "config.json");
|
|
35462
35628
|
}
|
|
35463
35629
|
function getGlobalConfigPath() {
|
|
35464
|
-
return
|
|
35630
|
+
return join13(getCleoHome(), "config.json");
|
|
35465
35631
|
}
|
|
35466
35632
|
function isAbsolutePath(path) {
|
|
35467
35633
|
return _isAbsolutePath(path);
|
|
35468
35634
|
}
|
|
35469
35635
|
function _readProjectNameFromInfo(projectRoot) {
|
|
35470
35636
|
try {
|
|
35471
|
-
const infoPath =
|
|
35472
|
-
if (!
|
|
35637
|
+
const infoPath = join13(projectRoot, ".cleo", "project-info.json");
|
|
35638
|
+
if (!existsSync14(infoPath)) return void 0;
|
|
35473
35639
|
const raw = readFileSync4(infoPath, "utf-8");
|
|
35474
35640
|
const data = JSON.parse(raw);
|
|
35475
35641
|
return typeof data.name === "string" && data.name.length > 0 ? data.name : void 0;
|
|
@@ -35495,8 +35661,8 @@ async function registerProjectOnEncounter(projectRoot, infoProjectId) {
|
|
|
35495
35661
|
if (existingRows.length > 0) {
|
|
35496
35662
|
const existingPath = existingRows[0].projectPath;
|
|
35497
35663
|
if (existingPath !== resolvedPath) {
|
|
35498
|
-
const newBrainDbPath =
|
|
35499
|
-
const newTasksDbPath =
|
|
35664
|
+
const newBrainDbPath = join13(resolvedPath, ".cleo", "brain.db");
|
|
35665
|
+
const newTasksDbPath = join13(resolvedPath, ".cleo", "tasks.db");
|
|
35500
35666
|
await db.update(projectRegistry2).set({
|
|
35501
35667
|
projectPath: resolvedPath,
|
|
35502
35668
|
projectHash: generateProjectHash2(resolvedPath),
|
|
@@ -35527,8 +35693,8 @@ async function registerProjectOnEncounter(projectRoot, infoProjectId) {
|
|
|
35527
35693
|
lastSync: now,
|
|
35528
35694
|
taskCount: 0,
|
|
35529
35695
|
labelsJson: "[]",
|
|
35530
|
-
brainDbPath:
|
|
35531
|
-
tasksDbPath:
|
|
35696
|
+
brainDbPath: join13(resolvedPath, ".cleo", "brain.db"),
|
|
35697
|
+
tasksDbPath: join13(resolvedPath, ".cleo", "tasks.db"),
|
|
35532
35698
|
statsJson: "{}"
|
|
35533
35699
|
}).onConflictDoNothing();
|
|
35534
35700
|
const aliases = canonicalResult.legacyAliases ?? [];
|
|
@@ -35561,7 +35727,7 @@ var init_paths = __esm({
|
|
|
35561
35727
|
// packages/core/src/store/file-utils.ts
|
|
35562
35728
|
import { randomBytes } from "node:crypto";
|
|
35563
35729
|
import {
|
|
35564
|
-
existsSync as
|
|
35730
|
+
existsSync as existsSync15,
|
|
35565
35731
|
mkdirSync as mkdirSync4,
|
|
35566
35732
|
readdirSync as readdirSync4,
|
|
35567
35733
|
readFileSync as readFileSync5,
|
|
@@ -35569,34 +35735,34 @@ import {
|
|
|
35569
35735
|
unlinkSync as unlinkSync3,
|
|
35570
35736
|
writeFileSync as writeFileSync3
|
|
35571
35737
|
} from "node:fs";
|
|
35572
|
-
import { basename as basename5, dirname as
|
|
35738
|
+
import { basename as basename5, dirname as dirname7, join as join14 } from "node:path";
|
|
35573
35739
|
import * as lockfile2 from "proper-lockfile";
|
|
35574
35740
|
function rotateBackup(filePath, mode) {
|
|
35575
|
-
const dir =
|
|
35741
|
+
const dir = dirname7(filePath);
|
|
35576
35742
|
const name15 = basename5(filePath);
|
|
35577
|
-
const backupDir =
|
|
35743
|
+
const backupDir = join14(dir, ".backups");
|
|
35578
35744
|
const dirMode = typeof mode === "number" ? modeToDirMode(mode) : void 0;
|
|
35579
|
-
if (!
|
|
35745
|
+
if (!existsSync15(backupDir)) {
|
|
35580
35746
|
mkdirSync4(backupDir, { recursive: true, mode: dirMode });
|
|
35581
35747
|
}
|
|
35582
35748
|
for (let i = MAX_BACKUPS; i >= 1; i--) {
|
|
35583
|
-
const current =
|
|
35749
|
+
const current = join14(backupDir, `${name15}.${i}`);
|
|
35584
35750
|
if (i === MAX_BACKUPS) {
|
|
35585
35751
|
try {
|
|
35586
35752
|
unlinkSync3(current);
|
|
35587
35753
|
} catch {
|
|
35588
35754
|
}
|
|
35589
35755
|
} else {
|
|
35590
|
-
const next =
|
|
35756
|
+
const next = join14(backupDir, `${name15}.${i + 1}`);
|
|
35591
35757
|
try {
|
|
35592
|
-
if (
|
|
35758
|
+
if (existsSync15(current)) renameSync3(current, next);
|
|
35593
35759
|
} catch {
|
|
35594
35760
|
}
|
|
35595
35761
|
}
|
|
35596
35762
|
}
|
|
35597
35763
|
try {
|
|
35598
35764
|
const content = readFileSync5(filePath, "utf-8");
|
|
35599
|
-
const backupPath =
|
|
35765
|
+
const backupPath = join14(backupDir, `${name15}.1`);
|
|
35600
35766
|
if (typeof mode === "number") {
|
|
35601
35767
|
writeFileSync3(backupPath, content, { encoding: "utf-8", mode });
|
|
35602
35768
|
} else {
|
|
@@ -35616,8 +35782,8 @@ function writeJsonFileAtomic(filePath, data, optsOrIndent = 2) {
|
|
|
35616
35782
|
const opts = typeof optsOrIndent === "number" ? { indent: optsOrIndent } : optsOrIndent;
|
|
35617
35783
|
const indent = opts.indent ?? 2;
|
|
35618
35784
|
const mode = opts.mode;
|
|
35619
|
-
const dir =
|
|
35620
|
-
const tempPath =
|
|
35785
|
+
const dir = dirname7(filePath);
|
|
35786
|
+
const tempPath = join14(dir, `.${basename5(filePath)}.${randomBytes(6).toString("hex")}.tmp`);
|
|
35621
35787
|
const content = JSON.stringify(data, null, indent) + "\n";
|
|
35622
35788
|
if (typeof mode === "number") {
|
|
35623
35789
|
writeFileSync3(tempPath, content, { encoding: "utf-8", mode });
|
|
@@ -35625,7 +35791,7 @@ function writeJsonFileAtomic(filePath, data, optsOrIndent = 2) {
|
|
|
35625
35791
|
writeFileSync3(tempPath, content, "utf-8");
|
|
35626
35792
|
}
|
|
35627
35793
|
try {
|
|
35628
|
-
if (
|
|
35794
|
+
if (existsSync15(filePath)) {
|
|
35629
35795
|
rotateBackup(filePath, mode);
|
|
35630
35796
|
}
|
|
35631
35797
|
renameSync3(tempPath, filePath);
|
|
@@ -35649,12 +35815,12 @@ function readJsonFile(filePath) {
|
|
|
35649
35815
|
}
|
|
35650
35816
|
}
|
|
35651
35817
|
async function withLock2(filePath, transform2, opts = {}) {
|
|
35652
|
-
const dir =
|
|
35818
|
+
const dir = dirname7(filePath);
|
|
35653
35819
|
const dirMode = typeof opts.mode === "number" ? modeToDirMode(opts.mode) : void 0;
|
|
35654
|
-
if (!
|
|
35820
|
+
if (!existsSync15(dir)) {
|
|
35655
35821
|
mkdirSync4(dir, { recursive: true, mode: dirMode });
|
|
35656
35822
|
}
|
|
35657
|
-
if (!
|
|
35823
|
+
if (!existsSync15(filePath)) {
|
|
35658
35824
|
if (typeof opts.mode === "number") {
|
|
35659
35825
|
writeFileSync3(filePath, "", { encoding: "utf-8", mode: opts.mode });
|
|
35660
35826
|
} else {
|
|
@@ -35675,11 +35841,11 @@ async function withLock2(filePath, transform2, opts = {}) {
|
|
|
35675
35841
|
}
|
|
35676
35842
|
}
|
|
35677
35843
|
async function withFileLock(filePath, operation) {
|
|
35678
|
-
const dir =
|
|
35679
|
-
if (!
|
|
35844
|
+
const dir = dirname7(filePath);
|
|
35845
|
+
if (!existsSync15(dir)) {
|
|
35680
35846
|
mkdirSync4(dir, { recursive: true });
|
|
35681
35847
|
}
|
|
35682
|
-
if (!
|
|
35848
|
+
if (!existsSync15(filePath)) {
|
|
35683
35849
|
writeFileSync3(filePath, "", "utf-8");
|
|
35684
35850
|
}
|
|
35685
35851
|
let release;
|
|
@@ -35713,10 +35879,10 @@ var init_file_utils = __esm({
|
|
|
35713
35879
|
|
|
35714
35880
|
// packages/core/src/llm/credential-removal.ts
|
|
35715
35881
|
import { unlinkSync as unlinkSync4 } from "node:fs";
|
|
35716
|
-
import { join as
|
|
35882
|
+
import { join as join15 } from "node:path";
|
|
35717
35883
|
import { getCleoHome as getCleoHome2 } from "@cleocode/paths";
|
|
35718
35884
|
function suppressionStatePath() {
|
|
35719
|
-
return
|
|
35885
|
+
return join15(getCleoHome2(), SUPPRESSION_FILENAME);
|
|
35720
35886
|
}
|
|
35721
35887
|
function readSuppressionFile() {
|
|
35722
35888
|
const data = readJsonFile(suppressionStatePath());
|
|
@@ -35820,7 +35986,7 @@ var init_credential_removal = __esm({
|
|
|
35820
35986
|
sourceId: "cleo-pkce",
|
|
35821
35987
|
description: "Delete CLEO-issued PKCE token at <CLEO_HOME>/anthropic-oauth.json",
|
|
35822
35988
|
async remove() {
|
|
35823
|
-
const path =
|
|
35989
|
+
const path = join15(getCleoHome2(), "anthropic-oauth.json");
|
|
35824
35990
|
const cleaned = [];
|
|
35825
35991
|
try {
|
|
35826
35992
|
unlinkSync4(path);
|
|
@@ -35899,9 +36065,9 @@ __export(config_exports, {
|
|
|
35899
36065
|
parseConfigValue: () => parseConfigValue,
|
|
35900
36066
|
setConfigValue: () => setConfigValue
|
|
35901
36067
|
});
|
|
35902
|
-
import { existsSync as
|
|
36068
|
+
import { existsSync as existsSync16 } from "node:fs";
|
|
35903
36069
|
import { mkdir as mkdir3, writeFile } from "node:fs/promises";
|
|
35904
|
-
import { dirname as
|
|
36070
|
+
import { dirname as dirname8 } from "node:path";
|
|
35905
36071
|
function getNestedValue(obj, path) {
|
|
35906
36072
|
const parts = path.split(".");
|
|
35907
36073
|
let current = obj;
|
|
@@ -36023,8 +36189,8 @@ function parseConfigValue(value) {
|
|
|
36023
36189
|
}
|
|
36024
36190
|
async function setConfigValue(key, value, cwd, opts) {
|
|
36025
36191
|
const configPath = opts?.global ? getGlobalConfigPath() : getConfigPath(cwd);
|
|
36026
|
-
if (!
|
|
36027
|
-
const dir =
|
|
36192
|
+
if (!existsSync16(configPath)) {
|
|
36193
|
+
const dir = dirname8(configPath);
|
|
36028
36194
|
await mkdir3(dir, { recursive: true });
|
|
36029
36195
|
await writeFile(configPath, "{}", "utf-8");
|
|
36030
36196
|
}
|
|
@@ -36037,8 +36203,8 @@ async function setConfigValue(key, value, cwd, opts) {
|
|
|
36037
36203
|
async function applyStrictnessPreset(preset, cwd, opts) {
|
|
36038
36204
|
const definition = STRICTNESS_PRESETS[preset];
|
|
36039
36205
|
const configPath = opts?.global ? getGlobalConfigPath() : getConfigPath(cwd);
|
|
36040
|
-
if (!
|
|
36041
|
-
const dir =
|
|
36206
|
+
if (!existsSync16(configPath)) {
|
|
36207
|
+
const dir = dirname8(configPath);
|
|
36042
36208
|
await mkdir3(dir, { recursive: true });
|
|
36043
36209
|
await writeFile(configPath, "{}", "utf-8");
|
|
36044
36210
|
}
|
|
@@ -36239,10 +36405,10 @@ var init_config = __esm({
|
|
|
36239
36405
|
// packages/core/src/llm/credential-seeders/claude-code-seeder.ts
|
|
36240
36406
|
import { readFileSync as readFileSync6 } from "node:fs";
|
|
36241
36407
|
import { homedir as homedir2 } from "node:os";
|
|
36242
|
-
import { join as
|
|
36408
|
+
import { join as join16 } from "node:path";
|
|
36243
36409
|
function defaultReadCredentialFile() {
|
|
36244
36410
|
try {
|
|
36245
|
-
return readFileSync6(
|
|
36411
|
+
return readFileSync6(join16(homedir2(), ".claude", ".credentials.json"), "utf-8");
|
|
36246
36412
|
} catch {
|
|
36247
36413
|
return null;
|
|
36248
36414
|
}
|
|
@@ -36337,9 +36503,9 @@ var init_claude_code_seeder = __esm({
|
|
|
36337
36503
|
|
|
36338
36504
|
// packages/core/src/llm/credential-seeders/cleo-pkce-seeder.ts
|
|
36339
36505
|
import { readFileSync as readFileSync7 } from "node:fs";
|
|
36340
|
-
import { join as
|
|
36506
|
+
import { join as join17 } from "node:path";
|
|
36341
36507
|
function defaultCleoPkcePath() {
|
|
36342
|
-
return
|
|
36508
|
+
return join17(getCleoHome(), "anthropic-oauth.json");
|
|
36343
36509
|
}
|
|
36344
36510
|
function defaultReadCredentialFile2() {
|
|
36345
36511
|
try {
|
|
@@ -36410,13 +36576,13 @@ var init_cleo_pkce_seeder = __esm({
|
|
|
36410
36576
|
});
|
|
36411
36577
|
|
|
36412
36578
|
// packages/core/src/llm/credential-seeders/codex-cli-seeder.ts
|
|
36413
|
-
import { existsSync as
|
|
36579
|
+
import { existsSync as existsSync17, readFileSync as readFileSync8 } from "node:fs";
|
|
36414
36580
|
import { homedir as homedir3 } from "node:os";
|
|
36415
|
-
import { join as
|
|
36581
|
+
import { join as join18 } from "node:path";
|
|
36416
36582
|
function getCodexAuthPath() {
|
|
36417
36583
|
const codexHome = (process.env["CODEX_HOME"] ?? "").trim();
|
|
36418
|
-
const root = codexHome ||
|
|
36419
|
-
return
|
|
36584
|
+
const root = codexHome || join18(homedir3(), ".codex");
|
|
36585
|
+
return join18(root, "auth.json");
|
|
36420
36586
|
}
|
|
36421
36587
|
var CodexCliSeeder, codexCliSeeder;
|
|
36422
36588
|
var init_codex_cli_seeder = __esm({
|
|
@@ -36435,7 +36601,7 @@ var init_codex_cli_seeder = __esm({
|
|
|
36435
36601
|
*/
|
|
36436
36602
|
async seed() {
|
|
36437
36603
|
const authPath = getCodexAuthPath();
|
|
36438
|
-
if (!
|
|
36604
|
+
if (!existsSync17(authPath)) {
|
|
36439
36605
|
return { entries: [] };
|
|
36440
36606
|
}
|
|
36441
36607
|
let raw;
|
|
@@ -36565,11 +36731,11 @@ var init_google_pkce = __esm({
|
|
|
36565
36731
|
});
|
|
36566
36732
|
|
|
36567
36733
|
// packages/core/src/llm/credential-seeders/gemini-cli-seeder.ts
|
|
36568
|
-
import { existsSync as
|
|
36569
|
-
import { join as
|
|
36734
|
+
import { existsSync as existsSync18, readFileSync as readFileSync9 } from "node:fs";
|
|
36735
|
+
import { join as join19 } from "node:path";
|
|
36570
36736
|
import { getCleoHome as getCleoHome3 } from "@cleocode/paths";
|
|
36571
36737
|
function getGoogleOauthPath() {
|
|
36572
|
-
return
|
|
36738
|
+
return join19(getCleoHome3(), "google_oauth.json");
|
|
36573
36739
|
}
|
|
36574
36740
|
function parseGoogleOauthFile(raw) {
|
|
36575
36741
|
let json3;
|
|
@@ -36614,7 +36780,7 @@ var init_gemini_cli_seeder = __esm({
|
|
|
36614
36780
|
*/
|
|
36615
36781
|
async seed() {
|
|
36616
36782
|
const path = getGoogleOauthPath();
|
|
36617
|
-
if (!
|
|
36783
|
+
if (!existsSync18(path)) {
|
|
36618
36784
|
return { entries: [] };
|
|
36619
36785
|
}
|
|
36620
36786
|
let raw;
|
|
@@ -36839,23 +37005,23 @@ var init_credential_seeders = __esm({
|
|
|
36839
37005
|
|
|
36840
37006
|
// packages/core/src/llm/global-config-migration.ts
|
|
36841
37007
|
import {
|
|
36842
|
-
existsSync as
|
|
37008
|
+
existsSync as existsSync19,
|
|
36843
37009
|
mkdirSync as mkdirSync5,
|
|
36844
37010
|
readFileSync as readFileSync10,
|
|
36845
37011
|
renameSync as renameSync4,
|
|
36846
37012
|
unlinkSync as unlinkSync5,
|
|
36847
37013
|
writeFileSync as writeFileSync4
|
|
36848
37014
|
} from "node:fs";
|
|
36849
|
-
import { join as
|
|
37015
|
+
import { join as join20 } from "node:path";
|
|
36850
37016
|
import { getCleoHome as getCleoHome4, getCleoPlatformPaths as getCleoPlatformPaths2 } from "@cleocode/paths";
|
|
36851
37017
|
function configDirGlobalConfigPath() {
|
|
36852
|
-
return
|
|
37018
|
+
return join20(getCleoPlatformPaths2().config, GLOBAL_CONFIG_FILENAME);
|
|
36853
37019
|
}
|
|
36854
37020
|
function legacyGlobalConfigPath() {
|
|
36855
|
-
return
|
|
37021
|
+
return join20(getCleoHome4(), GLOBAL_CONFIG_FILENAME);
|
|
36856
37022
|
}
|
|
36857
37023
|
function migrationMarkerPath() {
|
|
36858
|
-
return
|
|
37024
|
+
return join20(getCleoHome4(), MIGRATIONS_SUBDIR, MIGRATION_MARKER);
|
|
36859
37025
|
}
|
|
36860
37026
|
function tempTargetPath() {
|
|
36861
37027
|
return `${configDirGlobalConfigPath()}.tmp`;
|
|
@@ -36865,12 +37031,12 @@ function migrateGlobalConfigToConfigDir() {
|
|
|
36865
37031
|
const source = legacyGlobalConfigPath();
|
|
36866
37032
|
const target = configDirGlobalConfigPath();
|
|
36867
37033
|
const marker16 = migrationMarkerPath();
|
|
36868
|
-
if (
|
|
36869
|
-
if (!
|
|
37034
|
+
if (existsSync19(marker16)) return false;
|
|
37035
|
+
if (!existsSync19(source)) {
|
|
36870
37036
|
stampMarker(marker16);
|
|
36871
37037
|
return false;
|
|
36872
37038
|
}
|
|
36873
|
-
if (
|
|
37039
|
+
if (existsSync19(target)) {
|
|
36874
37040
|
backupSourceQuiet(source);
|
|
36875
37041
|
stampMarker(marker16);
|
|
36876
37042
|
return false;
|
|
@@ -36903,7 +37069,7 @@ function migrateGlobalConfigToConfigDir() {
|
|
|
36903
37069
|
} catch (err) {
|
|
36904
37070
|
try {
|
|
36905
37071
|
const temp = tempTargetPath();
|
|
36906
|
-
if (
|
|
37072
|
+
if (existsSync19(temp)) unlinkSync5(temp);
|
|
36907
37073
|
} catch {
|
|
36908
37074
|
}
|
|
36909
37075
|
console.error(
|
|
@@ -36914,7 +37080,7 @@ function migrateGlobalConfigToConfigDir() {
|
|
|
36914
37080
|
}
|
|
36915
37081
|
function stampMarker(markerPath) {
|
|
36916
37082
|
try {
|
|
36917
|
-
mkdirSync5(
|
|
37083
|
+
mkdirSync5(join20(getCleoHome4(), MIGRATIONS_SUBDIR), { recursive: true });
|
|
36918
37084
|
writeFileSync4(markerPath, `${(/* @__PURE__ */ new Date()).toISOString()}
|
|
36919
37085
|
`, { mode: 420 });
|
|
36920
37086
|
} catch {
|
|
@@ -36923,7 +37089,7 @@ function stampMarker(markerPath) {
|
|
|
36923
37089
|
function backupSourceQuiet(source) {
|
|
36924
37090
|
try {
|
|
36925
37091
|
const backup = `${source}${BACKUP_SUFFIX}`;
|
|
36926
|
-
if (
|
|
37092
|
+
if (existsSync19(backup)) return;
|
|
36927
37093
|
renameSync4(source, backup);
|
|
36928
37094
|
} catch {
|
|
36929
37095
|
}
|
|
@@ -36946,15 +37112,15 @@ var init_global_config_migration = __esm({
|
|
|
36946
37112
|
});
|
|
36947
37113
|
|
|
36948
37114
|
// packages/core/src/llm/legacy-flat-key-import.ts
|
|
36949
|
-
import { existsSync as
|
|
36950
|
-
import { join as
|
|
37115
|
+
import { existsSync as existsSync20, readFileSync as readFileSync11, renameSync as renameSync5, writeFileSync as writeFileSync5 } from "node:fs";
|
|
37116
|
+
import { join as join21 } from "node:path";
|
|
36951
37117
|
import { getCleoHome as getCleoHome5 } from "@cleocode/paths";
|
|
36952
37118
|
function migrationPaths() {
|
|
36953
37119
|
const home = getCleoHome5();
|
|
36954
37120
|
return {
|
|
36955
|
-
flatPath:
|
|
36956
|
-
bakPath:
|
|
36957
|
-
markerPath:
|
|
37121
|
+
flatPath: join21(home, "anthropic-key"),
|
|
37122
|
+
bakPath: join21(home, `anthropic-key${LEGACY_FLAT_KEY_BAK_SUFFIX}`),
|
|
37123
|
+
markerPath: join21(home, LEGACY_FLAT_KEY_MARKER)
|
|
36958
37124
|
};
|
|
36959
37125
|
}
|
|
36960
37126
|
function writeMarker(markerPath) {
|
|
@@ -36975,7 +37141,7 @@ function writeMarker(markerPath) {
|
|
|
36975
37141
|
}
|
|
36976
37142
|
function readFlatKey(flatPath) {
|
|
36977
37143
|
try {
|
|
36978
|
-
if (!
|
|
37144
|
+
if (!existsSync20(flatPath)) return null;
|
|
36979
37145
|
const raw = readFileSync11(flatPath, "utf-8").trim();
|
|
36980
37146
|
return raw || null;
|
|
36981
37147
|
} catch (err) {
|
|
@@ -36988,7 +37154,7 @@ function readFlatKey(flatPath) {
|
|
|
36988
37154
|
}
|
|
36989
37155
|
async function importLegacyFlatAnthropicKey() {
|
|
36990
37156
|
const { flatPath, bakPath, markerPath } = migrationPaths();
|
|
36991
|
-
if (
|
|
37157
|
+
if (existsSync20(markerPath)) {
|
|
36992
37158
|
return { status: "marker-present", flatPath, bakPath: null, markerPath };
|
|
36993
37159
|
}
|
|
36994
37160
|
let existing = null;
|
|
@@ -37005,7 +37171,7 @@ async function importLegacyFlatAnthropicKey() {
|
|
|
37005
37171
|
writeMarker(markerPath);
|
|
37006
37172
|
return { status: "already-imported", flatPath, bakPath: null, markerPath };
|
|
37007
37173
|
}
|
|
37008
|
-
if (!
|
|
37174
|
+
if (!existsSync20(flatPath)) {
|
|
37009
37175
|
writeMarker(markerPath);
|
|
37010
37176
|
return { status: "no-flat-file", flatPath, bakPath: null, markerPath };
|
|
37011
37177
|
}
|
|
@@ -37081,15 +37247,15 @@ __export(credentials_exports, {
|
|
|
37081
37247
|
resolveProviderStatus: () => resolveProviderStatus,
|
|
37082
37248
|
storeAnthropicApiKey: () => storeAnthropicApiKey
|
|
37083
37249
|
});
|
|
37084
|
-
import { existsSync as
|
|
37085
|
-
import { join as
|
|
37250
|
+
import { existsSync as existsSync21, mkdirSync as mkdirSync6, readFileSync as readFileSync12, writeFileSync as writeFileSync6 } from "node:fs";
|
|
37251
|
+
import { join as join22 } from "node:path";
|
|
37086
37252
|
import { getCleoHome as getCleoHome6 } from "@cleocode/paths";
|
|
37087
37253
|
function globalConfigPath() {
|
|
37088
37254
|
return configDirGlobalConfigPath();
|
|
37089
37255
|
}
|
|
37090
37256
|
function projectConfigPath(projectRoot) {
|
|
37091
37257
|
const cleoDir = process.env["CLEO_DIR"] ?? ".cleo";
|
|
37092
|
-
return
|
|
37258
|
+
return join22(projectRoot, cleoDir, "config.json");
|
|
37093
37259
|
}
|
|
37094
37260
|
function readGlobalProviderKey(provider) {
|
|
37095
37261
|
ensureGlobalConfigMigrated();
|
|
@@ -37099,8 +37265,8 @@ function readGlobalProviderKey(provider) {
|
|
|
37099
37265
|
}
|
|
37100
37266
|
function readFlatAnthropicKey() {
|
|
37101
37267
|
try {
|
|
37102
|
-
const keyFile =
|
|
37103
|
-
if (!
|
|
37268
|
+
const keyFile = join22(getCleoHome6(), "anthropic-key");
|
|
37269
|
+
if (!existsSync21(keyFile)) return null;
|
|
37104
37270
|
const stored = readFileSync12(keyFile, "utf-8").trim();
|
|
37105
37271
|
return stored || null;
|
|
37106
37272
|
} catch {
|
|
@@ -37109,7 +37275,7 @@ function readFlatAnthropicKey() {
|
|
|
37109
37275
|
}
|
|
37110
37276
|
function readProviderKeyFromConfig(configFile, provider) {
|
|
37111
37277
|
try {
|
|
37112
|
-
if (!
|
|
37278
|
+
if (!existsSync21(configFile)) return null;
|
|
37113
37279
|
const raw = readFileSync12(configFile, "utf-8");
|
|
37114
37280
|
const config2 = JSON.parse(raw);
|
|
37115
37281
|
const llm = config2["llm"];
|
|
@@ -37272,10 +37438,10 @@ function resolveProviderStatus(provider) {
|
|
|
37272
37438
|
}
|
|
37273
37439
|
function storeAnthropicApiKey(apiKey) {
|
|
37274
37440
|
const dir = getCleoHome6();
|
|
37275
|
-
if (!
|
|
37441
|
+
if (!existsSync21(dir)) {
|
|
37276
37442
|
mkdirSync6(dir, { recursive: true });
|
|
37277
37443
|
}
|
|
37278
|
-
const keyFile =
|
|
37444
|
+
const keyFile = join22(dir, "anthropic-key");
|
|
37279
37445
|
writeFileSync6(keyFile, apiKey.trim(), { mode: 384 });
|
|
37280
37446
|
}
|
|
37281
37447
|
function clearAnthropicKeyCache() {
|
|
@@ -37327,16 +37493,16 @@ var init_credentials2 = __esm({
|
|
|
37327
37493
|
});
|
|
37328
37494
|
|
|
37329
37495
|
// packages/core/src/llm/credentials-store.ts
|
|
37330
|
-
import { chmodSync, existsSync as
|
|
37331
|
-
import { dirname as
|
|
37496
|
+
import { chmodSync, existsSync as existsSync22, mkdirSync as mkdirSync7, readFileSync as readFileSync13, statSync as statSync6, writeFileSync as writeFileSync7 } from "node:fs";
|
|
37497
|
+
import { dirname as dirname9, join as join23 } from "node:path";
|
|
37332
37498
|
import { getCleoHome as getCleoHome7 } from "@cleocode/paths";
|
|
37333
37499
|
function credentialsStorePath() {
|
|
37334
|
-
return
|
|
37500
|
+
return join23(getCleoHome7(), "llm-credentials.json");
|
|
37335
37501
|
}
|
|
37336
37502
|
function ensureFileInitialized(path) {
|
|
37337
|
-
if (
|
|
37338
|
-
const dir =
|
|
37339
|
-
if (!
|
|
37503
|
+
if (existsSync22(path)) return;
|
|
37504
|
+
const dir = dirname9(path);
|
|
37505
|
+
if (!existsSync22(dir)) {
|
|
37340
37506
|
mkdirSync7(dir, { recursive: true, mode: 448 });
|
|
37341
37507
|
} else {
|
|
37342
37508
|
try {
|
|
@@ -37713,13 +37879,13 @@ var init_gemini = __esm({
|
|
|
37713
37879
|
|
|
37714
37880
|
// packages/core/src/llm/stable-device-id.ts
|
|
37715
37881
|
import { randomUUID } from "node:crypto";
|
|
37716
|
-
import { existsSync as
|
|
37717
|
-
import { dirname as
|
|
37882
|
+
import { existsSync as existsSync23, mkdirSync as mkdirSync8, readFileSync as readFileSync14, renameSync as renameSync6, writeFileSync as writeFileSync8 } from "node:fs";
|
|
37883
|
+
import { dirname as dirname10, join as join24 } from "node:path";
|
|
37718
37884
|
import { getCleoHome as getCleoHome8 } from "@cleocode/paths";
|
|
37719
37885
|
function getStableDeviceId() {
|
|
37720
37886
|
if (_cachedDeviceId !== null) return _cachedDeviceId;
|
|
37721
|
-
const path =
|
|
37722
|
-
if (
|
|
37887
|
+
const path = join24(getCleoHome8(), DEVICE_ID_FILE);
|
|
37888
|
+
if (existsSync23(path)) {
|
|
37723
37889
|
try {
|
|
37724
37890
|
const raw = readFileSync14(path, "utf-8").trim();
|
|
37725
37891
|
if (raw.length > 0) {
|
|
@@ -37731,8 +37897,8 @@ function getStableDeviceId() {
|
|
|
37731
37897
|
}
|
|
37732
37898
|
const fresh = randomUUID();
|
|
37733
37899
|
try {
|
|
37734
|
-
const dir =
|
|
37735
|
-
if (!
|
|
37900
|
+
const dir = dirname10(path);
|
|
37901
|
+
if (!existsSync23(dir)) {
|
|
37736
37902
|
mkdirSync8(dir, { recursive: true });
|
|
37737
37903
|
}
|
|
37738
37904
|
const tmpPath = `${path}.tmp.${process.pid}`;
|
|
@@ -38035,13 +38201,13 @@ var init_xai = __esm({
|
|
|
38035
38201
|
|
|
38036
38202
|
// packages/core/src/llm/provider-registry/loader.ts
|
|
38037
38203
|
import { readdirSync as readdirSync5, statSync as statSync7 } from "node:fs";
|
|
38038
|
-
import { join as
|
|
38204
|
+
import { join as join25 } from "node:path";
|
|
38039
38205
|
import { pathToFileURL } from "node:url";
|
|
38040
38206
|
function isPluginFile(filename) {
|
|
38041
38207
|
return PLUGIN_EXTENSIONS.some((ext) => filename.endsWith(ext));
|
|
38042
38208
|
}
|
|
38043
38209
|
function getPluginDir() {
|
|
38044
|
-
return
|
|
38210
|
+
return join25(getCleoHome(), "plugins", "model-providers");
|
|
38045
38211
|
}
|
|
38046
38212
|
async function loadOnePlugin(absPath, api) {
|
|
38047
38213
|
let mod;
|
|
@@ -38089,13 +38255,13 @@ async function scanAndLoadPlugins(pluginDir, api) {
|
|
|
38089
38255
|
}
|
|
38090
38256
|
const pluginFiles = entries.filter((name15) => !name15.startsWith(".") && isPluginFile(name15)).filter((name15) => {
|
|
38091
38257
|
try {
|
|
38092
|
-
return statSync7(
|
|
38258
|
+
return statSync7(join25(pluginDir, name15)).isFile();
|
|
38093
38259
|
} catch {
|
|
38094
38260
|
return false;
|
|
38095
38261
|
}
|
|
38096
38262
|
}).sort();
|
|
38097
38263
|
for (const filename of pluginFiles) {
|
|
38098
|
-
await loadOnePlugin(
|
|
38264
|
+
await loadOnePlugin(join25(pluginDir, filename), api);
|
|
38099
38265
|
}
|
|
38100
38266
|
}
|
|
38101
38267
|
async function runDiscovery(registerProvider2, builtins) {
|
|
@@ -38176,15 +38342,15 @@ var init_provider_registry = __esm({
|
|
|
38176
38342
|
});
|
|
38177
38343
|
|
|
38178
38344
|
// packages/core/src/llm/rate-limit-guard.ts
|
|
38179
|
-
import { existsSync as
|
|
38180
|
-
import { join as
|
|
38345
|
+
import { existsSync as existsSync24, mkdirSync as mkdirSync9, unlinkSync as unlinkSync6 } from "node:fs";
|
|
38346
|
+
import { join as join26 } from "node:path";
|
|
38181
38347
|
import { getCleoHome as getCleoHome9 } from "@cleocode/paths";
|
|
38182
38348
|
function sanitize(value) {
|
|
38183
38349
|
return value.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
38184
38350
|
}
|
|
38185
38351
|
function rateLimitStatePath(provider, label) {
|
|
38186
|
-
const dir =
|
|
38187
|
-
return
|
|
38352
|
+
const dir = join26(getCleoHome9(), "rate-limit-state");
|
|
38353
|
+
return join26(dir, `${sanitize(provider)}-${sanitize(label)}.json`);
|
|
38188
38354
|
}
|
|
38189
38355
|
function parseResetFromHeaders(headers) {
|
|
38190
38356
|
const get = (k) => {
|
|
@@ -38231,8 +38397,8 @@ async function recordRateLimit(provider, label, opts) {
|
|
|
38231
38397
|
source = "default";
|
|
38232
38398
|
}
|
|
38233
38399
|
const filePath = rateLimitStatePath(provider, label);
|
|
38234
|
-
const dir =
|
|
38235
|
-
if (!
|
|
38400
|
+
const dir = join26(getCleoHome9(), "rate-limit-state");
|
|
38401
|
+
if (!existsSync24(dir)) {
|
|
38236
38402
|
mkdirSync9(dir, { recursive: true });
|
|
38237
38403
|
}
|
|
38238
38404
|
const state = { resetAt, recordedAt: now, source };
|
|
@@ -39075,14 +39241,14 @@ var init_catalog_cache = __esm({
|
|
|
39075
39241
|
|
|
39076
39242
|
// packages/core/src/llm/model-metadata.ts
|
|
39077
39243
|
import { readFileSync as readFileSync15 } from "node:fs";
|
|
39078
|
-
import { dirname as
|
|
39244
|
+
import { dirname as dirname11, join as join27 } from "node:path";
|
|
39079
39245
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
39080
39246
|
function getCuratedTable() {
|
|
39081
39247
|
if (_curated !== void 0) {
|
|
39082
39248
|
return _curated;
|
|
39083
39249
|
}
|
|
39084
|
-
const thisDir =
|
|
39085
|
-
const jsonPath =
|
|
39250
|
+
const thisDir = dirname11(fileURLToPath3(import.meta.url));
|
|
39251
|
+
const jsonPath = join27(thisDir, "curated-models.json");
|
|
39086
39252
|
const raw = JSON.parse(readFileSync15(jsonPath, "utf-8"));
|
|
39087
39253
|
_curated = raw.models;
|
|
39088
39254
|
return _curated;
|