MCPcopy Create free account
hub / github.com/Ishabdullah/Codey-v2 / _update_preference

Method _update_preference

core/preferences.py:380–417  ·  view source on GitHub ↗

Update a preference with new evidence. Args: key: Preference category value: Detected value confidence: Confidence level (0.0-1.0)

(self, key: str, value: str, confidence: float = 0.3)

Source from the content-addressed store, hash-verified

378 return found
379
380 def _update_preference(self, key: str, value: str, confidence: float = 0.3):
381 """
382 Update a preference with new evidence.
383
384 Args:
385 key: Preference category
386 value: Detected value
387 confidence: Confidence level (0.0-1.0)
388 """
389 if key not in self._cache:
390 self._cache[key] = {
391 "value": value,
392 "confidence": confidence,
393 "observations": 1,
394 }
395 else:
396 current = self._cache[key]
397 # Exponential moving average
398 alpha = confidence
399 if current["value"] == value:
400 # Same value - increase confidence
401 current["confidence"] = min(1.0, current["confidence"] + alpha * 0.2)
402 current["observations"] += 1
403 else:
404 # Different value - weighted average
405 old_weight = 1.0 - alpha
406 new_weight = alpha
407 if current["confidence"] > 0.7:
408 # Strong existing preference, don't change easily
409 return
410 current["value"] = value
411 current["confidence"] = confidence
412 current["observations"] += 1
413
414 self._save_preferences()
415 # Mirror high-confidence preferences to CODEY.md Conventions section
416 if self._cache.get(key, {}).get("confidence", 0) >= 0.8:
417 self._sync_to_codeymd(key, value)
418
419 def _sync_to_codeymd(self, key: str, value: str):
420 """Write a learned preference into the Conventions section of CODEY.md."""

Callers 4

learn_from_fileMethod · 0.95
learn_from_filesMethod · 0.95
learn_from_messageMethod · 0.95
learn_from_correctionMethod · 0.95

Calls 3

_save_preferencesMethod · 0.95
_sync_to_codeymdMethod · 0.95
getMethod · 0.45

Tested by

no test coverage detected