From 6642f85a80125e81485af039dbaf4c970a37160c Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Mon, 7 Oct 2024 23:40:06 +0000 Subject: [PATCH] =?UTF-8?q?Add=20git=20branch=20default=20tool=20and=20enh?= =?UTF-8?q?ance=20PR=20descriptor=20tools=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/genaisrc/genaiscript.d.ts | 2 + docs/src/components/BuiltinTools.mdx | 1 + .../content/docs/reference/scripts/system.mdx | 43 +++++++++++++++++-- genaisrc/genaiscript.d.ts | 2 + packages/auto/genaiscript.d.ts | 2 + packages/core/src/genaisrc/genaiscript.d.ts | 2 + .../src/genaisrc/system.agent_git.genai.mjs | 6 ++- .../genaisrc/system.fs_diff_files.genai.mjs | 3 ++ .../core/src/genaisrc/system.git.genai.mjs | 12 +++++- .../src/genaisrc/system.git_info.genai.mjs | 8 ++++ .../sample/genaisrc/blog/genaiscript.d.ts | 2 + packages/sample/genaisrc/genaiscript.d.ts | 2 + .../sample/genaisrc/node/genaiscript.d.ts | 2 + packages/sample/genaisrc/prd-agent.genai.mts | 9 ++-- packages/sample/genaisrc/prd-tools.genai.mts | 25 +++++++++++ .../sample/genaisrc/python/genaiscript.d.ts | 2 + .../sample/genaisrc/style/genaiscript.d.ts | 2 + packages/sample/src/aici/genaiscript.d.ts | 2 + packages/sample/src/errors/genaiscript.d.ts | 2 + packages/sample/src/genaiscript.d.ts | 2 + packages/sample/src/makecode/genaiscript.d.ts | 2 + packages/sample/src/tla/genaiscript.d.ts | 2 + packages/sample/src/vision/genaiscript.d.ts | 2 + packages/vscode/genaisrc/genaiscript.d.ts | 2 + slides/genaisrc/genaiscript.d.ts | 2 + 25 files changed, 132 insertions(+), 9 deletions(-) create mode 100644 packages/core/src/genaisrc/system.git_info.genai.mjs create mode 100644 packages/sample/genaisrc/prd-tools.genai.mts diff --git a/docs/genaisrc/genaiscript.d.ts b/docs/genaisrc/genaiscript.d.ts index a92f8a9285..734ac6a52f 100644 --- a/docs/genaisrc/genaiscript.d.ts +++ b/docs/genaisrc/genaiscript.d.ts @@ -88,6 +88,7 @@ type SystemPromptId = OptionsOrString< | "system.fs_find_files" | "system.fs_read_file" | "system.git" + | "system.git_info" | "system.github_actions" | "system.github_files" | "system.github_info" @@ -121,6 +122,7 @@ type SystemToolId = OptionsOrString< | "fs_find_files" | "fs_read_file" | "git_branch_current" + | "git_branch_default" | "git_branch_list" | "git_diff" | "git_last_tag" diff --git a/docs/src/components/BuiltinTools.mdx b/docs/src/components/BuiltinTools.mdx index 2eba11f735..1a7c56f8d7 100644 --- a/docs/src/components/BuiltinTools.mdx +++ b/docs/src/components/BuiltinTools.mdx @@ -9,6 +9,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 dca0618930..f2d81a976c 100644 --- a/docs/src/content/docs/reference/scripts/system.mdx +++ b/docs/src/content/docs/reference/scripts/system.mdx @@ -203,8 +203,10 @@ defAgent( "query a repository using Git to accomplish tasks. Provide all the context information available to execute git queries.", `Your are a helpfull LLM agent that can use the git tools to query the current repository. Answer the question in QUERY. - - The current repository is the same as github repository.`, - { model, system: ["system.github_info"], tools: ["git"] } + - The current repository is the same as github repository. + - Prefer using diff to compare files rather than listing files. Listing files is only useful when you need to read the content of the files. + `, + { model, system: ["system.git_info", "system.github_info"], tools: ["git"] } ) ````` @@ -620,6 +622,9 @@ defTool( const f = await workspace.readText(filename) const of = await workspace.readText(otherfilename) return parsers.diff(f, of) + }, + { + maxTokens: 20000, } ) @@ -786,6 +791,7 @@ git read operations Tools to query a git repository. +- tool `git_branch_default`: Gets the default branch using git. - tool `git_branch_current`: Gets the current branch using git. - tool `git_branch_list`: List all branches using git. - tool `git_diff`: Computes file diffs using the git diff command. If the diff is too large, it returns the list of modified/added files. @@ -799,6 +805,15 @@ system({ description: "Tools to query a git repository.", }) +defTool( + "git_branch_default", + "Gets the default branch using git.", + {}, + async () => { + return await git.defaultBranch() + } +) + defTool( "git_branch_current", "Gets the current branch using git.", @@ -860,7 +875,8 @@ defTool( ...rest, }) return res - } + }, + { maxTokens: 20000 } ) defTool( @@ -918,6 +934,27 @@ defTool("git_last_tag", "Gets the last tag using git.", {}, async () => { ````` +### `system.git_info` + +Git repository information + + + + + +`````js wrap title="system.git_info" +system({ + title: "Git repository information", +}) + +const branch = await git.branch() +const defaultBranch = await git.defaultBranch() + +$`git: The current branch is ${branch} and the default branch is ${defaultBranch}.` + +````` + + ### `system.github_actions` github workflows diff --git a/genaisrc/genaiscript.d.ts b/genaisrc/genaiscript.d.ts index a92f8a9285..734ac6a52f 100644 --- a/genaisrc/genaiscript.d.ts +++ b/genaisrc/genaiscript.d.ts @@ -88,6 +88,7 @@ type SystemPromptId = OptionsOrString< | "system.fs_find_files" | "system.fs_read_file" | "system.git" + | "system.git_info" | "system.github_actions" | "system.github_files" | "system.github_info" @@ -121,6 +122,7 @@ type SystemToolId = OptionsOrString< | "fs_find_files" | "fs_read_file" | "git_branch_current" + | "git_branch_default" | "git_branch_list" | "git_diff" | "git_last_tag" diff --git a/packages/auto/genaiscript.d.ts b/packages/auto/genaiscript.d.ts index a92f8a9285..734ac6a52f 100644 --- a/packages/auto/genaiscript.d.ts +++ b/packages/auto/genaiscript.d.ts @@ -88,6 +88,7 @@ type SystemPromptId = OptionsOrString< | "system.fs_find_files" | "system.fs_read_file" | "system.git" + | "system.git_info" | "system.github_actions" | "system.github_files" | "system.github_info" @@ -121,6 +122,7 @@ type SystemToolId = OptionsOrString< | "fs_find_files" | "fs_read_file" | "git_branch_current" + | "git_branch_default" | "git_branch_list" | "git_diff" | "git_last_tag" diff --git a/packages/core/src/genaisrc/genaiscript.d.ts b/packages/core/src/genaisrc/genaiscript.d.ts index a92f8a9285..734ac6a52f 100644 --- a/packages/core/src/genaisrc/genaiscript.d.ts +++ b/packages/core/src/genaisrc/genaiscript.d.ts @@ -88,6 +88,7 @@ type SystemPromptId = OptionsOrString< | "system.fs_find_files" | "system.fs_read_file" | "system.git" + | "system.git_info" | "system.github_actions" | "system.github_files" | "system.github_info" @@ -121,6 +122,7 @@ type SystemToolId = OptionsOrString< | "fs_find_files" | "fs_read_file" | "git_branch_current" + | "git_branch_default" | "git_branch_list" | "git_diff" | "git_last_tag" diff --git a/packages/core/src/genaisrc/system.agent_git.genai.mjs b/packages/core/src/genaisrc/system.agent_git.genai.mjs index d3d53161c0..4304e4703c 100644 --- a/packages/core/src/genaisrc/system.agent_git.genai.mjs +++ b/packages/core/src/genaisrc/system.agent_git.genai.mjs @@ -9,6 +9,8 @@ defAgent( "query a repository using Git to accomplish tasks. Provide all the context information available to execute git queries.", `Your are a helpfull LLM agent that can use the git tools to query the current repository. Answer the question in QUERY. - - The current repository is the same as github repository.`, - { model, system: ["system.github_info"], tools: ["git"] } + - The current repository is the same as github repository. + - Prefer using diff to compare files rather than listing files. Listing files is only useful when you need to read the content of the files. + `, + { model, system: ["system.git_info", "system.github_info"], tools: ["git"] } ) diff --git a/packages/core/src/genaisrc/system.fs_diff_files.genai.mjs b/packages/core/src/genaisrc/system.fs_diff_files.genai.mjs index b30fd2743e..e6bbbf78cd 100644 --- a/packages/core/src/genaisrc/system.fs_diff_files.genai.mjs +++ b/packages/core/src/genaisrc/system.fs_diff_files.genai.mjs @@ -28,5 +28,8 @@ defTool( const f = await workspace.readText(filename) const of = await workspace.readText(otherfilename) return parsers.diff(f, of) + }, + { + maxTokens: 20000, } ) diff --git a/packages/core/src/genaisrc/system.git.genai.mjs b/packages/core/src/genaisrc/system.git.genai.mjs index a92bf3c5cb..73e79e3f2d 100644 --- a/packages/core/src/genaisrc/system.git.genai.mjs +++ b/packages/core/src/genaisrc/system.git.genai.mjs @@ -3,6 +3,15 @@ system({ description: "Tools to query a git repository.", }) +defTool( + "git_branch_default", + "Gets the default branch using git.", + {}, + async () => { + return await git.defaultBranch() + } +) + defTool( "git_branch_current", "Gets the current branch using git.", @@ -64,7 +73,8 @@ defTool( ...rest, }) return res - } + }, + { maxTokens: 20000 } ) defTool( diff --git a/packages/core/src/genaisrc/system.git_info.genai.mjs b/packages/core/src/genaisrc/system.git_info.genai.mjs new file mode 100644 index 0000000000..9c53d8aa4b --- /dev/null +++ b/packages/core/src/genaisrc/system.git_info.genai.mjs @@ -0,0 +1,8 @@ +system({ + title: "Git repository information", +}) + +const branch = await git.branch() +const defaultBranch = await git.defaultBranch() + +$`git: The current branch is ${branch} and the default branch is ${defaultBranch}.` diff --git a/packages/sample/genaisrc/blog/genaiscript.d.ts b/packages/sample/genaisrc/blog/genaiscript.d.ts index a92f8a9285..734ac6a52f 100644 --- a/packages/sample/genaisrc/blog/genaiscript.d.ts +++ b/packages/sample/genaisrc/blog/genaiscript.d.ts @@ -88,6 +88,7 @@ type SystemPromptId = OptionsOrString< | "system.fs_find_files" | "system.fs_read_file" | "system.git" + | "system.git_info" | "system.github_actions" | "system.github_files" | "system.github_info" @@ -121,6 +122,7 @@ type SystemToolId = OptionsOrString< | "fs_find_files" | "fs_read_file" | "git_branch_current" + | "git_branch_default" | "git_branch_list" | "git_diff" | "git_last_tag" diff --git a/packages/sample/genaisrc/genaiscript.d.ts b/packages/sample/genaisrc/genaiscript.d.ts index a92f8a9285..734ac6a52f 100644 --- a/packages/sample/genaisrc/genaiscript.d.ts +++ b/packages/sample/genaisrc/genaiscript.d.ts @@ -88,6 +88,7 @@ type SystemPromptId = OptionsOrString< | "system.fs_find_files" | "system.fs_read_file" | "system.git" + | "system.git_info" | "system.github_actions" | "system.github_files" | "system.github_info" @@ -121,6 +122,7 @@ type SystemToolId = OptionsOrString< | "fs_find_files" | "fs_read_file" | "git_branch_current" + | "git_branch_default" | "git_branch_list" | "git_diff" | "git_last_tag" diff --git a/packages/sample/genaisrc/node/genaiscript.d.ts b/packages/sample/genaisrc/node/genaiscript.d.ts index a92f8a9285..734ac6a52f 100644 --- a/packages/sample/genaisrc/node/genaiscript.d.ts +++ b/packages/sample/genaisrc/node/genaiscript.d.ts @@ -88,6 +88,7 @@ type SystemPromptId = OptionsOrString< | "system.fs_find_files" | "system.fs_read_file" | "system.git" + | "system.git_info" | "system.github_actions" | "system.github_files" | "system.github_info" @@ -121,6 +122,7 @@ type SystemToolId = OptionsOrString< | "fs_find_files" | "fs_read_file" | "git_branch_current" + | "git_branch_default" | "git_branch_list" | "git_diff" | "git_last_tag" diff --git a/packages/sample/genaisrc/prd-agent.genai.mts b/packages/sample/genaisrc/prd-agent.genai.mts index 18c51ea2bf..78f4c7e1e3 100644 --- a/packages/sample/genaisrc/prd-agent.genai.mts +++ b/packages/sample/genaisrc/prd-agent.genai.mts @@ -1,7 +1,7 @@ script({ title: "Pull Request Descriptor - Agent", description: "Generate a pull request description from the git diff", - tools: ["agent-ts", "agent-diff"], + tools: ["fs", "git_diff", "git_branch_current", "git_branch_default"], temperature: 0.5, }) @@ -9,14 +9,17 @@ $`You are an expert software developer and architect. ## Task -Describe a high level summary of the code changes in the current branch with a default branch in a way that a software engineer will understand. -This description will be used as the pull request description. +1. Compute the code different between the current branch and the default branch in this repository. +2. Describe a high level summary of the code changes. ## Instructions +- This description will be used as the pull request description. +- talk like a software engineer - try to extract the intent of the changes, don't focus on the details - use bullet points to list the changes - use emojis to make the description more engaging - focus on the most important changes - ignore comments about imports (like added, remove, changed, etc.) +- do NOT add a "pull request description" header ` diff --git a/packages/sample/genaisrc/prd-tools.genai.mts b/packages/sample/genaisrc/prd-tools.genai.mts new file mode 100644 index 0000000000..397b9c4e14 --- /dev/null +++ b/packages/sample/genaisrc/prd-tools.genai.mts @@ -0,0 +1,25 @@ +script({ + title: "Pull Request Descriptor - Agent", + description: "Generate a pull request description from the git diff", + tools: ["fs", "git_diff", "git_branch_current", "git_branch_default"], + temperature: 0.5, +}) + +$`You are an expert software developer and architect. + +## Task + +1. Compute the code different between the current branch and the default branch in this repository. +2. Describe a high level summary of the code changes. + +## Instructions + +- if the diff is too large, diff each file separately +- This description will be used as the pull request description. +- talk like a software engineer +- try to extract the intent of the changes, don't focus on the details +- use bullet points to list the changes +- use emojis to make the description more engaging +- focus on the most important changes +- ignore comments about imports (like added, remove, changed, etc.) +` diff --git a/packages/sample/genaisrc/python/genaiscript.d.ts b/packages/sample/genaisrc/python/genaiscript.d.ts index a92f8a9285..734ac6a52f 100644 --- a/packages/sample/genaisrc/python/genaiscript.d.ts +++ b/packages/sample/genaisrc/python/genaiscript.d.ts @@ -88,6 +88,7 @@ type SystemPromptId = OptionsOrString< | "system.fs_find_files" | "system.fs_read_file" | "system.git" + | "system.git_info" | "system.github_actions" | "system.github_files" | "system.github_info" @@ -121,6 +122,7 @@ type SystemToolId = OptionsOrString< | "fs_find_files" | "fs_read_file" | "git_branch_current" + | "git_branch_default" | "git_branch_list" | "git_diff" | "git_last_tag" diff --git a/packages/sample/genaisrc/style/genaiscript.d.ts b/packages/sample/genaisrc/style/genaiscript.d.ts index a92f8a9285..734ac6a52f 100644 --- a/packages/sample/genaisrc/style/genaiscript.d.ts +++ b/packages/sample/genaisrc/style/genaiscript.d.ts @@ -88,6 +88,7 @@ type SystemPromptId = OptionsOrString< | "system.fs_find_files" | "system.fs_read_file" | "system.git" + | "system.git_info" | "system.github_actions" | "system.github_files" | "system.github_info" @@ -121,6 +122,7 @@ type SystemToolId = OptionsOrString< | "fs_find_files" | "fs_read_file" | "git_branch_current" + | "git_branch_default" | "git_branch_list" | "git_diff" | "git_last_tag" diff --git a/packages/sample/src/aici/genaiscript.d.ts b/packages/sample/src/aici/genaiscript.d.ts index a92f8a9285..734ac6a52f 100644 --- a/packages/sample/src/aici/genaiscript.d.ts +++ b/packages/sample/src/aici/genaiscript.d.ts @@ -88,6 +88,7 @@ type SystemPromptId = OptionsOrString< | "system.fs_find_files" | "system.fs_read_file" | "system.git" + | "system.git_info" | "system.github_actions" | "system.github_files" | "system.github_info" @@ -121,6 +122,7 @@ type SystemToolId = OptionsOrString< | "fs_find_files" | "fs_read_file" | "git_branch_current" + | "git_branch_default" | "git_branch_list" | "git_diff" | "git_last_tag" diff --git a/packages/sample/src/errors/genaiscript.d.ts b/packages/sample/src/errors/genaiscript.d.ts index a92f8a9285..734ac6a52f 100644 --- a/packages/sample/src/errors/genaiscript.d.ts +++ b/packages/sample/src/errors/genaiscript.d.ts @@ -88,6 +88,7 @@ type SystemPromptId = OptionsOrString< | "system.fs_find_files" | "system.fs_read_file" | "system.git" + | "system.git_info" | "system.github_actions" | "system.github_files" | "system.github_info" @@ -121,6 +122,7 @@ type SystemToolId = OptionsOrString< | "fs_find_files" | "fs_read_file" | "git_branch_current" + | "git_branch_default" | "git_branch_list" | "git_diff" | "git_last_tag" diff --git a/packages/sample/src/genaiscript.d.ts b/packages/sample/src/genaiscript.d.ts index a92f8a9285..734ac6a52f 100644 --- a/packages/sample/src/genaiscript.d.ts +++ b/packages/sample/src/genaiscript.d.ts @@ -88,6 +88,7 @@ type SystemPromptId = OptionsOrString< | "system.fs_find_files" | "system.fs_read_file" | "system.git" + | "system.git_info" | "system.github_actions" | "system.github_files" | "system.github_info" @@ -121,6 +122,7 @@ type SystemToolId = OptionsOrString< | "fs_find_files" | "fs_read_file" | "git_branch_current" + | "git_branch_default" | "git_branch_list" | "git_diff" | "git_last_tag" diff --git a/packages/sample/src/makecode/genaiscript.d.ts b/packages/sample/src/makecode/genaiscript.d.ts index a92f8a9285..734ac6a52f 100644 --- a/packages/sample/src/makecode/genaiscript.d.ts +++ b/packages/sample/src/makecode/genaiscript.d.ts @@ -88,6 +88,7 @@ type SystemPromptId = OptionsOrString< | "system.fs_find_files" | "system.fs_read_file" | "system.git" + | "system.git_info" | "system.github_actions" | "system.github_files" | "system.github_info" @@ -121,6 +122,7 @@ type SystemToolId = OptionsOrString< | "fs_find_files" | "fs_read_file" | "git_branch_current" + | "git_branch_default" | "git_branch_list" | "git_diff" | "git_last_tag" diff --git a/packages/sample/src/tla/genaiscript.d.ts b/packages/sample/src/tla/genaiscript.d.ts index a92f8a9285..734ac6a52f 100644 --- a/packages/sample/src/tla/genaiscript.d.ts +++ b/packages/sample/src/tla/genaiscript.d.ts @@ -88,6 +88,7 @@ type SystemPromptId = OptionsOrString< | "system.fs_find_files" | "system.fs_read_file" | "system.git" + | "system.git_info" | "system.github_actions" | "system.github_files" | "system.github_info" @@ -121,6 +122,7 @@ type SystemToolId = OptionsOrString< | "fs_find_files" | "fs_read_file" | "git_branch_current" + | "git_branch_default" | "git_branch_list" | "git_diff" | "git_last_tag" diff --git a/packages/sample/src/vision/genaiscript.d.ts b/packages/sample/src/vision/genaiscript.d.ts index a92f8a9285..734ac6a52f 100644 --- a/packages/sample/src/vision/genaiscript.d.ts +++ b/packages/sample/src/vision/genaiscript.d.ts @@ -88,6 +88,7 @@ type SystemPromptId = OptionsOrString< | "system.fs_find_files" | "system.fs_read_file" | "system.git" + | "system.git_info" | "system.github_actions" | "system.github_files" | "system.github_info" @@ -121,6 +122,7 @@ type SystemToolId = OptionsOrString< | "fs_find_files" | "fs_read_file" | "git_branch_current" + | "git_branch_default" | "git_branch_list" | "git_diff" | "git_last_tag" diff --git a/packages/vscode/genaisrc/genaiscript.d.ts b/packages/vscode/genaisrc/genaiscript.d.ts index a92f8a9285..734ac6a52f 100644 --- a/packages/vscode/genaisrc/genaiscript.d.ts +++ b/packages/vscode/genaisrc/genaiscript.d.ts @@ -88,6 +88,7 @@ type SystemPromptId = OptionsOrString< | "system.fs_find_files" | "system.fs_read_file" | "system.git" + | "system.git_info" | "system.github_actions" | "system.github_files" | "system.github_info" @@ -121,6 +122,7 @@ type SystemToolId = OptionsOrString< | "fs_find_files" | "fs_read_file" | "git_branch_current" + | "git_branch_default" | "git_branch_list" | "git_diff" | "git_last_tag" diff --git a/slides/genaisrc/genaiscript.d.ts b/slides/genaisrc/genaiscript.d.ts index a92f8a9285..734ac6a52f 100644 --- a/slides/genaisrc/genaiscript.d.ts +++ b/slides/genaisrc/genaiscript.d.ts @@ -88,6 +88,7 @@ type SystemPromptId = OptionsOrString< | "system.fs_find_files" | "system.fs_read_file" | "system.git" + | "system.git_info" | "system.github_actions" | "system.github_files" | "system.github_info" @@ -121,6 +122,7 @@ type SystemToolId = OptionsOrString< | "fs_find_files" | "fs_read_file" | "git_branch_current" + | "git_branch_default" | "git_branch_list" | "git_diff" | "git_last_tag"