@lousy-agents /线头
用于AI代理技能、代理、钩子和指令文件的编程lint API。使用这个包可以在没有CLI的情况下,将低级代理的lint检查集成到您自己的工具、web应用程序或CI管道中。
有关基于cli的检测,请参见 lint 命令文件.
安装
npm install @lousy-agents/lint
快速入门
import { runLint } from '@lousy-agents/lint';
const result = await runLint({ directory: '/path/to/project' });
if (result.hasErrors) {
console.error('Lint failed');
for (const output of result.outputs) {
for (const diagnostic of output.diagnostics) {
console.error(`${diagnostic.filePath}:${diagnostic.line} [${diagnostic.severity}] ${diagnostic.message}`);
}
}
}
API
runLint(options): Promise<LintResult>
在项目目录上运行所有lint检查并返回结构化结果。
import { runLint, LintValidationError } from '@lousy-agents/lint';
try {
const result = await runLint({
directory: '/path/to/project',
targets: {
skills: true,
agents: true,
hooks: false, // skip hook linting
instructions: false, // skip instruction linting
},
});
console.log('Has errors:', result.hasErrors);
console.log('Outputs:', result.outputs.length);
} catch (error) {
if (error instanceof LintValidationError) {
console.error('Invalid input:', error.message);
} else {
throw error;
}
}
选项:
| 财产 | 类型 | 要求 | 描述 |
|---|---|---|---|
directory | string | ✅ | 要检测的项目目录的绝对或相对路径 |
targets.skills | boolean | - - - - - - | 绒线技能: .github/skills/*/SKILL.md, .claude/skills/*/SKILL.md, .agents/skills/*/SKILL.md, .pi/skills/*/SKILL.md, .pi/prompts/*/SKILL.md (技能列在根 skills-lock.json 省略了) |
targets.agents | boolean | - - - - - - | 棉绒剂前料在 .github/agents/**/*.md |
targets.subagents | boolean | - - - - - - | 仅标记(非GA) -把克劳德代码子代理的前体物塞进去 .claude/agents/**/*.md. 除非显式地运行,否则永远不会运行 true,即使在 targets 完全省略了 |
targets.hooks | boolean | - - - - - - | 绒钩配置: .github/hooks/agent-shell/hooks.json (副驾驶), .claude/settings.json 和 .claude/settings.local.json (Claude);只有当内容 preToolUse / PreToolUse;符号链接跳过 |
targets.instructions | boolean | - - - - - - | 棉绒指导质量: .github/copilot-instructions.md, .github/instructions/*.md, .github/agents/*.md (两用同剂),根 AGENTS.md、根 CLAUDE.md |
targets.mcpServers | boolean | - - - - - - | 仅标记(非GA) -验证MCP服务器配置文件: .mcp.json, .vscode/mcp.json. 除非显式地运行,否则永远不会运行 true,即使在 targets 完全省略了 |
logger | LintLogger | - - - - - - | 用于网关诊断的自定义记录器(必须具有 .warn 方法);默认为 consola |
当 targets 省略或所有标志都是 false, default-enabled 目标运行:技能,特工,诱饵,指令。 subagents 和 mcpServers 仅标记是分阶段推出的一部分吗 构建覆盖) -并且仅在显式设置为时运行 true,即使没有设置其他标志。
发现路径来自中的规范代理位置目录 @lousy-agents/core,与…分享 doctor. Doctor可能会列出其他尚未验证的构造(插件、多线束指令树等)。有意的差异: skills-lock.json 过滤(仅限lint),钩子 PreToolUse / preToolUse 内容启发式(仅限lint),仅适用于两者 .claude/settings*.json / .github/hooks/agent-shell/hooks.json 精确的路径(保留,而不是放松,对于这次推出),以及符号链接策略(lint跳过;医生遵循repo)。
抛出 LintValidationError 当 directory 为空、包含控制字符、路径遍历序列、不存在或不是目录。
createFormatter(format): LintFormatter
创建用于呈现的输出格式化程序 LintOutput[] 到一个字符串。
import { runLint, createFormatter } from '@lousy-agents/lint';
const result = await runLint({ directory: '/path/to/project' });
const formatter = createFormatter('human');
console.log(formatter.format(result.outputs));
| 格式 | 描述 |
|---|---|
'human' | 人类可读的文本,每行一个诊断 |
'json' | 所有诊断的JSON数组 |
'rdjsonl' | Reviewdog诊断格式 JSONL(每行一个JSON对象)——用于CI集成 |
DEFAULT_LINT_RULES
没有时使用的默认规则配置 lousy-agents.config.ts 是礼物。使用它来检查或扩展默认规则集。
import { DEFAULT_LINT_RULES } from '@lousy-agents/lint';
console.log(DEFAULT_LINT_RULES.skills);
// { 'skill/missing-name': 'error', 'skill/missing-description': 'error', ... }
LintValidationError
当用户提供的输入验证失败时抛出。捕获此错误以区分用户输入错误和系统错误。
import { runLint, LintValidationError } from '@lousy-agents/lint';
try {
await runLint({ directory: '' });
} catch (error) {
if (error instanceof LintValidationError) {
// directory was empty, missing, or not a directory
console.error(error.message);
}
}
类型
import type {
LintResult,
LintOutput,
LintDiagnostic,
LintSeverity,
LintTarget,
LintOptions,
LintLogger,
LintRulesConfig,
LintFormatType,
LintFormatter,
InstructionQualityResult,
} from '@lousy-agents/lint';
主要类型:
| 类型 | 描述 |
|---|---|
LintResult | 顶级的结果: outputs 阵列+ hasErrors 布尔 |
LintOutput | Per-target结果: diagnostics, filesAnalyzed, summary、可选 qualityResult |
LintDiagnostic | 单一的诊断: filePath, line, severity, message, ruleId, target |
LintSeverity | "error" | "warning" | "info" |
LintTarget | "skill" | "agent" | "subagent" | "instruction" | "hook" | "mcp-server" |
InstructionQualityResult | 教学质量分数和建议(填充时) instructions 目标运行) |
自定义日志记录器
传递任何带有 .warn 抑制或重定向网关诊断的方法:
import { runLint } from '@lousy-agents/lint';
import { createLogger } from 'your-logger';
const logger = createLogger('lint');
await runLint({
directory: '/path/to/project',
logger: { warn: (msg, ...args) => logger.warn(msg, ...args) },
});
CI集成(rdjsonl)
基于注释的CI反馈以Reviewdog诊断格式输出:
node -e "
const { runLint, createFormatter } = require('@lousy-agents/lint');
runLint({ directory: '.' }).then(r => {
process.stdout.write(createFormatter('rdjsonl').format(r.outputs));
process.exit(r.hasErrors ? 1 : 0);
});
"
相关的文档
lintCLI命令 -基于cli的检测npx @lousy-agents/cli lint- GitHub行动 -在GitHub Actions中运行linting而无需安装Node.js