Skip to content

Commit b1edc87

Browse files
feat(cli): ensure SDK is built as part of prebuild to keep CLI and SDK artifacts in sync. Also refine YAML rendering in the Codebuff client to robustly handle multi-line strings and nested objects.
🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
1 parent 79476f0 commit b1edc87

File tree

2 files changed

+34
-19
lines changed

2 files changed

+34
-19
lines changed

cli/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
},
1717
"scripts": {
1818
"dev": "bun run --watch src/index.tsx",
19-
"prebuild": "bun run build:opentui",
19+
"prebuild": "bun run build:sdk && bun run build:opentui",
2020
"build": "bun build src/index.tsx --outdir dist --target node --format esm",
21+
"build:sdk": "cd ../sdk && bun run build",
2122
"build:opentui": "cd ../packages/opentui && bun run build",
2223
"start": "bun run dist/index.js",
2324
"typecheck": "tsc --noEmit -p ."

cli/src/utils/codebuff-client.ts

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,44 +46,58 @@ export function getToolDisplayInfo(toolName: string): {
4646

4747
function toYaml(obj: any, indent = 0): string {
4848
const spaces = ' '.repeat(indent)
49-
49+
5050
if (obj === null || obj === undefined) {
5151
return 'null'
5252
}
53-
53+
5454
if (typeof obj === 'string') {
5555
if (obj.includes('\n')) {
5656
const lines = obj.split('\n')
57-
return '|\n' + lines.map(line => ' '.repeat(indent + 1) + line).join('\n')
57+
return (
58+
'|\n' + lines.map((line) => ' '.repeat(indent + 1) + line).join('\n')
59+
)
5860
}
5961
return obj.includes(':') || obj.includes('#') ? `"${obj}"` : obj
6062
}
61-
63+
6264
if (typeof obj === 'number' || typeof obj === 'boolean') {
6365
return String(obj)
6466
}
65-
67+
6668
if (Array.isArray(obj)) {
6769
if (obj.length === 0) return '[]'
68-
return '\n' + obj.map(item => spaces + '- ' + toYaml(item, indent + 1).trimStart()).join('\n')
70+
return (
71+
'\n' +
72+
obj
73+
.map((item) => spaces + '- ' + toYaml(item, indent + 1).trimStart())
74+
.join('\n')
75+
)
6976
}
70-
77+
7178
if (typeof obj === 'object') {
7279
const entries = Object.entries(obj)
7380
if (entries.length === 0) return '{}'
74-
75-
return entries.map(([key, value]) => {
76-
const yamlValue = toYaml(value, indent + 1)
77-
if (typeof value === 'object' && value !== null && !Array.isArray(value) && Object.keys(value).length > 0) {
78-
return `${spaces}${key}:\n${yamlValue}`
79-
}
80-
if (typeof value === 'string' && value.includes('\n')) {
81+
82+
return entries
83+
.map(([key, value]) => {
84+
const yamlValue = toYaml(value, indent + 1)
85+
if (
86+
typeof value === 'object' &&
87+
value !== null &&
88+
!Array.isArray(value) &&
89+
Object.keys(value).length > 0
90+
) {
91+
return `${spaces}${key}:\n${yamlValue}`
92+
}
93+
if (typeof value === 'string' && value.includes('\n')) {
94+
return `${spaces}${key}: ${yamlValue}`
95+
}
8196
return `${spaces}${key}: ${yamlValue}`
82-
}
83-
return `${spaces}${key}: ${yamlValue}`
84-
}).join('\n')
97+
})
98+
.join('\n')
8599
}
86-
100+
87101
return String(obj)
88102
}
89103

0 commit comments

Comments
 (0)