feat: remote command

This commit is contained in:
Nate 2025-07-20 18:30:09 -07:00
parent d755ad540a
commit 9aa3e7fe64
5 changed files with 123 additions and 3 deletions

62
src/commands/remote.ts Normal file
View file

@ -0,0 +1,62 @@
import chalk from "chalk";
import {
getAccessToken,
isAuthenticatedConfig,
loadAuthConfig,
} from "../auth/workos.js";
import { env } from "../env.js";
export async function remote(prompt: string) {
console.info(chalk.white("Setting up remote development environment..."));
try {
const authConfig = loadAuthConfig();
if (!isAuthenticatedConfig(authConfig)) {
console.error(
chalk.red("Not authenticated. Please run 'cn login' first.")
);
process.exit(1);
}
const accessToken = getAccessToken(authConfig);
const response = await fetch(new URL("agents/devboxes", env.apiBase), {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${accessToken}`,
},
body: JSON.stringify({
cUserId: authConfig.userId,
repoUrl: "https://github.com/continuedev/amplified.dev", // getRepoUrl(),
name: `devbox-${Date.now()}`,
prompt: prompt,
}),
});
if (!response.ok) {
const errorText = await response.text();
throw new Error(
`Failed to create remote environment: ${response.status} ${errorText}`
);
}
const result = await response.json();
console.info(
chalk.green("✅ Remote development environment created successfully!")
);
if (result.url) {
console.info(
chalk.white(`Access your environment at: ${result.url}:${result.port}`)
);
}
} catch (error: any) {
console.error(
chalk.red(`Failed to create remote environment: ${error.message}`)
);
process.exit(1);
}
}

View file

@ -4,6 +4,7 @@ dotenv.config();
export const env = {
apiBase: process.env.CONTINUE_API_BASE ?? "https://api.continue.dev/",
workOsClientId: "client_01J0FW6XN8N2XJAECF7NE0Y65J",
appUrl: "https://hub.continue.dev",
workOsClientId:
process.env.WORKOS_CLIENT_ID ?? "client_01J0FW6XN8N2XJAECF7NE0Y65J",
appUrl: process.env.HUB_URL ?? "https://hub.continue.dev",
};

View file

@ -4,6 +4,7 @@ import { Command } from "commander";
import { chat } from "./commands/chat.js";
import { login } from "./commands/login.js";
import { logout } from "./commands/logout.js";
import { remote } from "./commands/remote.js";
import { configureConsoleForHeadless } from "./util/consoleOverride.js";
import logger from "./util/logger.js";
import { getVersion } from "./version.js";
@ -87,6 +88,14 @@ program
await logout();
});
// Remote subcommand
program
.command("remote <prompt>")
.description("Launch a remote instance of the cn agent")
.action(async (prompt: string) => {
await remote(prompt);
});
// Handle unknown commands
program.on("command:*", () => {
console.error(`Error: Unknown command '${program.args.join(" ")}'\n`);

View file

@ -47,7 +47,8 @@ export function useConfigSelector({
if (config.type === "create") {
// Open the web browser to create new assistant
const url = "https://hub.continue.dev/new?type=assistant";
const url = new URL("https://hub.continue.dev/new");
url.searchParams.set("type", "assistant");
try {
let command: string;

47
src/util/git.ts Normal file
View file

@ -0,0 +1,47 @@
import { execSync } from "child_process";
/**
* Get the git remote URL for the current repository
* @param remote The remote name (defaults to 'origin')
* @returns The remote URL or null if not found
*/
export function getGitRemoteUrl(remote: string = "origin"): string | null {
try {
const result = execSync(`git remote get-url ${remote}`, {
encoding: "utf-8",
cwd: process.cwd(),
stdio: "pipe",
});
return result.trim();
} catch {
return null;
}
}
/**
* Check if current directory is a git repository
*/
export function isGitRepo(): boolean {
try {
execSync("git rev-parse --is-inside-work-tree", {
stdio: "ignore",
cwd: process.cwd(),
});
return true;
} catch {
return false;
}
}
/**
* Get the current repository URL, falling back to local path if not a git repo
* @returns Git remote URL or local path
*/
export function getRepoUrl(): string {
if (!isGitRepo()) {
return process.cwd();
}
const remoteUrl = getGitRemoteUrl();
return remoteUrl || process.cwd();
}