mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-02-15 10:53:18 +08:00
Bug fixes: - utils.js: prevent duplicate 'g' flag in countInFile regex construction - validate-agents.js: handle CRLF line endings in frontmatter parsing - validate-hooks.js: handle \t and \\ escape sequences in inline JS validation - session-aliases.js: prevent NaN in date sort when timestamps are missing - session-aliases.js: persist rollback on rename failure instead of silent loss - session-manager.js: require absolute paths in getSessionStats to prevent content strings ending with .tmp from being treated as file paths New tests (164 total, up from 97): - session-manager.test.js: 27 tests covering parseSessionFilename, parseSessionMetadata, getSessionStats, CRUD operations, getSessionSize, getSessionTitle, edge cases (null input, non-existent files, directories) - session-aliases.test.js: 40 tests covering loadAliases (corrupted JSON, invalid structure), setAlias (validation, reserved names), resolveAlias, listAliases (sort, search, limit), deleteAlias, renameAlias, updateAliasTitle, resolveSessionAlias, getAliasesForSession, cleanupAliases, atomic write Also includes hook-generated improvements: - utils.d.ts: document that readStdinJson never rejects - session-aliases.d.ts: fix updateAliasTitle type to accept null - package-manager.js: add try-catch to setProjectPackageManager writeFile
75 lines
1.9 KiB
JavaScript
75 lines
1.9 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Validate agent markdown files have required frontmatter
|
|
*/
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const AGENTS_DIR = path.join(__dirname, '../../agents');
|
|
const REQUIRED_FIELDS = ['model', 'tools'];
|
|
|
|
function extractFrontmatter(content) {
|
|
// Strip BOM if present (UTF-8 BOM: \uFEFF)
|
|
const cleanContent = content.replace(/^\uFEFF/, '');
|
|
// Support both LF and CRLF line endings
|
|
const match = cleanContent.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
if (!match) return null;
|
|
|
|
const frontmatter = {};
|
|
const lines = match[1].split(/\r?\n/);
|
|
for (const line of lines) {
|
|
const colonIdx = line.indexOf(':');
|
|
if (colonIdx > 0) {
|
|
const key = line.slice(0, colonIdx).trim();
|
|
const value = line.slice(colonIdx + 1).trim();
|
|
frontmatter[key] = value;
|
|
}
|
|
}
|
|
return frontmatter;
|
|
}
|
|
|
|
function validateAgents() {
|
|
if (!fs.existsSync(AGENTS_DIR)) {
|
|
console.log('No agents directory found, skipping validation');
|
|
process.exit(0);
|
|
}
|
|
|
|
const files = fs.readdirSync(AGENTS_DIR).filter(f => f.endsWith('.md'));
|
|
let hasErrors = false;
|
|
|
|
for (const file of files) {
|
|
const filePath = path.join(AGENTS_DIR, file);
|
|
let content;
|
|
try {
|
|
content = fs.readFileSync(filePath, 'utf-8');
|
|
} catch (err) {
|
|
console.error(`ERROR: ${file} - ${err.message}`);
|
|
hasErrors = true;
|
|
continue;
|
|
}
|
|
const frontmatter = extractFrontmatter(content);
|
|
|
|
if (!frontmatter) {
|
|
console.error(`ERROR: ${file} - Missing frontmatter`);
|
|
hasErrors = true;
|
|
continue;
|
|
}
|
|
|
|
for (const field of REQUIRED_FIELDS) {
|
|
if (!frontmatter[field]) {
|
|
console.error(`ERROR: ${file} - Missing required field: ${field}`);
|
|
hasErrors = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (hasErrors) {
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log(`Validated ${files.length} agent files`);
|
|
}
|
|
|
|
validateAgents();
|