@lesliechan721/aw 0.1.0-beta.82 → 0.1.0-beta.84

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 (190) hide show
  1. package/dist/authoring/assets/aw-runtime-config.mjs +1 -1
  2. package/dist/authoring/assets/aw-runtime-config.mjs.map +1 -1
  3. package/dist/src/commands/console.js +1 -0
  4. package/dist/src/commands/console.js.map +1 -1
  5. package/dist/src/commands/intent-command.d.ts +1 -0
  6. package/dist/src/commands/intent-command.js +6 -2
  7. package/dist/src/commands/intent-command.js.map +1 -1
  8. package/dist/src/commands/plugin-capabilities.js +3 -3
  9. package/dist/src/commands/plugin-capabilities.js.map +1 -1
  10. package/dist/src/commands/public-lifecycle-result.d.ts +11 -5
  11. package/dist/src/commands/public-lifecycle-result.js +131 -46
  12. package/dist/src/commands/public-lifecycle-result.js.map +1 -1
  13. package/dist/src/commands/public-lifecycle.d.ts +1 -2
  14. package/dist/src/commands/public-lifecycle.js +56 -34
  15. package/dist/src/commands/public-lifecycle.js.map +1 -1
  16. package/dist/src/commands/public-plugin-query.js +28 -11
  17. package/dist/src/commands/public-plugin-query.js.map +1 -1
  18. package/dist/src/commands/rebuild-command.d.ts +13 -3
  19. package/dist/src/commands/rebuild-command.js +647 -286
  20. package/dist/src/commands/rebuild-command.js.map +1 -1
  21. package/dist/src/commands/rebuild-integration.d.ts +5 -2
  22. package/dist/src/commands/rebuild-integration.js +55 -29
  23. package/dist/src/commands/rebuild-integration.js.map +1 -1
  24. package/dist/src/commands/rebuild-operations.d.ts +1 -0
  25. package/dist/src/commands/rebuild-operations.js +23 -4
  26. package/dist/src/commands/rebuild-operations.js.map +1 -1
  27. package/dist/src/commands/rebuild-platform-integration.d.ts +14 -3
  28. package/dist/src/commands/rebuild-platform-integration.js +240 -137
  29. package/dist/src/commands/rebuild-platform-integration.js.map +1 -1
  30. package/dist/src/index.js +105 -50
  31. package/dist/src/index.js.map +1 -1
  32. package/dist/src/output/public-result.d.ts +2 -0
  33. package/dist/src/output/public-result.js +43 -6
  34. package/dist/src/output/public-result.js.map +1 -1
  35. package/dist/src/output/rebuild-progress.d.ts +3 -0
  36. package/dist/src/output/rebuild-progress.js +12 -2
  37. package/dist/src/output/rebuild-progress.js.map +1 -1
  38. package/dist/src/output/receipt-projection.js +55 -18
  39. package/dist/src/output/receipt-projection.js.map +1 -1
  40. package/dist/src/output/skill-invocation-notices.d.ts +16 -0
  41. package/dist/src/output/skill-invocation-notices.js +48 -0
  42. package/dist/src/output/skill-invocation-notices.js.map +1 -0
  43. package/dist/src/platforms/capabilities.d.ts +2 -0
  44. package/dist/src/platforms/capabilities.js +73 -34
  45. package/dist/src/platforms/capabilities.js.map +1 -1
  46. package/dist/src/platforms/contracts.d.ts +9 -9
  47. package/dist/src/platforms/discovery.d.ts +0 -7
  48. package/dist/src/platforms/discovery.js +13 -53
  49. package/dist/src/platforms/discovery.js.map +1 -1
  50. package/dist/src/platforms/inspection-native.js +1 -80
  51. package/dist/src/platforms/inspection-native.js.map +1 -1
  52. package/dist/src/platforms/inspection-query.d.ts +2 -3
  53. package/dist/src/platforms/inspection-query.js +7 -18
  54. package/dist/src/platforms/inspection-query.js.map +1 -1
  55. package/dist/src/platforms/inspection.js +2 -2
  56. package/dist/src/platforms/inspection.js.map +1 -1
  57. package/dist/src/platforms/layout.js +1 -5
  58. package/dist/src/platforms/layout.js.map +1 -1
  59. package/dist/src/platforms/lifecycle-native-services.d.ts +1 -1
  60. package/dist/src/platforms/lifecycle-native-services.js +14 -14
  61. package/dist/src/platforms/lifecycle-native-services.js.map +1 -1
  62. package/dist/src/platforms/lifecycle-native.js +4 -88
  63. package/dist/src/platforms/lifecycle-native.js.map +1 -1
  64. package/dist/src/platforms/lifecycle.js +56 -56
  65. package/dist/src/platforms/lifecycle.js.map +1 -1
  66. package/dist/src/platforms/projection-code-extension.js +7 -3
  67. package/dist/src/platforms/projection-code-extension.js.map +1 -1
  68. package/dist/src/platforms/projection.d.ts +3 -0
  69. package/dist/src/platforms/projection.js +86 -54
  70. package/dist/src/platforms/projection.js.map +1 -1
  71. package/dist/src/portable/materializer.js +2 -2
  72. package/dist/src/portable/materializer.js.map +1 -1
  73. package/dist/src/portable/recovery.d.ts +29 -3
  74. package/dist/src/portable/recovery.js +220 -78
  75. package/dist/src/portable/recovery.js.map +1 -1
  76. package/dist/src/recovery/coordinator.d.ts +21 -5
  77. package/dist/src/recovery/coordinator.js +383 -151
  78. package/dist/src/recovery/coordinator.js.map +1 -1
  79. package/dist/src/recovery/install-concurrency.d.ts +48 -0
  80. package/dist/src/recovery/install-concurrency.js +195 -0
  81. package/dist/src/recovery/install-concurrency.js.map +1 -0
  82. package/dist/src/recovery/interruption.d.ts +19 -0
  83. package/dist/src/recovery/interruption.js +43 -0
  84. package/dist/src/recovery/interruption.js.map +1 -0
  85. package/dist/src/recovery/joint-coordinator.d.ts +11 -4
  86. package/dist/src/recovery/joint-coordinator.js +681 -333
  87. package/dist/src/recovery/joint-coordinator.js.map +1 -1
  88. package/dist/src/recovery/joint-demand.d.ts +8 -0
  89. package/dist/src/recovery/joint-demand.js +52 -1
  90. package/dist/src/recovery/joint-demand.js.map +1 -1
  91. package/dist/src/recovery/joint-install-execution.d.ts +19 -0
  92. package/dist/src/recovery/joint-install-execution.js +307 -0
  93. package/dist/src/recovery/joint-install-execution.js.map +1 -0
  94. package/dist/src/recovery/joint-install-native-rebase.d.ts +4 -0
  95. package/dist/src/recovery/joint-install-native-rebase.js +67 -0
  96. package/dist/src/recovery/joint-install-native-rebase.js.map +1 -0
  97. package/dist/src/recovery/receipt.d.ts +20 -0
  98. package/dist/src/recovery/receipt.js +67 -1
  99. package/dist/src/recovery/receipt.js.map +1 -1
  100. package/dist/src/recovery/retirement.js +1 -1
  101. package/dist/src/recovery/retirement.js.map +1 -1
  102. package/dist/src/recovery/status.js +26 -27
  103. package/dist/src/recovery/status.js.map +1 -1
  104. package/dist/src/review/platform-profile.d.ts +4 -1
  105. package/dist/src/review/platform-profile.js +13 -4
  106. package/dist/src/review/platform-profile.js.map +1 -1
  107. package/dist/src/review/skill-materialization.d.ts +1 -0
  108. package/dist/src/review/skill-materialization.js +28 -16
  109. package/dist/src/review/skill-materialization.js.map +1 -1
  110. package/dist/src/review/source-binding.js +6 -4
  111. package/dist/src/review/source-binding.js.map +1 -1
  112. package/dist/src/tui/catalog-generation.d.ts +6 -0
  113. package/dist/src/tui/catalog-generation.js +22 -6
  114. package/dist/src/tui/catalog-generation.js.map +1 -1
  115. package/dist/src/tui/console-app-v4.d.ts +1 -1
  116. package/dist/src/tui/console-app-v4.js +139 -59
  117. package/dist/src/tui/console-app-v4.js.map +1 -1
  118. package/dist/src/tui/controller-runtime.js +145 -53
  119. package/dist/src/tui/controller-runtime.js.map +1 -1
  120. package/dist/src/tui/controller.d.ts +13 -4
  121. package/dist/src/tui/controller.js +241 -102
  122. package/dist/src/tui/controller.js.map +1 -1
  123. package/dist/src/tui/deployment-view.js +6 -1
  124. package/dist/src/tui/deployment-view.js.map +1 -1
  125. package/dist/src/tui/diagnostic-projection.d.ts +4 -2
  126. package/dist/src/tui/diagnostic-projection.js +40 -4
  127. package/dist/src/tui/diagnostic-projection.js.map +1 -1
  128. package/dist/src/tui/glossary.js +1 -0
  129. package/dist/src/tui/glossary.js.map +1 -1
  130. package/dist/src/tui/operation-diagnostic-screens.d.ts +1 -1
  131. package/dist/src/tui/operation-diagnostic-screens.js +3 -1
  132. package/dist/src/tui/operation-diagnostic-screens.js.map +1 -1
  133. package/dist/src/tui/operation-history.d.ts +6 -3
  134. package/dist/src/tui/operation-history.js +15 -2
  135. package/dist/src/tui/operation-history.js.map +1 -1
  136. package/dist/src/tui/scoped-flow.d.ts +3 -1
  137. package/dist/src/tui/scoped-flow.js +99 -1
  138. package/dist/src/tui/scoped-flow.js.map +1 -1
  139. package/dist/src/tui/session-console-app.d.ts +2 -0
  140. package/dist/src/tui/session-console-app.js +11 -0
  141. package/dist/src/tui/session-console-app.js.map +1 -1
  142. package/dist/src/types.d.ts +8 -1
  143. package/dist/src/types.js.map +1 -1
  144. package/dist/src/utils/aw-home-mutation-lock.js +2 -1
  145. package/dist/src/utils/aw-home-mutation-lock.js.map +1 -1
  146. package/dist/src/utils/catalog-generation-resolver.d.ts +1 -0
  147. package/dist/src/utils/catalog-generation-resolver.js +1 -0
  148. package/dist/src/utils/catalog-generation-resolver.js.map +1 -1
  149. package/dist/src/utils/catalog-operation-context.d.ts +11 -0
  150. package/dist/src/utils/catalog-operation-context.js +18 -3
  151. package/dist/src/utils/catalog-operation-context.js.map +1 -1
  152. package/dist/src/utils/catalog-source-references.js +2 -14
  153. package/dist/src/utils/catalog-source-references.js.map +1 -1
  154. package/dist/src/utils/component-resources.js +1 -1
  155. package/dist/src/utils/component-resources.js.map +1 -1
  156. package/dist/src/utils/managed-command-materialization.d.ts +2 -1
  157. package/dist/src/utils/managed-command-materialization.js +3 -3
  158. package/dist/src/utils/managed-command-materialization.js.map +1 -1
  159. package/dist/src/utils/managed-command-store.d.ts +6 -0
  160. package/dist/src/utils/managed-command-store.js +90 -18
  161. package/dist/src/utils/managed-command-store.js.map +1 -1
  162. package/dist/src/utils/multi-source-catalog.d.ts +2 -0
  163. package/dist/src/utils/multi-source-catalog.js +3 -2
  164. package/dist/src/utils/multi-source-catalog.js.map +1 -1
  165. package/dist/src/utils/native-cli.d.ts +0 -19
  166. package/dist/src/utils/native-cli.js +2 -42
  167. package/dist/src/utils/native-cli.js.map +1 -1
  168. package/dist/src/utils/ownership.js +1 -1
  169. package/dist/src/utils/ownership.js.map +1 -1
  170. package/dist/src/utils/platform-empty-state.d.ts +1 -3
  171. package/dist/src/utils/platform-empty-state.js +1 -6
  172. package/dist/src/utils/platform-empty-state.js.map +1 -1
  173. package/dist/src/utils/plugin-config-write.d.ts +8 -0
  174. package/dist/src/utils/plugin-config-write.js +89 -25
  175. package/dist/src/utils/plugin-config-write.js.map +1 -1
  176. package/dist/src/utils/plugin-scripts.js +5 -0
  177. package/dist/src/utils/plugin-scripts.js.map +1 -1
  178. package/dist/src/utils/skill-invocation-warning.d.ts +15 -0
  179. package/dist/src/utils/skill-invocation-warning.js +42 -0
  180. package/dist/src/utils/skill-invocation-warning.js.map +1 -0
  181. package/package.json +3 -3
  182. package/dist/src/output/native-consent.d.ts +0 -2
  183. package/dist/src/output/native-consent.js +0 -5
  184. package/dist/src/output/native-consent.js.map +0 -1
  185. package/dist/src/platforms/gemini-activation.d.ts +0 -36
  186. package/dist/src/platforms/gemini-activation.js +0 -331
  187. package/dist/src/platforms/gemini-activation.js.map +0 -1
  188. package/dist/src/platforms/gemini-consent.d.ts +0 -8
  189. package/dist/src/platforms/gemini-consent.js +0 -81
  190. package/dist/src/platforms/gemini-consent.js.map +0 -1
@@ -11,11 +11,14 @@ import { bindNativeCliRunnerSignal, getDefaultNativeCliRunner, prepareNativeCliE
11
11
  import { portableRecoveryLayout } from '../portable/recovery-layout.js';
12
12
  import { canonicalizePathThroughExistingAncestor, resolveClaudeProjectKey, resolveCodexProjectKey } from '../utils/state-paths.js';
13
13
  import { parsePluginId } from '../utils/multi-source-catalog.js';
14
+ import { CatalogPreparationReadScope, selectCatalogOperationContext } from '../utils/catalog-operation-context.js';
15
+ import { CatalogGenerationError } from '../utils/catalog-generation-error.js';
16
+ import { createCatalogPreparationStoreKey } from '../utils/catalog-generation-resolver.js';
14
17
  import { activateCatalogSourceGeneration, probeCatalogSourceGeneration, } from '../utils/catalog-generation-service.js';
15
18
  import { readCatalogGenerationState } from '../utils/catalog-generation-state.js';
16
19
  import { readCatalogSourcesConfigSnapshot } from '../utils/catalog-sources.js';
17
20
  import { calculateCatalogSourceImpactDigest, inspectCatalogSourceImpact, } from '../utils/catalog-source-impact.js';
18
- import { preparePortableRecovery, portablePreparationDiagnostic, preparePortableCleanup, inspectPortableRecovery, inspectPortableResidue, executePortableRecovery, } from '../portable/recovery.js';
21
+ import { preparePortableRecovery, portablePreparationDiagnostic, portableReviewMatches, unobservedPortableTarget, preparePortableCleanup, inspectPortableRecovery, inspectPortableResidue, executePortableRecovery, PortableInterruptedError, } from '../portable/recovery.js';
19
22
  import { addRequirements } from '../commands/intent-command.js';
20
23
  import { readDemand, demandNativeProjection, resolveDelivery } from './demand.js';
21
24
  import { selectAgents, writePreferences } from '../intent/deployment-preferences.js';
@@ -27,6 +30,8 @@ import { createEmptyNativeDemandView } from '../utils/native-demand.js';
27
30
  import { resolvePluginMetaDependencyClosure } from '../utils/plugin-dependencies.js';
28
31
  import { runPreApplyScript } from '../utils/plugin-scripts.js';
29
32
  import { readSafeOperationError } from '../utils/safe-operation-diagnostic.js';
33
+ import { RebuildInterruptedError, RecoveryInterruptedError, recoveryInterruptionCode } from './interruption.js';
34
+ import { mapInstallReads } from './install-concurrency.js';
30
35
  import { measureRecoveryPerformanceStage } from './performance.js';
31
36
  import { disposePreparedPlatformRebuildSession } from '../commands/rebuild-integration.js';
32
37
  import { operationPlanNativeToolChanges } from '../commands/operation-plan.js';
@@ -144,6 +149,24 @@ function nativeTargetSelection(targets) {
144
149
  return { pluginIds: [...new Set(targets.map((target) => target.pluginId))],
145
150
  platform: platforms.size === 1 ? targets[0].platform : 'both', targets: [...targets] };
146
151
  }
152
+ // Rebuild accumulates one marketplace generation per platform across sources and scopes.
153
+ async function readNativeGroups(groups, read, signal) {
154
+ const lanes = new Map();
155
+ for (const group of groups) {
156
+ const key = group.command === 'install' || group.command === 'sync' ? group.platform : 'serial';
157
+ const lane = lanes.get(key) ?? [];
158
+ lane.push(group);
159
+ lanes.set(key, lane);
160
+ }
161
+ const results = new Map();
162
+ await mapInstallReads([...lanes.values()], async (lane) => {
163
+ for (const group of lane) {
164
+ signal?.throwIfAborted();
165
+ results.set(group, await read(group));
166
+ }
167
+ }, { signal });
168
+ return groups.map((group) => results.get(group));
169
+ }
147
170
  async function nativeOperation(plan, pluginIds, platform, preview, runtime = plan.runtime, command = plan.command, selectedTargets, catalogReadScope) {
148
171
  if (!runtime.awHomeMutationToken) {
149
172
  await prepareNativeCliExecution({ env: plan.context.env, runner: runtime.nativeCliRunner });
@@ -197,16 +220,16 @@ function nativeResults(plan, group, result, executed) {
197
220
  ...(plan.receipt.commandResults ?? []), ...result.commandResults,
198
221
  ].map((entry) => [getCommandPackageId(entry.producer), entry])).values()];
199
222
  }
223
+ const backend = buildRebuildReceiptJson(group.command === 'install' ? 'sync' : group.command, result);
200
224
  for (const { pluginId, platform } of nativeGroupTargets(group)) {
201
225
  const agent = agentForPlatform(platform);
202
226
  const target = pair(plan, pluginId, agent);
203
227
  if (!target)
204
228
  continue;
205
- const backend = buildRebuildReceiptJson(group.command === 'install' ? 'sync' : group.command, result);
206
229
  target.backend = backend;
207
- target.recoveryActions = backend.recoveryActions;
208
- const backendTargets = result.targetResults.filter((entry) => entry.target.pluginId === pluginId
209
- && entry.target.platform === platform && entry.target.scope === plan.options.scope);
230
+ const matchesTarget = (entry) => entry.target.pluginId === pluginId
231
+ && entry.target.platform === platform && entry.target.scope === plan.options.scope;
232
+ const backendTargets = result.targetResults.filter(matchesTarget);
210
233
  const deploymentPlans = new Map([
211
234
  ...(group.preview.operationPlan?.deploymentPlans ?? []),
212
235
  ...(result.operationPlan?.deploymentPlans ?? []),
@@ -246,6 +269,12 @@ function nativeResults(plan, group, result, executed) {
246
269
  && target.target.scope === (result.dependencyPlan?.targets.find((dependency) => dependency.pluginId === producerPluginId && dependency.platform === platform)?.resolvedScope
247
270
  ?? plan.options.scope));
248
271
  });
272
+ target.recoveryActions = backend.targetResults.length || backend.commandResults?.length
273
+ ? [...new Set([
274
+ ...backend.targetResults.filter(matchesTarget).flatMap((entry) => entry.recoveryActions),
275
+ ...producers.flatMap((producer) => producer.recoveryActions),
276
+ ])]
277
+ : backend.recoveryActions;
249
278
  for (const failure of backendTargets.filter((entry) => entry.state === 'failed')) {
250
279
  block(target, failure.errorCode ?? 'nativeRecoveryFailed');
251
280
  }
@@ -327,9 +356,10 @@ function nativeResults(plan, group, result, executed) {
327
356
  }
328
357
  }
329
358
  /** All scopes share one final marketplace generation before Review is returned. */
330
- export async function refreshRecoveryNativePreviews(plan, catalogReadScope) {
331
- for (const group of plan.nativeGroups) {
332
- group.preview = await nativeOperation(plan, group.pluginIds, group.platform, true, plan.runtime, group.command, nativeGroupTargets(group), catalogReadScope);
359
+ export async function refreshRecoveryNativePreviews(plan, catalogReadScope, signal = plan.runtime.signal) {
360
+ const previews = await readNativeGroups(plan.nativeGroups, (group) => nativeOperation(plan, group.pluginIds, group.platform, true, { ...plan.runtime, signal }, group.command, nativeGroupTargets(group), catalogReadScope), signal);
361
+ for (const [index, group] of plan.nativeGroups.entries()) {
362
+ group.preview = previews[index];
333
363
  nativeResults(plan, group, group.preview, false);
334
364
  }
335
365
  completeReceipt(plan.receipt);
@@ -372,6 +402,12 @@ function portableResults(plan, prepared) {
372
402
  function portableOutcomes(plan, prepared, agent, outcomes, globalBlockers) {
373
403
  const target = pair(plan, prepared.options.selector, agent);
374
404
  const contentOutcomes = outcomes.filter((entry) => entry.disposition !== 'remove');
405
+ for (const entry of contentOutcomes) {
406
+ if (entry.invocationWarning && entry.disposition === 'write' && entry.observation === 'satisfied'
407
+ && (entry.execution === 'applied' || entry.execution === 'no-op') && !entry.blockers.length) {
408
+ (target.reasons ??= []).push(entry.invocationWarning);
409
+ }
410
+ }
375
411
  const preparedTargets = prepared.targets.filter((entry) => entry.agent === agent);
376
412
  const gaps = (prepared.unmet ?? []).filter((gap) => gap.agent === agent);
377
413
  if (gaps.length)
@@ -418,20 +454,30 @@ function portableOutcomes(plan, prepared, agent, outcomes, globalBlockers) {
418
454
  execution: entry.execution, blockers: entry.blockers }));
419
455
  for (const code of [...globalBlockers, ...outcomes.flatMap((entry) => entry.blockers)])
420
456
  block(target, code);
421
- target.recoveryActions = portableRecoveryActions(plan, target.pluginId, outcomes.filter((entry) => ['conflict', 'unknown'].includes(entry.observation)));
457
+ target.recoveryActions = portableRecoveryActions(plan, target.pluginId, outcomes.filter((entry) => entry.observation === 'conflict' || entry.observation === 'unknown' && !entry.blockers.includes('operationReviewStale')));
458
+ if (globalBlockers.includes('operationReviewStale') && prepared.mode !== 'cleanup') {
459
+ target.recoveryActions.push(`aw plugin sync ${target.pluginId} --context ${target.scope} --target ${agent}`);
460
+ }
422
461
  }
423
462
  function portablePluginClosure(plan, prepared) {
424
463
  const { sourceId, pluginName } = parsePluginId(prepared.options.selector);
425
464
  return resolvePluginMetaDependencyClosure(plan.demand.plugins.filter((plugin) => plugin.sourceId === sourceId), [pluginName])
426
465
  .filter((plugin) => !prepared.options.excludedPluginIds?.includes(plugin.pluginId));
427
466
  }
467
+ function isHealthyPortableProvider(group) {
468
+ return !group.blockers.length && !group.unmet.length && (group.intentionalEmpty || group.targets.length > 0)
469
+ && group.targets.every((target) => target.disposition === 'write' && target.ownership === 'aw'
470
+ && target.observation === 'satisfied' && target.installedDigest === target.expectedDigest);
471
+ }
428
472
  function preparePortablePreApplyAuthorization(plan) {
429
473
  if (plan.command === 'cleanup' || plan.command === 'uninstall')
430
474
  return;
431
475
  const authorization = new Map();
476
+ const verifiedProviders = new Set(plan.portableGroups.filter((group) => plan.options.inheritedPortableProviderIds?.includes(group.options.selector) && isHealthyPortableProvider(group))
477
+ .map((group) => group.options.selector));
432
478
  for (const prepared of plan.portableGroups) {
433
479
  for (const plugin of portablePluginClosure(plan, prepared)) {
434
- if (!plugin.manifest.scripts?.preApply)
480
+ if (!plugin.manifest.scripts?.preApply || verifiedProviders.has(plugin.pluginId))
435
481
  continue;
436
482
  for (const platform of prepared.options.agents) {
437
483
  if (pair(plan, prepared.options.selector, platform)?.blockers.length)
@@ -466,6 +512,7 @@ async function executePreApplyAuthorization(plan, required, runtime) {
466
512
  return 'preApplyAuthorizationRequired';
467
513
  const cache = runtime.preApplyExecutionCache ??= new Map();
468
514
  for (const target of required) {
515
+ runtime.signal?.throwIfAborted();
469
516
  const plugin = plan.demand.plugins.find((entry) => entry.pluginId === target.pluginId);
470
517
  if (!plugin || plugin.sourceIdentity !== target.sourceIdentity)
471
518
  return 'sourceUnavailable';
@@ -486,9 +533,18 @@ async function executePreApplyAuthorization(plan, required, runtime) {
486
533
  await execution;
487
534
  }
488
535
  catch (error) {
489
- runtime.signal?.throwIfAborted();
490
- if (error instanceof Error && error.name === 'AbortError')
536
+ const interrupted = recoveryInterruptionCode(error, runtime.signal);
537
+ if (interrupted) {
538
+ const affected = pair(plan, target.pluginId, target.platform);
539
+ if (affected) {
540
+ affected.execution = 'partial';
541
+ affected.observation = 'unknown';
542
+ affected.content = 'unknown';
543
+ block(affected, interrupted);
544
+ }
545
+ plan.receipt.outputsMayHaveChanged = true;
491
546
  throw error;
547
+ }
492
548
  const operationDiagnostic = readSafeOperationError(error);
493
549
  const affected = pair(plan, target.pluginId, target.platform);
494
550
  if (affected) {
@@ -539,8 +595,7 @@ export async function executeRecoveryPreApply(plan, pluginId, agent, runtime) {
539
595
  return executePreApplyAuthorization(plan, authorization.preApplyAuthorization, runtime);
540
596
  }
541
597
  catch (error) {
542
- runtime.signal?.throwIfAborted();
543
- if (error instanceof Error && error.name === 'AbortError')
598
+ if (recoveryInterruptionCode(error, runtime.signal))
544
599
  throw error;
545
600
  return readSafeOperationError(error)?.code ?? errorCode(error, 'nativePreparationFailed');
546
601
  }
@@ -552,7 +607,7 @@ export async function executeRecoveryPreApply(plan, pluginId, agent, runtime) {
552
607
  return executePortablePreApply(plan, prepared, agent, runtime);
553
608
  }
554
609
  }
555
- async function checkFootprints(plan) {
610
+ export async function checkFootprints(plan) {
556
611
  const footprints = [];
557
612
  for (const [nativeGroup, group] of plan.nativeGroups.entries()) {
558
613
  const actions = group.preview.operationPlan?.actions.filter((action) => (action.kind === 'writeOwnedArtifact' || action.kind === 'removeOwnedArtifact')
@@ -563,7 +618,7 @@ async function checkFootprints(plan) {
563
618
  continue;
564
619
  const consumers = group.preview.dependencyPlan?.targets.filter((target) => target.pluginId === action.pluginId)
565
620
  .flatMap((target) => target.requiredBy ?? []) ?? [];
566
- footprints.push({ path: await canonicalizePathThroughExistingAncestor(action.path),
621
+ footprints.push({ path: action.path,
567
622
  pluginIds: group.pluginIds.filter((id) => id === action.pluginId || consumers.includes(id)),
568
623
  agent: agentForPlatform(action.platform), identity: `native:${action.platform}:${action.pluginId}`,
569
624
  sharedNative: 'shared' in action && action.shared,
@@ -575,17 +630,23 @@ async function checkFootprints(plan) {
575
630
  for (const prepared of plan.portableGroups) {
576
631
  for (const target of prepared.targets)
577
632
  footprints.push({
578
- path: await canonicalizePathThroughExistingAncestor(target.physicalPath),
633
+ path: target.physicalPath,
579
634
  pluginIds: [prepared.options.selector], agent: target.agent,
580
- identity: `agent-skills:${prepared.logicalIdentity}:${target.providerPluginId}:${target.expectedDigest}`,
635
+ identity: JSON.stringify(['agent-skills', prepared.logicalIdentity, target.providerPluginId, target.expectedDigest,
636
+ target.configDigest, target.disposition]),
581
637
  });
582
638
  }
639
+ const paths = [...new Set(footprints.map((entry) => entry.path))];
640
+ const canonical = new Map(await mapInstallReads(paths, async (value) => [value, await canonicalizePathThroughExistingAncestor(value)], { signal: plan.runtime.signal }));
641
+ for (const item of footprints)
642
+ item.path = canonical.get(item.path);
583
643
  for (let index = 0; index < footprints.length; index += 1) {
584
644
  const left = footprints[index];
585
645
  for (const right of footprints.slice(index + 1)) {
586
- if (left.path !== right.path || left.identity === right.identity
646
+ const overlap = left.path === right.path || left.path.startsWith(right.path + path.sep) || right.path.startsWith(left.path + path.sep);
647
+ if (!overlap || left.identity === right.identity
587
648
  || (left.nativeGroup !== undefined && left.nativeGroup === right.nativeGroup)
588
- || (left.sharedMarketplaceSource !== undefined
649
+ || (left.sharedMarketplaceSource !== undefined && left.agent === right.agent
589
650
  && left.sharedMarketplaceSource === right.sharedMarketplaceSource)
590
651
  || (left.sharedNative && right.sharedNative && left.agent === right.agent))
591
652
  continue;
@@ -603,7 +664,7 @@ async function checkFootprints(plan) {
603
664
  plan.changes.push(`${prepared.options.selector}:AW 写入所选 Agent 的 owned Skill 目录;准备目录 ${layout.generationRoot}。`);
604
665
  }
605
666
  }
606
- export async function prepareScopedRecovery(command, selectors, options, runtime = {}, { catalogReadScope, nativeObservationBatch } = {}) {
667
+ export async function prepareScopedRecovery(command, selectors, options, runtime = {}, { catalogReadScope, nativeObservationBatch, portableGenerations = new Map() } = {}) {
607
668
  runtime = { ...runtime, preparedArtifactRenderResults: runtime.preparedArtifactRenderResults ?? new Map() };
608
669
  options.signal?.throwIfAborted();
609
670
  const context = await createScopeContext({ scope: options.scope, cwd: options.cwd, env: options.env });
@@ -646,8 +707,7 @@ export async function prepareScopedRecovery(command, selectors, options, runtime
646
707
  configDigest: config.digest, impact, impactDigest: calculateCatalogSourceImpactDigest(impact) });
647
708
  }
648
709
  catch (error) {
649
- options.signal?.throwIfAborted();
650
- if (error instanceof Error && error.name === 'AbortError')
710
+ if (recoveryInterruptionCode(error, options.signal))
651
711
  throw error;
652
712
  const code = errorCode(error, 'catalogGenerationRefreshFailed');
653
713
  refreshFailures.set(sourceId, code.startsWith('catalog') ? code : 'catalogGenerationRefreshFailed');
@@ -766,15 +826,25 @@ export async function prepareScopedRecovery(command, selectors, options, runtime
766
826
  group.targets.push({ pluginId: target.pluginId, platform: target.delivery.platform });
767
827
  groups.set(key, group);
768
828
  }
769
- const preparationRuntime = { ...runtime, signal: options.signal,
770
- nativeObservationBatch: groups.size === 1 ? nativeObservationBatch : undefined };
771
- for (const pending of groups.values()) {
772
- const group = { ...nativeTargetSelection(pending.targets), command: pending.command };
773
- if (group.targets.length === 0)
774
- continue;
829
+ const preparationRuntime = { ...runtime, signal: options.signal, nativeObservationBatch };
830
+ const pendingGroups = [...groups.values()].map((pending) => ({
831
+ ...nativeTargetSelection(pending.targets), command: pending.command,
832
+ }));
833
+ const previews = await readNativeGroups(pendingGroups, async (group) => {
775
834
  try {
776
835
  const preview = await nativeOperation(plan, group.pluginIds, group.platform, true, preparationRuntime, group.command, group.targets, catalogReadScope);
777
- options.signal?.throwIfAborted();
836
+ return { ok: true, preview };
837
+ }
838
+ catch (error) {
839
+ if (recoveryInterruptionCode(error, options.signal))
840
+ throw error;
841
+ return { ok: false, error };
842
+ }
843
+ }, options.signal);
844
+ for (const [index, group] of pendingGroups.entries()) {
845
+ const result = previews[index];
846
+ if (result.ok) {
847
+ const { preview } = result;
778
848
  const nativeGroup = { ...group, preview };
779
849
  plan.nativeGroups.push(nativeGroup);
780
850
  nativeResults(plan, nativeGroup, preview, false);
@@ -796,10 +866,8 @@ export async function prepareScopedRecovery(command, selectors, options, runtime
796
866
  }
797
867
  plan.warnings.push(...preview.warnings);
798
868
  }
799
- catch (error) {
800
- options.signal?.throwIfAborted();
801
- if (error instanceof Error && error.name === 'AbortError')
802
- throw error;
869
+ else {
870
+ const { error } = result;
803
871
  if (error instanceof CatalogSourceInventoryIncompleteError) {
804
872
  receipt.blockers.push(...error.inventory.errors.map(inventoryRecoveryDiagnostic));
805
873
  }
@@ -808,26 +876,32 @@ export async function prepareScopedRecovery(command, selectors, options, runtime
808
876
  }
809
877
  }
810
878
  }
811
- for (const pluginId of receipt.requestedRoots) {
879
+ const portableReads = receipt.requestedRoots.flatMap((pluginId) => {
812
880
  const agents = receipt.targetResults.filter((target) => target.pluginId === pluginId
813
881
  && !target.blockers.length && target.delivery?.kind === 'agent-skills').map((target) => target.agent).filter(isPortableAgent);
814
- if (!agents.length)
815
- continue;
882
+ return agents.length ? [{ pluginId, agents }] : [];
883
+ });
884
+ const preparedGroups = await mapInstallReads(portableReads, async ({ pluginId, agents }) => {
816
885
  try {
817
886
  const prepared = command === 'cleanup' || command === 'uninstall'
818
887
  ? await preparePortableCleanup({ scope: options.scope, context, selector: pluginId, agents, force: options.force, signal: options.signal })
819
888
  : await preparePortableRecovery({ scope: options.scope, context, selector: pluginId, agents,
820
889
  env: options.env, cliVersion: options.cliVersion, signal: options.signal,
821
- catalogOperationContext: demand.catalogOperationContext, excludedPluginIds: options.excludedPluginIds }, catalogReadScope);
822
- plan.portableGroups.push(prepared);
890
+ catalogOperationContext: demand.catalogOperationContext, excludedPluginIds: options.excludedPluginIds }, catalogReadScope, portableGenerations);
891
+ return { ok: true, prepared };
823
892
  }
824
893
  catch (error) {
825
- options.signal?.throwIfAborted();
826
- if (error instanceof Error && error.name === 'AbortError')
894
+ if (recoveryInterruptionCode(error, options.signal))
827
895
  throw error;
828
- for (const agent of agents)
829
- block(pair(plan, pluginId, agent), errorCode(error, 'portablePreparationFailed'));
896
+ return { ok: false, agents, pluginId, code: errorCode(error, 'portablePreparationFailed') };
830
897
  }
898
+ }, { signal: options.signal });
899
+ for (const result of preparedGroups) {
900
+ if (result.ok)
901
+ plan.portableGroups.push(result.prepared);
902
+ else
903
+ for (const agent of result.agents)
904
+ block(pair(plan, result.pluginId, agent), result.code);
831
905
  }
832
906
  for (const prepared of plan.portableGroups)
833
907
  portableResults(plan, prepared);
@@ -836,31 +910,26 @@ export async function prepareScopedRecovery(command, selectors, options, runtime
836
910
  // Complete scope demand protects copies contributed by unselected roots and their dependencies.
837
911
  const desiredAgents = new Set([...receipt.selection.agents,
838
912
  ...(demand.preferences.state === 'valid' ? demand.preferences.value.targets : [])]);
839
- const retainedPortableTargets = [];
840
- for (const root of demand.roots ?? []) {
913
+ const protection = await mapInstallReads(demand.roots ?? [], async (root) => {
841
914
  const portableAgents = [...desiredAgents].filter(isPortableAgent).filter((agent) => root.plugin
842
915
  && resolveDelivery(root.plugin.manifest, agent, options.scope)?.kind === 'agent-skills');
843
- if (!portableAgents.length)
844
- continue;
916
+ if (!portableAgents.length || plan.portableGroups.some((group) => group.options.selector === root.pluginId
917
+ && portableAgents.every((agent) => group.options.agents.includes(agent))))
918
+ return;
845
919
  try {
846
- const prepared = plan.portableGroups.find((group) => group.options.selector === root.pluginId
847
- && portableAgents.every((agent) => group.options.agents.some((item) => item === agent)))
848
- ?? await preparePortableRecovery({ scope: options.scope, context, selector: root.pluginId,
849
- env: options.env, agents: portableAgents, cliVersion: options.cliVersion, signal: options.signal,
850
- catalogOperationContext: demand.catalogOperationContext, excludedPluginIds: options.excludedPluginIds }, catalogReadScope);
851
- if (!prepared.globalBlockers.length) {
852
- retainedPortableTargets.push(...prepared.targets.filter((target) => !target.blocker && ['satisfied', 'drifted'].includes(target.observation)));
853
- if (!plan.portableGroups.includes(prepared))
854
- plan.portableProtectionGroups.push(prepared);
855
- }
920
+ const prepared = await preparePortableRecovery({ scope: options.scope, context, selector: root.pluginId,
921
+ env: options.env, agents: portableAgents, cliVersion: options.cliVersion, signal: options.signal,
922
+ catalogOperationContext: demand.catalogOperationContext, excludedPluginIds: options.excludedPluginIds }, catalogReadScope, portableGenerations);
923
+ if (!prepared.globalBlockers.length)
924
+ return prepared;
856
925
  }
857
926
  catch (error) {
858
- options.signal?.throwIfAborted();
859
- if (error instanceof Error && error.name === 'AbortError')
927
+ if (recoveryInterruptionCode(error, options.signal))
860
928
  throw error;
861
929
  // Missing current Portable evidence cannot protect historical residue.
862
930
  }
863
- }
931
+ }, { signal: options.signal });
932
+ plan.portableProtectionGroups = protection.filter((prepared) => prepared !== undefined);
864
933
  }
865
934
  options.signal?.throwIfAborted();
866
935
  await checkFootprints(plan);
@@ -944,6 +1013,234 @@ export async function activateRecoverySourcesAndReprepare(plan, execution = {})
944
1013
  await plan.context.dispose();
945
1014
  }
946
1015
  }
1016
+ function portablePrewriteBinding(context, sourceId) {
1017
+ const source = context?.catalog.sources[0]?.resolution;
1018
+ const generation = context?.generationSet.sources[0];
1019
+ if (!context || context.catalog.sources.length !== 1 || context.generationSet.sources.length !== 1
1020
+ || !source || !generation || source.sourceId !== sourceId || generation.sourceId !== sourceId
1021
+ || source.rootDir !== generation.snapshotPath || source.sourceIdentity !== generation.sourceIdentity
1022
+ || source.logicalIdentity !== generation.logicalIdentity || source.resolvedCommit !== generation.resolvedCommit
1023
+ || source.manifestDigest !== generation.manifestDigest || source.snapshotDigest !== generation.snapshotDigest)
1024
+ return;
1025
+ return JSON.stringify([context.generationSetDigest,
1026
+ createCatalogPreparationStoreKey({ ...generation, requestedRef: source.requestedRef })]);
1027
+ }
1028
+ async function recheckPortableRecovery(plan, groups = plan.portableGroups, progress) {
1029
+ const executable = groups.filter(({ options }) => !options.agents.every((agent) => pair(plan, options.selector, agent)?.blockers.length));
1030
+ const providers = new Set(executable.flatMap((group) => plan.options.portableProviderChecks?.get(group.options.selector) ?? []));
1031
+ const inspections = [
1032
+ ...executable,
1033
+ ...plan.portableProtectionGroups,
1034
+ ...providers,
1035
+ ];
1036
+ if (!inspections.length)
1037
+ return;
1038
+ const readScope = new CatalogPreparationReadScope({ env: plan.context.env, signal: plan.runtime.signal });
1039
+ const active = new Map();
1040
+ const problems = await mapInstallReads(inspections, async (prepared) => {
1041
+ let current;
1042
+ const sourceId = parsePluginId(prepared.options.selector).sourceId;
1043
+ const reviewed = prepared.options.catalogOperationContext;
1044
+ if (sourceId && reviewed && prepared.mode === 'deploy') {
1045
+ try {
1046
+ let pending = active.get(sourceId);
1047
+ if (!pending) {
1048
+ pending = readScope.resolve({ sourceIds: [sourceId] }, true);
1049
+ active.set(sourceId, pending);
1050
+ }
1051
+ current = await pending;
1052
+ const original = selectCatalogOperationContext(reviewed, [sourceId]);
1053
+ if (portablePrewriteBinding(current, sourceId) !== portablePrewriteBinding(original, sourceId)) {
1054
+ return diagnostic('operationReviewStale');
1055
+ }
1056
+ }
1057
+ catch (error) {
1058
+ if (recoveryInterruptionCode(error, plan.runtime.signal))
1059
+ throw error;
1060
+ return { ...diagnostic('operationReviewStale'), subject: { sourceId },
1061
+ detail: { reasonCode: error instanceof CatalogGenerationError ? error.code : 'catalogReadFailed' } };
1062
+ }
1063
+ }
1064
+ const checked = await inspectPortableRecovery({ ...prepared.options, catalogOperationContext: current,
1065
+ signal: plan.runtime.signal }, readScope);
1066
+ // The provider ran first. Its original missing state is never sufficient for a consumer.
1067
+ if (providers.has(prepared) && !isHealthyPortableProvider(checked)
1068
+ || !await portableReviewMatches(prepared, checked, progress?.completed))
1069
+ return diagnostic('operationReviewStale');
1070
+ }, { signal: plan.runtime.signal });
1071
+ return problems.find((problem) => problem !== undefined);
1072
+ }
1073
+ async function executeNativeGroup(plan, group, nativeRuntime) {
1074
+ const { receipt } = plan;
1075
+ const running = new Set();
1076
+ try {
1077
+ const result = await nativeOperation(plan, group.pluginIds, group.platform, false, { ...nativeRuntime, onInstallTargetState(identity, state) {
1078
+ const target = identity.scope === plan.options.scope && identity.pluginId
1079
+ ? pair(plan, identity.pluginId, identity.platform) : undefined;
1080
+ if (target && state === 'running')
1081
+ running.add(target);
1082
+ else if (target)
1083
+ running.delete(target);
1084
+ nativeRuntime.onInstallTargetState?.(identity, state);
1085
+ }, expectedPlanFingerprint: group.preview.operationPlan?.planFingerprint }, group.command, nativeGroupTargets(group));
1086
+ receipt.outputsMayHaveChanged ||= result.rebuildResults.some((result) => result.actions.some((action) => action.name === 'stale.cleanup' || action.name === 'native.write' || action.name === 'artifacts.write'
1087
+ || action.name === 'recovery.cleanup' || action.name === 'cleanup.owned'))
1088
+ || ((result.commandResults?.length ?? 0) > 0
1089
+ && result.operationPlan?.actions.some((action) => action.kind === 'syncManagedCommandPackage') === true);
1090
+ nativeResults(plan, group, result, true);
1091
+ }
1092
+ catch (error) {
1093
+ if (error instanceof RebuildInterruptedError) {
1094
+ const recorded = error.result;
1095
+ const targets = nativeGroupTargets(group).filter(({ pluginId, platform }) => recorded.targetResults.some((entry) => entry.target.pluginId === pluginId && entry.target.platform === platform));
1096
+ nativeResults(plan, { ...group, targets }, recorded, true);
1097
+ receipt.outputsMayHaveChanged ||= recorded.rebuildResults.some((entry) => entry.actions.length > 0 || entry.deploymentReceipts?.some((deployment) => deployment.effects.some((effect) => effect.mutation !== 'none')))
1098
+ || recorded.commandResults?.some((command) => command.state === 'completed') === true;
1099
+ }
1100
+ const interruption = recoveryInterruptionCode(error, nativeRuntime.signal);
1101
+ if (interruption) {
1102
+ for (const target of running) {
1103
+ target.execution = 'partial';
1104
+ target.observation = 'unknown';
1105
+ target.content = 'unknown';
1106
+ block(target, interruption);
1107
+ receipt.outputsMayHaveChanged = true;
1108
+ }
1109
+ throw error;
1110
+ }
1111
+ const code = errorCode(error, 'nativeRecoveryFailed');
1112
+ receipt.outputsMayHaveChanged ||= code !== 'preApplyAuthorizationRequired';
1113
+ for (const { pluginId, platform } of nativeGroupTargets(group)) {
1114
+ const target = pair(plan, pluginId, agentForPlatform(platform));
1115
+ target.execution = 'failed';
1116
+ block(target, code);
1117
+ }
1118
+ }
1119
+ }
1120
+ async function executePortableGroups(plan, groups, nativeRuntime, progress, jointChecked = false) {
1121
+ const { receipt } = plan;
1122
+ for (const prepared of groups) {
1123
+ let started = false;
1124
+ const onStart = () => {
1125
+ if (started)
1126
+ return;
1127
+ started = true;
1128
+ try {
1129
+ nativeRuntime.onInstallTargetState?.({ pluginId: prepared.options.selector,
1130
+ platform: 'generic', scope: plan.options.scope }, 'running');
1131
+ }
1132
+ catch { /* Display callbacks don't control execution. */ }
1133
+ };
1134
+ const providers = plan.options.portableProviderChecks?.get(prepared.options.selector);
1135
+ const checkPrewrite = jointChecked || providers?.length ? () => recheckPortableRecovery(plan, [prepared], progress) : undefined;
1136
+ const agents = [];
1137
+ for (const agent of prepared.options.agents) {
1138
+ if (pair(plan, prepared.options.selector, agent).blockers.length)
1139
+ continue;
1140
+ const outcomes = prepared.targets.filter((entry) => entry.agent === agent).map((entry) => {
1141
+ const failed = progress.failed.find((failure) => failure.logicalIdentity === prepared.logicalIdentity
1142
+ && failure.outcome.physicalPath === entry.physicalPath && failure.outcome.expectedDigest === entry.expectedDigest
1143
+ && failure.outcome.providerPluginId === entry.providerPluginId);
1144
+ return failed ? { ...failed.outcome, agent } : { ...entry, execution: 'not-run', blockers: [] };
1145
+ });
1146
+ if (outcomes.some((entry) => entry.execution === 'failed')) {
1147
+ portableOutcomes(plan, prepared, agent, outcomes, []);
1148
+ continue;
1149
+ }
1150
+ const hasScript = plan.preApplyAuthorization?.some((target) => target.platform === agent
1151
+ && portablePluginClosure(plan, prepared).some((plugin) => plugin.pluginId === target.pluginId));
1152
+ const preApply = async () => {
1153
+ onStart();
1154
+ const stale = await checkPrewrite?.();
1155
+ if (stale) {
1156
+ receipt.blockers.push(stale);
1157
+ return stale.code;
1158
+ }
1159
+ return executePortablePreApply(plan, prepared, agent, nativeRuntime);
1160
+ };
1161
+ const preApplyFailure = !hasScript ? undefined : nativeRuntime.installAdmission
1162
+ ? await nativeRuntime.installAdmission.run([{ kind: 'exclusive' }], preApply, nativeRuntime.signal) : await preApply();
1163
+ if (preApplyFailure) {
1164
+ const target = pair(plan, prepared.options.selector, agent);
1165
+ portableOutcomes(plan, prepared, agent, prepared.targets.filter((entry) => entry.agent === agent)
1166
+ .map((entry) => unobservedPortableTarget(entry, preApplyFailure)), [preApplyFailure]);
1167
+ if (preApplyFailure !== 'operationReviewStale')
1168
+ target.execution = 'failed';
1169
+ target.recoveryActions = [`aw plugin sync ${target.pluginId} --context ${target.scope} --target ${agent}`
1170
+ + (preApplyFailure === 'operationReviewStale' ? '' : ' --yes')];
1171
+ continue;
1172
+ }
1173
+ agents.push(agent);
1174
+ }
1175
+ if (!agents.length)
1176
+ continue;
1177
+ let interruption;
1178
+ const result = await executePortableRecovery({ prepared, token: nativeRuntime.awHomeMutationToken, authorizeUpdate: plan.options.yes,
1179
+ action: plan.command === 'install' ? 'sync' : plan.command, force: plan.options.force,
1180
+ targets: prepared.targets.filter((target) => agents.includes(target.agent)).map(({ skill, agent }) => ({ skill, agent })),
1181
+ progress, checkPrewrite, readProviders: providers, onStart, admission: nativeRuntime.installAdmission, signal: nativeRuntime.signal }).catch((error) => {
1182
+ if (!(error instanceof PortableInterruptedError))
1183
+ throw error;
1184
+ interruption = error;
1185
+ return error.result;
1186
+ });
1187
+ if (result.reviewProblem)
1188
+ receipt.blockers.push(result.reviewProblem);
1189
+ receipt.outputsMayHaveChanged ||= result.outputsMayHaveChanged;
1190
+ for (const agent of agents) {
1191
+ portableOutcomes(plan, prepared, agent, result.targets.filter((entry) => entry.agent === agent), result.globalBlockers);
1192
+ if (interruption && result.outputsMayHaveChanged) {
1193
+ const target = pair(plan, prepared.options.selector, agent);
1194
+ if (target.execution === 'failed')
1195
+ target.execution = 'partial';
1196
+ }
1197
+ }
1198
+ if (interruption)
1199
+ throw interruption.cause;
1200
+ }
1201
+ }
1202
+ /** The joint coordinator holds the write lock and has checked this complete child against Review. */
1203
+ export async function executeCheckedScopedInstall(child, execution) {
1204
+ if (!execution.runtime.awHomeMutationToken || child.command !== 'sync' && child.command !== 'reinstall') {
1205
+ throw new Error('checkedScopedInstallUnavailable');
1206
+ }
1207
+ const selected = (pluginId) => !execution.pluginIds || execution.pluginIds.includes(pluginId);
1208
+ const receipt = structuredClone({ ...child.receipt,
1209
+ targetResults: child.receipt.targetResults.filter((target) => selected(target.pluginId)),
1210
+ requestedRoots: child.receipt.requestedRoots.filter(selected),
1211
+ });
1212
+ const plan = { ...child, receipt, runtime: { ...child.runtime, ...execution.runtime }, options: { ...child.options, yes: execution.yes ?? child.options.yes } };
1213
+ if (receipt.nativeToolChanges?.length && plan.options.yes !== true) {
1214
+ receipt.blockers.push(diagnostic('nativeToolAuthorizationRequired'));
1215
+ return completeReceipt(receipt);
1216
+ }
1217
+ if (plan.blockExecution)
1218
+ return completeReceipt(receipt);
1219
+ const runtime = plan.runtime;
1220
+ try {
1221
+ for (const group of plan.nativeGroups) {
1222
+ const targets = nativeGroupTargets(group);
1223
+ const blocked = new Map();
1224
+ for (const { pluginId, platform } of targets) {
1225
+ const code = pair(plan, pluginId, platform)?.blockers[0]?.code;
1226
+ if (code)
1227
+ blocked.set([pluginId, platform, plan.options.scope].join('\0'), code);
1228
+ }
1229
+ if (blocked.size === targets.length)
1230
+ continue;
1231
+ await executeNativeGroup(plan, group, { ...runtime, nativeInstallBlockers: blocked });
1232
+ }
1233
+ await executePortableGroups(plan, plan.portableGroups.filter((group) => selected(group.options.selector)), runtime, execution.portableProgress, true);
1234
+ return completeReceipt(receipt);
1235
+ }
1236
+ catch (error) {
1237
+ const code = recoveryInterruptionCode(error, runtime.signal);
1238
+ if (!code)
1239
+ throw error;
1240
+ receipt.blockers.push(diagnostic(code));
1241
+ throw new RecoveryInterruptedError(completeReceipt(receipt), error);
1242
+ }
1243
+ }
947
1244
  export async function executeScopedRecovery(plan, execution = {}) {
948
1245
  if (plan.sourceRefreshes.length > 0) {
949
1246
  const receipt = structuredClone(plan.receipt);
@@ -975,8 +1272,11 @@ export async function executeScopedRecovery(plan, execution = {}) {
975
1272
  }
976
1273
  return await withAwHomeMutationLock({ env: plan.options.env, token: plan.runtime.awHomeMutationToken,
977
1274
  action: async (token) => {
978
- const actualIntent = await observeIntent(plan.options);
979
- const current = await readDemand({ ...plan.options, preferences: undefined, ...(plan.declaration || plan.options.demandOverride ? { intent: plan.demand.intent } : {}) });
1275
+ const [actualIntent, current] = await Promise.all([
1276
+ observeIntent(plan.options),
1277
+ readDemand({ ...plan.options, preferences: undefined,
1278
+ ...(plan.declaration || plan.options.demandOverride ? { intent: plan.demand.intent } : {}) }),
1279
+ ]);
980
1280
  if (intentEvidence(actualIntent) !== plan.originalIntent || preferenceEvidence(current) !== plan.preferencesEvidence
981
1281
  || current.catalogOperationContext?.generationSetDigest !== plan.demand.catalogOperationContext?.generationSetDigest) {
982
1282
  receipt.blockers.push(diagnostic('operationReviewStale'));
@@ -996,37 +1296,29 @@ export async function executeScopedRecovery(plan, execution = {}) {
996
1296
  ...(session ? { codexObservationSession: session } : {}) };
997
1297
  try {
998
1298
  // Freeze every backend before the first declaration or output write.
999
- const executableNativeGroups = [];
1000
- for (const group of plan.nativeGroups) {
1299
+ const recheckedGroups = await readNativeGroups(plan.nativeGroups, async (group) => {
1001
1300
  const targets = nativeGroupTargets(group);
1002
1301
  const executable = targets.filter(({ pluginId, platform }) => !pair(plan, pluginId, agentForPlatform(platform)).blockers.length);
1003
- if (executable.length === 0)
1004
- continue;
1302
+ if (!executable.length)
1303
+ return;
1005
1304
  const checked = await nativeOperation(plan, group.pluginIds, group.platform, true, nativeRuntime, group.command, targets);
1006
- if (checked.operationPlan?.planFingerprint !== group.preview.operationPlan?.planFingerprint) {
1007
- receipt.blockers.push(diagnostic('operationReviewStale'));
1008
- return completeReceipt(receipt);
1009
- }
1305
+ if (checked.operationPlan?.planFingerprint !== group.preview.operationPlan?.planFingerprint)
1306
+ return 'stale';
1010
1307
  const selection = nativeTargetSelection(executable);
1011
1308
  const preview = executable.length === targets.length ? checked
1012
1309
  : await nativeOperation(plan, selection.pluginIds, selection.platform, true, nativeRuntime, group.command, executable);
1013
- executableNativeGroups.push({ ...group, ...selection, preview });
1014
- }
1015
- for (const prepared of plan.portableGroups) {
1016
- if (prepared.options.agents.every((agent) => pair(plan, prepared.options.selector, agent).blockers.length))
1017
- continue;
1018
- const checked = await inspectPortableRecovery(prepared.options);
1019
- if (checked.evidenceDigest !== prepared.evidenceDigest) {
1020
- receipt.blockers.push(diagnostic('operationReviewStale'));
1021
- return completeReceipt(receipt);
1022
- }
1310
+ return { ...group, ...selection, preview };
1311
+ }, nativeRuntime.signal);
1312
+ if (recheckedGroups.includes('stale')) {
1313
+ receipt.blockers.push(diagnostic('operationReviewStale'));
1314
+ return completeReceipt(receipt);
1023
1315
  }
1024
- for (const prepared of plan.portableProtectionGroups) {
1025
- const checked = await inspectPortableRecovery(prepared.options);
1026
- if (checked.evidenceDigest !== prepared.evidenceDigest) {
1027
- receipt.blockers.push(diagnostic('operationReviewStale'));
1028
- return completeReceipt(receipt);
1029
- }
1316
+ const executableNativeGroups = recheckedGroups.filter((group) => group !== undefined && group !== 'stale');
1317
+ const portableProgress = execution.portableProgress ?? { completed: [], failed: [] };
1318
+ const portableBlocker = await recheckPortableRecovery(plan, plan.portableGroups, portableProgress);
1319
+ if (portableBlocker) {
1320
+ receipt.blockers.push(portableBlocker);
1321
+ return completeReceipt(receipt);
1030
1322
  }
1031
1323
  for (const residue of plan.portableResidues) {
1032
1324
  const checked = await inspectPortableResidue({ scope: plan.options.scope, context: plan.context,
@@ -1057,71 +1349,9 @@ export async function executeScopedRecovery(plan, execution = {}) {
1057
1349
  return completeReceipt(receipt);
1058
1350
  }
1059
1351
  }
1060
- for (const group of executableNativeGroups) {
1061
- try {
1062
- const result = await nativeOperation(plan, group.pluginIds, group.platform, false, { ...nativeRuntime,
1063
- ...(group.preview.operationPlan
1064
- ? { expectedPlanFingerprint: group.preview.operationPlan.planFingerprint } : {}) }, group.command, nativeGroupTargets(group));
1065
- receipt.outputsMayHaveChanged ||= result.rebuildResults.some((result) => result.actions.some((action) => action.name === 'stale.cleanup' || action.name === 'native.write' || action.name === 'artifacts.write'
1066
- || action.name === 'recovery.cleanup' || action.name === 'cleanup.owned'))
1067
- || ((result.commandResults?.length ?? 0) > 0
1068
- && result.operationPlan?.actions.some((action) => action.kind === 'syncManagedCommandPackage') === true);
1069
- nativeResults(plan, group, result, true);
1070
- }
1071
- catch (error) {
1072
- const code = errorCode(error, 'nativeRecoveryFailed');
1073
- receipt.outputsMayHaveChanged ||= code !== 'preApplyAuthorizationRequired';
1074
- for (const { pluginId, platform } of nativeGroupTargets(group)) {
1075
- const target = pair(plan, pluginId, agentForPlatform(platform));
1076
- target.execution = 'failed';
1077
- block(target, code);
1078
- }
1079
- }
1080
- }
1081
- const completedFootprints = [];
1082
- const failedFootprints = [];
1083
- for (const prepared of plan.portableGroups) {
1084
- const agents = [];
1085
- for (const agent of prepared.options.agents) {
1086
- if (pair(plan, prepared.options.selector, agent).blockers.length)
1087
- continue;
1088
- const outcomes = prepared.targets.filter((entry) => entry.agent === agent).map((entry) => {
1089
- const failed = failedFootprints.find((failure) => failure.logicalIdentity === prepared.logicalIdentity
1090
- && failure.outcome.physicalPath === entry.physicalPath && failure.outcome.expectedDigest === entry.expectedDigest
1091
- && failure.outcome.providerPluginId === entry.providerPluginId);
1092
- return failed ? { ...failed.outcome, agent } : { ...entry, execution: 'not-run', blockers: [] };
1093
- });
1094
- if (outcomes.some((entry) => entry.execution === 'failed')) {
1095
- portableOutcomes(plan, prepared, agent, outcomes, []);
1096
- continue;
1097
- }
1098
- const preApplyFailure = await executePortablePreApply(plan, prepared, agent, nativeRuntime);
1099
- if (preApplyFailure) {
1100
- const target = pair(plan, prepared.options.selector, agent);
1101
- target.execution = 'failed';
1102
- block(target, preApplyFailure);
1103
- target.recoveryActions = [`aw plugin sync ${target.pluginId} --context ${target.scope} --target ${agent} --yes`];
1104
- continue;
1105
- }
1106
- agents.push(agent);
1107
- }
1108
- if (!agents.length)
1109
- continue;
1110
- const result = await executePortableRecovery({ prepared, token, authorizeUpdate: plan.options.yes,
1111
- action: plan.command === 'install' ? 'sync' : plan.command, force: plan.options.force,
1112
- targets: prepared.targets.filter((target) => agents.includes(target.agent)).map(({ skill, agent }) => ({ skill, agent })),
1113
- completedFootprints });
1114
- receipt.outputsMayHaveChanged ||= result.outputsMayHaveChanged;
1115
- for (const agent of agents) {
1116
- portableOutcomes(plan, prepared, agent, result.targets.filter((entry) => entry.agent === agent), result.globalBlockers);
1117
- }
1118
- failedFootprints.push(...result.targets.filter((target) => target.execution === 'failed')
1119
- .map((outcome) => ({ logicalIdentity: prepared.logicalIdentity, outcome })));
1120
- completedFootprints.push(...result.targets.filter((target) => target.observation === 'satisfied'
1121
- && ['applied', 'no-op'].includes(target.execution) && target.blockers.length === 0)
1122
- .map(({ physicalPath, expectedDigest, providerPluginId }) => ({ physicalPath, expectedDigest, providerPluginId,
1123
- logicalIdentity: prepared.logicalIdentity })));
1124
- }
1352
+ for (const group of executableNativeGroups)
1353
+ await executeNativeGroup(plan, group, nativeRuntime);
1354
+ await executePortableGroups(plan, plan.portableGroups, nativeRuntime, portableProgress);
1125
1355
  for (const { kind, pluginId, observation } of plan.portableResidues) {
1126
1356
  if (kind !== 'cleanup')
1127
1357
  continue;
@@ -1243,6 +1473,8 @@ export function describeRecoveryPlan(plan) {
1243
1473
  nativeActivationOnlyTargets: child.options.nativeActivationOnlyTargets,
1244
1474
  nativePlannedRetirements: child.options.nativePlannedRetirements,
1245
1475
  portable: child.portableGroups.map((group) => group.evidenceDigest),
1476
+ inheritedPortable: child.options.portableProviderChecks?.size
1477
+ ? [...child.options.portableProviderChecks].map(([root, providers]) => [root, providers.map((item) => item.evidenceDigest)]) : undefined,
1246
1478
  protectedPortable: child.portableProtectionGroups.map((group) => group.evidenceDigest),
1247
1479
  residue: child.portableResidues, blockers: child.receipt.blockers,
1248
1480
  targetBlockers: child.receipt.targetResults.map((target) => target.blockers),