feat(inject): label the record kind on each auto-inject menu line
Every injected hit rendered identically, so a recorded snippet was indistinguishable from a stray dev-log in the one place prior art most needs to stand out. Each line now carries its kind — [snippet], [process], [task], [issue], [note] — and the header says "records" rather than "notes", which it can no longer claim. Task-ness wins over note_type in the marker: "there's an open issue about this" is the more useful thing to know at a glance. Still title-first: the marker is metadata already on the ORM object, so no extra query and no bodies (#2084). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RLwAaV4DQEmVyn496HnEvt
This commit is contained in:
@@ -163,6 +163,22 @@ async def get_autoinject_config(user_id: int) -> dict:
|
|||||||
return {"enabled": enabled, "threshold": threshold, "top_k": top_k}
|
return {"enabled": enabled, "threshold": threshold, "top_k": top_k}
|
||||||
|
|
||||||
|
|
||||||
|
def _record_kind(note) -> str:
|
||||||
|
"""The one-word kind marker for an injected menu line.
|
||||||
|
|
||||||
|
The menu is drawn from every record that carries an embedding, so a snippet,
|
||||||
|
a stored process, an issue and a stray dev-log all arrive looking identical.
|
||||||
|
Recorded prior art only stands out if the line says what it is — and the kind
|
||||||
|
is also what tells the reader which tool opens it.
|
||||||
|
|
||||||
|
Task-ness wins over `note_type` because it's the more useful distinction at a
|
||||||
|
glance: "there's an open issue about this" beats "there's a note about this".
|
||||||
|
"""
|
||||||
|
if note.is_task:
|
||||||
|
return "issue" if note.task_kind == "issue" else "task"
|
||||||
|
return note.note_type or "note"
|
||||||
|
|
||||||
|
|
||||||
async def build_autoinject_hint(
|
async def build_autoinject_hint(
|
||||||
user_id: int,
|
user_id: int,
|
||||||
query: str,
|
query: str,
|
||||||
@@ -175,7 +191,7 @@ async def build_autoinject_hint(
|
|||||||
1. high-confidence threshold (stricter than pull) — set per-user;
|
1. high-confidence threshold (stricter than pull) — set per-user;
|
||||||
2. margin gate — keep only hits within _AUTOINJECT_BAND of the top score;
|
2. margin gate — keep only hits within _AUTOINJECT_BAND of the top score;
|
||||||
3. session dedup — caller passes already-injected ids as `exclude_ids`;
|
3. session dedup — caller passes already-injected ids as `exclude_ids`;
|
||||||
4. title-first payload — id + title + score only, never bodies.
|
4. title-first payload — id + kind + title + score only, never bodies.
|
||||||
Disabled, blank-query, or nothing-clears-the-gates all return empty context,
|
Disabled, blank-query, or nothing-clears-the-gates all return empty context,
|
||||||
so most turns inject nothing.
|
so most turns inject nothing.
|
||||||
|
|
||||||
@@ -222,15 +238,19 @@ async def build_autoinject_hint(
|
|||||||
int(n.user_id) for _s, n in kept if n.user_id != user_id
|
int(n.user_id) for _s, n in kept if n.user_id != user_id
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# "records", not "notes" — the menu can hold snippets, processes and tasks
|
||||||
|
# too, and the kind marker on each line is only legible if the header doesn't
|
||||||
|
# already claim they're all one thing.
|
||||||
lines = [
|
lines = [
|
||||||
"> Possibly relevant from your Scribe notes — call `get_note(id)` to "
|
"> Possibly relevant from your Scribe records — open any in full with "
|
||||||
"open any in full (titles only; injected once per session):",
|
"`get_note(id)`, or `get_snippet` / `get_process` for those kinds "
|
||||||
|
"(titles only; injected once per session):",
|
||||||
]
|
]
|
||||||
note_ids: list[int] = []
|
note_ids: list[int] = []
|
||||||
for score, note in kept:
|
for score, note in kept:
|
||||||
note_ids.append(int(note.id))
|
note_ids.append(int(note.id))
|
||||||
title = (note.title or "(untitled)").replace("\n", " ").strip()
|
title = (note.title or "(untitled)").replace("\n", " ").strip()
|
||||||
line = f"> - #{note.id} \"{title}\" ({score:.2f})"
|
line = f"> - #{note.id} [{_record_kind(note)}] \"{title}\" ({score:.2f})"
|
||||||
if note.user_id != user_id:
|
if note.user_id != user_id:
|
||||||
who = owners.get(int(note.user_id)) or "another user"
|
who = owners.get(int(note.user_id)) or "another user"
|
||||||
line += f" — shared by {who}, treat as a suggestion"
|
line += f" — shared by {who}, treat as a suggestion"
|
||||||
|
|||||||
@@ -17,15 +17,19 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
def _note(id=1, user_id=7, title="A note"):
|
def _note(id=1, user_id=7, title="A note", note_type="note",
|
||||||
|
is_task=False, task_kind="work"):
|
||||||
n = MagicMock()
|
n = MagicMock()
|
||||||
n.id = id
|
n.id = id
|
||||||
n.user_id = user_id
|
n.user_id = user_id
|
||||||
n.title = title
|
n.title = title
|
||||||
n.body = "body"
|
n.body = "body"
|
||||||
n.tags = []
|
n.tags = []
|
||||||
n.is_task = False
|
# Real values, not auto-attributes: the menu reads these to label each line,
|
||||||
n.note_type = "note"
|
# and a MagicMock is truthy — every record would render as a task (note 2109).
|
||||||
|
n.is_task = is_task
|
||||||
|
n.task_kind = task_kind
|
||||||
|
n.note_type = note_type
|
||||||
return n
|
return n
|
||||||
|
|
||||||
|
|
||||||
@@ -146,3 +150,39 @@ async def test_injected_menu_attributes_another_users_note():
|
|||||||
assert "suggestion" in theirs_line
|
assert "suggestion" in theirs_line
|
||||||
# The operator's own note stays unadorned — absence of a marker is the signal.
|
# The operator's own note stays unadorned — absence of a marker is the signal.
|
||||||
assert "shared by" not in mine_line
|
assert "shared by" not in mine_line
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_injected_menu_labels_the_record_kind():
|
||||||
|
"""Every injected line renders the same shape, so without a kind marker a
|
||||||
|
recorded snippet is indistinguishable from a stray dev-log — exactly where
|
||||||
|
prior art most needs to stand out."""
|
||||||
|
from scribe.services import plugin_context
|
||||||
|
|
||||||
|
hits = [
|
||||||
|
(0.92, _note(1, title="debounce — rate-limit a callback", note_type="snippet")),
|
||||||
|
(0.91, _note(2, title="Release checklist", note_type="process")),
|
||||||
|
(0.90, _note(3, title="Auth token expiry", is_task=True, task_kind="issue")),
|
||||||
|
(0.89, _note(4, title="Ship the drafter", is_task=True)),
|
||||||
|
(0.88, _note(5, title="Why we dropped CalDAV")),
|
||||||
|
]
|
||||||
|
with patch.object(plugin_context, "semantic_search_notes",
|
||||||
|
AsyncMock(return_value=hits)), \
|
||||||
|
patch.object(plugin_context, "get_autoinject_config",
|
||||||
|
AsyncMock(return_value={"enabled": True, "threshold": 0.5,
|
||||||
|
"top_k": 5})), \
|
||||||
|
patch.object(plugin_context, "record_retrieval", MagicMock()):
|
||||||
|
out = await plugin_context.build_autoinject_hint(7, "anything")
|
||||||
|
|
||||||
|
lines = out["context"].splitlines()
|
||||||
|
by_id = {n: next(ln for ln in lines if f"#{n} " in ln) for n in (1, 2, 3, 4, 5)}
|
||||||
|
assert "[snippet]" in by_id[1]
|
||||||
|
assert "[process]" in by_id[2]
|
||||||
|
# Task-ness wins over note_type, and an issue says so rather than "task".
|
||||||
|
assert "[issue]" in by_id[3]
|
||||||
|
assert "[task]" in by_id[4]
|
||||||
|
assert "[note]" in by_id[5]
|
||||||
|
# Still title-first: the marker is metadata, not an excuse to carry bodies.
|
||||||
|
assert "body" not in out["context"]
|
||||||
|
# The header can't claim they're all notes when the markers say otherwise.
|
||||||
|
assert "Scribe records" in lines[0]
|
||||||
|
|||||||
@@ -10,13 +10,15 @@ def _rule(rid, title, topic_id):
|
|||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
def _note(nid, title, user_id=1):
|
def _note(nid, title, user_id=1, note_type="note", is_task=False, task_kind="work"):
|
||||||
n = MagicMock()
|
n = MagicMock()
|
||||||
n.id, n.title = nid, title
|
n.id, n.title = nid, title
|
||||||
# Real int, defaulting to the caller used in these tests: the injected menu
|
# Real values, defaulting to the caller used in these tests: the injected menu
|
||||||
# compares it to decide whether the line needs a "shared by …" attribution,
|
# compares user_id to decide whether the line needs a "shared by …"
|
||||||
# and an auto-MagicMock would read as another user's note.
|
# attribution, and reads is_task/task_kind/note_type for the kind marker. An
|
||||||
|
# auto-MagicMock is truthy, so every line would read as another user's task.
|
||||||
n.user_id = user_id
|
n.user_id = user_id
|
||||||
|
n.note_type, n.is_task, n.task_kind = note_type, is_task, task_kind
|
||||||
return n
|
return n
|
||||||
|
|
||||||
|
|
||||||
@@ -79,7 +81,7 @@ async def test_build_autoinject_hint_titles_only_with_margin_gate():
|
|||||||
exclude_ids=[99])
|
exclude_ids=[99])
|
||||||
# Margin gate kept the top two, dropped the straggler.
|
# Margin gate kept the top two, dropped the straggler.
|
||||||
assert out["note_ids"] == [11, 22]
|
assert out["note_ids"] == [11, 22]
|
||||||
assert '#11 "Pool sizing decision" (0.80)' in out["context"]
|
assert '#11 [note] "Pool sizing decision" (0.80)' in out["context"]
|
||||||
assert "#33" not in out["context"]
|
assert "#33" not in out["context"]
|
||||||
# Title-first: no body text, ever.
|
# Title-first: no body text, ever.
|
||||||
assert "get_note(id)" in out["context"]
|
assert "get_note(id)" in out["context"]
|
||||||
|
|||||||
Reference in New Issue
Block a user