generated from coulomb/repo-seed
session-memory: map signals to catalog recommendations via covers (WP-0010 follow-up)
Closes the gap where recurring_error suggestions showed generic 'Investigate' instead of the curated recommendation. Added a covers[] field to SolutionPattern (lowercase substrings a pattern's recommendation also applies to) + Catalog.find_for (exact key first, then covers match against signal key+locus). Retro now resolves recommendations through find_for. Tagged the read-before-edit pattern with covers=['file has not been read','modified since read','file_not_read'] (v1.0.1). Live: file-not-read suggestions across all repos now inherit 'Read the file before Edit/Write'. 6 new tests; suite 158/158. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -30,7 +30,7 @@ from .schema import SolutionPattern
|
||||
# Content fields that define a pattern's substance. Version, timestamps, status,
|
||||
# and distribution_ready are metadata — changes to them never bump the version.
|
||||
_CONTENT_KEYS = ("name", "polarity", "problem", "resolutions", "scope",
|
||||
"provenance", "rendering_hints")
|
||||
"provenance", "rendering_hints", "covers")
|
||||
|
||||
ADDED = "added"
|
||||
UNCHANGED = "unchanged"
|
||||
@@ -86,6 +86,22 @@ class Catalog:
|
||||
with open(path, encoding="utf-8") as fh:
|
||||
return [json.loads(line) for line in fh if line.strip()]
|
||||
|
||||
def find_for(self, signal_key: str, locus: str = "") -> Optional[SolutionPattern]:
|
||||
"""Best catalog pattern for a detect signal: exact id first, then ``covers``.
|
||||
|
||||
Lets a signal that doesn't share a pattern's exact key (e.g. a
|
||||
``recurring_error`` fingerprint) inherit the curated recommendation when a
|
||||
pattern declares it covers that text.
|
||||
"""
|
||||
exact = self.load(SolutionPattern.make_id(signal_key))
|
||||
if exact is not None:
|
||||
return exact
|
||||
hay = f"{signal_key} {locus}".lower()
|
||||
for p in self.list(): # sorted by id -> deterministic
|
||||
if any(c.lower() in hay for c in p.covers):
|
||||
return p
|
||||
return None
|
||||
|
||||
# --- the single write path ---------------------------------------------
|
||||
|
||||
def upsert(self, pattern: SolutionPattern) -> str:
|
||||
|
||||
Reference in New Issue
Block a user