diff --git a/skills/shared/guanghu-lighthouse-navigator/scripts/resolve_lighthouse_route.py b/skills/shared/guanghu-lighthouse-navigator/scripts/resolve_lighthouse_route.py index facc421..e9340ec 100644 --- a/skills/shared/guanghu-lighthouse-navigator/scripts/resolve_lighthouse_route.py +++ b/skills/shared/guanghu-lighthouse-navigator/scripts/resolve_lighthouse_route.py @@ -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} diff --git a/skills/shared/guanghu-lighthouse-navigator/scripts/test_resolve_lighthouse_route.py b/skills/shared/guanghu-lighthouse-navigator/scripts/test_resolve_lighthouse_route.py index 16863aa..e8aa120 100644 --- a/skills/shared/guanghu-lighthouse-navigator/scripts/test_resolve_lighthouse_route.py +++ b/skills/shared/guanghu-lighthouse-navigator/scripts/test_resolve_lighthouse_route.py @@ -30,15 +30,19 @@ class LighthouseNavigatorTests(unittest.TestCase): self.assertEqual(qoder["intent"]["skill_id"], work["intent"]["skill_id"]) self.assertNotEqual(qoder["host"]["adapter_path"], work["host"]["adapter_path"]) - def test_unknown_host_and_intent_fail_closed(self): - self.assertEqual( - compile_route(self.registry, self.host_map, "mystery", "推一下线上仓库")["error"], - "HOST_UNKNOWN_NO_GUESS", - ) - self.assertEqual( - compile_route(self.registry, self.host_map, "codex", "今天吃什么")["error"], - "INTENT_UNKNOWN_NO_GUESS", - ) + def test_unknown_host_and_intent_request_clarification_without_navigation(self): + unknown_host = compile_route(self.registry, self.host_map, "mystery", "推一下线上仓库") + self.assertEqual(unknown_host["decision"], "CLARIFY") + self.assertEqual(unknown_host["error"], "HOST_UNKNOWN_NO_GUESS") + self.assertTrue(unknown_host["clarification"]["required"]) + self.assertIn("哪个宿主", unknown_host["clarification"]["question"]) + + unknown_intent = compile_route(self.registry, self.host_map, "codex", "今天吃什么") + self.assertEqual(unknown_intent["decision"], "CLARIFY") + self.assertEqual(unknown_intent["error"], "INTENT_UNKNOWN_NO_GUESS") + self.assertTrue(unknown_intent["clarification"]["required"]) + self.assertIn("哪个频道、系统、仓库或办公室", unknown_intent["clarification"]["question"]) + self.assertFalse(unknown_intent["authority_granted"]) def test_old_repository_is_redirect_only(self): from resolve_lighthouse_route import resolve_path