Files
makelore/electron/coding-runtime/pi/extensions/changed-file.ts

36 lines
1.3 KiB
TypeScript

import type { ConversationChangeTracker } from '../../../coding-projects/conversation-change-tracker';
import type { ChangedFileDetailsV1 } from '../../contracts';
export interface ChangedFileToolContext {
conversationId: string;
runId: string;
}
export async function reportChangedFiles(
tracker: ConversationChangeTracker,
context: ChangedFileToolContext,
input: unknown,
) {
if (!input || typeof input !== 'object' || Array.isArray(input)) {
throw new Error('Changed file report is invalid');
}
const record = input as Record<string, unknown>;
const rawPaths = record.paths ?? (record.path === undefined ? undefined : [record.path]);
if (!Array.isArray(rawPaths) || rawPaths.length === 0 || rawPaths.length > 200
|| rawPaths.some((item) => typeof item !== 'string')) {
throw new Error('Changed file report requires relative paths');
}
const snapshot = await tracker.recordTouchedPaths(
context.conversationId,
context.runId,
rawPaths as string[],
record.refresh !== false,
);
const paths = snapshot.files.map((file) => file.path);
const details: ChangedFileDetailsV1 = { schema: 'changed-file.v1', paths };
return {
content: [{ type: 'text' as const, text: JSON.stringify({ paths, changes: snapshot.files }) }],
details,
};
}