diff --git a/CHANGELOG.md b/CHANGELOG.md index f509d63..35b8b28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ submodule. ## [Unreleased] ### Added +- **Browse and pull Ollama models in Desktop.** Open the native model browser with `/ollama-pull` or Browse models in the model dropdown. Search the shared CLI catalog, sort models, filter cloud entries, inspect tags and sizes, and see which exact variants are already pulled on your agent’s server. Selecting a family chooses its default tag automatically; cloud-only browsing shows only cloud variants and counts only their installed tags. Sorting or changing the cloud filter clears stale details. Pull with streaming progress and cancellation, enter a tag manually when the catalog is unavailable, and explicitly choose Use in this agent after availability is confirmed. The separate window follows the app theme and uses its MandoCode icon. - **Attach images to Desktop prompts.** Paste a screenshot or copied image file, use Attach image, or drop image files into the chat. Select multiple files, preview the batch, and remove images individually before sending. Supports up to four PNG, JPEG, GIF, or WebP images per message, each limited to 4 MiB and 16 million pixels. Check vision support again at send time, retain refused drafts, and queue image bytes only after this agent claims the user turn. Image-only messages receive an explicit description prompt. - **Organize agents into workspaces.** A new upper tab row groups agents into named workspaces. Each workspace remembers its selected agent and split layout; switching workspaces keeps background agents running. Existing tabs move into **Main**, and all workspaces reopen on the next launch. Working and approval badges help you find agents that need attention, including in other workspaces. - **Close workspaces directly from their tabs.** The **×** appears on the selected workspace and when another workspace is hovered or focused, without shifting tab labels. Right-click still offers Rename and Close. Both closing actions keep at least one workspace open, block closure while agents or commands are running or approvals are waiting, and save conversations to History before closing. @@ -19,7 +20,7 @@ submodule. - **Two levels of tabs with matching scroll spacing.** Workspace tabs sit above agent tabs. Split and New agent stay beside the agents they control in the selected workspace. Both rows reserve space beneath their tabs for horizontal scrollbars, and agent mentions show the workspace name alongside the project folder. - **Separate Files and Agents mentions.** Typing `@` opens Files first; press Tab to switch to Agents and back. Gold headers explain the switch. Agent rows show name and project folder, files retain explicit paths when names collide, and quoted paths/names support spaces. - **Responsive file tagging on large projects.** Reuse the CLI's asynchronous file index, early root listing, shared scan/cache, query debounce, and filesystem watcher. Closing the picker keeps indexing in progress. Build result rows off the UI thread, replace the list in one batch, preserve selection across updates, ignore stale lookups, and show loading/indexing feedback. End drill-down when a selected folder is empty, and dispose file watchers when the tab closes. -- **Update the bundled engine to the MandoCode 0.16 generation.** Pin the shared engine to v0.16.1 (`277cd36`), including the RazorConsole 0.6 migration, maintenance improvements, and merged Windows/Linux CI fixes. The engine now separates commands, requests, lifecycle, model inspection, and history handling into focused code. Desktop keeps its existing WinUI conversation interface; terminal features are described in `MandoCode/docs/CHANGELOG.md`. +- **Update the bundled engine to the MandoCode 0.16 generation.** Pin the shared engine to the published CLI v0.16.2 release (`1087b8a`), including the RazorConsole 0.6 migration, maintenance improvements, Windows/Linux CI fixes, and the CLI startup/focus rendering fix. The engine now separates commands, requests, lifecycle, model inspection, and history handling into focused code. Desktop keeps its existing WinUI conversation interface; terminal features are described in `MandoCode/docs/CHANGELOG.md`. - **Plan mode starts only through /plan.** Ordinary requests run directly, including multi-step tasks and prose outlines. Desktop no longer automatically proposes structured plans based on task complexity or model tool calls. Existing plan review, editing, execution, and recovery remain available. Settings now explain the explicit command instead of offering automatic planning. ### Fixed diff --git a/MandoCode b/MandoCode index 277cd36..1087b8a 160000 --- a/MandoCode +++ b/MandoCode @@ -1 +1 @@ -Subproject commit 277cd36e3a10f259ac78e1c0c0a7f09e65523d06 +Subproject commit 1087b8adbed8658c17028e4c2a1d6ed592ae0daf diff --git a/README.md b/README.md index d6c72ef..296a09d 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,8 @@ Two problems, one app: ## Features +- **Ollama model browser**: type `/ollama-pull` or choose **Browse models…** from the model dropdown. Search the library, sort by Newest, Popular, or Name, inspect tags and sizes, and see which exact variants are already on your agent’s Ollama server. **Cloud only** shows cloud variants, including families with more than one cloud option. Pull with progress and cancellation, then explicitly choose **Use in this agent**. Downloads do not switch models automatically. + - **Image attachments for vision models** — paste a screenshot or copied image file, click **Attach image**, or drop image files into chat. Select multiple files or paste screenshots one at a time. Preview and remove individual images before sending. Supports up to four PNG, JPEG, GIF, or WebP images per message, each up to 4 MiB and 16 million pixels. The selected model must have confirmed vision support. Images are supplied for the submitted turn; attach again when another turn needs the original pixels. - **Workspace tabs** — group agents into named workspaces in the upper tab row. Each workspace remembers its selected agent and split layout; switching keeps background agents running. Use **+ Workspace** to create one. Close with the **×** on the selected tab, or hover/focus another workspace to reveal its close button. Right-click also offers Rename and Close. **Split** and **New agent** apply to the selected workspace. Workspaces restore on launch, and existing installations migrate their tabs into **Main**. Alt+Shift+N creates a workspace, Alt+Shift+Left/Right switches, and Alt+Shift+W closes an idle workspace. diff --git a/src/MandoCode.Desktop.Tests/MandoCode.Desktop.Tests.csproj b/src/MandoCode.Desktop.Tests/MandoCode.Desktop.Tests.csproj index d0a7f8a..e3bf83e 100644 --- a/src/MandoCode.Desktop.Tests/MandoCode.Desktop.Tests.csproj +++ b/src/MandoCode.Desktop.Tests/MandoCode.Desktop.Tests.csproj @@ -8,6 +8,8 @@ + + diff --git a/src/MandoCode.Desktop.Tests/OllamaBrowserTests.cs b/src/MandoCode.Desktop.Tests/OllamaBrowserTests.cs new file mode 100644 index 0000000..26dc547 --- /dev/null +++ b/src/MandoCode.Desktop.Tests/OllamaBrowserTests.cs @@ -0,0 +1,240 @@ +using MandoCode.Desktop.Services; +using MandoCode.Desktop.ViewModels; +using MandoCode.Services; +using Xunit; +using System.Net; +using System.Text; + +namespace MandoCode.Desktop.Tests; + +public class OllamaBrowserTests +{ + [Fact] public void InventoryUsesExactTagsAndPreservesNamespaces() + { + var inventory = new OllamaModelInventory(new[] { "library/qwen3", "qwen3:8b", "team/qwen3:4b", "registry:5000/qwen3:8b" }); + Assert.True(inventory.Contains("qwen3:latest")); + Assert.False(inventory.Contains("qwen3:4b")); + Assert.False(inventory.Contains("team/qwen3:8b")); + Assert.True(inventory.Contains("registry:5000/qwen3:8b")); + Assert.Equal(2, inventory.CountFamily("qwen3")); + } + [Fact] public async Task InventoryFailureRemainsUnknownWhileCatalogWorks() + { + var fake = new Fake { Inventory = _ => throw new IOException("offline") }; + using var vm = new OllamaBrowserViewModel(fake); + await vm.RefreshAsync(); + await vm.SelectModelAsync("qwen3"); + Assert.Single(vm.Models); + Assert.False(vm.InventoryKnown); + Assert.All(vm.Tags, t => Assert.Null(t.Installed)); + Assert.Contains("offline", vm.InventoryError); + } + [Fact] public async Task BadgeMatchesOnlyInstalledVariant() + { + using var vm = new OllamaBrowserViewModel(new Fake()); + await vm.RefreshAsync(); await vm.SelectModelAsync("qwen3"); + Assert.True(vm.Tags[0].Installed); + Assert.False(vm.Tags[1].Installed); + } + [Fact] public async Task LateTagsDoNotReplaceNewSelection() + { + var old = new TaskCompletionSource>(); + var fake = new Fake { + Catalog = new[] { new OllamaModelLibrary.Model("old", "", ""), new OllamaModelLibrary.Model("new", "", "") }, + Tags = (name, _) => name == "old" ? old.Task : Task.FromResult>(new[] { new OllamaModelLibrary.Tag("new:latest", "") }) + }; + using var vm = new OllamaBrowserViewModel(fake); + await vm.RefreshAsync(); var stale = vm.SelectModelAsync("old"); await vm.SelectModelAsync("new"); + old.SetResult(new[] { new OllamaModelLibrary.Tag("old:latest", "") }); await stale; + Assert.Equal("new:latest", Assert.Single(vm.Tags).Name); + } + [Fact] public async Task PullRefreshesInventoryWithoutSelectingModel() + { + var installed = new List(); + var fake = new Fake { + Inventory = _ => Task.FromResult>(installed.ToArray()), + Pull = (name, progress, _) => { progress(new("pulling", 5, 10)); installed.Add(name); return Task.CompletedTask; } + }; + using var vm = new OllamaBrowserViewModel(fake); + await vm.PullAsync("qwen3:4b"); + Assert.True(vm.IsInstalled("qwen3:4b")); + Assert.Null(vm.SelectedModel); Assert.False(vm.Downloading); + } + [Fact] public async Task FailedPullDoesNotMarkInstalled() + { + using var vm = new OllamaBrowserViewModel(new Fake { Pull = (_, _, _) => throw new IOException("missing") }); + await vm.PullAsync("missing:latest"); + Assert.False(vm.IsInstalled("missing:latest")); + Assert.Contains("missing", vm.DownloadError); + Assert.False(vm.Downloading); + } + [Fact] public async Task CancellationRefreshesServerInventory() + { + var started = new TaskCompletionSource(); + var fake = new Fake { Pull = async (_, _, ct) => { started.SetResult(); await Task.Delay(Timeout.Infinite, ct); } }; + using var vm = new OllamaBrowserViewModel(fake); + var pull = vm.PullAsync("qwen3:4b"); await started.Task; vm.CancelPull(); await pull; + Assert.False(vm.Downloading); Assert.True(vm.InventoryKnown); + Assert.Contains("cancelled", vm.DownloadStatus); + } + [Fact] public async Task DisposeCancelsPendingRequests() + { + var started = new TaskCompletionSource(); + var fake = new Fake { Pull = async (_, _, ct) => { started.SetResult(); await Task.Delay(Timeout.Infinite, ct); } }; + var vm = new OllamaBrowserViewModel(fake); var task = vm.PullAsync("qwen3:4b"); + await started.Task; vm.Dispose(); await task; + Assert.False(vm.Downloading); + } + [Theory] + [InlineData("{\"models\":[]}")] + [InlineData("{\"models\":[{\"name\":\"qwen3:8b\"}]}")] + public async Task InventoryQueriesCapturedServer(string json) + { + using var client = new OllamaBrowserClient("http://localhost:1234", new HttpClient(new Handler(req => { + Assert.Equal("http://localhost:1234/api/tags", req.RequestUri!.AbsoluteUri); + return new(HttpStatusCode.OK) { Content = new StringContent(json, Encoding.UTF8, "application/json") }; + }))); + var result = await client.InstalledAsync(default); + Assert.Equal(json.Contains("qwen3") ? 1 : 0, result.Count); + } + [Fact] public async Task MalformedInventoryDoesNotMeanEmpty() + { + using var client = new OllamaBrowserClient("http://localhost", new HttpClient(new Handler(_ => new(HttpStatusCode.OK) { Content = new StringContent("{}") }))); + await Assert.ThrowsAsync(() => client.InstalledAsync(default)); + } + [Fact] public async Task CloudTagsAreAvailabilityRatherThanLocalDownloadBadges() + { + var fake = new Fake { + Inventory = _ => Task.FromResult>(new[] { "qwen3:cloud" }), + Tags = (_, _) => Task.FromResult>(new[] { new OllamaModelLibrary.Tag("qwen3:cloud", "") }) + }; + using var vm = new OllamaBrowserViewModel(fake); + await vm.RefreshAsync(); await vm.SelectModelAsync("qwen3"); + Assert.Equal("✓ Available on server", Assert.Single(vm.Tags).Status); + } + + [Fact] public async Task PullSendsCapturedEndpointAndReportsStreamedProgress() + { + var stages = new List(); + using var client = new OllamaBrowserClient("http://localhost:1234", new HttpClient(new Handler(req => { + Assert.Equal(HttpMethod.Post, req.Method); + Assert.Equal("http://localhost:1234/api/pull", req.RequestUri!.AbsoluteUri); + return new(HttpStatusCode.OK) { + Content = new StringContent("{\"status\":\"pulling\",\"completed\":5,\"total\":10}\n{\"status\":\"success\"}\n") + }; + }))); + await client.PullAsync("qwen3:8b", stages.Add, default); + Assert.Contains(stages, p => p.Completed == 5 && p.Total == 10); + } + + [Fact] public async Task SelectingFamilyChoosesLatestTagWithoutAnotherClick() + { + var fake = new Fake { + Tags = (_, _) => Task.FromResult>(new[] { + new OllamaModelLibrary.Tag("qwen3:4b", ""), + new OllamaModelLibrary.Tag("qwen3:latest", "") }) + }; + using var vm = new OllamaBrowserViewModel(fake); + await vm.RefreshAsync(); await vm.SelectModelAsync("qwen3"); + Assert.Equal("qwen3:latest", vm.SelectedTag); + } + + [Fact] public async Task CloudOnlySelectionChoosesCloudInsteadOfLocalLatest() + { + var fake = new Fake { + Tags = (_, _) => Task.FromResult>(new[] { + new OllamaModelLibrary.Tag("qwen3:latest", ""), + new OllamaModelLibrary.Tag("qwen3:cloud", "") }) + }; + using var vm = new OllamaBrowserViewModel(fake) { CloudOnly = true }; + await vm.RefreshAsync(); await vm.SelectModelAsync("qwen3"); + Assert.Equal("qwen3:cloud", vm.SelectedTag); + } + + [Fact] public async Task CloudFamilyWithOneTagDoesNotRequireTagSelection() + { + var fake = new Fake { + Tags = (_, _) => Task.FromResult>(new[] { new OllamaModelLibrary.Tag("qwen3:cloud", "") }) + }; + using var vm = new OllamaBrowserViewModel(fake); + await vm.RefreshAsync(); await vm.SelectModelAsync("qwen3"); + Assert.Equal("qwen3:cloud", vm.SelectedTag); + } + + [Fact] public async Task ChangingSortClearsSelectionAndRejectsLateTags() + { + var pending = new TaskCompletionSource>(); + var fake = new Fake { Tags = (_, _) => pending.Task }; + using var vm = new OllamaBrowserViewModel(fake); + await vm.RefreshAsync(); + var lookup = vm.SelectModelAsync("qwen3"); + await vm.LoadCatalogAsync(OllamaCatalogSort.Popular); + Assert.Null(vm.SelectedModel); Assert.Null(vm.SelectedTag); + Assert.Empty(vm.Tags); Assert.False(vm.TagsLoading); + pending.SetResult(new[] { new OllamaModelLibrary.Tag("qwen3:latest", "") }); + await lookup; + Assert.Empty(vm.Tags); Assert.Null(vm.SelectedTag); + } + + [Fact] public async Task ChangingSortClearsPreviouslyLoadedDetails() + { + using var vm = new OllamaBrowserViewModel(new Fake()); + await vm.RefreshAsync(); await vm.SelectModelAsync("qwen3"); + Assert.NotNull(vm.SelectedTag); + await vm.LoadCatalogAsync(OllamaCatalogSort.Name); + Assert.Empty(vm.Tags); Assert.Null(vm.SelectedModel); Assert.Null(vm.SelectedTag); + } + + [Fact] public async Task CloudOnlyHidesLocalVariantsAndCountsOnlyCloudInventory() + { + var fake = new Fake { + Catalog = new[] { new OllamaModelLibrary.Model("mixed", "", "tools · cloud"), new OllamaModelLibrary.Model("local", "", "tools") }, + Inventory = _ => Task.FromResult>(new[] { "mixed:latest", "mixed:small", "mixed:cloud" }), + Tags = (_, _) => Task.FromResult>(new[] { + new OllamaModelLibrary.Tag("mixed:latest", "5GB"), + new OllamaModelLibrary.Tag("mixed:cloud", ""), + new OllamaModelLibrary.Tag("mixed:large-cloud", "") }) + }; + using var vm = new OllamaBrowserViewModel(fake) { CloudOnly = true }; + await vm.RefreshAsync(); await vm.SelectModelAsync("mixed"); + Assert.Equal("mixed", Assert.Single(vm.Models).Name); + Assert.Contains("1 tag(s)", vm.Models[0].Status); + Assert.Equal(2, vm.Tags.Count); + Assert.All(vm.Tags, t => Assert.True(MandoCode.Models.MandoCodeConfig.IsCloudModel(t.Name))); + Assert.Equal("mixed:cloud", vm.SelectedTag); + } + + [Fact] public async Task CloudOnlyNeverFallsBackToLocalLatest() + { + using var vm = new OllamaBrowserViewModel(new Fake()) { CloudOnly = true }; + await vm.RefreshAsync(); await vm.SelectModelAsync("qwen3"); + Assert.Null(vm.SelectedTag); Assert.Empty(vm.Tags); + Assert.Contains("No cloud tags", vm.TagsError); + } + + [Fact] public async Task CloudFilterChangeRejectsPendingLocalTags() + { + var pending = new TaskCompletionSource>(); + using var vm = new OllamaBrowserViewModel(new Fake { Tags = (_, _) => pending.Task }); + await vm.RefreshAsync(); var lookup = vm.SelectModelAsync("qwen3"); + vm.CloudOnly = true; + pending.SetResult(new[] { new OllamaModelLibrary.Tag("qwen3:latest", "") }); + await lookup; + Assert.Null(vm.SelectedModel); Assert.Null(vm.SelectedTag); Assert.Empty(vm.Tags); + } + + private sealed class Handler(Func handle) : HttpMessageHandler { + protected override Task SendAsync(HttpRequestMessage request, CancellationToken ct) => Task.FromResult(handle(request)); + } + private sealed class Fake : IOllamaBrowserClient + { + public IReadOnlyList Catalog = new[] { new OllamaModelLibrary.Model("qwen3", "test", "tools") }; + public Func>> Inventory = _ => Task.FromResult>(new[] { "qwen3:8b" }); + public Func>> Tags = (_, _) => Task.FromResult>(new[] { new OllamaModelLibrary.Tag("qwen3:8b", "5 GB"), new OllamaModelLibrary.Tag("qwen3:4b", "3 GB") }); + public Func, CancellationToken, Task> Pull = (_, _, _) => Task.CompletedTask; + public Task> ModelsAsync(bool newest, CancellationToken ct) => Task.FromResult(Catalog); + public Task> TagsAsync(string name, CancellationToken ct) => Tags(name, ct); + public Task> InstalledAsync(CancellationToken ct) => Inventory(ct); + public Task PullAsync(string name, Action progress, CancellationToken ct) => Pull(name, progress, ct); + } +} diff --git a/src/MandoCode.Desktop/Controls/Chat/ChatTabView.xaml b/src/MandoCode.Desktop/Controls/Chat/ChatTabView.xaml index 8d67061..6e1200d 100644 --- a/src/MandoCode.Desktop/Controls/Chat/ChatTabView.xaml +++ b/src/MandoCode.Desktop/Controls/Chat/ChatTabView.xaml @@ -57,6 +57,7 @@ + @@ -67,7 +68,7 @@ - @@ -95,6 +96,8 @@ +