Skip to content

feat(prompt): RulesSource port + .claude/rules discovery (#329) - #334

Merged
JAORMX merged 3 commits into
mainfrom
feat/rules-source-329
Aug 3, 2026
Merged

JAORMX merged 3 commits into
mainfrom
feat/rules-source-329

Conversation

@JAORMX

@JAORMX JAORMX commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Closes #329. Design decisions recorded in ADR 0081 (included).

Problem

.claude/rules/*.md was discovered by nothing in mecatl. Claude Code's own guidance is to split CLAUDE.md past ~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 public RulesSource port + Rule value object + RuleOrigin (consumer-local, the SoulSource/CommandSource precedent) and the RulesAssembler on the existing InstructionAssembler seam. Eager v1: all discovered rules injected at turn 0 as ONE user-role message, each fenced <rule name="…"> with its paths: globs stated as an Applies when: condition the model applies itself. Paths rides 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 on IncludeProjectTier with 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. sourceconformance gains the RunRulesSource suite + canonical fixture.
  • Composition — resolveRulesSeam resolves ONCE at Build and 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 by TestPerSessionAssemblerMatchesShared).
  • 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. No --rules-dir/--rules-conventional, no Config.Rules* fields.
  • Live e2e — a rules fixture + spec asserting the deterministic rules ENABLED build fact (plus a quarantined behavioural marker), verified live against OpenRouter locally.
  • Docs — ADR 0081, architecture.md, IMPLEMENTATION-NOTES.md, usage reference, new user-docs/extension-points/project-rules.md, AGENTS.md, regenerated llms.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: RuleOrigin has no explicit tier).
  • Rule names sanitized before <rule name="…"> interpolation (CWE-74 hardening — a crafted filename could break the fence).
  • Fence-structure test assertions strengthened (ordering + exact close-fence count, not bare Contains).
  • skillfs gained 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 (same instructions flows 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 issues
  • task test — full suite green incl. -race + GOWORK=off engine-standalone
  • task api:check — green (prompt.txt regenerated via task api:update; CHANGELOG Added entry per COMPATIBILITY.md)
  • go run ./cmd/mecademo — full offline session
  • task docs:check — 0 broken links/anchors/orphans
  • task site:build — user-docs build green
  • Live e2e focused run (-ginkgo.focus='rules') — 2 Passed, verified against OpenRouter

…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]>
@JAORMX JAORMX added the e2e-live Run the live e2e suite on this PR label Aug 2, 2026
JAORMX and others added 2 commits August 2, 2026 21:25
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]>
@JAORMX
JAORMX merged commit 2f08fd7 into main Aug 3, 2026
14 checks passed
@JAORMX
JAORMX deleted the feat/rules-source-329 branch August 3, 2026 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e2e-live Run the live e2e suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a public RulesSource port + Claude-compatible .claude/rules implementation — path-scoped rules are silently ignored today

1 participant