mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
The IDE MCP server took a new port and token in every run, so configured HTTP clients and port forwards broke at each restart; every MCP request brought the window to the front; and an agent's edits were announced as refactorings. - Settings › Agents › IDE MCP Server: Use a fixed port (on by default, 26371) with a fallback to a free port when it is in use or reserved, reported in Status; Keep the token (off by default) stores the bearer token in the app data, readable by this user only, with Regenerate Token. Changing either restarts the server. Access control is otherwise unchanged (127.0.0.1, bearer token, origin and host checks). - Only confirmations, which wait for the user, raise the window. - Agent edits stay undoable (Local History point for multi-file edits) but are not announced as refactorings. Co-authored-by: guoyucode <29471644+guoyucode@users.noreply.github.com>
60 lines
2.2 KiB
TypeScript
60 lines
2.2 KiB
TypeScript
import { onWorkspaceEditHistory, whenAllSynced, workspaceEditHistory } from "@/editor/api";
|
|
import { onIdeEvent } from "@/platform/ipc";
|
|
import { useProject } from "@/platform/project";
|
|
import { notifications } from "@/workbench/contributions";
|
|
|
|
/**
|
|
* The notification follows the same history state as editor Undo/Redo. An agent's edits (the MCP
|
|
* server's tools) stay undoable from the editor but are not announced: an agent makes many.
|
|
*/
|
|
export function installWorkspaceEditUndo(): () => void {
|
|
let current: { id: number; project: ReturnType<typeof useProject.getState>["project"]; undone: boolean } | null =
|
|
null;
|
|
const show = () => {
|
|
if (!current) return;
|
|
const entry = current;
|
|
const { id, project, undone } = entry;
|
|
notifications().notify({
|
|
level: "info",
|
|
title: undone ? "Refactoring undone" : "Refactoring applied",
|
|
key: "refactor.workspaceEdit",
|
|
actions: [
|
|
{
|
|
label: undone ? "Redo" : "Undo",
|
|
run: async () => {
|
|
try {
|
|
await whenAllSynced();
|
|
if (project !== useProject.getState().project)
|
|
throw new Error("The project for this refactoring is no longer open");
|
|
if (current !== entry || current.undone !== undone) return;
|
|
if (undone) await workspaceEditHistory(id, true);
|
|
else await workspaceEditHistory(id);
|
|
} catch (error) {
|
|
notifications().notify({
|
|
level: "error",
|
|
title: "Cannot undo refactoring",
|
|
body: error instanceof Error ? error.message : String(error),
|
|
});
|
|
}
|
|
},
|
|
},
|
|
],
|
|
});
|
|
};
|
|
const stopApplied = onIdeEvent("workspaceEditApplied", ({ id, byAgent }) => {
|
|
if (byAgent) return;
|
|
current = { id, project: useProject.getState().project, undone: false };
|
|
show();
|
|
});
|
|
const stopHistory = onWorkspaceEditHistory(({ id, undone }) => {
|
|
if (!current || current.id !== id || current.project !== useProject.getState().project) return;
|
|
current = { ...current, undone };
|
|
show();
|
|
});
|
|
return () => {
|
|
stopApplied();
|
|
stopHistory();
|
|
current = null;
|
|
};
|
|
}
|