-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add coder workspace support to scout #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This adds support for using Coder workspaces as compute environments
for the scout-agent, in addition to the existing Docker and Daytona providers.
The Coder provider uses the HTTP API directly via fetch calls:
- No CLI dependency required
- Authenticates via Coder-Session-Token header
- Creates/manages workspaces via REST API
- Executes commands via WebSocket reconnecting PTY endpoint
- Tunnels to compute server via PTY + netcat
API endpoints used:
- GET /api/v2/users/me - Current user info
- GET /api/v2/workspaces/{id} - Workspace details
- POST /api/v2/organizations/{org}/members/me/workspaces - Create workspace
- POST /api/v2/workspaces/{id}/builds - Start/stop workspace
- WS /api/v2/workspaceagents/{id}/pty - Command execution and tunneling
Configuration options:
- url: Coder deployment URL
- sessionToken: Authentication token
- template: Template for workspace creation
- workspaceName, agentName: Workspace identification
- richParameters: Template parameters
- startTimeoutSeconds: Workspace startup timeout
| useHttp, | ||
| } = opts; | ||
| const appSubdomain = `${computeServerPort}--${agentName}--${workspaceName}--${ownerName}`; | ||
| const appHost = appHostname.replace("*", appSubdomain); |
Check failure
Code scanning / CodeQL
Incomplete string escaping or encoding High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 3 days ago
To fix the issue, we should ensure that all occurrences of the asterisk (*) in appHostname are replaced with the value from appSubdomain. This is best achieved using the string .replace method with a regular expression and the global flag /\*/g. Only the highlighted line (537) needs modification: change appHost = appHostname.replace("*", appSubdomain); to appHost = appHostname.replace(/\*/g, appSubdomain);. No new imports are required.
-
Copy modified line R537
| @@ -534,7 +534,7 @@ | ||
| useHttp, | ||
| } = opts; | ||
| const appSubdomain = `${computeServerPort}--${agentName}--${workspaceName}--${ownerName}`; | ||
| const appHost = appHostname.replace("*", appSubdomain); | ||
| const appHost = appHostname.replace(/\*/g, appSubdomain); | ||
| const protocol = useHttp ? "http" : "https"; | ||
| const proxyUrl = `${protocol}://${appHost}/`; | ||
|
|
|
|
||
| // Replace the wildcard in appHostname with the subdomain | ||
| // e.g., "*.apps.coder.com" -> "22137--dev--main--hugo.apps.coder.com" | ||
| const appHost = appHostname.replace("*", appSubdomain); |
Check failure
Code scanning / CodeQL
Incomplete string escaping or encoding High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 3 days ago
The best fix is to change the replace operation on line 857 to use a regex with the global flag, so that all occurrences of "" are replaced by appSubdomain. This is simply done by changing appHostname.replace("*", appSubdomain) to appHostname.replace(/\*/g, appSubdomain). The rest of the functionality is preserved, and the code remains concise and maintainable. No additional dependencies or methods are needed; this uses standard JavaScript functionality and keeps behaviour unchanged except for correcting the substitution when multiple "" occur. Only line 857 of packages/scout-agent/lib/compute/coder/index.ts needs editing.
-
Copy modified line R857
| @@ -854,7 +854,7 @@ | ||
|
|
||
| // Replace the wildcard in appHostname with the subdomain | ||
| // e.g., "*.apps.coder.com" -> "22137--dev--main--hugo.apps.coder.com" | ||
| const appHost = appHostname.replace("*", appSubdomain); | ||
| const appHost = appHostname.replace(/\*/g, appSubdomain); | ||
|
|
||
| // Use ws:// for http:// URLs (e.g., local development), wss:// otherwise | ||
| const wsProtocol = options.coderUrl.startsWith("http://") ? "ws" : "wss"; |
1e0a077 to
0c554b1
Compare
No description provided.