feat(7833): each moment declares which kinds of record its search may consider, editable in Settings > Moments
CI & Build / Python lint (push) Successful in 3s
CI & Build / Plugin hooks (push) Successful in 15s
CI & Build / TypeScript typecheck (push) Successful in 34s
CI & Build / Python tests (push) Failing after 1m35s
CI & Build / integration (push) Successful in 1m58s
CI & Build / Build & push image (push) Skipped
CI & Build / Python lint (push) Successful in 3s
CI & Build / Plugin hooks (push) Successful in 15s
CI & Build / TypeScript typecheck (push) Successful in 34s
CI & Build / Python tests (push) Failing after 1m35s
CI & Build / integration (push) Successful in 1m58s
CI & Build / Build & push image (push) Skipped
The kind x moment table (services/record_kinds.py): - every record search fires at a door: the operator message, or a catalog moment (work.change for the write path); - each door considers a set of kinds (snippet, note, lesson, process, task:issue/work/spike/plan); a kind left out is never searched there; - the shipped defaults are today's behaviour; a user's change is stored per door, and putting a door back removes it. Both note arms read it, replacing their fixed kind lists, and a reserved slot whose kind is turned off is not reserved. The review re-run searches the same kinds. Settings > Moments shows and edits the table, with each cell's lines shown and opens from the record ledger. list_moments returns it as record_kinds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -35,7 +35,7 @@ import time
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any, Callable
|
||||
|
||||
from grimoire.services import cue_gate, rule_order
|
||||
from grimoire.services import cue_gate, record_kinds, rule_order
|
||||
from grimoire.services.lessons import LESSON_NOTE_TYPE, claim_line
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -1124,8 +1124,11 @@ class NoteArm:
|
||||
surfaced_as: str
|
||||
"""The `source` its surfacing rows carry."""
|
||||
|
||||
note_type: tuple[str, ...] | None = None
|
||||
task_kind: str | None = None
|
||||
door: str = record_kinds.MESSAGE
|
||||
"""Its row in the kind×moment table (`record_kinds.DOORS`): the kinds it
|
||||
may consider come from there, the user's own or the shipped default, and
|
||||
a kind absent there is unreachable from this arm, not merely outranked."""
|
||||
|
||||
include_global_kinds: bool = True
|
||||
"""Lessons are project-independent, so they join the candidate set
|
||||
from wherever they were learned."""
|
||||
@@ -1150,7 +1153,7 @@ class NoteArm:
|
||||
|
||||
AUTO_INJECT = NoteArm(
|
||||
"auto_inject", surfaced_as="auto_inject", slots=(REUSE_SLOT, LESSON_SLOT),
|
||||
gated=True,
|
||||
door=record_kinds.MESSAGE, gated=True,
|
||||
tuning=Surface(
|
||||
name="auto_inject",
|
||||
floor_key="kb_autoinject_threshold",
|
||||
@@ -1163,17 +1166,13 @@ AUTO_INJECT = NoteArm(
|
||||
),
|
||||
declared=Declared("the notes menu offered at the prompt boundary"),
|
||||
)
|
||||
# Snippets AND recorded experience: an issue saying "we tried this and it
|
||||
# deadlocked" is prior art for the code about to be written. `task_kind`
|
||||
# keeps the open to-do list out — a task resembles the code and answers
|
||||
# nothing. Lessons too: the arm is kind-FILTERED, so a kind absent here is
|
||||
# unreachable, not merely outranked. No reserved
|
||||
# slot: this arm fires before every Write and Edit, and the field is already
|
||||
# narrow enough that the 200:1 dilution a slot answers does not happen.
|
||||
# The kinds it considers are the `work.change` row of the kind×moment table,
|
||||
# where the default and its reasons live. No reserved slot: this arm fires
|
||||
# before every Write and Edit, and the field is already narrow enough that the
|
||||
# 200:1 dilution a slot answers does not happen.
|
||||
WRITE_PATH = NoteArm(
|
||||
"write_path", surfaced_as="write_path_semantic",
|
||||
note_type=("snippet", "note", LESSON_NOTE_TYPE), task_kind="issue",
|
||||
withholds=True, gated=True,
|
||||
door="work.change", withholds=True, gated=True,
|
||||
tuning=Surface(
|
||||
name="write_path",
|
||||
floor_key="kb_writepath_threshold",
|
||||
@@ -1201,16 +1200,13 @@ NOTE_SURFACED_SOURCES: tuple[str, ...] = (
|
||||
|
||||
|
||||
def note_search_filters(arm: NoteArm) -> dict:
|
||||
"""The arm's constant search keywords — which kinds, whose records.
|
||||
"""The arm's constant search keywords — whose records. Which kinds is the
|
||||
kind×moment table's, per user (`record_kinds.kinds_for`).
|
||||
|
||||
Read by `retrieval_review` too: a re-run that searched with different
|
||||
visibility or kinds from the arm's would judge a menu nobody was shown.
|
||||
"""
|
||||
out: dict = {}
|
||||
if arm.note_type:
|
||||
out["note_type"] = arm.note_type
|
||||
if arm.task_kind:
|
||||
out["task_kind"] = arm.task_kind
|
||||
if arm.include_global_kinds:
|
||||
out["include_global_kinds"] = True
|
||||
out["scope"] = arm.scope
|
||||
@@ -1253,6 +1249,11 @@ class NoteMoment:
|
||||
"""Of `in_menu`, those the search must still score (a pulled snippet's
|
||||
resemblance to the payload is evidence for the shape ledger)."""
|
||||
|
||||
kinds: frozenset[str] | None = None
|
||||
"""The kinds this user's door considers (`record_kinds.kinds_for`). None
|
||||
is the door's shipped default; an empty set means the arm searches
|
||||
nothing."""
|
||||
|
||||
|
||||
@dataclass
|
||||
class NoteResult:
|
||||
@@ -1293,8 +1294,10 @@ def _note_band(hits: list) -> list:
|
||||
async def _reserve_note_slot(
|
||||
io: NoteIO, arm: NoteArm, slot: NoteSlot, moment: NoteMoment, menu: list,
|
||||
*, floor: float, budget: int, shown: set[int], capped: bool = False,
|
||||
kinds: tuple[str, ...] | None = None,
|
||||
) -> tuple[list, int | None]:
|
||||
"""Guarantee `slot.kinds` one line, if one clears the arm's own bar.
|
||||
"""Guarantee `kinds` (the slot's kinds the door allows; all of
|
||||
`slot.kinds` by default) one line, if one clears the arm's own bar.
|
||||
|
||||
WHY A SLOT AT ALL. Ranking by raw cosine is blind to what KIND of record
|
||||
answers what kind of ask, and the corpus makes that fatal: Grimoire's
|
||||
@@ -1319,7 +1322,8 @@ async def _reserve_note_slot(
|
||||
|
||||
Returns the possibly-changed menu and the id the slot spent.
|
||||
"""
|
||||
if any(_record_kind(n) in slot.kinds for _s, n in menu):
|
||||
kinds = kinds or slot.kinds
|
||||
if any(_record_kind(n) in kinds for _s, n in menu):
|
||||
return menu, None
|
||||
# Under the gate the budget is a ceiling for every line, so a slot that
|
||||
# only extends has no room once the menu is full.
|
||||
@@ -1333,7 +1337,7 @@ async def _reserve_note_slot(
|
||||
"limit": 1, "threshold": floor, "project_id": moment.project_id or None,
|
||||
"exclude_ids": set(on_menu),
|
||||
# KIND-FILTERED, so the slot can only be spent on what it is for.
|
||||
"note_type": slot.kinds, "scope": arm.scope, "report": report,
|
||||
"note_type": kinds, "scope": arm.scope, "report": report,
|
||||
}
|
||||
if slot.include_global_kinds:
|
||||
kwargs["include_global_kinds"] = True
|
||||
@@ -1357,7 +1361,7 @@ async def _reserve_note_slot(
|
||||
# this menu already carries.
|
||||
placed = [
|
||||
(s, n) for s, n in found
|
||||
if _record_kind(n) in slot.kinds and int(n.id) not in on_menu
|
||||
if _record_kind(n) in kinds and int(n.id) not in on_menu
|
||||
][:1]
|
||||
if not placed:
|
||||
return menu, None
|
||||
@@ -1394,6 +1398,15 @@ async def run_note_arm(
|
||||
search → withhold this response's menu → fresh/repeat split → call row →
|
||||
band → reserved slots → surfacing rows. Fails open to an empty result.
|
||||
"""
|
||||
allowed = (
|
||||
moment.kinds if moment.kinds is not None
|
||||
else record_kinds.DOORS[arm.door].default
|
||||
)
|
||||
if not allowed:
|
||||
# The table turned every kind off at this door: nothing is searched,
|
||||
# so no call row either; a row would read as a search that found
|
||||
# nothing.
|
||||
return NoteResult()
|
||||
try:
|
||||
gate = (
|
||||
await _gate(io, moment.user_id, arm.source, moment.project_id)
|
||||
@@ -1408,6 +1421,7 @@ async def run_note_arm(
|
||||
"limit": budget + len(scored), "threshold": floor,
|
||||
"project_id": moment.project_id or None,
|
||||
**note_search_filters(arm), "report": report,
|
||||
"record_kinds": record_kinds.search_kinds(allowed),
|
||||
}
|
||||
if arm.withholds:
|
||||
kwargs["exclude_ids"] = set(moment.in_menu - scored)
|
||||
@@ -1479,9 +1493,14 @@ async def run_note_arm(
|
||||
# a slot that picks one does not book a surfacing the lookup booked.
|
||||
shown = set(moment.seen | moment.named)
|
||||
for slot in arm.slots:
|
||||
# A slot reserves a line for a kind; one the table turned off at
|
||||
# this door has nothing to reserve it for.
|
||||
kinds = tuple(k for k in slot.kinds if k in allowed)
|
||||
if not kinds:
|
||||
continue
|
||||
menu, slot_id = await _reserve_note_slot(
|
||||
io, arm, slot, moment, menu, floor=floor, budget=budget,
|
||||
shown=shown, capped=gate is not None,
|
||||
shown=shown, capped=gate is not None, kinds=kinds,
|
||||
)
|
||||
if slot_id is not None:
|
||||
result.slot_ids[slot.source] = slot_id
|
||||
|
||||
Reference in New Issue
Block a user