================================================================================
  SindByte MCP Server -- Qwen Code CLI Setup Guide
  Connecting Alibaba Qwen Code to Your Local Endpoint
================================================================================
Date: 2026-04-17
For: SindByte Server v1.9.09

--------------------------------------------------------------------------------
 1. WHAT IS QWEN CODE CLI?
--------------------------------------------------------------------------------
Qwen Code CLI is Alibaba's official terminal-based coding assistant
for the Qwen family of models. It is NOT the same as OpenCode or Codex.

  Official source:   https://github.com/QwenLM/qwen-code
  Install command:   npm install -g @qwen-code/qwen-code
  Config file:       ~/.qwen/settings.json

--------------------------------------------------------------------------------
 2. REQUIRED INFORMATION
--------------------------------------------------------------------------------
  SindByte Base URL:   http://127.0.0.1:8091/v1
  API Key:             sk-sindbyte-local   (or any text -- not checked)

  IMPORTANT: SindByte must be running before you start Qwen Code.

--------------------------------------------------------------------------------
 3. INSTALL QWEN CODE CLI
--------------------------------------------------------------------------------
  STEP 1 -- Open PowerShell and install:

    npm install -g @qwen-code/qwen-code

  STEP 2 -- Verify installation:

    qwen --version

--------------------------------------------------------------------------------
 4. CONFIGURE QWEN CODE FOR SINDBYTE
--------------------------------------------------------------------------------
Qwen Code uses standard OPENAI-compatible environment variables.

  STEP 1 -- Set these environment variables in your terminal:

    set OPENAI_API_KEY=sk-sindbyte-local
    set OPENAI_BASE_URL=http://127.0.0.1:8091/v1
    set OPENAI_MODEL=LMDirect

  STEP 2 -- Make permanent (Windows):
    Win+R -> sysdm.cpl -> Advanced -> Environment Variables
    Add:
      OPENAI_API_KEY  = sk-sindbyte-local
      OPENAI_BASE_URL = http://127.0.0.1:8091/v1
      OPENAI_MODEL    = LMDirect

  STEP 3 -- Start Qwen Code in your project folder:

    cd "[your-project-path]"
    qwen

--------------------------------------------------------------------------------
 5. ALTERNATIVE: CONFIG FILE SETUP
--------------------------------------------------------------------------------
You can also configure Qwen Code via its JSON settings file:

  STEP 1 -- Create or edit the config:

    mkdir "%USERPROFILE%\.qwen" 2>$null
    notepad "%USERPROFILE%\.qwen\settings.json"

  STEP 2 -- Paste this config:

    {
      "modelProviders": {
        "openai": [
          {
            "id": "LMDirect",
            "name": "SindByte LMDirect",
            "baseUrl": "http://127.0.0.1:8091/v1",
            "description": "SindByte MCP Server via OpenAI-compatible API",
            "envKey": "OPENAI_API_KEY"
          }
        ]
      },
      "env": {
        "OPENAI_API_KEY": "sk-sindbyte-local"
      },
      "security": {
        "auth": {
          "selectedType": "openai"
        }
      },
      "model": {
        "name": "LMDirect"
      }
    }

  STEP 3 -- Save and start Qwen Code:

    qwen

--------------------------------------------------------------------------------
 6. USING IQ TOOLS WITH QWEN CODE
--------------------------------------------------------------------------------
Qwen Code does not have built-in IQ profile selection.
To use IQ Tools, either:

  OPTION A -- Set the default IQ profile in SindByte Config
    1. Open SindByte tray icon -> Config
    2. Find API Provider -> Default IQ Profile
    3. Set to "default", "research", or "trading"
    4. Save and restart SindByte

  OPTION B -- Use an IQ model alias:

    Change OPENAI_MODEL (or model.name in config) to:
      "iq/full"      -- Full IQ pipeline
      "iq/research"  -- Web research + CoT
      "iq/trading"   -- Trading tools
      "iq/minimal"   -- Auto-expert only
      "iq/off"       -- Direct chat, no IQ

--------------------------------------------------------------------------------
 7. TROUBLESHOOTING
--------------------------------------------------------------------------------

  PROBLEM: "qwen command not found"
  FIX:     Make sure npm global bin is in your PATH.

  PROBLEM: "Cannot connect" or "Connection refused"
  FIX:     Verify SindByte is running on port 8091.

  PROBLEM: Qwen Code asks for DashScope API key
  FIX:     Make sure OPENAI_BASE_URL points to SindByte (:8091),
           not to Alibaba's DashScope endpoint.

  PROBLEM: "Model not found"
  FIX:     Use one of the exact SindByte model aliases (LMDirect, iq/full, etc.)

--------------------------------------------------------------------------------
 8. QUICK REFERENCE
--------------------------------------------------------------------------------
  | Setting          | Value                                  |
  |------------------|----------------------------------------|
  | Tool             | Qwen Code CLI (npm: @qwen-code/qwen-code) |
  | Base URL         | http://127.0.0.1:8091/v1               |
  | API Key          | sk-sindbyte-local                      |
  | Env var (URL)    | OPENAI_BASE_URL                        |
  | Env var (Key)    | OPENAI_API_KEY                         |
  | Env var (Model)  | OPENAI_MODEL                           |
  | Config file      | ~/.qwen/settings.json                  |
  | IQ Timeout       | 3600 sec (1 hour)                      |

================================================================================
  END OF GUIDE
================================================================================
