From 953a3fbba199134f48774a2f96903b4fb23f7b8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BB=9D=E5=B0=98?= <237809796@qq.com> Date: Sun, 2 Aug 2026 02:21:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96:=20prompt=20=E7=AD=96?= =?UTF-8?q?=E7=95=A5(obscura=20=E5=A4=B1=E8=B4=A5=E9=87=8D=E8=AF=95=20+=20?= =?UTF-8?q?=E7=B2=BE=E7=A1=AE=E4=B8=8D=E7=8C=9C=20+=20=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E8=81=8C=E8=B4=A3=20+=20get=5Fapp=5Fconfig=20=E5=BC=95?= =?UTF-8?q?=E5=AF=BC)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit obscura render 失败 2 次换方案 + 成功即收手;精确提取链接不臆造 URL;fetch_url/download_file /http_request 职责区分;get_app_config 引导(禁 run_command 查配置)。 --- src-tauri/src/commands/ai/prompt.rs | 138 ++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) diff --git a/src-tauri/src/commands/ai/prompt.rs b/src-tauri/src/commands/ai/prompt.rs index 1af5d77..8488393 100644 --- a/src-tauri/src/commands/ai/prompt.rs +++ b/src-tauri/src/commands/ai/prompt.rs @@ -135,6 +135,17 @@ fn doc_exploration_strategy_section(lang: &str) -> &'static str { match lang { "en" => "\n\ ## Documentation Exploration Strategy\n\ + ### Pick the right URL tool first (do NOT mix them up)\n\ + Three URL tools exist — using the wrong one fails and wastes round-trips:\n\ + - `fetch_url`: read a URL and convert to markdown (**HTML docs only**; refuses binary/images/files). For web pages, API docs, blog posts.\n\ + - `download_file`: **download any file** (image / archive / binary / document) to local disk. Streaming, binary-safe, never goes into the prompt.\n\ + - `http_request`: call an API (POST / auth / raw JSON response). For REST endpoints, webhooks, structured payloads.\n\ + Hard rule by URL kind:\n\ + 1. **Image / archive / binary file URL** (e.g. `.png` `.jpg` `.zip` `.pdf` `.exe` `.tar.gz`) → use `download_file`. Never `fetch_url` (it rejects binary) and never `run_command` curl (fails on Windows alias/encoding).\n\ + 2. **Web page / doc URL** (HTML the browser would render) → use `fetch_url`.\n\ + 3. **API endpoint URL** (returns JSON / needs auth / POST body) → use `http_request`.\n\ + If `fetch_url` ever returns an error mentioning binary content, switch to `download_file` immediately — do not retry `fetch_url` and do not fall back to `run_command` curl.\n\ + \n\ When the user gives you a URL (product page / API docs / SDK guide), follow this flow instead of blindly firing http_request at the raw URL:\n\ 1. **Sniff**: call `fetch_url` to turn the URL into clean markdown (strips HTML noise) and read what the page actually says.\n\ 2. **Identify intent**: is it an API doc (endpoints/auth), a product capability page, a config spec, or a code sample?\n\ @@ -143,6 +154,20 @@ fn doc_exploration_strategy_section(lang: &str) -> &'static str { 5. **Apply**: configure the Provider / write code / transcribe into a file via `write_file`.\n\ Rule: `fetch_url` is for *reading* a URL (docs/web/API description, markdown output); `http_request` is for *calling* an API (POST/auth/raw response). Never guess an endpoint — read the doc first, extract, then verify.\n\ \n\ + ### Extract real links — NEVER fabricate URLs\n\ + After a `fetch_url`/`http_request` returns content, do **not** invent URLs from memory or convention (no guessing `#hash` anchors, no speculating `/path` routes, no trying 'what the URL probably is'). Guessed URLs are ~99% dead (404/403) and waste round-trips. Extract the *real* links from the returned content, then fetch those verbatim:\n\ + 1. **Pull real links out of the response**: markdown `[text](url)`, HTML `` / `