Add the filter/rules engine

Implements FilterRule (one condition -> action, scoped to a feed and/or
folder or global) with an evaluation engine applied at ingest time:
after the fetch pipeline commits new/updated articles, each affected
subscriber's enabled rules run in priority order against them, with
tag/star/mark_read actions stacking and hide short-circuiting further
evaluation for that article.

Adds rule management (create/edit/delete) and a "Re-apply" action that
re-evaluates a user's full ruleset against their unread backlog, scoped
by the triggering rule's own feed/folder — so a newly added rule can
retroactively affect already-ingested articles, not just future ones.

Verified live in-browser: created a "title contains 'Show HN' -> star"
rule scoped to the subscribed Hacker News feed, re-applied it against
the existing unread backlog, and confirmed both matching articles were
starred.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
ksmithandClaude Sonnet 5 committed 2026-10-30 16:31:33 -06:00
1 parent 579696efc0
commit 5ed0499845
18 files changed
+1072 -6

No files matched your search

+111
View File
@@ -0,0 +1,111 @@
# Generated by Django 5.2.18 on 2026-10-30 22:27
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
("feeds", "0001_initial"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name="FilterRule",
fields=[
(
"id",
models.BigAutoField(
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
),
),
("name", models.CharField(blank=True, max_length=255)),
(
"match_field",
models.CharField(
choices=[
("title", "Title"),
("content", "Content"),
("author", "Author"),
("feed_title", "Feed"),
("url", "URL"),
],
max_length=20,
),
),
(
"match_type",
models.CharField(
choices=[
("contains", "Contains"),
("not_contains", "Does not contain"),
("regex", "Regex"),
("exact", "Exact match"),
],
max_length=20,
),
),
("match_value", models.CharField(max_length=500)),
("case_sensitive", models.BooleanField(default=False)),
(
"action",
models.CharField(
choices=[
("tag", "Add tag"),
("star", "Star"),
("hide", "Hide"),
("mark_read", "Mark read"),
],
max_length=20,
),
),
(
"action_value",
models.CharField(
blank=True,
help_text="Tag name, only used when action is 'Add tag'.",
max_length=100,
),
),
(
"priority",
models.PositiveIntegerField(default=0, help_text="Lower numbers run first."),
),
("is_enabled", models.BooleanField(default=True)),
(
"feed",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
to="feeds.feed",
),
),
(
"folder",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
to="feeds.folder",
),
),
(
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="filter_rules",
to=settings.AUTH_USER_MODEL,
),
),
],
options={
"ordering": ["priority", "id"],
},
),
]