b7d7ae9774
- biome.json: 2-space indent, single quotes, recommended rules - All 30 source files formatted (auto-fix, no logic changes) - CI: Biome lint runs before type check and tests - Root package.json with lint/lint:fix scripts 89 unit tests green (82 core + 7 watcher). 小橘 🍊(NEKO Team) Co-authored-by: 小橘 <xiaoju@shazhou.work>
71 lines
2.2 KiB
TypeScript
71 lines
2.2 KiB
TypeScript
/**
|
|
* commands/list.ts — upulse list (show current rule chain)
|
|
*/
|
|
|
|
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
import type { Command } from 'commander';
|
|
import { loadConfig, resolveDir } from '../config.js';
|
|
|
|
export function registerListCommand(program: Command): void {
|
|
program
|
|
.command('list')
|
|
.description('Show current rule chain (from engine)')
|
|
.action(() => {
|
|
const config = loadConfig(resolveDir(program.opts().dir));
|
|
const rulesDir = join(config.engine.path, 'rules');
|
|
|
|
if (!existsSync(rulesDir)) {
|
|
console.error('Error: rules/ directory not found in engine.');
|
|
process.exit(1);
|
|
}
|
|
|
|
// List rule files sorted by name (number prefix = order)
|
|
const files = readdirSync(rulesDir)
|
|
.filter((f) => f.endsWith('.ts'))
|
|
.sort();
|
|
|
|
if (files.length === 0) {
|
|
console.log('No rules found.');
|
|
return;
|
|
}
|
|
|
|
console.log('Rule chain:');
|
|
console.log('');
|
|
|
|
for (let i = 0; i < files.length; i++) {
|
|
const file = files[i];
|
|
const filePath = join(rulesDir, file);
|
|
|
|
// Try to extract a description from comments
|
|
const content = readFileSync(filePath, 'utf-8');
|
|
const commentMatch = content.match(/\/\/\s*(.+)/);
|
|
const desc = commentMatch ? commentMatch[1].trim() : '(no description)';
|
|
|
|
console.log(` ${i + 1}. ${file}`);
|
|
console.log(` ${desc}`);
|
|
}
|
|
|
|
// Also check pulse.config.ts for inline rules
|
|
const configFile = join(config.engine.path, 'pulse.config.ts');
|
|
if (existsSync(configFile)) {
|
|
const configContent = readFileSync(configFile, 'utf-8');
|
|
const rulesMatch = configContent.match(
|
|
/const rules\s*=\s*\[([\s\S]*?)\]/,
|
|
);
|
|
if (rulesMatch) {
|
|
console.log(`\n Inline rules in pulse.config.ts:`);
|
|
const inlineRules = rulesMatch[1]
|
|
.split('\n')
|
|
.map((l) => l.trim())
|
|
.filter((l) => l && !l.startsWith('//') && !l.startsWith(']'));
|
|
for (const rule of inlineRules) {
|
|
console.log(` ${rule.replace(/,\s*$/, '')}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
console.log(`\n Total: ${files.length} rule file(s)`);
|
|
});
|
|
}
|