cody icon indicating copy to clipboard operation
cody copied to clipboard

Enable extension-specific proxy settings

Open peterguy opened this issue 1 year ago • 3 comments

Support extension-specific proxy settings (don't rely on http(s)_proxy).

Support using a unix domain socket as a proxy.

Add a CA cert setting to enable using proxies with self-signed or not-public certificates.

Closes CODY-3092

Test plan

To test locally:

  1. Install socat and mitmproxy (brew install socat mitmproxy)
  2. Switch to this branch: git switch peterguy/vscode-add-proxy-settings
  3. In one terminal, start up socat to listen on a UDS and send TCP connections to mitm
socat -d -d unix-listen:${HOME}/mitm-proxy.sock,fork tcp:localhost:8080
  1. In another terminal, launch mitmproxy. I like to use mitmweb because it opens a web view of the traffic that is friendly.
mitmweb
  1. Add the following to VSCode's settings.json (It's at ~/Library/Application Support/Code/User/settings.json for me; you can also get to it by opening the Command Palette (Cmd-Shift-P), typing "settings" to filter, then selecting "Open User Settings (JSON)".
"http.proxySupport": "on",
"cody.proxy.path": "~/mitm-proxy.sock",
"cody.proxy.cacert": "~/.mitmproxy/mitmproxy-ca-cert.pem"

In addition to specifying proxy settings for the Cody extension, it also toggles VSCode's proxy support from override to on. If it's in the default override mode, it won't use the proxy agents we set up. I'd like to avoid this requirement, but until we figure out how to do that (probably with more "monkey patching", to quote @RXminuS 😄 ), we have to toggle the proxy support to either on or fallback. 5. Launch the Cody extension via the Run And Debug pane (Cmd-Shift-D), by clicking the green "play" icon at the top of the pane, when "Launch VSCode Extension (Desktop, recommended)" is selected (it's the default). 6. Note the outputs of socat and mitmproxy in the two terminals, and if you launched mitmweb, see the requests in the browser. If you are using mitmweb you can use the web interface to see the types of requests being made. 7. Execute a completion. I used Document Code as a simple triggerable one. If you launched mitmweb and are using a non-local LLM model (not Ollama), you should see calls to the completions endpoint in the mitm web page. 8. Optional: change the proxy settings to use mitmproxy directly. Remove the proxyPath setting and add proxyHost and proxyPort:

"cody.proxy.host": "localhost",
"cody.proxy.port": 8080

Then verify again that the extension is still operative. You should still see activity in the terminal that's running mitmproxy (or mitmweb), and the mitmweb web page should show more traffic, but there should be no activity in the socat terminal.

peterguy avatar Sep 20 '24 22:09 peterguy