Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai 003a44be5e feat(agents): Send to Agent from the editor tab menu and editor tab drops on the composer
The editor tab context menu gets Send to Agent, which adds the tab's file as
an @ reference. Dragging a file tab onto the agent composer adds the same
reference; session and virtual tabs are not accepted.
2026-11-27 03:22:04 +08:00
4 змінених файлів з 69 додано та 5 видалено

No files matched your search

+21 -3
Переглянути файл
@@ -24,7 +24,9 @@ import { registerKeyClaim } from "@/platform/keymap";
import { isVirtualUri } from "@/platform/virtualDocs";
import { copySourceOf } from "@/platform/clipboardSource";
import {
EDITOR_TAB_MIME,
getAgentContextSources,
maybeEditorService,
notifications,
OWNS_FILE_DROP,
type AgentContextSource,
@@ -100,6 +102,18 @@ type Item =
const isSection = (item: Item) => item.kind === "section";
/** The file of an editor tab drag payload (`{paneId, tabId}`), null for virtual and non-file tabs. */
const tabFilePath = (payload: string): string | null => {
try {
const p = JSON.parse(payload) as { paneId?: unknown; tabId?: unknown };
if (typeof p.paneId !== "string" || typeof p.tabId !== "string") return null;
const input = maybeEditorService()?.tabInput?.(p.paneId, p.tabId);
return input?.kind === "file" && input.path && !isVirtualUri(input.path) ? input.path : null;
} catch {
return null;
}
};
const SECTION_TITLES: Record<Section, string> = {
command: "Commands",
skill: "Skills",
@@ -941,17 +955,21 @@ export function Composer(props: ComposerProps) {
};
}, [addPaths, addImages]);
// Files and folders dragged from the Project view: the same `@` references.
// Files and folders dragged from the Project view, and file tabs dragged from the editor:
// the same `@` references.
useEffect(() => {
const el = boxRef.current;
if (!el) return;
return registerDropTarget(el, {
accepts: (type) => type === FILES_DRAG,
accepts: (type, data) => type === FILES_DRAG || (type === EDITOR_TAB_MIME && !!tabFilePath(data.payload)),
over: () => setFileOver(true),
leave: () => setFileOver(false),
drop: (data) => {
setFileOver(false);
addPaths(data.payload.split("\n").filter(Boolean));
if (data.type === EDITOR_TAB_MIME) {
const path = tabFilePath(data.payload);
if (path) addPaths([path]);
} else addPaths(data.payload.split("\n").filter(Boolean));
},
});
}, [addPaths]);
+27
Переглянути файл
@@ -7,6 +7,7 @@ import userEvent from "@testing-library/user-event";
import { caretOf, setCaret, textOf, typeChars, typeIn } from "./composerTesting";
import chipStyles from "./ReferenceChip.module.css";
import { FILES_DRAG, dragSession } from "@/ui";
import { EDITOR_TAB_MIME, provideEditorService, type EditorService } from "@/workbench/contributions";
import { useProject } from "@/platform/project";
const findFiles = vi.fn();
@@ -123,6 +124,32 @@ describe("Composer dropped paths", () => {
expect(textOf(box)).toBe("@src/a.ts @src/dir/ ");
});
it("references the file of an editor tab dragged onto it and ignores other tabs", () => {
provideEditorService({
tabInput: (_pane: string, tab: string) =>
tab === "file"
? { kind: "file", key: "/p/src/a.ts", path: "/p/src/a.ts" }
: { kind: "agentSession", key: "agent:one", data: { task: "one" } },
} as unknown as EditorService);
const box = renderComposer();
const restore = document.elementFromPoint;
document.elementFromPoint = () => box;
try {
act(() => {
const other = dragSession({
type: EDITOR_TAB_MIME,
payload: JSON.stringify({ paneId: "p", tabId: "session" }),
});
expect(other.drop(0, 0)).toBe(false);
const file = dragSession({ type: EDITOR_TAB_MIME, payload: JSON.stringify({ paneId: "p", tabId: "file" }) });
expect(file.drop(0, 0)).toBe(true);
});
} finally {
document.elementFromPoint = restore;
}
expect(textOf(box)).toBe("@src/a.ts ");
});
it("deduplicates live references and allows a deleted reference to be dropped again", () => {
const box = renderComposer();
drop(box, "/p/src/a.ts\n/p/src/a.ts\n/p/src/dir/");
+3 -2
Переглянути файл
@@ -232,7 +232,7 @@ export function activate(): () => void {
registerStatusItem({ id: "agents.status", align: "right", priority: 3, title: "Agents", component: AgentsStatus }),
registerMenuGroup({
id: "agents.send",
menus: ["editor", "projectView"],
menus: ["editor", "editorTab", "projectView"],
order: 80,
items: (menu, { paths, dirs }) =>
paths.length && !paths.some(isVirtualUri) && agentsHere()
@@ -240,7 +240,8 @@ export function activate(): () => void {
{
kind: "action",
action: "agents.sendToAgent",
arg: menu === "projectView" ? paths.map((p, i) => (dirs?.[i] ? `${p}/` : p)) : undefined,
// The editor sends its selection; a tab or the Project view sends the files.
arg: menu === "editor" ? undefined : paths.map((p, i) => (dirs?.[i] ? `${p}/` : p)),
},
]
: [],
+18
Переглянути файл
@@ -3,6 +3,7 @@ import { act, fireEvent, render, screen } from "@testing-library/react";
import type { AgentEntry, AgentEvent, AgentTask } from "@/bindings";
import {
dropOnEditor,
menuGroupItems,
useContributions,
useEditorTabTitles,
type EditorInput,
@@ -595,3 +596,20 @@ describe("the diff of an agent change", () => {
expect(backend.openInput.mock.lastCall![0].data.chain).toBeUndefined();
});
});
describe("Send to Agent menus", () => {
it("sends the selection from the editor and the files from an editor tab or the Project view", () => {
const dispose = activate();
try {
const send = (menu: "editor" | "editorTab" | "projectView", dirs?: boolean[]) =>
menuGroupItems(menu, { paths: ["/p/a.ts", "/p/src"].slice(0, dirs ? 2 : 1), dirs }).find(
(i) => "action" in i && i.action === "agents.sendToAgent",
);
expect(send("editor")).toMatchObject({ arg: undefined });
expect(send("editorTab")).toMatchObject({ arg: ["/p/a.ts"] });
expect(send("projectView", [false, true])).toMatchObject({ arg: ["/p/a.ts", "/p/src/"] });
} finally {
dispose();
}
});
});