Skip to content

Conversation

@hugodutka
Copy link
Collaborator

No description provided.

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

This replaces only the first occurrence of "*".

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.


Suggested changeset 1
packages/scout-agent/lib/compute/coder/index.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/scout-agent/lib/compute/coder/index.ts b/packages/scout-agent/lib/compute/coder/index.ts
--- a/packages/scout-agent/lib/compute/coder/index.ts
+++ b/packages/scout-agent/lib/compute/coder/index.ts
@@ -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}/`;
 
EOF
@@ -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}/`;

Copilot is powered by AI and may make mistakes. Always verify output.

// 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

This replaces only the first occurrence of "*".

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.

Suggested changeset 1
packages/scout-agent/lib/compute/coder/index.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/scout-agent/lib/compute/coder/index.ts b/packages/scout-agent/lib/compute/coder/index.ts
--- a/packages/scout-agent/lib/compute/coder/index.ts
+++ b/packages/scout-agent/lib/compute/coder/index.ts
@@ -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";
EOF
@@ -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";
Copilot is powered by AI and may make mistakes. Always verify output.
@hugodutka hugodutka force-pushed the feat/coder-compute-provider branch from 1e0a077 to 0c554b1 Compare December 5, 2025 12:06
@hugodutka hugodutka merged commit b74b2be into main Dec 5, 2025
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant