From 48be6235c08fb945ebee51b12103fcc8062b7e91 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Fri, 20 Sep 2024 19:01:14 +0000 Subject: [PATCH] helper scripts --- genaisrc/gcm.genai.mts | 1 - genaisrc/rv.genai.mts | 60 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 genaisrc/rv.genai.mts diff --git a/genaisrc/gcm.genai.mts b/genaisrc/gcm.genai.mts index 5631b4fb5..e1ebd1197 100644 --- a/genaisrc/gcm.genai.mts +++ b/genaisrc/gcm.genai.mts @@ -4,7 +4,6 @@ script({ title: "git commit message", description: "Generate a commit message for all staged changes", - model: "openai:gpt-4o", }) // TODO: update this diff command to match your workspace diff --git a/genaisrc/rv.genai.mts b/genaisrc/rv.genai.mts new file mode 100644 index 000000000..40b660a8a --- /dev/null +++ b/genaisrc/rv.genai.mts @@ -0,0 +1,60 @@ +script({ + title: "Reviewer", + description: "Review the current files", + system: ["system.annotations"], + tools: ["fs"], + cache: "rv", + parameters: { + errors: { + type: "boolean", + description: "Report errors only", + default: false, + }, + }, +}) + +/** ------------------------------------------------ + * Configuration + */ +const { errors } = env.vars + +/** ------------------------------------------------ + * Context + */ +let content = "" +/** + * env.files contains the file selected by the user in VSCode or through the cli arguments. + */ +if (env.files.length) { + content = def("FILE", env.files, { + maxTokens: 5000, + glob: "**/*.{py,ts,cs,rs,c,cpp,h,hpp,js,mjs,mts}", // TODO: + }) +} else { + // No files selected, review the current changes + console.log("No files found. Using git diff.") + const { stdout: diff } = await host.exec("git diff -U6") + // customize git diff to filter some files + if (!diff) cancel("No changes found, did you forget to stage your changes?") + content = def("GIT_DIFF", diff, { language: "diff" }) +} + +$` +## Role + +You are an expert developer at all known programming languages. +You are very helpful at reviewing code and providing constructive feedback. + +## Task + +Report ${errors ? `errors` : `errors and warnings`} in ${content} using the annotation format. + +## Guidance + +- Use best practices of the programming language of each file. +- If available, provide a URL to the official documentation for the best practice. do NOT invent URLs. +- Analyze ALL the code. Do not be lazy. This is IMPORTANT. +- Use tools to read the entire file content to get more context +${errors ? `- Do not report warnings, only errors.` : ``} +` +// TODO: customize with more rules