feat(7732): a pass weighs each rule — enforcement, salience and triggers proposed from its text and delivery history, confirmed by the operator
CI & Build / Python lint (push) Successful in 2s
CI & Build / Plugin hooks (push) Successful in 15s
CI & Build / TypeScript typecheck (push) Successful in 34s
CI & Build / Python tests (push) Failing after 1m41s
CI & Build / integration (push) Successful in 2m9s
CI & Build / Build & push image (push) Skipped
CI & Build / Python lint (push) Successful in 2s
CI & Build / Plugin hooks (push) Successful in 15s
CI & Build / TypeScript typecheck (push) Successful in 34s
CI & Build / Python tests (push) Failing after 1m41s
CI & Build / integration (push) Successful in 2m9s
CI & Build / Build & push image (push) Skipped
Adds rule_field_judgments (migration 0132), the rules_to_weigh / propose_rule_weights / rule_weight_proposals / judge_rule_weights tools, the routes and the Settings › Moments panel that confirms them. A value equal to the rule's own is recorded as agreed; a different one waits; enforce is refused for a rule no act reaches; a direct edit answers a waiting suggestion. Backup v30 carries the judgments. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -16,6 +16,7 @@ from grimoire.mcp._context import current_user_id
|
||||
from grimoire.services import moment_actions as actions_svc
|
||||
from grimoire.services import moments as moments_svc
|
||||
from grimoire.services import reply_shapes as shapes_svc
|
||||
from grimoire.services import rule_field_judgments as weights_svc
|
||||
from grimoire.services import rule_moment_judgments as judgments_svc
|
||||
|
||||
|
||||
@@ -232,6 +233,90 @@ async def rule_misfired(rule_id: int, moment: str, why: str,
|
||||
)
|
||||
|
||||
|
||||
async def rules_to_weigh(limit: int = 25, offset: int = 0) -> dict:
|
||||
"""The rules nobody has weighed, each with what happened when it reached a session — a page at a time.
|
||||
|
||||
Weighing a rule is deciding how strongly it arrives once the work reaches
|
||||
it, and what reaches it exactly:
|
||||
|
||||
- `enforcement`: `inform` is a line beside the work, and is right for
|
||||
most rules. `hold` makes the act or reply wait until the rule has been
|
||||
read once in the session (file edits are never held). `enforce` refuses
|
||||
the act the rule governs, in the rule's own words, every time — for a
|
||||
rule whose breach an act commits and that must never be crossed without
|
||||
the operator (pushing to a protected branch, a destructive command). A
|
||||
preference is always `inform`.
|
||||
- `salience`: `high`, `normal` or `low` — how it ranks beside rules of the
|
||||
same enforcement when a moment has more to say than fits.
|
||||
- `triggers`: typed predicates on the act (`tool`, `path`, `command`,
|
||||
`keyword`, optionally scoped to a moment) that reach the rule exactly.
|
||||
Propose one when the rule names the act it governs; an `enforce` rule
|
||||
needs one, or a mount on an act's moment, to have an act to refuse.
|
||||
|
||||
Each rule carries its current `enforcement`, `salience`, `mounted` and
|
||||
`triggers`, and `history` over the last 90 days: `delivered` and `opened`
|
||||
in total and at each place (`places`), `pulled`, `applied`, `departed`
|
||||
and `misfire_days`. Read the history as evidence about the rule's
|
||||
weight, not as the decision: a rule delivered often and rarely opened is
|
||||
either reaching the wrong work (a trigger fixes that) or arriving too
|
||||
loudly for what it asks (lower salience); a rule sessions keep departing
|
||||
from or breaching may need `hold`.
|
||||
|
||||
Record the answer with `propose_rule_weights`. A rule leaves this list as
|
||||
soon as an answer is recorded, so the next call returns the next rules.
|
||||
Returns `rules`, `total_unweighed` and `offset`.
|
||||
"""
|
||||
return await weights_svc.unweighed_rules(current_user_id(), limit=limit, offset=offset)
|
||||
|
||||
|
||||
async def propose_rule_weights(proposals: list[dict]) -> dict:
|
||||
"""Propose rules' enforcement, salience and triggers — for the operator to confirm; nothing changes on this call.
|
||||
|
||||
Each item is
|
||||
`{"rule_id": N, "enforcement": "inform"|"hold"|"enforce",
|
||||
"salience": "high"|"normal"|"low", "triggers": [{"kind": "command",
|
||||
"pattern": "git push", "moment": ""}], "why": "…"}`.
|
||||
|
||||
Give both enforcement and salience for every rule, even where they match
|
||||
what it has: a value equal to the rule's own is recorded as agreed, which
|
||||
is what marks the rule as weighed. A different value waits as a
|
||||
suggestion. `triggers` lists only triggers to add; omit it when none fits.
|
||||
`why` is shown to the operator beside each suggestion: say what in the
|
||||
rule and its history led to it, so they can say yes or no without opening
|
||||
the rule.
|
||||
|
||||
Refused alone, under `refused`, with why: an unknown value, a preference
|
||||
proposed to hold or enforce, and `enforce` on a rule no act reaches.
|
||||
A value the operator already rejected is listed under `skipped`. Then show
|
||||
the operator what is waiting (`rule_weight_proposals`) and let them
|
||||
decide.
|
||||
"""
|
||||
return await weights_svc.propose(current_user_id(), proposals)
|
||||
|
||||
|
||||
async def rule_weight_proposals(rule_id: int = 0) -> dict:
|
||||
"""The enforcement, salience and trigger suggestions waiting on the operator, grouped by rule.
|
||||
|
||||
Each rule carries its current enforcement, salience, mounts and triggers
|
||||
beside its `proposals`: each a `field`, the suggested `value` (a trigger
|
||||
also as `trigger`), `why`, and the delivery history the proposer read
|
||||
(`evidence`). `rule_id` narrows to one rule.
|
||||
"""
|
||||
return await weights_svc.pending(current_user_id(), rule_id=rule_id or None)
|
||||
|
||||
|
||||
async def judge_rule_weights(judgments: list[dict]) -> dict:
|
||||
"""Confirm or reject weight suggestions — on the operator's word, since a confirm changes how the rule arrives.
|
||||
|
||||
Each item is `{"rule_id": N, "field": "enforcement"|"salience"|"trigger",
|
||||
"value": "hold" (or the trigger object), "verdict": "confirm"|"reject",
|
||||
"note": "why"}`. Confirm sets the field on the rule (a trigger is added
|
||||
beside the rule's others); reject records that the value is wrong for this
|
||||
rule, so it is never proposed again. Put the operator's reason in `note`.
|
||||
"""
|
||||
return await weights_svc.judge(current_user_id(), judgments)
|
||||
|
||||
|
||||
def register(mcp) -> None:
|
||||
mcp.tool(name="list_moments")(list_moments)
|
||||
mcp.tool(name="list_reply_shapes")(list_reply_shapes)
|
||||
@@ -242,3 +327,7 @@ def register(mcp) -> None:
|
||||
mcp.tool(name="rule_moment_proposals")(rule_moment_proposals)
|
||||
mcp.tool(name="judge_rule_moments")(judge_rule_moments)
|
||||
mcp.tool(name="rule_misfired")(rule_misfired)
|
||||
mcp.tool(name="rules_to_weigh")(rules_to_weigh)
|
||||
mcp.tool(name="propose_rule_weights")(propose_rule_weights)
|
||||
mcp.tool(name="rule_weight_proposals")(rule_weight_proposals)
|
||||
mcp.tool(name="judge_rule_weights")(judge_rule_weights)
|
||||
|
||||
Reference in New Issue
Block a user