This commit is contained in:
@@ -65,7 +65,7 @@ function create(meta) {
|
||||
return summary;
|
||||
}
|
||||
|
||||
function load(id) {
|
||||
function load(id, opts) {
|
||||
const dir = sessionDir(id);
|
||||
let summary;
|
||||
try {
|
||||
@@ -74,7 +74,7 @@ function load(id) {
|
||||
throw new Error('session not found: ' + id);
|
||||
}
|
||||
summary.history = readJsonl(path.join(dir, 'chat_history.jsonl'));
|
||||
summary.updates = readJsonl(path.join(dir, 'updates.jsonl'));
|
||||
summary.updates = opts && opts.updates ? readJsonl(path.join(dir, 'updates.jsonl')) : [];
|
||||
return summary;
|
||||
}
|
||||
|
||||
@@ -118,6 +118,50 @@ function writePlan(id, text) {
|
||||
return file;
|
||||
}
|
||||
|
||||
function rmDeep(dir) {
|
||||
let ents = [];
|
||||
try {
|
||||
ents = fs.readdirSync(dir, { withFileTypes: true });
|
||||
} catch (_) {
|
||||
return;
|
||||
}
|
||||
for (const ent of ents) {
|
||||
const child = path.join(dir, ent.name);
|
||||
const isDir = typeof ent.isDirectory === 'function' ? ent.isDirectory() : false;
|
||||
if (isDir) rmDeep(child);
|
||||
else {
|
||||
try {
|
||||
fs.unlinkSync(child);
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
try {
|
||||
fs.rmdirSync(dir);
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
function remove(id) {
|
||||
if (!id) return false;
|
||||
const dir = path.join(sessionsRoot(), sanitizeId(id));
|
||||
try {
|
||||
if (typeof fs.rmSync === 'function') fs.rmSync(dir, { recursive: true, force: true });
|
||||
else rmDeep(dir);
|
||||
return true;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function exists(id) {
|
||||
if (!id) return false;
|
||||
try {
|
||||
fs.statSync(path.join(sessionsRoot(), sanitizeId(id), 'summary.json'));
|
||||
return true;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function list() {
|
||||
const root = sessionsRoot();
|
||||
let names = [];
|
||||
@@ -149,5 +193,7 @@ module.exports = {
|
||||
readPlan,
|
||||
writePlan,
|
||||
list,
|
||||
remove,
|
||||
exists,
|
||||
makeId,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user