Repository navigation
feat: enforce contributor-quality checks for ECC skills #3030
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
Closed
+1,078
−0
Closed
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
2b072a0
feat: add skill quality validator
Rupam0710 8ed3e47
fix: resolve skill-quality validator review comments
Rupam0710 7ecef04
fix: tighten strict skill section validation
Rupam0710 346a28d
fix: resolve skill validator lint and strict checks
Rupam0710 bbc30bf
fix: address skill validator review feedback
Rupam0710 fdd769c
fix: replace unsupported end-of-input assertion
Rupam0710 11eb2c7
fix: finalize skill validator guardrails
Rupam0710 7cd34d9
fix: resolve final review comments
Rupam0710 f1f9173
fix: handle unreadable skill directories
Rupam0710 f277946
Merge branch 'main' into feat/skill-quality-validator
Rupam0710 e03e011
refactor: merge quality checks into validate-skills with rules-based …
Rupam0710 f71bddf
fix: resolve Greptile review feedback for skill-quality-validator
Rupam0710 bac0e47
fix: eliminate collection mutations in skill-quality-validator
Rupam0710 04036ae
fix: reduce credential detection minimum and eliminate collection mut…
Rupam0710 7c58b9c
fix: restore section boundary state in extractSectionBody to prevent …
Rupam0710 9378b64
test: add standalone validator regression coverage for untrusted CLI …
Rupam0710 f66454e
fix: unify skill quality validation rules
Rupam0710 b768cc7
Merge upstream/main into feat/skill-quality-validator
Rupam0710 412f898
fix: enforce skill quality checks on changed skills in CI
Rupam0710 75d9f79
fix: handle non-ASCII skill paths and push events in changed-skill qu…
Rupam0710 f8a71eb
fix: diff new-branch and force pushes against the default branch in s…
Rupam0710 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
Some comments aren't visible on the classic Files Changed page.
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
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,189 @@ | ||
| #!/usr/bin/env node | ||
| /** | ||
| * Validate the quality of curated skill files. | ||
| * | ||
| * Checks for the minimum structure and safety bar expected by ECC before a | ||
| * contribution is merged, without overblocking contributors during initial | ||
| * onboarding. | ||
| */ | ||
|
|
||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| const DEFAULT_SKILLS_DIR = path.join(__dirname, '../../skills'); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| const STRICT = process.argv.includes('--strict') || process.env.CI_STRICT_SKILLS === '1'; | ||
|
|
||
| const REQUIRED_SECTIONS = [ | ||
| 'When to Activate', | ||
| 'Core Concepts', | ||
| 'Examples', | ||
| 'Anti-Patterns', | ||
| 'Best Practices', | ||
| ]; | ||
|
|
||
| const SECRET_PATTERNS = [ | ||
| /(?:api[_-]?key|token|secret|passwd|password|access[_-]?key)[\s:=\"']+[A-Za-z0-9_\-]{8,}/i, | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| /sk_(?:live|test)_[A-Za-z0-9]+/i, | ||
| /ghp_[A-Za-z0-9]{20,}/i, | ||
| /xox[baprs]-[A-Za-z0-9-]+/i, | ||
| ]; | ||
|
|
||
| function logError(message) { | ||
| console.error(`ERROR: ${message}`); | ||
| } | ||
|
|
||
| function logWarning(message) { | ||
| console.warn(`WARN: ${message}`); | ||
| } | ||
|
|
||
| function readFileSafe(filePath) { | ||
| try { | ||
| return fs.readFileSync(filePath, 'utf8'); | ||
| } catch (error) { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| function parseFrontmatter(content) { | ||
| const cleaned = content.replace(/^\uFEFF/, ''); | ||
| const match = cleaned.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/); | ||
| if (!match) return null; | ||
|
|
||
| const body = match[1]; | ||
| const result = {}; | ||
| const lines = body.split(/\r?\n/); | ||
| for (const line of lines) { | ||
| const m = line.match(/^([A-Za-z0-9_-]+):\s*(.*)$/); | ||
| if (!m) continue; | ||
| const [, key, rawValue] = m; | ||
| const value = rawValue.trim().replace(/^['"]|['"]$/g, ''); | ||
| result[key] = value; | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| function findMissingSections(markdown) { | ||
| const missing = []; | ||
| for (const section of REQUIRED_SECTIONS) { | ||
| const heading = new RegExp(`^##?\\s*${section.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`, 'm'); | ||
| if (!heading.test(markdown)) { | ||
| missing.push(section); | ||
| } | ||
| } | ||
| return missing; | ||
| } | ||
|
greptile-apps[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| function scanSecrets(markdown) { | ||
| const matches = []; | ||
| for (const pattern of SECRET_PATTERNS) { | ||
| const result = markdown.match(pattern); | ||
| if (result) { | ||
| matches.push(result[0]); | ||
| } | ||
| } | ||
| return matches; | ||
| } | ||
|
|
||
| function getSkillFiles(rootDir) { | ||
| if (!fs.existsSync(rootDir)) return []; | ||
|
|
||
| const files = []; | ||
|
|
||
| function walk(currentDir) { | ||
| const entries = fs.readdirSync(currentDir, { withFileTypes: true }); | ||
|
greptile-apps[bot] marked this conversation as resolved.
Resolved
|
||
| for (const entry of entries) { | ||
| const fullPath = path.join(currentDir, entry.name); | ||
| if (entry.isDirectory()) { | ||
| walk(fullPath); | ||
| } else if (entry.isFile() && entry.name === 'SKILL.md') { | ||
| files.push(fullPath); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| walk(rootDir); | ||
| return files.sort(); | ||
| } | ||
|
|
||
| function validateSkillFile(skillFile) { | ||
| const relativePath = path.relative(process.cwd(), skillFile) || skillFile; | ||
| const contents = readFileSafe(skillFile); | ||
| if (!contents) { | ||
| logError(`${relativePath} could not be read`); | ||
| return false; | ||
| } | ||
|
|
||
| const frontmatter = parseFrontmatter(contents); | ||
| let ok = true; | ||
|
|
||
| if (!frontmatter) { | ||
| logError(`${relativePath} is missing YAML frontmatter`); | ||
| ok = false; | ||
| } else { | ||
| if (!frontmatter.name) { | ||
| logError(`${relativePath} is missing a name field`); | ||
| ok = false; | ||
| } | ||
| if (!frontmatter.description) { | ||
| logError(`${relativePath} is missing a description field`); | ||
| ok = false; | ||
| } | ||
|
|
||
| const dirName = path.basename(path.dirname(skillFile)); | ||
| if (frontmatter.name && frontmatter.name !== dirName) { | ||
| logError(`${relativePath} has name "${frontmatter.name}" but directory is "${dirName}"`); | ||
| ok = false; | ||
| } | ||
| } | ||
|
|
||
| const missingSections = findMissingSections(contents); | ||
| if (missingSections.length > 0) { | ||
| const missingText = missingSections.join(', '); | ||
| logError(`${relativePath} is missing required sections: ${missingText}`); | ||
| ok = false; | ||
| } | ||
|
|
||
| const badSecrets = scanSecrets(contents); | ||
| if (badSecrets.length > 0) { | ||
| logError(`${relativePath} contains secret-like patterns: ${badSecrets.slice(0, 3).join(', ')}`); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
greptile-apps[bot] marked this conversation as resolved.
Resolved
|
||
| ok = false; | ||
| } | ||
|
|
||
| const trimmed = contents.trim(); | ||
| if (trimmed.length < 200) { | ||
| const message = `${relativePath} is very short and may not provide enough guidance`; | ||
| if (STRICT) { | ||
| logError(message); | ||
| } else { | ||
| logWarning(message); | ||
| } | ||
| ok = ok && !STRICT; | ||
| } | ||
|
|
||
| return ok; | ||
| } | ||
|
|
||
| function main() { | ||
| const skillsDir = process.env.ECC_SKILLS_DIR || DEFAULT_SKILLS_DIR; | ||
| const files = getSkillFiles(skillsDir); | ||
|
|
||
| if (files.length === 0) { | ||
| console.log(`No skill files found under ${skillsDir}`); | ||
| process.exit(0); | ||
| } | ||
|
|
||
| let hasErrors = false; | ||
| for (const file of files) { | ||
| const isValid = validateSkillFile(file); | ||
| if (!isValid) hasErrors = true; | ||
| } | ||
|
|
||
| if (hasErrors) { | ||
| process.exit(1); | ||
| } | ||
|
|
||
| console.log(`Validated ${files.length} skill file(s) successfully.`); | ||
| } | ||
|
|
||
| main(); | ||
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,168 @@ | ||
| /** | ||
| * Tests for the skill quality validator. | ||
| */ | ||
|
|
||
| const assert = require('assert'); | ||
| const fs = require('fs'); | ||
| const os = require('os'); | ||
| const path = require('path'); | ||
| const { spawnSync } = require('child_process'); | ||
|
|
||
| const SCRIPT_PATH = path.join(__dirname, '..', '..', 'scripts', 'ci', 'validate-skill-quality.js'); | ||
|
|
||
| function runValidator(files, extraArgs = []) { | ||
| const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-skill-quality-')); | ||
| try { | ||
| for (const [name, contents] of Object.entries(files)) { | ||
| const filePath = path.join(tempDir, name); | ||
| fs.mkdirSync(path.dirname(filePath), { recursive: true }); | ||
| fs.writeFileSync(filePath, contents, 'utf8'); | ||
| } | ||
|
|
||
| const result = spawnSync('node', [SCRIPT_PATH, ...extraArgs], { | ||
| encoding: 'utf8', | ||
| env: { | ||
| ...process.env, | ||
| ECC_SKILLS_DIR: tempDir, | ||
| }, | ||
| }); | ||
|
|
||
| return { | ||
| status: result.status ?? 1, | ||
| stdout: result.stdout || '', | ||
| stderr: result.stderr || '', | ||
| }; | ||
| } finally { | ||
| fs.rmSync(tempDir, { recursive: true, force: true }); | ||
| } | ||
| } | ||
|
|
||
| function run() { | ||
| console.log('\n=== Testing skill quality validation ===\n'); | ||
|
|
||
| let passed = 0; | ||
| let failed = 0; | ||
|
|
||
| const check = (name, fn) => { | ||
| try { | ||
| fn(); | ||
| console.log(` ✓ ${name}`); | ||
| passed += 1; | ||
| } catch (error) { | ||
| console.log(` ✗ ${name}`); | ||
| console.log(` Error: ${error.message}`); | ||
| failed += 1; | ||
| } | ||
| }; | ||
|
|
||
| check('accepts a valid skill', () => { | ||
| const result = runValidator({ | ||
| 'skills/good-skill/SKILL.md': `--- | ||
| name: good-skill | ||
| description: Useful workflow for validating a good skill. | ||
| --- | ||
| # Good Skill | ||
|
|
||
| ## When to Activate | ||
| Use when you need a good example. | ||
|
|
||
| ## Core Concepts | ||
| Keep it practical. | ||
|
|
||
| ## Examples | ||
| \`\`\`bash | ||
| node scripts/validate-skill-quality.js | ||
| \`\`\` | ||
|
|
||
| ## Anti-Patterns | ||
| Avoid generic advice. | ||
|
|
||
| ## Best Practices | ||
| - Keep it concrete. | ||
| `, | ||
| }); | ||
| assert.strictEqual(result.status, 0, `${result.stderr || result.stdout}`); | ||
| }); | ||
|
|
||
| check('reports missing activation section', () => { | ||
| const result = runValidator({ | ||
| 'skills/weak-skill/SKILL.md': `--- | ||
| name: weak-skill | ||
| description: A weak skill. | ||
| --- | ||
| # Weak Skill | ||
|
|
||
| ## Core Concepts | ||
| No activation section. | ||
|
|
||
| ## Examples | ||
| Example only. | ||
| `, | ||
| }); | ||
| assert.notStrictEqual(result.status, 0, 'Expected validator to fail'); | ||
| assert.match(result.stderr || result.stdout, /When to Activate/i); | ||
| }); | ||
|
|
||
| check('rejects hardcoded secrets in examples', () => { | ||
| const result = runValidator({ | ||
| 'skills/secret-skill/SKILL.md': `--- | ||
| name: secret-skill | ||
| description: Demo skill. | ||
| --- | ||
| # Secret Skill | ||
|
|
||
| ## When to Activate | ||
| Use when you need a secret example. | ||
|
|
||
| ## Core Concepts | ||
| Check for credentials. | ||
|
|
||
| ## Examples | ||
| \`\`\`bash | ||
| export API_KEY=sk_live_1234567890 | ||
| \`\`\` | ||
|
|
||
| ## Anti-Patterns | ||
| Avoid leaked variables. | ||
|
|
||
| ## Best Practices | ||
| - Avoid secrets. | ||
| `, | ||
| }); | ||
| assert.notStrictEqual(result.status, 0, 'Expected validator to fail'); | ||
| assert.match(result.stderr || result.stdout, /secret|token|API_KEY/i); | ||
| }); | ||
|
|
||
| check('supports --strict mode for missing anti-patterns', () => { | ||
| const result = runValidator({ | ||
| 'skills/no-anti-patterns/SKILL.md': `--- | ||
| name: no-anti-patterns | ||
| description: A basic skill. | ||
| --- | ||
| # No Anti-Patterns | ||
|
|
||
| ## When to Activate | ||
| Use when the task is simple. | ||
|
|
||
| ## Core Concepts | ||
| Keep it simple. | ||
|
|
||
| ## Examples | ||
| \`\`\`bash | ||
| echo hello | ||
| \`\`\` | ||
|
|
||
| ## Best Practices | ||
| - Keep it simple. | ||
| `, | ||
| }, ['--strict']); | ||
| assert.notStrictEqual(result.status, 0, 'Expected strict mode to fail'); | ||
| assert.match(result.stderr || result.stdout, /Anti-Patterns/i); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| }); | ||
|
|
||
| console.log(`\nPassed: ${passed}`); | ||
| console.log(`Failed: ${failed}`); | ||
| process.exit(failed > 0 ? 1 : 0); | ||
| } | ||
|
|
||
| run(); | ||
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.