feat(7730): prior art and preferences speak only past a cue-swap gate, at most two lines
CI & Build / Plugin hooks (push) Successful in 13s
CI & Build / Python lint (push) Successful in 3s
CI & Build / TypeScript typecheck (push) Successful in 37s
CI & Build / Python tests (push) Failing after 1m35s
CI & Build / integration (push) Successful in 2m1s
CI & Build / Build & push image (push) Skipped
CI & Build / Plugin hooks (push) Successful in 13s
CI & Build / Python lint (push) Successful in 3s
CI & Build / TypeScript typecheck (push) Successful in 37s
CI & Build / Python tests (push) Failing after 1m35s
CI & Build / integration (push) Successful in 2m1s
CI & Build / Build & push image (push) Skipped
A record or preference found by resemblance alone is shown only when the message's score beats all but a set share (default 10%) of the user's own recent cues on that surface and project. The comparison set is the best_available_score already logged per call, so the bar rises with the store by construction and a fixed floor no longer decides. Too few cues to judge by is silence; the searches still run and calibrate the gate. - cue_gate: conformal bar, per (user, surface, project) with a user-wide fallback, cached five minutes; readout for Settings. - Notes arms (auto_inject, write_path) abstain unless the top line passes, show at most two lines, and hold slots to the same bar and cap. - Rule arms hold preference lines to the gate; rules are not gated. - retrieval_logs gains gate_bar and gate_kept (migration 0131). - Turns the harness wrote are refused server-side as well as in the plugin. - Settings: the rate field and a per-surface readout of bar and how often each surface spoke; GET /api/retrieval/gate. - Replay test: on unrelated cues a fixed bar tuned to 5% on a 32-record store fires ~97% on 2,048 records; the gate stays near 10% at both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -20,7 +20,7 @@ import textwrap
|
||||
from dataclasses import replace
|
||||
|
||||
from grimoire.services import design_systems as design_systems_svc
|
||||
from grimoire.services import hook_payload
|
||||
from grimoire.services import cue_gate, hook_payload
|
||||
from grimoire.services import knowledge as knowledge_svc
|
||||
from grimoire.services import notes as notes_svc
|
||||
from grimoire.services import projects as projects_svc
|
||||
@@ -452,6 +452,22 @@ _NO_SUBJECT_WORDS = frozenset("""
|
||||
""".split())
|
||||
|
||||
|
||||
# A TURN THE HARNESS WROTE. Claude Code delivers a background task's
|
||||
# completion, a slash command's expansion and a local command's output as if
|
||||
# the operator had typed them. None is a question about anything, so none is
|
||||
# searched: the plugin skips them before calling, and the server refuses them
|
||||
# too, for a plugin that predates the skip.
|
||||
_HARNESS_OPENINGS = (
|
||||
"<task-notification>", "<agent-message>", "<agent-message ",
|
||||
"<command-name>", "<command-message>", "<command-args>",
|
||||
"<local-command-stdout>", "<local-command-stderr>", "<local-command-caveat>",
|
||||
)
|
||||
|
||||
|
||||
def is_harness_turn(prompt: str) -> bool:
|
||||
return (prompt or "").lstrip().startswith(_HARNESS_OPENINGS)
|
||||
|
||||
|
||||
def _has_subject(prompt: str) -> bool:
|
||||
"""Does the operator's message name anything a record could be about?
|
||||
|
||||
@@ -647,7 +663,7 @@ async def build_autoinject_hint(
|
||||
cfg = await get_autoinject_config(user_id)
|
||||
empty = {"context": "", "note_ids": [], "config": cfg}
|
||||
q = (query or "").strip()
|
||||
if not cfg["enabled"] or not q:
|
||||
if not cfg["enabled"] or not q or is_harness_turn(q):
|
||||
return empty
|
||||
# RECORDS NAMED BY NUMBER, read from the operator's own words before
|
||||
# the query is enriched: a number in the assistant's reply is not one the
|
||||
@@ -847,9 +863,15 @@ def _note_io() -> rp.NoteIO:
|
||||
search=semantic_search_notes,
|
||||
record_retrieval=record_retrieval,
|
||||
record_surfaced=record_surfaced,
|
||||
gate=_gate_for,
|
||||
)
|
||||
|
||||
|
||||
async def _gate_for(user_id: int, source: str, project_id):
|
||||
"""`cue_gate.gate_for`, read at call time like the rest of the door's IO."""
|
||||
return await cue_gate.gate_for(user_id, source, project_id)
|
||||
|
||||
|
||||
async def _rules_via_lessons(
|
||||
user_id: int, query: str, *, project_id: int | None, skip: set[int],
|
||||
held: set[int], where: str,
|
||||
@@ -951,7 +973,7 @@ async def build_prompt_rule_hint(
|
||||
"""
|
||||
out: dict = {"context": "", "rule_ids": []}
|
||||
q = (query or "").strip()
|
||||
if not q:
|
||||
if not q or is_harness_turn(q):
|
||||
return out
|
||||
# The same enrichment the notes arm gets. A rule is meant to
|
||||
# arrive while the work it governs is under way, not once the operator
|
||||
@@ -1006,6 +1028,7 @@ def _rule_io() -> rp.RuleIO:
|
||||
history=rule_deliveries.history if bound else None,
|
||||
record_delivery=rule_deliveries.record if bound else None,
|
||||
retired=rule_deliveries.retired if bound else None,
|
||||
gate=_gate_for,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user