harn-rules
БесплатноБез исполняемых скриптовНе проверенUse for authoring and running declarative structural rules — patterns, lint diagnostics, and codemods.
от burin-labs★ 34 звезды на GitHubОб этом скилле
Harn rule engine
Use this skill when matching or rewriting code structurally — a search pattern,
a lint rule, or a codemod — instead of with regex/glob. The engine is the
harn-rules crate; it is exposed to Harn as std/rules and to the CLI as
harn scan (read-only) and harn codemod (apply).
Pair it with harn-language for .harn syntax and harn-testing for
conformance fixtures.
Start here
crates/harn-rules/README.mdis the rule-model reference (matcher forms, relational/composite algebra,where/transform/fix, safety tiers).docs/src/cookbooks/rules-engine.mdis the worked-example cookbook (harn scan/harn codemod, authoring a rule).- A rule is TOML; an agent can author and run one entirely from
.harn(viastd/rules) without recompiling the binary.
A rule, end to end
- A rule has an identity (
id,language,severity,message), a[rule]matcher block, and an optionalfix. - Scalar fields come before
[rule]—[rule]opens a TOML table, so any later top-level scalar would bind to it. - The rule's kind is derived: a
fixmakes it a codemod; amessagewith nofixis a lint; a bare matcher is a search.
Matcher forms (the [rule] block)
pattern— a code snippet with$VARmetavariable holes (ast-grep style), compiled to a tree-sitter query. Operators/keywords match literally (??≠||); a repeated$VARunifies; a metavar-free pattern is a literal pattern (foo()matches calls tofoo, not any call). Matching is exact-shape: the target must have exactly the pattern's children and keywords (only a terminating;may be omitted), sogetById($A)does not matchsvc.getById(x)orgetById(a, b). Put a hole where code varies ($OBJ.getById($A)); there is no variadic$$$yet. Java/C#/C/C++/PHP expressions are written without;. A trailing;roots the pattern at the statement.$VAR:kind— a typed placeholder: bind only nodes of a syntactic class.expr/stmt/type/identaliases resolve to the grammar's supertype (TypeScript/JS/Python), else use an exact tree-sitter kind. Unknown kind = compile error.kind— a bare tree-sitter node kind.regex— a regex over node text.- Relational (each a sub-rule, tuned by
stopBy/field):inside(ancestor),has(descendant),follows/precedes(siblings). - Composite:
all/any(lists),not(a sub-rule),matches(a[utils.NAME]utility rule by id). Every key on a node is ANDed.
Predicates, rewrite, and safety
- A
wherepredicate narrows matches:regex,comparison = { op, value }, a recursivepattern, or Harn-only semantic filtersresolvesTo = { name, kind, line, column, id }andtype = "int". Harn match dictionaries keep text incapturesand addcapture_metadatawithresolved/typewhere available. [transform.NAME]synthesizes a metavar before fixing (convert = "snake",replace = { regex, by },substring = { start, end }).fixinterpolates$VAR/${VAR}($$→$) and splices format-preserving edits.safety(least→most dangerous):format-only→behavior-preserving→scope-local(default) →surface-changing→capability-changing→needs-human. The two safest are machine-applicable; the rest are suggestions (opt-in).auto_applyrefuses anything riskier;apply_checkedalso fails a non-idempotent fix.
From the CLI
harn scan '<pattern>' <paths> --lang <lang>— structural search; also--rule <file>/--rule-pack <pack>,--report-only(per-file counts),--json.harn codemod --rule <file> <paths>— dry-run by default (a unified diff per file with safety + idempotency);--applywrites (capability-gated),--allow-unsafeapplies above machine-applicable safety,--json.harn lint <paths>— runs project lint rules. Declarativelanguage = "harn"rules and imperative*.lint.harnmodules in[rules] ruleDirsmerge into the normal output. A script rule exportslint(source)and returns a{message, severity?, line?, column?}finding, a list of findings, or therules_diagnostics(...)result..harnrules run read-only and fail safe. Trusted native Rust rule libraries can also be loaded from[rules] nativeRuleDirs; they exportharn_native_lint_register_v1and emit the same diagnostic/fix shape as built-ins.
From .harn (std/rules)
rules_search({rule, source|paths, language})→ matches with capture bindings.rules_report(...)→ a report-only data table (counts + rows).rules_diagnostics(...)→ declarative diagnostics.rules_apply({..., dry_run, allow_unsafe})→ codemod (gated;dry_runby default).rules_visit({rule, ..., on_match: fn(node, ctx) { ... }})— the imperative escape hatch: the visitor returns its report(s) (nil/falseto skip,trueto flag, a{message, fix, safety, severity}dict, or
Установить harn-rules в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл harn-rules?
Use for authoring and running declarative structural rules — patterns, lint diagnostics, and codemods.
Как установить скилл harn-rules?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл harn-rules запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic