@lesliechan721/aw 0.1.0-beta.72 → 0.1.0-beta.73

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.
@@ -18,6 +18,7 @@ import { readJointDemand, deriveJointDemand, findPlacementConflicts, targetsConf
18
18
  import { prepareScopedRecovery, executeScopedRecovery, executeRecoveryPreApply, describeRecoveryPlan } from './coordinator.js';
19
19
  import { readScopedRecoveryStatus, readRecoveryStatus } from './status.js';
20
20
  import { measureRecoveryPerformanceStage, recordRecoveryPerformanceStage } from './performance.js';
21
+ import { resolvePluginMetaDependencyClosure } from '../utils/plugin-dependencies.js';
21
22
  const diagnostic = (code, message = code) => ({ code, message });
22
23
  function intentReceipt(observation) {
23
24
  return { state: observation.state,
@@ -110,13 +111,18 @@ export async function prepareJointRecovery(command, selectors, options, runtime)
110
111
  }
111
112
  }
112
113
  async function prepareJointRecoveryInSession(command, selectors, options, runtime, snapshot) {
114
+ // Status observes saved requirements, before projecting proposed declarations.
115
+ // Reuse them only within this preparation; execution reads them again under the lock.
116
+ const savedDemand = snapshot;
117
+ let observedStatus;
113
118
  const evidence = snapshotEvidence(snapshot);
114
119
  const scope = options.scope ?? snapshot.context.context;
115
120
  const observedIntent = (scope === 'project' ? snapshot.project : snapshot.user).intent;
116
121
  if (options.existingOnly) {
117
122
  // Existing owned deployments can be refreshed without converting them into declarations.
118
- const observed = await readRecoveryStatus({ ...options, nativeCliRunner: runtime.nativeCliRunner, codexObservationSession: runtime.codexObservationSession });
119
- const installed = (observed.existingTargets ?? []).filter((item) => selectors.some((selector) => selector === item.pluginId
123
+ observedStatus = await readRecoveryStatus({ ...options, nativeCliRunner: runtime.nativeCliRunner,
124
+ codexObservationSession: runtime.codexObservationSession }, savedDemand);
125
+ const installed = (observedStatus.existingTargets ?? []).filter((item) => selectors.some((selector) => selector === item.pluginId
120
126
  || !selector.includes('/') && parsePluginId(item.pluginId).pluginName === selector)
121
127
  && (!options.targets || options.targets.includes(item.agent)));
122
128
  if (installed.length) {
@@ -144,6 +150,22 @@ async function prepareJointRecoveryInSession(command, selectors, options, runtim
144
150
  }
145
151
  }
146
152
  const previousDemand = deriveJointDemand(snapshot);
153
+ const previousPlugins = [...new Map([...(snapshot.user.plugins), ...(snapshot.project?.plugins ?? [])]
154
+ .map((plugin) => [plugin.pluginId, plugin])).values()];
155
+ const dependencyClosures = new Map();
156
+ const dependencies = (pluginId) => {
157
+ if (!dependencyClosures.has(pluginId)) {
158
+ try {
159
+ const parsed = parsePluginId(pluginId);
160
+ const closure = resolvePluginMetaDependencyClosure(previousPlugins.filter((plugin) => plugin.sourceId === parsed.sourceId), [parsed.pluginName]);
161
+ dependencyClosures.set(pluginId, closure.filter((plugin) => plugin.pluginId !== pluginId).map((plugin) => plugin.pluginId));
162
+ }
163
+ catch {
164
+ dependencyClosures.set(pluginId, null);
165
+ }
166
+ }
167
+ return dependencyClosures.get(pluginId);
168
+ };
147
169
  const original = scope === 'project' ? snapshot.project : snapshot.user;
148
170
  const errors = [];
149
171
  let declaration;
@@ -164,9 +186,17 @@ async function prepareJointRecoveryInSession(command, selectors, options, runtim
164
186
  }
165
187
  }
166
188
  else if (command === 'uninstall') {
189
+ const selectable = [...new Set([...(original.roots ?? []).map((root) => root.pluginId),
190
+ ...previousDemand.placements.filter((placement) => placement.scope === scope).map((placement) => placement.pluginId)])];
191
+ requested = selectors.flatMap((selector) => {
192
+ const parsed = parsePluginId(selector);
193
+ const matches = selectable.filter((id) => parsed.sourceId ? id === selector : parsePluginId(id).pluginName === parsed.pluginName);
194
+ if (matches.length !== 1)
195
+ errors.push(diagnostic('pluginIntentRootMissing'));
196
+ return matches.length === 1 ? matches : [selector];
197
+ });
167
198
  try {
168
- const sourceIds = new Set((original.roots ?? []).filter((root) => selectors.some((selector) => selector === root.pluginId
169
- || !selector.includes('/') && parsePluginId(root.pluginId).pluginName === selector)).map((root) => root.sourceId));
199
+ const sourceIds = new Set(requested.map((id) => parsePluginId(id).sourceId));
170
200
  for (const sourceId of sourceIds) {
171
201
  const source = original.catalogOperationContext?.catalog.sources.find((entry) => entry.sourceId === sourceId)?.resolution;
172
202
  if (!source)
@@ -184,19 +214,13 @@ async function prepareJointRecoveryInSession(command, selectors, options, runtim
184
214
  errors.push(diagnostic('pluginIntentStateInvalid'));
185
215
  else {
186
216
  let value = original.intent.state === 'valid' ? original.intent.value : createEmptyIntent();
187
- for (const selector of selectors) {
188
- const parsed = parsePluginId(selector);
189
- const matches = value.roots.filter((root) => parsed.sourceId ? root.pluginId === selector
190
- : parsePluginId(root.pluginId).pluginName === parsed.pluginName);
191
- if (matches.length !== 1) {
192
- errors.push(diagnostic('pluginIntentRootMissing'));
193
- continue;
194
- }
195
- requested[requested.indexOf(selector)] = matches[0].pluginId;
196
- value = removeIntentRoot(value, matches[0].pluginId);
217
+ for (const pluginId of requested) {
218
+ if (value.roots.some((root) => root.pluginId === pluginId))
219
+ value = removeIntentRoot(value, pluginId);
197
220
  }
198
221
  if (!errors.length) {
199
- declaration = { scope, value };
222
+ if (original.intent.state === 'valid' && calculateIntentDigest(value) !== original.intent.digest)
223
+ declaration = { scope, value };
200
224
  const demand = await readDemand({ ...options, preferences: undefined, scope, intent: asObservation(value) });
201
225
  snapshot = { ...snapshot, [scope]: demand };
202
226
  }
@@ -209,16 +233,30 @@ async function prepareJointRecoveryInSession(command, selectors, options, runtim
209
233
  if (command !== 'install' && command !== 'uninstall') {
210
234
  requested = selectors.length ? selectors.flatMap((selector) => {
211
235
  const parsed = parsePluginId(selector);
212
- const matches = (options.existingOnly ? [...new Set([...rootIds, ...demand.placements.map((item) => item.pluginId)])] : rootIds).filter((id) => parsed.sourceId ? id === selector : parsePluginId(id).pluginName === parsed.pluginName);
236
+ const matches = (options.existingOnly || options.allowDependencySelectors ? [...new Set([...rootIds, ...demand.placements.map((item) => item.pluginId)])] : rootIds).filter((id) => parsed.sourceId ? id === selector : parsePluginId(id).pluginName === parsed.pluginName);
213
237
  if (matches.length !== 1 && !options.existingOnly)
214
238
  errors.push(diagnostic('syncPluginNotDesired', `${selector} 未声明或名称不唯一。`));
215
239
  return matches.length === 1 ? matches : [];
216
240
  }) : rootIds;
217
241
  }
218
242
  const targets = options.targets ? normalizeAgents(options.targets) : snapshot.preferences?.targets ?? [];
219
- if (options.exactTargets && (!options.exactTargets.length && !options.existingOnly || options.exactTargets.some((exact) => !targets.includes(exact.agent) || !demand.roots.some((root) => root.pluginId === exact.pluginId
243
+ const explicitlyRemoves = (item) => item.scope === scope && requested.includes(item.pluginId) && (!options.exactTargets
244
+ || options.exactTargets.some((exact) => exact.pluginId === item.pluginId && exact.agent === item.agent
245
+ && (!exact.scope || exact.scope === item.scope)));
246
+ if (command === 'uninstall' && !options.force) {
247
+ for (const pluginId of requested) {
248
+ const consumers = demand.placements.filter((placement) => placement.pluginId === pluginId
249
+ && explicitlyRemoves({ pluginId, agent: placement.target, scope }))
250
+ .flatMap((placement) => placement.contributions.filter((item) => item.path.length > 1
251
+ && (placement.scope === scope || item.scope === scope)).map((item) => item.root));
252
+ if (consumers.length)
253
+ errors.push(diagnostic('dependencyStillRequired', `${pluginId} 仍被 ${[...new Set(consumers)].join('、')} 依赖。使用 --force 可强制移除所选输出。`));
254
+ }
255
+ }
256
+ const selectionDemand = command === 'uninstall' ? previousDemand : demand;
257
+ if (options.exactTargets && (!options.exactTargets.length && !options.existingOnly || options.exactTargets.some((exact) => !targets.includes(exact.agent) || !selectionDemand.roots.some((root) => root.pluginId === exact.pluginId
220
258
  && requested.includes(root.pluginId) && root.target === exact.agent && (!exact.scope || root.scope === exact.scope))
221
- && !demand.placements.some((placement) => placement.pluginId === exact.pluginId && placement.target === exact.agent
259
+ && !selectionDemand.placements.some((placement) => placement.pluginId === exact.pluginId && placement.target === exact.agent
222
260
  && (!exact.scope || placement.scope === exact.scope || placement.contributions.some((item) => item.scope === exact.scope))
223
261
  && (requested.includes(placement.pluginId) || placement.contributions.some((item) => requested.includes(item.root))))))) {
224
262
  errors.push(diagnostic('invalidExactTargets', '精确重试目标不属于当前请求,请重新检查并选择。'));
@@ -226,11 +264,16 @@ async function prepareJointRecoveryInSession(command, selectors, options, runtim
226
264
  const selected = demand.placements.filter((placement) => targets.includes(placement.target)
227
265
  && !demand.conflicts.some((conflict) => [conflict.left, conflict.right].some((position) => position.target === placement.target && position.scope === placement.scope))
228
266
  && (!options.exactTargets || options.exactTargets.some((exact) => exact.agent === placement.target
229
- && (!exact.scope || placement.contributions.some((item) => item.scope === exact.scope))
230
- && (exact.pluginId === placement.pluginId || placement.contributions.some((item) => item.path.includes(exact.pluginId)))))
231
- && (command === 'uninstall' ? requested.includes(placement.pluginId)
232
- || previousDemand.placements.some((previous) => previous.pluginId === placement.pluginId && previous.target === placement.target && previous.scope !== placement.scope)
233
- : placement.contributions.some((item) => requested.includes(item.root)) || options.existingOnly && requested.includes(placement.pluginId)));
267
+ && (command === 'uninstall' ? previousDemand.placements.some((previous) => previous.pluginId === placement.pluginId
268
+ && previous.target === placement.target && previous.contributions.some((item) => item.path.includes(exact.pluginId)
269
+ && (!exact.scope || item.scope === exact.scope)))
270
+ : (!exact.scope || placement.contributions.some((item) => item.scope === exact.scope))
271
+ && (exact.pluginId === placement.pluginId || placement.contributions.some((item) => item.path.includes(exact.pluginId))))))
272
+ && (command === 'uninstall' ? !(options.force && requested.includes(placement.pluginId))
273
+ && previousDemand.placements.some((previous) => previous.pluginId === placement.pluginId && previous.target === placement.target
274
+ && previous.scope !== placement.scope && previous.contributions.some((item) => item.scope === scope && requested.includes(item.root)))
275
+ : placement.contributions.some((item) => requested.includes(item.root)
276
+ || options.allowDependencySelectors && item.path.some((id) => requested.includes(id))) || options.existingOnly && requested.includes(placement.pluginId)));
234
277
  const activationOnlyTargets = [];
235
278
  if (snapshot.project && !errors.length) {
236
279
  const sharedNative = selected.filter((item) => item.scope === 'user' && (item.target === 'codex' || item.target === 'claude')
@@ -283,14 +326,14 @@ async function prepareJointRecoveryInSession(command, selectors, options, runtim
283
326
  };
284
327
  const children = [];
285
328
  const { signal: _signal, ...executionOptions } = options;
286
- const joint = { snapshot, demand, children, originalOptions: executionOptions,
329
+ const joint = { snapshot, demand, removalDependencies: dependencyClosures, children, originalOptions: executionOptions,
287
330
  selectors: [...selectors], declaration, evidence };
288
331
  const plan = { command, options: { ...executionOptions, scope }, receipt, context, demand: baseDemand,
289
332
  originalIntent: observationEvidence(original.intent), preferencesEvidence: observationEvidence(snapshot.user.preferences),
290
333
  plannedImpact: { declaration: Boolean(declaration), preferences: false, config: false, outputs: false },
291
334
  changes: declaration ? [`保存 ${scope} 插件需求。`] : [], warnings: [], nativeGroups: [],
292
335
  historicalNativeTargets: new Set(), deliverySwitchChecks: [], portableGroups: [], portableProtectionGroups: [],
293
- portableResidues: [], sourceRefreshes: [], sourceRefreshFailures: [], runtime, blockExecution: errors.some((error) => ['syncPluginNotDesired', 'pluginIntentRootMissing', 'pluginIntentStateInvalid', 'catalogSnapshotInvalid', 'installTargetSelectionUnsupported', 'invalidExactTargets'].includes(error.code)
336
+ portableResidues: [], sourceRefreshes: [], sourceRefreshFailures: [], runtime, blockExecution: errors.some((error) => ['syncPluginNotDesired', 'pluginIntentRootMissing', 'pluginIntentStateInvalid', 'catalogSnapshotInvalid', 'installTargetSelectionUnsupported', 'invalidExactTargets', 'dependencyStillRequired'].includes(error.code)
294
337
  || error.code === 'targetsNotConfigured' && !options.retireUnselectedTargets)
295
338
  || !snapshot.preferences || snapshot.user.roots === null || snapshot.project?.roots === null, joint };
296
339
  const dispose = context.dispose;
@@ -298,8 +341,62 @@ async function prepareJointRecoveryInSession(command, selectors, options, runtim
298
341
  if (plan.blockExecution)
299
342
  return plan;
300
343
  try {
301
- const currentStatus = await readRecoveryStatus({ ...options, nativeCliRunner: runtime.nativeCliRunner,
302
- codexObservationSession: runtime.codexObservationSession, targets: undefined });
344
+ const currentStatus = observedStatus ?? await readRecoveryStatus({ ...options, nativeCliRunner: runtime.nativeCliRunner,
345
+ codexObservationSession: runtime.codexObservationSession, targets: undefined }, savedDemand);
346
+ const ownsOutput = (item) => currentStatus.ownedTargets?.some((owned) => owned.pluginId === item.pluginId
347
+ && owned.agent === item.agent && owned.scope === item.scope) === true;
348
+ const liveConsumers = currentStatus.existingTargets ?? [];
349
+ const sameProvider = (consumer, provider) => consumer.agent === provider.agent && (provider.scope === 'user' || consumer.scope === provider.scope);
350
+ const automaticRetirements = command === 'uninstall' && !options.keepDependencies && demand.complete
351
+ ? previousDemand.placements.filter((placement) => placement.scope === scope && targets.includes(placement.target)
352
+ && (placement.target === 'codex' || placement.target === 'claude' ? currentStatus.coverage.native : currentStatus.coverage.portable)
353
+ && !requested.includes(placement.pluginId) && !rootIds.includes(placement.pluginId)
354
+ && placement.contributions.some((item) => explicitlyRemoves({ pluginId: item.root, agent: placement.target, scope: item.scope }))
355
+ && !demand.placements.some((item) => item.pluginId === placement.pluginId && item.target === placement.target)
356
+ && ownsOutput({ pluginId: placement.pluginId, agent: placement.target, scope: placement.scope })) : [];
357
+ // A live consumer can outlast its Intent or its Active catalog entry.
358
+ const retainedConsumerFor = (provider) => liveConsumers.find((consumer) => {
359
+ if (explicitlyRemoves(consumer) && ownsOutput(consumer) || automaticRetirements.some((item) => item.pluginId === consumer.pluginId && item.target === consumer.agent && item.scope === consumer.scope))
360
+ return false;
361
+ if (!sameProvider(consumer, provider))
362
+ return false;
363
+ const closure = dependencies(consumer.pluginId);
364
+ if (!closure?.includes(provider.pluginId) && !(closure === null
365
+ && parsePluginId(consumer.pluginId).sourceId === parsePluginId(provider.pluginId).sourceId))
366
+ return false;
367
+ return !demand.placements.some((item) => item.pluginId === provider.pluginId && item.target === provider.agent
368
+ && item.scope !== provider.scope && sameProvider(consumer, { agent: item.target, scope: item.scope }));
369
+ });
370
+ for (let index = automaticRetirements.length - 1; index >= 0; index--) {
371
+ const candidate = automaticRetirements[index];
372
+ if (retainedConsumerFor({ pluginId: candidate.pluginId, agent: candidate.target, scope: candidate.scope })) {
373
+ automaticRetirements.splice(index, 1);
374
+ }
375
+ }
376
+ if (command === 'uninstall' && !options.force) {
377
+ for (const pluginId of requested)
378
+ for (const agent of new Set(liveConsumers.map((consumer) => consumer.agent))) {
379
+ const provider = { pluginId, agent, scope };
380
+ const consumer = explicitlyRemoves(provider) ? retainedConsumerFor(provider) : undefined;
381
+ if (consumer)
382
+ errors.push(diagnostic('dependencyStillRequired', `${pluginId} 的移除无法保留 ${consumer.pluginId} 的现有依赖。`));
383
+ }
384
+ if (errors.some((error) => error.code === 'dependencyStillRequired')) {
385
+ plan.blockExecution = true;
386
+ return plan;
387
+ }
388
+ }
389
+ if (command === 'uninstall')
390
+ for (const replacement of selected) {
391
+ const old = currentStatus.ownedTargets?.find((item) => item.pluginId === replacement.pluginId
392
+ && item.agent === replacement.target && item.scope !== replacement.scope && retainedConsumerFor(item));
393
+ if (!old)
394
+ continue;
395
+ errors.push(diagnostic('dependencyStillRequired', `${old.pluginId} 的提供位置切换会破坏现存消费者的依赖。`));
396
+ plan.blockExecution = true;
397
+ return plan;
398
+ }
399
+ plan.dependencyCleanupTargets = automaticRetirements.map((item) => ({ pluginId: item.pluginId, agent: item.target, scope: item.scope }));
303
400
  // Native platforms share one complete marketplace candidate per scope.
304
401
  const nativeTargets = targets.filter((target) => target === 'codex' || target === 'claude');
305
402
  const targetGroups = [...(nativeTargets.length ? [nativeTargets] : []),
@@ -368,10 +465,7 @@ async function prepareJointRecoveryInSession(command, selectors, options, runtim
368
465
  }
369
466
  plan.receipt.blockers.push(conflict);
370
467
  }
371
- // Only explicit target exits, selected removals and provider switches retire outputs.
372
- // Unrelated indirect dependencies remain visible residue.
373
- const ownsOutput = (item) => currentStatus.ownedTargets?.some((owned) => owned.pluginId === item.pluginId
374
- && owned.agent === item.agent && owned.scope === item.scope) === true;
468
+ // Retire this removal's orphaned dependencies, explicit exits and provider switches.
375
469
  const requiredNativeActivation = (item) => {
376
470
  const backend = item.backend;
377
471
  const scopedExtensions = (backend?.live?.components ?? backend?.components ?? []).some((component) => component.kind === 'ownership' && component.key !== 'native'
@@ -404,7 +498,7 @@ async function prepareJointRecoveryInSession(command, selectors, options, runtim
404
498
  }
405
499
  const retire = currentStatus.extraObserved.filter((item) => item.agent !== null && !requiredNativeActivation(item) && (options.retireUnselectedTargets && (!snapshot.preferences.targets.includes(item.agent)
406
500
  || snapshot.preferences.exclusions.some((entry) => entry.plugin === item.pluginId && entry.target === item.agent))
407
- || command === 'uninstall' && requested.includes(item.pluginId)
501
+ || command === 'uninstall' && explicitlyRemoves(item)
408
502
  || selected.some((placement) => placement.pluginId === item.pluginId && placement.target === item.agent && placement.scope !== item.scope
409
503
  && (item.delivery?.kind !== 'agent-skills' || item.backend?.logicalIdentity === placement.plugin.catalogLogicalIdentity))));
410
504
  for (const item of currentStatus.observedTargets ?? []) {
@@ -416,9 +510,16 @@ async function prepareJointRecoveryInSession(command, selectors, options, runtim
416
510
  }
417
511
  // A removed declaration is still present in the observed snapshot, so include its exact old outputs.
418
512
  if (command === 'uninstall')
419
- for (const item of currentStatus.inventory?.flatMap((entry) => entry.targetResults) ?? []) {
420
- if (!requested.includes(item.pluginId) || item.scope !== scope || !ownsOutput(item)
421
- || demand.placements.some((placement) => placement.pluginId === item.pluginId && placement.target === item.agent && placement.scope === item.scope))
513
+ for (const item of [
514
+ ...(currentStatus.observedTargets ?? []), ...currentStatus.extraObserved,
515
+ ]) {
516
+ const automatic = automaticRetirements.some((candidate) => candidate.pluginId === item.pluginId
517
+ && candidate.target === item.agent && candidate.scope === item.scope);
518
+ if (!automatic && !explicitlyRemoves(item)
519
+ || !ownsOutput(item) || !targets.includes(item.agent)
520
+ || !options.force && requiredNativeActivation(item)
521
+ || !options.force && demand.placements.some((placement) => placement.pluginId === item.pluginId
522
+ && placement.target === item.agent && placement.scope === item.scope))
422
523
  continue;
423
524
  retire.push(item);
424
525
  }
@@ -443,16 +544,35 @@ async function prepareJointRecoveryInSession(command, selectors, options, runtim
443
544
  || child.receipt.targetResults.some((item) => item.blockers.length));
444
545
  if (!plan.blockExecution && !deploymentBlocked) {
445
546
  const cleanups = [];
446
- for (const item of [...new Map(safeRetirements.map((entry) => [`${entry.pluginId}\0${entry.agent}\0${entry.scope}`, entry])).values()]) {
547
+ const pendingRetirements = [...new Map(safeRetirements.map((entry) => [`${entry.pluginId}\0${entry.agent}\0${entry.scope}`, entry])).values()];
548
+ const orderedRetirements = [];
549
+ while (pendingRetirements.length) {
550
+ const ready = pendingRetirements.findIndex((candidate) => !pendingRetirements.some((consumer) => consumer !== candidate && consumer.agent === candidate.agent
551
+ && dependencies(consumer.pluginId)?.includes(candidate.pluginId)));
552
+ if (ready < 0)
553
+ throw new Error('dependencyGraphInvalid');
554
+ orderedRetirements.push(...pendingRetirements.splice(ready, 1));
555
+ }
556
+ for (const item of orderedRetirements) {
447
557
  if (!item.agent)
448
558
  continue;
559
+ dependencies(item.pluginId);
449
560
  const cleanupDemand = item.scope === 'project' ? { ...snapshot.project,
450
561
  userProviders: Object.fromEntries((snapshot.preferences?.targets ?? []).map((target) => [target,
451
562
  demand.placements.filter((placement) => placement.scope === 'user' && placement.target === target)
452
563
  .map((placement) => placement.pluginId)])), } : snapshot.user;
453
564
  const cleanup = await prepareScopedRecovery('cleanup', [item.pluginId], { ...options,
454
565
  scope: item.scope, cwd: snapshot.context.projectRoot ?? options.cwd, targets: [item.agent], all: false,
455
- exactTargets: undefined, demandOverride: cleanupDemand }, runtime);
566
+ // Ordinary remove's force bypasses dependencies, never ownership checks.
567
+ force: false, exactTargets: undefined, demandOverride: cleanupDemand }, runtime);
568
+ if (automaticRetirements.some((candidate) => candidate.pluginId === item.pluginId
569
+ && candidate.target === item.agent && candidate.scope === item.scope)) {
570
+ for (const target of cleanup.receipt.targetResults) {
571
+ target.relation = 'dependency';
572
+ target.requiredBy = previousDemand.placements.find((candidate) => candidate.pluginId === item.pluginId
573
+ && candidate.target === item.agent && candidate.scope === item.scope)?.contributions.map((entry) => entry.root) ?? [];
574
+ }
575
+ }
456
576
  cleanups.push(cleanup);
457
577
  }
458
578
  children.unshift(...cleanups);
@@ -564,11 +684,15 @@ export async function executeJointRecovery(plan, execution) {
564
684
  fresh.originalIntent = observationEvidence(currentIntent);
565
685
  for (const target of fresh.receipt.targetResults) {
566
686
  const reviewed = child.receipt.targetResults.find((entry) => entry.pluginId === target.pluginId && entry.agent === target.agent);
687
+ if (reviewed?.relation === 'dependency') {
688
+ target.relation = 'dependency';
689
+ target.requiredBy = [...reviewed.requiredBy];
690
+ }
567
691
  // Native/provider observations are refreshed after preceding nodes.
568
692
  // Keep only joint constraints and an already failed script gate.
569
693
  target.blockers.push(...(reviewed?.blockers ?? []).filter((error) => reviewed?.execution === 'failed'
570
694
  || ['configApplyRequiresExistingOutput', 'crossScopeSkillCollision', 'targetPlacementConflict',
571
- 'preApplyAuthorizationRequired', 'nativeToolAuthorizationRequired', 'providerSwitchPreApplyFailed'].includes(error.code)));
695
+ 'preApplyAuthorizationRequired', 'nativeToolAuthorizationRequired', 'providerSwitchPreApplyFailed', 'dependencyStillRequired'].includes(error.code)));
572
696
  if (reviewed?.execution === 'failed')
573
697
  target.execution = 'failed';
574
698
  if (child.command !== 'cleanup' && failedCleanups.some((failed) => targetsConflict({ target: failed.agent, scope: failed.scope }, { target: target.agent, scope: target.scope })
@@ -629,6 +753,16 @@ export async function executeJointRecovery(plan, execution) {
629
753
  // old output when its corresponding replacement cannot run.
630
754
  for (const child of joint.children.filter((child) => child.command === 'cleanup')) {
631
755
  for (const target of child.receipt.requestedTargets) {
756
+ if (plan.command === 'uninstall' && failedCleanups.some((failed) => {
757
+ if (failed.agent !== target.agent)
758
+ return false;
759
+ const required = joint.removalDependencies.get(failed.pluginId);
760
+ return required?.includes(target.pluginId) || required === null
761
+ && parsePluginId(failed.pluginId).sourceId === parsePluginId(target.pluginId).sourceId;
762
+ })) {
763
+ child.receipt.targetResults.find((entry) => entry.pluginId === target.pluginId && entry.agent === target.agent)
764
+ .blockers.push(diagnostic('dependencyStillRequired', '依赖者未完成删除,保留其依赖输出。'));
765
+ }
632
766
  if ([...replacementFailures].some((failed) => failed.startsWith(`${target.pluginId}\0`)
633
767
  && (failed === `${target.pluginId}\0${target.agent}`
634
768
  || !joint.children.some((replacement) => replacement.command !== 'cleanup'