feat(7831): every record a session is shown, asks for or opens on its own is recorded per session, by kind
CI & Build / Plugin hooks (push) Successful in 18s
CI & Build / Python lint (push) Successful in 2s
CI & Build / TypeScript typecheck (push) Successful in 38s
CI & Build / Python tests (push) Successful in 1m59s
CI & Build / integration (push) Successful in 2m6s
CI & Build / Build & push image (push) Successful in 32s

A ledger beside the rule deliveries (record_deliveries, migration 0136):
- every note, snippet, issue, lesson or process line a plugin door pushes
  is recorded against the session, only when the payload kept it;
- a search the session runs itself records its results as asked, matched
  to the server log of that call;
- an open is stamped on the delivery it followed, or recorded as direct
  when nothing showed the record first.

The plugin reports opens and searches from the tool calls
(grimoire_record_read.sh). The readout is in retrieval_telemetry
(record_reach), at /api/retrieval/record-reach, and in Settings > Moments
as "How records reach the work". Plugin 2026.11.24.1827.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-24 13:27:13 -05:00
co-authored by Claude Opus 5.5
parent 394f83427d
commit b0fab00fe2
21 changed files with 951 additions and 9 deletions
+51 -1
View File
@@ -22,6 +22,7 @@ from grimoire.services import reply_shapes as reply_shapes_svc
from grimoire.services import repo_bindings as repo_bindings_svc
from grimoire.services import rule_adherence as rule_adherence_svc
from grimoire.services import report_check as report_check_svc
from grimoire.services import record_deliveries as record_deliveries_svc
from grimoire.services import rule_deliveries as rule_deliveries_svc
from grimoire.services import rule_moment_judgments as judgments_svc
from grimoire.services import shape_check as shape_check_svc
@@ -60,12 +61,14 @@ async def _bind_delivery_session() -> None:
@plugin_bp.after_request
async def _flush_deliveries(response):
"""Write any rule deliveries a door rendered without fitting a payload.
"""Write any rule and record deliveries a door rendered without fitting a
payload.
A door that fits its payload (`hook_payload.fit`) has already written the
lines it kept and dropped the rest, so this finds nothing left for it.
"""
rule_deliveries_svc.flush()
record_deliveries_svc.flush()
return response
@@ -459,6 +462,53 @@ async def rule_opened():
))
@plugin_bp.post("/record-opened")
@login_required
async def record_opened():
"""A session opened a record (a note, snippet, task, lesson or process).
Body: `{"session_id", "note_id"}`, posted by the plugin after a `get_note`,
`get_task`, `get_snippet`, `get_lesson` or `get_process` call. The open is
stamped on this session's latest delivery of the record; with none, it
is recorded as `direct`, a record reached without being shown. Answers
`{"way"}`: how the open was counted, or "" when it was not.
"""
data = await request.get_json(silent=True) or {}
if not isinstance(data, dict):
return jsonify({"way": ""})
try:
note_id = int(data.get("note_id") or 0)
except (TypeError, ValueError):
note_id = 0
if note_id <= 0:
return jsonify({"way": ""})
way = await record_deliveries_svc.mark_opened(
g.user.id, str(data.get("session_id") or ""), note_id,
plugin=rule_deliveries_svc.current_plugin(),
)
return jsonify({"way": way})
@plugin_bp.post("/record-searched")
@login_required
async def record_searched():
"""A session ran `search` itself.
Body: `{"session_id", "q"}`, posted by the plugin after the call. The
results that call returned, read from the server's own log of it, are
recorded against the session as `asked`, so an open that follows counts
as one the session reached by asking. Answers `{"recorded"}`.
"""
data = await request.get_json(silent=True) or {}
if not isinstance(data, dict):
return jsonify({"recorded": 0})
recorded = await record_deliveries_svc.from_search(
g.user.id, str(data.get("session_id") or ""), str(data.get("q") or ""),
plugin=rule_deliveries_svc.current_plugin(),
)
return jsonify({"recorded": recorded})
@plugin_bp.post("/rule-verdict")
@login_required
async def rule_verdict():
+14
View File
@@ -21,6 +21,7 @@ from grimoire.auth import get_current_user_id, login_required
from grimoire.services import moment_actions as moment_actions_svc
from grimoire.services import moments as moments_svc
from grimoire.services import reply_shapes as shapes_svc
from grimoire.services import record_deliveries as record_deliveries_svc
from grimoire.services import rule_adherence as adherence_svc
from grimoire.services import rule_field_judgments as weights_svc
from grimoire.services import rule_moment_judgments as judgments_svc
@@ -258,6 +259,19 @@ async def adherence_route():
))
@retrieval_bp.route("/record-reach", methods=["GET"])
@login_required
async def record_reach_route():
"""How non-rule records reached this user's sessions: per kind, pushed by
a hook, returned by the session's own search, or opened directly, and how
many were opened each way. `?days=` sets the window (default 30)."""
try:
days = int(request.args.get("days") or 30)
except ValueError:
return jsonify({"error": "days must be a whole number"}), 400
return jsonify(await record_deliveries_svc.summary(get_current_user_id(), days=days))
@retrieval_bp.route("/weights/proposals", methods=["GET"])
@login_required
async def weight_proposals_route():