Repository navigation
feat(prompt): RulesSource port + .claude/rules discovery (#329) - #334
Merged
Merged
Conversation
…d rules reach turn-0 context (#329) .claude/rules/*.md was discovered by nothing in mecatl: a repo that followed Claude Code's own guidance (split CLAUDE.md past ~200 lines into .claude/rules/) silently lost every rule it split out. This closes the last unimplemented .claude/* convention through a public port, per ADR 0081: - engine/prompt: the RulesSource port + Rule value object + RuleOrigin (consumer-local, the SoulSource/CommandSource precedent) and the RulesAssembler on the InstructionAssembler seam — eager v1: all rules injected at turn 0 as ONE user-role message, each fenced with its paths: globs stated as a model-applied "Applies when:" condition. 20 KiB/rule + 40 KiB combined + 32-count caps, fail-soft, never aborts a run. IsInjectedTurn0Fragment recognises the fragment. - engine/adapter/rulesfs: the FS implementation (flat <name>.md, the agentfs structural twin) — project tiers (.mecatl/rules, .claude/rules) trust-gated on IncludeProjectTier, user tiers (XDG + ~/.claude/rules) always active. paths: parses as a YAML sequence with scalar/comma tolerance. sourceconformance gains the RunRulesSource suite + fixture. - Composition: resolveRulesSeam resolves ONCE at Build and threads the same assembler into shared + per-session engines (the issue-#42 drift class), with the trust-gate WITHHELD WARN and the ENABLED/DISABLED build-once facts. - NO FLAGS (operator decision, ADR 0081 §5): conventional discovery is always-on like AGENTS.md/CLAUDE.md themselves — the conventional lanes are inert without dirs and TrustProject is the one gate. - Live e2e: a rules fixture + spec asserting the deterministic "rules ENABLED" build fact (plus a quarantined behavioural marker), verified live against OpenRouter. Panel review (Spec/Standards/Security/Architecture/reuse/duplication + QA): zero ship-blockers. Applied findings: stale origin-extraction trip-wire comment updated in agentsource.go (the third seam arrived and extraction was deferred — the label sets differ); rule names sanitized before fence interpolation (CWE-74 hardening); fence-structure test assertions strengthened; skillfs gained the missing carry-parity pin. Deferred: factory-path variant of TestPerSessionAssemblerMatchesShared (the capture is structural; the behavioural test proves no doubling). Co-Authored-By: mecatl <[email protected]>
Co-Authored-By: mecatl <[email protected]>
The live suite only exercised the trusted lane (the harness always spawns with --trust-project), leaving the trust gate — the ONE boundary for always-on rules discovery (ADR 0081 §5) — proven only offline. Add a spec spawning a second mecated with --trust-project=false (flag pkg last-wins) asserting the project-tier-withheld WARN and the ABSENCE of "rules ENABLED" — a regression here means a malicious repo's .claude/rules reaches the model. Also correct the spawn comment: the flag is load-bearing for agent defs and rules, not just "skills + any project allows". Verified live against OpenRouter (focused runs of all three rules specs). Co-Authored-By: mecatl <[email protected]>
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.
Closes #329. Design decisions recorded in ADR 0081 (included).
Problem
.claude/rules/*.mdwas discovered by nothing in mecatl. Claude Code's own guidance is to splitCLAUDE.mdpast ~200 lines into.claude/rules/— a repo that followed that advice ran mecatl with a fraction of its stated policy, silently. Unlike #328 there was no implementation to graduate; this had to be built.What
engine/prompt— the publicRulesSourceport +Rulevalue object +RuleOrigin(consumer-local, theSoulSource/CommandSourceprecedent) and theRulesAssembleron the existingInstructionAssemblerseam. Eager v1: all discovered rules injected at turn 0 as ONE user-role message, each fenced<rule name="…">with itspaths:globs stated as anApplies when:condition the model applies itself.Pathsrides the port from day one so lazy path-triggered activation is additive later. Caps: 20 KiB/rule, 40 KiB combined, 32 rules — fail-soft, never aborts a run.engine/adapter/rulesfs— the Claude-compatible FS implementation (flat<name>.md, the agentfs structural twin): project tiers (.mecatl/rules,.claude/rules) trust-gated onIncludeProjectTierwith the standard WITHHELD WARN; user tiers ($XDG_CONFIG_HOME/mecatl/rules,~/.claude/rules) always active.paths:parses as a YAML sequence with scalar/comma tolerance.sourceconformancegains theRunRulesSourcesuite + canonical fixture.resolveRulesSeamresolves ONCE atBuildand threads the same assembler into the shared engine AND the per-session factory (the issue-Per-session engines drop memory and user-model tools #42 drift class, guarded byTestPerSessionAssemblerMatchesShared).AGENTS.md/CLAUDE.mdthemselves — the conventional lanes are inert without dirs andTrustProjectis the one gate. No--rules-dir/--rules-conventional, noConfig.Rules*fields.rules ENABLEDbuild fact (plus a quarantined behavioural marker), verified live against OpenRouter locally.user-docs/extension-points/project-rules.md, AGENTS.md, regeneratedllms.txt.Review
Full dev-pipeline: separate architect → 3 implementer waves → panel review (Spec / Standards / Security / Architecture / library-reuse / code-duplication) + independent QA test-adequacy review. Zero ship-blockers. Applied findings:
agentsource.go's origin-extraction trip-wire comment updated — the third seam arrived and extraction was deferred (the label sets differ:RuleOriginhas noexplicittier).<rule name="…">interpolation (CWE-74 hardening — a crafted filename could break the fence).Contains).skillfsgained the missing carry-parity pin (closes the four-way byte-identity ring).Deferred (flagged honestly): a factory-path variant of
TestPerSessionAssemblerMatchesShared— the capture is structural (sameinstructionsflows both paths) and the behavioural test proves no doubling; the QA reviewer rated it should-add, not must-add.Verification
task lint(both modules) — 0 issuestask test— full suite green incl.-race+ GOWORK=off engine-standalonetask api:check— green (prompt.txt regenerated viatask api:update; CHANGELOGAddedentry per COMPATIBILITY.md)go run ./cmd/mecademo— full offline sessiontask docs:check— 0 broken links/anchors/orphanstask site:build— user-docs build green-ginkgo.focus='rules') — 2 Passed, verified against OpenRouter