feat: tail-load global RULES.md into per-turn prompt#3
Open
benhoverter wants to merge 5 commits into
Open
Conversation
Introduce read_global_rules() in openfang-types::config that reads $OPENFANG_HOME/RULES.md, trims it, and returns None if absent or blank. Output is truncated to RULES_MD_MAX_CHARS (2000) so a runaway file can't balloon the system prompt. Companion to the per-turn reload path: the kernel calls this on every turn so edits to RULES.md land on the next message without restart. Includes 4 unit tests: missing file, empty/whitespace, present, oversized.
Adds Option<String> rules_md alongside context_md. Field is per-turn reloadable; the kernel will populate it from read_global_rules() on each turn. Default is None so existing call sites keep compiling via #[derive(Default)].
Insert a new ## Global Rules (RULES.md) section into build_system_prompt between Workspace Context (14) and Live Context (15). The framing makes the rules authoritative over earlier guidance, with one explicit carveout: the Safety section above remains non-negotiable. Section is elided when ctx.rules_md is None or trims to empty so the prompt stays clean for users who never write a RULES.md. Includes 4 unit tests covering presence, blank/None elision, ordering relative to Safety + Live Context, and subagent inheritance.
Populate PromptContext.rules_md via openfang_types::config::read_global_rules() at both PromptContext construction sites in kernel.rs. Re-read on every turn alongside context_md so edits to ~/.openfang/RULES.md take effect on the very next message — no daemon restart required.
- docs/global-rules.md: full reference for the per-turn RULES.md overlay — contract, position in the system prompt (14.5), authority + Safety carveout, subagent inheritance, gotchas, worked example. - docs/templates/RULES.md.example: starter template with common patterns (style preferences, channel etiquette, escalation rules) all commented out so users uncomment what they want. - docs/README.md: index updated under Getting Started and Important Paths.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a per-turn loader for
~/.openfang/RULES.mdthat appends user-defined global rules to every agent's system prompt. Hot-reloadable (re-read each turn), 2KB cap, missing file = no-op.Commit chain
d1271c4feat(types): addread_global_rules()loader with 2KB cap3746232feat(runtime): addrules_mdfield toPromptContext20e022ffeat(runtime): render RULES.md section at position 14.5 (after Workspace Context, before Safety override line)7ba629bfeat(kernel): wire RULES.md loader into per-turn prompt buildfd497d5docs: document global RULES.md mechanism + example template (docs/global-rules.md,docs/templates/RULES.md.example)Behavior
~/.openfang/RULES.mdtake effect on the next message, no daemon restart.Test plan
- Always end responses with 🦊in~/.openfang/RULES.md, sent message to coder-openfang, rule was respected on next turn.🤖 Generated with Claude Code