fix(lighthouse): ask for clarification on unknown routes

This commit is contained in:
冰朔 2026-09-11 12:57:06 +08:00
commit 9844d8b695
2 changed files with 49 additions and 11 deletions

View file

@ -64,6 +64,28 @@ def resolve_intent(host_map: dict, text: str) -> dict | None:
return max(scored, default=(0, "", None))[2]
def clarification_prompt(host_map: dict, host_name: str, intent_text: str, reason: str) -> dict:
examples = [
{
"intent_id": intent["id"],
"target_id": intent.get("target_id"),
"examples": intent.get("phrases", [])[:2],
}
for intent in host_map.get("intents", [])[:8]
]
if reason == "HOST_UNKNOWN_NO_GUESS":
question = f"我还不知道要用哪个宿主来处理“{intent_text}”。你要我在 Codex、Qoder、Qwen 还是 Doubao 上继续?"
else:
question = f"我暂时找不到“{intent_text}”对应的已登记路径。你要我查哪个频道、系统、仓库或办公室?请直接说名称或编号。"
return {
"required": True,
"question": question,
"reason": "UNKNOWN_ROUTE_IS_CLARIFIABLE_NOT_EXECUTABLE",
"examples": examples,
"can_continue_after_answer": True,
}
def resolve_path(registry: dict, route_id: str) -> dict:
for path in registry["paths"]:
if path["id"].upper() == route_id.upper():
@ -99,10 +121,22 @@ def keychain_helper_status() -> dict:
def compile_route(registry: dict, host_map: dict, host_name: str, intent_text: str) -> dict:
host = resolve_host(host_map, host_name)
if not host:
return {"decision": "BLOCK", "error": "HOST_UNKNOWN_NO_GUESS", "requested_host": host_name}
return {
"decision": "CLARIFY",
"error": "HOST_UNKNOWN_NO_GUESS",
"requested_host": host_name,
"clarification": clarification_prompt(host_map, host_name, intent_text, "HOST_UNKNOWN_NO_GUESS"),
"authority_granted": False,
}
intent = resolve_intent(host_map, intent_text)
if not intent:
return {"decision": "BLOCK", "error": "INTENT_UNKNOWN_NO_GUESS", "requested_intent": intent_text}
return {
"decision": "CLARIFY",
"error": "INTENT_UNKNOWN_NO_GUESS",
"requested_intent": intent_text,
"clarification": clarification_prompt(host_map, host_name, intent_text, "INTENT_UNKNOWN_NO_GUESS"),
"authority_granted": False,
}
target = resolve_path(registry, intent["target_id"])
if target["status"] != "VALID_REGISTERED":
return {"decision": "BLOCK", "error": "LIGHTHOUSE_TARGET_INVALID", "target": target}