@lesliechan721/aw 0.1.0-beta.101 → 0.1.0-beta.103

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. package/dist/src/commands/catalog-generation.d.ts +2 -5
  2. package/dist/src/commands/catalog-generation.js +2 -4
  3. package/dist/src/commands/catalog-generation.js.map +1 -1
  4. package/dist/src/commands/lifecycle-command-package.d.ts +1 -1
  5. package/dist/src/commands/lifecycle-command-package.js +40 -2
  6. package/dist/src/commands/lifecycle-command-package.js.map +1 -1
  7. package/dist/src/commands/managed-commands.d.ts +2 -1
  8. package/dist/src/commands/managed-commands.js +4 -2
  9. package/dist/src/commands/managed-commands.js.map +1 -1
  10. package/dist/src/commands/operation-plan.d.ts +2 -8
  11. package/dist/src/commands/operation-plan.js.map +1 -1
  12. package/dist/src/commands/public-config-confirmation.d.ts +16 -10
  13. package/dist/src/commands/public-config-confirmation.js +87 -52
  14. package/dist/src/commands/public-config-confirmation.js.map +1 -1
  15. package/dist/src/commands/public-lifecycle.d.ts +1 -1
  16. package/dist/src/commands/public-lifecycle.js +36 -8
  17. package/dist/src/commands/public-lifecycle.js.map +1 -1
  18. package/dist/src/commands/public-plugin-query.js +6 -4
  19. package/dist/src/commands/public-plugin-query.js.map +1 -1
  20. package/dist/src/commands/rebuild-command.d.ts +22 -6
  21. package/dist/src/commands/rebuild-command.js +273 -557
  22. package/dist/src/commands/rebuild-command.js.map +1 -1
  23. package/dist/src/commands/rebuild-integration.d.ts +12 -39
  24. package/dist/src/commands/rebuild-integration.js +67 -303
  25. package/dist/src/commands/rebuild-integration.js.map +1 -1
  26. package/dist/src/commands/rebuild-operations.d.ts +0 -4
  27. package/dist/src/commands/rebuild-operations.js +9 -8
  28. package/dist/src/commands/rebuild-operations.js.map +1 -1
  29. package/dist/src/commands/rebuild-platform-integration.d.ts +14 -6
  30. package/dist/src/commands/rebuild-platform-integration.js +310 -101
  31. package/dist/src/commands/rebuild-platform-integration.js.map +1 -1
  32. package/dist/src/commands/status-v6.d.ts +3 -117
  33. package/dist/src/commands/status-v6.js +0 -2886
  34. package/dist/src/commands/status-v6.js.map +1 -1
  35. package/dist/src/commands/write-commands.js +0 -3
  36. package/dist/src/commands/write-commands.js.map +1 -1
  37. package/dist/src/index.js +44 -36
  38. package/dist/src/index.js.map +1 -1
  39. package/dist/src/intent/deployment-preferences.js +4 -3
  40. package/dist/src/intent/deployment-preferences.js.map +1 -1
  41. package/dist/src/intent/intent-store.js +3 -2
  42. package/dist/src/intent/intent-store.js.map +1 -1
  43. package/dist/src/output/command-receipt.d.ts +0 -6
  44. package/dist/src/output/command-receipt.js +0 -15
  45. package/dist/src/output/command-receipt.js.map +1 -1
  46. package/dist/src/output/receipt-projection.js +2 -1
  47. package/dist/src/output/receipt-projection.js.map +1 -1
  48. package/dist/src/platforms/capabilities.js +8 -2
  49. package/dist/src/platforms/capabilities.js.map +1 -1
  50. package/dist/src/platforms/contracts.d.ts +2 -0
  51. package/dist/src/platforms/discovery.d.ts +2 -0
  52. package/dist/src/platforms/discovery.js +95 -49
  53. package/dist/src/platforms/discovery.js.map +1 -1
  54. package/dist/src/platforms/inspection-native.d.ts +7 -1
  55. package/dist/src/platforms/inspection-native.js +6 -3
  56. package/dist/src/platforms/inspection-native.js.map +1 -1
  57. package/dist/src/platforms/inspection-query.d.ts +28 -14
  58. package/dist/src/platforms/inspection-query.js +102 -8
  59. package/dist/src/platforms/inspection-query.js.map +1 -1
  60. package/dist/src/platforms/lifecycle-native-services.d.ts +1 -1
  61. package/dist/src/platforms/lifecycle-native-services.js +7 -2
  62. package/dist/src/platforms/lifecycle-native-services.js.map +1 -1
  63. package/dist/src/platforms/lifecycle-native.js +20 -3
  64. package/dist/src/platforms/lifecycle-native.js.map +1 -1
  65. package/dist/src/platforms/lifecycle.js +5 -0
  66. package/dist/src/platforms/lifecycle.js.map +1 -1
  67. package/dist/src/platforms/supplement-state.js +11 -2
  68. package/dist/src/platforms/supplement-state.js.map +1 -1
  69. package/dist/src/portable/commands.d.ts +1 -0
  70. package/dist/src/portable/commands.js.map +1 -1
  71. package/dist/src/portable/materializer.d.ts +2 -0
  72. package/dist/src/portable/materializer.js +4 -4
  73. package/dist/src/portable/materializer.js.map +1 -1
  74. package/dist/src/portable/recovery.d.ts +1 -0
  75. package/dist/src/portable/recovery.js +3 -2
  76. package/dist/src/portable/recovery.js.map +1 -1
  77. package/dist/src/recovery/coordinator.d.ts +6 -1
  78. package/dist/src/recovery/coordinator.js +113 -108
  79. package/dist/src/recovery/coordinator.js.map +1 -1
  80. package/dist/src/recovery/demand.d.ts +1 -2
  81. package/dist/src/recovery/demand.js +4 -11
  82. package/dist/src/recovery/demand.js.map +1 -1
  83. package/dist/src/recovery/install-concurrency.d.ts +12 -0
  84. package/dist/src/recovery/install-concurrency.js +39 -0
  85. package/dist/src/recovery/install-concurrency.js.map +1 -1
  86. package/dist/src/recovery/joint-coordinator.d.ts +3 -4
  87. package/dist/src/recovery/joint-coordinator.js +324 -188
  88. package/dist/src/recovery/joint-coordinator.js.map +1 -1
  89. package/dist/src/recovery/joint-demand.js +4 -3
  90. package/dist/src/recovery/joint-demand.js.map +1 -1
  91. package/dist/src/recovery/joint-install-execution.js +46 -2
  92. package/dist/src/recovery/joint-install-execution.js.map +1 -1
  93. package/dist/src/recovery/joint-install-native-rebase.js +5 -2
  94. package/dist/src/recovery/joint-install-native-rebase.js.map +1 -1
  95. package/dist/src/recovery/locked-prepared-execution.d.ts +32 -0
  96. package/dist/src/recovery/locked-prepared-execution.js +67 -0
  97. package/dist/src/recovery/locked-prepared-execution.js.map +1 -0
  98. package/dist/src/recovery/status.d.ts +20 -6
  99. package/dist/src/recovery/status.js +153 -98
  100. package/dist/src/recovery/status.js.map +1 -1
  101. package/dist/src/review/skill-materialization.d.ts +1 -0
  102. package/dist/src/review/skill-materialization.js.map +1 -1
  103. package/dist/src/tui/console-app-v4.js +4 -14
  104. package/dist/src/tui/console-app-v4.js.map +1 -1
  105. package/dist/src/tui/controller-runtime.js +201 -57
  106. package/dist/src/tui/controller-runtime.js.map +1 -1
  107. package/dist/src/tui/controller.d.ts +8 -9
  108. package/dist/src/tui/controller.js +5 -6
  109. package/dist/src/tui/controller.js.map +1 -1
  110. package/dist/src/tui/operation-review-planner.js +14 -103
  111. package/dist/src/tui/operation-review-planner.js.map +1 -1
  112. package/dist/src/types.d.ts +5 -1
  113. package/dist/src/types.js.map +1 -1
  114. package/dist/src/utils/agent-version.js +1 -0
  115. package/dist/src/utils/agent-version.js.map +1 -1
  116. package/dist/src/utils/artifact-renderer.d.ts +10 -0
  117. package/dist/src/utils/artifact-renderer.js +28 -2
  118. package/dist/src/utils/artifact-renderer.js.map +1 -1
  119. package/dist/src/utils/aw-home-mutation-lock.d.ts +8 -0
  120. package/dist/src/utils/aw-home-mutation-lock.js +44 -8
  121. package/dist/src/utils/aw-home-mutation-lock.js.map +1 -1
  122. package/dist/src/utils/bundle-integrity.js +126 -33
  123. package/dist/src/utils/bundle-integrity.js.map +1 -1
  124. package/dist/src/utils/catalog-generation-resolver.d.ts +4 -0
  125. package/dist/src/utils/catalog-generation-resolver.js +4 -0
  126. package/dist/src/utils/catalog-generation-resolver.js.map +1 -1
  127. package/dist/src/utils/catalog-generation-service.d.ts +50 -11
  128. package/dist/src/utils/catalog-generation-service.js +276 -130
  129. package/dist/src/utils/catalog-generation-service.js.map +1 -1
  130. package/dist/src/utils/catalog-generation-state.js +6 -1
  131. package/dist/src/utils/catalog-generation-state.js.map +1 -1
  132. package/dist/src/utils/catalog-generation-store.d.ts +5 -0
  133. package/dist/src/utils/catalog-generation-store.js +36 -13
  134. package/dist/src/utils/catalog-generation-store.js.map +1 -1
  135. package/dist/src/utils/catalog-operation-context.d.ts +17 -3
  136. package/dist/src/utils/catalog-operation-context.js +220 -22
  137. package/dist/src/utils/catalog-operation-context.js.map +1 -1
  138. package/dist/src/utils/catalog-performance.d.ts +3 -0
  139. package/dist/src/utils/catalog-performance.js +26 -0
  140. package/dist/src/utils/catalog-performance.js.map +1 -0
  141. package/dist/src/utils/catalog-snapshot.d.ts +5 -2
  142. package/dist/src/utils/catalog-snapshot.js +3 -2
  143. package/dist/src/utils/catalog-snapshot.js.map +1 -1
  144. package/dist/src/utils/catalog-source-impact.d.ts +2 -1
  145. package/dist/src/utils/catalog-source-impact.js +2 -2
  146. package/dist/src/utils/catalog-source-impact.js.map +1 -1
  147. package/dist/src/utils/catalog-source-references.d.ts +2 -0
  148. package/dist/src/utils/catalog-source-references.js +284 -148
  149. package/dist/src/utils/catalog-source-references.js.map +1 -1
  150. package/dist/src/utils/codex-executable-discovery.js +1 -0
  151. package/dist/src/utils/codex-executable-discovery.js.map +1 -1
  152. package/dist/src/utils/codex-manager.js +1 -0
  153. package/dist/src/utils/codex-manager.js.map +1 -1
  154. package/dist/src/utils/codex-native-observation.d.ts +5 -2
  155. package/dist/src/utils/codex-native-observation.js +8 -4
  156. package/dist/src/utils/codex-native-observation.js.map +1 -1
  157. package/dist/src/utils/component-command-preparation.d.ts +1 -0
  158. package/dist/src/utils/component-command-preparation.js.map +1 -1
  159. package/dist/src/utils/git-catalog-provider.d.ts +38 -5
  160. package/dist/src/utils/git-catalog-provider.js +365 -156
  161. package/dist/src/utils/git-catalog-provider.js.map +1 -1
  162. package/dist/src/utils/managed-command-closure.d.ts +3 -1
  163. package/dist/src/utils/managed-command-closure.js +10 -5
  164. package/dist/src/utils/managed-command-closure.js.map +1 -1
  165. package/dist/src/utils/managed-command-materialization.d.ts +2 -0
  166. package/dist/src/utils/managed-command-materialization.js +4 -3
  167. package/dist/src/utils/managed-command-materialization.js.map +1 -1
  168. package/dist/src/utils/managed-command-preparation.js +1 -1
  169. package/dist/src/utils/managed-command-preparation.js.map +1 -1
  170. package/dist/src/utils/multi-source-catalog.d.ts +1 -1
  171. package/dist/src/utils/multi-source-catalog.js +3 -3
  172. package/dist/src/utils/multi-source-catalog.js.map +1 -1
  173. package/dist/src/utils/native-cli.d.ts +6 -1
  174. package/dist/src/utils/native-cli.js +67 -32
  175. package/dist/src/utils/native-cli.js.map +1 -1
  176. package/dist/src/utils/platform-empty-state.d.ts +2 -0
  177. package/dist/src/utils/platform-empty-state.js +5 -5
  178. package/dist/src/utils/platform-empty-state.js.map +1 -1
  179. package/dist/src/utils/plugin-config-command-apply.d.ts +14 -4
  180. package/dist/src/utils/plugin-config-command-apply.js +49 -5
  181. package/dist/src/utils/plugin-config-command-apply.js.map +1 -1
  182. package/dist/src/utils/plugin-config-impact.d.ts +42 -0
  183. package/dist/src/utils/plugin-config-impact.js +170 -14
  184. package/dist/src/utils/plugin-config-impact.js.map +1 -1
  185. package/dist/src/utils/plugin-config-references.d.ts +3 -1
  186. package/dist/src/utils/plugin-config-references.js +3 -5
  187. package/dist/src/utils/plugin-config-references.js.map +1 -1
  188. package/dist/src/utils/plugin-config-write.d.ts +14 -5
  189. package/dist/src/utils/plugin-config-write.js +213 -117
  190. package/dist/src/utils/plugin-config-write.js.map +1 -1
  191. package/dist/src/utils/plugin-config.d.ts +2 -0
  192. package/dist/src/utils/plugin-config.js.map +1 -1
  193. package/dist/src/utils/plugin-scripts.d.ts +2 -0
  194. package/dist/src/utils/plugin-scripts.js +102 -3
  195. package/dist/src/utils/plugin-scripts.js.map +1 -1
  196. package/package.json +3 -5
  197. package/dist/src/utils/codex-reconciler.d.ts +0 -123
  198. package/dist/src/utils/codex-reconciler.js +0 -322
  199. package/dist/src/utils/codex-reconciler.js.map +0 -1
@@ -1,8 +1,9 @@
1
1
  import { readAgentSettings, previewAgentSettings, saveAgentSettings } from './agent-settings.js';
2
2
  import { observePreferences } from '../intent/deployment-preferences.js';
3
+ import { observeIntent } from '../intent/intent-store.js';
3
4
  import { resolveConfigurableLayers, classifyResidualConfigLayers } from '../utils/config-platforms.js';
4
5
  import { configObjectHasSensitiveChild } from './config-value-presentation.js';
5
- import { selectPluginConfigProfile, getPluginConfigReferenceChoices, PLATFORM_TARGETS, NATIVE_PLATFORM_TARGETS, resolveSupportedPlatforms } from '@lesliechan721/aw-plugin-core';
6
+ import { selectPluginConfigProfile, getPluginConfigReferenceChoices, PLATFORM_TARGETS, NATIVE_PLATFORM_TARGETS, resolveSupportedPlatforms, getCommandPackageId } from '@lesliechan721/aw-plugin-core';
6
7
  import { configReferenceKey, configReferenceScalars } from './config-references.js';
7
8
  import { preparePluginConfigSuggestions } from '../utils/plugin-config-suggestions.js';
8
9
  import crypto from 'node:crypto';
@@ -168,7 +169,7 @@ function currentConfigTargets(status, pluginId, configContext, consumers = [], p
168
169
  const selected = new Set([pluginId, ...consumers]);
169
170
  const observations = [...(status.observedTargets ?? []), ...(status.inventory ?? []).flatMap((root) => root.targetResults)];
170
171
  return [...new Map((status.existingTargets ?? []).flatMap((target) => {
171
- if (target.agent === 'generic' || !selected.has(target.pluginId)
172
+ if (!selected.has(target.pluginId)
172
173
  || configContext === 'user' && target.scope !== 'user'
173
174
  || platform && target.agent !== platform)
174
175
  return [];
@@ -254,7 +255,7 @@ async function loadCatalogView(options) {
254
255
  });
255
256
  }
256
257
  function configNeedsReferencePlugins(plugin) {
257
- return pluginConfigHasExternalReferences(plugin.manifest)
258
+ return !!plugin.manifest.dependencies?.length || pluginConfigHasExternalReferences(plugin.manifest)
258
259
  || (plugin.manifest.config !== undefined && [undefined, ...PLATFORM_TARGETS].some((platform) => Object.values(selectPluginConfigProfile(plugin.manifest.config, platform).fields)
259
260
  .some((field) => field.type === 'array' && field.items.type === 'object')));
260
261
  }
@@ -274,18 +275,20 @@ function configPackageReviewChanges(plan, reviews) {
274
275
  async function reviewConfigMutationApply(options, reviewed, fresh) {
275
276
  const mayChangeHostPermissions = options.applyTargets?.some(({ platform }) => isPermissionHost(platform) || platform === 'claude');
276
277
  // The writer revalidates the frozen command package candidate before saving.
277
- if (fresh && !mayChangeHostPermissions)
278
+ const hasPortableTargets = !!options.applyGenericTargets?.length;
279
+ if (fresh && !mayChangeHostPermissions && !hasPortableTargets)
278
280
  return {
279
281
  commandPackageEvidence: reviewed?.commandPackageEvidence,
280
282
  commandReviewChanges: reviewed?.commandReviewChanges,
281
283
  };
282
- if (!options.applyCommandPackages?.length && !mayChangeHostPermissions)
284
+ if (!options.applyCommandPackages?.length && !mayChangeHostPermissions && !hasPortableTargets)
283
285
  return { commandPackageEvidence: [] };
284
286
  const prepared = await preparePluginConfigApply(options);
285
287
  try {
286
288
  const hostPermissionEffects = recoveryHostPermissionEffects(prepared.plan);
287
289
  return { commandPackageEvidence: prepared.commandPackageEvidence,
288
290
  commandReviewChanges: configPackageReviewChanges(prepared.plan, prepared.commandPackageReviews),
291
+ preApplyAuthorization: prepared.preApplyAuthorization,
289
292
  ...(hostPermissionEffects.length ? { hostPermissionEffects } : {}) };
290
293
  }
291
294
  finally {
@@ -309,12 +312,17 @@ async function configRetryStoreDigest(options) {
309
312
  ...options.preApplyAuthorization.map(({ pluginName, scope }) => ({ pluginName, scope, platform: options.platform }))];
310
313
  return digest(await collectPluginConfigReferenceEvidence({ ...options, profiles, plugins }));
311
314
  }
312
- function configImpactVisibleTargets(pluginName, targets) {
313
- return targets.map((target) => ({
314
- pluginName: target.pluginName ?? pluginName,
315
- platform: target.platform,
316
- scope: target.scope,
317
- }));
315
+ function splitConfigTargets(targets) {
316
+ return {
317
+ visibleTargets: targets.flatMap(({ pluginName, platform, scope }) => platform === 'generic' ? [] : [{ pluginName, platform, scope }]),
318
+ visibleGenericTargets: targets.flatMap(({ pluginId, pluginName, platform, scope }) => platform === 'generic' ? [{ pluginId, pluginName, scope }] : []),
319
+ };
320
+ }
321
+ function configEvidenceTargets(impact, fallback) {
322
+ const targets = impact
323
+ ? [...impact.affectedTargets, ...impact.affectedGenericTargets.map((target) => ({ ...target, platform: 'generic' }))]
324
+ : fallback;
325
+ return targets.map(({ pluginName, platform, scope }) => ({ pluginName, platform, scope }));
318
326
  }
319
327
  function configIntentRequestsApply(intent) {
320
328
  if (!intent.apply)
@@ -326,6 +334,9 @@ function configIntentRequestsApply(intent) {
326
334
  return Object.keys(intent.updates ?? {}).length > 0
327
335
  || (intent.removeKeys?.length ?? 0) > 0;
328
336
  }
337
+ function configImpactTargetKey(target) {
338
+ return [target.pluginId, target.platform, target.scope].join('\0');
339
+ }
329
340
  function configSaveBatchGroupIntent(intent, group) {
330
341
  return {
331
342
  kind: 'configSave',
@@ -654,6 +665,7 @@ function createReviewStageReporter(options) {
654
665
  };
655
666
  }
656
667
  export function createTuiControllerDependencies(context, progressFeed, options = {}) {
668
+ const catalogGenerationRuntime = { debugLogger: context.debugLogger, ...options.catalogGenerationRuntime };
657
669
  const readInventory = options.inventoryCatalogSourceReferences
658
670
  ?? inventoryCatalogSourceReferences;
659
671
  let validatedStoreEntries = new Map();
@@ -695,6 +707,107 @@ export function createTuiControllerDependencies(context, progressFeed, options =
695
707
  let sessionRecoveryStatus;
696
708
  let latestStatusRead = 0;
697
709
  let bindNewCatalog = true;
710
+ const savedProfileImpacts = new Map();
711
+ // Only fresh, complete native observations can justify narrowing a subsequent apply.
712
+ const completeConfigImpact = new WeakSet();
713
+ const savedImpactKey = (intent) => [intent.pluginId, intent.context ?? 'user'].join('\0');
714
+ const savedStoreDigest = (intent, source) => configLayerStoreDigest({ source, pluginName: parsePluginId(intent.pluginId).pluginName,
715
+ scope: 'user', cwd: context.cwd, env: context.env }).catch(() => undefined);
716
+ const savedSelectionDigest = async (intent, plugin, referencePlugins) => {
717
+ const scope = intent.context ?? 'user';
718
+ try {
719
+ const work = await resolveWorkContext({ cwd: context.cwd, context: scope });
720
+ const preferences = await observePreferences({ scope: 'user', cwd: context.cwd, env: context.env });
721
+ const intents = await Promise.all(work.scopes.map((scope) => observeIntent({
722
+ scope, cwd: context.cwd, env: context.env,
723
+ })));
724
+ if (preferences.state !== 'valid' || intents.some((entry) => entry.state !== 'absent' && entry.state !== 'valid'))
725
+ return undefined;
726
+ const references = configNeedsReferencePlugins(plugin) ? await Promise.all((referencePlugins ?? [])
727
+ .filter((entry) => entry.manifest.config && entry.manifest.name !== plugin.manifest.name)
728
+ .map(async (entry) => {
729
+ const store = await readPluginConfigStore({ sourceId: entry.sourceId, sourceIdentity: entry.sourceIdentity,
730
+ logicalIdentity: entry.catalogLogicalIdentity, pluginName: entry.manifest.name,
731
+ scope: 'user', cwd: context.cwd, env: context.env });
732
+ return { pluginName: entry.manifest.name, exists: store.exists, rawDigest: store.rawDigest };
733
+ })) : [];
734
+ return digest({ context: work.context, projectRoot: work.projectRoot, preferences: preferences.rawDigest,
735
+ intents: intents.map((entry) => entry.state === 'valid' ? entry.rawDigest : entry.state),
736
+ references: references.sort((left, right) => left.pluginName.localeCompare(right.pluginName, 'en')) });
737
+ }
738
+ catch {
739
+ // An unreadable binding cannot justify the narrower replay. The full apply
740
+ // retains its ordinary diagnosis and recovery behavior.
741
+ return undefined;
742
+ }
743
+ };
744
+ const recordSavedImpact = async (intent, evidence, beforeDigest, selectionDigest, result) => {
745
+ if (intent.apply || !evidence.source || !evidence.config || !evidence.catalog.generationSetDigest)
746
+ return;
747
+ const key = savedImpactKey(intent);
748
+ const profileKey = intent.platform ?? 'common';
749
+ const postSaveConfigStoreDigest = await savedStoreDigest(intent, evidence.source);
750
+ const prior = savedProfileImpacts.get(key);
751
+ // The document contains all profiles. Later successful writes may advance the
752
+ // digest of prior profiles only while their original digest still matches.
753
+ const profiles = new Map([...(prior ?? [])].filter(([, entry]) => entry.postSaveConfigStoreDigest === beforeDigest
754
+ && entry.generationSetDigest === evidence.catalog.generationSetDigest && entry.selectionDigest === selectionDigest));
755
+ if (!beforeDigest || !postSaveConfigStoreDigest || !selectionDigest) {
756
+ savedProfileImpacts.delete(key);
757
+ return;
758
+ }
759
+ for (const [profile, entry] of profiles)
760
+ profiles.set(profile, { ...entry, postSaveConfigStoreDigest });
761
+ if (beforeDigest === postSaveConfigStoreDigest
762
+ || result.apply.state === 'skipped' && result.apply.reason === 'noConfigChange') {
763
+ // A no-op save is not evidence that previously published outputs are current.
764
+ profiles.delete(profileKey);
765
+ }
766
+ else {
767
+ const previous = profiles.get(profileKey);
768
+ const targets = evidence.config.affectedTargets.map(({ pluginName = parsePluginId(intent.pluginId).pluginName, platform, scope }) => ({ pluginId: `${evidence.source.sourceId}/${pluginName}`, pluginName, platform, scope }));
769
+ profiles.set(profileKey, {
770
+ profileKey,
771
+ postSaveConfigStoreDigest,
772
+ generationSetDigest: evidence.catalog.generationSetDigest,
773
+ selectionDigest,
774
+ impactKnown: completeConfigImpact.has(evidence) && evidence.config.impactState === 'known'
775
+ && (previous?.impactKnown ?? true),
776
+ affectedTargets: [...new Map([...(previous?.affectedTargets ?? []), ...targets]
777
+ .map((target) => [configImpactTargetKey(target), target])).values()],
778
+ affectedCommandPackages: [...new Set([...(previous?.affectedCommandPackages ?? []),
779
+ ...(evidence.config.commandPackages ?? []).map(({ packageId }) => packageId)])],
780
+ });
781
+ }
782
+ savedProfileImpacts.set(key, profiles);
783
+ };
784
+ const selectSavedImpact = async (intent, source, generationSetDigest, plugin, referencePlugins) => {
785
+ if (!intent.savedProfiles?.length)
786
+ return undefined;
787
+ const profiles = savedProfileImpacts.get(savedImpactKey(intent));
788
+ if (!profiles)
789
+ return undefined;
790
+ const currentDigest = await savedStoreDigest(intent, source);
791
+ const selectionDigest = await savedSelectionDigest(intent, plugin, referencePlugins);
792
+ const selected = intent.savedProfiles.map((profile) => profiles.get(profile));
793
+ if (!currentDigest || !selectionDigest || !selected.every((entry) => !!entry?.impactKnown && entry.postSaveConfigStoreDigest === currentDigest
794
+ && entry.generationSetDigest === generationSetDigest
795
+ && entry.selectionDigest === selectionDigest))
796
+ return undefined;
797
+ const applyCommandPackages = [...new Set(selected.flatMap(({ affectedCommandPackages }) => affectedCommandPackages))];
798
+ // Saved consumer impact does not prove the current package host and its providers.
799
+ // As in ordinary config apply, retain a joint plan for dependency-bearing packages.
800
+ if (applyCommandPackages.some((packageId) => !referencePlugins.some((entry) => entry.sourceId && entry.sourceIdentity
801
+ && !entry.manifest.dependencies?.length && getCommandPackageId({ sourceId: entry.sourceId,
802
+ sourceIdentity: entry.sourceIdentity, pluginName: entry.manifest.name }) === packageId)))
803
+ return undefined;
804
+ const scopedTargets = [...new Map(selected.flatMap(({ affectedTargets }) => affectedTargets)
805
+ .filter((target) => (!intent.platform || target.platform === intent.platform)
806
+ && (!intent.targets || intent.targets.includes(target.platform)))
807
+ .map((target) => [configImpactTargetKey(target), target])).values()];
808
+ const { visibleTargets, visibleGenericTargets } = splitConfigTargets(scopedTargets);
809
+ return { applyTargets: visibleTargets, ...(visibleGenericTargets.length ? { applyGenericTargets: visibleGenericTargets } : {}), applyCommandPackages };
810
+ };
698
811
  const sessionContextForPlugin = (pluginId) => {
699
812
  const sourceId = parsePluginId(pluginId).sourceId;
700
813
  if (!sourceId || !sessionCatalogOperationContext)
@@ -782,6 +895,8 @@ export function createTuiControllerDependencies(context, progressFeed, options =
782
895
  configured: new Set(catalogOperationContext.catalog.sources.map((source) => source.sourceId)),
783
896
  }) } : {}),
784
897
  });
898
+ // Final receipt observations belong to their completed operation. A page
899
+ // refresh must observe current inputs and deployments independently.
785
900
  const current = await readRecoveryStatus({ cwd: context.cwd, env: context.env, signal,
786
901
  cliVersion: packageInfo.version, nativeCliRunner: context.nativeCliRunner, catalogOperationContext, catalogReadScope }, snapshot);
787
902
  const dependencyOverviews = await loadDependencyOverviews({
@@ -1056,7 +1171,7 @@ export function createTuiControllerDependencies(context, progressFeed, options =
1056
1171
  scope: 'user', context: intent.context ?? 'user', platform: intent.platform,
1057
1172
  cwd: context.cwd,
1058
1173
  env: context.env,
1059
- visibleTargets: configImpactVisibleTargets(plugin.manifest.name, relevantTargets),
1174
+ ...splitConfigTargets(relevantTargets),
1060
1175
  mutation: { kind: 'reset' },
1061
1176
  }),
1062
1177
  }),
@@ -1088,8 +1203,7 @@ export function createTuiControllerDependencies(context, progressFeed, options =
1088
1203
  ...(selected?.impact.noEffectiveChange ? { noEffectiveChange: true } : {}),
1089
1204
  ...(selected?.impact.affectedCommandPackages.length
1090
1205
  ? { commandPackages: selected.impact.affectedCommandPackages } : {}),
1091
- affectedTargets: (selected?.impact.affectedTargets
1092
- ?? relevantTargets).map(({ platform, scope }) => ({ platform, scope })),
1206
+ affectedTargets: configEvidenceTargets(selected?.impact, relevantTargets).map(({ platform, scope }) => ({ platform, scope })),
1093
1207
  ...((selected?.impact.sharedNativeRenderUnits.length ?? 0) > 0
1094
1208
  ? { sharedNativeRenderUnits: selected.impact.sharedNativeRenderUnits }
1095
1209
  : {}),
@@ -1198,7 +1312,7 @@ export function createTuiControllerDependencies(context, progressFeed, options =
1198
1312
  expectedConfigDigest: config.digest,
1199
1313
  env: context.env,
1200
1314
  signal,
1201
- runtime: options.catalogGenerationRuntime,
1315
+ runtime: catalogGenerationRuntime,
1202
1316
  })
1203
1317
  : canReuseCandidate
1204
1318
  ? structuredClone(reusableCandidate.probe)
@@ -1208,7 +1322,7 @@ export function createTuiControllerDependencies(context, progressFeed, options =
1208
1322
  cliVersion: packageInfo.version,
1209
1323
  env: context.env,
1210
1324
  signal,
1211
- runtime: options.catalogGenerationRuntime,
1325
+ runtime: catalogGenerationRuntime,
1212
1326
  });
1213
1327
  signal?.throwIfAborted();
1214
1328
  await preparation?.reporter.emit('evidence');
@@ -1500,8 +1614,11 @@ export function createTuiControllerDependencies(context, progressFeed, options =
1500
1614
  logicalIdentity: plugin.catalogLogicalIdentity, env: context.env,
1501
1615
  operationContext: selectedCatalogOperation,
1502
1616
  });
1617
+ const sourceEvidence = sourceEvidenceForPlugin(source, plugin.manifest.name);
1618
+ const savedApplySelection = await selectSavedImpact(intent, sourceEvidence, selectedCatalogOperation.generationSetDigest, plugin, referencePlugins);
1503
1619
  const prepared = await preparePluginConfigApply({
1504
1620
  plugin, scope: 'user', context: intent.context ?? 'user', platform: intent.platform,
1621
+ ...savedApplySelection,
1505
1622
  ...(intent.targets ? { targets: intent.targets } : {}),
1506
1623
  cwd: context.cwd, env: context.env, cliVersion: packageInfo.version,
1507
1624
  nativeCliRunner: context.nativeCliRunner,
@@ -1528,14 +1645,17 @@ export function createTuiControllerDependencies(context, progressFeed, options =
1528
1645
  compositeDigest: selectedCatalogOperation.catalog.compositeDigest,
1529
1646
  ...(selectedCatalogOperation ? { generationSetDigest: selectedCatalogOperation.generationSetDigest } : {}),
1530
1647
  },
1531
- source: sourceEvidenceForPlugin(source, plugin.manifest.name),
1648
+ source: sourceEvidence,
1532
1649
  config: {
1533
1650
  scope: 'user', context: intent.context ?? 'user', platform: intent.platform,
1534
1651
  schemaIdentity: configSchemaIdentity(plugin, source.manifestDigest, intent.platform),
1535
1652
  storeDigest: digest(prepared.evidence),
1536
1653
  impactState: 'known', affectedTargets: targets,
1537
- commandPackages: prepared.commandPackages,
1654
+ commandPackages: savedApplySelection
1655
+ ? prepared.commandPackages.filter(({ packageId }) => savedApplySelection.applyCommandPackages.includes(packageId))
1656
+ : prepared.commandPackages,
1538
1657
  applyEvidence: prepared.evidence, applyChanges: prepared.plan.changes,
1658
+ ...(savedApplySelection ? { savedApplySelection } : {}),
1539
1659
  commandPackageEvidence: prepared.commandPackageEvidence,
1540
1660
  commandReviewChanges: configPackageReviewChanges(prepared.plan, prepared.commandPackageReviews),
1541
1661
  hostPermissionEffects: recoveryHostPermissionEffects(prepared.plan),
@@ -1621,7 +1741,7 @@ export function createTuiControllerDependencies(context, progressFeed, options =
1621
1741
  scope: 'user', context: intent.context ?? 'user', platform: intent.platform,
1622
1742
  cwd: context.cwd,
1623
1743
  env: context.env,
1624
- visibleTargets: configImpactVisibleTargets(plugin.manifest.name, relevantTargets),
1744
+ ...splitConfigTargets(relevantTargets),
1625
1745
  mutation: {
1626
1746
  kind: 'patch',
1627
1747
  updates: intent.updates,
@@ -1629,13 +1749,23 @@ export function createTuiControllerDependencies(context, progressFeed, options =
1629
1749
  },
1630
1750
  });
1631
1751
  const affectedTargets = intent.retryApply
1632
- ? configImpactVisibleTargets(plugin.manifest.name, relevantTargets)
1752
+ ? splitConfigTargets(relevantTargets).visibleTargets
1633
1753
  : impact.affectedTargets;
1634
1754
  const commandPackages = impact?.affectedCommandPackages
1635
1755
  ?? (await discoverPluginConfigManagedCommandPackages({ plugin, scope: intent.context ?? 'user',
1636
1756
  cwd: context.cwd, env: context.env ?? process.env, platformTargets: affectedTargets, referencePlugins })).packages;
1757
+ const { preApplyAuthorization: planAuthorization, ...commandReview } = configIntentRequestsApply(intent) ? await reviewConfigMutationApply({
1758
+ plugin, scope: 'user', context: intent.context ?? 'user', platform: intent.platform,
1759
+ cwd: context.cwd, env: context.env, cliVersion: packageInfo.version, nativeCliRunner: context.nativeCliRunner,
1760
+ applyTargets: affectedTargets, applyGenericTargets: impact?.affectedGenericTargets,
1761
+ applyCommandPackages: commandPackages.map(({ packageId }) => packageId),
1762
+ mutation: { kind: 'patch', updates: intent.updates, removeKeys: intent.removeKeys },
1763
+ rebuildRuntime: { ...context, signal, referencePlugins, catalogOperationContext: preparedCatalogOperation,
1764
+ expectedGenerationSetDigest: preparedCatalogOperation.generationSetDigest,
1765
+ scriptTimeoutMs: reviewedScriptTimeoutMs(intent), inventoryCatalogSourceReferences: operationInventory },
1766
+ }, reviewedEvidence?.config, freshCatalog) : {};
1637
1767
  const preApplyAuthorization = configIntentRequestsApply(intent)
1638
- ? (await resolveConfigPreApplyAuthorization({
1768
+ ? planAuthorization ?? (await resolveConfigPreApplyAuthorization({
1639
1769
  plugin,
1640
1770
  scope: 'user', context: intent.context ?? 'user', platform: intent.platform,
1641
1771
  cwd: context.cwd,
@@ -1650,15 +1780,6 @@ export function createTuiControllerDependencies(context, progressFeed, options =
1650
1780
  },
1651
1781
  })).targets
1652
1782
  : [];
1653
- const commandReview = configIntentRequestsApply(intent) ? await reviewConfigMutationApply({
1654
- plugin, scope: 'user', context: intent.context ?? 'user', platform: intent.platform,
1655
- cwd: context.cwd, env: context.env, cliVersion: packageInfo.version, nativeCliRunner: context.nativeCliRunner,
1656
- applyTargets: affectedTargets, applyCommandPackages: commandPackages.map(({ packageId }) => packageId),
1657
- mutation: { kind: 'patch', updates: intent.updates, removeKeys: intent.removeKeys },
1658
- rebuildRuntime: { ...context, signal, referencePlugins, catalogOperationContext: preparedCatalogOperation,
1659
- expectedGenerationSetDigest: preparedCatalogOperation.generationSetDigest,
1660
- scriptTimeoutMs: reviewedScriptTimeoutMs(intent), inventoryCatalogSourceReferences: operationInventory },
1661
- }, reviewedEvidence?.config, freshCatalog) : {};
1662
1783
  return {
1663
1784
  pluginName: plugin.manifest.name,
1664
1785
  source: sourceEvidenceForPlugin(source, plugin.manifest.name),
@@ -1694,8 +1815,7 @@ export function createTuiControllerDependencies(context, progressFeed, options =
1694
1815
  ...(selected.impact?.noEffectiveChange ? { noEffectiveChange: true } : {}),
1695
1816
  ...(selected.commandPackages.length ? { commandPackages: selected.commandPackages } : {}),
1696
1817
  ...selected.commandReview,
1697
- affectedTargets: (selected.impact?.affectedTargets
1698
- ?? relevantTargets).map(({ pluginName, platform, scope }) => ({ pluginName, platform, scope })),
1818
+ affectedTargets: configEvidenceTargets(selected.impact, relevantTargets),
1699
1819
  ...(selected.preApplyAuthorization.length > 0
1700
1820
  ? { preApplyAuthorization: selected.preApplyAuthorization }
1701
1821
  : {}),
@@ -1766,7 +1886,7 @@ export function createTuiControllerDependencies(context, progressFeed, options =
1766
1886
  scope: 'user', context: intent.context ?? 'user', platform: intent.platform,
1767
1887
  cwd: context.cwd,
1768
1888
  env: context.env,
1769
- visibleTargets: configImpactVisibleTargets(plugin.manifest.name, configVisibleTargets),
1889
+ ...splitConfigTargets(configVisibleTargets),
1770
1890
  mutation: {
1771
1891
  kind: 'patch',
1772
1892
  updates: intent.updates,
@@ -1775,23 +1895,33 @@ export function createTuiControllerDependencies(context, progressFeed, options =
1775
1895
  })
1776
1896
  : undefined;
1777
1897
  const affectedTargets = intent.kind === 'configSave'
1778
- ? intent.retryApply ? configImpactVisibleTargets(plugin.manifest.name, configVisibleTargets) : impact.affectedTargets
1898
+ ? intent.retryApply ? splitConfigTargets(configVisibleTargets).visibleTargets : impact.affectedTargets
1779
1899
  : [];
1780
1900
  const commandPackages = impact?.affectedCommandPackages
1781
1901
  ?? (intent.kind === 'configSave' ? (await discoverPluginConfigManagedCommandPackages({
1782
1902
  plugin, scope: intent.context ?? 'user', cwd: context.cwd, env: context.env ?? process.env,
1783
- platformTargets: configImpactVisibleTargets(plugin.manifest.name, configVisibleTargets),
1903
+ platformTargets: splitConfigTargets(configVisibleTargets).visibleTargets,
1784
1904
  referencePlugins,
1785
1905
  })).packages : []);
1906
+ const { preApplyAuthorization: planAuthorization, ...commandReview } = intent.kind === 'configSave' && configIntentRequestsApply(intent) ? await reviewConfigMutationApply({
1907
+ plugin, scope: 'user', context: intent.context ?? 'user', platform: intent.platform,
1908
+ cwd: context.cwd, env: context.env, cliVersion: packageInfo.version, nativeCliRunner: context.nativeCliRunner,
1909
+ applyTargets: affectedTargets, applyGenericTargets: impact?.affectedGenericTargets,
1910
+ applyCommandPackages: commandPackages.map(({ packageId }) => packageId),
1911
+ mutation: { kind: 'patch', updates: intent.updates, removeKeys: intent.removeKeys },
1912
+ rebuildRuntime: { ...context, signal, referencePlugins, catalogOperationContext: catalogOperation,
1913
+ expectedGenerationSetDigest: catalogOperation?.generationSetDigest,
1914
+ scriptTimeoutMs: reviewedScriptTimeoutMs(intent), inventoryCatalogSourceReferences: operationInventory },
1915
+ }, reviewedEvidence?.config, freshCatalog) : {};
1786
1916
  const preApplyAuthorization = intent.kind === 'configSave'
1787
1917
  && configIntentRequestsApply(intent)
1788
- ? (await resolveConfigPreApplyAuthorization({
1918
+ ? planAuthorization ?? (await resolveConfigPreApplyAuthorization({
1789
1919
  plugin,
1790
1920
  scope: 'user', context: intent.context ?? 'user', platform: intent.platform,
1791
1921
  cwd: context.cwd,
1792
1922
  env: context.env,
1793
1923
  applyTargets: intent.retryApply
1794
- ? configImpactVisibleTargets(plugin.manifest.name, configVisibleTargets)
1924
+ ? splitConfigTargets(configVisibleTargets).visibleTargets
1795
1925
  : impact.affectedTargets,
1796
1926
  nativeCliRunner: context.nativeCliRunner,
1797
1927
  rebuildRuntime: {
@@ -1804,15 +1934,6 @@ export function createTuiControllerDependencies(context, progressFeed, options =
1804
1934
  },
1805
1935
  })).targets
1806
1936
  : [];
1807
- const commandReview = intent.kind === 'configSave' && configIntentRequestsApply(intent) ? await reviewConfigMutationApply({
1808
- plugin, scope: 'user', context: intent.context ?? 'user', platform: intent.platform,
1809
- cwd: context.cwd, env: context.env, cliVersion: packageInfo.version, nativeCliRunner: context.nativeCliRunner,
1810
- applyTargets: affectedTargets, applyCommandPackages: commandPackages.map(({ packageId }) => packageId),
1811
- mutation: { kind: 'patch', updates: intent.updates, removeKeys: intent.removeKeys },
1812
- rebuildRuntime: { ...context, signal, referencePlugins, catalogOperationContext: catalogOperation,
1813
- expectedGenerationSetDigest: catalogOperation?.generationSetDigest,
1814
- scriptTimeoutMs: reviewedScriptTimeoutMs(intent), inventoryCatalogSourceReferences: operationInventory },
1815
- }, reviewedEvidence?.config, freshCatalog) : {};
1816
1937
  return {
1817
1938
  pluginName: plugin.manifest.name,
1818
1939
  source: sourceEvidenceForPlugin(source, plugin.manifest.name),
@@ -1826,7 +1947,7 @@ export function createTuiControllerDependencies(context, progressFeed, options =
1826
1947
  commandPackages, preApplyAuthorization, cwd: context.cwd, env: context.env, plugins: referencePlugins }) : undefined,
1827
1948
  sharedNativeRenderUnits: intent.kind === 'configSave'
1828
1949
  ? intent.retryApply
1829
- ? await configRetrySharedNativeRenderUnits(plugin, configImpactVisibleTargets(plugin.manifest.name, configVisibleTargets), context.env, referencePlugins)
1950
+ ? await configRetrySharedNativeRenderUnits(plugin, splitConfigTargets(configVisibleTargets).visibleTargets, context.env, referencePlugins)
1830
1951
  : impact.sharedNativeRenderUnits
1831
1952
  : [],
1832
1953
  };
@@ -1861,8 +1982,7 @@ export function createTuiControllerDependencies(context, progressFeed, options =
1861
1982
  ...('commandPackages' in selected && selected.commandPackages.length
1862
1983
  ? { commandPackages: selected.commandPackages } : {}),
1863
1984
  ...('commandReview' in selected ? selected.commandReview : {}),
1864
- affectedTargets: (impact?.affectedTargets
1865
- ?? evidenceTargets).map(({ pluginName, platform, scope }) => ({ pluginName, platform, scope })),
1985
+ affectedTargets: configEvidenceTargets(impact, evidenceTargets),
1866
1986
  ...('sharedNativeRenderUnits' in selected
1867
1987
  && selected.sharedNativeRenderUnits.length > 0
1868
1988
  ? { sharedNativeRenderUnits: selected.sharedNativeRenderUnits }
@@ -1874,6 +1994,10 @@ export function createTuiControllerDependencies(context, progressFeed, options =
1874
1994
  };
1875
1995
  }
1876
1996
  await assertConfigEditEvidence(intent, evidence);
1997
+ if (intent.kind === 'configSave' && status.coverage.native && status.coverage.portable
1998
+ && status.coverage.requestComplete !== false && status.inventory !== null && status.errors.length === 0) {
1999
+ completeConfigImpact.add(evidence);
2000
+ }
1877
2001
  if (catalogOperation)
1878
2002
  catalogOperationByEvidence.set(evidence, catalogOperation);
1879
2003
  return evidence;
@@ -1881,8 +2005,12 @@ export function createTuiControllerDependencies(context, progressFeed, options =
1881
2005
  const dependencies = {
1882
2006
  readAgentSettings: () => readAgentSettings(context),
1883
2007
  previewAgentSettings: (preferences, pluginId) => previewAgentSettings(context, preferences, pluginId),
1884
- saveAgentSettings: (request) => saveAgentSettings(context, request),
2008
+ saveAgentSettings: (request) => {
2009
+ savedProfileImpacts.clear();
2010
+ return saveAgentSettings(context, request);
2011
+ },
1885
2012
  beginCatalogSession(sessionOptions) {
2013
+ savedProfileImpacts.clear();
1886
2014
  latestStatusRead += 1;
1887
2015
  bindNewCatalog = true;
1888
2016
  validatedStoreEntries = sessionOptions?.reuseValidatedGenerations === true
@@ -1980,6 +2108,7 @@ export function createTuiControllerDependencies(context, progressFeed, options =
1980
2108
  return { kind: 'recovery', scope: request.scope, plan };
1981
2109
  },
1982
2110
  async executeScopedTask(plan) {
2111
+ savedProfileImpacts.clear();
1983
2112
  if (plan.kind === 'targets') {
1984
2113
  const result = await executeTargetsPlan({ scope: plan.scope, cwd: context.cwd, env: context.env }, plan);
1985
2114
  return { kind: 'targets', ...result };
@@ -2020,7 +2149,7 @@ export function createTuiControllerDependencies(context, progressFeed, options =
2020
2149
  signal,
2021
2150
  fullValidation: freshnessOptions.fullValidation,
2022
2151
  runtime: {
2023
- ...options.catalogGenerationRuntime,
2152
+ ...catalogGenerationRuntime,
2024
2153
  ...storeEntries,
2025
2154
  },
2026
2155
  });
@@ -2418,6 +2547,8 @@ export function createTuiControllerDependencies(context, progressFeed, options =
2418
2547
  };
2419
2548
  },
2420
2549
  async executeIntent(intent, expectedEvidence, signal) {
2550
+ if (intent.kind !== 'configSaveBatch' && intent.kind !== 'configSave')
2551
+ savedProfileImpacts.clear();
2421
2552
  if (intent.kind === 'pluginWrite' || intent.kind === 'pluginWriteBatch'
2422
2553
  || intent.kind === 'pluginWriteTask') {
2423
2554
  throw new TuiOperationBlockedError('useScopedRecovery', '请使用统一范围恢复任务。');
@@ -2486,7 +2617,7 @@ export function createTuiControllerDependencies(context, progressFeed, options =
2486
2617
  expectedCandidate: expected.candidate,
2487
2618
  env: context.env,
2488
2619
  signal,
2489
- runtime: options.catalogGenerationRuntime,
2620
+ runtime: catalogGenerationRuntime,
2490
2621
  });
2491
2622
  }
2492
2623
  else if (intent.action === 'repair') {
@@ -2500,7 +2631,7 @@ export function createTuiControllerDependencies(context, progressFeed, options =
2500
2631
  env: context.env,
2501
2632
  signal,
2502
2633
  runtime: {
2503
- ...options.catalogGenerationRuntime,
2634
+ ...catalogGenerationRuntime,
2504
2635
  afterCandidateResolved: tuiControllerRuntimeTestHooks
2505
2636
  ?.afterCatalogGenerationCandidateResolved,
2506
2637
  },
@@ -2515,7 +2646,7 @@ export function createTuiControllerDependencies(context, progressFeed, options =
2515
2646
  expectedConfigDigest: expected.proposedConfigDigest ?? expected.configDigest,
2516
2647
  env: context.env,
2517
2648
  signal,
2518
- runtime: options.catalogGenerationRuntime,
2649
+ runtime: catalogGenerationRuntime,
2519
2650
  });
2520
2651
  }
2521
2652
  else if (intent.action === 'replaceDamaged') {
@@ -2531,7 +2662,7 @@ export function createTuiControllerDependencies(context, progressFeed, options =
2531
2662
  env: context.env,
2532
2663
  signal,
2533
2664
  runtime: {
2534
- ...options.catalogGenerationRuntime,
2665
+ ...catalogGenerationRuntime,
2535
2666
  afterCandidateResolved: tuiControllerRuntimeTestHooks
2536
2667
  ?.afterCatalogGenerationCandidateResolved,
2537
2668
  },
@@ -2552,7 +2683,7 @@ export function createTuiControllerDependencies(context, progressFeed, options =
2552
2683
  env: context.env,
2553
2684
  signal,
2554
2685
  runtime: {
2555
- ...options.catalogGenerationRuntime,
2686
+ ...catalogGenerationRuntime,
2556
2687
  afterCandidateResolved: tuiControllerRuntimeTestHooks
2557
2688
  ?.afterCatalogGenerationCandidateResolved,
2558
2689
  },
@@ -2724,6 +2855,8 @@ export function createTuiControllerDependencies(context, progressFeed, options =
2724
2855
  }
2725
2856
  await tuiControllerRuntimeTestHooks?.afterMutationEvidenceCapture?.();
2726
2857
  if (intent.kind === 'configSaveBatch') {
2858
+ if (intent.apply)
2859
+ savedProfileImpacts.clear();
2727
2860
  assertConfigSaveBatchIntent(intent);
2728
2861
  const reviewedBatch = expectedEvidence.configBatch;
2729
2862
  if (!reviewedBatch || !currentEvidence.configBatch || !currentEvidence.source) {
@@ -2799,7 +2932,9 @@ export function createTuiControllerDependencies(context, progressFeed, options =
2799
2932
  scope: target.scope,
2800
2933
  }))
2801
2934
  : [];
2802
- return applyPluginConfigWrite({
2935
+ const beforeDigest = !intent.apply ? await savedStoreDigest(groupIntent, freshSource) : undefined;
2936
+ const selectionDigest = beforeDigest ? await savedSelectionDigest(groupIntent, plugin, referencePlugins) : undefined;
2937
+ const write = await applyPluginConfigWrite({
2803
2938
  plugin,
2804
2939
  pluginName: plugin.manifest.name,
2805
2940
  scope: 'user', platform: group.platform, context: intent.context ?? 'user',
@@ -2831,6 +2966,8 @@ export function createTuiControllerDependencies(context, progressFeed, options =
2831
2966
  preApplyConfirmed: true,
2832
2967
  preApplyAuthorizedTargets: approvedPreApplyTargets,
2833
2968
  });
2969
+ await recordSavedImpact(groupIntent, freshEvidence, beforeDigest, selectionDigest, write);
2970
+ return write;
2834
2971
  },
2835
2972
  });
2836
2973
  configSaved = result.configWrite === 'succeeded';
@@ -2948,9 +3085,12 @@ export function createTuiControllerDependencies(context, progressFeed, options =
2948
3085
  scope: target.scope,
2949
3086
  })) ?? []
2950
3087
  : [];
3088
+ const beforeDigest = !intent.retryApply && !intent.apply ? await savedStoreDigest(intent, currentSource) : undefined;
3089
+ const selectionDigest = beforeDigest ? await savedSelectionDigest(intent, plugin, referencePlugins) : undefined;
2951
3090
  const result = intent.retryApply
2952
3091
  ? await applyPluginConfig({
2953
3092
  plugin,
3093
+ ...currentEvidence.config?.savedApplySelection,
2954
3094
  scope: 'user', platform: intent.platform, context: intent.context ?? 'user',
2955
3095
  ...(intent.targets ? { targets: intent.targets } : {}),
2956
3096
  cliVersion: packageInfo.version,
@@ -3008,6 +3148,10 @@ export function createTuiControllerDependencies(context, progressFeed, options =
3008
3148
  preApplyConfirmed: true,
3009
3149
  preApplyAuthorizedTargets: expectedEvidence.config?.preApplyAuthorization ?? [],
3010
3150
  });
3151
+ if (intent.retryApply || intent.apply)
3152
+ savedProfileImpacts.delete(savedImpactKey(intent));
3153
+ else
3154
+ await recordSavedImpact(intent, currentEvidence, beforeDigest, selectionDigest, result);
3011
3155
  return { ...result, operationRebuildResults };
3012
3156
  },
3013
3157
  }).catch((error) => {