mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 09:01:00 -10:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
25f29075a2 |
No files matched your search
@@ -64,7 +64,7 @@ export function McpPicker({
|
||||
testData,
|
||||
}: McpPickerProps) {
|
||||
const tx = useTx();
|
||||
useMcpCatalogSync();
|
||||
useMcpCatalogSync(!hideTrigger);
|
||||
const catalogServers = useMcpCatalog((s) => s.servers);
|
||||
const catalogSources = useMcpCatalog((s) => s.sources);
|
||||
const projectIdeMcp = useProject((s) => s.settings?.mcpServer?.enabled ?? false);
|
||||
|
||||
@@ -176,7 +176,7 @@ export function SessionPicker({
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className={styles.list}>{children(query, controls)}</div>
|
||||
<div className={styles.list}>{open && children(query, controls)}</div>
|
||||
|
||||
<div className={styles.footer}>
|
||||
<span>
|
||||
|
||||
@@ -67,7 +67,7 @@ export function SkillsPicker({
|
||||
testData,
|
||||
}: SkillsPickerProps) {
|
||||
const tx = useTx();
|
||||
useSkillsCatalogSync(backend);
|
||||
useSkillsCatalogSync(!hideTrigger, backend);
|
||||
const catalogSkills = useSkillsCatalog((s) => s.skills);
|
||||
const skills = testData?.skills ?? catalogSkills;
|
||||
const resolved = useMemo(() => resolveSessionSkills(skills, overrides ?? {}), [skills, overrides]);
|
||||
|
||||
@@ -3,10 +3,13 @@ import { sendKeyAction } from "./Composer";
|
||||
import { act, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { EditorView } from "@codemirror/view";
|
||||
import type { AgentCommand, AgentProvider } from "@/bindings";
|
||||
import type { AgentCommand, AgentProvider, AgentSkillState } from "@/bindings";
|
||||
|
||||
const agentCommands = vi.fn();
|
||||
const agentCreate = vi.fn();
|
||||
const agentMcpList = vi.fn();
|
||||
const agentMcpDiscoverSources = vi.fn();
|
||||
const agentSkillsList = vi.fn();
|
||||
const vcsBranches = vi.fn();
|
||||
const vcsBranchInfo = vi.fn();
|
||||
const clipboardImage = vi.fn();
|
||||
@@ -20,6 +23,9 @@ vi.mock("@/platform/ipc", async (importOriginal) => {
|
||||
...real.commands,
|
||||
agentCommands: (provider: string, task: string | null) => agentCommands(provider, task),
|
||||
agentCreate: (request: unknown) => agentCreate(request),
|
||||
agentMcpList: () => agentMcpList(),
|
||||
agentMcpDiscoverSources: () => agentMcpDiscoverSources(),
|
||||
agentSkillsList: () => agentSkillsList(),
|
||||
agentRefreshModels: async (provider: string) => ({
|
||||
status: "ok",
|
||||
data: {
|
||||
@@ -108,6 +114,9 @@ beforeEach(() => {
|
||||
}),
|
||||
);
|
||||
agentCommands.mockReset();
|
||||
for (const request of [agentMcpList, agentMcpDiscoverSources, agentSkillsList]) {
|
||||
request.mockReset().mockResolvedValue({ status: "ok", data: [] });
|
||||
}
|
||||
clipboardImage.mockReset().mockResolvedValue({
|
||||
status: "ok",
|
||||
data: "data:image/png;base64,iVBORw0KGgo=",
|
||||
@@ -174,6 +183,8 @@ describe("New Task composer commands", () => {
|
||||
it("opens the per-session MCP picker when /mcp is completed in the composer", async () => {
|
||||
agentCommands.mockResolvedValue({ status: "ok", data: [] });
|
||||
render(<HomeEditor />);
|
||||
expect(agentMcpList).not.toHaveBeenCalled();
|
||||
expect(agentMcpDiscoverSources).not.toHaveBeenCalled();
|
||||
const box = screen.getByRole("textbox");
|
||||
typeIn(box, "/mc");
|
||||
const list = await screen.findByRole("listbox", { name: "Commands" });
|
||||
@@ -181,11 +192,14 @@ describe("New Task composer commands", () => {
|
||||
fireEvent.keyDown(box, { key: "Enter" });
|
||||
expect(textOf(box)).toBe("");
|
||||
expect(await screen.findByText("Session MCP Servers")).toBeInTheDocument();
|
||||
expect(agentMcpList).toHaveBeenCalledOnce();
|
||||
expect(agentMcpDiscoverSources).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it("opens the per-session skills picker when /skills is completed in the composer", async () => {
|
||||
agentCommands.mockResolvedValue({ status: "ok", data: [] });
|
||||
render(<HomeEditor />);
|
||||
expect(agentSkillsList).not.toHaveBeenCalled();
|
||||
const box = screen.getByRole("textbox");
|
||||
typeIn(box, "/sk");
|
||||
const list = await screen.findByRole("listbox", { name: "Commands" });
|
||||
@@ -193,6 +207,7 @@ describe("New Task composer commands", () => {
|
||||
fireEvent.keyDown(box, { key: "Enter" });
|
||||
expect(textOf(box)).toBe("");
|
||||
expect(await screen.findByText("Session Skills")).toBeInTheDocument();
|
||||
expect(agentSkillsList).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it("names the icon-only Start action and disables it while starting", async () => {
|
||||
@@ -331,34 +346,32 @@ describe("New Task composer commands", () => {
|
||||
expect(agentCreate.mock.calls[0]![0]).toMatchObject({ idle: true, prompt: { text: "!gi" } });
|
||||
});
|
||||
|
||||
it("reflects per-session draft skillOverrides immediately in / completion", async () => {
|
||||
it.each(["saved", "edited"])("reflects %s draft skill overrides in / completion", async (source) => {
|
||||
agentCommands.mockResolvedValue({
|
||||
status: "ok",
|
||||
data: [command("triage", "Triage issues", "skill"), command("compact", "Compact")],
|
||||
});
|
||||
useSkillsCatalog.setState({
|
||||
loaded: true,
|
||||
skills: [
|
||||
{
|
||||
skill: {
|
||||
name: "impeccable",
|
||||
description: "Muted globally, enabled for this draft",
|
||||
path: "/skills/impeccable",
|
||||
source: "user",
|
||||
valid: true,
|
||||
warnings: [],
|
||||
},
|
||||
mode: "off",
|
||||
origin: "user",
|
||||
const skills: AgentSkillState[] = [
|
||||
{
|
||||
skill: {
|
||||
name: "impeccable",
|
||||
description: "Muted globally, enabled for this draft",
|
||||
path: "/skills/impeccable",
|
||||
source: "user",
|
||||
valid: true,
|
||||
warnings: [],
|
||||
},
|
||||
],
|
||||
});
|
||||
mode: "off",
|
||||
origin: "user",
|
||||
},
|
||||
];
|
||||
const overrides = { triage: "off", impeccable: "auto" } as const;
|
||||
agentSkillsList.mockResolvedValue({ status: "ok", data: skills });
|
||||
useSkillsCatalog.setState({ loaded: source === "edited", skills: source === "edited" ? skills : [] });
|
||||
if (source === "saved") setDraftSkillOverrides(overrides);
|
||||
render(<HomeEditor />);
|
||||
await waitFor(() => expect(agentCommands).toHaveBeenCalled());
|
||||
|
||||
act(() => {
|
||||
setDraftSkillOverrides({ triage: "off", impeccable: "auto" });
|
||||
});
|
||||
if (source === "edited") act(() => setDraftSkillOverrides(overrides));
|
||||
|
||||
const box = screen.getByRole("textbox");
|
||||
typeIn(box, "/");
|
||||
|
||||
@@ -239,13 +239,15 @@ export async function refreshMcpCatalog(): Promise<void> {
|
||||
}));
|
||||
}
|
||||
|
||||
export function useMcpCatalogSync(): void {
|
||||
export function useMcpCatalogSync(eager: boolean): void {
|
||||
const root = useProject((s) => s.project?.root);
|
||||
useEffect(() => {
|
||||
if (!isTauri()) return;
|
||||
void refreshMcpCatalog();
|
||||
const onFocus = () => void refreshMcpCatalog();
|
||||
window.addEventListener("focus", onFocus);
|
||||
if (eager) {
|
||||
onFocus();
|
||||
window.addEventListener("focus", onFocus);
|
||||
}
|
||||
if (!listenerAttached && typeof onIdeEvent === "function") {
|
||||
listenerAttached = true;
|
||||
onIdeEvent("settingsChanged", (e) => {
|
||||
@@ -255,5 +257,5 @@ export function useMcpCatalogSync(): void {
|
||||
});
|
||||
}
|
||||
return () => window.removeEventListener("focus", onFocus);
|
||||
}, [root]);
|
||||
}, [eager, root]);
|
||||
}
|
||||
@@ -551,6 +551,41 @@ export function Stream({
|
||||
),
|
||||
[task, lastIndex, busy, thinking, onDiagramDrawn, renderRow],
|
||||
);
|
||||
const agentName = providerName(task.provider);
|
||||
// Switching tabs changes visibility without changing the conversation rows.
|
||||
const renderedRows = useMemo(
|
||||
() =>
|
||||
rows.map((row) => {
|
||||
const images = toolImages(row);
|
||||
return (
|
||||
<div
|
||||
key={row.index}
|
||||
className={styles.conversationRow}
|
||||
data-message={
|
||||
(row.kind === "entry" && (row.entry.type === "user" || row.entry.type === "agent")) || undefined
|
||||
}
|
||||
data-process={row.kind !== "entry" || row.entry.type !== "user" || undefined}
|
||||
data-author={authorHeaders.has(row.index) || undefined}
|
||||
>
|
||||
{authorHeaders.has(row.index) && (
|
||||
<div className={styles.agentAuthor}>
|
||||
<div className={styles.role}>
|
||||
<Icon name={providerIcon(task.provider)} size={13} />
|
||||
<span>{agentName}</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{renderConversationRow(row)}
|
||||
{images.length > 0 && (
|
||||
<div className={styles.toolImages}>
|
||||
<ImageStrip images={images} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}),
|
||||
[rows, authorHeaders, task.provider, agentName, renderConversationRow],
|
||||
);
|
||||
return (
|
||||
<OpenFolds.Provider value={openFolds}>
|
||||
<KeepFoldHeader.Provider value={keepFoldHeader}>
|
||||
@@ -654,37 +689,7 @@ export function Stream({
|
||||
) : entries.length === 0 && !busy && !loadError ? (
|
||||
<EmptyState title="No conversation history" />
|
||||
) : (
|
||||
<RowRenderer.Provider value={renderConversationRow}>
|
||||
{rows.map((row) => {
|
||||
const images = toolImages(row);
|
||||
return (
|
||||
<div
|
||||
key={row.index}
|
||||
className={styles.conversationRow}
|
||||
data-message={
|
||||
(row.kind === "entry" && (row.entry.type === "user" || row.entry.type === "agent")) || undefined
|
||||
}
|
||||
data-process={row.kind !== "entry" || row.entry.type !== "user" || undefined}
|
||||
data-author={authorHeaders.has(row.index) || undefined}
|
||||
>
|
||||
{authorHeaders.has(row.index) && (
|
||||
<div className={styles.agentAuthor}>
|
||||
<div className={styles.role}>
|
||||
<Icon name={providerIcon(task.provider)} size={13} />
|
||||
<span>{providerName(task.provider)}</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{renderConversationRow(row)}
|
||||
{images.length > 0 && (
|
||||
<div className={styles.toolImages}>
|
||||
<ImageStrip images={images} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</RowRenderer.Provider>
|
||||
<RowRenderer.Provider value={renderConversationRow}>{renderedRows}</RowRenderer.Provider>
|
||||
)}
|
||||
<WorkingRow task={task} entries={entries} subagent={subagent} />
|
||||
</div>
|
||||
|
||||
@@ -153,13 +153,15 @@ export async function refreshSkillsCatalog(backend: SkillsBackend = defaultSkill
|
||||
if (skills) useSkillsCatalog.setState({ skills, loaded: true });
|
||||
}
|
||||
|
||||
export function useSkillsCatalogSync(backend: SkillsBackend = defaultSkillsBackend): void {
|
||||
export function useSkillsCatalogSync(eager: boolean, backend: SkillsBackend = defaultSkillsBackend): void {
|
||||
const root = useProject((s) => s.project?.root);
|
||||
useEffect(() => {
|
||||
if (!isTauri()) return;
|
||||
void refreshSkillsCatalog(backend);
|
||||
const onFocus = () => void refreshSkillsCatalog(backend);
|
||||
window.addEventListener("focus", onFocus);
|
||||
if (eager) {
|
||||
onFocus();
|
||||
window.addEventListener("focus", onFocus);
|
||||
}
|
||||
if (!listenerAttached && typeof onIdeEvent === "function") {
|
||||
listenerAttached = true;
|
||||
onIdeEvent("settingsChanged", (e) => {
|
||||
@@ -169,5 +171,5 @@ export function useSkillsCatalogSync(backend: SkillsBackend = defaultSkillsBacke
|
||||
});
|
||||
}
|
||||
return () => window.removeEventListener("focus", onFocus);
|
||||
}, [root, backend]);
|
||||
}, [eager, root, backend]);
|
||||
}
|
||||
@@ -27,7 +27,7 @@ import { auxiliaryWindow, windowLabel } from "@/platform/auxWindow";
|
||||
import { routeToWindow, taskWindowDraft, taskWindowFocused, updateTaskWindowDraft } from "./taskWindowRouting";
|
||||
import { clearAgentTaskFontZoom, resetAllAgentFontZoom } from "./fontZoom";
|
||||
import { clearDismissedAssets } from "./sessionAssetsModel";
|
||||
import { useSkillsCatalog } from "./skillsModel";
|
||||
import { useSkillsCatalog, useSkillsCatalogSync } from "./skillsModel";
|
||||
import { basename, useProject } from "@/platform/project";
|
||||
import { projectLocation } from "@/platform/remote";
|
||||
import { defaultTaskProject } from "./project";
|
||||
@@ -1067,6 +1067,8 @@ export function useAgentCommands(
|
||||
offered: readonly AgentCommand[],
|
||||
): readonly AgentCommand[] {
|
||||
const skillOverrides = useAgents((s) => (task ? s.tasks.get(task)?.skillOverrides : s.draft.skillOverrides));
|
||||
// The server's draft commands omit skills that only this draft has enabled.
|
||||
useSkillsCatalogSync(task === null && Object.values(skillOverrides ?? {}).some((mode) => mode !== "off"));
|
||||
const catalogSkills = useSkillsCatalog((s) => s.skills);
|
||||
const [found, setFound] = useState<{
|
||||
for: unknown[];
|
||||
|
||||
Reference in new issue
Block a user