Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions cli/src/__tests__/cli-args.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,46 @@ describe('Codebuff --trust-agents', () => {
expect(result.initialPrompt).toBe('fix it')
})
})

describe('Freebuff initial prompt', () => {
test('takes bare words as the initial prompt', () => {
const result = parseArgs({
argv: ['node', 'freebuff', 'fix the flaky login test'],
isFreebuff: true,
version: '1.0.0',
})
expect(result.initialPrompt).toBe('fix the flaky login test')
expect(result.command).toBeUndefined()
})

test('keeps login and doctor as commands, not prompts', () => {
for (const command of ['login', 'doctor']) {
const result = parseArgs({
argv: ['node', 'freebuff', command],
isFreebuff: true,
version: '1.0.0',
})
expect(result.command).toBe(command)
expect(result.initialPrompt).toBeNull()
}
})

test('joins a multi-word prompt that follows flags', () => {
const result = parseArgs({
argv: ['node', 'freebuff', '--trust-agents', 'fix', 'it'],
isFreebuff: true,
version: '1.0.0',
})
expect(result.trustAgents).toBe(true)
expect(result.initialPrompt).toBe('fix it')
})

test('leaves the codebuff prompt path alone', () => {
const result = parseArgs({
argv: ['node', 'codebuff', 'fix', 'it'],
isFreebuff: false,
version: '1.0.0',
})
expect(result.initialPrompt).toBe('fix it')
})
})
22 changes: 19 additions & 3 deletions cli/src/cli-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,12 @@ export function parseArgs({
"Load this repository's .agents files and mcp.json without asking (for CI)",
)
.addArgument(
new Argument('[command]', 'Command to run: login, or doctor to check this computer for common problems').choices(['login', 'doctor']),
new Argument(
'[prompt...]',
'Command to run (login, or doctor), or an initial prompt to send to the agent',
),
)
.allowExcessArguments(true)
.helpOption('-h, --help', 'Show this help message')
} else {
// Codebuff: full CLI with all options
Expand Down Expand Up @@ -128,9 +132,21 @@ export function parseArgs({
if (options.plan) initialMode = 'PLAN'
}

// Freebuff accepts a first task the way Codebuff does: bare words that are not
// one of its commands become the session's initial prompt, so a launcher can
// start the session with its task instead of typing it into the TUI.
const freebuffCommands: readonly string[] = ['login', 'doctor']
const freebuffCommand =
isFreebuff && args[0] !== undefined && freebuffCommands.includes(args[0])
? args[0]
: undefined

return {
initialPrompt: !isFreebuff && args.length > 0 ? args.join(' ') : null,
command: args[0],
initialPrompt:
args.length > 0 && (!isFreebuff || freebuffCommand === undefined)
? args.join(' ')
: null,
command: isFreebuff ? freebuffCommand : args[0],
agent: options.agent,
clearLogs: options.clearLogs || false,
continue: Boolean(continueFlag),
Expand Down
Loading