feat: replace Code conversation archive with deletion
This commit is contained in:
1 parent
140f6be8db
commit
bf101c1e52
19 files changed
+1001
-292
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { mkdir, rename, stat } from 'node:fs/promises';
|
||||
import { mkdir, readdir, rename, rm, stat } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { atomicWriteJson, atomicWriteText } from '../../coding-projects/atomic-json';
|
||||
import { validateSessionKey } from '../../coding-projects/conversation-store';
|
||||
@@ -166,6 +166,33 @@ export async function archivePiConversationSession(input: {
|
||||
}
|
||||
}
|
||||
|
||||
export async function deletePiConversationSession(input: {
|
||||
userDataDir: string;
|
||||
projectId: string;
|
||||
sessionKey: string;
|
||||
}): Promise<void> {
|
||||
const projectId = managedSegment(input.projectId, 'Project id');
|
||||
const sessionKey = validateSessionKey(input.sessionKey);
|
||||
const paths = getPiManagedPaths(input.userDataDir);
|
||||
const basename = `${sessionKey}.jsonl`;
|
||||
for (const root of [paths.sessionsDir, paths.trashDir]) {
|
||||
const directory = path.join(root, projectId);
|
||||
const entries = await readdir(directory, { withFileTypes: true }).catch((error: NodeJS.ErrnoException) => {
|
||||
if (error.code === 'ENOENT') return [];
|
||||
throw error;
|
||||
});
|
||||
for (const entry of entries) {
|
||||
// Pi 0.84 stores sessions as <ISO timestamp>_<session id>.jsonl;
|
||||
// earlier managed sessions used the session id alone.
|
||||
const timestamp = entry.name.endsWith(`_${basename}`)
|
||||
? entry.name.slice(0, -(`_${basename}`.length))
|
||||
: '';
|
||||
if (entry.name !== basename && !/^\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}-\d{3}Z$/u.test(timestamp)) continue;
|
||||
await rm(path.join(directory, entry.name), { force: true });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeSkillEntries(skillEntries: readonly PiSkillEntry[]): PiSkillEntry[] {
|
||||
const result: PiSkillEntry[] = [];
|
||||
const seen = new Set<string>();
|
||||
|
||||
Reference in new issue
Block a user