Skip to content

Free, open-source Windows optimization tool for performance, privacy, and simplicity.

docs: power pattern in AGENTS and CONTRIBUTING (en, ja, tr)

fatDuckb8cf77a6e9cb
diff --git a/.github/contributing/CONTRIBUTING.ja-JP.md b/.github/contributing/CONTRIBUTING.ja-JP.md
index b8d3053..a7c871f 100644
--- a/.github/contributing/CONTRIBUTING.ja-JP.md
+++ b/.github/contributing/CONTRIBUTING.ja-JP.md
@@ -207,7 +207,7 @@ optimizerDuck.slnx # ソリューションファイル
| 判断 | 理由 |
|---|---|
| **リフレクションによる自動検出** | DI 登録配列を更新する必要がありません。`ReflectionHelper.FindImplementationsInLoadedAssemblies<T>()` が `optimizerDuck.*` アセンブリをスキャンします。新しい最適化や設定は自動的に検出されます。 |
-| **プロバイダーサービス** | ステートレスなサービス(`RegistryService`、`ScheduledTaskService`、`ServiceProcessService`)は **static** です — 明示的な `OpCall`(`context`)で直接呼びます。`ShellService`(+ `ProcessRunner`)は DI シングルトンです(ライブ設定状態を持つ)。ドメインコードは `context.Shell`(`ShellService`)を使います。 |
+| **プロバイダーサービス** | ステートレスなサービス(`RegistryService`、`ScheduledTaskService`、`ServiceProcessService`)は **static** です — 明示的な `OpCall`(`context`)で直接呼びます。`ShellService`(+ `ProcessRunner`)は DI シングルトンです(ライブ設定状態を持つ)。ドメインコードは `context.Shell`(`ShellService`)を使います。例外:`PowerPlanService` は lean な DI シングルトンです(読み取りは id のみ、書き込みは `ILogger?` のみで何も記録しません。名前付き record 結果)。記録は `PowerPlanChanges` がエッジで行います。 |
| **ファイルベースのリバート追跡** | 適用状態 = ディスク上にファイルが存在する(`%localappdata%\optimizerDuck\Revert\{id}.json`)。データベースは使用しません。`File.Replace()` によるアトミック書き込み。 |
| **条件システム(フェイルオープン)** | 最適化や設定は互換性条件を宣言できます。評価の失敗がアイテムを隠すことはありません — [条件システム](#the-condition-system) を参照。 |
| **統合スタイルのテスト** | 実際のファイルシステム、実際のレジストリ(`HKCU\Software\TestOptimizerDuck*` 配下)、実際のプロセス実行。モックライブラリは使用せず、手書きのテストダブルのみ。 |
@@ -322,7 +322,7 @@ public class Performance : IOptimizationCategory
| **`context.Changes.ToApplyResult()` を返す** | `call.Changes`(`ChangeSet`)に集められた変更から `ApplyResult` を導出。早期終了の失敗時を除き、手動で `ApplyResult` を構築しないこと。 |
| **進捗を報告する** | `progress.Report(new ProcessingProgress { ... })` で UI ダイアログを更新。 |
| **すべての例外をキャッチしない** | 例外は上位に伝播。プロバイダーが `OpResult` に成功/失敗を記録し、`OptimizationService` が `ChangeSet` から処理。 |
-| **リバートステップを手動で作成しない** | インスタンス型プロバイダーが `call.Changes` への記録経由で自動的に行う。 |
+| **リバートステップを手動で作成しない** | インスタンス型プロバイダーが `call.Changes` への記録経由で自動的に行う。電源呼び出しは `PowerPlanChanges` 経由で記録し、手動で行わない。 |
| **`context.Logger` を使用する** | 重要な診断情報の記録に使用。 |
| **`context.Snapshot` を使用する** | `OptimizationContext.Snapshot`(`SystemInfo`)が RAM、GPU、CPU、OS 情報を提供。条件分岐に使用。 |
| **`context.StreamService` を使用する** | リモートリソース(電源プランなど)をダウンロードする最適化向け。 |
@@ -330,7 +330,7 @@ public class Performance : IOptimizationCategory
<h3 id="available-service-providers">利用可能なサービスプロバイダー</h3>
-ステートレスなサービスは **static** で直接呼びます(`new` 不要・割り当てなし)。`Shell` は `BaseOptimization`/`BaseCustomizeSetting` のプロパティを使います。これらのクラスはログ記録、エラー処理、`call.Changes` への変更記録を担当し、各操作は `OpResult` を返します。`ShellService` と `ProcessRunner` は DI シングルトンです(タイムアウトは設定からライブ読み取り)。
+ステートレスなサービスは **static** で直接呼びます(`new` 不要・割り当てなし)。`Shell` は `BaseOptimization`/`BaseCustomizeSetting` のプロパティを使います。これらのクラスはログ記録、エラー処理、`call.Changes` への変更記録を担当し、各操作は `OpResult` を返します。例外は lean な電源コアです:`ILogger?` を取り、何も記録しません。`ShellService` と `ProcessRunner` は DI シングルトンです(タイムアウトは設定からライブ読み取り)。
| サービス | 主要メソッド | 使用理由 |
|---|---|---|
@@ -338,6 +338,7 @@ public class Performance : IOptimizationCategory
| **`context.Shell`**(`ShellService`) | `CMDAsync()`、`PowerShellAsync()`、`CMD()`(同期)、`PowerShell()`(同期)、`QueryCMDAsync()`/`QueryPowerShellAsync()`(記録なしの素の実行) | CMD / PowerShell コマンドの実行。非同期版を推奨。元に戻すコマンドを `revertCommand` で指定可能。非標準終了コードは `ShellPolicy` を参照。 |
| **`ScheduledTaskService`**(static) | `DisableTask(path, context)`、`EnableTask(path, context)`、`GetTaskEnabledState()`、`DeleteTask()`、`GetAllTasks()`、`RegisterTask()`、`RunTask()`、`StopTask()` | Windows スケジュールタスクの管理。 |
| **`ServiceProcessService`**(static) | `ChangeServiceStartupTypeAsync(item, context)`(単体/配列)、`GetStartupTypeAsync()` | Windows サービスの管理。常に非同期版を使用。配列でバッチ変更可能。 |
+| **`PowerPlanService`**(DI シングルトン、lean)+ **`PowerPlanChanges`**(static エッジ記録) | `GetActiveSchemeId()`、`ListSchemes()`、`SetActiveScheme()`、`SetSetting()`、`ImportSchemeAsync()`、`InstallSchemeAsync()` | id を直接読み、書き込みはロガーのみ。複数値の戻り値は名前付き record(`ActivationResult`、`SettingWriteResult`、`SchemeRefResult`、`InstallResult`)。メンバーで読み、位置分解しない。`InstallAsync` 1 回で単一のリバートステップを記録。 |
> **params 配列で複数アイテムを受け付けるメソッド**:ほとんどの書き込み/変更メソッドは params 配列を受け付けます(例:`RegistryService.Write(context, item1, item2, item3)`)。個別呼び出しより効率的です。
diff --git a/.github/contributing/CONTRIBUTING.tr-TR.md b/.github/contributing/CONTRIBUTING.tr-TR.md
index f53f9fa..93c0630 100644
--- a/.github/contributing/CONTRIBUTING.tr-TR.md
+++ b/.github/contributing/CONTRIBUTING.tr-TR.md
@@ -207,7 +207,7 @@ optimizerDuck.slnx # Solution file (.slnx format)
| Karar | Gerekçe |
|---|---|
| **Yansıma tabanlı keşif** | Güncellenecek DI kayıt dizisi yok. `ReflectionHelper.FindImplementationsInLoadedAssemblies<T>()` `optimizerDuck.*` derlemelerini tarar. Yeni optimizasyonlar/ayarlar otomatik keşfedilir. |
-| **Sağlayıcı hizmetler** | Durumsuz hizmetler (`RegistryService`, `ScheduledTaskService`, `ServiceProcessService`) **statik**tir — açık `OpCall` (`context`) ile doğrudan çağırın. `ShellService` (+ `ProcessRunner`) DI singleton'dır (canlı ayar durumuna sahiptir); domain kodu `Shell` özelliğini kullanır. |
+| **Sağlayıcı hizmetler** | Durumsuz hizmetler (`RegistryService`, `ScheduledTaskService`, `ServiceProcessService`) **statik**tir — açık `OpCall` (`context`) ile doğrudan çağırın. `ShellService` (+ `ProcessRunner`) DI singleton'dır (canlı ayar durumuna sahiptir); domain kodu `Shell` özelliğini kullanır. İstisna: `PowerPlanService` yalın bir DI singleton'dır. Okumalar id alır, yazmalar yalnızca `ILogger?` alır ve hiçbir şey kaydetmez (adlandırılmış record sonuçları). Kaydı kenarda `PowerPlanChanges` yapar. |
| **Dosya tabanlı geri alma takibi** | Uygulanma durumu = diskte dosya var (`%localappdata%\optimizerDuck\Revert\{id}.json`). Veritabanı yok. `File.Replace()` ile atomik yazma. |
| **Koşul sistemi (açık kalma)** | Optimizasyonlar ve ayarlar uyumluluk koşulları bildirebilir. Değerlendirme hataları asla bir öğeyi gizlemez — [Koşul Sistemi](#the-condition-system) bölümüne bakın. |
| **Entegrasyon tarzı testler** | Gerçek dosya sistemi, gerçek kayıt defteri (`HKCU\Software\TestOptimizerDuck*` altında), gerçek süreç yürütme. Mock kütüphanesi yok — yalnızca elle yazılmış test ikizleri. |
@@ -323,7 +323,7 @@ public class Performance : IOptimizationCategory
| **`context.Changes.ToApplyResult()` döndürün** | `call.Changes` içinde toplanan değişikliklerden `ApplyResult` türetir. Erken çıkıştaki başarısızlıklar dışında `ApplyResult`'ı elle oluşturmayın. |
| **İlerlemeyi bildirin** | UI diyaloğunu güncellemek için `progress.Report(new ProcessingProgress { ... })` kullanın. |
| **Tüm istisnaları yakalamayın** | Yukarı yayılsın. Başarı/başarısızlık `ChangeSet` içinde izlenir; `OptimizationService` istisnaları işler. |
-| **Geri alma adımlarını elle oluşturmayın** | Örnek sağlayıcılar bunu otomatik yapar (`call.Changes` içine kaydeder). `ChangeSet.Add()` ile elle kayıt yapmayın (USB durumları gibi özel sağlayıcı dışı durumlar dışında). |
+| **Geri alma adımlarını elle oluşturmayın** | Örnek sağlayıcılar bunu otomatik yapar (`call.Changes` içine kaydeder). `ChangeSet.Add()` ile elle kayıt yapmayın (USB durumları gibi özel sağlayıcı dışı durumlar dışında). Güç çağrılarını `PowerPlanChanges` ile kaydedin, elle yapmayın. |
| **`context.Logger` kullanın** | Önemli tanılama bilgileri için günlük kaydı sağlar. |
| **`context.Snapshot` kullanın** | `OptimizationContext.Snapshot` (`SystemInfo`) RAM, GPU, CPU, OS bilgisi verir. Koşullu mantık için kullanın. |
| **`context.StreamService` kullanın** | Uzak kaynakları (örn. güç planları) indiren optimizasyonlar için. |
@@ -331,7 +331,7 @@ public class Performance : IOptimizationCategory
<h3 id="available-service-providers">Mevcut Hizmet Sağlayıcılar</h3>
-Bu sınıflar günlük kaydı, hata işleme ve otomatik geri alma adımı kaydını yönetir. Her yazma/değiştirme çağrısı açık bir `OpCall` alır (`OptimizationContext` bir `OpCall`'dır), değişikliği `call.Changes` içine kaydeder ve `OpResult` döndürür. Durumsuz hizmetler statiktir (doğrudan çağırın); `Shell` için hazır özelliği kullanın.
+Bu sınıflar günlük kaydı, hata işleme ve otomatik geri alma adımı kaydını yönetir. Her yazma/değiştirme çağrısı açık bir `OpCall` alır (`OptimizationContext` bir `OpCall`'dır), değişikliği `call.Changes` içine kaydeder ve `OpResult` döndürür. İstisna yalın güç çekirdeğidir: `ILogger?` alır ve hiçbir şey kaydetmez. Durumsuz hizmetler statiktir (doğrudan çağırın); `Shell` için hazır özelliği kullanın.
| Hizmet | Temel Metotlar | Neden Kullanılır |
|---|---|---|
@@ -339,6 +339,7 @@ Bu sınıflar günlük kaydı, hata işleme ve otomatik geri alma adımı kaydı
| **`context.Shell`**(`ShellService`) | `CMDAsync(command, call, revertCommand?)`, `PowerShellAsync(command, call, revertCommand?)`, ham çalıştırma için `QueryCMDAsync` / `QueryPowerShellAsync` | CMD veya PowerShell komutları çalıştırır. Asenkron sürümleri tercih edin. Geri alma için isteğe bağlı `revertCommand` parametresi. Standart dışı çıkış kodları için `ShellPolicy`'ye bakın. Ham `Run*` metotları değişiklik **kaydetmez**. |
| **`ScheduledTaskService`** | `DisableTask(path, call)`, `EnableTask(path, call)`, `GetTaskEnabledState(path, call?)`, `DeleteTask(...)`, `GetAllTasks(call?)`, `RegisterTask(...)`, `RunTask(...)`, `StopTask(...)` | Windows Zamanlanmış Görevlerini yönetir. |
| **`ServiceProcessService`** | `ChangeServiceStartupTypeAsync(item, call)`, `ChangeServiceStartupTypeAsync(items, call)`, `GetStartupTypeAsync(name, call?)` | Windows Hizmetlerini yönetir. Her zaman asenkron sürümleri kullanın. Toplu değişikliği dizi aşırı yüklemesiyle yapın. |
+| **`PowerPlanService`** (DI singleton, yalın) + **`PowerPlanChanges`** (statik kenar kaydedici) | `GetActiveSchemeId()`, `ListSchemes()`, `SetActiveScheme()`, `SetSetting()`, `ImportSchemeAsync()`, `InstallSchemeAsync()` | id'leri doğrudan okuyun, yazmalarda yalnızca logger kullanın. Çok değerli dönüşler adlandırılmış record'tur (`ActivationResult`, `SettingWriteResult`, `SchemeRefResult`, `InstallResult`). Üyelere erişin, konumsal parçalama yapmayın. Tek `InstallAsync` çağrısı tek geri alma adımını kaydeder. |
> **Toplu çağrılar**: Tekil params yerine `RegistryService.Write(context, item1, item2)` ve `ServiceProcessService.ChangeServiceStartupTypeAsync([item1, item2], context)` kullanın. Bu, tek tek çağrılardan daha verimlidir.
diff --git a/AGENTS.md b/AGENTS.md
index eeed47b..da64bd7 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -28,13 +28,14 @@
- `Optimizations/Categories/` — Performance, SecurityAndPrivacy, Gpu, PowerManagement, BloatwareAndServices, UserExperience, AI (nested optimization classes)
- `Optimizations/Models/` — `BaseOptimization`, `ApplyResult`, `OptimizationContext`, `OptimizationResult`
- `Optimizations/Models/Services/` — `RegistryItem`, `ServiceItem` (+ `ServiceStartupType`), `ShellResult`
+ - `Optimizations/Models/Power/` — `PowerScheme`, `PowerSettingGroup`, `PowerSetting`, `PowerSource`, `PowerValueKind`, `PowerPossibleValue`, `PowerPlanError` (raw-vs-semantic-vs-display: numeric AC/DC stay numeric)
- `Optimizations/Models/Bloatware/` — `AppXPackage`
- `Optimizations/Models/Cleanup/` — `CleanupItem`
- `Optimizations/Models/ScheduledTask/` — `ScheduledTaskModel`
- `Optimizations/Models/StartupManager/` — `StartupApp`, `StartupTask`
- `Customize/Models/` — `BaseCustomizeSetting`, `RegistryToggle`, `RegistryBinding`, `CustomizeRefreshScope`, `SettingOption`, `CustomizeControlType`, `RecommendationState`, `CustomizeRecommendationResult`
- `Revert/` — `RevertData`, `RevertResult`
- - `Revert/Steps/` — `RegistryRevertStep`, `ServiceRevertStep`, `ScheduledTaskRevertStep`, `ShellRevertStep`, `UsbPowerRevertStep`
+ - `Revert/Steps/` — `RegistryRevertStep`, `ServiceRevertStep`, `ScheduledTaskRevertStep`, `ShellRevertStep`, `UsbPowerRevertStep`, `PowerPlanRevertStep`, `PowerSettingRevertStep`
- `Configuration/` — `AppSettings`
- `UI/` — enums: `OptimizationRisk`, `OptimizationTags` (flags), `OptimizationCategoryOrder`, `CustomizeOrder`, `OptimizationSuccessResult`, `OptimizationState` (ObservableObject with relative-time display), `RiskVisual`, `ProcessingProgress`, `LanguageOption`
- `Optimizations/Models/Services/` — also `RegistryValues` (shared value equality), `ShellPolicy` (shell success/error policy), `ShellResult`
@@ -43,11 +44,11 @@
- `Configuration/` — `ConfigManager`, `LanguageManager`
- `Customize/` — `CustomizeRegistry` (reflection-based discovery), `CustomizationExecutor` (debounce + sequential serialization for setting writes)
- `Optimization/` — `OptimizationRegistry`, `OptimizationService`, `OptimizationValidation` (fail-fast Id checks at startup)
- - `Optimization/Providers/` — `RegistryService`, `ScheduledTaskService`, `ServiceProcessService` are **static** (stateless); `ShellService` + `ProcessRunner` are DI singletons (stateful; `ShellService` reads the timeout live from settings). All take an explicit `OpCall`, record into `call.Changes`, log via `call.Logger`, return `OpResult`. `ShellMapping` centralises cmd/PowerShell argument building and result mapping.
+ - `System/Primitives/` — `RegistryService`, `ScheduledTaskService`, `ServiceProcessService` are **static** (stateless); `ShellService` + `ProcessRunner` are DI singletons (stateful; `ShellService` reads the timeout live from settings). Those four take an explicit `OpCall`, record into `call.Changes`, log via `call.Logger`, return `OpResult`. `ShellMapping` centralises cmd/PowerShell argument building and result mapping. `PowerPlanChanges` is the single edge recorder turning lean `PowerPlanService` results into `Change` + revert step + retry (categories never hand-roll power steps).
- `Windows/Services/ScStartupTypeParser.cs` — shared parser for `sc.exe qc` START_TYPE output, used by `ServiceProcessService`.
- `ApplicationServiceCollectionExtensions.cs` — `AddOptimizerApplication(IConfiguration)`: the whole application graph, separated from `App.xaml.cs` so a test can build it
- `Revert/` — `RevertManager` (atomic file-based revert data persistence)
- - `System/` — `RegistryWatcher` (+ `IRegistryWatcher`), `SystemInfoService` (defines `SystemInfo` + models), `StreamService`, `UpdaterService`, `CrossPageEventBus`, `CrossPageEvents`
+ - `System/` — `RegistryWatcher` (+ `IRegistryWatcher`), `SystemInfoService` (defines `SystemInfo` + models), `StreamService`, `UpdaterService`, `CrossPageEventBus`, `CrossPageEvents`, `PowerPlanService` (lean native core: reads take ids, writes take `ILogger? = null` and record nothing; single owner of all `powrprof.dll` interop)
- `UI/` — `BloatwareService`, `DiskCleanupService`, `StartupManagerService`
- `UI/` — XAML pages, ViewModels, windows, controls, dialogs, styles
- `Common/` — extensions, helpers, converters:
@@ -76,12 +77,12 @@
- **New customize settings**: Same nesting pattern inside `Domain/Customize/Categories/`, extend `BaseCustomizeSetting`, decorate with `[CustomizeSetting(Section = ..., Icon = ..., Recommendation = ..., Condition = typeof(...)?)]`. `Icon` is required (`SymbolRegular` enum). `Section` can be a string or enum value. `Recommendation` can be `On`, `Off`, `Depends`, `Experimental`, or `None`.
- **Category classes**: Decorate with `[OptimizationCategory(typeof(PageClass))]` or `[CustomizeCategory(PageType = typeof(PageClass))]`.
- **Discovery**: `ReflectionHelper.FindImplementationsInLoadedAssemblies<T>()` scans assemblies whose name starts with `optimizerDuck` — no DI registration array to update. Results are cached in `_implementationCache`.
-- **Provider services**: stateless services are static (`RegistryService`, `ServiceProcessService`, `ScheduledTaskService`) — call directly. `ShellService` + `ProcessRunner` are DI singletons, reached from optimizations as `context.Shell`. All take an explicit `OpCall`, record into `call.Changes`, return `OpResult`.
+- **Provider services**: stateless services are static (`RegistryService`, `ServiceProcessService`, `ScheduledTaskService`) — call directly. `ShellService` + `ProcessRunner` are DI singletons, reached from optimizations as `context.Shell`. All take an explicit `OpCall`, record into `call.Changes`, return `OpResult`. Exception: `PowerPlanService` is a lean DI singleton — reads take ids, writes take `ILogger? = null` and record nothing (named record results); `PowerPlanChanges` records at the edge instead.
- **Results**: Optimizations end `ApplyAsync` with `return context.Changes.ToApplyResult();`. Do not manually construct `ApplyResult` except for early-out failures.
- **Single execution path**: `BaseOptimization` + `OptimizationContext` (`OpCall`) + static providers + `ShellService`, orchestrated by `OptimizationService`. There is no second framework — do not add one, and do not write a second implementation of an existing Windows operation.
-- **One implementation per Windows operation**: `RegistryService`/`ServiceProcessService`/`ScheduledTaskService`/`ShellService` are the single source of truth (plus the shared `ScStartupTypeParser`, `RegistryValues`, `ShellMapping`). Fix behaviour there, not in a copy.
+- **One implementation per Windows operation**: `RegistryService`/`ServiceProcessService`/`ScheduledTaskService`/`ShellService` are the single source of truth (plus the shared `ScStartupTypeParser`, `RegistryValues`, `ShellMapping`). `PowerPlanService` is the single owner of all `powrprof.dll` interop. Fix behaviour there, not in a copy.
- **DI**: register through `AddOptimizerApplication(configuration)` (the whole app graph); `App.xaml.cs` only builds the host. The host sets `ValidateOnBuild`/`ValidateScopes`, so a broken registration fails at startup instead of at Apply time — keep it that way.
-- **Per-step failure policy**: providers record a failed `Change` with an error and (where a retry can help) a retry action; they do not throw. Only truly unrecoverable state throws. `OptimizationService` persists partial work with `CancellationToken.None` and builds the `OptimizationResult`.
+- **Per-step failure policy**: providers record a failed `Change` with an error and (where a retry can help) a retry action; they do not throw. Power failures record the same way via `PowerPlanChanges` (the service itself only returns diagnostics). Only truly unrecoverable state throws. `OptimizationService` persists partial work with `CancellationToken.None` and builds the `OptimizationResult`.
- **Preloading**: `OptimizationRegistry.PreloadOptimizationsAsync()` / `EnsurePreloadedAsync()` (and `CustomizeRegistry.PreloadCategoriesAsync()` / `EnsurePreloadedAsync()`) run reflection discovery on a background thread. `App.xaml.cs` preloads at startup; the Optimize/Customize pages call `EnsurePreloadedAsync()` before binding.
## Condition System (Compatibility Gating)
@@ -96,7 +97,7 @@
- **Atomic writes**: `RevertManager` writes to `.tmp` via `FileStream(WriteThrough)` + `Flush(flushToDisk: true)`, then `File.Replace` for crash safety. Stale `.tmp` files are swept at startup (`RemoveOrphanedTempFiles`).
- **Concurrent access**: Per-file `SemaphoreSlim` locks with 30-second timeout prevent race conditions. Lock entries are never disposed while in use.
- **Compact layout**: only successful steps persist, each with a fresh index; no null gaps. Re-apply appends new entries; recovered retry steps append via `AppendRevertStepAsync` (never overwrite — LIFO revert still ends at the original backup).
-- **Step types**: `RegistryRevertStep`, `ServiceRevertStep`, `ScheduledTaskRevertStep`, `ShellRevertStep`, `UsbPowerRevertStep`. Each verifies its own effect inside `ExecuteAsync` (registry read-back, service re-query, task state re-check). Access-denied is failure, never success. Missing `OriginalEnabled` throws (fail-closed).
+- **Step types**: `RegistryRevertStep`, `ServiceRevertStep`, `ScheduledTaskRevertStep`, `ShellRevertStep`, `UsbPowerRevertStep`, `PowerPlanRevertStep`, `PowerSettingRevertStep`. Each verifies its own effect inside `ExecuteAsync` (registry read-back, service re-query, task state re-check, power re-read). Access-denied is failure, never success. Missing `OriginalEnabled` throws (fail-closed).
- **Unknown types**: persisted data with an unregistered step type becomes a failing step with a clear message (never silently skipped); raw payload round-trips.
- **Step registry**: Revert step deserialization uses reflection-based `_stepRegistry` (`ConcurrentDictionary`). New step types auto-register by implementing `IRevertStep` with a static `FromData(JObject)` method.
- **Retry**: `OptimizationService.RetryFailedStepsWithResultsAsync()` re-invokes `Retry` with a fresh `OpCall` and persists recovered steps via `AppendRevertStepAsync`.
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 9321915..a632898 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -207,7 +207,7 @@ optimizerDuck.slnx # Solution file (.slnx format)
| Decision | Rationale |
|---|---|
| **Reflection-based discovery** | No DI registration arrays to update. `ReflectionHelper.FindImplementationsInLoadedAssemblies<T>()` scans `optimizerDuck.*` assemblies. New optimizations/settings are auto-discovered. |
-| **Provider services** | Stateless services (`RegistryService`, `ScheduledTaskService`, `ServiceProcessService`) are **static** — call them directly, passing the explicit `OpCall` (`context`). `ShellService` is a DI singleton (it holds the live shell timeout) and reaches optimizations as `context.Shell`. |
+| **Provider services** | Stateless services (`RegistryService`, `ScheduledTaskService`, `ServiceProcessService`) are **static** — call them directly, passing the explicit `OpCall` (`context`). `ShellService` is a DI singleton (it holds the live shell timeout) and reaches optimizations as `context.Shell`. Exception: `PowerPlanService` is a lean DI singleton — reads take ids, writes take `ILogger?` and record nothing (named record results); `PowerPlanChanges` records at the edge instead. |
| **File-based revert tracking** | Applied state = file exists on disk (`%localappdata%\optimizerDuck\Revert\{id}.json`). No database. Atomic writes via `File.Replace()`. |
| **Condition system (fail-open)** | Optimizations and settings can declare compatibility conditions. Evaluation failures never hide an item — see [The Condition System](#the-condition-system). |
| **Integration-style tests** | Real filesystem, real registry (under `HKCU\Software\TestOptimizerDuck*`), real process execution. No mocking libraries — hand-written test doubles only. |
@@ -322,7 +322,7 @@ public class Performance : IOptimizationCategory
| **Return `context.Changes.ToApplyResult()`** | Maps recorded changes to `ApplyResult`: any success is success; total failure carries the first error. Don't construct `ApplyResult` manually. |
| **Report progress** | Use `progress.Report(new ProcessingProgress { ... })` to update the UI dialog. |
| **Don't catch all exceptions** | Let them bubble up. `ChangeSet` tracks per-step success/failure; `OptimizationService` handles exceptions. |
-| **Don't manually create revert steps** | Static providers record `Change` entries (with revert steps) into `context.Changes` automatically. |
+| **Don't manually create revert steps** | Static providers record `Change` entries (with revert steps) into `context.Changes` automatically. Power callers record via `PowerPlanChanges`, never by hand. |
| **Use `context.Logger`** | The optimization context provides a logger for important diagnostic info. |
| **Use `context.Snapshot`** | `OptimizationContext.Snapshot` (a `SystemInfo`) gives system info: memory, GPU, CPU, Windows, firmware, security, power, storage. Use it for conditional logic. |
| **Use `context.StreamService`** | For optimizations that need to download remote resources (e.g. power plans). |
@@ -339,12 +339,13 @@ All of them handle logging, error handling, and revert recording through the exp
| **`RegistryService`** (static) | `Write()`, `Read<T>()`, `DeleteValue()`, `CreateSubKey()`, `DeleteSubKeyTree()`, `KeyExists()`, `CleanupEmptyKeys()` | Read/write/delete registry keys. Backs up original values for revert. Supports batch writes via params array. |
| **`context.Shell`** (`ShellService`) | `CMDAsync()`, `PowerShellAsync()` (record a change), `QueryCMDAsync()`, `QueryPowerShellAsync()` (read-only) | Run CMD or PowerShell commands. Prefer the async variants. Pass a `revertCommand` string, or an `IRevertStep`, for undo. See `ShellPolicy` for non-standard exit codes. |
| **`ScheduledTaskService`** (static) | `DisableTask()`, `EnableTask()`, `GetTaskEnabledState()`, `DeleteTask()`, `GetAllTasks()`, `RegisterTask()`, `RunTask()`, `StopTask()` | Manage Windows Scheduled Tasks. |
-| **`ServiceProcessService`** (static) | `ChangeServiceStartupTypeAsync()`, `GetStartupTypeAsync()` | Manage Windows Services. Always use async variants. Supports batch changes via array overload. |
+| **`PowerPlanService`** (DI singleton, lean) + **`PowerPlanChanges`** (static edge recorder) | `GetActiveSchemeId()`, `ListSchemes()`, `SetActiveScheme()`, `SetSetting()`, `ImportSchemeAsync()`, `InstallSchemeAsync()` | Read ids directly; write with a logger only. Multi-value returns are named records (`ActivationResult`, `SettingWriteResult`, `SchemeRefResult`, `InstallResult`) — read members, never deconstruct positionally. One `InstallAsync` call records the single revert step. |
> **Methods accepting multiple items via params**: Most write/change methods accept a params array of items (e.g., `RegistryService.Write(context, item1, item2, item3)`). This is more efficient than multiple individual calls.
Every mutating call takes the `OpCall` explicitly and returns an
-`OpResult`. Reads take an optional call for logging
+`OpResult`. The exception is the lean power core: it takes `ILogger?` and records nothing.
+Reads take an optional call for logging
(`RegistryService.Read<T>(item, context)` or `RegistryService.Read<T>(item)` for silent reads).
```csharp