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
+27
View File
@@ -279,6 +279,33 @@ export interface AdherencePayload {
by_moment: MomentAdherenceRow[];
}
/** How a record arrived in front of a session. */
export type RecordWay = "pushed" | "asked" | "direct";
export interface WayCounts {
delivered: number;
opened: number;
}
export interface RecordReachKind {
/** `snippet`, `note`, `lesson`, `process`, or `task:<kind>`. */
kind: string;
ways: Record<RecordWay, WayCounts>;
sources: { way: RecordWay; source: string; delivered: number; opened: number }[];
}
export interface RecordReachPayload {
days: number;
sessions: number;
totals: Record<RecordWay, WayCounts>;
by_kind: RecordReachKind[];
}
/** How non-rule records reached sessions: pushed, asked for, or opened directly. */
export function getRecordReach(days = 30): Promise<RecordReachPayload> {
return apiGet(`/api/retrieval/record-reach?days=${days}`);
}
/** Whether the rules in force at each moment were followed there. */
export function getAdherence(days = 30): Promise<AdherencePayload> {
return apiGet(`/api/retrieval/adherence?days=${days}`);
+19 -3
View File
@@ -4,9 +4,10 @@ import { useMomentsStore } from "@/stores/moments";
import MomentProposals from "@/components/MomentProposals.vue";
import MomentRuleUsage from "@/components/MomentRuleUsage.vue";
import WeightProposals from "@/components/WeightProposals.vue";
import RecordReach from "@/components/RecordReach.vue";
import RuleAdherence from "@/components/RuleAdherence.vue";
import { getAdherence } from "@/api/moments";
import type { AdherencePayload, MomentAction, MomentAdherenceRow, MomentUsage } from "@/api/moments";
import { getAdherence, getRecordReach } from "@/api/moments";
import type { AdherencePayload, MomentAction, MomentAdherenceRow, MomentUsage, RecordReachPayload } from "@/api/moments";
import { fmtDate } from "@/utils/dateFormat";
/**
@@ -48,6 +49,20 @@ async function loadAdherence() {
}
}
// How records other than rules reach sessions, read on its own for the same
// reason as adherence.
const reach = ref<RecordReachPayload | null>(null);
const reachFailed = ref(false);
async function loadReach() {
try {
reach.value = await getRecordReach(days.value);
reachFailed.value = false;
} catch {
reachFailed.value = true;
}
}
function followed(moment: string): MomentAdherenceRow | null {
return adherence.value?.by_moment.find((m) => m.at === moment) ?? null;
}
@@ -128,7 +143,7 @@ async function addMapping() {
onMounted(async () => {
await store.load(true);
await loadAdherence();
await Promise.all([loadAdherence(), loadReach()]);
});
</script>
@@ -156,6 +171,7 @@ onMounted(async () => {
<MomentProposals />
<WeightProposals />
<RuleAdherence :data="adherence" :failed="adherenceFailed" @retry="loadAdherence" />
<RecordReach :data="reach" :failed="reachFailed" @retry="loadReach" />
<ul class="moment-list">
<li v-for="m in catalog" :key="m.name" class="moment-row">
+115
View File
@@ -0,0 +1,115 @@
<script setup lang="ts">
import { computed } from "vue";
import type { RecordReachPayload, RecordWay, WayCounts } from "@/api/moments";
/**
* How records other than rules reached sessions: shown by a hook, found by a
* search the session ran itself, or opened with nothing showing them first —
* and how many were opened each way. It says, per kind, whether a record is
* found by being pushed or by being asked for. One row per kind; open a row
* for the doors behind it.
*/
const props = defineProps<{
data: RecordReachPayload | null;
failed: boolean;
}>();
const emit = defineEmits<{ retry: [] }>();
const rows = computed(() => props.data?.by_kind ?? []);
const KIND_LABELS: Record<string, string> = {
snippet: "Snippets",
note: "Notes",
lesson: "Lessons",
process: "Processes",
"task:issue": "Issues",
"task:work": "Work tasks",
"task:spike": "Spikes",
};
function kindLabel(kind: string): string {
return KIND_LABELS[kind] ?? kind;
}
// Each way in reading order. A direct open is opened by definition, so it
// shows one number; the others show how many of those delivered were opened.
const WAYS: [RecordWay, string][] = [
["pushed", "shown by a hook"],
["asked", "from its own search"],
["direct", "opened unshown"],
];
function wayText(way: RecordWay, c: WayCounts): string {
return way === "direct" ? `${c.opened}` : `${c.opened} of ${c.delivered}`;
}
</script>
<template>
<section class="reach" aria-labelledby="reach-title">
<h3 id="reach-title" class="sub-title">How records reach the work</h3>
<p v-if="failed" class="error-msg">
Record reach could not be loaded.
<button type="button" class="btn-text" @click="emit('retry')">Try again</button>
</p>
<p v-else-if="!data" class="empty-msg">Loading record reach…</p>
<p v-else-if="!rows.length" class="empty-msg">
No record reached a session in the last {{ data.days }} days from a plugin that reports opens.
</p>
<template v-else>
<p class="field-hint">
Records opened, out of those delivered, over the last {{ data.days }} days across
{{ data.sessions }} sessions: shown by a hook, returned by a search the session ran,
or opened with nothing showing them first.
</p>
<div class="reach-totals">
<span v-for="[way, label] in WAYS" :key="way">
{{ label }} {{ wayText(way, data.totals[way]) }}
</span>
</div>
<ul class="reach-list">
<li v-for="r in rows" :key="r.kind" class="reach-kind">
<details>
<summary class="reach-row">
<span class="reach-title">{{ kindLabel(r.kind) }}</span>
<span class="reach-counts">
<span v-for="[way, label] in WAYS" :key="way" :class="{ 'way-none': !r.ways[way].delivered }">
{{ label }} {{ wayText(way, r.ways[way]) }}
</span>
</span>
</summary>
<ul class="reach-sources">
<li v-for="s in r.sources" :key="`${s.way}:${s.source}`" class="reach-row">
<code class="moment-name">{{ s.source }}</code>
<span class="reach-counts">
<span>{{ s.way === "direct" ? `${s.opened} opened` : `${s.opened} of ${s.delivered} opened` }}</span>
</span>
</li>
</ul>
</details>
</li>
</ul>
</template>
</section>
</template>
<style scoped>
.reach { display: flex; flex-direction: column; gap: var(--fs-space-2); }
.sub-title { margin: 0; font-size: 0.95rem; color: var(--fs-text-primary); }
.reach-totals,
.reach-counts {
display: inline-flex; flex-wrap: wrap; gap: var(--fs-space-2);
font-size: var(--fs-size-tiny); color: var(--fs-text-secondary);
font-variant-numeric: tabular-nums;
}
.reach-counts { margin-left: auto; justify-content: flex-end; }
.reach-list,
.reach-sources { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--fs-space-1); }
.reach-sources { margin: var(--fs-space-1) 0 var(--fs-space-2) var(--fs-space-4); }
.reach-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--fs-space-2); }
.reach-kind summary { cursor: pointer; }
.reach-title { font-size: var(--fs-size-body-sm); color: var(--fs-text-primary); }
/* A way that delivered nothing for this kind is a gap, not a zero to read. */
.way-none { color: var(--fs-text-tertiary); }
</style>
<style src="@/assets/moments-shared.css" />