fix(coding): close PI-100 review findings
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import { mkdir, stat } from 'node:fs/promises';
|
||||
import { mkdir, rename, stat } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import {
|
||||
BUNDLED_CODING_SKILL_IDS,
|
||||
type BundledCodingSkillId,
|
||||
} from '../../../shared/coding-skills';
|
||||
import { atomicWriteJson, atomicWriteText } from '../../coding-projects/atomic-json';
|
||||
import { validateSessionKey } from '../../coding-projects/conversation-store';
|
||||
import type { PiProviderSelection } from './provider-config';
|
||||
import type { PiManagedInputRevision } from './managed-input-revision';
|
||||
|
||||
@@ -104,6 +105,31 @@ export async function ensurePiManagedPaths(userDataDir: string): Promise<PiManag
|
||||
return paths;
|
||||
}
|
||||
|
||||
export async function archivePiConversationSession(input: {
|
||||
userDataDir: string;
|
||||
projectId: string;
|
||||
sessionKey: string;
|
||||
}): Promise<string | null> {
|
||||
const projectId = managedSegment(input.projectId, 'Project id');
|
||||
const sessionKey = validateSessionKey(input.sessionKey);
|
||||
const paths = getPiManagedPaths(input.userDataDir);
|
||||
const source = path.join(paths.sessionsDir, projectId, `${sessionKey}.jsonl`);
|
||||
const targetDirectory = path.join(paths.trashDir, projectId);
|
||||
const target = path.join(targetDirectory, `${sessionKey}.jsonl`);
|
||||
await mkdir(targetDirectory, { recursive: true });
|
||||
try {
|
||||
await rename(source, target);
|
||||
return target;
|
||||
} catch (error) {
|
||||
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error;
|
||||
const alreadyArchived = await stat(target).catch((targetError: NodeJS.ErrnoException) => {
|
||||
if (targetError.code === 'ENOENT') return null;
|
||||
throw targetError;
|
||||
});
|
||||
return alreadyArchived?.isFile() ? target : null;
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeSkillIds(skillIds: readonly string[]): BundledCodingSkillId[] {
|
||||
const result: BundledCodingSkillId[] = [];
|
||||
const seen = new Set<string>();
|
||||
|
||||
Reference in New Issue
Block a user