diff --git a/docs/genaisrc/genaiscript.d.ts b/docs/genaisrc/genaiscript.d.ts index d9596b1677..a726567079 100644 --- a/docs/genaisrc/genaiscript.d.ts +++ b/docs/genaisrc/genaiscript.d.ts @@ -83,6 +83,7 @@ type SystemPromptId = OptionsOrString< | "system.explanations" | "system.files" | "system.files_schema" + | "system.fs_diff_files" | "system.fs_find_files" | "system.fs_read_file" | "system.git" @@ -112,6 +113,7 @@ type SystemToolId = OptionsOrString< | "agent_github" | "agent_interpreter" | "agent_user_input" + | "fs_diff_files" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -1242,6 +1244,11 @@ interface Parsers { * Renders a jinja template */ jinja(text: string | WorkspaceFile, data: Record): string + + /** + * Computes a diff between two files + */ + diff(left: WorkspaceFile, right: WorkspaceFile, options?: DefDiffOptions): string } interface AICIGenOptions { diff --git a/docs/src/components/BuiltinTools.mdx b/docs/src/components/BuiltinTools.mdx index 7a7842505e..b7c58b17a3 100644 --- a/docs/src/components/BuiltinTools.mdx +++ b/docs/src/components/BuiltinTools.mdx @@ -11,6 +11,7 @@ import { LinkCard } from '@astrojs/starlight/components'; + diff --git a/docs/src/content/docs/reference/scripts/system.mdx b/docs/src/content/docs/reference/scripts/system.mdx index 0310942d63..2ad84a3271 100644 --- a/docs/src/content/docs/reference/scripts/system.mdx +++ b/docs/src/content/docs/reference/scripts/system.mdx @@ -143,6 +143,7 @@ defTool( "system.explanations", "system.fs_find_files", "system.fs_read_file", + "system.fs_diff_files", "system.retrieval_fuzz_search", "system.md_frontmatter", ], @@ -652,6 +653,51 @@ def(`File ${folder}/data.json`, `...`, { ````` +### `system.fs_diff_files` + +File Diff Files + +Tool to compute a diff betweeen two files. + +- tool `fs_diff_files`: Computes a diff between two files. + +`````js wrap title="system.fs_diff_files" +system({ + title: "File Diff Files", + description: "Tool to compute a diff betweeen two files.", +}) + +defTool( + "fs_diff_files", + "Computes a diff between two files.", + { + type: "object", + properties: { + filename: { + type: "string", + description: + "Path of the file to compare, relative to the workspace.", + }, + otherfilename: { + type: "string", + description: + "Path of the other file to compare, relative to the workspace.", + }, + }, + required: ["filename"], + }, + async (args) => { + const { context, filename, otherfilename } = args + context.log(`diff: ${filename} ${filename}`) + const f = await workspace.readText(filename) + const of = await workspace.readText(otherfilename) + return parsers.diff(f, of) + } +) + +````` + + ### `system.fs_find_files` File find files diff --git a/genaisrc/genaiscript.d.ts b/genaisrc/genaiscript.d.ts index d9596b1677..a726567079 100644 --- a/genaisrc/genaiscript.d.ts +++ b/genaisrc/genaiscript.d.ts @@ -83,6 +83,7 @@ type SystemPromptId = OptionsOrString< | "system.explanations" | "system.files" | "system.files_schema" + | "system.fs_diff_files" | "system.fs_find_files" | "system.fs_read_file" | "system.git" @@ -112,6 +113,7 @@ type SystemToolId = OptionsOrString< | "agent_github" | "agent_interpreter" | "agent_user_input" + | "fs_diff_files" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -1242,6 +1244,11 @@ interface Parsers { * Renders a jinja template */ jinja(text: string | WorkspaceFile, data: Record): string + + /** + * Computes a diff between two files + */ + diff(left: WorkspaceFile, right: WorkspaceFile, options?: DefDiffOptions): string } interface AICIGenOptions { diff --git a/packages/auto/genaiscript.d.ts b/packages/auto/genaiscript.d.ts index d9596b1677..a726567079 100644 --- a/packages/auto/genaiscript.d.ts +++ b/packages/auto/genaiscript.d.ts @@ -83,6 +83,7 @@ type SystemPromptId = OptionsOrString< | "system.explanations" | "system.files" | "system.files_schema" + | "system.fs_diff_files" | "system.fs_find_files" | "system.fs_read_file" | "system.git" @@ -112,6 +113,7 @@ type SystemToolId = OptionsOrString< | "agent_github" | "agent_interpreter" | "agent_user_input" + | "fs_diff_files" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -1242,6 +1244,11 @@ interface Parsers { * Renders a jinja template */ jinja(text: string | WorkspaceFile, data: Record): string + + /** + * Computes a diff between two files + */ + diff(left: WorkspaceFile, right: WorkspaceFile, options?: DefDiffOptions): string } interface AICIGenOptions { diff --git a/packages/core/src/genaisrc/genaiscript.d.ts b/packages/core/src/genaisrc/genaiscript.d.ts index d9596b1677..a726567079 100644 --- a/packages/core/src/genaisrc/genaiscript.d.ts +++ b/packages/core/src/genaisrc/genaiscript.d.ts @@ -83,6 +83,7 @@ type SystemPromptId = OptionsOrString< | "system.explanations" | "system.files" | "system.files_schema" + | "system.fs_diff_files" | "system.fs_find_files" | "system.fs_read_file" | "system.git" @@ -112,6 +113,7 @@ type SystemToolId = OptionsOrString< | "agent_github" | "agent_interpreter" | "agent_user_input" + | "fs_diff_files" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -1242,6 +1244,11 @@ interface Parsers { * Renders a jinja template */ jinja(text: string | WorkspaceFile, data: Record): string + + /** + * Computes a diff between two files + */ + diff(left: WorkspaceFile, right: WorkspaceFile, options?: DefDiffOptions): string } interface AICIGenOptions { diff --git a/packages/core/src/genaisrc/system.agent_fs.genai.mjs b/packages/core/src/genaisrc/system.agent_fs.genai.mjs index 7ba3b86f43..f5f5879793 100644 --- a/packages/core/src/genaisrc/system.agent_fs.genai.mjs +++ b/packages/core/src/genaisrc/system.agent_fs.genai.mjs @@ -36,6 +36,7 @@ defTool( "system.explanations", "system.fs_find_files", "system.fs_read_file", + "system.fs_diff_files", "system.retrieval_fuzz_search", "system.md_frontmatter", ], diff --git a/packages/core/src/genaisrc/system.fs_diff_files.genai.mjs b/packages/core/src/genaisrc/system.fs_diff_files.genai.mjs new file mode 100644 index 0000000000..b30fd2743e --- /dev/null +++ b/packages/core/src/genaisrc/system.fs_diff_files.genai.mjs @@ -0,0 +1,32 @@ +system({ + title: "File Diff Files", + description: "Tool to compute a diff betweeen two files.", +}) + +defTool( + "fs_diff_files", + "Computes a diff between two files.", + { + type: "object", + properties: { + filename: { + type: "string", + description: + "Path of the file to compare, relative to the workspace.", + }, + otherfilename: { + type: "string", + description: + "Path of the other file to compare, relative to the workspace.", + }, + }, + required: ["filename"], + }, + async (args) => { + const { context, filename, otherfilename } = args + context.log(`diff: ${filename} ${filename}`) + const f = await workspace.readText(filename) + const of = await workspace.readText(otherfilename) + return parsers.diff(f, of) + } +) diff --git a/packages/core/src/genaisrc/system.fs_find_files.genai.js b/packages/core/src/genaisrc/system.fs_find_files.genai.mjs similarity index 100% rename from packages/core/src/genaisrc/system.fs_find_files.genai.js rename to packages/core/src/genaisrc/system.fs_find_files.genai.mjs diff --git a/packages/core/src/genaisrc/system.fs_read_file.genai.js b/packages/core/src/genaisrc/system.fs_read_file.genai.mjs similarity index 100% rename from packages/core/src/genaisrc/system.fs_read_file.genai.js rename to packages/core/src/genaisrc/system.fs_read_file.genai.mjs diff --git a/packages/core/src/parsers.ts b/packages/core/src/parsers.ts index 0a6ca302ee..c4971bded3 100644 --- a/packages/core/src/parsers.ts +++ b/packages/core/src/parsers.ts @@ -25,6 +25,7 @@ import { resolveFileContent } from "./file" import { resolveTokenEncoder } from "./encoders" import { mustacheRender } from "./mustache" import { jinjaRender } from "./jinja" +import { createDiff, llmifyDiff } from "./diff" export async function createParsers(options: { trace: MarkdownTrace @@ -115,5 +116,6 @@ export async function createParsers(options: { const f = filenameOrFileToContent(file) return jinjaRender(f, data) }, + diff: (f1, f2) => llmifyDiff(createDiff(f1, f2)), }) } diff --git a/packages/core/src/types/prompt_template.d.ts b/packages/core/src/types/prompt_template.d.ts index 765b14a6e8..19d97f770e 100644 --- a/packages/core/src/types/prompt_template.d.ts +++ b/packages/core/src/types/prompt_template.d.ts @@ -1170,6 +1170,11 @@ interface Parsers { * Renders a jinja template */ jinja(text: string | WorkspaceFile, data: Record): string + + /** + * Computes a diff between two files + */ + diff(left: WorkspaceFile, right: WorkspaceFile, options?: DefDiffOptions): string } interface AICIGenOptions { diff --git a/packages/sample/genaisrc/blog/genaiscript.d.ts b/packages/sample/genaisrc/blog/genaiscript.d.ts index d9596b1677..a726567079 100644 --- a/packages/sample/genaisrc/blog/genaiscript.d.ts +++ b/packages/sample/genaisrc/blog/genaiscript.d.ts @@ -83,6 +83,7 @@ type SystemPromptId = OptionsOrString< | "system.explanations" | "system.files" | "system.files_schema" + | "system.fs_diff_files" | "system.fs_find_files" | "system.fs_read_file" | "system.git" @@ -112,6 +113,7 @@ type SystemToolId = OptionsOrString< | "agent_github" | "agent_interpreter" | "agent_user_input" + | "fs_diff_files" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -1242,6 +1244,11 @@ interface Parsers { * Renders a jinja template */ jinja(text: string | WorkspaceFile, data: Record): string + + /** + * Computes a diff between two files + */ + diff(left: WorkspaceFile, right: WorkspaceFile, options?: DefDiffOptions): string } interface AICIGenOptions { diff --git a/packages/sample/genaisrc/files.genai.js b/packages/sample/genaisrc/files.genai.mjs similarity index 54% rename from packages/sample/genaisrc/files.genai.js rename to packages/sample/genaisrc/files.genai.mjs index 75dc4ed9d4..ef712b66fe 100644 --- a/packages/sample/genaisrc/files.genai.js +++ b/packages/sample/genaisrc/files.genai.mjs @@ -1,7 +1,7 @@ script({ model: "gpt-3.5-turbo", system: ["system", "system.files"], - tests: {} + tests: {}, }) -$`Generate a poem and save it in a file "poem.txt".` \ No newline at end of file +$`Generate a poem and save it in a file "poem.txt".` diff --git a/packages/sample/genaisrc/genaiscript.d.ts b/packages/sample/genaisrc/genaiscript.d.ts index d9596b1677..a726567079 100644 --- a/packages/sample/genaisrc/genaiscript.d.ts +++ b/packages/sample/genaisrc/genaiscript.d.ts @@ -83,6 +83,7 @@ type SystemPromptId = OptionsOrString< | "system.explanations" | "system.files" | "system.files_schema" + | "system.fs_diff_files" | "system.fs_find_files" | "system.fs_read_file" | "system.git" @@ -112,6 +113,7 @@ type SystemToolId = OptionsOrString< | "agent_github" | "agent_interpreter" | "agent_user_input" + | "fs_diff_files" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -1242,6 +1244,11 @@ interface Parsers { * Renders a jinja template */ jinja(text: string | WorkspaceFile, data: Record): string + + /** + * Computes a diff between two files + */ + diff(left: WorkspaceFile, right: WorkspaceFile, options?: DefDiffOptions): string } interface AICIGenOptions { diff --git a/packages/sample/genaisrc/node/genaiscript.d.ts b/packages/sample/genaisrc/node/genaiscript.d.ts index d9596b1677..a726567079 100644 --- a/packages/sample/genaisrc/node/genaiscript.d.ts +++ b/packages/sample/genaisrc/node/genaiscript.d.ts @@ -83,6 +83,7 @@ type SystemPromptId = OptionsOrString< | "system.explanations" | "system.files" | "system.files_schema" + | "system.fs_diff_files" | "system.fs_find_files" | "system.fs_read_file" | "system.git" @@ -112,6 +113,7 @@ type SystemToolId = OptionsOrString< | "agent_github" | "agent_interpreter" | "agent_user_input" + | "fs_diff_files" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -1242,6 +1244,11 @@ interface Parsers { * Renders a jinja template */ jinja(text: string | WorkspaceFile, data: Record): string + + /** + * Computes a diff between two files + */ + diff(left: WorkspaceFile, right: WorkspaceFile, options?: DefDiffOptions): string } interface AICIGenOptions { diff --git a/packages/sample/genaisrc/python/genaiscript.d.ts b/packages/sample/genaisrc/python/genaiscript.d.ts index d9596b1677..a726567079 100644 --- a/packages/sample/genaisrc/python/genaiscript.d.ts +++ b/packages/sample/genaisrc/python/genaiscript.d.ts @@ -83,6 +83,7 @@ type SystemPromptId = OptionsOrString< | "system.explanations" | "system.files" | "system.files_schema" + | "system.fs_diff_files" | "system.fs_find_files" | "system.fs_read_file" | "system.git" @@ -112,6 +113,7 @@ type SystemToolId = OptionsOrString< | "agent_github" | "agent_interpreter" | "agent_user_input" + | "fs_diff_files" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -1242,6 +1244,11 @@ interface Parsers { * Renders a jinja template */ jinja(text: string | WorkspaceFile, data: Record): string + + /** + * Computes a diff between two files + */ + diff(left: WorkspaceFile, right: WorkspaceFile, options?: DefDiffOptions): string } interface AICIGenOptions { diff --git a/packages/sample/genaisrc/style/genaiscript.d.ts b/packages/sample/genaisrc/style/genaiscript.d.ts index d9596b1677..a726567079 100644 --- a/packages/sample/genaisrc/style/genaiscript.d.ts +++ b/packages/sample/genaisrc/style/genaiscript.d.ts @@ -83,6 +83,7 @@ type SystemPromptId = OptionsOrString< | "system.explanations" | "system.files" | "system.files_schema" + | "system.fs_diff_files" | "system.fs_find_files" | "system.fs_read_file" | "system.git" @@ -112,6 +113,7 @@ type SystemToolId = OptionsOrString< | "agent_github" | "agent_interpreter" | "agent_user_input" + | "fs_diff_files" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -1242,6 +1244,11 @@ interface Parsers { * Renders a jinja template */ jinja(text: string | WorkspaceFile, data: Record): string + + /** + * Computes a diff between two files + */ + diff(left: WorkspaceFile, right: WorkspaceFile, options?: DefDiffOptions): string } interface AICIGenOptions { diff --git a/packages/sample/src/aici/genaiscript.d.ts b/packages/sample/src/aici/genaiscript.d.ts index d9596b1677..a726567079 100644 --- a/packages/sample/src/aici/genaiscript.d.ts +++ b/packages/sample/src/aici/genaiscript.d.ts @@ -83,6 +83,7 @@ type SystemPromptId = OptionsOrString< | "system.explanations" | "system.files" | "system.files_schema" + | "system.fs_diff_files" | "system.fs_find_files" | "system.fs_read_file" | "system.git" @@ -112,6 +113,7 @@ type SystemToolId = OptionsOrString< | "agent_github" | "agent_interpreter" | "agent_user_input" + | "fs_diff_files" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -1242,6 +1244,11 @@ interface Parsers { * Renders a jinja template */ jinja(text: string | WorkspaceFile, data: Record): string + + /** + * Computes a diff between two files + */ + diff(left: WorkspaceFile, right: WorkspaceFile, options?: DefDiffOptions): string } interface AICIGenOptions { diff --git a/packages/sample/src/errors/genaiscript.d.ts b/packages/sample/src/errors/genaiscript.d.ts index d9596b1677..a726567079 100644 --- a/packages/sample/src/errors/genaiscript.d.ts +++ b/packages/sample/src/errors/genaiscript.d.ts @@ -83,6 +83,7 @@ type SystemPromptId = OptionsOrString< | "system.explanations" | "system.files" | "system.files_schema" + | "system.fs_diff_files" | "system.fs_find_files" | "system.fs_read_file" | "system.git" @@ -112,6 +113,7 @@ type SystemToolId = OptionsOrString< | "agent_github" | "agent_interpreter" | "agent_user_input" + | "fs_diff_files" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -1242,6 +1244,11 @@ interface Parsers { * Renders a jinja template */ jinja(text: string | WorkspaceFile, data: Record): string + + /** + * Computes a diff between two files + */ + diff(left: WorkspaceFile, right: WorkspaceFile, options?: DefDiffOptions): string } interface AICIGenOptions { diff --git a/packages/sample/src/genaiscript.d.ts b/packages/sample/src/genaiscript.d.ts index d9596b1677..a726567079 100644 --- a/packages/sample/src/genaiscript.d.ts +++ b/packages/sample/src/genaiscript.d.ts @@ -83,6 +83,7 @@ type SystemPromptId = OptionsOrString< | "system.explanations" | "system.files" | "system.files_schema" + | "system.fs_diff_files" | "system.fs_find_files" | "system.fs_read_file" | "system.git" @@ -112,6 +113,7 @@ type SystemToolId = OptionsOrString< | "agent_github" | "agent_interpreter" | "agent_user_input" + | "fs_diff_files" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -1242,6 +1244,11 @@ interface Parsers { * Renders a jinja template */ jinja(text: string | WorkspaceFile, data: Record): string + + /** + * Computes a diff between two files + */ + diff(left: WorkspaceFile, right: WorkspaceFile, options?: DefDiffOptions): string } interface AICIGenOptions { diff --git a/packages/sample/src/makecode/genaiscript.d.ts b/packages/sample/src/makecode/genaiscript.d.ts index d9596b1677..a726567079 100644 --- a/packages/sample/src/makecode/genaiscript.d.ts +++ b/packages/sample/src/makecode/genaiscript.d.ts @@ -83,6 +83,7 @@ type SystemPromptId = OptionsOrString< | "system.explanations" | "system.files" | "system.files_schema" + | "system.fs_diff_files" | "system.fs_find_files" | "system.fs_read_file" | "system.git" @@ -112,6 +113,7 @@ type SystemToolId = OptionsOrString< | "agent_github" | "agent_interpreter" | "agent_user_input" + | "fs_diff_files" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -1242,6 +1244,11 @@ interface Parsers { * Renders a jinja template */ jinja(text: string | WorkspaceFile, data: Record): string + + /** + * Computes a diff between two files + */ + diff(left: WorkspaceFile, right: WorkspaceFile, options?: DefDiffOptions): string } interface AICIGenOptions { diff --git a/packages/sample/src/tla/genaiscript.d.ts b/packages/sample/src/tla/genaiscript.d.ts index d9596b1677..a726567079 100644 --- a/packages/sample/src/tla/genaiscript.d.ts +++ b/packages/sample/src/tla/genaiscript.d.ts @@ -83,6 +83,7 @@ type SystemPromptId = OptionsOrString< | "system.explanations" | "system.files" | "system.files_schema" + | "system.fs_diff_files" | "system.fs_find_files" | "system.fs_read_file" | "system.git" @@ -112,6 +113,7 @@ type SystemToolId = OptionsOrString< | "agent_github" | "agent_interpreter" | "agent_user_input" + | "fs_diff_files" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -1242,6 +1244,11 @@ interface Parsers { * Renders a jinja template */ jinja(text: string | WorkspaceFile, data: Record): string + + /** + * Computes a diff between two files + */ + diff(left: WorkspaceFile, right: WorkspaceFile, options?: DefDiffOptions): string } interface AICIGenOptions { diff --git a/packages/sample/src/vision/genaiscript.d.ts b/packages/sample/src/vision/genaiscript.d.ts index d9596b1677..a726567079 100644 --- a/packages/sample/src/vision/genaiscript.d.ts +++ b/packages/sample/src/vision/genaiscript.d.ts @@ -83,6 +83,7 @@ type SystemPromptId = OptionsOrString< | "system.explanations" | "system.files" | "system.files_schema" + | "system.fs_diff_files" | "system.fs_find_files" | "system.fs_read_file" | "system.git" @@ -112,6 +113,7 @@ type SystemToolId = OptionsOrString< | "agent_github" | "agent_interpreter" | "agent_user_input" + | "fs_diff_files" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -1242,6 +1244,11 @@ interface Parsers { * Renders a jinja template */ jinja(text: string | WorkspaceFile, data: Record): string + + /** + * Computes a diff between two files + */ + diff(left: WorkspaceFile, right: WorkspaceFile, options?: DefDiffOptions): string } interface AICIGenOptions { diff --git a/packages/vscode/genaisrc/genaiscript.d.ts b/packages/vscode/genaisrc/genaiscript.d.ts index d9596b1677..a726567079 100644 --- a/packages/vscode/genaisrc/genaiscript.d.ts +++ b/packages/vscode/genaisrc/genaiscript.d.ts @@ -83,6 +83,7 @@ type SystemPromptId = OptionsOrString< | "system.explanations" | "system.files" | "system.files_schema" + | "system.fs_diff_files" | "system.fs_find_files" | "system.fs_read_file" | "system.git" @@ -112,6 +113,7 @@ type SystemToolId = OptionsOrString< | "agent_github" | "agent_interpreter" | "agent_user_input" + | "fs_diff_files" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -1242,6 +1244,11 @@ interface Parsers { * Renders a jinja template */ jinja(text: string | WorkspaceFile, data: Record): string + + /** + * Computes a diff between two files + */ + diff(left: WorkspaceFile, right: WorkspaceFile, options?: DefDiffOptions): string } interface AICIGenOptions { diff --git a/slides/genaisrc/genaiscript.d.ts b/slides/genaisrc/genaiscript.d.ts index d9596b1677..a726567079 100644 --- a/slides/genaisrc/genaiscript.d.ts +++ b/slides/genaisrc/genaiscript.d.ts @@ -83,6 +83,7 @@ type SystemPromptId = OptionsOrString< | "system.explanations" | "system.files" | "system.files_schema" + | "system.fs_diff_files" | "system.fs_find_files" | "system.fs_read_file" | "system.git" @@ -112,6 +113,7 @@ type SystemToolId = OptionsOrString< | "agent_github" | "agent_interpreter" | "agent_user_input" + | "fs_diff_files" | "fs_find_files" | "fs_read_file" | "git_branch_current" @@ -1242,6 +1244,11 @@ interface Parsers { * Renders a jinja template */ jinja(text: string | WorkspaceFile, data: Record): string + + /** + * Computes a diff between two files + */ + diff(left: WorkspaceFile, right: WorkspaceFile, options?: DefDiffOptions): string } interface AICIGenOptions {