/otter:otter-rules-enginefrom otter
Guides authoring and debugging Otter @o3r/rules-engine artifacts: facts, operators, actions, and rulesets for runtime-conditional behavior.
Ships in otter. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
The Otter rules engine (@o3r/rules-engine) is a client-side mechanism that evaluates a sorted list of Rulesets and applies actions based on the application's runtime context. When building or editing rules-engine artifacts, follow the workflow below so facts, operators, actions, and rulesets stay consistent and correctly registered.
| Concept | What it is | How to create |
|---|---|---|
| Ruleset | Sorted list of rules; may be gated by validityRange / linkedComponents | Hand-authored/generated JSON validated by the ruleset schema |
| Rule | Tree of IF_ELSE blocks (branches) ending in ACTION blocks (leaves), identified by a unique id | Inside the Ruleset JSON |
| Operator | Pure function evaluating a condition (up to two operands) | ng g @o3r/rules-engine:operator |
| Fact | A stream of business values (value$) that triggers re-evaluation | ng g @o3r/rules-engine:facts-service |
| Action | Side effect applied at runtime, identified by a unique actionType | Built-in, or a custom RulesEngineActionHandler |
Requires an Otter-based app with @o3r/rules-engine installed (ng add @o3r/rules-engine) and the runner registered via provideRulesEngineRunner() (see below). To enable rules-engine on an existing Otter component, run the schematic rather than wiring it by hand:
ng g @o3r/rules-engine:rules-engine-to-component --path=<path-to-component-class.ts>
What is missing to express the rule?
├── A business value the condition depends on → create a FACT
├── A comparison the built-in operators don't cover → create an OPERATOR
├── A runtime effect not covered by built-ins → create an ACTION handler
└── Only the logic itself → edit the RULESET JSON only
Always prefer built-in actions and operators before creating custom ones. Built-in actions:
UPDATE_CONFIG — modify a configurable component's config (@o3r/configuration)UPDATE_ASSET — override an asset path used by o3rDynamicContent (@o3r/dynamic-content)UPDATE_LOCALISATION — substitute a translation key (@o3r/localization)UPDATE_PLACEHOLDER — inject HTML into a placeholder (@o3r/components)Generate the fact structure with the schematic — do not hand-create the files:
ng g @o3r/rules-engine:facts-service <name> --path=<path-to-fact-folder>
This produces a FactDefinitions interface and a service extending FactsService. Then implement the logic and follow these rules:
distinctUntilChanged() to avoid re-evaluating every dependent rule on each emission.filter so the fact registers even before a lazy-loaded store emits..register() inside runInInjectionContext.Performance: a rule re-evaluates whenever an input fact updates. Avoid high-frequency facts (e.g. 1s timers); gate the ruleset with linkedComponents when the affected component may be absent.
ng g @o3r/rules-engine:operator <name> --path=<path-to-operators-folder>
dateInNextMinutes.validateLhs (and validateRhs when a right operand exists) so invalid operand types fail fast.rulesEngine.upsertOperators([myOperator]).@title TSDoc tag for a human-friendly name in extracted metadata.matchesPattern, oneMatches, allMatch), escape special chars with double backslashes (\\t) and prefix a leading / with \\ so it is not wrongly detected as an ES RegExp.o3rCurrentTime built-in factOperators like dateInNextMinutes depend on the implicit o3rCurrentTime fact, backed by CurrentTimeFactsService. Although the service ships with the package (providedIn: 'root'), it is not registered with the engine automatically — you must register it or the whole ruleset fails, exactly like any other unregistered fact. It also does not refresh on its own — call currentTime.tick() to recompute the current time on a trigger that fits the app; a common one is each router navigation:
const router = inject(Router);
const currentTime = inject(CurrentTimeFactsService);
currentTime.register();
router.events.pipe(
filter((event) => event instanceof NavigationEnd),
takeUntilDestroyed()
).subscribe(() => currentTime.tick());
Without a tick(), time-based conditions never re-evaluate.
Only when no built-in action fits. An action handler implements RulesEngineActionHandler, declares its ids in supportingActions, and runs them in executeActions.
actionType constant and export it — it is the contract between JSON and code.RulesEngineAction with a typed payload interface.ruleEngine.registerActionHandlers(inject(MyActionHandler)).Every Ruleset JSON references the schema and gives every ruleset and rule a unique id:
{
"schema": "https://raw.githubusercontent.com/AmadeusITGroup/otter/main/packages/%40o3r/rules-engine/schemas/rulesets.schema.json",
"rulesets": [
{
"id": "<uuid>",
"name": "My Ruleset",
"disabled": false,
"rules": [ /* ... */ ]
}
]
}
Rules:
inputRuntimeFacts and outputRuntimeFacts must list every runtime fact it reads or sets, or re-evaluation optimization breaks.IF_ELSE block with no condition always runs its successElements.linkedComponents; gate time-bound rulesets with validityRange.The engine is agnostic — everything must be explicitly registered or it silently no-ops (or warns). Register at bootstrap through the application config providers array, but only add the action provider for action types your rulesets actually use — do not register handlers for actions you never emit:
export const appConfig: ApplicationConfig = {
providers: [
provideRulesEngineRunner({ debug: !environment.production }),
// Add ONLY the action providers matching the actions used in your rulesets:
provideConfigurationRulesEngineAction(), // only if UPDATE_CONFIG is used
// provideAssetRulesEngineAction(), // only if UPDATE_ASSET is used
// providePlaceholderRulesEngineAction(), // only if UPDATE_PLACEHOLDER is used (bundles its request/template stores)
provideRulesEngineDevtools(), // optional, dev only
]
};
Then verify:
provideConfigurationRulesEngineAction() for UPDATE_CONFIG, provideAssetRulesEngineAction() for UPDATE_ASSET, providePlaceholderRulesEngineAction() for UPDATE_PLACEHOLDER. For UPDATE_LOCALISATION there is no provider function yet — import LocalizationRulesEngineActionModule via importProvidersFrom(LocalizationRulesEngineActionModule)..register()upsertOperatorsfailureElements (or a safe default action value) that preserves current behavior.disabled: false only when their safe path is verified; otherwise ship disabled: true and enable deliberately.Enable debug mode and use the console devtools before assuming a rule is wrong:
provideRulesEngineRunner({ debug: true })
_OTTER_DEVTOOLS_.rulesEngine.getActiveRulesets();
_OTTER_DEVTOOLS_.rulesEngine.getRulesetExecutions(rulesetId);
_OTTER_DEVTOOLS_.rulesEngine.getAllOutputActions();
Or install the Otter rules-engine Chrome extension for a visual view. When a rule does not fire, check the Registration Checklist first — an unregistered action raises a warning, and an unregistered fact leaves the ruleset failing until the fact becomes available.
| Symptom | Likely cause |
|---|---|
Rule evaluates and its action appears in getAllOutputActions(), but nothing changes in the app | The matching action provider is missing — e.g. UPDATE_CONFIG emitted but provideConfigurationRulesEngineAction() not added. The engine emits the action; with no handler registered it is silently dropped (a console warning is logged in debug mode). |
| Ruleset never activates / stays in a failing state | An input fact is unregistered or has not emitted yet — register it via the fact service .register() and guard lazy state with a filter. |
| Custom operator throws or the rule is skipped | Operator not registered via upsertOperators, or validateLhs/validateRhs rejecting the operand types. |
Time-based operator (dateInNextMinutes, …) never matches, or its ruleset fails | CurrentTimeFactsService not registered (.register()), or registered but never tick()ed so o3rCurrentTime never refreshes. |
Ruleset absent from getActiveRulesets() | Ruleset not loaded into the runner, or gated out by validityRange / linkedComponents. |
The first row is the most common trap after wiring rulesets: the rule logic is correct and the action is produced, but no visible effect occurs because the action's provider was never added (or was removed as "unused"). Confirm the provider for that action type is in the bootstrap providers.
If rules are administered through a UI, extract fact and operator metadata with the builder so the UI knows what is available:
ng run <project>:extract-rules-engine
Configure factFilePatterns, operatorFilePatterns, and libraries in angular.json. Fact interface properties and operator @title/TSDoc drive the generated metadata, so document them.
Halt and ask for clarification if:
UPDATE_CONFIG, UPDATE_ASSET, UPDATE_LOCALISATION, UPDATE_PLACEHOLDER) would sufficedistinctUntilChanged()inputRuntimeFacts / outputRuntimeFactsWhat SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub amadeusitgroup/otter --plugin otter11 skills in this plugin
/logic-component-shapeDecision tree for single component versus container/presenter, which componentStructure to generate, and which componentType to declare. Invoked by `logic-placement` and `logic-review`, not directly./logic-placementDecide where new logic belongs — component shape, logic layer, and store variant — when designing a component, service, or store in an Angular/Otter workspace. Use `logic-review` to assess existing code./logic-reviewReview existing components, services, or stores for misplaced logic — presenter leaks, componentType mismatches, wrong store variants. Use `logic-placement` when designing something new.Other plugins' skills for the same job