feat(8141): every gate that stops a tool call is recorded, with what followed
A rule set to enforce or hold, the act checkpoint and the project fence
stopped work and left no record. The hook that makes each stop now reports
it to POST /api/plugin/gate-stop; the hook decides, not the server, because
the per-rule and per-session caps are kept in the plugin.
- gate_stops table (migration 0138): gate, outcome (stopped / let_through /
asked), rule, where it was reached, tool, target project, call id.
- An open of the rule stamps the stop as cleared (rule-opened). A fenced
call that then runs stamps ran: grimoire_fence_ran.sh, a PostToolUse on
the fenced tools, matches the call id the fence left pending. That is
the operator's yes.
- A hold or checkpoint the spent session budget lets through is reported
as let_through; the per-rule once is not.
- The readout: by gate and by rule, stops, cleared by a read, misfired
(rule_misfired after it), let through by the cap, ran. In
retrieval_telemetry as `gates`, at /api/retrieval/gate-stops, and on the
Moments settings page ("When a rule stopped the work").
- act_decision carries `at`, the moment the deciding rule was reached at.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
"""gate stops: each time a Grimoire gate stood in front of a tool call
|
||||
|
||||
Revision ID: 0138
|
||||
Revises: 0137
|
||||
Create Date: 2026-11-27
|
||||
|
||||
A row per stop the plugin made: a moment rule set to enforce or hold, the
|
||||
act checkpoint, or the project fence asking the operator. With whether the
|
||||
session then opened the rule (`cleared_at`) and whether the stopped call ran
|
||||
after all (`ran_at`), so how often each gate stops work, for which rule, and
|
||||
whether it cleared the way it is meant to can be read.
|
||||
"""
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision = "0138"
|
||||
down_revision = "0137"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"gate_stops",
|
||||
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("gate", sa.Text(), nullable=False),
|
||||
sa.Column("outcome", sa.Text(), nullable=False),
|
||||
sa.Column("rule_id", sa.BigInteger(), nullable=True),
|
||||
sa.Column("tool", sa.Text(), nullable=False),
|
||||
sa.Column("at", sa.Text(), nullable=True),
|
||||
sa.Column("target", sa.Text(), nullable=True),
|
||||
sa.Column("call_id", sa.Text(), nullable=True),
|
||||
sa.Column("stopped_at", sa.DateTime(timezone=True), nullable=False,
|
||||
server_default=sa.func.now()),
|
||||
sa.Column("cleared_at", sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column("ran_at", sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column("plugin", sa.Text(), nullable=True),
|
||||
)
|
||||
op.create_index("ix_gate_stops_session_rule", "gate_stops",
|
||||
["user_id", "session_id", "rule_id", "stopped_at"])
|
||||
op.create_index("ix_gate_stops_stopped_at", "gate_stops", ["stopped_at"])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index("ix_gate_stops_stopped_at", table_name="gate_stops")
|
||||
op.drop_index("ix_gate_stops_session_rule", table_name="gate_stops")
|
||||
op.drop_table("gate_stops")
|
||||
Reference in New Issue
Block a user