Context Grammar — Floor 4
Tokens go in. A single ui.command comes out. The deterministic translation layer between context state and surface rendering.
Position in the Stack
The Rule Engine is the bridge between vocabulary and behavior. It takes the 8 context tokens plus memory from the Brain, runs if/then logic, and emits a single ui.command for every interaction.
The Short Version
Before diving into the mechanics, here is the single image that makes everything click.
The Core Translation
Brain memory and Token state cannot reach the UI directly. The human facts "tired," "on the train," "one hand" don't tell the screen what to draw. Rule Engine translates those facts into a concrete drawing instruction — a ui.command.
Current values of 8 Context Tokens, plus facts read from Brain — allergies, budget, schedules.
Fires matching rules. Same input always produces the same output — no mood swings.
An abstract command any surface can read and render — device-agnostic drawing instructions.
Internal Anatomy
Three stages inside every Rule Engine cycle. Once you see them, nothing gets confusing.
Aggregate current values of all 8 Tokens. Pull relevant facts from Brain — a single Brain at home, up to five in enterprise. Allergies, budget, Brand constraints, Research signals — all arrive here.
Check every if/then condition against the current Token state. Fire every match. When multiple rules fire, overlay them by priority. Conflicts go to the Priority Weight Token first.
Merge all fired results into one ui.command object and emit it. The device is not known yet — that is the surface's problem, not the Engine's.
if Form Factor = phone → layout: vertical. That is all.
Live example
Mai is in the kitchen with the kids. She steps in front of the fridge. Here is what happens inside the Rule Engine.
"What should I put in Sota's lunch box… I'm running out of time."
— Mai (38) · Tuesday 7:02 AM, kitchen
Scale
The Rule Engine is scale-agnostic. Whether it's a household Brain or an enterprise stack of five, the Engine always receives one synthesized Token set and runs the same rules.
Rule Engine reads Token current values — but those values don't have to come from a single Brain. Whether it's P1's single Context Brain or P4's five-Brain enterprise stack, the Engine always receives one synthesized Token set.
These Brains each contribute facts from their Identity Layer, Learning Layer, and Now Layer to a Token Bus. The Rule Engine never counts Brains — it runs the same translation every time. Same Engine, different Brain configuration — output changes with the Tokens.
Technical Depth
Rule Engine is not theory. Three YAML files and 33 Behavior Rules — actually writable.
brain.allergy, brain.history.yesterday, etc.intent / density / items / tone / candidates / exclude / input / time-budget / decision-by — the shared dictionary every surface reads. Implementation may be JSON or protobuf.Multiple rules firing simultaneously is normal. Non-conflicting rules all apply. Conflicting rules go through a three-stage arbitration.
| Stage | Arbiter | Criterion |
|---|---|---|
| 1 | Priority Weight Token | The user's declared current priority — "finish the lunch box" — applied first. |
| 2 | Rule priority value |
Static numeric weight (0–999). Trust-related rules such as Disclosure Guard are set to 999. |
| 3 | Brain Learning Layer | Past user decision patterns for this exact conflict type — whichever path the user has historically chosen more often. |
Disclosure = hidden and Autonomy > Confirm cannot coexist. "No disclosure × full delegation" is logically impossible — the Engine always resets Autonomy to Confirm. This is enforced by the priority-999 Trust Breach Recovery rule.
given: { cognitive_load: high, form_factor: phone } → expect: { density: minimal, layout: vertical }. Validation that an LLM can never provide.
Parts + Assembly
AX Patterns are small UI blueprints. The Rule Engine decides which blueprints to select and how to compose them based on Token state. Patterns are words; Rule Engine is grammar — that is why this system is called "Context Grammar."
Total: 23 patterns. The Engine doesn't call them directly — it fires matching rules, and the result is a composed ui.command that corresponds to one or more pattern activations.
D4 provides the "leave it to AI" skeleton. D6 adds friction for high-stakes moments — if the price exceeds the threshold, confirmation fires. E5 monitors whether Disclosure and Autonomy are logically consistent. A2 compresses density to minimal because Cognitive Load is high. The Engine folds all four into one ui.command.
Architecture
Brain holds memory. UI renders pixels. Without Rule Engine between them, both sides become tightly coupled — a maintenance nightmare every time a device changes.
Q&A
priority value, then Brain Learning Layer history. See Section F for the full conflict table.intent / density / tone / candidates / constraints — is readable by every surface. Any new device (wall display, AR glasses, robot) can join without touching the Brain or Engine.Rules are only as good as the memory behind them — and the specs that pin them down. Pick your next floor.