openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
57 lines (56 loc) • 2.52 kB
JavaScript
import { r as resolveStateDir } from "./state-dir-DiG0gXzD.mjs";
import { i as listAgentIds } from "./agent-roster-t1ooUdXp.mjs";
import { a as resolveUnsuffixedSqliteTargetFromSessionStorePath, r as parseSqliteTargetSuffixIndex } from "./session-sqlite-target-paths-Dw0pT36E.mjs";
import { r as isUpdateRehearsalReadOnlyPath } from "./update-rehearsal-paths-Dr1MbUA_.mjs";
import { s as resolveConfiguredAgentDatabaseTargets } from "./targets-BVE0__Jb.mjs";
import path from "node:path";
//#region src/commands/doctor-relative-session-store-paths.ts
/** Preflight inspects custom stores without binding their migration owners. */
function resolveDoctorAgentMigrationTargets(e, t, n) {
const r = n.skipConfigured ? [] : resolveConfiguredAgentDatabaseTargets(e, {
env: t,
registeredDatabases: n.registeredDatabases
});
if (n.mode === "doctor") r.push(...resolveRelativeSessionStoreMigrationTargets(e, t, n.registeredDatabases).filter((e) => !isUpdateRehearsalReadOnlyPath(e.path, t)));
return r;
}
/** Match recorded old working directories without searching unrelated filesystem roots. */
function registeredRelativeStoreBase(e, t, n, r) {
const i = t.split(path.sep);
let a = 0;
while (i[0] === "..") {
i.shift();
a++;
}
const o = i.pop();
if (!o) return;
const s = path.basename(e);
if (s !== o && (!r || parseSqliteTargetSuffixIndex(s, `${path.basename(o, ".sqlite")}.${n}`) === void 0)) return;
const c = path.join(...i, s);
if (!e.endsWith(`${path.sep}${c}`)) return;
const l = e.slice(0, -c.length);
return path.join(l, ...Array(a).fill(".old-session-cwd"));
}
/** Doctor retains these prior selectors through schema repair, backup, and the final merge. */
function resolveRelativeSessionStoreMigrationTargets(e, t, n) {
const r = e.session?.store;
const i = [];
if (!r || r.startsWith("~") || path.isAbsolute(r)) return i;
const a = path.join(resolveStateDir(t), ".relative-session-store-probe");
for (const t of listAgentIds(e)) {
const e = r.replaceAll("{agentId}", t);
const o = resolveUnsuffixedSqliteTargetFromSessionStorePath(path.resolve(a, e));
for (const r of n) {
if (!o.shared && r.agentId !== t) continue;
const n = registeredRelativeStoreBase(r.path, path.relative(a, o.path), r.agentId, !o.agentId && !o.shared);
if (n !== void 0) i.push({
...r,
configuredAgentId: t,
storePath: path.resolve(n, e)
});
}
}
return i;
}
//#endregion
export { resolveRelativeSessionStoreMigrationTargets as n, resolveDoctorAgentMigrationTargets as t };