Merge remote-tracking branch 'origin/main' into HEAD

# Conflicts:
#	src/features/agents/session/Stream.tsx
Цей коміт міститься в:
l0ng-ai committed 2026-11-24 15:37:52 +08:00
коміт e1df881099
13 files changed
+113 -71

No files matched your search

+8
Переглянути файл
@@ -432,6 +432,14 @@ async fn patches_read_and_write_the_requested_repository() {
})
.collect::<String>();
let root = Some(roots[0].clone());
// Automatic mappings wait for indexing; the new folders and exclude rule may start a rescan.
tokio::time::sleep(Duration::from_millis(200)).await;
for _ in 0..500 {
if !project.index.status().indexing {
break;
}
tokio::time::sleep(Duration::from_millis(10)).await;
}
let preview = vcs::vcs_patch_preview(&host, "main", root.clone(), patch.clone(), None, None).await.unwrap();
assert!(preview.files.iter().all(|file| file.applies && !file.missing_base));
assert_eq!(preview.automatic_mappings.len(), 1);
+3
Переглянути файл
@@ -1605,7 +1605,10 @@ mod pipenv_tests {
#[test]
fn environments_are_named_as_pipenv_names_them() {
// `sanitize(folder)[:42] + "-" + urlsafe_b64encode(sha256(Pipfile path).digest()[:6])`, from pipenv.
#[cfg(unix)]
assert_eq!(pipenv_env_name(Path::new("/home/me/My Shop (2)")), "My_Shop__2_-6rNTtAUD");
#[cfg(windows)]
assert_eq!(pipenv_env_name(Path::new(r"C:\Users\me\My Shop (2)")), "My_Shop__2_-ED1rXUDC");
}
#[test]
+1 -1
Переглянути файл
@@ -597,7 +597,7 @@ fn saved_python_configs_keep_their_explicit_interpreter() {
config.cwd = Some(Path::new("member").into());
apply_to_run_configs(std::slice::from_mut(&mut config), root, &settings);
assert_eq!(config.command, command);
assert_eq!(config.env["VIRTUAL_ENV"], root.join("member/.override").to_string_lossy());
assert_eq!(config.env["VIRTUAL_ENV"], root.join("member").join(".override").to_string_lossy());
let saved = without_derived(&config, root, &settings);
assert_eq!(saved.command, command);
}
+10 -4
Переглянути файл
@@ -228,6 +228,14 @@ mod tests {
(coalescing_sink(Arc::new(move |event| saved.lock().push(event)), tokio::runtime::Handle::current()), events)
}
/// Waits for the coalescing window to flush `n` events (a fixed sleep is too short on slow CI timers).
async fn wait_for_events(events: &Mutex<Vec<IdeEvent>>, n: usize) {
let deadline = std::time::Instant::now() + Duration::from_secs(5);
while events.lock().len() < n && std::time::Instant::now() < deadline {
tokio::time::sleep(Duration::from_millis(5)).await;
}
}
fn diagnostics(path: &str, source: &str, message: &str) -> IdeEvent {
IdeEvent::Diagnostics {
path: IpcPath::from(path),
@@ -316,9 +324,7 @@ mod tests {
sink.emit(diagnostics("/p/b.rs", "rust-analyzer", "other"));
assert!(events.lock().is_empty());
tokio::task::yield_now().await;
tokio::time::sleep(Duration::from_millis(30)).await;
tokio::task::yield_now().await;
wait_for_events(&events, 3).await;
{
let saved_events = events.lock();
@@ -381,7 +387,7 @@ mod tests {
}
assert_eq!(events.lock().len(), MAX_PENDING_DIAGNOSTICS);
tokio::time::sleep(Duration::from_millis(30)).await;
wait_for_events(&events, MAX_PENDING_DIAGNOSTICS + 1).await;
assert_eq!(events.lock().len(), MAX_PENDING_DIAGNOSTICS + 1);
}
+1 -1
Переглянути файл
@@ -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);
+2
Переглянути файл
@@ -412,6 +412,8 @@
.reply {
position: relative;
/* Keep WebKit's selection gap fill from extending across reply boundaries. */
transform: translateX(0);
}
.replyFooter {
position: absolute;
+1 -1
Переглянути файл
@@ -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>
+1 -1
Переглянути файл
@@ -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]);
+35 -22
Переглянути файл
@@ -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, "/");
+6 -4
Переглянути файл
@@ -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]);
}
+36 -32
Переглянути файл
@@ -575,6 +575,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}>
@@ -675,38 +710,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>
+6 -4
Переглянути файл
@@ -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]);
}
+3 -1
Переглянути файл
@@ -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[];