rules-engine

August 24, 2026 · View on GitHub

Generated: 2026-06-16 / updated 2026-08-24 (f3642fcda)

OVERVIEW

@oh-my-opencode/rules-engine (renamed from rules-core). Harness-neutral TypeScript package that discovers markdown rule files and matches them against target paths. Consumed by the rules-injector hook in omo-opencode, the rules component in omo-codex, and agents-md-core for AGENTS.md walk-up discovery.

KEY FILES

FileRole
src/index.tsBarrel: legacy/simple API (findRuleFiles, shouldApplyRule, findAgentsMdUp)
src/engine/index.tsBarrel: comprehensive engine API (createEngine, findRuleCandidates, matchRule)
src/finder.tsfindRuleFiles() — walks project + user home directories to collect rule candidates
src/matcher.tsshouldApplyRule() — picomatch against rule globs/paths with LRU cache
src/agents-md.tsfindAgentsMdUp() — walk-up discovery for AGENTS.md from start dir to root
src/engine/engine.tscreateEngine() — static + dynamic loading, session state, formatting, truncation
src/engine/finder.tsfindRuleCandidates() + findPluginBundledCandidates() with source filtering
src/engine/matcher.tsmatchRule() with content-hash dedup
src/engine/scanner.tsscanRuleFiles() — recursive directory scanner with caching
src/engine/formatter.tsformatStaticBlock() / formatDynamicBlock() with per-mode char budgets
src/engine/truncator.tsChar-budget truncation for static/dynamic/post-compact blocks
src/engine/parser-yaml.tsYAML frontmatter parser (largest impl file)
src/constants.tsRule sources, extensions, source priority map, project root markers

FLOW

Discovery (finder.ts / engine/finder.ts) Walk UP from cwd toward project root Scan .omo/rules, .claude/rules, .cursor/rules, .github/instructions Collect .md / .mdc files + single-file rules (.github/copilot-instructions.md, CONTEXT.md) Walk user home: ~/.omo/rules, ~/.opencode/rules, ~/.claude/rules .sisyphus/rules (project + user) still matched but emits a deprecation warning (hook: setSisyphusRuleDeprecationLogger); migrate to .omo/rules Plugin bundled: platform-gated rules under bundled-rules/

Matching (matcher.ts / engine/matcher.ts) Parse YAML frontmatter (globs, paths, applyTo, alwaysApply) Picomatch against target file path (relative + basename) Negative globs (!) excluded; alwaysApply: true bypasses matching

Ordering Source priority map (SOURCE_PRIORITY) + distance from target file Lower priority value = earlier; closest distance wins

NOTES

  • Two APIs: root src/ (simple functions) and src/engine/ (stateful engine with truncation budgets). Both consumed in production.
  • ESM split: src/engine/ uses explicit .js relative imports; root src/ is extensionless. Do not normalize either tree.
  • Deps: picomatch + @oh-my-opencode/utils only.
  • Default char budgets: static 12K rule / 40K total; dynamic 4K / 10K; post-compact 3.5K / 4K.
  • AGENTS.md discovery lives here but injection logic is in agents-md-core.
  • Parent: packages/AGENTS.md