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
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:
@@ -62,6 +62,7 @@ from grimoire.models.note_usage import NoteUsageEvent # noqa: E402, F401
|
||||
from grimoire.models.rule_usage import RuleUsageEvent # noqa: E402, F401
|
||||
from grimoire.models.rule_delivery import RuleDelivery # noqa: E402, F401
|
||||
from grimoire.models.rule_adherence import RuleAdherence # noqa: E402, F401
|
||||
from grimoire.models.record_delivery import RecordDelivery # noqa: E402, F401
|
||||
from grimoire.models.system_usage import SystemUsageEvent # noqa: E402, F401
|
||||
from grimoire.models.retrieval_judgment import RetrievalJudgment # noqa: E402, F401
|
||||
from grimoire.models.moment_mapping import MomentMapping # noqa: E402, F401
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import BigInteger, DateTime, Index, Text, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from grimoire.models import Base
|
||||
from grimoire.models.base import iso
|
||||
|
||||
# How a record came to be in front of the session.
|
||||
PUSHED = "pushed" # a hook put it there unasked (auto-inject, the write path, a slot)
|
||||
ASKED = "asked" # it was a result of a search the session ran itself
|
||||
DIRECT = "direct" # it was opened with nothing delivering it first in the session
|
||||
WAYS = (PUSHED, ASKED, DIRECT)
|
||||
|
||||
|
||||
class RecordDelivery(Base):
|
||||
"""One record put in front of one session, and whether it was opened.
|
||||
|
||||
The note-side twin of `rule_deliveries`, for every record kind that is not
|
||||
a rule (note, snippet, issue, work task, lesson, process). It answers what
|
||||
`note_usage_events` cannot: a pull there does not say which door led to
|
||||
it, so "was this note opened because a hook pushed it, because the session
|
||||
searched for it, or because the session went to it on its own" has no
|
||||
answer. Here each line is a row against its session, and the open is
|
||||
stamped on the row it followed.
|
||||
|
||||
`way` says how the record arrived (`pushed`, `asked`, `direct`). `source`
|
||||
is the door: the hook arm (`auto_inject`, `write_path_semantic`,
|
||||
`write_path_place`, `lesson_slot`, …), `mcp_search` for a search the
|
||||
session ran, or `direct`. `kind` is the record's kind when it was
|
||||
delivered (`snippet`, `note`, `lesson`, `process`, `task:issue`,
|
||||
`task:work`, …), kept on the row so the readout needs no join and survives
|
||||
the record's deletion.
|
||||
|
||||
A `direct` row is written when a session opens a record that nothing
|
||||
delivered to it within the open window — found through a cross-reference,
|
||||
a task's own id, the operator naming it. It is delivered and opened at the
|
||||
same instant, and it is the measure of records a session reaches without
|
||||
being shown them.
|
||||
|
||||
FK-free on `note_id` and `user_id`, like the other telemetry tables, and
|
||||
pruned after `rule_deliveries.RETAIN_DAYS`.
|
||||
"""
|
||||
|
||||
__tablename__ = "record_deliveries"
|
||||
|
||||
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
|
||||
user_id: Mapped[int] = mapped_column(BigInteger, nullable=False)
|
||||
session_id: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
note_id: Mapped[int] = mapped_column(BigInteger, nullable=False)
|
||||
kind: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
way: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
source: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
delivered_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), nullable=False, server_default=func.now(),
|
||||
)
|
||||
opened_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|
||||
plugin: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
|
||||
__table_args__ = (
|
||||
# Stamping an open: this session's latest delivery of this record.
|
||||
Index("ix_record_deliveries_session_note", "user_id", "session_id", "note_id", "delivered_at"),
|
||||
Index("ix_record_deliveries_delivered_at", "delivered_at"),
|
||||
)
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
return {
|
||||
"id": self.id,
|
||||
"user_id": self.user_id,
|
||||
"session_id": self.session_id,
|
||||
"note_id": self.note_id,
|
||||
"kind": self.kind,
|
||||
"way": self.way,
|
||||
"source": self.source,
|
||||
"delivered_at": iso(self.delivered_at),
|
||||
"opened_at": iso(self.opened_at),
|
||||
"plugin": self.plugin,
|
||||
}
|
||||
Reference in New Issue
Block a user