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 `` / `