|
| 1 | +# Replace NuGet package lookup CLI calls with NuGet Protocol |
| 2 | + |
| 3 | +**GitHub Issue:** #72 |
| 4 | + |
| 5 | +## Description |
| 6 | + |
| 7 | +`NuGetPackageService` currently uses `dotnet package search` CLI calls to look up package versions. This needs to be replaced with direct NuGet Protocol API usage for correctness and performance. |
| 8 | + |
| 9 | +## Problems with Current Implementation |
| 10 | + |
| 11 | +1. **Prerelease packages reported as "not found"** - Missing `--prerelease` flag means packages like `TimeWarp.Amuru`, `TimeWarp.Jaribu`, and `TimeWarp.Multiavatar` are not found when only prerelease versions exist |
| 12 | +2. **Slow lookups** - Each package spawns a new `dotnet` process, making `ganda nuget outdated` much slower than tools like `dotnet outdated` |
| 13 | + |
| 14 | +## Checklist |
| 15 | + |
| 16 | +- [x] Add NuGet.Protocol and NuGet.Configuration package references |
| 17 | +- [x] Implement `SourceRepository` creation from configured NuGet sources |
| 18 | +- [x] Implement `PackageMetadataResource` caching per source (via `NuGetSourceCache`) |
| 19 | +- [x] Replace `dotnet package search` CLI call with `FindPackageByIdResource.GetAllVersionsAsync()` API |
| 20 | +- [x] Ensure prerelease packages are correctly found |
| 21 | +- [x] Ensure authenticated feeds work correctly |
| 22 | +- [x] Maintain existing `INuGetPackageService` contract compatibility |
| 23 | +- [x] Add/update unit tests for the new implementation |
| 24 | +- [x] Verify performance improvement over CLI approach |
| 25 | +- [x] Update documentation if needed |
| 26 | + |
| 27 | +## Session |
| 28 | + |
| 29 | +- Created: ses_27dd18c7effe1K4rnFRhnQezjn (2026-04-12) |
| 30 | + |
| 31 | +## Notes |
| 32 | + |
| 33 | +- Current implementation location: `NuGetPackageService` |
| 34 | +- Current CLI command: `dotnet package search {packageId} --exact-match --format json` |
| 35 | +- The new implementation should: |
| 36 | + - correctly find prerelease packages |
| 37 | + - be much faster (avoid process startup overhead) |
| 38 | + - work with configured NuGet sources and authenticated feeds |
| 39 | + - preserve the existing `INuGetPackageService` contract |
| 40 | +- Repro observed: `ganda nuget outdated --update` shows packages as "(not found on NuGet)" even though they exist as prerelease |
| 41 | + |
| 42 | +--- |
| 43 | + |
| 44 | +## Implementation Plan |
| 45 | + |
| 46 | +### Files Modified |
| 47 | +- `Directory.Packages.props` - Added `NuGet.Protocol`, `NuGet.Configuration`, `NuGet.Common` (upgraded to 7.3.0) |
| 48 | +- `source/timewarp-amuru/timewarp-amuru.csproj` - Added package references |
| 49 | +- `source/timewarp-amuru/nu-get/nuget-package-service.cs` - Replaced CLI calls with `FindPackageByIdResource.GetAllVersionsAsync()` |
| 50 | +- `source/timewarp-amuru/nu-get/NuGetModels.cs` - Renamed to `nuget-models.cs` (kebab-case) |
| 51 | + |
| 52 | +### Files Created |
| 53 | +- `source/timewarp-amuru/nu-get/nuget-source-cache.cs` - Cache `SourceRepository` instances per source URL |
| 54 | + |
| 55 | +### Tests Updated |
| 56 | +- `tests/timewarp-amuru/single-file-tests/repo-services/nuget-package-service.cs` - Added prerelease package tests, all 29 tests pass |
| 57 | + |
| 58 | +### Key Decisions |
| 59 | +1. Use `FindPackageByIdResource` instead of `PackageMetadataResource` - returns all versions including prerelease, simpler API |
| 60 | +2. Upgraded NuGet packages to 7.3.0 (from 6.11.0) - uses System.Text.Json instead of Newtonsoft.Json |
| 61 | +3. Cache `SourceRepository` instances in `NuGetSourceCache` to avoid repeated initialization |
| 62 | +4. Remove `ParseSearchResult` method entirely (CLI JSON parsing no longer needed) |
| 63 | +5. `INuGetPackageService` contract remains unchanged - backward compatible |
| 64 | +6. Aggregate versions from all enabled NuGet sources |
| 65 | + |
| 66 | +### Additional Changes (Style/Cleanup) |
| 67 | +- All `source/timewarp-amuru/` files renamed to kebab-case (PascalCase → kebab-case) |
| 68 | +- All `TODO:` region comments replaced with proper purpose/design descriptions |
| 69 | +- `global-usings.cs` consolidated into single project-level file (removed folder-level duplicates) |
| 70 | +- `*.lscache` files added to `.gitignore` |
| 71 | +- Test files updated: replaced `ProcessStartInfo` with `Shell.Builder` (fixing RS0030 violations) |
| 72 | +- `tools/dev-cli/services/process-helpers.cs` - Replaced `ProcessStartInfo` with `Shell.Builder` + argument parser |
| 73 | +- Dev-cli: `TreatWarningsAsErrors` enabled, `global-usings.cs` added to compilation, `IL2104`/`IL3053` suppressed (StreamJsonRpc transitive Newtonsoft dep) |
| 74 | +- `Directory.Packages.props`: `ModelContextProtocol.Core` updated to 1.0.0 |
| 75 | +- `AGENTS.md` updated to reflect that build scripts/dev-cli should prefer `Shell.Builder` |
| 76 | +- Command core files now use richer collocated `#region` documentation (`Purpose`, `Design`, `Responsibilities`, `Execution Modes`, `Implementation Boundaries`) |
| 77 | +- Stale sidecar docs `source/timewarp-amuru/core/command-extensions.md` and `command-result.md` deleted in favor of collocated source documentation |
| 78 | +- README and architectural docs updated to reference source files instead of deleted sidecar docs |
| 79 | + |
| 80 | +### Implementation Steps |
| 81 | +1. ✅ Add NuGet.Protocol and NuGet.Configuration to Directory.Packages.props |
| 82 | +2. ✅ Add package references to timewarp-amuru.csproj |
| 83 | +3. ✅ Create NuGetSourceCache.cs helper class |
| 84 | +4. ✅ Rewrite NuGetPackageService.SearchAsync() using FindPackageByIdResource |
| 85 | +5. ✅ Remove ParseSearchResult private method |
| 86 | +6. ✅ Add NuGetVersionComparer helper |
| 87 | +7. ✅ Update tests with prerelease package test case |
| 88 | +8. ✅ Verify RepoCheckVersionService and CheckVersionCommand work unchanged |
| 89 | +9. ✅ Run full test suite (355 passed, 1 skipped) |
| 90 | +10. ✅ Update documentation |
0 commit comments