web: auto-create index entries for unindexed sessions in active-runs

This commit is contained in:
kumarabhirup 2026-02-19 21:52:01 -08:00
parent 19f327a48c
commit f5c6fa186f
No known key found for this signature in database
GPG Key ID: DB7CA2289CAB0167

View File

@ -356,12 +356,35 @@ function updateIndex(
) {
try {
const idxPath = indexFile();
if (!existsSync(idxPath)) {return;}
const index = JSON.parse(
let index: Array<Record<string, unknown>>;
if (!existsSync(idxPath)) {
// Auto-create index with a bootstrap entry for this session so
// orphaned .jsonl files become visible in the sidebar.
index = [{
id: sessionId,
title: opts.title || "New Chat",
createdAt: Date.now(),
updatedAt: Date.now(),
messageCount: opts.incrementCount || 0,
}];
writeFileSync(idxPath, JSON.stringify(index, null, 2));
return;
}
index = JSON.parse(
readFileSync(idxPath, "utf-8"),
) as Array<Record<string, unknown>>;
const session = index.find((s) => s.id === sessionId);
if (!session) {return;}
let session = index.find((s) => s.id === sessionId);
if (!session) {
// Session file exists but wasn't indexed — add it.
session = {
id: sessionId,
title: opts.title || "New Chat",
createdAt: Date.now(),
updatedAt: Date.now(),
messageCount: 0,
};
index.unshift(session);
}
session.updatedAt = Date.now();
if (opts.incrementCount) {
session.messageCount =