feat(rules): project rule + topic suppressions
Lets a project mute individual rules or whole topics from rulebooks it subscribes to, without unsubscribing the rulebook. Two new association tables (migration 0060), 4 MCP tools (suppress/unsuppress × rule/topic), 4 REST endpoints, and an inline "× skip" affordance plus collapsed "Suppressed (N)" section in the project's Rules tab. get_applicable_rules now emits suppressed_rules and suppressed_topics (detail objects with rulebook/topic context, not just IDs) so the UI can render the suppressed list without a follow-up lookup. The main rules projection grew topic_id and rulebook_id columns for the per-row suppress affordance. Project deletion cascades the suppression rows via hard DELETE — they are pure associations with no soft-delete column, and restoring a deleted project should start fresh, not inherit stale mutes. Project-scoped rules (Rule.project_id) are deliberately not suppressible — delete them with delete_rule instead. Implements plan-task #187. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -80,6 +80,8 @@ async def enter_project(project_id: int) -> dict:
|
||||
"milestone_summary": milestone_summary,
|
||||
"applicable_rules": applicable["rules"],
|
||||
"project_rules": applicable.get("project_rules", []),
|
||||
"suppressed_rules": applicable.get("suppressed_rules", []),
|
||||
"suppressed_topics": applicable.get("suppressed_topics", []),
|
||||
"subscribed_rulebooks": applicable["subscribed_rulebooks"],
|
||||
"applicable_rules_truncated": applicable["truncated"],
|
||||
"open_tasks": [
|
||||
@@ -122,6 +124,8 @@ async def get_project(project_id: int) -> dict:
|
||||
data["applicable_rules_truncated"] = applicable["truncated"]
|
||||
data["subscribed_rulebooks"] = applicable["subscribed_rulebooks"]
|
||||
data["project_rules"] = applicable.get("project_rules", [])
|
||||
data["suppressed_rules"] = applicable.get("suppressed_rules", [])
|
||||
data["suppressed_topics"] = applicable.get("suppressed_topics", [])
|
||||
return data
|
||||
|
||||
|
||||
|
||||
@@ -364,6 +364,62 @@ async def unsubscribe_project_from_rulebook(
|
||||
return {"project_id": project_id, "rulebook_id": rulebook_id, "subscribed": False}
|
||||
|
||||
|
||||
# ── Suppressions — project-level mute of rulebook rules / topics ────────
|
||||
|
||||
async def suppress_rule_for_project(
|
||||
project_id: int, rule_id: int,
|
||||
) -> dict:
|
||||
"""Mute a single rulebook rule for one project.
|
||||
|
||||
The rule stays in its rulebook for other projects; only this project
|
||||
skips it. Idempotent. Use unsuppress_rule_for_project to re-enable.
|
||||
Project-scoped rules (create_project_rule) are NOT suppressible — delete
|
||||
them with delete_rule instead.
|
||||
"""
|
||||
uid = current_user_id()
|
||||
await rulebooks_svc.suppress_rule_for_project(
|
||||
project_id=project_id, rule_id=rule_id, user_id=uid,
|
||||
)
|
||||
return {"project_id": project_id, "rule_id": rule_id, "suppressed": True}
|
||||
|
||||
|
||||
async def unsuppress_rule_for_project(
|
||||
project_id: int, rule_id: int,
|
||||
) -> dict:
|
||||
"""Re-enable a previously-suppressed rule for one project. Idempotent."""
|
||||
uid = current_user_id()
|
||||
await rulebooks_svc.unsuppress_rule_for_project(
|
||||
project_id=project_id, rule_id=rule_id, user_id=uid,
|
||||
)
|
||||
return {"project_id": project_id, "rule_id": rule_id, "suppressed": False}
|
||||
|
||||
|
||||
async def suppress_topic_for_project(
|
||||
project_id: int, topic_id: int,
|
||||
) -> dict:
|
||||
"""Mute every rule under a topic for one project.
|
||||
|
||||
Equivalent to suppressing each rule in the topic individually, but
|
||||
auto-includes new rules added to the topic later. Idempotent.
|
||||
"""
|
||||
uid = current_user_id()
|
||||
await rulebooks_svc.suppress_topic_for_project(
|
||||
project_id=project_id, topic_id=topic_id, user_id=uid,
|
||||
)
|
||||
return {"project_id": project_id, "topic_id": topic_id, "suppressed": True}
|
||||
|
||||
|
||||
async def unsuppress_topic_for_project(
|
||||
project_id: int, topic_id: int,
|
||||
) -> dict:
|
||||
"""Re-enable a previously-suppressed topic for one project. Idempotent."""
|
||||
uid = current_user_id()
|
||||
await rulebooks_svc.unsuppress_topic_for_project(
|
||||
project_id=project_id, topic_id=topic_id, user_id=uid,
|
||||
)
|
||||
return {"project_id": project_id, "topic_id": topic_id, "suppressed": False}
|
||||
|
||||
|
||||
def register(mcp) -> None:
|
||||
for fn in (
|
||||
list_rulebooks, get_rulebook, create_rulebook, update_rulebook, delete_rulebook,
|
||||
@@ -371,5 +427,7 @@ def register(mcp) -> None:
|
||||
list_rules, list_always_on_rules, get_rule,
|
||||
create_rule, create_project_rule, update_rule, delete_rule,
|
||||
subscribe_project_to_rulebook, unsubscribe_project_from_rulebook,
|
||||
suppress_rule_for_project, unsuppress_rule_for_project,
|
||||
suppress_topic_for_project, unsuppress_topic_for_project,
|
||||
):
|
||||
mcp.tool(name=fn.__name__)(fn)
|
||||
|
||||
@@ -83,6 +83,8 @@ async def get_task(task_id: int) -> dict:
|
||||
data["subscribed_rulebooks"] = applicable["subscribed_rulebooks"]
|
||||
data["applicable_rules_truncated"] = applicable["truncated"]
|
||||
data["project_rules"] = applicable.get("project_rules", [])
|
||||
data["suppressed_rules"] = applicable.get("suppressed_rules", [])
|
||||
data["suppressed_topics"] = applicable.get("suppressed_topics", [])
|
||||
return data
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user