Skip to content

Commit 8b89623

Browse files
authored
Merge pull request #64 from dmoliveira/my_opencode-e9-rule-schema
docs: define conditional rules schema contract
2 parents 956d488 + 7c6a04e commit 8b89623

File tree

3 files changed

+81
-6
lines changed

3 files changed

+81
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ All notable changes to this project are documented in this file.
2727
- Added `scripts/keyword_mode_schema.py` and `scripts/keyword_mode_command.py` to parse prompt keywords, resolve precedence-aware mode flags, and persist keyword mode runtime context.
2828
- Added `/keyword-mode` aliases (`status|detect|apply`) to inspect and apply keyword-triggered execution modes.
2929
- Added keyword mode controls for global enable/disable and per-keyword toggles (`disable-keyword` / `enable-keyword`) with persisted config state.
30+
- Added `instructions/conditional_rules_schema.md` defining rule frontmatter schema, discovery precedence, conflict resolution, and validation requirements for Epic 9 Task 9.1.
3031

3132
### Changes
3233
- Documented extension evaluation outcomes and when each tool is the better fit.

IMPLEMENTATION_ROADMAP.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Use this map to avoid overlapping implementations.
4545
| E6 | Session Intelligence and Resume Tooling | paused | Medium | E2 | TBD | Resume when core orchestration stabilizes |
4646
| E7 | Tmux Visual Multi-Agent Mode | postponed | Low | E2 | TBD | Optional power-user feature |
4747
| E8 | Keyword-Triggered Execution Modes | done | High | E1, E4 | bd-302, bd-2fb, bd-2zq, bd-3dp | Fast power-mode activation from prompt text |
48-
| E9 | Conditional Rules Injector | planned | High | E1 | TBD | Enforce project conventions with scoped rules |
48+
| E9 | Conditional Rules Injector | in_progress | High | E1 | bd-1q8 | Enforce project conventions with scoped rules |
4949
| E10 | Auto Slash Command Detector | paused | Medium | E1, E8 | TBD | Resume only if intent precision stays high in prototypes |
5050
| E11 | Context-Window Resilience Toolkit | planned | High | E4 | TBD | Improve long-session stability and recovery |
5151
| E12 | Provider/Model Fallback Visibility | planned | Medium | E5 | TBD | Explain why model routing decisions happen |
@@ -407,15 +407,16 @@ Every command-oriented epic must ship all of the following:
407407

408408
## Epic 9 - Conditional Rules Injector
409409

410-
**Status:** `planned`
410+
**Status:** `in_progress`
411411
**Priority:** High
412412
**Goal:** Load project/user rule files with optional glob conditions to enforce coding conventions contextually.
413413
**Depends on:** Epic 1
414414

415-
- [ ] Task 9.1: Define rule file schema and precedence
416-
- [ ] Subtask 9.1.1: Define frontmatter fields (`globs`, `alwaysApply`, `description`, `priority`)
417-
- [ ] Subtask 9.1.2: Define project/user rule search paths
418-
- [ ] Subtask 9.1.3: Define rule conflict resolution strategy
415+
- [x] Task 9.1: Define rule file schema and precedence
416+
- [x] Subtask 9.1.1: Define frontmatter fields (`globs`, `alwaysApply`, `description`, `priority`)
417+
- [x] Subtask 9.1.2: Define project/user rule search paths
418+
- [x] Subtask 9.1.3: Define rule conflict resolution strategy
419+
- [x] Notes: Added `instructions/conditional_rules_schema.md` with deterministic discovery, matching, precedence, conflict handling, and validation requirements.
419420
- [ ] Task 9.2: Implement rule discovery and matching engine
420421
- [ ] Subtask 9.2.1: Discover markdown rule files recursively
421422
- [ ] Subtask 9.2.2: Match rules by file path and operation context
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Conditional Rules Schema
2+
3+
Epic 9 Task 9.1 defines the schema and precedence contract for conditional rule injection.
4+
5+
## Rule sources and discovery
6+
7+
Rules are discovered from layered scopes in deterministic order:
8+
9+
1. user scope: `~/.config/opencode/rules/**/*.md`
10+
2. project scope: `.opencode/rules/**/*.md`
11+
12+
Project scope has higher precedence when two rules have equivalent priority and target overlap.
13+
14+
## Rule file format
15+
16+
Each rule file is markdown with YAML frontmatter.
17+
18+
Required frontmatter fields:
19+
20+
- `description`: short purpose summary
21+
- `priority`: integer from `0` to `100` (higher applies first)
22+
23+
Optional frontmatter fields:
24+
25+
- `globs`: list of file globs where rule applies
26+
- `alwaysApply`: boolean forcing rule application regardless of file path
27+
- `id`: stable rule identifier (fallback: normalized file stem)
28+
- `tags`: list of category tags for diagnostics/reporting
29+
30+
Rule body (markdown after frontmatter) is the instruction payload injected at runtime.
31+
32+
## Matching semantics
33+
34+
- If `alwaysApply` is `true`, the rule always applies.
35+
- Else if `globs` is present, any glob match applies the rule.
36+
- Else the rule is considered inactive by default.
37+
38+
Glob matching uses workspace-relative POSIX-style paths.
39+
40+
## Conflict resolution
41+
42+
Sort and merge rules by deterministic key:
43+
44+
1. descending `priority`
45+
2. scope precedence (`project` before `user`)
46+
3. lexical `id`
47+
48+
Conflicts are resolved by first-writer-wins over normalized rule ids after sorting.
49+
50+
Diagnostics must surface:
51+
52+
- winning rule id and source
53+
- overridden/conflicting rule ids
54+
- effective ordered rule stack for any target path
55+
56+
## Config controls (for Task 9.3)
57+
58+
Planned config controls:
59+
60+
- `rules.enabled` (default `true`)
61+
- `rules.disabled_ids` (list)
62+
- `rules.extra_paths` (additional discovery roots)
63+
64+
## Validation requirements
65+
66+
Reject and report rules when:
67+
68+
- required frontmatter keys are missing
69+
- `priority` is out of range or non-numeric
70+
- `globs` is not a list of strings
71+
- `alwaysApply` is non-boolean
72+
73+
Validation errors should include rule path and actionable remediation.

0 commit comments

Comments
 (0)