feat(vscode): add attach mode for connecting to existing server
Summary
- Add configuration settings for attach mode (
opencode.attach.enabled,.host,.port) - When enabled, run
opencode attachinstead of spawning a new instance - Support both
http://andhttps://protocols in host configuration - Enables session sharing between terminal/web and VSCode in cloud workspaces (e.g., Coder)
Changes
-
sdks/vscode/package.json: Addcontributes.configurationsection -
sdks/vscode/src/extension.ts: Read config, conditional attach command, protocol-aware URL building -
sdks/vscode/README.md: Document new settings including HTTPS support
Usage
Enable attach mode in VS Code settings:
{
"opencode.attach.enabled": true,
"opencode.attach.host": "localhost",
"opencode.attach.port": 4096
}
For HTTPS connections:
{
"opencode.attach.host": "https://myserver.com",
"opencode.attach.port": 443
}
/review
@rekram1-node I should have definitely had a little more attention before I submitted this. It caught a legitimate potential bug.
I've updated it with the suggested fix, it's slightly different syntax than the way the original did it, but it should accomplish the same outcome.
If you want me to adjust the formatting let me know.
this is mostly just the builtin /review command nothing super crazy glad it works!
/review
/review
(does this work for non contributers, i doubt it)
it only works for admins!
/review
lgtm
it only works for admins!
I figured as much, I am actually using your guy's exact review workflow in a project of mine, and will be adding it to the rest of my repo's. I saw "Owner" as a filter but wasn't certain on who counted as that fronm my brief skim.
The primary motivator for this update to the vscode extension is I am running Coder workspaces and I run a copy of opencode as a background task, so being able to attach to it is super helpful from within vscode.
My normal workflow currently is to "attach" to the server outside of the vscode extension, but this makes it much easier to have a one click launch, the actual endpoint for us is always going to be localhost:4096, but having it configurable could be beneficial if you're running something like cloudflare agents to host a copy of opencode, or really anytime you could want to attach to a running instance.
LMK if there's any concerns.
The way the extension currently works is when the extension opens a terminal with a random port, so it can communicate for the append.
I don't see an easy endpoint for doing this same thing, so the solution I am testing is using the terminal.sendText with the shouldExecute set to false.
This really only impacts if a user is opening multiple opencode windows inside of the editor.
If we need to have a larger discussion around this I am happy to put this on hold.
wait so what does that have to do w/ the extra setting? I don't know if im following