Skip to content

Commit 35a4a68

Browse files
feat(app): add /reload to reload configuration (#59887)
Co-authored-by: vimtor <[email protected]>
1 parent b6c43a5 commit 35a4a68

3 files changed

Lines changed: 64 additions & 0 deletions

File tree

‎packages/app/e2e/regression/composer.spec.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,10 +915,32 @@ test("lists slash commands in their built-in order", async ({ page }) => {
915915
"/mcp",
916916
"/model",
917917
"/connect",
918+
"/reload",
918919
"/btw",
919920
])
920921
})
921922

923+
test("/reload reloads the server's configuration once and reports it", async ({ page }) => {
924+
const { editor } = await openSession(page, { name: "ComposerReload", provider: NO_PROVIDER })
925+
const reloaded = Promise.withResolvers<void>()
926+
let reloads = 0
927+
await page.route(/\/api\/location\/reload$/, async (route) => {
928+
reloads++
929+
await reloaded.promise
930+
await route.fulfill({ status: 204 })
931+
})
932+
933+
await editor.fill("/reload")
934+
await expect(page.locator('[data-suggestion-id="config.reload"]')).toHaveAttribute("data-active", "")
935+
await editor.press("Enter")
936+
await expect(page.getByText("Reloading configuration…", { exact: true })).toBeVisible()
937+
reloaded.resolve()
938+
await expect(page.getByText("Configuration reloaded", { exact: true })).toBeVisible()
939+
await expect(page.getByText("Reloading configuration…", { exact: true })).toBeHidden()
940+
await expect(editor).toBeEmpty()
941+
expect(reloads).toBe(1)
942+
})
943+
922944
const followUp = "Add follow-up, / for commands, @ for context…"
923945

924946
for (const row of [

‎packages/app/src/composer/commands.tsx‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import { useSessionLayout } from "@/session/session-layout"
99
import { createSessionOwnership } from "@/session/session-ownership"
1010
import { useWorkspaceLocation } from "@/workspaces/location"
1111
import { useData } from "@/runtime/server/current"
12+
import { useServerSDK } from "@/runtime/server/client"
13+
import { formatServerError } from "@/runtime/server/errors"
14+
import { showToast } from "@/shell/notifications/toast"
15+
import { toaster } from "@opencode/ui/toast"
1216

1317
const withCategory = (category: string) => {
1418
return (option: Omit<CommandOption, "category">): CommandOption => ({
@@ -26,12 +30,14 @@ export const useComposerCommands = (input: { model?: ModelSelection } = {}) => {
2630
const workspace = useWorkspaceLocation()
2731
const { sessionKey, params } = useSessionLayout()
2832
const data = useData()
33+
const sdk = useServerSDK()
2934
const sessionOwnership = createSessionOwnership(sessionKey)
3035
const model = input.model ?? local.model
3136
const modelCommand = withCategory(language.t("command.category.model"))
3237
const agentCommand = withCategory(language.t("command.category.agent"))
3338
const providerCommand = withCategory(language.t("command.category.provider"))
3439
const viewCommand = withCategory(language.t("command.category.view"))
40+
const serverCommand = withCategory(language.t("command.category.server"))
3541

3642
// Mirrors the TUI's `/connect`, which the Console's setup steps tell people to run.
3743
const connectProvider = async () => {
@@ -40,6 +46,28 @@ export const useComposerCommands = (input: { model?: ModelSelection } = {}) => {
4046
void dialog.show(() => <DialogConnectProvider directory={workspace().directory} selection={model} />)
4147
}
4248

49+
// Mirrors the TUI's `/reload`. The server rebuilds every loaded location and announces the changed agents,
50+
// commands, models and skills, so the data layer refreshes them without restarting the app.
51+
const reloadConfig = () => {
52+
const pending = showToast({
53+
variant: "loading",
54+
title: language.t("command.config.reload.pending"),
55+
persistent: true,
56+
})
57+
58+
void sdk.api.location
59+
.reload()
60+
.then(() => showToast({ variant: "success", title: language.t("command.config.reload.done") }))
61+
.catch((error) =>
62+
showToast({
63+
variant: "error",
64+
title: language.t("command.config.reload.failed"),
65+
description: formatServerError(error, language.t),
66+
}),
67+
)
68+
.finally(() => toaster.dismiss(pending))
69+
}
70+
4371
const chooseModel = () => {
4472
const Picker = settings.general.newModelPicker() ? DialogSelectModelNext : DialogSelectModel
4573
sessionOwnership.capture().run(() => {
@@ -50,10 +78,12 @@ export const useComposerCommands = (input: { model?: ModelSelection } = {}) => {
5078
const viewUsage = async () => {
5179
const { DialogUsage } = await import("@/usage/dialog")
5280
const current = model.current()
81+
5382
// Console refuses with 402 only when the workspace can't pay, which the dialog explains.
5483
const last = params.id
5584
? data.session.message.list(params.id)?.findLast((message) => message.type === "assistant")
5685
: undefined
86+
5787
void dialog.show(() => (
5888
<DialogUsage
5989
location={workspace().ref}
@@ -93,6 +123,13 @@ export const useComposerCommands = (input: { model?: ModelSelection } = {}) => {
93123
slash: "connect",
94124
onSelect: connectProvider,
95125
}),
126+
serverCommand({
127+
id: "config.reload",
128+
title: language.t("command.config.reload"),
129+
description: language.t("command.config.reload.description"),
130+
slash: "reload",
131+
onSelect: reloadConfig,
132+
}),
96133
agentCommand({
97134
id: "agent.cycle",
98135
title: language.t("command.agent.cycle"),

‎packages/app/src/runtime/i18n/en.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ export const dict = {
5757
"command.provider.connect": "Connect an integration",
5858
"command.provider.connect.description": "Sign in to OpenCode Go, OpenCode Console, or another model provider",
5959
"command.settings.open": "Open settings",
60+
"command.config.reload": "Reload configuration",
61+
"command.config.reload.description": "Reload agents, commands, skills, MCP servers and plugins from your config",
62+
"command.config.reload.pending": "Reloading configuration…",
63+
"command.config.reload.done": "Configuration reloaded",
64+
"command.config.reload.failed": "Couldn't reload configuration",
6065
"command.usage.view": "View usage",
6166
"command.usage.view.description": "See your OpenCode Go allowance and Console budgets",
6267
"command.session.location.cycle": "Cycle session location",

0 commit comments

Comments
 (0)