Skip to content

Keep the workspace in sync with the disk; add UnloadSolution; move to .NET 10 / MCP SDK 2.2.0 - #25

Open
Jaben wants to merge 2 commits into
kooshi:mainfrom
ChangemakerStudios:feature/disk-sync
Open

Keep the workspace in sync with the disk; add UnloadSolution; move to .NET 10 / MCP SDK 2.2.0#25
Jaben wants to merge 2 commits into
kooshi:mainfrom
ChangemakerStudios:feature/disk-sync

Conversation

@Jaben

@Jaben Jaben commented Aug 22, 2026

Copy link
Copy Markdown

MSBuildWorkspace never watches the file system, so a document edited outside SharpTools (an editor, git, another agent tool) was invisible, and the next SharpTools write rewrote that file from the stale in-memory buffer — I hit this in daily use and confirmed it silently reverted outside edits. This is the per-document take on what #11 set out to do: instead of a FileSystemWatcher and full reloads, every tool call first stats the loaded documents and re-reads only the ones whose content changed (~10 ms for a 420-document solution); files added or removed under a project directory, or a changed project/solution file, trigger a reload. Tool results end with an <externalChanges> note naming what was re-read (or that the solution reloaded) so the agent knows its picture of those files is old. Writes are diffed against the solution the tool actually started from (tracked per invocation) and rebased onto the workspace's own solution, so untouched files are never rewritten, and an edit to a document that changed underneath fails with a retry message instead of losing the other change. Also adds SharpTool_UnloadSolution and an xunit project (SharpTools.Tools.Tests) covering visibility, no-clobber, untouched-not-rewritten, add/remove/project-file reload, sequential same-file edits, and the stale/drift rejections; beyond the unit tests this was exercised end-to-end through the stdio server against a real 420-file net10 solution.

The second commit moves everything to net10.0 and updates packages: ModelContextProtocol 0.4.0-preview.3 → 2.2.0 (no code changes except pinning the SharpTask prompt name, since 2.x defaults unnamed prompts to snake_case), Roslyn 5.9.0 across the board, Microsoft.Build.Locator 1.11.2 (its new copy-local check is disabled in Directory.Build.props — the flagged assemblies are Microsoft.Build.Framework, transitive from Roslyn, and NuGet.Frameworks, which NuGet.Protocol needs in-process, and MSBuild itself only runs in Roslyn's out-of-proc BuildHost), plus Decompiler, LibGit2Sharp, NuGet.Protocol, Serilog, System.CommandLine and the test SDK. Happy to split that into its own PR if you'd rather review them separately.

Jaben added 2 commits August 21, 2026 21:03
MSBuildWorkspace never watches the file system, so a document edited outside SharpTools (editor, git, another tool) was invisible and the next write rewrote it from the stale buffer. Every tool now syncs first: documents are stat'ed and only the ones that changed are re-read; files added or removed, or a changed project file, trigger a reload. Results carry an <externalChanges> note naming what was re-read. Writes are diffed against the solution the tool actually started from and rebased onto the workspace, so untouched files are never rewritten and an edit to a document that changed underneath fails with a retry message instead of losing the other change. Adds SharpTool_UnloadSolution and an xunit project covering the sync and conflict paths. Supersedes the FileSystemWatcher/full-reload approach proposed in kooshi#11.
…other packages

All projects now target net10.0. ModelContextProtocol 0.4.0-preview.3 -> 2.2.0 needed no code changes apart from pinning the SharpTask prompt name, since 2.x defaults unnamed prompts to snake_case. Roslyn packages aligned at 5.9.0 (Workspaces.MSBuild had been left at 5.6.0, tripping NU1608). Microsoft.Build.Locator 1.11.2's copy-local check is disabled in Directory.Build.props: the flagged assemblies are Microsoft.Build.Framework (transitive from Roslyn) and NuGet.Frameworks (needed in-process by NuGet.Protocol), and MSBuild itself only runs in Roslyn's out-of-proc BuildHost, so the version-mixing hazard the check guards against does not apply. Also bumps ICSharpCode.Decompiler, LibGit2Sharp, NuGet.Protocol, Serilog, System.CommandLine, test SDK/xunit runner, and drops the in-box System.Reflection.Metadata reference.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant