Skip to content
HomeWebAppSetDocsAbout
🌐 Auto English 简体中文 繁體中文 Español Français Русский العربية Português Deutsch 日本語 한국어 हिन्दी

Smart Rules Engine

The Smart Rules Engine turns your knowledge base’s MORAYA.md into an efficient, on-demand context system for the AI assistant — so large rule files no longer get hard-truncated or billed in full on every message.

The problem it solves

Earlier, MORAYA.md was injected into the AI system prompt with a fixed character limit. That caused three issues: rules could be cut off mid-sentence, big files ran up token costs on every request, and the AI had to guess when to re-read the file.

The rules engine replaces “single-file truncation” with auto-split + indexed on-demand loading. You still maintain one file; Moraya compiles it into rule segments the AI loads only when relevant.

How it works

When you save MORAYA.md, Moraya compares a hash of its contents. If it changed, the file is split by its top-level headings into segments under a derived .moraya/rules/ directory:

The system prompt then carries a compact index plus any glob-matched segment content, instead of the entire file.

Design principles

PrincipleWhat it means
Single source of truthYou only maintain MORAYA.md; .moraya/rules/ is a generated artifact
Zero learning curveNo glob syntax required — just write good Markdown headings
Everyone winsYou see the whole document, the AI reads segments, billing loads on demand
Self-healing.moraya/ isn’t committed to Git; a new machine rebuilds it automatically
Backward compatibleFiles without headings behave exactly as before

Adding conditional rules

To scope a rule to certain files, add a glob comment under its heading:

## API documentation style
<!-- globs: docs/api/**/*.md -->

- Every endpoint must document its error responses.
- Use `snake_case` for JSON field names.

Now that section is injected only when you’re editing a file under docs/api/. Sections without a glob comment stay in the index and are pulled in by the AI when they’re relevant to the conversation.

Tips