-
Notifications
You must be signed in to change notification settings - Fork 217
Adding a basic linter #1482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Adding a basic linter #1482
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
10d9b3a
adding base script
pelikhan 6ad44e5
add error message
pelikhan 43ea1a5
✨ feat: update git diff base to HEAD^
pelikhan f210759
✨: Enhance git diff configuration for linters
pelikhan 9f45b62
✨ feat: enhance linter script with base parameter support
pelikhan 1350f5f
:truck: Rename and enhance workflows and linter paths
pelikhan 7b465f2
Merge remote-tracking branch 'origin/dev' into linter-script
pelikhan e2e4684
✨ feat: Enhance linting with git diff and tool support
pelikhan 343bc18
✨: Improve AI evaluation prompt clarity
pelikhan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Make sure the code is well-commented and easy to understand. Use comments to explain complex logic, provide context, and clarify the purpose of functions and classes. Avoid redundant comments that restate the code. Use docstrings for public methods and classes to describe their purpose, parameters, and return values. | ||
| Use inline comments sparingly and only when necessary. Comments should be in English and follow proper grammar and punctuation rules. Use consistent formatting for comments throughout the codebase. | ||
| Avoid using comments to disable code or leave TODOs. Instead, use version control systems to track changes and create issues for tasks that need to be addressed later. If you need to leave a comment, make sure it is clear and actionable. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| name: genai linters | ||
| on: | ||
| workflow_dispatch: | ||
| pull_request: | ||
| types: [opened, ready_for_review, reopened] | ||
| paths: | ||
| - yarn.lock | ||
| - "packages/core/**/*" | ||
| - "packages/cli/**/*" | ||
| - "packages/samples/**/*" | ||
| concurrency: | ||
| group: linters-${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
| env: | ||
| GENAISCRIPT_DEFAULT_REASONING_MODEL: ${{ vars.GENAISCRIPT_DEFAULT_REASONING_MODEL }} | ||
| GENAISCRIPT_DEFAULT_REASONING_SMALL_MODEL: ${{ vars.GENAISCRIPT_DEFAULT_REASONING_SMALL_MODEL }} | ||
| GENAISCRIPT_DEFAULT_MODEL: ${{ vars.GENAISCRIPT_DEFAULT_MODEL }} | ||
| GENAISCRIPT_DEFAULT_SMALL_MODEL: ${{ vars.GENAISCRIPT_DEFAULT_SMALL_MODEL }} | ||
| GENAISCRIPT_DEFAULT_VISION_MODEL: ${{ vars.GENAISCRIPT_DEFAULT_VISION_MODEL }} | ||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| pull-requests: write | ||
| models: read | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| submodules: "recursive" | ||
| fetch-depth: 10 | ||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: "20" | ||
| cache: yarn | ||
| - run: yarn install --frozen-lockfile | ||
| - name: compile | ||
| run: yarn compile | ||
| - name: git stuff | ||
| run: git fetch origin && git pull origin dev:dev | ||
| - name: genaiscript | ||
| run: node packages/cli/built/genaiscript.cjs run linters --out ./temp/genai/linters -prc -m reasoning --out-trace $GITHUB_STEP_SUMMARY --vars defaultBranch=dev | ||
pelikhan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| continue-on-error: true | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| GITHUB_COMMIT_SHA: ${{ github.event.pull_request.base.sha}} | ||
| - name: Archive genai results | ||
| if: always() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: genai-results | ||
pelikhan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| path: ./temp/genai/** | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| script({ | ||
| title: "Linters", | ||
| systemSafety: false, | ||
| system: ["system", "system.assistant", "system.annotations"], | ||
| responseType: "text", | ||
| tools: ["agent_fs", "agent_git"], | ||
| parameters: { | ||
| base: { | ||
| type: "string", | ||
| description: "The base commit to compare against.", | ||
| default: "HEAD^", | ||
| }, | ||
| }, | ||
| }) | ||
|
|
||
| const base = env.vars.base || (await git.defaultBranch()) | ||
| const changes = await git.diff({ | ||
| base, | ||
| ignoreSpaceChange: true, | ||
| }) | ||
| def("GIT_DIFF", changes, { | ||
| maxTokens: 14000, | ||
| detectPromptInjection: "available", | ||
| }) | ||
|
|
||
| const { vars, dbg, output } = env | ||
pelikhan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const linters = await workspace.findFiles(".github/linters/*.md") | ||
| if (!linters) cancel("no linters found in .github/linters/*.md") | ||
| dbg(`found %d linters`, linters.length) | ||
|
|
||
| const diff = await git.diff({ | ||
| base, | ||
| llmify: true, | ||
| ignoreSpaceChange: true, | ||
| }) | ||
| if (!diff) cancel("nothing changed") | ||
| def("DIFF", diff, { language: "diff", maxTokens: 7000 }) | ||
| dbg(diff) | ||
|
|
||
| $`You are an expert in code linting. | ||
|
|
||
| You will be provided a list of linters and you will apply them | ||
| to the code in the <DIFF> variable using the strategy below. | ||
|
|
||
| ## Strategy | ||
|
|
||
| for each linter: | ||
| read the linter description | ||
| apply the linter to the code in <DIFF> | ||
| report any errors or warnings using annotations format. Use the linter name as the code. | ||
|
|
||
| ## Linters | ||
|
|
||
| `.role("system") | ||
| for (const linter of linters) { | ||
| const name = path.basename(linter.filename) | ||
| const content = MD.content(linter) | ||
pelikhan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| $`### ${name}`.role("system") | ||
| writeText(content, { role: "system" }) | ||
| } | ||
|
|
||
| $`## Output | ||
| You will output the results of the linting process using the annotation format. | ||
| `.role("system") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 'git fetch origin && git pull origin dev:dev' command can be non-obvious; please add a comment explaining its purpose.