openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
60 lines (59 loc) • 2.04 kB
JavaScript
import { i as isPathStrictlyInside } from "./path-guards-TIjxtj6H.mjs";
import "./file-access-runtime-BD2Fjfbw.mjs";
import { i as readMemoryArtifactProvenance } from "./memory-artifact-provenance-5S6kb8QC.mjs";
import "./memory-core-host-runtime-core-vt7Kf2j2.mjs";
import path from "node:path";
import fs from "node:fs/promises";
//#region extensions/memory-core/src/memory/memory-path-provenance.ts
async function resolveMemoryPathClassification(e) {
if (e.source !== "memory") return {
curatedRoot: false,
originClass: "untrusted"
};
let t;
if (e.readSource !== void 0) {
const n = e.readSource.canonicalRelativePath;
if (!n || n === "." || n === ".." || n.startsWith("../") || path.posix.isAbsolute(n) || path.win32.isAbsolute(n) || n.includes("\\") || n.includes("\0") || path.posix.normalize(n) !== n) return {
curatedRoot: false,
originClass: "untrusted"
};
t = n;
} else {
let n;
let r;
try {
[n, r] = await Promise.all([fs.realpath(e.workspaceDir), fs.realpath(e.absolutePath)]);
} catch {
return {
curatedRoot: false,
originClass: "untrusted"
};
}
if (!isPathStrictlyInside(n, r)) return {
curatedRoot: false,
originClass: "untrusted"
};
t = path.relative(n, r).replaceAll(path.sep, "/");
}
const n = t.split("/");
const r = n.length === 1 && (n[0] === "MEMORY.md" || n[0] === "memory.md" || n[0] === "USER.md");
if (n.length === 1 && (n[0] === "DREAMS.md" || n[0] === "dreams.md") || n[0] === "memory" && (n[1] === "dreaming" || n[1] === ".dreams")) return {
curatedRoot: r,
originClass: "system"
};
const i = r || /^users\/[a-zA-Z0-9][a-zA-Z0-9_-]{0,127}\/USER\.md$/.test(t) || n[0] === "memory" && n.at(-1)?.endsWith(".md") === true;
const a = i ? await readMemoryArtifactProvenance({
workspaceDir: e.workspaceDir,
relativePath: t
}) : void 0;
if (a) return {
curatedRoot: r,
originClass: a.originClass
};
return {
curatedRoot: r,
originClass: i ? "agent" : "untrusted"
};
}
//#endregion
export { resolveMemoryPathClassification as t };