Skip to content

Commit 80c79e8

Browse files
Sync public snapshot from freebuff-private
Source: CodebuffAI/freebuff-private@c0ffc5fe85e218f98057d2fc3651c3217b4f64f3
1 parent 1c0643d commit 80c79e8

4 files changed

Lines changed: 42 additions & 28 deletions

File tree

bun.lock

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/src/utils/__tests__/message-block-helpers.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,7 @@ describe('extractBlockById', () => {
975975
blocks,
976976
'nested-child',
977977
)
978+
expect(remainingBlocks).toHaveLength(1)
978979
expect((remainingBlocks[0] as AgentContentBlock).blocks).toHaveLength(0)
979980
expect(extractedBlock).not.toBeNull()
980981
expect((extractedBlock as AgentContentBlock).agentId).toBe('nested-child')
@@ -1016,6 +1017,7 @@ describe('extractBlockById', () => {
10161017
blocks,
10171018
'extract-me',
10181019
)
1020+
expect(remainingBlocks).toHaveLength(1)
10191021
const parentBlock = remainingBlocks[0] as AgentContentBlock
10201022
expect(parentBlock.blocks).toHaveLength(2)
10211023
expect((parentBlock.blocks![0] as TextContentBlock).content).toBe(
@@ -1195,6 +1197,22 @@ describe('updateToolBlockWithOutput', () => {
11951197
expect((result[0] as ToolContentBlock).output).toBe('outerr')
11961198
})
11971199

1200+
test('falls back to formatted output when terminal payload has no stdout/stderr', () => {
1201+
const blocks: ContentBlock[] = [
1202+
{
1203+
type: 'tool',
1204+
toolCallId: 'tool-123',
1205+
toolName: 'run_terminal_command',
1206+
input: { command: 'cmd' },
1207+
},
1208+
]
1209+
const result = updateToolBlockWithOutput(blocks, {
1210+
toolCallId: 'tool-123',
1211+
toolOutput: [{ type: 'json', value: { exitCode: 1 } }],
1212+
})
1213+
expect((result[0] as ToolContentBlock).output).toBe('exitCode: 1')
1214+
})
1215+
11981216
test('does not update non-matching tool block', () => {
11991217
const blocks: ContentBlock[] = [
12001218
{

cli/src/utils/message-block-helpers.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,8 @@ const checkBlockIsUnderParent = (
476476
if (block.type === 'agent' && block.agentId === parentAgentId) {
477477
// Found the parent, check if target is anywhere in its children
478478
return findBlockInChildren(block.blocks || [], targetAgentId)
479-
} else if (block.type === 'agent' && block.blocks) {
479+
}
480+
if (block.type === 'agent' && block.blocks) {
480481
// Recurse into other agent blocks to find the parent
481482
if (checkBlockIsUnderParent(block.blocks, targetAgentId, parentAgentId)) {
482483
return true
@@ -502,14 +503,16 @@ export const extractBlockById = (
502503
if (block.type === 'agent' && block.agentId === targetAgentId) {
503504
extractedBlock = block
504505
// Don't add to result - we're extracting it
505-
} else if (block.type === 'agent' && block.blocks) {
506+
continue
507+
}
508+
if (block.type === 'agent' && block.blocks) {
506509
result.push({
507510
...block,
508511
blocks: extractRecursively(block.blocks),
509512
})
510-
} else {
511-
result.push(block)
513+
continue
512514
}
515+
result.push(block)
513516
}
514517
return result
515518
}
@@ -659,19 +662,17 @@ export const updateToolBlockWithOutput = (
659662

660663
return blocks.map((block) => {
661664
if (block.type === 'tool' && block.toolCallId === toolCallId) {
662-
let output: string
663-
if (block.toolName === 'run_terminal_command') {
664-
const parsed = (toolOutput?.[0] as any)?.value
665-
if (parsed?.stdout || parsed?.stderr) {
666-
output = (parsed.stdout || '') + (parsed.stderr || '')
667-
} else {
668-
output = formatToolOutput(toolOutput)
669-
}
670-
} else {
671-
output = formatToolOutput(toolOutput)
665+
if (block.toolName !== 'run_terminal_command') {
666+
return { ...block, output: formatToolOutput(toolOutput) }
672667
}
668+
const parsed = (toolOutput?.[0] as any)?.value
669+
const output =
670+
parsed?.stdout || parsed?.stderr
671+
? (parsed.stdout || '') + (parsed.stderr || '')
672+
: formatToolOutput(toolOutput)
673673
return { ...block, output }
674-
} else if (block.type === 'agent' && block.blocks) {
674+
}
675+
if (block.type === 'agent' && block.blocks) {
675676
const updatedBlocks = updateToolBlockWithOutput(block.blocks, options)
676677
// Avoid creating new block if nested blocks didn't change
677678
if (isEqual(block.blocks, updatedBlocks)) {

cli/src/utils/time-format.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
import { formatTimeUntil } from '@codebuff/common/util/dates'
22

33
/**
4-
* Format time until reset in human-readable form.
4+
* Format time until reset in human-readable form, including days.
55
* @param resetDate - The date when the quota/resource resets
6-
* @returns Human-readable string like "2h 30m" or "45m"
6+
* @returns Human-readable string like "4d 7h" or "2h 30m"
77
*/
8-
export const formatResetTime = (resetDate: Date | null): string => {
8+
export const formatResetTimeLong = (resetDate: Date | string | null): string => {
99
if (!resetDate) return ''
1010
return formatTimeUntil(resetDate, { fallback: 'now' })
1111
}
1212

1313
/**
14-
* Format time until reset in human-readable form, including days.
14+
* Alias for {@link formatResetTimeLong} with a narrower `Date`-only parameter
15+
* type.
1516
* @param resetDate - The date when the quota/resource resets
1617
* @returns Human-readable string like "4d 7h" or "2h 30m"
1718
*/
18-
export const formatResetTimeLong = (resetDate: Date | string | null): string => {
19-
if (!resetDate) return ''
20-
return formatTimeUntil(resetDate, { fallback: 'now' })
21-
}
19+
export const formatResetTime = (resetDate: Date | null): string =>
20+
formatResetTimeLong(resetDate)

0 commit comments

Comments
 (0)