Skip to content

Commit fb96ff9

Browse files
authored
Merge pull request #3231 from Kilo-Org/bdo/add-config-command
Add slash config command to cli
2 parents 2cf0cb7 + 2375945 commit fb96ff9

File tree

4 files changed

+99
-0
lines changed

4 files changed

+99
-0
lines changed

apps/kilocode-docs/docs/cli.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ to start the CLI and begin a new task with your preferred model and relevant mod
4242
| `/model list` | List available models | |
4343
| `/model info` | Prints description for a specific model by name | `/model info z-ai/glm-4.5v` |
4444
| `/model select` | Select and switch to a new model | |
45+
| `/config` | Open configuration editor (same as `kilocode config`) | |
4546
| `/new` | Start a new task with the agent with a clean slate | |
4647
| `/help` | List available commands and how to use them | |
4748
| `/exit` | Exit the CLI | |
@@ -56,6 +57,10 @@ You can reference the [Provider Configuration Guide](https://github.com/Kilo-Org
5657

5758
to complete configuration with an interactive workflow on the command line.
5859

60+
:::tip
61+
You can also use the `/config` slash command during an interactive session, which is equivalent to running `kilocode config`.
62+
:::
63+
5964
## Autonomous mode (Non-Interactive)
6065

6166
Autonomous mode allows Kilo Code to run in automated environments like CI/CD pipelines without requiring user interaction.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { describe, it, expect, vi, beforeEach } from "vitest"
2+
import { configCommand } from "../config.js"
3+
import type { CommandContext } from "../core/types.js"
4+
import openConfigFile from "../../config/openConfig.js"
5+
6+
// Mock the openConfigFile function
7+
vi.mock("../../config/openConfig.js", () => ({
8+
default: vi.fn(),
9+
}))
10+
11+
describe("configCommand", () => {
12+
let mockContext: CommandContext
13+
let addMessageSpy: ReturnType<typeof vi.fn>
14+
15+
beforeEach(() => {
16+
vi.clearAllMocks()
17+
addMessageSpy = vi.fn()
18+
19+
mockContext = {
20+
input: "/config",
21+
args: [],
22+
options: {},
23+
sendMessage: vi.fn(),
24+
addMessage: addMessageSpy,
25+
clearMessages: vi.fn(),
26+
replaceMessages: vi.fn(),
27+
clearTask: vi.fn(),
28+
setMode: vi.fn(),
29+
exit: vi.fn(),
30+
routerModels: null,
31+
currentProvider: null,
32+
kilocodeDefaultModel: "",
33+
updateProviderModel: vi.fn(),
34+
refreshRouterModels: vi.fn(),
35+
updateProvider: vi.fn(),
36+
profileData: null,
37+
balanceData: null,
38+
profileLoading: false,
39+
balanceLoading: false,
40+
}
41+
})
42+
43+
it("should have correct metadata", () => {
44+
expect(configCommand.name).toBe("config")
45+
expect(configCommand.aliases).toContain("c")
46+
expect(configCommand.aliases).toContain("settings")
47+
expect(configCommand.category).toBe("settings")
48+
expect(configCommand.priority).toBe(8)
49+
})
50+
51+
it("should open config file successfully", async () => {
52+
vi.mocked(openConfigFile).mockResolvedValue(undefined)
53+
54+
await configCommand.handler(mockContext)
55+
56+
expect(addMessageSpy).toHaveBeenCalledWith(
57+
expect.objectContaining({
58+
type: "system",
59+
content: "Opening configuration file...",
60+
}),
61+
)
62+
expect(openConfigFile).toHaveBeenCalled()
63+
})
64+
})

cli/src/commands/config.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* /config command - Open the CLI configuration file
3+
*/
4+
5+
import type { Command } from "./core/types.js"
6+
import openConfigFile from "../config/openConfig.js"
7+
8+
export const configCommand: Command = {
9+
name: "config",
10+
aliases: ["c", "settings"],
11+
description: "Open the CLI configuration file in your default editor",
12+
usage: "/config",
13+
examples: ["/config"],
14+
category: "settings",
15+
priority: 8,
16+
handler: async (context) => {
17+
const { addMessage } = context
18+
19+
addMessage({
20+
id: Date.now().toString(),
21+
type: "system",
22+
content: "Opening configuration file...",
23+
ts: Date.now(),
24+
})
25+
26+
await openConfigFile()
27+
},
28+
}

cli/src/commands/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { modeCommand } from "./mode.js"
1515
import { modelCommand } from "./model.js"
1616
import { profileCommand } from "./profile.js"
1717
import { teamsCommand } from "./teams.js"
18+
import { configCommand } from "./config.js"
1819

1920
/**
2021
* Initialize all commands
@@ -29,4 +30,5 @@ export function initializeCommands(): void {
2930
commandRegistry.register(modelCommand)
3031
commandRegistry.register(profileCommand)
3132
commandRegistry.register(teamsCommand)
33+
commandRegistry.register(configCommand)
3234
}

0 commit comments

Comments
 (0)