дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-06 18:17:15 +02:00
Adds Settings › Agents › Memory and a Session Memory picker (/memory, /memories, the composer + menu and the context meter link). They list each agent's own instruction files, path-scoped rules and auto-memory notes: AGENTS.md, CLAUDE.md and .claude/rules, .github/copilot-instructions.md and .github/instructions, .cursor/rules, GEMINI.md, and the Claude Code, Codex and Hermes auto-memory folders. Per-file modes (Auto / Always / Off) and the auto-memory policy (Inherit / Read & Write / Read Only / Off) are stored in settings.toml at user or workspace scope and never edit tracked files. Workspace entries load only in trusted projects. Each driver receives the policy natively: Claude Code through --settings and --add-dir, Codex through its memories config and /memories, GitHub Copilot through excludedTools and the system message, and Hermes through config.yaml. A file set to Always is staged into other agents' sessions. Auto-memory notes can be promoted into the workspace AGENTS.md, and an idle session restarts when a memory policy changes. Groups of the same agent are titled by scope, for example Claude Code (User) and Claude Code (Auto Memory). Closes #6810 Co-authored-by: dengliu <[email protected]>
269 рядки
9.3 KiB
TypeScript
269 рядки
9.3 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { fireEvent, render, screen, waitFor, within } from "@testing-library/react";
|
|
import type {
|
|
AgentMemoryCatalog,
|
|
AgentMemoryKind,
|
|
AgentMemoryMode,
|
|
AgentMemorySource,
|
|
AgentMemoryState,
|
|
AutoMemoryMode,
|
|
CreateAgentMemoryInput,
|
|
McpScope,
|
|
ProjectInfo,
|
|
PromoteAgentMemoryInput,
|
|
} from "@/bindings";
|
|
import { closeSettings } from "@/features/settings/model/staging";
|
|
import { useProject } from "@/platform/project";
|
|
import { MemoryPage, type MemoryBackend } from "./MemoryPage";
|
|
|
|
function makeEntry(
|
|
id: string,
|
|
title: string,
|
|
source: AgentMemorySource,
|
|
kind: AgentMemoryKind,
|
|
mode: AgentMemoryMode = "auto",
|
|
extra: Partial<AgentMemoryState["entry"]> = {},
|
|
origin: AgentMemoryState["origin"] = "none",
|
|
): AgentMemoryState {
|
|
return {
|
|
entry: {
|
|
id,
|
|
title,
|
|
description: `${title} guidance`,
|
|
kind,
|
|
source,
|
|
path: `/repo/${title}`,
|
|
approxTokens: 120,
|
|
lineCount: 40,
|
|
byteLen: 480,
|
|
writable: kind === "autoNote",
|
|
valid: true,
|
|
...extra,
|
|
},
|
|
mode,
|
|
origin,
|
|
};
|
|
}
|
|
|
|
const INITIAL_CATALOG: AgentMemoryCatalog = {
|
|
autoMemory: "inherit",
|
|
autoMemoryOrigin: "none",
|
|
providers: [
|
|
{
|
|
provider: "claude",
|
|
label: "Claude Code",
|
|
mode: "readWrite",
|
|
origin: "none",
|
|
noteCount: 2,
|
|
rolloutCount: 0,
|
|
approxTokens: 240,
|
|
storagePath: "/home/.claude/projects/repo/memory",
|
|
supportsAutoControl: true,
|
|
supportsFileExclusion: true,
|
|
supportsReset: true,
|
|
},
|
|
{
|
|
provider: "codex",
|
|
label: "Codex",
|
|
mode: "readOnly",
|
|
origin: "workspace",
|
|
noteCount: 1,
|
|
rolloutCount: 3,
|
|
approxTokens: 120,
|
|
storagePath: "/home/.codex/memories",
|
|
supportsAutoControl: true,
|
|
supportsFileExclusion: false,
|
|
supportsReset: true,
|
|
},
|
|
{
|
|
provider: "acp",
|
|
label: "Cursor / Gemini / ACP",
|
|
mode: "inherit",
|
|
origin: "none",
|
|
noteCount: 0,
|
|
rolloutCount: 0,
|
|
approxTokens: 0,
|
|
supportsAutoControl: false,
|
|
supportsFileExclusion: false,
|
|
supportsReset: false,
|
|
},
|
|
],
|
|
entries: [
|
|
makeEntry("workspace::AGENTS.md", "AGENTS.md", "workspace", "instruction", "auto", {
|
|
alsoIn: ["claudeWorkspace"],
|
|
}),
|
|
makeEntry("claudeAuto::feedback_tests.md", "feedback_tests.md", "claudeAuto", "autoNote", "auto", {
|
|
category: "feedback",
|
|
}),
|
|
makeEntry("claudeAuto::MEMORY.md", "MEMORY.md", "claudeAuto", "autoNote", "auto", {
|
|
valid: false,
|
|
warnings: ["`MEMORY.md` exceeds Claude Code's startup limit"],
|
|
}),
|
|
makeEntry("cursorWorkspace::react.mdc", "react.mdc", "cursorWorkspace", "rule", "auto", {
|
|
paths: ["src/**/*.tsx"],
|
|
}),
|
|
makeEntry(
|
|
"copilotUser::legacy.instructions.md",
|
|
"legacy.instructions.md",
|
|
"copilotUser",
|
|
"rule",
|
|
"off",
|
|
{},
|
|
"user",
|
|
),
|
|
],
|
|
};
|
|
|
|
function createBackend() {
|
|
let state: AgentMemoryCatalog = structuredClone(INITIAL_CATALOG);
|
|
const setModeCalls: Array<{ id: string; scope: McpScope; mode: AgentMemoryMode }> = [];
|
|
const setAutoCalls: Array<{ scope: McpScope; provider: string | null; mode: AutoMemoryMode }> = [];
|
|
const createCalls: CreateAgentMemoryInput[] = [];
|
|
const promoteCalls: PromoteAgentMemoryInput[] = [];
|
|
const resetCalls: string[] = [];
|
|
|
|
const backend: MemoryBackend = {
|
|
list: vi.fn(async () => state),
|
|
setMode: vi.fn(async (id, scope, mode) => {
|
|
setModeCalls.push({ id, scope, mode });
|
|
state = {
|
|
...state,
|
|
entries: state.entries.map((e) => (e.entry.id === id ? { ...e, mode } : e)),
|
|
};
|
|
return state;
|
|
}),
|
|
setAuto: vi.fn(async (scope, provider, mode) => {
|
|
setAutoCalls.push({ scope, provider, mode });
|
|
state = { ...state, autoMemory: mode };
|
|
return state;
|
|
}),
|
|
create: vi.fn(async (input) => {
|
|
createCalls.push(input);
|
|
state = {
|
|
...state,
|
|
entries: [...state.entries, makeEntry(`workspace::${input.name}.md`, `${input.name}.md`, "workspace", "rule")],
|
|
};
|
|
return state;
|
|
}),
|
|
promote: vi.fn(async (input) => {
|
|
promoteCalls.push(input);
|
|
state = {
|
|
...state,
|
|
entries: input.removeSource ? state.entries.filter((e) => e.entry.id !== input.sourceId) : state.entries,
|
|
};
|
|
return state;
|
|
}),
|
|
remove: vi.fn(async (id) => {
|
|
state = { ...state, entries: state.entries.filter((e) => e.entry.id !== id) };
|
|
return state;
|
|
}),
|
|
resetProvider: vi.fn(async (provider) => {
|
|
resetCalls.push(provider);
|
|
return state;
|
|
}),
|
|
};
|
|
|
|
return { backend, setModeCalls, setAutoCalls, createCalls, promoteCalls, resetCalls };
|
|
}
|
|
|
|
function pick(triggerLabel: string, option: string) {
|
|
fireEvent.click(screen.getByRole("button", { name: triggerLabel }));
|
|
fireEvent.click(within(screen.getByRole("listbox", { name: triggerLabel })).getByText(option));
|
|
}
|
|
|
|
afterEach(() => {
|
|
useProject.setState({ project: null, lightEdit: false });
|
|
closeSettings();
|
|
});
|
|
|
|
describe("MemoryPage", () => {
|
|
it("groups multi-agent instructions, rules, and auto-memories and filters by tabs and search", async () => {
|
|
const { backend } = createBackend();
|
|
render(<MemoryPage backend={backend} />);
|
|
|
|
await waitFor(() => expect(screen.getByText("AGENTS.md")).toBeInTheDocument());
|
|
expect(screen.getByRole("region", { name: "Workspace" })).toBeInTheDocument();
|
|
expect(screen.getByRole("region", { name: "Claude Code (Auto Memory)" })).toBeInTheDocument();
|
|
expect(screen.getByRole("region", { name: "Cursor" })).toBeInTheDocument();
|
|
expect(screen.getByRole("region", { name: "GitHub Copilot (User)" })).toBeInTheDocument();
|
|
expect(screen.getByText("Warning")).toBeInTheDocument();
|
|
|
|
fireEvent.click(screen.getByRole("tab", { name: /Auto Memory/ }));
|
|
expect(screen.getByText("feedback_tests.md")).toBeInTheDocument();
|
|
expect(screen.queryByText("AGENTS.md")).not.toBeInTheDocument();
|
|
|
|
fireEvent.click(screen.getByRole("tab", { name: /Instructions & Rules/ }));
|
|
expect(screen.getByText("AGENTS.md")).toBeInTheDocument();
|
|
expect(screen.getByText("react.mdc")).toBeInTheDocument();
|
|
expect(screen.queryByText("feedback_tests.md")).not.toBeInTheDocument();
|
|
|
|
fireEvent.change(screen.getByPlaceholderText("Type to search..."), { target: { value: "tsx" } });
|
|
expect(screen.getByText("react.mdc")).toBeInTheDocument();
|
|
expect(screen.queryByText("AGENTS.md")).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("updates auto-memory policy, provider reset, and entry modes", async () => {
|
|
useProject.setState({
|
|
project: { name: "openidea", root: "/repo", trusted: true, workspace: false } as unknown as ProjectInfo,
|
|
});
|
|
const spy = createBackend();
|
|
render(<MemoryPage backend={spy.backend} />);
|
|
|
|
await waitFor(() => expect(screen.getByText("AGENTS.md")).toBeInTheDocument());
|
|
|
|
pick("Auto-memory mode", "Read Only");
|
|
await waitFor(() => expect(spy.setAutoCalls).toEqual([{ scope: "workspace", provider: null, mode: "readOnly" }]));
|
|
|
|
const resetButtons = screen.getAllByRole("button", { name: "Reset" });
|
|
fireEvent.click(resetButtons[0]!);
|
|
await waitFor(() => expect(spy.resetCalls).toEqual(["claude"]));
|
|
|
|
pick("Mode for AGENTS.md", "Off");
|
|
await waitFor(() => expect(spy.setModeCalls).toEqual([{ id: "workspace::AGENTS.md", scope: "user", mode: "off" }]));
|
|
});
|
|
|
|
it("creates new rules and promotes auto-memory notes into AGENTS.md", async () => {
|
|
useProject.setState({
|
|
project: { name: "openidea", root: "/repo", trusted: true, workspace: false } as unknown as ProjectInfo,
|
|
});
|
|
const spy = createBackend();
|
|
render(<MemoryPage backend={spy.backend} />);
|
|
|
|
await waitFor(() => expect(screen.getByText("feedback_tests.md")).toBeInTheDocument());
|
|
|
|
// 1. Add Memory dialog
|
|
fireEvent.click(screen.getByRole("button", { name: "Add Memory…" }));
|
|
pick("Format", "Claude Rule (.claude/rules)");
|
|
fireEvent.change(screen.getByRole("textbox", { name: "Name" }), { target: { value: "ipc-rules" } });
|
|
fireEvent.change(screen.getByRole("textbox", { name: "Paths" }), { target: { value: "crates/**/*.rs" } });
|
|
fireEvent.change(screen.getByRole("textbox", { name: "Content" }), { target: { value: "Keep disk I/O async." } });
|
|
fireEvent.click(screen.getByRole("button", { name: "Create" }));
|
|
|
|
await waitFor(() => expect(spy.createCalls).toHaveLength(1));
|
|
expect(spy.createCalls[0]).toMatchObject({
|
|
scope: "workspace",
|
|
target: "claudeRule",
|
|
name: "ipc-rules",
|
|
paths: ["crates/**/*.rs"],
|
|
content: "Keep disk I/O async.",
|
|
});
|
|
expect(await screen.findByText("ipc-rules.md")).toBeInTheDocument();
|
|
|
|
// 2. Expand auto-memory note and promote to AGENTS.md
|
|
fireEvent.click(screen.getByText("feedback_tests.md"));
|
|
fireEvent.click(await screen.findByRole("button", { name: "Promote to AGENTS.md…" }));
|
|
fireEvent.change(screen.getByRole("textbox", { name: "Section heading (optional)" }), {
|
|
target: { value: "Testing" },
|
|
});
|
|
fireEvent.click(screen.getByRole("button", { name: "Promote" }));
|
|
|
|
await waitFor(() => expect(spy.promoteCalls).toHaveLength(1));
|
|
expect(spy.promoteCalls[0]).toMatchObject({
|
|
sourceId: "claudeAuto::feedback_tests.md",
|
|
heading: "Testing",
|
|
removeSource: true,
|
|
});
|
|
await waitFor(() => expect(screen.queryByText("feedback_tests.md")).not.toBeInTheDocument());
|
|
});
|
|
});
|