-
Notifications
You must be signed in to change notification settings - Fork 0
Gate agent-skills length on tokens rather than lines #448
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
Changes from all commits
Commits
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,30 @@ | ||
| --- | ||
| '@gtbuchanan/eslint-plugin-agent-skills': major | ||
| --- | ||
|
|
||
| Gate skill length on tokens rather than lines | ||
|
|
||
| `configs.recommended` now caps both `SKILL.md` and | ||
| `**/skills/*/references/**/*.md` with `agent-skills/max-tokens` at 5000, | ||
| and applies `agent-skills/max-lines` to neither. The rule still ships, so | ||
| a repo wanting the spec's 500-line figure can wire it explicitly: | ||
|
|
||
| ```js | ||
| { | ||
| files: ['**/skills/*/SKILL.md'], | ||
| rules: { 'agent-skills/max-lines': ['warn', { max: 500 }] }, | ||
| } | ||
| ``` | ||
|
|
||
| Both rules proxy for how much context a skill costs to load, and tokens | ||
| measure it directly. At the ~10-14 tokens per line typical of prose | ||
| skills, 500 lines works out to 5200-7000 tokens, so the token cap is the | ||
| one that fires. The line cap leads only below ~10 tokens per line, where | ||
| it reports formatting — semantic line breaks and dense lists raise a line | ||
| count without changing what the agent loads. | ||
|
|
||
| The 300-line cap on `references/` had no upstream basis: the spec's third | ||
| tier is "Resources (as needed)" and `skill-creator` calls bundled | ||
| resources "unlimited, loaded as needed". The 5000 there is a backstop for | ||
| a reference file costing more to load than the instructions tier it was | ||
| split out of. |
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
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
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
99 changes: 99 additions & 0 deletions
99
packages/eslint-plugin-agent-skills/test/max-lines.test.ts
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,99 @@ | ||
| import { RuleTester } from 'eslint'; | ||
| import { describe, it } from 'vitest'; | ||
| import { maxLines } from '#src/rules/max-lines.js'; | ||
| import * as parser from './parser.js'; | ||
|
|
||
| const ruleTester = new RuleTester({ | ||
| languageOptions: { parser }, | ||
| }); | ||
|
|
||
| const filename = '/repo/skills/my-skill/SKILL.md'; | ||
|
|
||
| /* Numbered so a miscount shows up as the wrong number in the message | ||
| rather than as an off-by-one nobody can see. */ | ||
| const body = (lineCount: number): string => Array | ||
| .from({ length: lineCount }, (_unused, index) => `Line ${(index + 1).toString()}.`) | ||
| .join('\n'); | ||
|
|
||
| describe.concurrent('agent-skills/max-lines', () => { | ||
| it('passes when the file is at the limit', ({ expect }) => { | ||
| expect(() => { | ||
| ruleTester.run('agent-skills/max-lines', maxLines, { | ||
| invalid: [], | ||
| valid: [{ code: body(500), filename }], | ||
| }); | ||
| }).not.toThrow(); | ||
| }); | ||
|
|
||
| it('flags when the file exceeds the limit', ({ expect }) => { | ||
| expect(() => { | ||
| ruleTester.run('agent-skills/max-lines', maxLines, { | ||
| invalid: [ | ||
| { | ||
| code: body(501), | ||
| errors: [{ message: /501.*Maximum allowed is 500/v }], | ||
| filename, | ||
| }, | ||
| ], | ||
| valid: [], | ||
| }); | ||
| }).not.toThrow(); | ||
| }); | ||
|
|
||
| it('honors an explicit max option', ({ expect }) => { | ||
| expect(() => { | ||
| ruleTester.run('agent-skills/max-lines', maxLines, { | ||
| invalid: [ | ||
| { | ||
| code: body(11), | ||
| errors: [{ message: /11.*Maximum allowed is 10/v }], | ||
| filename, | ||
| options: [{ max: 10 }], | ||
| }, | ||
| ], | ||
| valid: [{ code: body(10), filename, options: [{ max: 10 }] }], | ||
| }); | ||
| }).not.toThrow(); | ||
| }); | ||
|
|
||
| /* Unlike core's `max-lines`, this rule takes the file's physical line | ||
| count — there is no `skipBlankLines`/`skipComments` equivalent, so | ||
| structural lines are counted like any other. */ | ||
| it('counts blank lines', ({ expect }) => { | ||
| expect(() => { | ||
| ruleTester.run('agent-skills/max-lines', maxLines, { | ||
| invalid: [ | ||
| { | ||
| code: '\n'.repeat(10), | ||
| errors: [{ message: /11.*Maximum allowed is 10/v }], | ||
| filename, | ||
| options: [{ max: 10 }], | ||
| }, | ||
| ], | ||
| valid: [], | ||
| }); | ||
| }).not.toThrow(); | ||
| }); | ||
|
|
||
| it('reports from the first line past the limit to end of file', ({ expect }) => { | ||
| expect(() => { | ||
| ruleTester.run('agent-skills/max-lines', maxLines, { | ||
| invalid: [ | ||
| { | ||
| code: 'a\nb\nc', | ||
| errors: [{ | ||
| column: 1, | ||
| endColumn: 2, | ||
| endLine: 3, | ||
| line: 3, | ||
| messageId: 'tooLong', | ||
| }], | ||
| filename, | ||
| options: [{ max: 2 }], | ||
| }, | ||
| ], | ||
| valid: [], | ||
| }); | ||
| }).not.toThrow(); | ||
| }); | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.