Skip to content

Commit 580fe83

Browse files
committed
findGitRoot can return null
1 parent c49dc90 commit 580fe83

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

cli/src/project-files.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function setProjectRoot(dir: string) {
1818

1919
export function getProjectRoot() {
2020
if (!projectRoot) {
21-
projectRoot = findGitRoot()
21+
projectRoot = findGitRoot() ?? process.cwd()
2222
}
2323
return projectRoot
2424
}

cli/src/utils/codebuff-client.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { API_KEY_ENV_VAR } from '@codebuff/common/old-constants'
12
import { CodebuffClient } from '@codebuff/sdk'
23

3-
import { API_KEY_ENV_VAR } from '@codebuff/common/old-constants'
4-
import { findGitRoot } from './git'
54
import { getAuthTokenDetails } from './auth'
65
import { loadAgentDefinitions } from './load-agent-definitions'
76
import { logger } from './logger'
7+
import { getProjectRoot } from '../project-files'
88

99
let clientInstance: CodebuffClient | null = null
1010

@@ -28,12 +28,12 @@ export function getCodebuffClient(): CodebuffClient | null {
2828
return null
2929
}
3030

31-
const gitRoot = findGitRoot()
31+
const projectRoot = getProjectRoot()
3232
try {
3333
const agentDefinitions = loadAgentDefinitions()
3434
clientInstance = new CodebuffClient({
3535
apiKey,
36-
cwd: gitRoot,
36+
cwd: projectRoot,
3737
agentDefinitions,
3838
})
3939
} catch (error) {
@@ -128,7 +128,11 @@ export function formatToolOutput(output: unknown): string {
128128
.map((item) => {
129129
if (item.type === 'json') {
130130
// Handle errorMessage in the value object
131-
if (item.value && typeof item.value === 'object' && 'errorMessage' in item.value) {
131+
if (
132+
item.value &&
133+
typeof item.value === 'object' &&
134+
'errorMessage' in item.value
135+
) {
132136
return String(item.value.errorMessage)
133137
}
134138
return toYaml(item.value)

cli/src/utils/git.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { dirname, join } from 'path'
22
import { existsSync } from 'fs'
33

4-
export function findGitRoot(): string {
4+
export function findGitRoot(): string | null {
55
let currentDir = process.cwd()
66

77
while (currentDir !== dirname(currentDir)) {
@@ -11,5 +11,5 @@ export function findGitRoot(): string {
1111
currentDir = dirname(currentDir)
1212
}
1313

14-
return process.cwd()
14+
return null
1515
}

0 commit comments

Comments
 (0)