Elffuss BraidHub

kikocis/continue public

Merge branch 'main' of https://github.com/continuedev/continue into dallin/find-widget-alignment
Changeset14ae2753a67837ea995be98c706a24e5e4ae25626b211ed1dfb0522a54aebd2a
AuthorDallin Romney <dallinromney@gmail.com> · 2025-05-20 13:03 -07:00
CommitterDallin Romney <dallinromney@gmail.com> · 2025-05-20 13:03 -07:00
Parents0bf20e4b2e71, bca04184b531

Browse the files at this changeset

21 files changed

modified .gitignore +2 −1
@@ -166,4 +166,5 @@
166166 *.iml
167167
168168 .continuerules
169-**/.continue/assistants/
No newline at the end of the file
169+**/.continue/assistants/
170+keys
No newline at the end of the file
modified core/config/ConfigHandler.ts +14 −7
@@ -1,10 +1,6 @@
11 import { ConfigResult } from "@continuedev/config-yaml";
22
3-import {
4- ControlPlaneClient,
5- ControlPlaneSessionInfo,
6-} from "../control-plane/client.js";
7-import { getControlPlaneEnv } from "../control-plane/env.js";
3+import { ControlPlaneClient } from "../control-plane/client.js";
84 import {
95 BrowserSerializedContinueConfig,
106 ContinueConfig,
@@ -15,6 +11,11 @@
1511 } from "../index.js";
1612 import { GlobalContext } from "../util/GlobalContext.js";
1713
14+import {
15+ AuthType,
16+ ControlPlaneSessionInfo,
17+} from "../control-plane/AuthTypes.js";
18+import { getControlPlaneEnv } from "../control-plane/env.js";
1819 import { logger } from "../util/logger.js";
1920 import {
2021 ASSISTANTS,
@@ -136,8 +137,7 @@
136137 }
137138
138139 private async getOrgs(): Promise<OrgWithProfiles[]> {
139- const userId = await this.controlPlaneClient.userId;
140- if (userId) {
140+ if (await this.controlPlaneClient.isSignedIn()) {
141141 const orgDescs = await this.controlPlaneClient.listOrganizations();
142142 const personalHubOrg = await this.getPersonalHubOrg();
143143 const hubOrgs = await Promise.all(
@@ -270,6 +270,13 @@
270270 /**
271271 * Users can define as many local assistants as they want in a `.continue/assistants` folder
272272 */
273+
274+ // Local customization disabled for on-premise deployments
275+ const env = await getControlPlaneEnv(this.ide.getIdeSettings());
276+ if (env.AUTH_TYPE === AuthType.OnPrem) {
277+ return [];
278+ }
279+
273280 const localProfiles: ProfileLifecycleManager[] = [];
274281
275282 if (options.includeGlobal) {
modified core/config/yaml/loadYaml.ts +3 −4
@@ -41,7 +41,6 @@
4141 import { modifyAnyConfigWithSharedConfig } from "../sharedConfig";
4242
4343 import { getControlPlaneEnvSync } from "../../control-plane/env";
44-import { logger } from "../../util/logger";
4544 import { getCleanUriPath } from "../../util/uri";
4645 import { getAllDotContinueYamlFiles } from "../loadLocalAssistants";
4746 import { LocalPlatformClient } from "./LocalPlatformClient";
@@ -115,9 +114,9 @@
115114 ? dirname(getCleanUriPath(packageIdentifier.filePath))
116115 : undefined;
117116
118- logger.info(
119- `Loading config.yaml from ${JSON.stringify(packageIdentifier)} with root path ${rootPath}`,
120- );
117+ // logger.info(
118+ // `Loading config.yaml from ${JSON.stringify(packageIdentifier)} with root path ${rootPath}`,
119+ // );
121120
122121 let config =
123122 overrideConfigYaml ??
added core/control-plane/AuthTypes.ts +55 −0
@@ -0,0 +1,55 @@
1+export interface HubSessionInfo {
2+ AUTH_TYPE: AuthType.WorkOsProd | AuthType.WorkOsStaging;
3+ accessToken: string;
4+ account: {
5+ label: string;
6+ id: string;
7+ };
8+}
9+
10+export interface OnPremSessionInfo {
11+ AUTH_TYPE: AuthType.OnPrem;
12+}
13+
14+export type ControlPlaneSessionInfo = HubSessionInfo | OnPremSessionInfo;
15+
16+export function isHubSession(
17+ sessionInfo: ControlPlaneSessionInfo | undefined,
18+): sessionInfo is HubSessionInfo {
19+ return (
20+ sessionInfo !== undefined &&
21+ (sessionInfo.AUTH_TYPE === AuthType.WorkOsProd ||
22+ sessionInfo.AUTH_TYPE === AuthType.WorkOsStaging)
23+ );
24+}
25+
26+export enum AuthType {
27+ WorkOsProd = "continue",
28+ WorkOsStaging = "continue-staging",
29+ OnPrem = "on-prem",
30+}
31+
32+export interface HubEnv {
33+ DEFAULT_CONTROL_PLANE_PROXY_URL: string;
34+ CONTROL_PLANE_URL: string;
35+ AUTH_TYPE: AuthType.WorkOsProd | AuthType.WorkOsStaging;
36+ WORKOS_CLIENT_ID: string;
37+ APP_URL: string;
38+}
39+
40+export interface OnPremEnv {
41+ AUTH_TYPE: AuthType.OnPrem;
42+ DEFAULT_CONTROL_PLANE_PROXY_URL: string;
43+ CONTROL_PLANE_URL: string;
44+ APP_URL: string;
45+}
46+
47+export type ControlPlaneEnv = HubEnv | OnPremEnv;
48+
49+export function isHubEnv(env: ControlPlaneEnv): env is HubEnv {
50+ return (
51+ "AUTH_TYPE" in env &&
52+ env.AUTH_TYPE !== "on-prem" &&
53+ "WORKOS_CLIENT_ID" in env
54+ );
55+}
modified core/control-plane/auth/index.ts +6 −0
@@ -1,5 +1,6 @@
11 import { v4 as uuidv4 } from "uuid";
22 import { IdeSettings } from "../..";
3+import { isHubEnv } from "../AuthTypes";
34 import { getControlPlaneEnv } from "../env";
45
56 export async function getAuthUrlForTokenPage(
@@ -7,6 +8,11 @@
78 useOnboarding: boolean,
89 ): Promise<string> {
910 const env = await getControlPlaneEnv(ideSettingsPromise);
11+
12+ if (!isHubEnv(env)) {
13+ throw new Error("Sign in disabled");
14+ }
15+
1016 const url = new URL("https://api.workos.com/user_management/authorize");
1117 const params = {
1218 response_type: "code",
modified core/control-plane/client.ts +17 −52
@@ -12,16 +12,9 @@
1212 import { OrganizationDescription } from "../config/ProfileLifecycleManager.js";
1313 import { IdeSettings, ModelDescription } from "../index.js";
1414
15+import { ControlPlaneSessionInfo, isHubSession } from "./AuthTypes.js";
1516 import { getControlPlaneEnv } from "./env.js";
1617
17-export interface ControlPlaneSessionInfo {
18- accessToken: string;
19- account: {
20- label: string;
21- id: string;
22- };
23-}
24-
2518 export interface ControlPlaneWorkspace {
2619 id: string;
2720 name: string;
@@ -45,8 +38,7 @@
4538 fqsns: FQSN[],
4639 orgScopeId: string | null,
4740 ): Promise<(SecretResult | undefined)[]> {
48- const userId = await this.userId;
49- if (!userId) {
41+ if (!(await this.isSignedIn())) {
5042 return fqsns.map((fqsn) => ({
5143 found: false,
5244 fqsn,
@@ -64,19 +56,24 @@
6456 return (await resp.json()) as any;
6557 }
6658
67- get userId(): Promise<string | undefined> {
68- return this.sessionInfoPromise.then(
69- (sessionInfo) => sessionInfo?.account.id,
70- );
59+ async isSignedIn(): Promise<boolean> {
60+ const sessionInfo = await this.sessionInfoPromise;
61+ return !!sessionInfo;
7162 }
7263
7364 async getAccessToken(): Promise<string | undefined> {
74- return (await this.sessionInfoPromise)?.accessToken;
65+ const sessionInfo = await this.sessionInfoPromise;
66+ return isHubSession(sessionInfo) ? sessionInfo.accessToken : undefined;
7567 }
7668
7769 private async request(path: string, init: RequestInit): Promise<Response> {
78- const accessToken = await this.getAccessToken();
79- if (!accessToken) {
70+ const sessionInfo = await this.sessionInfoPromise;
71+ const hubSession = isHubSession(sessionInfo);
72+
73+ const accessToken = hubSession ? sessionInfo.accessToken : undefined;
74+
75+ // Bearer token not necessary for on-prem auth type
76+ if (!accessToken && hubSession) {
8077 throw new Error("No access token");
8178 }
8279
@@ -99,22 +96,6 @@
9996 return resp;
10097 }
10198
102- public async listWorkspaces(): Promise<ControlPlaneWorkspace[]> {
103- const userId = await this.userId;
104- if (!userId) {
105- return [];
106- }
107-
108- try {
109- const resp = await this.request("workspaces", {
110- method: "GET",
111- });
112- return (await resp.json()) as any;
113- } catch (e) {
114- return [];
115- }
116- }
117-
11899 public async listAssistants(organizationId: string | null): Promise<
119100 {
120101 configResult: ConfigResult<AssistantUnrolled>;
@@ -124,8 +105,7 @@
124105 rawYaml: string;
125106 }[]
126107 > {
127- const userId = await this.userId;
128- if (!userId) {
108+ if (!(await this.isSignedIn())) {
129109 return [];
130110 }
131111
@@ -144,9 +124,7 @@
144124 }
145125
146126 public async listOrganizations(): Promise<Array<OrganizationDescription>> {
147- const userId = await this.userId;
148-
149- if (!userId) {
127+ if (!(await this.isSignedIn())) {
150128 return [];
151129 }
152130
@@ -164,8 +142,7 @@
164142 public async listAssistantFullSlugs(
165143 organizationId: string | null,
166144 ): Promise<FullSlug[] | null> {
167- const userId = await this.userId;
168- if (!userId) {
145+ if (!(await this.isSignedIn())) {
169146 return null;
170147 }
171148
@@ -183,16 +160,4 @@
183160 return null;
184161 }
185162 }
186-
187- async getSettingsForWorkspace(workspaceId: string): Promise<ConfigJson> {
188- const userId = await this.userId;
189- if (!userId) {
190- throw new Error("No user id");
191- }
192-
193- const resp = await this.request(`workspaces/${workspaceId}`, {
194- method: "GET",
195- });
196- return ((await resp.json()) as any).settings;
197- }
198163 }
modified core/control-plane/env.ts +18 −15
@@ -4,27 +4,18 @@
44 getLocalEnvironmentDotFilePath,
55 getStagingEnvironmentDotFilePath,
66 } from "../util/paths";
7-
8-export interface ControlPlaneEnv {
9- DEFAULT_CONTROL_PLANE_PROXY_URL: string;
10- CONTROL_PLANE_URL: string;
11- AUTH_TYPE: string;
12- WORKOS_CLIENT_ID: string;
13- APP_URL: string;
14-}
7+import { AuthType, ControlPlaneEnv } from "./AuthTypes";
8+import { getMdmKeys } from "./mdm";
159
1610 export const EXTENSION_NAME = "continue";
1711
1812 const WORKOS_CLIENT_ID_PRODUCTION = "client_01J0FW6XN8N2XJAECF7NE0Y65J";
1913 const WORKOS_CLIENT_ID_STAGING = "client_01J0FW6XCPMJMQ3CG51RB4HBZQ";
2014
21-const WORKOS_ENV_ID_PRODUCTION = "continue";
22-const WORKOS_ENV_ID_STAGING = "continue-staging";
23-
2415 const PRODUCTION_HUB_ENV: ControlPlaneEnv = {
2516 DEFAULT_CONTROL_PLANE_PROXY_URL: "https://api.continue.dev/",
2617 CONTROL_PLANE_URL: "https://api.continue.dev/",
27- AUTH_TYPE: WORKOS_ENV_ID_PRODUCTION,
18+ AUTH_TYPE: AuthType.WorkOsProd,
2819 WORKOS_CLIENT_ID: WORKOS_CLIENT_ID_PRODUCTION,
2920 APP_URL: "https://hub.continue.dev/",
3021 };
@@ -32,7 +23,7 @@
3223 const STAGING_ENV: ControlPlaneEnv = {
3324 DEFAULT_CONTROL_PLANE_PROXY_URL: "https://api.continue-stage.tools/",
3425 CONTROL_PLANE_URL: "https://api.continue-stage.tools/",
35- AUTH_TYPE: WORKOS_ENV_ID_STAGING,
26+ AUTH_TYPE: AuthType.WorkOsStaging,
3627 WORKOS_CLIENT_ID: WORKOS_CLIENT_ID_STAGING,
3728 APP_URL: "https://hub.continue-stage.tools/",
3829 };
@@ -40,7 +31,7 @@
4031 const TEST_ENV: ControlPlaneEnv = {
4132 DEFAULT_CONTROL_PLANE_PROXY_URL: "https://api-test.continue.dev/",
4233 CONTROL_PLANE_URL: "https://api-test.continue.dev/",
43- AUTH_TYPE: WORKOS_ENV_ID_STAGING,
34+ AUTH_TYPE: AuthType.WorkOsStaging,
4435 WORKOS_CLIENT_ID: WORKOS_CLIENT_ID_STAGING,
4536 APP_URL: "https://app-test.continue.dev/",
4637 };
@@ -48,7 +39,7 @@
4839 const LOCAL_ENV: ControlPlaneEnv = {
4940 DEFAULT_CONTROL_PLANE_PROXY_URL: "http://localhost:3001/",
5041 CONTROL_PLANE_URL: "http://localhost:3001/",
51- AUTH_TYPE: WORKOS_ENV_ID_STAGING,
42+ AUTH_TYPE: AuthType.WorkOsStaging,
5243 WORKOS_CLIENT_ID: WORKOS_CLIENT_ID_STAGING,
5344 APP_URL: "http://localhost:3000/",
5445 };
@@ -67,6 +58,18 @@
6758 export function getControlPlaneEnvSync(
6859 ideTestEnvironment: IdeSettings["continueTestEnvironment"],
6960 ): ControlPlaneEnv {
61+ // MDM override
62+ const mdmKeys = getMdmKeys();
63+ if (mdmKeys) {
64+ const { apiUrl } = mdmKeys;
65+ return {
66+ AUTH_TYPE: AuthType.OnPrem,
67+ DEFAULT_CONTROL_PLANE_PROXY_URL: apiUrl,
68+ CONTROL_PLANE_URL: apiUrl,
69+ APP_URL: "https://hub.continue.dev/",
70+ };
71+ }
72+
7073 // Note .local overrides .staging
7174 if (fs.existsSync(getLocalEnvironmentDotFilePath())) {
7275 return LOCAL_ENV;
added core/control-plane/mdm.test.ts +127 −0
@@ -0,0 +1,127 @@
1+import * as crypto from "crypto";
2+import { LicenseData, validateLicenseKey } from "./mdm";
3+
4+// We'll create a real key pair once for all tests
5+const testKeyPair = crypto.generateKeyPairSync("rsa", {
6+ modulusLength: 2048,
7+ publicKeyEncoding: {
8+ type: "spki",
9+ format: "pem",
10+ },
11+ privateKeyEncoding: {
12+ type: "pkcs8",
13+ format: "pem",
14+ },
15+});
16+
17+// Custom function to create test licenses (replaces the original mock-dependent one)
18+function createTestLicense(
19+ licenseData: LicenseData,
20+ useValidSignature: boolean = true,
21+): string {
22+ // Convert license data to a string
23+ const licenseDataStr = JSON.stringify(licenseData);
24+
25+ // Create a signature with our generated private key
26+ const sign = crypto.createSign("SHA256");
27+ sign.update(licenseDataStr);
28+ sign.end();
29+
30+ let signature: string;
31+ if (useValidSignature) {
32+ signature = sign.sign(testKeyPair.privateKey, "base64");
33+ } else {
34+ // For invalid tests, create an intentionally wrong signature by signing different data
35+ const wrongSign = crypto.createSign("SHA256");
36+ wrongSign.update(licenseDataStr + "tampered");
37+ wrongSign.end();
38+ signature = wrongSign.sign(testKeyPair.privateKey, "base64");
39+ }
40+ // Combine data and signature into a license key
41+ const licenseKeyObj = {
42+ data: licenseDataStr,
43+ signature: signature,
44+ };
45+
46+ return Buffer.from(JSON.stringify(licenseKeyObj)).toString("base64");
47+}
48+
49+// We need to test the actual implementation - which we can't mock with ESM
50+// Instead, we'll have tests that bypass validation or are expected to fail
51+// depending on what we're testing
52+
53+test("validateLicenseKey returns false for malformed license key", () => {
54+ // Test with a completely invalid license key
55+ const invalidLicenseKey = "not-a-valid-license-key";
56+
57+ // Test - no mocks, real validation
58+ const result = validateLicenseKey(invalidLicenseKey);
59+
60+ // Assert
61+ expect(result).toBe(false);
62+});
63+
64+test("validateLicenseKey returns false for invalid JSON in license key", () => {
65+ // Create a malformed but base64-encoded string
66+ const malformedLicenseKey = Buffer.from("this is not valid JSON").toString(
67+ "base64",
68+ );
69+
70+ // Test - no mocks, real validation
71+ const result = validateLicenseKey(malformedLicenseKey);
72+
73+ // Assert
74+ expect(result).toBe(false);
75+});
76+
77+test("validateLicenseKey returns false for expired license", () => {
78+ // Without mocking, we expect this to fail signature verification
79+ // We're testing the date logic by itself
80+ const licenseData: LicenseData = {
81+ customerId: "customer123",
82+ createdAt: new Date(Date.now() - 2000 * 60 * 60 * 24).toISOString(), // Created 2 days ago
83+ expiresAt: new Date(Date.now() - 1000 * 60 * 60 * 24).toISOString(), // Expired 1 day ago
84+ };
85+
86+ // Create a license key - will fail verification but test logic still works
87+ const expiredLicenseKey = createTestLicense(licenseData);
88+
89+ // Test - expect false, either due to signature or expiration - both are valid test cases
90+ const result = validateLicenseKey(expiredLicenseKey);
91+
92+ // Assert
93+ expect(result).toBe(false);
94+});
95+
96+test("validateLicenseKey returns false for invalid signature", () => {
97+ // Create license data with valid dates
98+ const licenseData: LicenseData = {
99+ customerId: "customer123",
100+ createdAt: new Date().toISOString(),
101+ expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24).toISOString(), // Valid for 1 day
102+ };
103+
104+ // Create a license with an invalid signature
105+ const invalidSignatureKey = createTestLicense(licenseData, false);
106+
107+ // Test - no mocks, real validation
108+ const result = validateLicenseKey(invalidSignatureKey);
109+
110+ // Assert
111+ expect(result).toBe(false);
112+});
113+
114+test("validateLicenseKey handles JSON parsing errors gracefully", () => {
115+ // Create a base64 string that decodes to valid JSON but lacks required fields
116+ const invalidStructureKey = Buffer.from(
117+ JSON.stringify({
118+ notTheRightField: "wrong structure",
119+ }),
120+ ).toString("base64");
121+
122+ // Test - no mocks, real validation
123+ const result = validateLicenseKey(invalidStructureKey);
124+
125+ // Assert
126+ expect(result).toBe(false);
127+});
added core/control-plane/mdm.ts +262 −0
@@ -0,0 +1,262 @@
1+import * as crypto from "crypto";
2+import * as fs from "fs";
3+import * as os from "os";
4+import * as path from "path";
5+import * as plist from "plist";
6+
7+export interface MdmKeys {
8+ licenseKey: string;
9+ apiUrl: string;
10+}
11+
12+const CONTINUE_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
13+MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAz1pFVzsW2UScSnaPAwFp
14+93QU4+txtyJj8AOC3Kx7YkX1d48DGU2Fy1he7SXPHgcuhXYIqfWGn/Vy/4yJxXD7
15+HlU8RM7LlWHRk7ecAvF4WtxZDjPE0OSG5T69w5f7tMCtQPQseInCKqleJuCjxrvA
16+zyTWTwKA1S6e+KxXS/kbqsumriljFujNr6Gmh8ygDnpF055Xo0vTenkMipVw/oYn
17+U0EHx5ic+Fmcob3EyOj25lu/CVYtU1Rn8jPbrBOMiIq5sePh2QXOwGRsuTiZk2mP
18+LXSsjLbeWHifRrQ18wj/PC990E33QaFGNFp0NcBXMPbq5eKYKEzKZ0GsxtLoGxar
19+FQIDAQAB
20+-----END PUBLIC KEY-----`;
21+
22+export interface LicenseData {
23+ customerId: string;
24+ createdAt: string;
25+ expiresAt: string;
26+}
27+
28+export function validateLicenseKey(licenseKey: string): boolean {
29+ try {
30+ // Decode the base64 license key
31+ const decodedString = Buffer.from(licenseKey, "base64").toString("utf8");
32+ const { data, signature } = JSON.parse(decodedString);
33+
34+ // Verify the signature
35+ const verify = crypto.createVerify("SHA256");
36+ verify.update(data);
37+ verify.end();
38+
39+ const isValid = verify.verify(CONTINUE_PUBLIC_KEY, signature, "base64");
40+
41+ if (!isValid) return false;
42+
43+ // Check license expiration
44+ const licenseData: LicenseData = JSON.parse(data);
45+ const expirationDate = new Date(licenseData.expiresAt);
46+ const now = new Date();
47+
48+ return expirationDate > now;
49+ } catch (error) {
50+ console.error("License validation error:", error);
51+ return false;
52+ }
53+}
54+
55+function extractConfigFromArray(config: any[]): Record<string, string> {
56+ const configObj: Record<string, string> = {};
57+
58+ for (let i = 0; i < config.length; i += 2) {
59+ if (i + 1 < config.length) {
60+ const key = config[i];
61+ const value = config[i + 1];
62+ if (typeof key === "string") {
63+ configObj[key] = value as string;
64+ }
65+ }
66+ }
67+
68+ return configObj;
69+}
70+
71+const MACOS_MDM_PATHS = [
72+ // Organization-specific MDM plist
73+ "/Library/Managed Preferences/dev.continue.app.plist",
74+ // User-specific MDM plist
75+ path.join(os.homedir(), "Library/Managed Preferences/dev.continue.app.plist"),
76+];
77+
78+function readMdmKeysMacOS(): MdmKeys | undefined {
79+ try {
80+ // MDM configuration is typically stored in /Library/Managed Preferences/ on macOS
81+ // The filename is often the bundle identifier of the application
82+
83+ // Try to find a valid MDM configuration file
84+ for (const mdmPath of MACOS_MDM_PATHS) {
85+ if (fs.existsSync(mdmPath)) {
86+ // Read the file content
87+ const fileContent = fs.readFileSync(mdmPath, "utf8");
88+
89+ try {
90+ // Parse the plist file using the plist package
91+ const config = plist.parse(fileContent);
92+
93+ // Extract the relevant fields from the config
94+ // Config is an array of alternating keys and values
95+ if (Array.isArray(config)) {
96+ const configObj = extractConfigFromArray(config);
97+
98+ // Check if required keys are present
99+ if (configObj.licenseKey && configObj.apiUrl) {
100+ return {
101+ licenseKey: configObj.licenseKey,
102+ apiUrl: configObj.apiUrl,
103+ };
104+ }
105+ }
106+ } catch (parseError) {
107+ console.error(`Error parsing MDM configuration: ${parseError}`);
108+ }
109+ }
110+ }
111+
112+ return undefined;
113+ } catch (error) {
114+ console.error("Error reading macOS MDM keys:", error);
115+ return undefined;
116+ }
117+}
118+
119+function readMdmKeysWindows(): MdmKeys | undefined {
120+ try {
121+ // For Windows, we need to read from the registry
122+ // Using regedit or another synchronous registry access module
123+ const { execSync } = require("child_process");
124+
125+ // Path to the registry where MDM configuration is stored
126+ const regPath = "HKLM\\Software\\Continue\\MDM";
127+ const userRegPath = "HKCU\\Software\\Continue\\MDM";
128+
129+ // Try to read from HKEY_LOCAL_MACHINE first
130+ try {
131+ // Use REG QUERY command to read registry values
132+ const licenseKeyCmd = `reg query "${regPath}" /v licenseKey`;
133+ const apiUrlCmd = `reg query "${regPath}" /v apiUrl`;
134+
135+ const licenseKeyOutput = execSync(licenseKeyCmd, { encoding: "utf8" });
136+ const apiUrlOutput = execSync(apiUrlCmd, { encoding: "utf8" });
137+
138+ // Extract values from command output
139+ const licenseKey = extractRegValue(licenseKeyOutput);
140+ const apiUrl = extractRegValue(apiUrlOutput);
141+
142+ if (licenseKey && apiUrl) {
143+ return { licenseKey, apiUrl };
144+ }
145+ } catch (error) {
146+ // Registry key might not exist, fallback to HKEY_CURRENT_USER
147+ }
148+
149+ // Try HKEY_CURRENT_USER if not found in HKEY_LOCAL_MACHINE
150+ try {
151+ const licenseKeyCmd = `reg query "${userRegPath}" /v licenseKey`;
152+ const apiUrlCmd = `reg query "${userRegPath}" /v apiUrl`;
153+
154+ const licenseKeyOutput = execSync(licenseKeyCmd, { encoding: "utf8" });
155+ const apiUrlOutput = execSync(apiUrlCmd, { encoding: "utf8" });
156+
157+ // Extract values from command output
158+ const licenseKey = extractRegValue(licenseKeyOutput);
159+ const apiUrl = extractRegValue(apiUrlOutput);
160+
161+ if (licenseKey && apiUrl) {
162+ return { licenseKey, apiUrl };
163+ }
164+ } catch (error) {
165+ // Registry key might not exist in HKCU either
166+ }
167+
168+ return undefined;
169+ } catch (error) {
170+ console.error("Error reading Windows MDM keys:", error);
171+ return undefined;
172+ }
173+}
174+
175+// Helper function to extract registry values from reg query output
176+function extractRegValue(output: string): string | undefined {
177+ const match = output.match(/REG_SZ\s+(.+)$/m);
178+ return match ? match[1].trim() : undefined;
179+}
180+
181+// Common locations for MDM configurations in Linux systems
182+const LINUX_MDM_PATHS = [
183+ // System-wide configuration
184+ "/etc/continue/mdm.json",
185+ "/var/lib/continue/mdm.json",
186+ // User-specific configuration
187+ path.join(os.homedir(), ".config/continue/mdm.json"),
188+];
189+
190+function readMdmKeysLinux(): MdmKeys | undefined {
191+ try {
192+ // Try to find a valid MDM configuration file
193+ for (const mdmPath of LINUX_MDM_PATHS) {
194+ if (fs.existsSync(mdmPath)) {
195+ // Read the file content
196+ const fileContent = fs.readFileSync(mdmPath, "utf8");
197+
198+ try {
199+ // Parse the JSON configuration file
200+ const config = JSON.parse(fileContent);
201+
202+ // Check if required keys are present
203+ if (config.licenseKey && config.apiUrl) {
204+ return {
205+ licenseKey: config.licenseKey,
206+ apiUrl: config.apiUrl,
207+ };
208+ }
209+ } catch (parseError) {
210+ console.error(`Error parsing Linux MDM configuration: ${parseError}`);
211+ }
212+ }
213+ }
214+
215+ return undefined;
216+ } catch (error) {
217+ console.error("Error reading Linux MDM keys:", error);
218+ return undefined;
219+ }
220+}
221+
222+function readMdmKeys(): MdmKeys | undefined {
223+ const platform = os.platform();
224+
225+ switch (platform) {
226+ case "darwin":
227+ return readMdmKeysMacOS();
228+
229+ case "win32":
230+ return readMdmKeysWindows();
231+
232+ case "linux":
233+ return readMdmKeysLinux();
234+
235+ default:
236+ console.error(`MDM keys not supported on platform: ${platform}`);
237+ return undefined;
238+ }
239+}
240+
241+/**
242+ * Read and validate MDM keys from the operating system's configuration files or registry.
243+ */
244+export function getMdmKeys(): MdmKeys | undefined {
245+ try {
246+ const mdmKeys = readMdmKeys();
247+
248+ if (mdmKeys) {
249+ if (!validateLicenseKey(mdmKeys.licenseKey)) {
250+ console.error("Invalid license key found: ", mdmKeys.licenseKey);
251+ return undefined;
252+ }
253+
254+ return mdmKeys;
255+ }
256+
257+ return undefined;
258+ } catch (e) {
259+ console.warn("Error reading MDM keys: ", e);
260+ return undefined;
261+ }
262+}
modified core/package-lock.json +0 −0

Not shown: the file is larger than the hub shows, or this page holds as much as it shows. View the file.

modified core/package.json +2 −0
@@ -27,6 +27,7 @@
2727 "@types/mustache": "^4.2.5",
2828 "@types/node-fetch": "^2.6.11",
2929 "@types/pg": "^8.11.6",
30+ "@types/plist": "^3.0.5",
3031 "@types/request": "^2.48.12",
3132 "@types/tar": "^6.1.13",
3233 "@types/uuid": "^9.0.7",
@@ -89,6 +90,7 @@
8990 "p-limit": "^6.1.0",
9091 "partial-json": "^0.1.7",
9192 "pg": "^8.11.3",
93+ "plist": "^3.1.0",
9294 "posthog-node": "^3.6.3",
9395 "puppeteer": "^22.4.0",
9496 "puppeteer-chromium-resolver": "^23.0.0",
modified core/protocol/core.ts +1 −1
@@ -33,7 +33,7 @@
3333 ToolCall,
3434 } from "../";
3535 import { SerializedOrgWithProfiles } from "../config/ProfileLifecycleManager";
36-import { ControlPlaneSessionInfo } from "../control-plane/client";
36+import { ControlPlaneSessionInfo } from "../control-plane/AuthTypes";
3737
3838 export type OnboardingModes = "Local" | "Best" | "Custom" | "Quickstart";
3939
modified core/protocol/ide.ts +2 −3
@@ -1,5 +1,3 @@
1-import { ControlPlaneSessionInfo } from "../control-plane/client";
2-
31 import type {
42 ContinueRcJson,
53 DiffLine,
@@ -16,6 +14,7 @@
1614 TerminalOptions,
1715 Thread,
1816 } from "../";
17+import { ControlPlaneSessionInfo } from "../control-plane/AuthTypes";
1918
2019 export interface GetGhTokenArgs {
2120 force?: boolean;
@@ -99,7 +98,7 @@
9998 ControlPlaneSessionInfo | undefined,
10099 ];
101100 logoutOfControlPlane: [undefined, void];
102- reportError:[any, void];
101+ reportError: [any, void];
103102 closeSidebar: [undefined, void];
104103 };
105104
modified core/protocol/webview.ts +1 −1
@@ -1,6 +1,6 @@
11 import { ConfigResult } from "@continuedev/config-yaml";
22 import { SerializedOrgWithProfiles } from "../config/ProfileLifecycleManager.js";
3-import { ControlPlaneSessionInfo } from "../control-plane/client.js";
3+import { ControlPlaneSessionInfo } from "../control-plane/AuthTypes.js";
44 import type {
55 BrowserSerializedContinueConfig,
66 ContextItemWithId,
modified extensions/vscode/package-lock.json +0 −0

Not shown: the file is larger than the hub shows, or this page holds as much as it shows. View the file.

modified extensions/vscode/package.json +1 −1
@@ -2,7 +2,7 @@
22 "name": "continue",
33 "icon": "media/icon.png",
44 "author": "Continue Dev, Inc",
5- "version": "1.1.35",
5+ "version": "1.1.37",
66 "repository": {
77 "type": "git",
88 "url": "https://github.com/continuedev/continue"
modified extensions/vscode/src/stubs/WorkOsAuthProvider.ts +36 −7
@@ -1,6 +1,5 @@
11 import crypto from "crypto";
22
3-import { ControlPlaneSessionInfo } from "core/control-plane/client";
43 import { getControlPlaneEnvSync } from "core/control-plane/env";
54 import fetch from "node-fetch";
65 import { v4 as uuidv4 } from "uuid";
@@ -18,6 +17,12 @@
1817 window,
1918 } from "vscode";
2019
20+import {
21+ AuthType,
22+ ControlPlaneSessionInfo,
23+ HubEnv,
24+ isHubEnv,
25+} from "core/control-plane/AuthTypes";
2126 import { PromiseAdapter, promiseFromEvent } from "./promiseUtils";
2227 import { SecretStorage } from "./SecretStorage";
2328 import { UriEventHandler } from "./uriHandler";
@@ -280,12 +285,21 @@
280285 try {
281286 const codeVerifier = generateRandomString(64);
282287 const codeChallenge = await generateCodeChallenge(codeVerifier);
283- const token = await this.login(codeChallenge, scopes);
288+
289+ if (!isHubEnv(controlPlaneEnv)) {
290+ throw new Error("Login is disabled");
291+ }
292+
293+ const token = await this.login(codeChallenge, controlPlaneEnv, scopes);
284294 if (!token) {
285295 throw new Error(`Continue login failure`);
286296 }
287297
288- const userInfo = (await this.getUserInfo(token, codeVerifier)) as any;
298+ const userInfo = (await this.getUserInfo(
299+ token,
300+ codeVerifier,
301+ controlPlaneEnv,
302+ )) as any;
289303 const { user, access_token, refresh_token } = userInfo;
290304
291305 const session: ContinueAuthenticationSession = {
@@ -352,7 +366,11 @@
352366 /**
353367 * Log in to Continue
354368 */
355- private async login(codeChallenge: string, scopes: string[] = []) {
369+ private async login(
370+ codeChallenge: string,
371+ hubEnv: HubEnv,
372+ scopes: string[] = [],
373+ ) {
356374 return await window.withProgress<string>(
357375 {
358376 location: ProgressLocation.Notification,
@@ -369,7 +387,7 @@
369387 const url = new URL("https://api.workos.com/user_management/authorize");
370388 const params = {
371389 response_type: "code",
372- client_id: controlPlaneEnv.WORKOS_CLIENT_ID,
390+ client_id: hubEnv.WORKOS_CLIENT_ID,
373391 redirect_uri: this.redirectUri,
374392 state: stateId,
375393 code_challenge: codeChallenge,
@@ -458,7 +476,11 @@
458476 * @param token
459477 * @returns
460478 */
461- private async getUserInfo(token: string, codeVerifier: string) {
479+ private async getUserInfo(
480+ token: string,
481+ codeVerifier: string,
482+ hubEnv: HubEnv,
483+ ) {
462484 const resp = await fetch(
463485 "https://api.workos.com/user_management/authenticate",
464486 {
@@ -467,7 +489,7 @@
467489 "Content-Type": "application/json",
468490 },
469491 body: JSON.stringify({
470- client_id: controlPlaneEnv.WORKOS_CLIENT_ID,
492+ client_id: hubEnv.WORKOS_CLIENT_ID,
471493 code_verifier: codeVerifier,
472494 grant_type: "authorization_code",
473495 code: token,
@@ -484,6 +506,12 @@
484506 silent: boolean,
485507 useOnboarding: boolean,
486508 ): Promise<ControlPlaneSessionInfo | undefined> {
509+ if (!isHubEnv(controlPlaneEnv)) {
510+ return {
511+ AUTH_TYPE: AuthType.OnPrem,
512+ };
513+ }
514+
487515 try {
488516 if (useOnboarding) {
489517 WorkOsAuthProvider.useOnboardingUri = true;
@@ -498,6 +526,7 @@
498526 return undefined;
499527 }
500528 return {
529+ AUTH_TYPE: controlPlaneEnv.AUTH_TYPE,
501530 accessToken: session.accessToken,
502531 account: {
503532 id: session.account.id,
modified gui/package-lock.json +0 −0

Not shown: the file is larger than the hub shows, or this page holds as much as it shows. View the file.

modified gui/src/context/Auth.tsx +1 −1
@@ -2,7 +2,7 @@
22 OrganizationDescription,
33 ProfileDescription,
44 } from "core/config/ProfileLifecycleManager";
5-import { ControlPlaneSessionInfo } from "core/control-plane/client";
5+import { ControlPlaneSessionInfo } from "core/control-plane/AuthTypes";
66 import React, {
77 createContext,
88 useCallback,
modified gui/src/context/MockIdeMessenger.ts +2 −0
@@ -1,4 +1,5 @@
11 import { IDE, PromptLog } from "core";
2+import { AuthType } from "core/control-plane/AuthTypes";
23 import {
34 FromIdeProtocol,
45 FromWebviewProtocol,
@@ -38,6 +39,7 @@
3839 ]);
3940 case "getControlPlaneSessionInfo":
4041 return returnFor("getControlPlaneSessionInfo", {
42+ AUTH_TYPE: AuthType.WorkOsStaging,
4143 accessToken: "",
4244 account: {
4345 label: "",
modified gui/src/pages/config/AccountButton.tsx +6 −0
@@ -1,5 +1,6 @@
11 import { UserCircleIcon } from "@heroicons/react/24/solid";
22
3+import { isHubSession } from "core/control-plane/AuthTypes";
34 import { SecondaryButton } from "../../components";
45 import {
56 Popover,
@@ -27,6 +28,11 @@
2728 );
2829 }
2930
31+ // No login button for on-prem deployments
32+ if (!isHubSession(session)) {
33+ return null;
34+ }
35+
3036 return (
3137 <Popover className="relative">
3238 {({ close }) => (