dsh-net-switch: Harness Runtime Network Switching

Introduction

In DeepSeek Harness (DSH), HTTP traffic for LLM calls, web searches/scraping, HTTP MCP, and certain agent shell subprocesses is routed through an in-process HTTP stack. The official @deepseek-ai/dsh-http-proxy reads policies from environment variables (or $DSH_HOME/.env) at startup once and installs them as a process-level undici dispatcher. It does not support SOCKS or PAC, nor does it read the operating system proxy. Consequently, “System Proxy” in Clash Verge is ineffective for the Harness itself—only subprocesses like curl, git, or npm within the shell are affected by the system proxy.

To change routing, the official method typically involves modifying environment variables and restarting the Harness. If you use Clash Verge Rev for hybrid proxying locally but want the agent to switch between “via proxy” and “direct/LAN” without restarting, the community plugin dsh-net-switch (Maintainer: B1aZerr, Category: Networking Tools) targets this gap.

What is this?

dsh-net-switch provides a runtime outbound network switch for DSH: it switches the Harness’s own outbound traffic between “Local Clash Verge Proxy” and “Direct (including LAN)” without requiring a restart. The current version is 0.1.0, licensed under MIT, and requires DSH >=0.2.0-rc.2.

Three entry points drive the same logic:

Entry Point Usage
Session header status capsule Located immediately to the right of the mode selection button; Green dot “Proxy” / Gray dot “Direct” / Amber “Proxy Offline”. Click to switch.
Agent Tool network_mode: Allows the model to temporarily switch to clash for specific tasks and revert to lan afterwards.
Slash Commands /net clash, /net lan, /net status

Plugin Directory Page: https://www.skillhub.cn/plugins/B1aZerr/dsh-net-switch; Source Code & Docs: https://github.com/B1aZerr/dsh-net-switch.

Core Features

In-process Routing Replacement

The plugin replaces the official “resolve once at startup” dispatcher with a SwitchDispatcher that judges on every request:

  • mode=clash → Sends traffic to Clash Verge via ProxyAgent (default 127.0.0.1:7897, can auto-read the mixed port from verge.yaml)
  • mode=lan → Uses the original direct-connection dispatcher
  • Targets matching NO_PROXY are always connected directly

Coverage includes: LLM calls, web search/scraping, HTTP MCP; optionally syncs HTTP_PROXY / HTTPS_PROXY / NO_PROXY / NODE_USE_ENV_PROXY to subprocesses like git/curl/npm/pwsh via publishEnvToChildren.

Private Network and Loopback Bypass

A stricter bypass list than the official policy: localhost, 127.0.0.0/8, ::1, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 169.254.0.0/16, plus additional hostnames/IPs/CIDRs in the noProxy config option. NAS, LAN IPs, and local services will not be mistakenly routed through the proxy.

Fail-Open and Status Display

If clash is selected but the proxy port is unreachable, it defaults to automatically falling back to direct connection (fail-open) to prevent the agent from hanging; the status retains mode: clash with degraded: true, and the capsule shows an amber “Proxy Offline”. If you require “fail without proxy”, set autoFallback to false.

The plugin reads only Clash Verge’s verge.yaml for port discovery and does not modify its system proxy, TUN, or subscriptions. Upon uninstallation, it restores the original dispatcher and proxy environment variables.

GUI and Security

The status capsule is registered at conversation.session.header.actions (order: -5, between agent-preset and job-list), streaming with the header layout without overriding existing controls.

The host exposes loopback-only HTTP routes: GET /dsh-net-switch/state, POST /dsh-net-switch/mode (supporting {"mode":"clash"|"lan"} or {"toggle":true}). The Host must be a loopback address; cross-site POST requests will be rejected due to Origin validation.

Installation and Activation

Prerequisites: DSH with a profile (example profile named desktop), Clash Verge Rev running (mixed port defaults to 7897).

Choose one of the following three methods (commands from the project README):

# Method A: Install from GitHub (Recommended)
dsh plugin --profile desktop add github:B1aZerr/dsh-net-switch

# Method B: Local link (Instant effect when modifying code during development)
git clone https://github.com/B1aZerr/dsh-net-switch
dsh plugin --profile desktop add link:<clone_path>\dsh-net-switch

# Method C: Install from tgz
dsh plugin --profile desktop add file:<extract_path>\dsh-net-switch-0.1.0.tgz

Pre-built package (no local build required):

https://github.com/B1aZerr/dsh-net-switch/releases/latest/download/dsh-net-switch.tgz

After installation, you can run a self-check in the plugin directory (against the running host):

node dsh-net-switch\tools\verify-install.mjs

A status capsule should appear in the conversation header, to the right of the mode selection button (default “Direct”). If you modify the host-side code, you need to turn off and then on net-switch in “Settings → Plugins”, or restart DSH Desktop; otherwise, host module caching might prevent changes from taking effect. The client side only requires a page refresh.

Typical Usage

  1. Manual Switching: Click the header capsule, or run /net clash, /net lan in the conversation; use /net status to view the current mode and probe results.
  2. Agent Autonomous Switching: Ask the model to call network_mode in the conversation, e.g., switch to clash when accessing overseas APIs and switch back to lan after the task is done.
  3. Optional Configuration: Override plugin config in the profile’s cordis.patch.yml (excerpt):
- id: net-switch
  name: 'dsh-net-switch'
  config:
    proxy: 'http://127.0.0.1:7897'
    mode: lan
    autoFallback: true
    probeIntervalMs: 5000
    probeTimeoutMs: 2000
    noProxy: ['nas.home.arpa']
    persist: true
    publishEnvToChildren: true
    enabled: true

Mode Priority: config.mode → Persisted Status File (default $DSH_HOME/storages/dsh-net-switch.json) → lan.

Use Cases and Notes

Who it is for: Users who run Clash Verge locally long-term and use DSH Desktop for agent development or daily conversation, requiring frequent switching between “Harness via Proxy” and “Direct/LAN” without wanting to change .env and restart every time.

Important to know:

  • The plugin runs with the permissions of the current DSH process. Please read the source code and MIT license before installation to ensure the proxy URL and routing logic comply with your security policies.
  • Does not support SOCKS/PAC; the proxy address must be in HTTP format (consistent with the official http-proxy).
  • The community directory skillhub.cn is an independent site with no official affiliation with DeepSeek / High-Flyer. The DSH ecosystem follows “everything is a plugin”, and this plugin is a community-maintained networking tool extension.

Conclusion

dsh-net-switch changes Harness outbound networking from “fixed at startup” to “one-click runtime switching,” integrating with Clash Verge mixed ports, header UI, the network_mode tool, and /net commands. If your pain point is exactly that “System Proxy is ineffective for Harness and routing changes require a restart,” you can install it using the commands above and verify it via the header capsule or slash commands.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye