feat: implement PI-090 product tools

This commit is contained in:
2026-08-23 15:14:50 +08:00
parent 77cdee7e73
commit 13ab383e53
32 changed files with 2035 additions and 49 deletions

View File

@@ -0,0 +1,35 @@
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,
};
}