feat(7728): typed triggers on a rule, and a rule says its piece once per session
CI & Build / TypeScript typecheck (push) Successful in 34s
CI & Build / Plugin hooks (push) Successful in 22s
CI & Build / Python lint (push) Successful in 3s
CI & Build / Python tests (push) Failing after 1m48s
CI & Build / integration (push) Successful in 2m8s
CI & Build / Build & push image (push) Skipped
CI & Build / TypeScript typecheck (push) Successful in 34s
CI & Build / Plugin hooks (push) Successful in 22s
CI & Build / Python lint (push) Successful in 3s
CI & Build / Python tests (push) Failing after 1m48s
CI & Build / integration (push) Successful in 2m8s
CI & Build / Build & push image (push) Skipped
Triggers (migration 0130, table rule_triggers): a rule can name the act it applies to, as a tool, a path glob, a command head or a keyword, checked exactly against the act rather than by resemblance. With no moment a trigger delivers its rule on any matching act, even one that reaches no moment; scoped to a moment, it makes the rule's mount there conditional on the act matching. A triggered line ranks above a mounted one in the delivery order and names the trigger that fired. Writable through every MCP and REST rule door, carried by backup (version 29), and edited in the rule editor under "Acts that trigger it". The plugin's catch-all hook is told which tools a trigger can reach. Lifecycle: a rule's life in a session is one full line, one reminder, then silence. A repeat whose latest delivery in the session was already a reminder is left out of both rule arms. A rule that holds stays armed until it is opened, an opened rule keeps its line, and a full delivery (after a compaction or once the ledger ages it out) re-arms it. Read from the delivery records, so it needs no new plugin ledger. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -470,9 +470,9 @@ async def co_surfaced_partners(user_id: int, rule_ids: list[int]) -> list[Rule]:
|
||||
|
||||
async def rule_detail(
|
||||
user_id: int, rule: Rule, system_ids: list[int] | None = None,
|
||||
moments: list[str] | None = None,
|
||||
moments: list[str] | None = None, triggers: list | None = None,
|
||||
) -> dict:
|
||||
"""The full record, with its areas, moments and edges attached.
|
||||
"""The full record, with its areas, moments, triggers and edges attached.
|
||||
|
||||
ONE seam for both doors and every write path, so create, update and get
|
||||
cannot disagree about what a rule looks like coming back — the same
|
||||
@@ -482,15 +482,21 @@ async def rule_detail(
|
||||
`system_ids=None` / `moments=None` mean "leave them alone"; a list
|
||||
(including []) REPLACES them. Doors validate `moments` with
|
||||
`moments.require_moments` BEFORE their create, so an unknown name is
|
||||
refused without leaving a rule behind.
|
||||
refused without leaving a rule behind; `triggers` the same way, with
|
||||
`rule_triggers.require_triggers`, and it replaces them the same way.
|
||||
"""
|
||||
from grimoire.services import rule_triggers
|
||||
|
||||
if system_ids is not None:
|
||||
await set_rule_systems(rule.id, user_id, system_ids)
|
||||
if moments is not None:
|
||||
await set_rule_moments(rule.id, user_id, moments)
|
||||
if triggers is not None:
|
||||
await rule_triggers.set_rule_triggers(rule.id, triggers)
|
||||
data = rule.to_dict()
|
||||
systems = (await list_rule_systems([rule.id])).get(rule.id, [])
|
||||
mounted = (await list_rule_moments([rule.id])).get(rule.id, [])
|
||||
triggered = (await rule_triggers.list_rule_triggers([rule.id])).get(rule.id, [])
|
||||
relations = (await list_rule_relations([rule.id])).get(rule.id, [])
|
||||
# Attached only when present: an empty key reads as a capability
|
||||
# the record has and isn't using, which is a different claim.
|
||||
@@ -498,6 +504,8 @@ async def rule_detail(
|
||||
data["systems"] = systems
|
||||
if mounted:
|
||||
data["moments"] = mounted
|
||||
if triggered:
|
||||
data["triggers"] = triggered
|
||||
if relations:
|
||||
data["relations"] = relations
|
||||
# The concrete situations judged (or proposed) to be instances of this
|
||||
|
||||
Reference in New Issue
Block a user