Compare commits

...
Author SHA1 Message Date
Matchy d399c82f51 fix(server): keep plugin entries other writers put in config.json (#11501)
The daemon owns plugin source entries and `paseo reload` does not pick up
edits to `plugins`, so its in-memory copy goes stale when config.json is
edited while it runs. Every plugin operation (install, enable, disable,
update, remove) then wrote that whole stale map back to disk. A hand-added
entry was silently deleted by the next operation on any other plugin, and
an entry removed by hand was written back. Local directory plugins hit
this most, since they are the ones people add by editing config.json.

Persisting a plugins patch now applies only the entries that changed
relative to the in-memory copy onto the plugins read from disk. Reload
still ignores plugin edits; they now survive until the next restart loads
them, as docs/plugins.md describes.

Verified with new DaemonConfigStore tests covering a hand-added entry, a
hand-removed entry, and removing one plugin while another sits on disk;
all three failed before the change.
2026-11-30 19:42:40 +00:00
SunicemanandShane Su 9a520f0adc Keep attached plugin slash commands out of the agent conversation (#11483)
Co-authored-by: Shane Su <26364206+suniceman@users.noreply.github.com>
2026-11-30 17:12:44 +00:00
15 changed files with 167 additions and 15 deletions
@@ -1,5 +1,11 @@
import { expect, test, type Page } from "../support/fixtures";
import { composerLocator, expectComposerVisible, submitMessage } from "../support/helpers/composer";
import { withDirectoryPlugin } from "../support/helpers/plugin-timeline";
import {
attachImageFromMenu,
composerLocator,
expectComposerVisible,
submitMessage,
} from "../support/helpers/composer";
import { openAgentRoute, seedMockAgentWorkspace } from "../support/helpers/mock-agent";
import {
expectSessionRowArchived,
@@ -140,6 +146,47 @@ async function waitForReplacementAgentId(page: Page, oldAgentId: string): Promis
}
test.describe("Client slash commands", () => {
test("keeps the draft when a typed plugin slash command has an attachment", async ({ page }) => {
test.setTimeout(90_000);
await withDirectoryPlugin({
pluginId: "attachment-slash-e2e",
source: `
export default function contribute(client) {
client.addSlashCommand({name:"picture", description:"Review an attached picture", argumentHint:"<question>", context:"agent",
onSubmit(){throw new Error("Plugin handler unexpectedly received this command");}});
return () => {};
}`,
run: async () => {
await withOpenReadyMockAgent(page, { title: "Attached slash command" }, async () => {
const input = composerLocator(page);
await input.fill("/pict");
await expect(
page.getByText("Review an attached picture", { exact: true }).first(),
).toBeVisible();
await input.fill("");
await attachImageFromMenu(page, {
name: "picture.png",
mimeType: "image/png",
buffer: Buffer.from(
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==",
"base64",
),
});
await input.fill("/picture what is this?");
await input.press("Enter");
await expect(
page.getByRole("alert").filter({ hasText: "Remove attachments to run /picture." }),
).toBeVisible();
await expect(input).toHaveValue("/picture what is this?");
await expect(page.getByTestId("composer-image-attachment-pill")).toBeVisible();
await expect(
page.getByTestId("user-message").filter({ hasText: "/picture what is this?" }),
).toHaveCount(0);
});
},
});
});
test("slash quit archives the active agent and removes its tab", async ({ page }) => {
await withOpenReadyMockAgent(page, { title: "Slash quit e2e" }, async ({ agentId, title }) => {
await runClientSlashCommand(page, "/quit");
+19 -7
View File
@@ -1671,7 +1671,16 @@ function ComposerContentImpl({
);
const runPluginClientSlashCommand = useCallback(
(resolved: { command: (typeof pluginClientSlashCommands)[number]; args: string }): boolean => {
(
resolved: { command: (typeof pluginClientSlashCommands)[number]; args: string },
hasAttachments: boolean,
) => {
if (hasAttachments) {
setSendError(
t("composer.errors.removePluginCommandAttachments", { command: resolved.command.name }),
);
return;
}
if (blurOnSubmit) messageInputRef.current?.blur();
clearDraft("sent");
replaceUserInput("");
@@ -1686,9 +1695,8 @@ function ComposerContentImpl({
toastErrorRef.current(error instanceof Error ? error.message : String(error));
},
});
return true;
},
[blurOnSubmit, clearDraft, replaceUserInput, resetSuppression, setSelectedAttachments],
[blurOnSubmit, clearDraft, replaceUserInput, resetSuppression, setSelectedAttachments, t],
);
const { pickImages } = useImageAttachmentPicker();
@@ -1988,10 +1996,12 @@ function ComposerContentImpl({
}
const pluginSlashCommand = resolvePluginClientSlashCommand({
text: payload.text,
hasAttachments: outgoingAttachments.length > 0,
commands: pluginClientSlashCommands,
});
if (pluginSlashCommand && runPluginClientSlashCommand(pluginSlashCommand)) return;
if (pluginSlashCommand) {
runPluginClientSlashCommand(pluginSlashCommand, outgoingAttachments.length > 0);
return;
}
if (blurOnSubmit) {
messageInputRef.current?.blur();
@@ -2261,10 +2271,12 @@ function ComposerContentImpl({
}
const pluginSlashCommand = resolvePluginClientSlashCommand({
text: payload.text,
hasAttachments: outgoingAttachments.length > 0,
commands: pluginClientSlashCommands,
});
if (pluginSlashCommand && runPluginClientSlashCommand(pluginSlashCommand)) return;
if (pluginSlashCommand) {
runPluginClientSlashCommand(pluginSlashCommand, outgoingAttachments.length > 0);
return;
}
queueMessage(payload.text, outgoingAttachments);
},
[
+1
View File
@@ -195,6 +195,7 @@ export const ar: TranslationResources = {
removeReview: "إزالة مرفق المراجعة",
},
errors: {
removePluginCommandAttachments: "أزل المرفقات لتشغيل الأمر /{{command}}.",
failedToSend: "فشل في إرسال الرسالة",
failedToCreateAgent: "فشل في إنشاء الوكيل",
noHostSelected: "لم يتم تحديد مضيف",
+1
View File
@@ -193,6 +193,7 @@ export const en = {
removeReview: "Remove review attachment",
},
errors: {
removePluginCommandAttachments: "Remove attachments to run /{{command}}.",
failedToSend: "Failed to send message",
failedToCreateAgent: "Failed to create agent",
noHostSelected: "No host selected",
+1
View File
@@ -196,6 +196,7 @@ export const es: TranslationResources = {
removeReview: "Eliminar archivo adjunto de reseña",
},
errors: {
removePluginCommandAttachments: "Quita los archivos adjuntos para ejecutar /{{command}}.",
failedToSend: "No se pudo enviar el mensaje",
failedToCreateAgent: "No se pudo crear el agente",
noHostSelected: "Ningún anfitrión seleccionado",
+1
View File
@@ -197,6 +197,7 @@ export const fr: TranslationResources = {
removeReview: "Retirer la revue jointe",
},
errors: {
removePluginCommandAttachments: "Retirez les pièces jointes pour exécuter /{{command}}.",
failedToSend: "Impossible d’envoyer le message",
failedToCreateAgent: "Impossible de créer l’agent",
noHostSelected: "Aucun hôte sélectionné",
+1
View File
@@ -196,6 +196,7 @@ export const ja: TranslationResources = {
removeReview: "レビュー添付ファイルを削除",
},
errors: {
removePluginCommandAttachments: "/{{command}} を実行するには添付ファイルを削除してください。",
failedToSend: "メッセージの送信に失敗しました",
failedToCreateAgent: "エージェントの作成に失敗しました",
noHostSelected: "ホストが選択されていません",
+1
View File
@@ -195,6 +195,7 @@ export const ko: TranslationResources = {
removeReview: "리뷰 첨부 제거",
},
errors: {
removePluginCommandAttachments: "/{{command}} 명령을 실행하려면 첨부 파일을 제거하세요.",
failedToSend: "메시지를 보내지 못했습니다",
failedToCreateAgent: "에이전트를 생성하지 못했습니다",
noHostSelected: "선택된 호스트가 없습니다",
+1
View File
@@ -196,6 +196,7 @@ export const ptBR: TranslationResources = {
removeReview: "Remover anexo de revisão",
},
errors: {
removePluginCommandAttachments: "Remova os anexos para executar /{{command}}.",
failedToSend: "Falha ao enviar mensagem",
failedToCreateAgent: "Falha ao criar agente",
noHostSelected: "Nenhum host selecionado",
+1
View File
@@ -196,6 +196,7 @@ export const ru: TranslationResources = {
removeReview: "Удалить вложение проверки",
},
errors: {
removePluginCommandAttachments: "Чтобы выполнить /{{command}}, удалите вложения.",
failedToSend: "Не удалось отправить сообщение",
failedToCreateAgent: "Не удалось создать агента.",
noHostSelected: "Хост не выбран",
+1
View File
@@ -195,6 +195,7 @@ export const zhCN: TranslationResources = {
removeReview: "移除 review 附件",
},
errors: {
removePluginCommandAttachments: "请先移除附件,再运行 /{{command}}。",
failedToSend: "发送消息失败",
failedToCreateAgent: "创建 Agent 失败",
noHostSelected: "未选择 Host",
@@ -33,14 +33,12 @@ describe("plugin client slash commands", () => {
expect(
resolvePluginClientSlashCommand({
text: " /review foo bar ",
hasAttachments: false,
commands: [command],
}),
).toEqual({ command, args: "foo bar" });
expect(
resolvePluginClientSlashCommand({
text: "/review foo",
hasAttachments: true,
text: "/another-command foo",
commands: [command],
}),
).toBeNull();
@@ -47,10 +47,8 @@ export function mergeSlashCommandSources<
export function resolvePluginClientSlashCommand<Command extends SlashCommandDescriptor>(input: {
text: string;
hasAttachments: boolean;
commands: readonly Command[];
}): { command: Command; args: string } | null {
if (input.hasAttachments) return null;
const match = /^\/([^\s]+)(?:\s+([\s\S]*))?$/.exec(input.text.trim());
if (!match) return null;
const command = input.commands.find((candidate) => candidate.name === match[1]);
@@ -1548,6 +1548,64 @@ describe("DaemonConfigStore reload", () => {
});
});
describe("plugin entries edited in config.json while the daemon runs", () => {
const other = { source: "directory", path: "/other", enabled: true } as const;
const local = { source: "directory", path: "/local", enabled: true } as const;
function disableOther(store: DaemonConfigStore) {
return store.patch((current) => ({
plugins: { ...current.plugins, other: { ...current.plugins.other!, enabled: false } },
}));
}
function removeOther(store: DaemonConfigStore) {
return store.patch((current) => {
const { other: _removed, ...rest } = current.plugins;
return { plugins: rest };
});
}
test("keeps a hand-added entry on disk when another plugin changes", async () => {
const { paseoHome, store, persisted } = createReloadableStore({
initialPersisted: { version: 1, plugins: { other } },
});
writeConfig(paseoHome, { ...persisted, plugins: { other, local } });
await disableOther(store);
expect(loadPersistedConfig(paseoHome).plugins).toEqual({
other: { ...other, enabled: false },
local,
});
expect(store.get().plugins).toEqual({ other: { ...other, enabled: false } });
});
test("does not write back an entry removed by hand when another plugin changes", async () => {
const { paseoHome, store, persisted } = createReloadableStore({
initialPersisted: { version: 1, plugins: { other, local } },
});
writeConfig(paseoHome, { ...persisted, plugins: { other } });
await disableOther(store);
expect(loadPersistedConfig(paseoHome).plugins).toEqual({
other: { ...other, enabled: false },
});
});
test("removing a plugin deletes only that entry from disk", async () => {
const { paseoHome, store, persisted } = createReloadableStore({
initialPersisted: { version: 1, plugins: { other } },
});
writeConfig(paseoHome, { ...persisted, plugins: { other, local } });
await removeOther(store);
expect(loadPersistedConfig(paseoHome).plugins).toEqual({ local });
expect(store.get().plugins).toEqual({});
});
});
test("serializes overlapping patches before committing their combined state", async () => {
const { paseoHome, store } = createReloadableStore();
const first = store.patch({ appendSystemPrompt: "first" });
@@ -1012,6 +1012,7 @@ export class DaemonConfigStore {
patch,
removeProviders,
persistRelayEnabled: this.relayEnabledMutable,
pluginsBeforePatch: this.current.plugins ?? {},
});
const nextPersisted = merge(persisted);
const knownNext = merge(this.lastKnownPersisted);
@@ -1025,8 +1026,9 @@ function mergeMutablePatchIntoPersistedConfig(params: {
patch: Omit<SupportedMutableConfigPatch, "removeProviders">;
removeProviders: readonly string[];
persistRelayEnabled: boolean;
pluginsBeforePatch: PluginSources;
}): PersistedConfig {
const { persisted, patch, removeProviders, persistRelayEnabled } = params;
const { persisted, patch, removeProviders, persistRelayEnabled, pluginsBeforePatch } = params;
const daemon = mergeMutableDaemonPatch(persisted.daemon, patch, persistRelayEnabled);
const agents = mergeMutableAgentPatch(persisted.agents, patch, removeProviders);
const withSpeech = patch.features
@@ -1035,12 +1037,40 @@ function mergeMutablePatchIntoPersistedConfig(params: {
return {
...withSpeech,
...(patch.pluginsEnabled !== undefined ? { pluginsEnabled: patch.pluginsEnabled } : {}),
...(patch.plugins !== undefined ? { plugins: patch.plugins } : {}),
...(patch.plugins !== undefined
? {
plugins: applyChangedPluginEntries({
persisted: persisted.plugins,
before: pluginsBeforePatch,
after: patch.plugins,
}),
}
: {}),
...(daemon ? { daemon } : { daemon: undefined }),
...(agents ? { agents } : { agents: undefined }),
} as PersistedConfig;
}
type PluginSources = NonNullable<MutableDaemonConfig["plugins"]>;
// The daemon never reloads plugin entries from config.json, so its copy can be stale. Writing only
// the entries this patch changed keeps entries other writers put on disk until the next restart.
function applyChangedPluginEntries(params: {
persisted: PersistedConfig["plugins"];
before: PluginSources;
after: PluginSources;
}): PluginSources {
const { persisted, before, after } = params;
const next: PluginSources = { ...persisted };
for (const [pluginId, source] of Object.entries(after)) {
if (!isEqualValue(before[pluginId], source)) next[pluginId] = source;
}
for (const pluginId of Object.keys(before)) {
if (!(pluginId in after)) delete next[pluginId];
}
return next;
}
function mergeMutableAgentPatch(
persistedAgents: PersistedConfig["agents"],
patch: Omit<SupportedMutableConfigPatch, "removeProviders">,