CI & Build / TypeScript typecheck (push) Successful in 41s
CI & Build / Plugin hooks (push) Successful in 17s
CI & Build / Python lint (push) Successful in 3s
CI & Build / Python tests (push) Failing after 1m41s
CI & Build / integration (push) Successful in 1m59s
CI & Build / Build & push image (push) Skipped
Every rule arm now ranks what it delivers with one function (services/rule_order.py): enforcement, then salience, then how narrowly the rule was reached, then first mention before reminder, then the rule's own open rate at that moment, then similarity. A crowded moment drops the same rules whichever arm brought them, and a rule that holds is never cut for a line beside it. The open rate comes from a new table, rule_deliveries (migration 0129): one row per rule line a plugin session is shown, full or repeat, with the open stamped on the latest delivery it followed. The plugin routes bind the session per request; the prompt, pre-tool and write-path hooks now send it, and the opened hook reports every open, with its acts only when no hook had just named the rule. Rows are pruned daily after 180 days. Also fixes the TypeScript check: the store's list row now carries the new enforcement field. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
"""rule deliveries — each rule line a session was shown, and whether it was opened after
|
|
|
|
Revision ID: 0129
|
|
Revises: 0128
|
|
Create Date: 2026-11-22
|
|
|
|
One row per rule line delivered to a session, with the open stamped on the
|
|
delivery it followed. The open rate per rule and moment is read from it, both
|
|
for the ordering of what reaches a moment and for the adherence readout.
|
|
"""
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
|
|
revision = "0129"
|
|
down_revision = "0128"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"rule_deliveries",
|
|
sa.Column("id", sa.BigInteger(), primary_key=True),
|
|
sa.Column("user_id", sa.BigInteger(), nullable=False),
|
|
sa.Column("session_id", sa.Text(), nullable=False),
|
|
sa.Column("rule_id", sa.BigInteger(), nullable=False),
|
|
sa.Column("source", sa.Text(), nullable=False),
|
|
sa.Column("at", sa.Text(), nullable=False),
|
|
sa.Column("form", sa.Text(), nullable=False),
|
|
sa.Column("delivered_at", sa.DateTime(timezone=True), nullable=False,
|
|
server_default=sa.func.now()),
|
|
sa.Column("opened_at", sa.DateTime(timezone=True), nullable=True),
|
|
sa.CheckConstraint("form IN ('full', 'repeat')", name="ck_rule_deliveries_form"),
|
|
)
|
|
op.create_index("ix_rule_deliveries_session_rule", "rule_deliveries",
|
|
["user_id", "session_id", "rule_id", "delivered_at"])
|
|
op.create_index("ix_rule_deliveries_rule_at", "rule_deliveries", ["rule_id", "at"])
|
|
op.create_index("ix_rule_deliveries_delivered_at", "rule_deliveries", ["delivered_at"])
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_table("rule_deliveries")
|