server, ui: only offer a working directory when a tool reads it (#26762)

The working directory chip showed up as soon as the server exposed any
builtin tool, so a server started with just get_datetime, or a user who
turned every filesystem tool off in the settings, still got a control
that nothing would read.

Tools now declare whether they resolve their paths and run against the
working directory, next to the write permission they already publish in
the /tools listing. The WebUI shows the chip and enables the /cwd
command only when at least one such tool is both served and left
enabled.
This commit is contained in:
Pascal
2026-08-08 16:36:21 +02:00
committed by GitHub
parent dd2c7c4471
commit 18f7ad7fc9
8 changed files with 38 additions and 7 deletions
@@ -156,7 +156,7 @@
focusInput: refocusInput,
getShowModelSelector: () => showModelSelector,
hasPrompts: () => mcpStore.hasPromptsCapability(conversationsStore.getAllMcpServerOverrides()),
hasBuiltinTools: () => toolsStore.builtinTools.length > 0,
hasCwdTools: () => toolsStore.hasEnabledCwdTools,
getCwd: () => cwd,
getServerHome: () => toolsStore.serverHome ?? null,
openModelSelector: () => chatFormActionsRef?.openModelSelector(),
@@ -651,7 +651,7 @@
<ContextGaugePopup />
{#if toolsStore.builtinTools.length > 0}
{#if toolsStore.hasEnabledCwdTools}
<ChatFormWorkingDirectory
directory={cwd}
isOpen={pickers.isWorkingDirectoryPickerOpen}
+2 -2
View File
@@ -8,7 +8,7 @@ interface ChatCommandsOptions {
/** Gates `/prompt`. */
hasPrompts: () => boolean;
/** Gates `/cwd`. */
hasBuiltinTools: () => boolean;
hasCwdTools: () => boolean;
}
/**
@@ -32,7 +32,7 @@ export function getChatCommands(options: ChatCommandsOptions): ChatFormCommand[]
description: SET_WORKING_DIRECTORY_LABEL,
keywords: ['current working directory'],
action: ChatFormCommandAction.CWD,
disabled: !options.hasBuiltinTools()
disabled: !options.hasCwdTools()
},
{
name: 'model',
@@ -24,7 +24,7 @@ export interface UseChatFormPickersOptions {
/** Gates `/prompt`. */
hasPrompts: () => boolean;
/** Gates `/cwd`. */
hasBuiltinTools: () => boolean;
hasCwdTools: () => boolean;
getCwd: () => string | null;
/** Mention search fallback scope. */
getServerHome: () => string | null;
@@ -63,7 +63,7 @@ export function useChatFormPickers(opts: UseChatFormPickersOptions) {
getChatCommands({
showModelSelector: opts.getShowModelSelector(),
hasPrompts: opts.hasPrompts,
hasBuiltinTools: opts.hasBuiltinTools
hasCwdTools: opts.hasCwdTools
})
);
+21
View File
@@ -27,6 +27,9 @@ class ToolsStore {
private _loading = $state(false);
private _error = $state<string | null>(null);
private _disabledTools = $state(new SvelteSet<string>());
// builtin tools that resolve their paths against the working directory,
// as declared by the server in its `/tools` listing
private _cwdAwareTools = $state(new SvelteSet<string>());
private _toolsEndpointUnreachable = $state(false);
private _serverHome = $state<string | null | undefined>(undefined);
@@ -476,6 +479,21 @@ class ToolsStore {
return this.getEnabledToolsForLLM().length > 0;
}
/**
* Check if a working directory is worth setting: at least one builtin tool
* that reads it is both served and left enabled by the user.
*/
get hasEnabledCwdTools(): boolean {
return this._builtinTools.some((def) => {
const name = def.function.name;
return (
this._cwdAwareTools.has(name) &&
!this._disabledTools.has(this.toolKey(ToolSource.BUILTIN, name))
);
});
}
async fetchBuiltinTools(): Promise<void> {
if (this._loading) return;
@@ -486,6 +504,9 @@ class ToolsStore {
try {
const toolInfos = await ToolsService.list();
this._builtinTools = toolInfos.map((info) => info.definition);
this._cwdAwareTools = new SvelteSet(
toolInfos.filter((info) => info.uses_cwd).map((info) => info.tool)
);
} catch (err) {
const errorMessage = err instanceof Error ? err.message : String(err);
this._error = errorMessage;
+1
View File
@@ -292,6 +292,7 @@ export interface ServerBuiltinToolInfo {
permissions: {
write: boolean;
};
uses_cwd: boolean;
definition: OpenAIToolDefinition;
}