Skip to content

Commit b9a2db2

Browse files
committed
add finish message to print mode
1 parent 2400382 commit b9a2db2

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

common/src/types/print-mode.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ export type PrintModeText = z.infer<typeof printModeTextSchema>
3838

3939
export const printModeFinishSchema = z.object({
4040
type: z.literal('finish'),
41-
agentId: z.string(),
42-
model: z.string(),
41+
agentId: z.string().optional(),
4342
totalCost: z.number(),
4443
})
4544
export type PrintModeFinish = z.infer<typeof printModeFinishSchema>

npm-app/src/cli.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
yellow,
2828
} from 'picocolors'
2929

30+
import { PrintModeFinish } from '@codebuff/common/types/print-mode'
3031
import {
3132
killAllBackgroundProcesses,
3233
sendKillSignalToAllBackgroundProcesses,
@@ -1201,6 +1202,17 @@ export class CLI {
12011202
.flat()
12021203
.reduce((sum, credits) => sum + credits, 0)
12031204

1205+
if (printModeIsEnabled()) {
1206+
const finishObj: PrintModeFinish = {
1207+
type: 'finish',
1208+
totalCost: totalCreditsUsedThisSession,
1209+
}
1210+
const agentId = CLI.getInstance().agent
1211+
if (agentId) {
1212+
finishObj.agentId = agentId
1213+
}
1214+
printModeLog(finishObj)
1215+
}
12041216
let exitUsageMessage = `${pluralize(totalCreditsUsedThisSession, 'credit')} used this session`
12051217
if (client.usageData.remainingBalance !== null) {
12061218
exitUsageMessage += `, ${client.usageData.remainingBalance.toLocaleString()} credits left.`

0 commit comments

Comments
 (0)