@cleocode/core 2026.6.9 → 2026.6.10
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 +227 -129
- package/dist/docs/export-document.js.map +2 -2
- package/dist/llm/plugin-facade.js +340 -241
- package/dist/llm/plugin-facade.js.map +2 -2
- package/dist/store/dual-scope-db.d.ts.map +1 -1
- package/dist/store/dual-scope-db.js +15 -0
- package/dist/store/dual-scope-db.js.map +1 -1
- package/dist/store/migration-manager.d.ts +99 -0
- package/dist/store/migration-manager.d.ts.map +1 -1
- package/dist/store/migration-manager.js +323 -23
- package/dist/store/migration-manager.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;
|
|
@@ -22743,6 +22821,8 @@ function probeAndMarkApplied(nativeDb, migration, logSubsystem) {
|
|
|
22743
22821
|
return false;
|
|
22744
22822
|
}
|
|
22745
22823
|
function reconcileJournal(nativeDb, migrationsFolder, existenceTable2, logSubsystem) {
|
|
22824
|
+
const eliminatedTables = computeEliminatedTables(readMigrationFiles({ migrationsFolder }));
|
|
22825
|
+
const cutoverPrefix = resolveConsolidationCutoverPrefix(migrationsFolder);
|
|
22746
22826
|
if (tableExists(nativeDb, existenceTable2) && !tableExists(nativeDb, "__drizzle_migrations")) {
|
|
22747
22827
|
const migrations = readMigrationFiles({ migrationsFolder });
|
|
22748
22828
|
const baseline = migrations[0];
|
|
@@ -22786,7 +22866,7 @@ function reconcileJournal(nativeDb, migrationsFolder, existenceTable2, logSubsys
|
|
|
22786
22866
|
);
|
|
22787
22867
|
for (const m of localMigrations) {
|
|
22788
22868
|
if (journaledHashesAfter.has(m.hash)) continue;
|
|
22789
|
-
probeAndMarkApplied(nativeDb, m, logSubsystem);
|
|
22869
|
+
probeAndMarkApplied(nativeDb, m, logSubsystem, eliminatedTables, cutoverPrefix);
|
|
22790
22870
|
}
|
|
22791
22871
|
}
|
|
22792
22872
|
}
|
|
@@ -22809,7 +22889,7 @@ function reconcileJournal(nativeDb, migrationsFolder, existenceTable2, logSubsys
|
|
|
22809
22889
|
});
|
|
22810
22890
|
}
|
|
22811
22891
|
if (alterMatches.length === 0) {
|
|
22812
|
-
const stripped = fullSql
|
|
22892
|
+
const stripped = stripSqlComments(fullSql).trim();
|
|
22813
22893
|
if (stripped === "") {
|
|
22814
22894
|
const log7 = getLogger(logSubsystem);
|
|
22815
22895
|
log7.debug(
|
|
@@ -22828,9 +22908,11 @@ function reconcileJournal(nativeDb, migrationsFolder, existenceTable2, logSubsys
|
|
|
22828
22908
|
const createTableRe = /CREATE\s+TABLE/i;
|
|
22829
22909
|
const createTriggerRe = /CREATE\s+TRIGGER/i;
|
|
22830
22910
|
if (renameRe.test(fullSql) && createTableRe.test(fullSql)) {
|
|
22831
|
-
probeAndMarkApplied(nativeDb, migration, logSubsystem);
|
|
22911
|
+
probeAndMarkApplied(nativeDb, migration, logSubsystem, eliminatedTables, cutoverPrefix);
|
|
22832
22912
|
} else if (createTableRe.test(fullSql) || createTriggerRe.test(fullSql)) {
|
|
22833
|
-
probeAndMarkApplied(nativeDb, migration, logSubsystem);
|
|
22913
|
+
probeAndMarkApplied(nativeDb, migration, logSubsystem, eliminatedTables, cutoverPrefix);
|
|
22914
|
+
} else {
|
|
22915
|
+
probeAndMarkApplied(nativeDb, migration, logSubsystem, eliminatedTables, cutoverPrefix);
|
|
22834
22916
|
}
|
|
22835
22917
|
continue;
|
|
22836
22918
|
}
|
|
@@ -22907,13 +22989,22 @@ function reconcileJournal(nativeDb, migrationsFolder, existenceTable2, logSubsys
|
|
|
22907
22989
|
}
|
|
22908
22990
|
}
|
|
22909
22991
|
}
|
|
22992
|
+
function collectErrorMessages(err) {
|
|
22993
|
+
const messages = [];
|
|
22994
|
+
let current = err;
|
|
22995
|
+
for (let depth = 0; current instanceof Error && depth < 16; depth++) {
|
|
22996
|
+
messages.push(current.message);
|
|
22997
|
+
current = current.cause;
|
|
22998
|
+
}
|
|
22999
|
+
return messages.join("\n");
|
|
23000
|
+
}
|
|
22910
23001
|
function isDuplicateColumnError(err) {
|
|
22911
23002
|
if (!(err instanceof Error)) return false;
|
|
22912
|
-
return /duplicate column name/i.test(err
|
|
23003
|
+
return /duplicate column name/i.test(collectErrorMessages(err));
|
|
22913
23004
|
}
|
|
22914
23005
|
function isTableAlreadyExistsError(err) {
|
|
22915
23006
|
if (!(err instanceof Error)) return false;
|
|
22916
|
-
return /table .+ already exists/i.test(err
|
|
23007
|
+
return /table .+ already exists/i.test(collectErrorMessages(err));
|
|
22917
23008
|
}
|
|
22918
23009
|
function isExecutableStatement(stmt) {
|
|
22919
23010
|
if (stmt.trim() === "") return false;
|
|
@@ -22984,7 +23075,7 @@ function ensureColumns(nativeDb, tableName, requiredColumns, logSubsystem, conte
|
|
|
22984
23075
|
}
|
|
22985
23076
|
}
|
|
22986
23077
|
}
|
|
22987
|
-
var MAX_MIGRATION_RETRIES, MIGRATION_RETRY_BASE_DELAY_MS, MIGRATION_RETRY_MAX_DELAY_MS;
|
|
23078
|
+
var MAX_MIGRATION_RETRIES, MIGRATION_RETRY_BASE_DELAY_MS, MIGRATION_RETRY_MAX_DELAY_MS, CONSOLIDATION_CUTOVER_PREFIX, MIGRATION_TIMESTAMP_PREFIX_LEN;
|
|
22988
23079
|
var init_migration_manager = __esm({
|
|
22989
23080
|
"packages/core/src/store/migration-manager.ts"() {
|
|
22990
23081
|
"use strict";
|
|
@@ -22994,27 +23085,29 @@ var init_migration_manager = __esm({
|
|
|
22994
23085
|
MAX_MIGRATION_RETRIES = 5;
|
|
22995
23086
|
MIGRATION_RETRY_BASE_DELAY_MS = 100;
|
|
22996
23087
|
MIGRATION_RETRY_MAX_DELAY_MS = 2e3;
|
|
23088
|
+
CONSOLIDATION_CUTOVER_PREFIX = "20260531000001";
|
|
23089
|
+
MIGRATION_TIMESTAMP_PREFIX_LEN = 14;
|
|
22997
23090
|
}
|
|
22998
23091
|
});
|
|
22999
23092
|
|
|
23000
23093
|
// packages/core/src/store/resolve-migrations-folder.ts
|
|
23001
23094
|
import { createRequire } from "node:module";
|
|
23002
|
-
import { dirname, join as
|
|
23095
|
+
import { dirname as dirname2, join as join4 } from "node:path";
|
|
23003
23096
|
import { fileURLToPath } from "node:url";
|
|
23004
23097
|
function coreRootFromEntry(entryPath) {
|
|
23005
|
-
return
|
|
23098
|
+
return dirname2(dirname2(entryPath));
|
|
23006
23099
|
}
|
|
23007
23100
|
function resolveCorePackageMigrationsFolder(setName) {
|
|
23008
23101
|
try {
|
|
23009
23102
|
const resolved = import.meta.resolve("@cleocode/core", import.meta.url);
|
|
23010
23103
|
const entryPath = fileURLToPath(resolved);
|
|
23011
|
-
return
|
|
23104
|
+
return join4(coreRootFromEntry(entryPath), "migrations", setName);
|
|
23012
23105
|
} catch {
|
|
23013
23106
|
}
|
|
23014
23107
|
const _require3 = createRequire(import.meta.url);
|
|
23015
23108
|
try {
|
|
23016
23109
|
const entryPath = _require3.resolve("@cleocode/core");
|
|
23017
|
-
return
|
|
23110
|
+
return join4(coreRootFromEntry(entryPath), "migrations", setName);
|
|
23018
23111
|
} catch (err) {
|
|
23019
23112
|
throw new Error(
|
|
23020
23113
|
`resolveCorePackageMigrationsFolder("${setName}"): cannot locate @cleocode/core from "${import.meta.url}". Ensure @cleocode/core is installed (workspace or npm). Original error: ${err.message}`
|
|
@@ -31094,11 +31187,11 @@ var init_lock = __esm({
|
|
|
31094
31187
|
|
|
31095
31188
|
// packages/core/src/store/atomic.ts
|
|
31096
31189
|
import { mkdir, readFile as readFile2, rename, unlink } from "node:fs/promises";
|
|
31097
|
-
import { dirname as
|
|
31190
|
+
import { dirname as dirname3 } from "node:path";
|
|
31098
31191
|
import writeFileAtomic from "write-file-atomic";
|
|
31099
31192
|
async function atomicWrite(filePath, data, options) {
|
|
31100
31193
|
try {
|
|
31101
|
-
await mkdir(
|
|
31194
|
+
await mkdir(dirname3(filePath), { recursive: true });
|
|
31102
31195
|
await writeFileAtomic(filePath, data, {
|
|
31103
31196
|
encoding: options?.encoding ?? "utf8",
|
|
31104
31197
|
mode: options?.mode
|
|
@@ -31131,7 +31224,7 @@ var init_atomic = __esm({
|
|
|
31131
31224
|
|
|
31132
31225
|
// packages/core/src/store/backup.ts
|
|
31133
31226
|
import { copyFile, rename as fsRename, mkdir as mkdir2, readdir, stat, unlink as unlink2 } from "node:fs/promises";
|
|
31134
|
-
import { basename, join as
|
|
31227
|
+
import { basename, join as join5 } from "node:path";
|
|
31135
31228
|
async function createBackup(filePath, backupDir, maxBackups = DEFAULT_MAX_BACKUPS) {
|
|
31136
31229
|
try {
|
|
31137
31230
|
await mkdir2(backupDir, { recursive: true });
|
|
@@ -31142,14 +31235,14 @@ async function createBackup(filePath, backupDir, maxBackups = DEFAULT_MAX_BACKUP
|
|
|
31142
31235
|
throw new CleoError(3 /* FILE_ERROR */, `Cannot backup: source file not found: ${filePath}`);
|
|
31143
31236
|
}
|
|
31144
31237
|
for (let i = maxBackups; i >= 1; i--) {
|
|
31145
|
-
const current =
|
|
31238
|
+
const current = join5(backupDir, `${fileName}.${i}`);
|
|
31146
31239
|
if (i === maxBackups) {
|
|
31147
31240
|
try {
|
|
31148
31241
|
await unlink2(current);
|
|
31149
31242
|
} catch {
|
|
31150
31243
|
}
|
|
31151
31244
|
} else {
|
|
31152
|
-
const next =
|
|
31245
|
+
const next = join5(backupDir, `${fileName}.${i + 1}`);
|
|
31153
31246
|
try {
|
|
31154
31247
|
await stat(current);
|
|
31155
31248
|
await fsRename(current, next);
|
|
@@ -31157,7 +31250,7 @@ async function createBackup(filePath, backupDir, maxBackups = DEFAULT_MAX_BACKUP
|
|
|
31157
31250
|
}
|
|
31158
31251
|
}
|
|
31159
31252
|
}
|
|
31160
|
-
const backupPath =
|
|
31253
|
+
const backupPath = join5(backupDir, `${fileName}.1`);
|
|
31161
31254
|
await copyFile(filePath, backupPath);
|
|
31162
31255
|
return backupPath;
|
|
31163
31256
|
} catch (err) {
|
|
@@ -31436,16 +31529,16 @@ var init_json2 = __esm({
|
|
|
31436
31529
|
});
|
|
31437
31530
|
|
|
31438
31531
|
// packages/core/src/scaffold/ensure-config.ts
|
|
31439
|
-
import { existsSync as
|
|
31440
|
-
import { basename as basename2, dirname as
|
|
31532
|
+
import { existsSync as existsSync3, readFileSync } from "node:fs";
|
|
31533
|
+
import { basename as basename2, dirname as dirname4, join as join6, resolve as resolve2 } from "node:path";
|
|
31441
31534
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
31442
31535
|
function getPackageRoot() {
|
|
31443
31536
|
const thisFile = fileURLToPath2(import.meta.url);
|
|
31444
|
-
return resolve2(
|
|
31537
|
+
return resolve2(dirname4(thisFile), "..", "..");
|
|
31445
31538
|
}
|
|
31446
31539
|
function getCleoVersion() {
|
|
31447
31540
|
try {
|
|
31448
|
-
const pkgPath =
|
|
31541
|
+
const pkgPath = join6(getPackageRoot(), "package.json");
|
|
31449
31542
|
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
31450
31543
|
return pkg.version ?? "0.0.0";
|
|
31451
31544
|
} catch {
|
|
@@ -31463,26 +31556,26 @@ var init_ensure_config = __esm({
|
|
|
31463
31556
|
|
|
31464
31557
|
// packages/core/src/store/exodus/archive.ts
|
|
31465
31558
|
import {
|
|
31466
|
-
copyFileSync,
|
|
31467
|
-
existsSync as
|
|
31559
|
+
copyFileSync as copyFileSync2,
|
|
31560
|
+
existsSync as existsSync4,
|
|
31468
31561
|
mkdirSync,
|
|
31469
31562
|
renameSync,
|
|
31470
31563
|
unlinkSync,
|
|
31471
31564
|
writeFileSync
|
|
31472
31565
|
} from "node:fs";
|
|
31473
|
-
import { basename as basename3, join as
|
|
31566
|
+
import { basename as basename3, join as join7 } from "node:path";
|
|
31474
31567
|
function scopeBaseDir(scope, cwd) {
|
|
31475
31568
|
return scope === "project" ? resolveCleoDir(cwd) : getCleoHome();
|
|
31476
31569
|
}
|
|
31477
31570
|
function exodusArchiveDir(scope, cwd) {
|
|
31478
|
-
return
|
|
31571
|
+
return join7(scopeBaseDir(scope, cwd), ARCHIVE_DIR_NAME);
|
|
31479
31572
|
}
|
|
31480
31573
|
function exodusMarkerPath(scope, cwd) {
|
|
31481
|
-
return
|
|
31574
|
+
return join7(scopeBaseDir(scope, cwd), MARKER_FILENAME_BY_SCOPE[scope]);
|
|
31482
31575
|
}
|
|
31483
31576
|
function hasExodusCompleteMarker(scope, cwd) {
|
|
31484
31577
|
try {
|
|
31485
|
-
return
|
|
31578
|
+
return existsSync4(exodusMarkerPath(scope, cwd));
|
|
31486
31579
|
} catch {
|
|
31487
31580
|
return false;
|
|
31488
31581
|
}
|
|
@@ -31506,28 +31599,28 @@ function writeExodusCompleteMarker(scope, archivedSources, cwd) {
|
|
|
31506
31599
|
}
|
|
31507
31600
|
function moveFileInto(srcPath, destDir) {
|
|
31508
31601
|
mkdirSync(destDir, { recursive: true });
|
|
31509
|
-
let dest =
|
|
31510
|
-
if (
|
|
31602
|
+
let dest = join7(destDir, basename3(srcPath));
|
|
31603
|
+
if (existsSync4(dest)) {
|
|
31511
31604
|
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "").replace(/Z$/, "Z");
|
|
31512
|
-
dest =
|
|
31605
|
+
dest = join7(destDir, `${basename3(srcPath)}.${stamp}`);
|
|
31513
31606
|
}
|
|
31514
31607
|
try {
|
|
31515
31608
|
renameSync(srcPath, dest);
|
|
31516
31609
|
} catch {
|
|
31517
|
-
|
|
31610
|
+
copyFileSync2(srcPath, dest);
|
|
31518
31611
|
unlinkSync(srcPath);
|
|
31519
31612
|
}
|
|
31520
31613
|
return dest;
|
|
31521
31614
|
}
|
|
31522
31615
|
function archiveSourceDb(source, cwd) {
|
|
31523
|
-
if (!
|
|
31616
|
+
if (!existsSync4(source.path)) {
|
|
31524
31617
|
return { name: source.name, sourcePath: source.path, archivedTo: null, action: "absent" };
|
|
31525
31618
|
}
|
|
31526
31619
|
const destDir = exodusArchiveDir(source.targetScope, cwd);
|
|
31527
31620
|
const archivedTo = moveFileInto(source.path, destDir);
|
|
31528
31621
|
for (const suffix of SIDECAR_SUFFIXES) {
|
|
31529
31622
|
const sidecar = `${source.path}${suffix}`;
|
|
31530
|
-
if (
|
|
31623
|
+
if (existsSync4(sidecar)) {
|
|
31531
31624
|
try {
|
|
31532
31625
|
moveFileInto(sidecar, destDir);
|
|
31533
31626
|
} catch (err) {
|
|
@@ -31573,7 +31666,7 @@ function detectStrandedResidue(sources, cwd) {
|
|
|
31573
31666
|
const stranded = [];
|
|
31574
31667
|
for (const source of sources) {
|
|
31575
31668
|
if (!markedScopes.has(source.targetScope)) continue;
|
|
31576
|
-
if (
|
|
31669
|
+
if (existsSync4(source.path)) {
|
|
31577
31670
|
stranded.push({ name: source.name, path: source.path, scope: source.targetScope });
|
|
31578
31671
|
}
|
|
31579
31672
|
}
|
|
@@ -31990,7 +32083,7 @@ var init_table_name_map = __esm({
|
|
|
31990
32083
|
});
|
|
31991
32084
|
|
|
31992
32085
|
// packages/core/src/store/exodus/count-parity.ts
|
|
31993
|
-
import { existsSync as
|
|
32086
|
+
import { existsSync as existsSync5 } from "node:fs";
|
|
31994
32087
|
function listTables(db) {
|
|
31995
32088
|
return db.prepare(
|
|
31996
32089
|
"SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' AND name NOT LIKE '__drizzle_%' ORDER BY name"
|
|
@@ -32011,14 +32104,14 @@ function rowCount(db, tableName) {
|
|
|
32011
32104
|
function computeCountParity(sources, projectDbPath, globalDbPath) {
|
|
32012
32105
|
const entries = [];
|
|
32013
32106
|
let skipped = 0;
|
|
32014
|
-
if (!
|
|
32107
|
+
if (!existsSync5(projectDbPath) || !existsSync5(globalDbPath)) {
|
|
32015
32108
|
return { ok: false, entries: [], deficits: [], checked: 0, skipped: 0 };
|
|
32016
32109
|
}
|
|
32017
32110
|
const projectSnap = openCleoDbSnapshot(projectDbPath, { readOnly: true });
|
|
32018
32111
|
const globalSnap = openCleoDbSnapshot(globalDbPath, { readOnly: true });
|
|
32019
32112
|
try {
|
|
32020
32113
|
for (const src of sources) {
|
|
32021
|
-
if (!
|
|
32114
|
+
if (!existsSync5(src.path)) continue;
|
|
32022
32115
|
const srcSnap = openCleoDbSnapshot(src.path, { readOnly: true });
|
|
32023
32116
|
try {
|
|
32024
32117
|
for (const legacyTable of listTables(srcSnap.db)) {
|
|
@@ -32076,8 +32169,8 @@ var init_count_parity = __esm({
|
|
|
32076
32169
|
});
|
|
32077
32170
|
|
|
32078
32171
|
// packages/core/src/store/exodus/plan.ts
|
|
32079
|
-
import { existsSync as
|
|
32080
|
-
import { join as
|
|
32172
|
+
import { existsSync as existsSync6, readdirSync as readdirSync2, statfsSync, statSync } from "node:fs";
|
|
32173
|
+
import { join as join8 } from "node:path";
|
|
32081
32174
|
function computeRequiredBytes(totalSourceBytes, largestSourceBytes) {
|
|
32082
32175
|
return Math.ceil(STAGING_HEADROOM_FACTOR * largestSourceBytes) + totalSourceBytes;
|
|
32083
32176
|
}
|
|
@@ -32088,33 +32181,33 @@ function buildSourceDescriptors(cwd) {
|
|
|
32088
32181
|
// Project-tier — go into consolidated project-scope cleo.db
|
|
32089
32182
|
{
|
|
32090
32183
|
name: "tasks",
|
|
32091
|
-
path:
|
|
32184
|
+
path: join8(cleoDir, "tasks.db"),
|
|
32092
32185
|
targetScope: "project"
|
|
32093
32186
|
},
|
|
32094
32187
|
{
|
|
32095
32188
|
name: "brain (project)",
|
|
32096
|
-
path:
|
|
32189
|
+
path: join8(cleoDir, "brain.db"),
|
|
32097
32190
|
targetScope: "project"
|
|
32098
32191
|
},
|
|
32099
32192
|
{
|
|
32100
32193
|
name: "conduit",
|
|
32101
|
-
path:
|
|
32194
|
+
path: join8(cleoDir, "conduit.db"),
|
|
32102
32195
|
targetScope: "project"
|
|
32103
32196
|
},
|
|
32104
32197
|
// Global-tier — go into consolidated global-scope cleo.db
|
|
32105
32198
|
{
|
|
32106
32199
|
name: "nexus",
|
|
32107
|
-
path:
|
|
32200
|
+
path: join8(cleoHome, "nexus.db"),
|
|
32108
32201
|
targetScope: "global"
|
|
32109
32202
|
},
|
|
32110
32203
|
{
|
|
32111
32204
|
name: "signaldock",
|
|
32112
|
-
path:
|
|
32205
|
+
path: join8(cleoHome, "signaldock.db"),
|
|
32113
32206
|
targetScope: "global"
|
|
32114
32207
|
},
|
|
32115
32208
|
{
|
|
32116
32209
|
name: "skills",
|
|
32117
|
-
path:
|
|
32210
|
+
path: join8(cleoHome, "skills.db"),
|
|
32118
32211
|
targetScope: "global"
|
|
32119
32212
|
}
|
|
32120
32213
|
];
|
|
@@ -32143,7 +32236,7 @@ function findExistingStaging(cleoDir) {
|
|
|
32143
32236
|
const entries = readdirSync2(cleoDir, { withFileTypes: true });
|
|
32144
32237
|
const stagingDirs = entries.filter((e) => e.isDirectory() && e.name.startsWith("exodus-staging-")).map((e) => e.name).sort().reverse();
|
|
32145
32238
|
if (stagingDirs.length > 0) {
|
|
32146
|
-
return
|
|
32239
|
+
return join8(cleoDir, stagingDirs[0]);
|
|
32147
32240
|
}
|
|
32148
32241
|
} catch {
|
|
32149
32242
|
}
|
|
@@ -32159,7 +32252,7 @@ function buildExodusPlan(cwd) {
|
|
|
32159
32252
|
const availableBytes = getAvailableBytes(cleoDir);
|
|
32160
32253
|
const diskPreflight = totalSourceBytes === 0 || availableBytes >= requiredBytes;
|
|
32161
32254
|
const existingStaging = findExistingStaging(cleoDir);
|
|
32162
|
-
const stagingDir = existingStaging ??
|
|
32255
|
+
const stagingDir = existingStaging ?? join8(cleoDir, deriveStagingDirName());
|
|
32163
32256
|
const resumeFromStaging = existingStaging !== null;
|
|
32164
32257
|
const projectDbPath = resolveDualScopeDbPath("project", cwd);
|
|
32165
32258
|
const globalDbPath = resolveDualScopeDbPath("global");
|
|
@@ -32178,7 +32271,7 @@ function buildExodusPlan(cwd) {
|
|
|
32178
32271
|
};
|
|
32179
32272
|
}
|
|
32180
32273
|
function sourcesPresent(sources) {
|
|
32181
|
-
return sources.some((s) =>
|
|
32274
|
+
return sources.some((s) => existsSync6(s.path));
|
|
32182
32275
|
}
|
|
32183
32276
|
var STAGING_HEADROOM_FACTOR, STAGING_COPY_SKIP_THRESHOLD_BYTES;
|
|
32184
32277
|
var init_plan2 = __esm({
|
|
@@ -32192,18 +32285,18 @@ var init_plan2 = __esm({
|
|
|
32192
32285
|
});
|
|
32193
32286
|
|
|
32194
32287
|
// packages/core/src/store/exodus/health.ts
|
|
32195
|
-
import { existsSync as
|
|
32288
|
+
import { existsSync as existsSync7, statSync as statSync2 } from "node:fs";
|
|
32196
32289
|
function buildExodusHealth(cwd) {
|
|
32197
32290
|
const plan = buildExodusPlan(cwd);
|
|
32198
|
-
const anyLegacyPresent = plan.sources.some((s) =>
|
|
32291
|
+
const anyLegacyPresent = plan.sources.some((s) => existsSync7(s.path));
|
|
32199
32292
|
const parity = anyLegacyPresent ? computeCountParity(plan.sources, plan.projectDbPath, plan.globalDbPath) : { ok: true, entries: [], deficits: [], checked: 0, skipped: 0 };
|
|
32200
32293
|
const consolidatedExistsByScope = {
|
|
32201
|
-
project:
|
|
32202
|
-
global:
|
|
32294
|
+
project: existsSync7(plan.projectDbPath),
|
|
32295
|
+
global: existsSync7(plan.globalDbPath)
|
|
32203
32296
|
};
|
|
32204
32297
|
const buildScope = (scope) => {
|
|
32205
32298
|
const sources = plan.sources.filter((s) => s.targetScope === scope).map((s) => {
|
|
32206
|
-
const present =
|
|
32299
|
+
const present = existsSync7(s.path);
|
|
32207
32300
|
let bytes = 0;
|
|
32208
32301
|
if (present) {
|
|
32209
32302
|
try {
|
|
@@ -32469,8 +32562,8 @@ var init_types = __esm({
|
|
|
32469
32562
|
|
|
32470
32563
|
// packages/core/src/store/exodus/migrate.ts
|
|
32471
32564
|
import {
|
|
32472
|
-
copyFileSync as
|
|
32473
|
-
existsSync as
|
|
32565
|
+
copyFileSync as copyFileSync3,
|
|
32566
|
+
existsSync as existsSync8,
|
|
32474
32567
|
mkdirSync as mkdirSync2,
|
|
32475
32568
|
readFileSync as readFileSync2,
|
|
32476
32569
|
renameSync as renameSync2,
|
|
@@ -32478,7 +32571,7 @@ import {
|
|
|
32478
32571
|
unlinkSync as unlinkSync2,
|
|
32479
32572
|
writeFileSync as writeFileSync2
|
|
32480
32573
|
} from "node:fs";
|
|
32481
|
-
import { join as
|
|
32574
|
+
import { join as join9 } from "node:path";
|
|
32482
32575
|
function getSqliteVersion(db) {
|
|
32483
32576
|
try {
|
|
32484
32577
|
const row = db.prepare("SELECT sqlite_version() AS v").get();
|
|
@@ -32494,14 +32587,14 @@ function listTables2(db) {
|
|
|
32494
32587
|
return rows.map((r) => r.name);
|
|
32495
32588
|
}
|
|
32496
32589
|
function writeJournal(stagingDir, journal) {
|
|
32497
|
-
const journalPath =
|
|
32590
|
+
const journalPath = join9(stagingDir, JOURNAL_FILENAME);
|
|
32498
32591
|
const tmpPath = `${journalPath}.tmp`;
|
|
32499
32592
|
writeFileSync2(tmpPath, JSON.stringify(journal, null, 2) + "\n", "utf8");
|
|
32500
32593
|
renameSync2(tmpPath, journalPath);
|
|
32501
32594
|
}
|
|
32502
32595
|
function readJournal(stagingDir) {
|
|
32503
|
-
const journalPath =
|
|
32504
|
-
if (!
|
|
32596
|
+
const journalPath = join9(stagingDir, JOURNAL_FILENAME);
|
|
32597
|
+
if (!existsSync8(journalPath)) return null;
|
|
32505
32598
|
try {
|
|
32506
32599
|
return JSON.parse(readFileSync2(journalPath, "utf8"));
|
|
32507
32600
|
} catch {
|
|
@@ -32509,9 +32602,9 @@ function readJournal(stagingDir) {
|
|
|
32509
32602
|
}
|
|
32510
32603
|
}
|
|
32511
32604
|
function clearExodusJournal(stagingDir) {
|
|
32512
|
-
const journalPath =
|
|
32605
|
+
const journalPath = join9(stagingDir, JOURNAL_FILENAME);
|
|
32513
32606
|
try {
|
|
32514
|
-
if (!
|
|
32607
|
+
if (!existsSync8(journalPath)) return false;
|
|
32515
32608
|
unlinkSync2(journalPath);
|
|
32516
32609
|
log3.info(
|
|
32517
32610
|
{ stagingDir },
|
|
@@ -32776,7 +32869,7 @@ async function runExodusMigrate(plan, forceCrossVersion = false, onProgress) {
|
|
|
32776
32869
|
mkdirSync2(stagingDir, { recursive: true });
|
|
32777
32870
|
let sqliteVersion = "unknown";
|
|
32778
32871
|
for (const src of sources) {
|
|
32779
|
-
if (
|
|
32872
|
+
if (existsSync8(src.path)) {
|
|
32780
32873
|
const snap = openCleoDbSnapshot(src.path, { readOnly: true });
|
|
32781
32874
|
sqliteVersion = getSqliteVersion(snap.db);
|
|
32782
32875
|
snap.close();
|
|
@@ -32817,17 +32910,17 @@ async function runExodusMigrate(plan, forceCrossVersion = false, onProgress) {
|
|
|
32817
32910
|
};
|
|
32818
32911
|
var extractNativeDb = extractNativeDb2;
|
|
32819
32912
|
for (const src of sources) {
|
|
32820
|
-
if (!
|
|
32821
|
-
const backupDest =
|
|
32913
|
+
if (!existsSync8(src.path)) continue;
|
|
32914
|
+
const backupDest = join9(stagingDir, `${src.name.replace(/[^a-z0-9-]/g, "_")}-backup.db`);
|
|
32822
32915
|
const srcBytes = safeStatBytes(src.path);
|
|
32823
32916
|
const skipStagingCopy = srcBytes > plan.stagingCopyThresholdBytes;
|
|
32824
32917
|
if (skipStagingCopy) {
|
|
32825
32918
|
onProgress?.(
|
|
32826
32919
|
`Skipping full staging copy of ${src.name} (${srcBytes} bytes > ${plan.stagingCopyThresholdBytes} threshold) \u2014 source is archived, not deleted, on success.`
|
|
32827
32920
|
);
|
|
32828
|
-
} else if (!
|
|
32921
|
+
} else if (!existsSync8(backupDest)) {
|
|
32829
32922
|
onProgress?.(`Backing up ${src.name} \u2192 staging dir\u2026`);
|
|
32830
|
-
|
|
32923
|
+
copyFileSync3(src.path, backupDest);
|
|
32831
32924
|
backupPaths.push(backupDest);
|
|
32832
32925
|
}
|
|
32833
32926
|
acquireAdvisoryLock(src.path);
|
|
@@ -32843,8 +32936,8 @@ async function runExodusMigrate(plan, forceCrossVersion = false, onProgress) {
|
|
|
32843
32936
|
});
|
|
32844
32937
|
const projectNative = extractNativeDb2(projectHandle);
|
|
32845
32938
|
const globalNative = extractNativeDb2(globalHandle);
|
|
32846
|
-
const projectSources = sources.filter((s) => s.targetScope === "project" &&
|
|
32847
|
-
const globalSources = sources.filter((s) => s.targetScope === "global" &&
|
|
32939
|
+
const projectSources = sources.filter((s) => s.targetScope === "project" && existsSync8(s.path));
|
|
32940
|
+
const globalSources = sources.filter((s) => s.targetScope === "global" && existsSync8(s.path));
|
|
32848
32941
|
await migrateScope(
|
|
32849
32942
|
"project",
|
|
32850
32943
|
projectSources,
|
|
@@ -33119,11 +33212,11 @@ var init_seal = __esm({
|
|
|
33119
33212
|
});
|
|
33120
33213
|
|
|
33121
33214
|
// packages/core/src/store/exodus/status.ts
|
|
33122
|
-
import { existsSync as
|
|
33123
|
-
import { join as
|
|
33215
|
+
import { existsSync as existsSync9, readdirSync as readdirSync3, readFileSync as readFileSync3, statSync as statSync4 } from "node:fs";
|
|
33216
|
+
import { join as join10 } from "node:path";
|
|
33124
33217
|
function readJournal2(stagingDir) {
|
|
33125
|
-
const p =
|
|
33126
|
-
if (!
|
|
33218
|
+
const p = join10(stagingDir, JOURNAL_FILENAME2);
|
|
33219
|
+
if (!existsSync9(p)) return null;
|
|
33127
33220
|
try {
|
|
33128
33221
|
return JSON.parse(readFileSync3(p, "utf8"));
|
|
33129
33222
|
} catch {
|
|
@@ -33132,7 +33225,7 @@ function readJournal2(stagingDir) {
|
|
|
33132
33225
|
}
|
|
33133
33226
|
function findStagingDirs(cleoDir) {
|
|
33134
33227
|
try {
|
|
33135
|
-
return readdirSync3(cleoDir, { withFileTypes: true }).filter((e) => e.isDirectory() && e.name.startsWith("exodus-staging-")).map((e) =>
|
|
33228
|
+
return readdirSync3(cleoDir, { withFileTypes: true }).filter((e) => e.isDirectory() && e.name.startsWith("exodus-staging-")).map((e) => join10(cleoDir, e.name)).sort().reverse();
|
|
33136
33229
|
} catch {
|
|
33137
33230
|
return [];
|
|
33138
33231
|
}
|
|
@@ -33155,15 +33248,15 @@ function runExodusStatus(cwd) {
|
|
|
33155
33248
|
const sourcesInfo = plan.sources.map((s) => ({
|
|
33156
33249
|
name: s.name,
|
|
33157
33250
|
path: s.path,
|
|
33158
|
-
exists:
|
|
33251
|
+
exists: existsSync9(s.path),
|
|
33159
33252
|
bytes: safeBytes(s.path)
|
|
33160
33253
|
}));
|
|
33161
33254
|
return {
|
|
33162
33255
|
hasStaging: latestStaging !== null,
|
|
33163
33256
|
stagingDir: latestStaging,
|
|
33164
33257
|
journal,
|
|
33165
|
-
projectDbExists:
|
|
33166
|
-
globalDbExists:
|
|
33258
|
+
projectDbExists: existsSync9(projectDbPath),
|
|
33259
|
+
globalDbExists: existsSync9(globalDbPath),
|
|
33167
33260
|
sourcesPresent: sourcesInfo.some((s) => s.exists),
|
|
33168
33261
|
sources: sourcesInfo
|
|
33169
33262
|
};
|
|
@@ -33180,7 +33273,7 @@ var init_status = __esm({
|
|
|
33180
33273
|
});
|
|
33181
33274
|
|
|
33182
33275
|
// packages/core/src/store/exodus/verify-migration.ts
|
|
33183
|
-
import { existsSync as
|
|
33276
|
+
import { existsSync as existsSync10 } from "node:fs";
|
|
33184
33277
|
import { createRequire as createRequire3 } from "node:module";
|
|
33185
33278
|
function orderByClause(db, tableName) {
|
|
33186
33279
|
try {
|
|
@@ -33428,7 +33521,7 @@ function verifyMigration(sources, projectDbPath, globalDbPath, onProgress) {
|
|
|
33428
33521
|
const preExistingForeignKeyViolations = [];
|
|
33429
33522
|
const failureLines = [];
|
|
33430
33523
|
const sourceOrphanSigs = /* @__PURE__ */ new Set();
|
|
33431
|
-
if (!
|
|
33524
|
+
if (!existsSync10(projectDbPath)) {
|
|
33432
33525
|
return {
|
|
33433
33526
|
ok: false,
|
|
33434
33527
|
tables: [],
|
|
@@ -33439,7 +33532,7 @@ function verifyMigration(sources, projectDbPath, globalDbPath, onProgress) {
|
|
|
33439
33532
|
error: `Consolidated project cleo.db not found at ${projectDbPath}. Run 'cleo exodus migrate' first.`
|
|
33440
33533
|
};
|
|
33441
33534
|
}
|
|
33442
|
-
if (!
|
|
33535
|
+
if (!existsSync10(globalDbPath)) {
|
|
33443
33536
|
return {
|
|
33444
33537
|
ok: false,
|
|
33445
33538
|
tables: [],
|
|
@@ -33454,7 +33547,7 @@ function verifyMigration(sources, projectDbPath, globalDbPath, onProgress) {
|
|
|
33454
33547
|
const globalSnap = openCleoDbSnapshot(globalDbPath, { readOnly: true });
|
|
33455
33548
|
try {
|
|
33456
33549
|
for (const src of sources) {
|
|
33457
|
-
if (!
|
|
33550
|
+
if (!existsSync10(src.path)) {
|
|
33458
33551
|
onProgress?.(`Skipping ${src.name} (not present)`);
|
|
33459
33552
|
continue;
|
|
33460
33553
|
}
|
|
@@ -33737,7 +33830,7 @@ __export(on_open_exports, {
|
|
|
33737
33830
|
isDataContinuityOk: () => isDataContinuityOk,
|
|
33738
33831
|
maybeRunExodusOnOpen: () => maybeRunExodusOnOpen
|
|
33739
33832
|
});
|
|
33740
|
-
import { existsSync as
|
|
33833
|
+
import { existsSync as existsSync11 } from "node:fs";
|
|
33741
33834
|
function isDisabledByEnv() {
|
|
33742
33835
|
const v = process.env.CLEO_DISABLE_EXODUS_ON_OPEN;
|
|
33743
33836
|
return v === "1" || v === "true";
|
|
@@ -33852,7 +33945,7 @@ async function maybeRunExodusOnOpen(scope, dbPath, nativeDb, cwd) {
|
|
|
33852
33945
|
const { buildExodusPlan: buildExodusPlan2, runExodusMigrate: runExodusMigrate2, verifyMigration: verifyMigration2, clearExodusJournal: clearExodusJournal2 } = await Promise.resolve().then(() => (init_exodus(), exodus_exports));
|
|
33853
33946
|
const plan = buildExodusPlan2(cwd);
|
|
33854
33947
|
const scopeSources = plan.sources.filter((s) => s.targetScope === scope);
|
|
33855
|
-
if (!scopeSources.some((s) =>
|
|
33948
|
+
if (!scopeSources.some((s) => existsSync11(s.path))) {
|
|
33856
33949
|
return {
|
|
33857
33950
|
outcome: "skipped",
|
|
33858
33951
|
reason: `no legacy ${scope}-scope source DBs present (fresh install or cross-scope-only)`
|
|
@@ -33869,7 +33962,7 @@ async function maybeRunExodusOnOpen(scope, dbPath, nativeDb, cwd) {
|
|
|
33869
33962
|
{
|
|
33870
33963
|
scope,
|
|
33871
33964
|
dbPath,
|
|
33872
|
-
sources: plan.sources.filter((s) =>
|
|
33965
|
+
sources: plan.sources.filter((s) => existsSync11(s.path)).map((s) => s.name)
|
|
33873
33966
|
},
|
|
33874
33967
|
"exodus-on-open: consolidated cleo.db is empty and legacy data present \u2014 auto-migrating"
|
|
33875
33968
|
);
|
|
@@ -33925,7 +34018,7 @@ async function maybeRunExodusOnOpen(scope, dbPath, nativeDb, cwd) {
|
|
|
33925
34018
|
"exodus-on-open: parity verified \u2014 legacy data migrated into consolidated cleo.db"
|
|
33926
34019
|
);
|
|
33927
34020
|
try {
|
|
33928
|
-
const consumed = plan.sources.filter((s) =>
|
|
34021
|
+
const consumed = plan.sources.filter((s) => existsSync11(s.path));
|
|
33929
34022
|
const archiveResult = archiveMigratedSources(consumed, cwd);
|
|
33930
34023
|
log6.info(
|
|
33931
34024
|
{
|
|
@@ -33982,9 +34075,9 @@ __export(dual_scope_db_exports, {
|
|
|
33982
34075
|
resolveDualScopeDbPath: () => resolveDualScopeDbPath,
|
|
33983
34076
|
upsertIdempotent: () => upsertIdempotent
|
|
33984
34077
|
});
|
|
33985
|
-
import { existsSync as
|
|
34078
|
+
import { existsSync as existsSync12, mkdirSync as mkdirSync3 } from "node:fs";
|
|
33986
34079
|
import { createRequire as createRequire4 } from "node:module";
|
|
33987
|
-
import { dirname as
|
|
34080
|
+
import { dirname as dirname5, join as join11 } from "node:path";
|
|
33988
34081
|
function assertWriteDurable(handle) {
|
|
33989
34082
|
if (handle.exodusAbort) {
|
|
33990
34083
|
throw new ExodusAbortWriteUnsafeError(handle.exodusAbort);
|
|
@@ -34001,9 +34094,9 @@ function cacheKey(scope, dbPath) {
|
|
|
34001
34094
|
}
|
|
34002
34095
|
function resolveDualScopeDbPath(scope, cwd) {
|
|
34003
34096
|
if (scope === "project") {
|
|
34004
|
-
return
|
|
34097
|
+
return join11(resolveCleoDir(cwd), "cleo.db");
|
|
34005
34098
|
}
|
|
34006
|
-
return
|
|
34099
|
+
return join11(getCleoHome(), "cleo.db");
|
|
34007
34100
|
}
|
|
34008
34101
|
function migrationsSetName(scope) {
|
|
34009
34102
|
return scope === "project" ? "drizzle-cleo-project" : "drizzle-cleo-global";
|
|
@@ -34043,8 +34136,8 @@ async function openDualScopeDb(scope, cwd) {
|
|
|
34043
34136
|
}
|
|
34044
34137
|
async function openDedicatedDualScopeDb(scope, dbPath, log7) {
|
|
34045
34138
|
log7.debug({ scope, dbPath }, "opening DEDICATED (non-cached) dual-scope cleo.db (T11782 FIX D)");
|
|
34046
|
-
const dir =
|
|
34047
|
-
if (!
|
|
34139
|
+
const dir = dirname5(dbPath);
|
|
34140
|
+
if (!existsSync12(dir)) {
|
|
34048
34141
|
mkdirSync3(dir, { recursive: true });
|
|
34049
34142
|
}
|
|
34050
34143
|
const DatabaseSyncCtor = getDatabaseSyncCtor();
|
|
@@ -34093,8 +34186,8 @@ async function openDualScopeDbAtPath(scope, dbPath, exodusCwd, options) {
|
|
|
34093
34186
|
}
|
|
34094
34187
|
const initPromise = (async () => {
|
|
34095
34188
|
log7.debug({ scope, dbPath }, "opening dual-scope cleo.db");
|
|
34096
|
-
const dir =
|
|
34097
|
-
if (!
|
|
34189
|
+
const dir = dirname5(dbPath);
|
|
34190
|
+
if (!existsSync12(dir)) {
|
|
34098
34191
|
mkdirSync3(dir, { recursive: true });
|
|
34099
34192
|
}
|
|
34100
34193
|
const DatabaseSyncCtor = getDatabaseSyncCtor();
|
|
@@ -34172,6 +34265,12 @@ async function openDualScopeDbAtPath(scope, dbPath, exodusCwd, options) {
|
|
|
34172
34265
|
nativeDb: null,
|
|
34173
34266
|
initPromise
|
|
34174
34267
|
});
|
|
34268
|
+
initPromise.catch(() => {
|
|
34269
|
+
const entry = _cache.get(key);
|
|
34270
|
+
if (entry && entry.initPromise === initPromise) {
|
|
34271
|
+
_cache.delete(key);
|
|
34272
|
+
}
|
|
34273
|
+
});
|
|
34175
34274
|
return initPromise;
|
|
34176
34275
|
}
|
|
34177
34276
|
function _resetDualScopeDbCache(scope) {
|
|
@@ -34762,8 +34861,8 @@ __export(nexus_sqlite_exports, {
|
|
|
34762
34861
|
resetNexusDbState: () => resetNexusDbState,
|
|
34763
34862
|
resolveNexusMigrationsFolder: () => resolveNexusMigrationsFolder
|
|
34764
34863
|
});
|
|
34765
|
-
import { copyFileSync as
|
|
34766
|
-
import { join as
|
|
34864
|
+
import { copyFileSync as copyFileSync4, existsSync as existsSync13 } from "node:fs";
|
|
34865
|
+
import { join as join12 } from "node:path";
|
|
34767
34866
|
function getNexusDbPath(cwd) {
|
|
34768
34867
|
return resolveDualScopeDbPath("project", cwd);
|
|
34769
34868
|
}
|
|
@@ -34795,7 +34894,7 @@ function resolveNexusMigrationsFolder() {
|
|
|
34795
34894
|
return resolveCorePackageMigrationsFolder("drizzle-nexus");
|
|
34796
34895
|
}
|
|
34797
34896
|
function getNestedNexusSentinelPath() {
|
|
34798
|
-
return
|
|
34897
|
+
return join12(getCleoHome(), "nexus", NESTED_NEXUS_SENTINEL);
|
|
34799
34898
|
}
|
|
34800
34899
|
function detectAndWarnOnNestedNexus() {
|
|
34801
34900
|
let nestedPath;
|
|
@@ -34804,7 +34903,7 @@ function detectAndWarnOnNestedNexus() {
|
|
|
34804
34903
|
} catch {
|
|
34805
34904
|
return false;
|
|
34806
34905
|
}
|
|
34807
|
-
if (!
|
|
34906
|
+
if (!existsSync13(nestedPath)) return false;
|
|
34808
34907
|
if (_warnedNestedPaths.has(nestedPath)) return false;
|
|
34809
34908
|
_warnedNestedPaths.add(nestedPath);
|
|
34810
34909
|
const canonicalPath = getNexusDbPath();
|
|
@@ -34963,9 +35062,9 @@ function runNexusMigrations(nativeDb, db) {
|
|
|
34963
35062
|
const migrationsFolder = resolveNexusMigrationsFolder();
|
|
34964
35063
|
if (tableExists4(nativeDb, "nexus_nodes") && _nexusDbPath) {
|
|
34965
35064
|
const backupPath = _nexusDbPath.replace(/\.db$/, "-pre-cleo.db.bak");
|
|
34966
|
-
if (!
|
|
35065
|
+
if (!existsSync13(backupPath)) {
|
|
34967
35066
|
try {
|
|
34968
|
-
|
|
35067
|
+
copyFileSync4(_nexusDbPath, backupPath);
|
|
34969
35068
|
} catch {
|
|
34970
35069
|
}
|
|
34971
35070
|
}
|
|
@@ -35095,10 +35194,10 @@ var init_nexus_sqlite = __esm({
|
|
|
35095
35194
|
|
|
35096
35195
|
// packages/core/src/paths.ts
|
|
35097
35196
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
35098
|
-
import { existsSync as
|
|
35197
|
+
import { existsSync as existsSync14, readFileSync as readFileSync4, statSync as statSync5 } from "node:fs";
|
|
35099
35198
|
import { createRequire as createRequire5 } from "node:module";
|
|
35100
35199
|
import { homedir } from "node:os";
|
|
35101
|
-
import { basename as basename4, dirname as
|
|
35200
|
+
import { basename as basename4, dirname as dirname6, join as join13, resolve as resolve3 } from "node:path";
|
|
35102
35201
|
import {
|
|
35103
35202
|
computeCanonicalProjectId as _computeCanonicalProjectId,
|
|
35104
35203
|
getCanonicalTemplatesTildePath as _getCanonicalTemplatesTildePath,
|
|
@@ -35188,8 +35287,8 @@ function getCleoDirAbsolute(cwd, opts) {
|
|
|
35188
35287
|
function _resolveProjectByCwdFromNexus(cwd) {
|
|
35189
35288
|
try {
|
|
35190
35289
|
const cleoHome = getCleoHome();
|
|
35191
|
-
const globalDbPath =
|
|
35192
|
-
if (!
|
|
35290
|
+
const globalDbPath = join13(cleoHome, "cleo.db");
|
|
35291
|
+
if (!existsSync14(globalDbPath)) return null;
|
|
35193
35292
|
const start = resolve3(cwd ?? process.cwd());
|
|
35194
35293
|
let current = start;
|
|
35195
35294
|
const DatabaseSync2 = _getDatabaseSyncCtor();
|
|
@@ -35203,7 +35302,7 @@ function _resolveProjectByCwdFromNexus(cwd) {
|
|
|
35203
35302
|
if (row && typeof row.project_id === "string" && row.project_id.length > 0) {
|
|
35204
35303
|
return row.project_id;
|
|
35205
35304
|
}
|
|
35206
|
-
const parent =
|
|
35305
|
+
const parent = dirname6(current);
|
|
35207
35306
|
if (parent === current) break;
|
|
35208
35307
|
current = parent;
|
|
35209
35308
|
}
|
|
@@ -35228,13 +35327,13 @@ function _findCleoDirRoot(cwd) {
|
|
|
35228
35327
|
const isDangerousRoot = current === homeRoot || current === "/" || current === "";
|
|
35229
35328
|
if (!isDangerousRoot) {
|
|
35230
35329
|
try {
|
|
35231
|
-
if (statSync5(
|
|
35330
|
+
if (statSync5(join13(current, ".cleo")).isDirectory()) {
|
|
35232
35331
|
return current;
|
|
35233
35332
|
}
|
|
35234
35333
|
} catch {
|
|
35235
35334
|
}
|
|
35236
35335
|
}
|
|
35237
|
-
const parent =
|
|
35336
|
+
const parent = dirname6(current);
|
|
35238
35337
|
if (parent === current) break;
|
|
35239
35338
|
current = parent;
|
|
35240
35339
|
}
|
|
@@ -35243,7 +35342,7 @@ function _findCleoDirRoot(cwd) {
|
|
|
35243
35342
|
function resolveCleoDir(cwd) {
|
|
35244
35343
|
const scope = worktreeScope.getStore();
|
|
35245
35344
|
if (scope !== void 0) {
|
|
35246
|
-
return
|
|
35345
|
+
return join13(scope.worktreeRoot, ".cleo");
|
|
35247
35346
|
}
|
|
35248
35347
|
const override = _cleoDirEnvOverride();
|
|
35249
35348
|
if (override !== null) {
|
|
@@ -35251,16 +35350,16 @@ function resolveCleoDir(cwd) {
|
|
|
35251
35350
|
}
|
|
35252
35351
|
const root = _findCleoDirRoot(cwd);
|
|
35253
35352
|
if (root !== null) {
|
|
35254
|
-
return
|
|
35353
|
+
return join13(root, ".cleo");
|
|
35255
35354
|
}
|
|
35256
35355
|
const start = resolve3(cwd ?? process.cwd());
|
|
35257
35356
|
let current = start;
|
|
35258
35357
|
while (true) {
|
|
35259
35358
|
const mainRepo = _resolveMainRepoFromGitlink(current);
|
|
35260
35359
|
if (mainRepo !== null) {
|
|
35261
|
-
return
|
|
35360
|
+
return join13(mainRepo, ".cleo");
|
|
35262
35361
|
}
|
|
35263
|
-
const parent =
|
|
35362
|
+
const parent = dirname6(current);
|
|
35264
35363
|
if (parent === current) {
|
|
35265
35364
|
break;
|
|
35266
35365
|
}
|
|
@@ -35300,30 +35399,30 @@ function _cwdHasGitAncestor(cwd) {
|
|
|
35300
35399
|
const start = resolve3(cwd ?? process.cwd());
|
|
35301
35400
|
let current = start;
|
|
35302
35401
|
while (true) {
|
|
35303
|
-
const gitMarker =
|
|
35402
|
+
const gitMarker = join13(current, ".git");
|
|
35304
35403
|
try {
|
|
35305
|
-
if (
|
|
35404
|
+
if (existsSync14(gitMarker)) {
|
|
35306
35405
|
return true;
|
|
35307
35406
|
}
|
|
35308
35407
|
} catch {
|
|
35309
35408
|
}
|
|
35310
|
-
const parent =
|
|
35409
|
+
const parent = dirname6(current);
|
|
35311
35410
|
if (parent === current) return false;
|
|
35312
35411
|
current = parent;
|
|
35313
35412
|
}
|
|
35314
35413
|
}
|
|
35315
35414
|
function _resolveMainRepoFromGitlink(gitlinkDir) {
|
|
35316
35415
|
try {
|
|
35317
|
-
const gitLinkPath =
|
|
35318
|
-
if (!
|
|
35416
|
+
const gitLinkPath = join13(gitlinkDir, ".git");
|
|
35417
|
+
if (!existsSync14(gitLinkPath)) return null;
|
|
35319
35418
|
const stat2 = statSync5(gitLinkPath);
|
|
35320
35419
|
if (!stat2.isFile()) return null;
|
|
35321
35420
|
const gitLinkContent = readFileSync4(gitLinkPath, "utf-8").trim();
|
|
35322
35421
|
const match = gitLinkContent.match(/^gitdir:\s*(.+)$/m);
|
|
35323
35422
|
if (!match) return null;
|
|
35324
35423
|
const gitdir = match[1].trim();
|
|
35325
|
-
const mainRepo =
|
|
35326
|
-
if (
|
|
35424
|
+
const mainRepo = dirname6(dirname6(dirname6(gitdir)));
|
|
35425
|
+
if (existsSync14(join13(mainRepo, ".cleo")) && validateProjectRoot(mainRepo)) {
|
|
35327
35426
|
return mainRepo;
|
|
35328
35427
|
}
|
|
35329
35428
|
} catch {
|
|
@@ -35331,18 +35430,18 @@ function _resolveMainRepoFromGitlink(gitlinkDir) {
|
|
|
35331
35430
|
return null;
|
|
35332
35431
|
}
|
|
35333
35432
|
function validateProjectRoot(candidate) {
|
|
35334
|
-
const cleoDir =
|
|
35335
|
-
if (!
|
|
35433
|
+
const cleoDir = join13(candidate, ".cleo");
|
|
35434
|
+
if (!existsSync14(cleoDir)) {
|
|
35336
35435
|
return false;
|
|
35337
35436
|
}
|
|
35338
|
-
const projectInfoPath =
|
|
35339
|
-
if (
|
|
35437
|
+
const projectInfoPath = join13(cleoDir, "project-info.json");
|
|
35438
|
+
if (existsSync14(projectInfoPath)) {
|
|
35340
35439
|
try {
|
|
35341
35440
|
const raw = readFileSync4(projectInfoPath, "utf-8");
|
|
35342
35441
|
const parsed = JSON.parse(raw);
|
|
35343
35442
|
if (typeof parsed === "object" && parsed !== null && "projectId" in parsed && typeof parsed["projectId"] === "string" && parsed["projectId"] !== "") {
|
|
35344
|
-
const gitMarker =
|
|
35345
|
-
if (
|
|
35443
|
+
const gitMarker = join13(candidate, ".git");
|
|
35444
|
+
if (existsSync14(gitMarker)) {
|
|
35346
35445
|
try {
|
|
35347
35446
|
if (!statSync5(gitMarker).isDirectory()) {
|
|
35348
35447
|
return false;
|
|
@@ -35356,8 +35455,8 @@ function validateProjectRoot(candidate) {
|
|
|
35356
35455
|
} catch {
|
|
35357
35456
|
}
|
|
35358
35457
|
}
|
|
35359
|
-
const gitDir =
|
|
35360
|
-
if (
|
|
35458
|
+
const gitDir = join13(candidate, ".git");
|
|
35459
|
+
if (existsSync14(gitDir)) {
|
|
35361
35460
|
let isRealGitDir = false;
|
|
35362
35461
|
try {
|
|
35363
35462
|
const stat2 = statSync5(gitDir);
|
|
@@ -35393,7 +35492,7 @@ function getProjectRoot(cwd) {
|
|
|
35393
35492
|
const cleoDirEnv = process.env["CLEO_DIR"];
|
|
35394
35493
|
if (cleoDirEnv && isAbsolutePath(cleoDirEnv)) {
|
|
35395
35494
|
if (cleoDirEnv.endsWith("/.cleo") || cleoDirEnv.endsWith("\\.cleo")) {
|
|
35396
|
-
return
|
|
35495
|
+
return dirname6(cleoDirEnv);
|
|
35397
35496
|
}
|
|
35398
35497
|
return cleoDirEnv;
|
|
35399
35498
|
}
|
|
@@ -35404,16 +35503,16 @@ function getProjectRoot(cwd) {
|
|
|
35404
35503
|
const homeRoot = homedir();
|
|
35405
35504
|
const skippedCleoDirs = [];
|
|
35406
35505
|
while (true) {
|
|
35407
|
-
const cleoDir =
|
|
35408
|
-
const gitDir =
|
|
35506
|
+
const cleoDir = join13(current, ".cleo");
|
|
35507
|
+
const gitDir = join13(current, ".git");
|
|
35409
35508
|
const isDangerousRoot = current === homeRoot || current === "/" || current === "";
|
|
35410
|
-
if (
|
|
35509
|
+
if (existsSync14(cleoDir) && !isDangerousRoot) {
|
|
35411
35510
|
if (validateProjectRoot(current)) {
|
|
35412
35511
|
return current;
|
|
35413
35512
|
}
|
|
35414
35513
|
skippedCleoDirs.push(current);
|
|
35415
35514
|
}
|
|
35416
|
-
if (
|
|
35515
|
+
if (existsSync14(gitDir) && !isDangerousRoot) {
|
|
35417
35516
|
let isRealGitDir = false;
|
|
35418
35517
|
try {
|
|
35419
35518
|
isRealGitDir = statSync5(gitDir).isDirectory();
|
|
@@ -35428,7 +35527,7 @@ function getProjectRoot(cwd) {
|
|
|
35428
35527
|
const mainRepoFromWalk = _resolveMainRepoFromGitlink(current);
|
|
35429
35528
|
if (mainRepoFromWalk !== null) return mainRepoFromWalk;
|
|
35430
35529
|
}
|
|
35431
|
-
const parent =
|
|
35530
|
+
const parent = dirname6(current);
|
|
35432
35531
|
if (parent === current) {
|
|
35433
35532
|
break;
|
|
35434
35533
|
}
|
|
@@ -35458,18 +35557,18 @@ function resolveOrCwd(maybeRoot) {
|
|
|
35458
35557
|
return getProjectRoot();
|
|
35459
35558
|
}
|
|
35460
35559
|
function getConfigPath(cwd) {
|
|
35461
|
-
return
|
|
35560
|
+
return join13(_resolveCleoDir(cwd), "config.json");
|
|
35462
35561
|
}
|
|
35463
35562
|
function getGlobalConfigPath() {
|
|
35464
|
-
return
|
|
35563
|
+
return join13(getCleoHome(), "config.json");
|
|
35465
35564
|
}
|
|
35466
35565
|
function isAbsolutePath(path) {
|
|
35467
35566
|
return _isAbsolutePath(path);
|
|
35468
35567
|
}
|
|
35469
35568
|
function _readProjectNameFromInfo(projectRoot) {
|
|
35470
35569
|
try {
|
|
35471
|
-
const infoPath =
|
|
35472
|
-
if (!
|
|
35570
|
+
const infoPath = join13(projectRoot, ".cleo", "project-info.json");
|
|
35571
|
+
if (!existsSync14(infoPath)) return void 0;
|
|
35473
35572
|
const raw = readFileSync4(infoPath, "utf-8");
|
|
35474
35573
|
const data = JSON.parse(raw);
|
|
35475
35574
|
return typeof data.name === "string" && data.name.length > 0 ? data.name : void 0;
|
|
@@ -35495,8 +35594,8 @@ async function registerProjectOnEncounter(projectRoot, infoProjectId) {
|
|
|
35495
35594
|
if (existingRows.length > 0) {
|
|
35496
35595
|
const existingPath = existingRows[0].projectPath;
|
|
35497
35596
|
if (existingPath !== resolvedPath) {
|
|
35498
|
-
const newBrainDbPath =
|
|
35499
|
-
const newTasksDbPath =
|
|
35597
|
+
const newBrainDbPath = join13(resolvedPath, ".cleo", "brain.db");
|
|
35598
|
+
const newTasksDbPath = join13(resolvedPath, ".cleo", "tasks.db");
|
|
35500
35599
|
await db.update(projectRegistry2).set({
|
|
35501
35600
|
projectPath: resolvedPath,
|
|
35502
35601
|
projectHash: generateProjectHash2(resolvedPath),
|
|
@@ -35527,8 +35626,8 @@ async function registerProjectOnEncounter(projectRoot, infoProjectId) {
|
|
|
35527
35626
|
lastSync: now,
|
|
35528
35627
|
taskCount: 0,
|
|
35529
35628
|
labelsJson: "[]",
|
|
35530
|
-
brainDbPath:
|
|
35531
|
-
tasksDbPath:
|
|
35629
|
+
brainDbPath: join13(resolvedPath, ".cleo", "brain.db"),
|
|
35630
|
+
tasksDbPath: join13(resolvedPath, ".cleo", "tasks.db"),
|
|
35532
35631
|
statsJson: "{}"
|
|
35533
35632
|
}).onConflictDoNothing();
|
|
35534
35633
|
const aliases = canonicalResult.legacyAliases ?? [];
|
|
@@ -35561,7 +35660,7 @@ var init_paths = __esm({
|
|
|
35561
35660
|
// packages/core/src/store/file-utils.ts
|
|
35562
35661
|
import { randomBytes } from "node:crypto";
|
|
35563
35662
|
import {
|
|
35564
|
-
existsSync as
|
|
35663
|
+
existsSync as existsSync15,
|
|
35565
35664
|
mkdirSync as mkdirSync4,
|
|
35566
35665
|
readdirSync as readdirSync4,
|
|
35567
35666
|
readFileSync as readFileSync5,
|
|
@@ -35569,34 +35668,34 @@ import {
|
|
|
35569
35668
|
unlinkSync as unlinkSync3,
|
|
35570
35669
|
writeFileSync as writeFileSync3
|
|
35571
35670
|
} from "node:fs";
|
|
35572
|
-
import { basename as basename5, dirname as
|
|
35671
|
+
import { basename as basename5, dirname as dirname7, join as join14 } from "node:path";
|
|
35573
35672
|
import * as lockfile2 from "proper-lockfile";
|
|
35574
35673
|
function rotateBackup(filePath, mode) {
|
|
35575
|
-
const dir =
|
|
35674
|
+
const dir = dirname7(filePath);
|
|
35576
35675
|
const name15 = basename5(filePath);
|
|
35577
|
-
const backupDir =
|
|
35676
|
+
const backupDir = join14(dir, ".backups");
|
|
35578
35677
|
const dirMode = typeof mode === "number" ? modeToDirMode(mode) : void 0;
|
|
35579
|
-
if (!
|
|
35678
|
+
if (!existsSync15(backupDir)) {
|
|
35580
35679
|
mkdirSync4(backupDir, { recursive: true, mode: dirMode });
|
|
35581
35680
|
}
|
|
35582
35681
|
for (let i = MAX_BACKUPS; i >= 1; i--) {
|
|
35583
|
-
const current =
|
|
35682
|
+
const current = join14(backupDir, `${name15}.${i}`);
|
|
35584
35683
|
if (i === MAX_BACKUPS) {
|
|
35585
35684
|
try {
|
|
35586
35685
|
unlinkSync3(current);
|
|
35587
35686
|
} catch {
|
|
35588
35687
|
}
|
|
35589
35688
|
} else {
|
|
35590
|
-
const next =
|
|
35689
|
+
const next = join14(backupDir, `${name15}.${i + 1}`);
|
|
35591
35690
|
try {
|
|
35592
|
-
if (
|
|
35691
|
+
if (existsSync15(current)) renameSync3(current, next);
|
|
35593
35692
|
} catch {
|
|
35594
35693
|
}
|
|
35595
35694
|
}
|
|
35596
35695
|
}
|
|
35597
35696
|
try {
|
|
35598
35697
|
const content = readFileSync5(filePath, "utf-8");
|
|
35599
|
-
const backupPath =
|
|
35698
|
+
const backupPath = join14(backupDir, `${name15}.1`);
|
|
35600
35699
|
if (typeof mode === "number") {
|
|
35601
35700
|
writeFileSync3(backupPath, content, { encoding: "utf-8", mode });
|
|
35602
35701
|
} else {
|
|
@@ -35616,8 +35715,8 @@ function writeJsonFileAtomic(filePath, data, optsOrIndent = 2) {
|
|
|
35616
35715
|
const opts = typeof optsOrIndent === "number" ? { indent: optsOrIndent } : optsOrIndent;
|
|
35617
35716
|
const indent = opts.indent ?? 2;
|
|
35618
35717
|
const mode = opts.mode;
|
|
35619
|
-
const dir =
|
|
35620
|
-
const tempPath =
|
|
35718
|
+
const dir = dirname7(filePath);
|
|
35719
|
+
const tempPath = join14(dir, `.${basename5(filePath)}.${randomBytes(6).toString("hex")}.tmp`);
|
|
35621
35720
|
const content = JSON.stringify(data, null, indent) + "\n";
|
|
35622
35721
|
if (typeof mode === "number") {
|
|
35623
35722
|
writeFileSync3(tempPath, content, { encoding: "utf-8", mode });
|
|
@@ -35625,7 +35724,7 @@ function writeJsonFileAtomic(filePath, data, optsOrIndent = 2) {
|
|
|
35625
35724
|
writeFileSync3(tempPath, content, "utf-8");
|
|
35626
35725
|
}
|
|
35627
35726
|
try {
|
|
35628
|
-
if (
|
|
35727
|
+
if (existsSync15(filePath)) {
|
|
35629
35728
|
rotateBackup(filePath, mode);
|
|
35630
35729
|
}
|
|
35631
35730
|
renameSync3(tempPath, filePath);
|
|
@@ -35649,12 +35748,12 @@ function readJsonFile(filePath) {
|
|
|
35649
35748
|
}
|
|
35650
35749
|
}
|
|
35651
35750
|
async function withLock2(filePath, transform2, opts = {}) {
|
|
35652
|
-
const dir =
|
|
35751
|
+
const dir = dirname7(filePath);
|
|
35653
35752
|
const dirMode = typeof opts.mode === "number" ? modeToDirMode(opts.mode) : void 0;
|
|
35654
|
-
if (!
|
|
35753
|
+
if (!existsSync15(dir)) {
|
|
35655
35754
|
mkdirSync4(dir, { recursive: true, mode: dirMode });
|
|
35656
35755
|
}
|
|
35657
|
-
if (!
|
|
35756
|
+
if (!existsSync15(filePath)) {
|
|
35658
35757
|
if (typeof opts.mode === "number") {
|
|
35659
35758
|
writeFileSync3(filePath, "", { encoding: "utf-8", mode: opts.mode });
|
|
35660
35759
|
} else {
|
|
@@ -35675,11 +35774,11 @@ async function withLock2(filePath, transform2, opts = {}) {
|
|
|
35675
35774
|
}
|
|
35676
35775
|
}
|
|
35677
35776
|
async function withFileLock(filePath, operation) {
|
|
35678
|
-
const dir =
|
|
35679
|
-
if (!
|
|
35777
|
+
const dir = dirname7(filePath);
|
|
35778
|
+
if (!existsSync15(dir)) {
|
|
35680
35779
|
mkdirSync4(dir, { recursive: true });
|
|
35681
35780
|
}
|
|
35682
|
-
if (!
|
|
35781
|
+
if (!existsSync15(filePath)) {
|
|
35683
35782
|
writeFileSync3(filePath, "", "utf-8");
|
|
35684
35783
|
}
|
|
35685
35784
|
let release;
|
|
@@ -35713,10 +35812,10 @@ var init_file_utils = __esm({
|
|
|
35713
35812
|
|
|
35714
35813
|
// packages/core/src/llm/credential-removal.ts
|
|
35715
35814
|
import { unlinkSync as unlinkSync4 } from "node:fs";
|
|
35716
|
-
import { join as
|
|
35815
|
+
import { join as join15 } from "node:path";
|
|
35717
35816
|
import { getCleoHome as getCleoHome2 } from "@cleocode/paths";
|
|
35718
35817
|
function suppressionStatePath() {
|
|
35719
|
-
return
|
|
35818
|
+
return join15(getCleoHome2(), SUPPRESSION_FILENAME);
|
|
35720
35819
|
}
|
|
35721
35820
|
function readSuppressionFile() {
|
|
35722
35821
|
const data = readJsonFile(suppressionStatePath());
|
|
@@ -35820,7 +35919,7 @@ var init_credential_removal = __esm({
|
|
|
35820
35919
|
sourceId: "cleo-pkce",
|
|
35821
35920
|
description: "Delete CLEO-issued PKCE token at <CLEO_HOME>/anthropic-oauth.json",
|
|
35822
35921
|
async remove() {
|
|
35823
|
-
const path =
|
|
35922
|
+
const path = join15(getCleoHome2(), "anthropic-oauth.json");
|
|
35824
35923
|
const cleaned = [];
|
|
35825
35924
|
try {
|
|
35826
35925
|
unlinkSync4(path);
|
|
@@ -35899,9 +35998,9 @@ __export(config_exports, {
|
|
|
35899
35998
|
parseConfigValue: () => parseConfigValue,
|
|
35900
35999
|
setConfigValue: () => setConfigValue
|
|
35901
36000
|
});
|
|
35902
|
-
import { existsSync as
|
|
36001
|
+
import { existsSync as existsSync16 } from "node:fs";
|
|
35903
36002
|
import { mkdir as mkdir3, writeFile } from "node:fs/promises";
|
|
35904
|
-
import { dirname as
|
|
36003
|
+
import { dirname as dirname8 } from "node:path";
|
|
35905
36004
|
function getNestedValue(obj, path) {
|
|
35906
36005
|
const parts = path.split(".");
|
|
35907
36006
|
let current = obj;
|
|
@@ -36023,8 +36122,8 @@ function parseConfigValue(value) {
|
|
|
36023
36122
|
}
|
|
36024
36123
|
async function setConfigValue(key, value, cwd, opts) {
|
|
36025
36124
|
const configPath = opts?.global ? getGlobalConfigPath() : getConfigPath(cwd);
|
|
36026
|
-
if (!
|
|
36027
|
-
const dir =
|
|
36125
|
+
if (!existsSync16(configPath)) {
|
|
36126
|
+
const dir = dirname8(configPath);
|
|
36028
36127
|
await mkdir3(dir, { recursive: true });
|
|
36029
36128
|
await writeFile(configPath, "{}", "utf-8");
|
|
36030
36129
|
}
|
|
@@ -36037,8 +36136,8 @@ async function setConfigValue(key, value, cwd, opts) {
|
|
|
36037
36136
|
async function applyStrictnessPreset(preset, cwd, opts) {
|
|
36038
36137
|
const definition = STRICTNESS_PRESETS[preset];
|
|
36039
36138
|
const configPath = opts?.global ? getGlobalConfigPath() : getConfigPath(cwd);
|
|
36040
|
-
if (!
|
|
36041
|
-
const dir =
|
|
36139
|
+
if (!existsSync16(configPath)) {
|
|
36140
|
+
const dir = dirname8(configPath);
|
|
36042
36141
|
await mkdir3(dir, { recursive: true });
|
|
36043
36142
|
await writeFile(configPath, "{}", "utf-8");
|
|
36044
36143
|
}
|
|
@@ -36239,10 +36338,10 @@ var init_config = __esm({
|
|
|
36239
36338
|
// packages/core/src/llm/credential-seeders/claude-code-seeder.ts
|
|
36240
36339
|
import { readFileSync as readFileSync6 } from "node:fs";
|
|
36241
36340
|
import { homedir as homedir2 } from "node:os";
|
|
36242
|
-
import { join as
|
|
36341
|
+
import { join as join16 } from "node:path";
|
|
36243
36342
|
function defaultReadCredentialFile() {
|
|
36244
36343
|
try {
|
|
36245
|
-
return readFileSync6(
|
|
36344
|
+
return readFileSync6(join16(homedir2(), ".claude", ".credentials.json"), "utf-8");
|
|
36246
36345
|
} catch {
|
|
36247
36346
|
return null;
|
|
36248
36347
|
}
|
|
@@ -36337,9 +36436,9 @@ var init_claude_code_seeder = __esm({
|
|
|
36337
36436
|
|
|
36338
36437
|
// packages/core/src/llm/credential-seeders/cleo-pkce-seeder.ts
|
|
36339
36438
|
import { readFileSync as readFileSync7 } from "node:fs";
|
|
36340
|
-
import { join as
|
|
36439
|
+
import { join as join17 } from "node:path";
|
|
36341
36440
|
function defaultCleoPkcePath() {
|
|
36342
|
-
return
|
|
36441
|
+
return join17(getCleoHome(), "anthropic-oauth.json");
|
|
36343
36442
|
}
|
|
36344
36443
|
function defaultReadCredentialFile2() {
|
|
36345
36444
|
try {
|
|
@@ -36410,13 +36509,13 @@ var init_cleo_pkce_seeder = __esm({
|
|
|
36410
36509
|
});
|
|
36411
36510
|
|
|
36412
36511
|
// packages/core/src/llm/credential-seeders/codex-cli-seeder.ts
|
|
36413
|
-
import { existsSync as
|
|
36512
|
+
import { existsSync as existsSync17, readFileSync as readFileSync8 } from "node:fs";
|
|
36414
36513
|
import { homedir as homedir3 } from "node:os";
|
|
36415
|
-
import { join as
|
|
36514
|
+
import { join as join18 } from "node:path";
|
|
36416
36515
|
function getCodexAuthPath() {
|
|
36417
36516
|
const codexHome = (process.env["CODEX_HOME"] ?? "").trim();
|
|
36418
|
-
const root = codexHome ||
|
|
36419
|
-
return
|
|
36517
|
+
const root = codexHome || join18(homedir3(), ".codex");
|
|
36518
|
+
return join18(root, "auth.json");
|
|
36420
36519
|
}
|
|
36421
36520
|
var CodexCliSeeder, codexCliSeeder;
|
|
36422
36521
|
var init_codex_cli_seeder = __esm({
|
|
@@ -36435,7 +36534,7 @@ var init_codex_cli_seeder = __esm({
|
|
|
36435
36534
|
*/
|
|
36436
36535
|
async seed() {
|
|
36437
36536
|
const authPath = getCodexAuthPath();
|
|
36438
|
-
if (!
|
|
36537
|
+
if (!existsSync17(authPath)) {
|
|
36439
36538
|
return { entries: [] };
|
|
36440
36539
|
}
|
|
36441
36540
|
let raw;
|
|
@@ -36565,11 +36664,11 @@ var init_google_pkce = __esm({
|
|
|
36565
36664
|
});
|
|
36566
36665
|
|
|
36567
36666
|
// packages/core/src/llm/credential-seeders/gemini-cli-seeder.ts
|
|
36568
|
-
import { existsSync as
|
|
36569
|
-
import { join as
|
|
36667
|
+
import { existsSync as existsSync18, readFileSync as readFileSync9 } from "node:fs";
|
|
36668
|
+
import { join as join19 } from "node:path";
|
|
36570
36669
|
import { getCleoHome as getCleoHome3 } from "@cleocode/paths";
|
|
36571
36670
|
function getGoogleOauthPath() {
|
|
36572
|
-
return
|
|
36671
|
+
return join19(getCleoHome3(), "google_oauth.json");
|
|
36573
36672
|
}
|
|
36574
36673
|
function parseGoogleOauthFile(raw) {
|
|
36575
36674
|
let json3;
|
|
@@ -36614,7 +36713,7 @@ var init_gemini_cli_seeder = __esm({
|
|
|
36614
36713
|
*/
|
|
36615
36714
|
async seed() {
|
|
36616
36715
|
const path = getGoogleOauthPath();
|
|
36617
|
-
if (!
|
|
36716
|
+
if (!existsSync18(path)) {
|
|
36618
36717
|
return { entries: [] };
|
|
36619
36718
|
}
|
|
36620
36719
|
let raw;
|
|
@@ -36839,23 +36938,23 @@ var init_credential_seeders = __esm({
|
|
|
36839
36938
|
|
|
36840
36939
|
// packages/core/src/llm/global-config-migration.ts
|
|
36841
36940
|
import {
|
|
36842
|
-
existsSync as
|
|
36941
|
+
existsSync as existsSync19,
|
|
36843
36942
|
mkdirSync as mkdirSync5,
|
|
36844
36943
|
readFileSync as readFileSync10,
|
|
36845
36944
|
renameSync as renameSync4,
|
|
36846
36945
|
unlinkSync as unlinkSync5,
|
|
36847
36946
|
writeFileSync as writeFileSync4
|
|
36848
36947
|
} from "node:fs";
|
|
36849
|
-
import { join as
|
|
36948
|
+
import { join as join20 } from "node:path";
|
|
36850
36949
|
import { getCleoHome as getCleoHome4, getCleoPlatformPaths as getCleoPlatformPaths2 } from "@cleocode/paths";
|
|
36851
36950
|
function configDirGlobalConfigPath() {
|
|
36852
|
-
return
|
|
36951
|
+
return join20(getCleoPlatformPaths2().config, GLOBAL_CONFIG_FILENAME);
|
|
36853
36952
|
}
|
|
36854
36953
|
function legacyGlobalConfigPath() {
|
|
36855
|
-
return
|
|
36954
|
+
return join20(getCleoHome4(), GLOBAL_CONFIG_FILENAME);
|
|
36856
36955
|
}
|
|
36857
36956
|
function migrationMarkerPath() {
|
|
36858
|
-
return
|
|
36957
|
+
return join20(getCleoHome4(), MIGRATIONS_SUBDIR, MIGRATION_MARKER);
|
|
36859
36958
|
}
|
|
36860
36959
|
function tempTargetPath() {
|
|
36861
36960
|
return `${configDirGlobalConfigPath()}.tmp`;
|
|
@@ -36865,12 +36964,12 @@ function migrateGlobalConfigToConfigDir() {
|
|
|
36865
36964
|
const source = legacyGlobalConfigPath();
|
|
36866
36965
|
const target = configDirGlobalConfigPath();
|
|
36867
36966
|
const marker16 = migrationMarkerPath();
|
|
36868
|
-
if (
|
|
36869
|
-
if (!
|
|
36967
|
+
if (existsSync19(marker16)) return false;
|
|
36968
|
+
if (!existsSync19(source)) {
|
|
36870
36969
|
stampMarker(marker16);
|
|
36871
36970
|
return false;
|
|
36872
36971
|
}
|
|
36873
|
-
if (
|
|
36972
|
+
if (existsSync19(target)) {
|
|
36874
36973
|
backupSourceQuiet(source);
|
|
36875
36974
|
stampMarker(marker16);
|
|
36876
36975
|
return false;
|
|
@@ -36903,7 +37002,7 @@ function migrateGlobalConfigToConfigDir() {
|
|
|
36903
37002
|
} catch (err) {
|
|
36904
37003
|
try {
|
|
36905
37004
|
const temp = tempTargetPath();
|
|
36906
|
-
if (
|
|
37005
|
+
if (existsSync19(temp)) unlinkSync5(temp);
|
|
36907
37006
|
} catch {
|
|
36908
37007
|
}
|
|
36909
37008
|
console.error(
|
|
@@ -36914,7 +37013,7 @@ function migrateGlobalConfigToConfigDir() {
|
|
|
36914
37013
|
}
|
|
36915
37014
|
function stampMarker(markerPath) {
|
|
36916
37015
|
try {
|
|
36917
|
-
mkdirSync5(
|
|
37016
|
+
mkdirSync5(join20(getCleoHome4(), MIGRATIONS_SUBDIR), { recursive: true });
|
|
36918
37017
|
writeFileSync4(markerPath, `${(/* @__PURE__ */ new Date()).toISOString()}
|
|
36919
37018
|
`, { mode: 420 });
|
|
36920
37019
|
} catch {
|
|
@@ -36923,7 +37022,7 @@ function stampMarker(markerPath) {
|
|
|
36923
37022
|
function backupSourceQuiet(source) {
|
|
36924
37023
|
try {
|
|
36925
37024
|
const backup = `${source}${BACKUP_SUFFIX}`;
|
|
36926
|
-
if (
|
|
37025
|
+
if (existsSync19(backup)) return;
|
|
36927
37026
|
renameSync4(source, backup);
|
|
36928
37027
|
} catch {
|
|
36929
37028
|
}
|
|
@@ -36946,15 +37045,15 @@ var init_global_config_migration = __esm({
|
|
|
36946
37045
|
});
|
|
36947
37046
|
|
|
36948
37047
|
// packages/core/src/llm/legacy-flat-key-import.ts
|
|
36949
|
-
import { existsSync as
|
|
36950
|
-
import { join as
|
|
37048
|
+
import { existsSync as existsSync20, readFileSync as readFileSync11, renameSync as renameSync5, writeFileSync as writeFileSync5 } from "node:fs";
|
|
37049
|
+
import { join as join21 } from "node:path";
|
|
36951
37050
|
import { getCleoHome as getCleoHome5 } from "@cleocode/paths";
|
|
36952
37051
|
function migrationPaths() {
|
|
36953
37052
|
const home = getCleoHome5();
|
|
36954
37053
|
return {
|
|
36955
|
-
flatPath:
|
|
36956
|
-
bakPath:
|
|
36957
|
-
markerPath:
|
|
37054
|
+
flatPath: join21(home, "anthropic-key"),
|
|
37055
|
+
bakPath: join21(home, `anthropic-key${LEGACY_FLAT_KEY_BAK_SUFFIX}`),
|
|
37056
|
+
markerPath: join21(home, LEGACY_FLAT_KEY_MARKER)
|
|
36958
37057
|
};
|
|
36959
37058
|
}
|
|
36960
37059
|
function writeMarker(markerPath) {
|
|
@@ -36975,7 +37074,7 @@ function writeMarker(markerPath) {
|
|
|
36975
37074
|
}
|
|
36976
37075
|
function readFlatKey(flatPath) {
|
|
36977
37076
|
try {
|
|
36978
|
-
if (!
|
|
37077
|
+
if (!existsSync20(flatPath)) return null;
|
|
36979
37078
|
const raw = readFileSync11(flatPath, "utf-8").trim();
|
|
36980
37079
|
return raw || null;
|
|
36981
37080
|
} catch (err) {
|
|
@@ -36988,7 +37087,7 @@ function readFlatKey(flatPath) {
|
|
|
36988
37087
|
}
|
|
36989
37088
|
async function importLegacyFlatAnthropicKey() {
|
|
36990
37089
|
const { flatPath, bakPath, markerPath } = migrationPaths();
|
|
36991
|
-
if (
|
|
37090
|
+
if (existsSync20(markerPath)) {
|
|
36992
37091
|
return { status: "marker-present", flatPath, bakPath: null, markerPath };
|
|
36993
37092
|
}
|
|
36994
37093
|
let existing = null;
|
|
@@ -37005,7 +37104,7 @@ async function importLegacyFlatAnthropicKey() {
|
|
|
37005
37104
|
writeMarker(markerPath);
|
|
37006
37105
|
return { status: "already-imported", flatPath, bakPath: null, markerPath };
|
|
37007
37106
|
}
|
|
37008
|
-
if (!
|
|
37107
|
+
if (!existsSync20(flatPath)) {
|
|
37009
37108
|
writeMarker(markerPath);
|
|
37010
37109
|
return { status: "no-flat-file", flatPath, bakPath: null, markerPath };
|
|
37011
37110
|
}
|
|
@@ -37081,15 +37180,15 @@ __export(credentials_exports, {
|
|
|
37081
37180
|
resolveProviderStatus: () => resolveProviderStatus,
|
|
37082
37181
|
storeAnthropicApiKey: () => storeAnthropicApiKey
|
|
37083
37182
|
});
|
|
37084
|
-
import { existsSync as
|
|
37085
|
-
import { join as
|
|
37183
|
+
import { existsSync as existsSync21, mkdirSync as mkdirSync6, readFileSync as readFileSync12, writeFileSync as writeFileSync6 } from "node:fs";
|
|
37184
|
+
import { join as join22 } from "node:path";
|
|
37086
37185
|
import { getCleoHome as getCleoHome6 } from "@cleocode/paths";
|
|
37087
37186
|
function globalConfigPath() {
|
|
37088
37187
|
return configDirGlobalConfigPath();
|
|
37089
37188
|
}
|
|
37090
37189
|
function projectConfigPath(projectRoot) {
|
|
37091
37190
|
const cleoDir = process.env["CLEO_DIR"] ?? ".cleo";
|
|
37092
|
-
return
|
|
37191
|
+
return join22(projectRoot, cleoDir, "config.json");
|
|
37093
37192
|
}
|
|
37094
37193
|
function readGlobalProviderKey(provider) {
|
|
37095
37194
|
ensureGlobalConfigMigrated();
|
|
@@ -37099,8 +37198,8 @@ function readGlobalProviderKey(provider) {
|
|
|
37099
37198
|
}
|
|
37100
37199
|
function readFlatAnthropicKey() {
|
|
37101
37200
|
try {
|
|
37102
|
-
const keyFile =
|
|
37103
|
-
if (!
|
|
37201
|
+
const keyFile = join22(getCleoHome6(), "anthropic-key");
|
|
37202
|
+
if (!existsSync21(keyFile)) return null;
|
|
37104
37203
|
const stored = readFileSync12(keyFile, "utf-8").trim();
|
|
37105
37204
|
return stored || null;
|
|
37106
37205
|
} catch {
|
|
@@ -37109,7 +37208,7 @@ function readFlatAnthropicKey() {
|
|
|
37109
37208
|
}
|
|
37110
37209
|
function readProviderKeyFromConfig(configFile, provider) {
|
|
37111
37210
|
try {
|
|
37112
|
-
if (!
|
|
37211
|
+
if (!existsSync21(configFile)) return null;
|
|
37113
37212
|
const raw = readFileSync12(configFile, "utf-8");
|
|
37114
37213
|
const config2 = JSON.parse(raw);
|
|
37115
37214
|
const llm = config2["llm"];
|
|
@@ -37272,10 +37371,10 @@ function resolveProviderStatus(provider) {
|
|
|
37272
37371
|
}
|
|
37273
37372
|
function storeAnthropicApiKey(apiKey) {
|
|
37274
37373
|
const dir = getCleoHome6();
|
|
37275
|
-
if (!
|
|
37374
|
+
if (!existsSync21(dir)) {
|
|
37276
37375
|
mkdirSync6(dir, { recursive: true });
|
|
37277
37376
|
}
|
|
37278
|
-
const keyFile =
|
|
37377
|
+
const keyFile = join22(dir, "anthropic-key");
|
|
37279
37378
|
writeFileSync6(keyFile, apiKey.trim(), { mode: 384 });
|
|
37280
37379
|
}
|
|
37281
37380
|
function clearAnthropicKeyCache() {
|
|
@@ -37327,16 +37426,16 @@ var init_credentials2 = __esm({
|
|
|
37327
37426
|
});
|
|
37328
37427
|
|
|
37329
37428
|
// packages/core/src/llm/credentials-store.ts
|
|
37330
|
-
import { chmodSync, existsSync as
|
|
37331
|
-
import { dirname as
|
|
37429
|
+
import { chmodSync, existsSync as existsSync22, mkdirSync as mkdirSync7, readFileSync as readFileSync13, statSync as statSync6, writeFileSync as writeFileSync7 } from "node:fs";
|
|
37430
|
+
import { dirname as dirname9, join as join23 } from "node:path";
|
|
37332
37431
|
import { getCleoHome as getCleoHome7 } from "@cleocode/paths";
|
|
37333
37432
|
function credentialsStorePath() {
|
|
37334
|
-
return
|
|
37433
|
+
return join23(getCleoHome7(), "llm-credentials.json");
|
|
37335
37434
|
}
|
|
37336
37435
|
function ensureFileInitialized(path) {
|
|
37337
|
-
if (
|
|
37338
|
-
const dir =
|
|
37339
|
-
if (!
|
|
37436
|
+
if (existsSync22(path)) return;
|
|
37437
|
+
const dir = dirname9(path);
|
|
37438
|
+
if (!existsSync22(dir)) {
|
|
37340
37439
|
mkdirSync7(dir, { recursive: true, mode: 448 });
|
|
37341
37440
|
} else {
|
|
37342
37441
|
try {
|
|
@@ -37713,13 +37812,13 @@ var init_gemini = __esm({
|
|
|
37713
37812
|
|
|
37714
37813
|
// packages/core/src/llm/stable-device-id.ts
|
|
37715
37814
|
import { randomUUID } from "node:crypto";
|
|
37716
|
-
import { existsSync as
|
|
37717
|
-
import { dirname as
|
|
37815
|
+
import { existsSync as existsSync23, mkdirSync as mkdirSync8, readFileSync as readFileSync14, renameSync as renameSync6, writeFileSync as writeFileSync8 } from "node:fs";
|
|
37816
|
+
import { dirname as dirname10, join as join24 } from "node:path";
|
|
37718
37817
|
import { getCleoHome as getCleoHome8 } from "@cleocode/paths";
|
|
37719
37818
|
function getStableDeviceId() {
|
|
37720
37819
|
if (_cachedDeviceId !== null) return _cachedDeviceId;
|
|
37721
|
-
const path =
|
|
37722
|
-
if (
|
|
37820
|
+
const path = join24(getCleoHome8(), DEVICE_ID_FILE);
|
|
37821
|
+
if (existsSync23(path)) {
|
|
37723
37822
|
try {
|
|
37724
37823
|
const raw = readFileSync14(path, "utf-8").trim();
|
|
37725
37824
|
if (raw.length > 0) {
|
|
@@ -37731,8 +37830,8 @@ function getStableDeviceId() {
|
|
|
37731
37830
|
}
|
|
37732
37831
|
const fresh = randomUUID();
|
|
37733
37832
|
try {
|
|
37734
|
-
const dir =
|
|
37735
|
-
if (!
|
|
37833
|
+
const dir = dirname10(path);
|
|
37834
|
+
if (!existsSync23(dir)) {
|
|
37736
37835
|
mkdirSync8(dir, { recursive: true });
|
|
37737
37836
|
}
|
|
37738
37837
|
const tmpPath = `${path}.tmp.${process.pid}`;
|
|
@@ -38035,13 +38134,13 @@ var init_xai = __esm({
|
|
|
38035
38134
|
|
|
38036
38135
|
// packages/core/src/llm/provider-registry/loader.ts
|
|
38037
38136
|
import { readdirSync as readdirSync5, statSync as statSync7 } from "node:fs";
|
|
38038
|
-
import { join as
|
|
38137
|
+
import { join as join25 } from "node:path";
|
|
38039
38138
|
import { pathToFileURL } from "node:url";
|
|
38040
38139
|
function isPluginFile(filename) {
|
|
38041
38140
|
return PLUGIN_EXTENSIONS.some((ext) => filename.endsWith(ext));
|
|
38042
38141
|
}
|
|
38043
38142
|
function getPluginDir() {
|
|
38044
|
-
return
|
|
38143
|
+
return join25(getCleoHome(), "plugins", "model-providers");
|
|
38045
38144
|
}
|
|
38046
38145
|
async function loadOnePlugin(absPath, api) {
|
|
38047
38146
|
let mod;
|
|
@@ -38089,13 +38188,13 @@ async function scanAndLoadPlugins(pluginDir, api) {
|
|
|
38089
38188
|
}
|
|
38090
38189
|
const pluginFiles = entries.filter((name15) => !name15.startsWith(".") && isPluginFile(name15)).filter((name15) => {
|
|
38091
38190
|
try {
|
|
38092
|
-
return statSync7(
|
|
38191
|
+
return statSync7(join25(pluginDir, name15)).isFile();
|
|
38093
38192
|
} catch {
|
|
38094
38193
|
return false;
|
|
38095
38194
|
}
|
|
38096
38195
|
}).sort();
|
|
38097
38196
|
for (const filename of pluginFiles) {
|
|
38098
|
-
await loadOnePlugin(
|
|
38197
|
+
await loadOnePlugin(join25(pluginDir, filename), api);
|
|
38099
38198
|
}
|
|
38100
38199
|
}
|
|
38101
38200
|
async function runDiscovery(registerProvider2, builtins) {
|
|
@@ -38176,15 +38275,15 @@ var init_provider_registry = __esm({
|
|
|
38176
38275
|
});
|
|
38177
38276
|
|
|
38178
38277
|
// packages/core/src/llm/rate-limit-guard.ts
|
|
38179
|
-
import { existsSync as
|
|
38180
|
-
import { join as
|
|
38278
|
+
import { existsSync as existsSync24, mkdirSync as mkdirSync9, unlinkSync as unlinkSync6 } from "node:fs";
|
|
38279
|
+
import { join as join26 } from "node:path";
|
|
38181
38280
|
import { getCleoHome as getCleoHome9 } from "@cleocode/paths";
|
|
38182
38281
|
function sanitize(value) {
|
|
38183
38282
|
return value.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
38184
38283
|
}
|
|
38185
38284
|
function rateLimitStatePath(provider, label) {
|
|
38186
|
-
const dir =
|
|
38187
|
-
return
|
|
38285
|
+
const dir = join26(getCleoHome9(), "rate-limit-state");
|
|
38286
|
+
return join26(dir, `${sanitize(provider)}-${sanitize(label)}.json`);
|
|
38188
38287
|
}
|
|
38189
38288
|
function parseResetFromHeaders(headers) {
|
|
38190
38289
|
const get = (k) => {
|
|
@@ -38231,8 +38330,8 @@ async function recordRateLimit(provider, label, opts) {
|
|
|
38231
38330
|
source = "default";
|
|
38232
38331
|
}
|
|
38233
38332
|
const filePath = rateLimitStatePath(provider, label);
|
|
38234
|
-
const dir =
|
|
38235
|
-
if (!
|
|
38333
|
+
const dir = join26(getCleoHome9(), "rate-limit-state");
|
|
38334
|
+
if (!existsSync24(dir)) {
|
|
38236
38335
|
mkdirSync9(dir, { recursive: true });
|
|
38237
38336
|
}
|
|
38238
38337
|
const state = { resetAt, recordedAt: now, source };
|
|
@@ -39075,14 +39174,14 @@ var init_catalog_cache = __esm({
|
|
|
39075
39174
|
|
|
39076
39175
|
// packages/core/src/llm/model-metadata.ts
|
|
39077
39176
|
import { readFileSync as readFileSync15 } from "node:fs";
|
|
39078
|
-
import { dirname as
|
|
39177
|
+
import { dirname as dirname11, join as join27 } from "node:path";
|
|
39079
39178
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
39080
39179
|
function getCuratedTable() {
|
|
39081
39180
|
if (_curated !== void 0) {
|
|
39082
39181
|
return _curated;
|
|
39083
39182
|
}
|
|
39084
|
-
const thisDir =
|
|
39085
|
-
const jsonPath =
|
|
39183
|
+
const thisDir = dirname11(fileURLToPath3(import.meta.url));
|
|
39184
|
+
const jsonPath = join27(thisDir, "curated-models.json");
|
|
39086
39185
|
const raw = JSON.parse(readFileSync15(jsonPath, "utf-8"));
|
|
39087
39186
|
_curated = raw.models;
|
|
39088
39187
|
return _curated;
|