Skip to content

Commit f6b7413

Browse files
committed
[codecane] Add SDK environment info display for testing
Added getEnvironmentInfo() method to CodebuffClient that exposes both raw NEXT_PUBLIC_* environment variables and computed SDK constants (WEBSITE_URL, BACKEND_URL, WEBSOCKET_URL, IS_DEV, IS_TEST, IS_PROD). Updated CLI welcome message to display SDK environment alongside CLI environment variables. This helps verify that env vars are flowing correctly through the build pipeline: build process -> CLI binary -> SDK. Changes marked with [TEST] comments for easy identification and removal.
1 parent 21cf743 commit f6b7413

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

cli/src/chat.tsx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import { clientEnvVars } from '@codebuff/common/env-schema'
5959
import { openFileAtPath } from './utils/open-file'
6060
import { formatValidationError } from './utils/validation-error-formatting'
6161
import { createValidationErrorBlocks } from './utils/create-validation-error-blocks'
62+
import { getCodebuffClient } from './utils/codebuff-client'
6263

6364
import type { User } from './utils/auth'
6465
import type { ToolName } from '@codebuff/sdk'
@@ -289,10 +290,37 @@ export const App = ({
289290

290291
blocks.push({
291292
type: 'text',
292-
content: `\nEnvironment variables:\n${envVarsList}`,
293+
content: `\nCLI Environment variables:\n${envVarsList}`,
293294
marginTop: 1,
294295
})
295296

297+
// [TEST] Display SDK environment variables
298+
const client = getCodebuffClient()
299+
if (client) {
300+
const sdkEnv = client.getEnvironmentInfo()
301+
const sdkEnvLines = [
302+
'Raw SDK env vars:',
303+
...Object.entries(sdkEnv.rawEnv).map(
304+
([key, value]) => ` ${key}=${value}`,
305+
),
306+
'',
307+
'Computed SDK constants:',
308+
...Object.entries(sdkEnv.computed).map(([key, value]) => {
309+
const displayValue =
310+
typeof value === 'string' && value.length > 50
311+
? value.substring(0, 47) + '...'
312+
: String(value)
313+
return ` ${key}=${displayValue}`
314+
}),
315+
].join('\n')
316+
317+
blocks.push({
318+
type: 'text',
319+
content: `\nSDK Environment:\n${sdkEnvLines}`,
320+
marginTop: 1,
321+
})
322+
}
323+
296324
// Calculate path from home directory to repository root
297325
// agentsDir is typically in the root, so use its parent as the repository root
298326
const homeDir = os.homedir()

sdk/src/client.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { BACKEND_URL, WEBSITE_URL } from './constants'
1+
import { BACKEND_URL, WEBSITE_URL, WEBSOCKET_URL, IS_DEV, IS_TEST, IS_PROD } from './constants'
22
import { run } from './run'
33
import { API_KEY_ENV_VAR } from '../../common/src/old-constants'
4+
import { env } from '@codebuff/common/env'
45

56
import type { RunOptions, CodebuffClientOptions } from './run'
67
import type { RunState } from './run-state'
@@ -81,4 +82,29 @@ export class CodebuffClient {
8182
return false
8283
}
8384
}
85+
86+
/**
87+
* [TEST] Get environment information from the SDK
88+
*
89+
* @returns Object containing SDK environment variables and computed constants
90+
*/
91+
public getEnvironmentInfo() {
92+
return {
93+
// Raw env vars
94+
rawEnv: {
95+
NEXT_PUBLIC_CB_ENVIRONMENT: env.NEXT_PUBLIC_CB_ENVIRONMENT,
96+
NEXT_PUBLIC_CODEBUFF_APP_URL: env.NEXT_PUBLIC_CODEBUFF_APP_URL,
97+
NEXT_PUBLIC_CODEBUFF_BACKEND_URL: env.NEXT_PUBLIC_CODEBUFF_BACKEND_URL,
98+
},
99+
// Computed constants
100+
computed: {
101+
WEBSITE_URL,
102+
BACKEND_URL,
103+
WEBSOCKET_URL,
104+
IS_DEV,
105+
IS_TEST,
106+
IS_PROD,
107+
},
108+
}
109+
}
84110
}

0 commit comments

Comments
 (0)