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
40 changes: 40 additions & 0 deletions apps/cli/src/commands/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Result } from 'better-result';
import { Command } from 'commander';

import { updateModel } from '../client/index.ts';
import { ensureServer } from '../server/manager.ts';

const configModelCommand = new Command('model')
.description('Deprecated alias for "btca connect --provider ... --model ..."')
.requiredOption('-p, --provider <id>', 'Provider ID')
.requiredOption('-m, --model <id>', 'Model ID')
.action(async (options: { provider: string; model: string }, command) => {
const root = command.parent?.parent;
const globalOpts = root?.opts() as { server?: string; port?: number } | undefined;

const result = await Result.tryPromise(async () => {
const server = await ensureServer({
serverUrl: globalOpts?.server,
port: globalOpts?.port,
quiet: true
});

const updated = await updateModel(server.url, options.provider, options.model);
server.stop();
Comment on lines +22 to +23
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Server not stopped on updateModel failure

If updateModel throws, server.stop() on line 23 is never reached because the exception propagates out of the tryPromise callback immediately. This leaves an auto-started server running and can cause port conflicts for subsequent commands.

Consider wrapping the server.stop() call in a try/finally block:

Suggested change
const updated = await updateModel(server.url, options.provider, options.model);
server.stop();
try {
const updated = await updateModel(server.url, options.provider, options.model);
console.warn(
'Deprecation: "btca config model" will be removed in a future release. Use "btca connect --provider ... --model ...".'
);
console.log(`Model updated: ${updated.provider}/${updated.model}`);
} finally {
server.stop();
}
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/cli/src/commands/config.ts
Line: 22-23

Comment:
**Server not stopped on `updateModel` failure**

If `updateModel` throws, `server.stop()` on line 23 is never reached because the exception propagates out of the `tryPromise` callback immediately. This leaves an auto-started server running and can cause port conflicts for subsequent commands.

Consider wrapping the `server.stop()` call in a `try/finally` block:

```suggestion
			try {
				const updated = await updateModel(server.url, options.provider, options.model);

				console.warn(
					'Deprecation: "btca config model" will be removed in a future release. Use "btca connect --provider ... --model ...".'
				);
				console.log(`Model updated: ${updated.provider}/${updated.model}`);
			} finally {
				server.stop();
			}
```

How can I resolve this? If you propose a fix, please make it concise.


console.warn(
'Deprecation: "btca config model" will be removed in a future release. Use "btca connect --provider ... --model ...".'
);
console.log(`Model updated: ${updated.provider}/${updated.model}`);
});

if (Result.isError(result)) {
const message = result.error instanceof Error ? result.error.message : String(result.error);
console.error(`Error: ${message}`);
process.exit(1);
}
});

export const configCommand = new Command('config')
.description('Deprecated config command compatibility aliases')
.addCommand(configModelCommand);
6 changes: 6 additions & 0 deletions apps/cli/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ describe('cli dispatch', () => {
expect(result.output).toContain('Usage: btca add');
});

test('keeps nested subcommand help contextual for btca config model', () => {
const result = runCli(['config', 'model', '--help']);
expect(result.exitCode).toBe(0);
expect(result.output).toContain('Usage: btca config model');
});

test('rejects unknown top-level commands with a suggestion', () => {
const result = runCli(['remoev'], 250);
expect(result.exitCode).toBe(1);
Expand Down
2 changes: 2 additions & 0 deletions apps/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Command } from 'commander';
import { addCommand } from './commands/add.ts';
import { askCommand } from './commands/ask.ts';
import { clearCommand } from './commands/clear.ts';
import { configCommand } from './commands/config.ts';
import { connectCommand } from './commands/connect.ts';
import { disconnectCommand } from './commands/disconnect.ts';
import { initCommand } from './commands/init.ts';
Expand Down Expand Up @@ -53,6 +54,7 @@ program.addCommand(askCommand);

// Configuration commands
program.addCommand(connectCommand);
program.addCommand(configCommand);
program.addCommand(disconnectCommand);
program.addCommand(initCommand);
program.addCommand(statusCommand);
Expand Down
12 changes: 11 additions & 1 deletion apps/docs/guides/cli-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Options:

- `-g, --global` sets the flag, but target resolution still depends on whether a project config exists.
- `-n, --name <name>` sets a resource name.
- `-b, --branch <branch>` sets a branch (default `main`).
- `-b, --branch <branch>` sets a branch (auto-detected when omitted).
- `-s, --search-path <path...>` sets one or more search paths.
- `--notes <notes>` sets special notes.
- `-t, --type <git|local|npm>` forces the resource type.
Expand Down Expand Up @@ -168,6 +168,16 @@ For `openai-compat`, the interactive flow additionally prompts for:
- Model ID (required): saved as `model` in `btca.config.jsonc`.
- API key (optional): only if your server requires auth, stored in OpenCode auth.

## `btca config model` (compatibility alias)

Backward-compatible alias for model updates:

```bash
btca config model --provider <id> --model <id>
```

This command delegates to the same update path as `btca connect` and prints a deprecation notice.

## `btca status`

Shows current btca status.
Expand Down