feat(7728): a rule declares its enforcement and salience
CI & Build / Plugin hooks (push) Successful in 14s
CI & Build / Python lint (push) Successful in 2s
CI & Build / TypeScript typecheck (push) Failing after 21s
CI & Build / Python tests (push) Successful in 1m55s
CI & Build / integration (push) Successful in 2m2s
CI & Build / Build & push image (push) Skipped
CI & Build / Plugin hooks (push) Successful in 14s
CI & Build / Python lint (push) Successful in 2s
CI & Build / TypeScript typecheck (push) Failing after 21s
CI & Build / Python tests (push) Successful in 1m55s
CI & Build / integration (push) Successful in 2m2s
CI & Build / Build & push image (push) Skipped
A rule now carries what it does when it arrives, declared by its author rather than guessed from a score: enforce (the act is checked), hold (the reply or act waits for one read) or inform (a line beside the work, the default). And a salience, high, normal or low, for ranking among rules of the same enforcement at a crowded moment. A preference is always inform. Migration 0128 adds both with CHECKs. Every door carries them: the service, the MCP create and update tools, REST, backup and restore, and the rule editor, which also marks holding and enforced rules in the list. Unknown values are refused rather than mapped. Nothing reads them yet beyond the record; the ordering function and the lifecycle come next in this step, and step 5 decides who holds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -342,6 +342,7 @@ async def create_rule(
|
||||
arose_from_id: int = 0, verify_with: str = "", expires_when: str = "",
|
||||
system_ids: list[int] | None = None,
|
||||
moments: list[str] | None = None, force: bool = False,
|
||||
enforcement: str = "inform", salience: str = "normal",
|
||||
) -> dict:
|
||||
"""Create a new rule in a rulebook (a SHARED rule — keep it general).
|
||||
|
||||
@@ -530,6 +531,14 @@ async def create_rule(
|
||||
constraint expires when the ground under it moves, not on a
|
||||
schedule. Pairs with verify_with; both empty is the normal case.
|
||||
order_index: Display order within the topic (default 0).
|
||||
enforcement: What this rule does when it arrives. `inform` (the
|
||||
default) puts a line beside the work. `hold` makes the reply or
|
||||
act it governs wait for one read of it — for a rule whose miss
|
||||
costs a rewrite. `enforce` checks the act itself — for a hard
|
||||
boundary. Declare hold or enforce on purpose; most rules inform.
|
||||
salience: `high`, `normal` (the default) or `low` — how this record
|
||||
ranks against others of the same enforcement when a moment has
|
||||
more to say than fits.
|
||||
force: Bypass the near-duplicate gate. By default, a title-identical rule
|
||||
already in this topic BLOCKS creation and returns its id so you update
|
||||
it instead. Set true only for a genuinely distinct rule. A rule or
|
||||
@@ -553,6 +562,7 @@ async def create_rule(
|
||||
arose_from_id=arose_from_id,
|
||||
why=why, how_to_apply=how_to_apply, order_index=order_index,
|
||||
verify_with=verify_with, expires_when=expires_when,
|
||||
enforcement=enforcement, salience=salience,
|
||||
)
|
||||
data = await rulebooks_svc.rule_detail(uid, rule, system_ids, moments)
|
||||
data.update(dedup_svc.overlap_response(overlaps, "rule"))
|
||||
@@ -565,6 +575,7 @@ async def create_project_rule(
|
||||
arose_from_id: int = 0, verify_with: str = "", expires_when: str = "",
|
||||
system_ids: list[int] | None = None,
|
||||
moments: list[str] | None = None, force: bool = False,
|
||||
enforcement: str = "inform", salience: str = "normal",
|
||||
) -> dict:
|
||||
"""Create a rule scoped to a single project (no rulebook needed).
|
||||
|
||||
@@ -640,6 +651,14 @@ async def create_project_rule(
|
||||
expires_when: The state under which the rule stops being true — see
|
||||
create_rule. A state, not a date.
|
||||
order_index: Display order within the project's rule list (default 0).
|
||||
enforcement: What this rule does when it arrives. `inform` (the
|
||||
default) puts a line beside the work. `hold` makes the reply or
|
||||
act it governs wait for one read of it — for a rule whose miss
|
||||
costs a rewrite. `enforce` checks the act itself — for a hard
|
||||
boundary. Declare hold or enforce on purpose; most rules inform.
|
||||
salience: `high`, `normal` (the default) or `low` — how this record
|
||||
ranks against others of the same enforcement when a moment has
|
||||
more to say than fits.
|
||||
force: Bypass the near-duplicate gate. By default, a title-identical rule
|
||||
already on this project BLOCKS creation and returns its id so you
|
||||
update it instead. Set true only for a genuinely distinct rule. An
|
||||
@@ -662,6 +681,7 @@ async def create_project_rule(
|
||||
arose_from_id=arose_from_id,
|
||||
why=why, how_to_apply=how_to_apply, order_index=order_index,
|
||||
verify_with=verify_with, expires_when=expires_when,
|
||||
enforcement=enforcement, salience=salience,
|
||||
)
|
||||
data = await rulebooks_svc.rule_detail(uid, rule, system_ids, moments)
|
||||
data.update(dedup_svc.overlap_response(overlaps, "rule"))
|
||||
@@ -675,6 +695,7 @@ async def update_rule(
|
||||
moments: list[str] | None = None, arose_from_id: int = 0,
|
||||
verify_with: str = "", expires_when: str = "", kind: str = "",
|
||||
clear_fields: list[str] | None = None,
|
||||
enforcement: str = "", salience: str = "",
|
||||
) -> dict:
|
||||
"""Update a rule. Empty strings / order_index=-1 leave fields unchanged.
|
||||
|
||||
@@ -735,6 +756,15 @@ async def update_rule(
|
||||
expires_when: The state under which the rule stops being true. A
|
||||
state, not a date. See create_rule.
|
||||
clear_fields: Names of fields to empty, as above.
|
||||
enforcement: What this rule does when it arrives. `inform` (the
|
||||
default for a new rule) puts a line beside the work. `hold` makes the reply or
|
||||
act it governs wait for one read of it — for a rule whose miss
|
||||
costs a rewrite. `enforce` checks the act itself — for a hard
|
||||
boundary. Declare hold or enforce on purpose; most rules inform.
|
||||
salience: `high`, `normal` (the default) or `low` — how this record
|
||||
ranks against others of the same enforcement when a moment has
|
||||
more to say than fits.
|
||||
Omit either to leave it unchanged.
|
||||
"""
|
||||
uid = current_user_id()
|
||||
moments = moments_svc.require_moments(moments)
|
||||
@@ -759,6 +789,10 @@ async def update_rule(
|
||||
fields["expires_when"] = expires_when
|
||||
if order_index >= 0:
|
||||
fields["order_index"] = order_index
|
||||
if enforcement:
|
||||
fields["enforcement"] = enforcement
|
||||
if salience:
|
||||
fields["salience"] = salience
|
||||
rule = await rulebooks_svc.update_rule(
|
||||
rule_id, uid, clear=clear_fields or (), **fields,
|
||||
)
|
||||
@@ -786,7 +820,7 @@ async def create_preference(
|
||||
arose_from_id: int, why: str = "", how_to_apply: str = "",
|
||||
order_index: int = 0, system_ids: list[int] | None = None,
|
||||
moments: list[str] | None = None,
|
||||
force: bool = False,
|
||||
force: bool = False, salience: str = "normal",
|
||||
) -> dict:
|
||||
"""Record how the operator wants work done. No approval loop — write it.
|
||||
|
||||
@@ -860,6 +894,9 @@ async def create_preference(
|
||||
done rather than what it is about: a rule on when work counts as
|
||||
finished belongs at work.finish and reply.report, where nothing
|
||||
said resembles it. Replaces the set; [] clears it.
|
||||
salience: `high`, `normal` (the default) or `low` — how this record
|
||||
ranks against others of the same enforcement when a moment has
|
||||
more to say than fits.
|
||||
force: Bypass the near-duplicate gate. For a genuinely distinct
|
||||
preference, not for one that is "mostly" different — a mostly
|
||||
different preference is an update. A RULE that already answers
|
||||
@@ -893,6 +930,7 @@ async def create_preference(
|
||||
title=title, statement=statement, when_to_apply=when_to_apply,
|
||||
kind="preference", arose_from_id=arose_from_id,
|
||||
why=why, how_to_apply=how_to_apply, order_index=order_index,
|
||||
salience=salience,
|
||||
)
|
||||
data = await rulebooks_svc.rule_detail(uid, rule, system_ids, moments)
|
||||
data.update(dedup_svc.overlap_response(overlaps, "preference"))
|
||||
@@ -905,6 +943,7 @@ async def update_preference(
|
||||
how_to_apply: str = "", order_index: int = -1,
|
||||
system_ids: list[int] | None = None,
|
||||
moments: list[str] | None = None, clear_fields: list[str] | None = None,
|
||||
salience: str = "",
|
||||
) -> dict:
|
||||
"""Bring a preference up to date. Doing this mid-work is expected.
|
||||
|
||||
@@ -959,6 +998,10 @@ async def update_preference(
|
||||
moments: Replaces the moments this preference arrives at (see
|
||||
create_preference); omit to leave them alone.
|
||||
when_to_apply: The moment it applies, in session vocabulary. See above.
|
||||
salience: `high`, `normal` (the default) or `low` — how this record
|
||||
ranks against others of the same enforcement when a moment has
|
||||
more to say than fits.
|
||||
Omit to leave it unchanged.
|
||||
"""
|
||||
uid = current_user_id()
|
||||
moments = moments_svc.require_moments(moments)
|
||||
@@ -981,6 +1024,8 @@ async def update_preference(
|
||||
fields["how_to_apply"] = how_to_apply
|
||||
if order_index >= 0:
|
||||
fields["order_index"] = order_index
|
||||
if salience:
|
||||
fields["salience"] = salience
|
||||
rule = await rulebooks_svc.update_rule(
|
||||
rule_id, uid, clear=clear_fields or (), **fields,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user