mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-10-09 08:22:19 +02:00
Harden maintainer-preview harness and review fixes
Unify conversational domain routing, preserve artifact completion evidence, replace provisional tool-round prose with terminal synthesis, and resolve verified maintainer review findings across search, frontend module identity, path policy, configuration, and built-in skill startup.
This commit is contained in:
@@ -5,11 +5,13 @@ from __future__ import annotations
|
||||
from pathlib import Path
|
||||
from typing import Iterable
|
||||
|
||||
from src.constants import BUILTIN_SKILLS_DIR
|
||||
|
||||
from .skill_format import Skill
|
||||
from .skills import SkillsManager
|
||||
|
||||
|
||||
_BUILTIN_ROOT = Path(__file__).resolve().parents[2] / "resources" / "skills"
|
||||
_BUILTIN_ROOT = Path(BUILTIN_SKILLS_DIR)
|
||||
_SYNC_FIELDS = (
|
||||
"name",
|
||||
"description",
|
||||
@@ -40,7 +42,7 @@ def install_builtin_skills(manager: SkillsManager, owners: Iterable[str]) -> int
|
||||
Installation is safe before first-user setup because no owner identity is
|
||||
assigned and unauthenticated requests still cannot access skill routes.
|
||||
"""
|
||||
existing = {row.get("name") for row in manager.load_all()}
|
||||
existing = {row.get("name"): row for row in manager.load_all()}
|
||||
installed = 0
|
||||
paths = sorted(_BUILTIN_ROOT.rglob("SKILL.md")) if _BUILTIN_ROOT.is_dir() else []
|
||||
for path in paths:
|
||||
@@ -52,9 +54,8 @@ def install_builtin_skills(manager: SkillsManager, owners: Iterable[str]) -> int
|
||||
# available immediately and never enter the user's audit queue.
|
||||
skill.status = "published"
|
||||
skill.confidence = 1.0
|
||||
existing_rows = [row for row in manager.load_all() if row.get("name") == skill.name]
|
||||
if existing_rows:
|
||||
row = existing_rows[0]
|
||||
row = existing.get(skill.name)
|
||||
if row:
|
||||
# Built-ins are immutable tracked assets. Synchronize updated
|
||||
# versions/procedures on startup while leaving usage counters in
|
||||
# their sidecar untouched. Older startup code could also stamp the
|
||||
@@ -64,11 +65,11 @@ def install_builtin_skills(manager: SkillsManager, owners: Iterable[str]) -> int
|
||||
skill.source = "builtin"
|
||||
desired = skill.to_dict()
|
||||
if any(row.get(field) != desired.get(field) for field in _SYNC_FIELDS):
|
||||
manager._write_skill(skill)
|
||||
manager.sync_builtin_skill(skill)
|
||||
continue
|
||||
skill.owner = ""
|
||||
skill.source = "builtin"
|
||||
manager._write_skill(skill)
|
||||
existing.add(skill.name)
|
||||
manager.sync_builtin_skill(skill)
|
||||
existing[skill.name] = skill.to_dict()
|
||||
installed += 1
|
||||
return installed
|
||||
|
||||
@@ -226,6 +226,10 @@ class SkillsManager:
|
||||
sk.path = path
|
||||
return path
|
||||
|
||||
def sync_builtin_skill(self, skill: Skill) -> str:
|
||||
"""Persist a trusted built-in skill during startup synchronization."""
|
||||
return self._write_skill(skill)
|
||||
|
||||
def backfill_owner(self, primary_owner: str, valid_owners: Optional[set[str]] = None) -> int:
|
||||
"""Assign legacy/unclaimed skill files to the primary owner.
|
||||
|
||||
|
||||
+30
-8
@@ -226,6 +226,21 @@ def _meaningful_query_terms(query: str) -> list[str]:
|
||||
]
|
||||
|
||||
|
||||
# Leading function/auxiliary words carry no entity signal. They are kept out
|
||||
# of _SEARCH_QUERY_FILLER (which gates overall query meaningfulness) and
|
||||
# applied only to the document-cue entity test below, where taking the *first*
|
||||
# surviving token as the entity otherwise picks "how"/"i"/"best" and rejects
|
||||
# every genuinely relevant result.
|
||||
_QUERY_FUNCTION_WORDS = frozenset({
|
||||
"how", "to", "i", "we", "you", "your", "my", "our", "me", "us",
|
||||
"a", "an", "is", "are", "was", "were", "do", "does", "did", "can",
|
||||
"could", "should", "would", "will", "get", "getting", "got",
|
||||
"there", "here", "need", "needed", "want", "looking", "show", "give",
|
||||
"help", "best", "good", "top", "recommended", "some", "it", "its",
|
||||
"of", "in", "on", "at", "by", "or", "and", "be", "have", "has",
|
||||
})
|
||||
|
||||
|
||||
def _result_has_query_overlap(query: str, result: dict) -> bool:
|
||||
terms = _meaningful_query_terms(query)
|
||||
if not terms:
|
||||
@@ -247,7 +262,7 @@ def _result_has_query_overlap(query: str, result: dict) -> bool:
|
||||
"documentation", "docs", "pdf", "handbook",
|
||||
}
|
||||
if query_tokens & document_cues:
|
||||
entity_fillers = _SEARCH_QUERY_FILLER | document_cues | {
|
||||
entity_fillers = _SEARCH_QUERY_FILLER | document_cues | _QUERY_FUNCTION_WORDS | {
|
||||
"english", "operator", "owner", "owners", "user", "installation",
|
||||
}
|
||||
ordered_query_tokens = re.findall(r"[a-z0-9]+", str(query or "").lower())
|
||||
@@ -258,7 +273,13 @@ def _result_has_query_overlap(query: str, result: dict) -> bool:
|
||||
# Product/manual lookups are especially vulnerable to homonyms. A
|
||||
# result matching only the generic product word and "manual" is not
|
||||
# evidence for the named brand/entity in the request.
|
||||
if entity_terms and entity_terms[0] not in result_tokens:
|
||||
#
|
||||
# Test *any* entity term rather than specifically the first. Position
|
||||
# does not identify the entity: "how to configure nginx docs" leads
|
||||
# with a task verb, "best guide for sourdough" with a qualifier. A
|
||||
# result naming none of the entity terms is still rejected, which is
|
||||
# what keeps a Ford manual out of an IKEA BILLY lookup.
|
||||
if entity_terms and not (set(entity_terms) & result_tokens):
|
||||
return False
|
||||
model_numbers = {token for token in ordered_query_tokens if token.isdigit()}
|
||||
# Temporal qualifiers are not product identifiers. In particular,
|
||||
@@ -296,12 +317,13 @@ def _result_has_query_overlap(query: str, result: dict) -> bool:
|
||||
def _filter_low_relevance_results(query: str, results: list[dict]) -> list[dict]:
|
||||
if not results:
|
||||
return []
|
||||
relevant = [result for result in results
|
||||
if _result_matches_site_scope(query, result)
|
||||
and _result_has_query_overlap(query, result)]
|
||||
# Only reject a provider when it returned a fully off-topic page set. Mixed
|
||||
# result pages are common; ranking can handle those.
|
||||
return relevant if relevant else []
|
||||
scoped = [result for result in results if _result_matches_site_scope(query, result)]
|
||||
relevant = [result for result in scoped if _result_has_query_overlap(query, result)]
|
||||
# Relevance matching is intentionally conservative and cannot understand
|
||||
# every inflection or language. Keep explicit site constraints strict, but
|
||||
# let ranking handle a provider page when the heuristic rejects every
|
||||
# otherwise in-scope result.
|
||||
return relevant or scoped
|
||||
|
||||
|
||||
def _result_matches_site_scope(query: str, result: dict) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user