fix: save agent prompt and reload changes reliably

Agent settings now correctly save an emptied system prompt instead of silently keeping the old text.

After saving agent, command, or skill settings, OpenChamber refreshes the updated configuration instead of showing stale values from a short-lived cache.

Reload actions now surface refresh failures consistently while avoiding noisy background errors.
This commit is contained in:
Bohdan Triapitsyn
2026-06-08 13:43:45 +03:00
parent b2b71198ca
commit ef71a997a8
10 changed files with 103 additions and 14 deletions
@@ -47,6 +47,10 @@ const getCommandsCacheKey = (directory: string | null): string => {
return directory?.trim() || DEFAULT_COMMANDS_CACHE_KEY;
};
export const invalidateCommandsLoadCache = (directory: string | null = getRequestDirectory()) => {
commandsLastLoadedAt.delete(getCommandsCacheKey(directory));
};
const buildCommandsSignature = (commands: Command[]): string => {
return commands
.map((command) => [
@@ -277,6 +281,7 @@ export const useCommandsStore = create<CommandsStore>()(
console.log('[CommandsStore] Command created successfully');
const needsReload = payload?.requiresReload ?? true;
invalidateCommandsLoadCache(directory);
if (needsReload) {
requiresReload = true;
await performFullConfigRefresh({
@@ -338,6 +343,7 @@ export const useCommandsStore = create<CommandsStore>()(
console.log('[CommandsStore] Command updated successfully');
const needsReload = payload?.requiresReload ?? true;
invalidateCommandsLoadCache(directory);
if (needsReload) {
requiresReload = true;
await performFullConfigRefresh({
@@ -384,6 +390,7 @@ export const useCommandsStore = create<CommandsStore>()(
console.log('[CommandsStore] Command deleted successfully');
const needsReload = payload?.requiresReload ?? true;
invalidateCommandsLoadCache(directory);
if (needsReload) {
requiresReload = true;
await performFullConfigRefresh({
@@ -495,6 +502,7 @@ async function performFullConfigRefresh(options: { message?: string; delayMs?: n
const commandsStore = useCommandsStore.getState();
invalidateCommandsLoadCache();
await commandsStore.loadCommands();
emitConfigChange("commands", { source: CONFIG_EVENT_SOURCE });
@@ -502,6 +510,7 @@ async function performFullConfigRefresh(options: { message?: string; delayMs?: n
console.error("[CommandsStore] Failed to refresh configuration after OpenCode restart:", error);
updateConfigUpdateMessage("OpenCode refresh failed. Please retry refreshing configuration manually.");
await sleep(1500);
throw error;
} finally {
finishConfigUpdate();
}