@lesliechan721/aw 0.1.0-beta.83 → 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 (179) 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 +13 -3
  28. package/dist/src/commands/rebuild-platform-integration.js +229 -133
  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 +18 -4
  77. package/dist/src/recovery/coordinator.js +357 -165
  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 +671 -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/console-app-v4.d.ts +1 -1
  113. package/dist/src/tui/console-app-v4.js +137 -57
  114. package/dist/src/tui/console-app-v4.js.map +1 -1
  115. package/dist/src/tui/controller-runtime.js +45 -9
  116. package/dist/src/tui/controller-runtime.js.map +1 -1
  117. package/dist/src/tui/controller.d.ts +13 -4
  118. package/dist/src/tui/controller.js +233 -102
  119. package/dist/src/tui/controller.js.map +1 -1
  120. package/dist/src/tui/deployment-view.js +6 -1
  121. package/dist/src/tui/deployment-view.js.map +1 -1
  122. package/dist/src/tui/diagnostic-projection.d.ts +4 -2
  123. package/dist/src/tui/diagnostic-projection.js +40 -4
  124. package/dist/src/tui/diagnostic-projection.js.map +1 -1
  125. package/dist/src/tui/operation-diagnostic-screens.d.ts +1 -1
  126. package/dist/src/tui/operation-diagnostic-screens.js +3 -1
  127. package/dist/src/tui/operation-diagnostic-screens.js.map +1 -1
  128. package/dist/src/tui/operation-history.d.ts +6 -3
  129. package/dist/src/tui/operation-history.js +15 -2
  130. package/dist/src/tui/operation-history.js.map +1 -1
  131. package/dist/src/tui/scoped-flow.d.ts +3 -1
  132. package/dist/src/tui/scoped-flow.js +99 -1
  133. package/dist/src/tui/scoped-flow.js.map +1 -1
  134. package/dist/src/tui/session-console-app.d.ts +2 -0
  135. package/dist/src/tui/session-console-app.js +11 -0
  136. package/dist/src/tui/session-console-app.js.map +1 -1
  137. package/dist/src/types.d.ts +8 -1
  138. package/dist/src/types.js.map +1 -1
  139. package/dist/src/utils/aw-home-mutation-lock.js +2 -1
  140. package/dist/src/utils/aw-home-mutation-lock.js.map +1 -1
  141. package/dist/src/utils/catalog-source-references.js +2 -14
  142. package/dist/src/utils/catalog-source-references.js.map +1 -1
  143. package/dist/src/utils/component-resources.js +1 -1
  144. package/dist/src/utils/component-resources.js.map +1 -1
  145. package/dist/src/utils/managed-command-materialization.d.ts +2 -1
  146. package/dist/src/utils/managed-command-materialization.js +3 -3
  147. package/dist/src/utils/managed-command-materialization.js.map +1 -1
  148. package/dist/src/utils/managed-command-store.d.ts +6 -0
  149. package/dist/src/utils/managed-command-store.js +90 -18
  150. package/dist/src/utils/managed-command-store.js.map +1 -1
  151. package/dist/src/utils/multi-source-catalog.d.ts +2 -0
  152. package/dist/src/utils/multi-source-catalog.js +3 -2
  153. package/dist/src/utils/multi-source-catalog.js.map +1 -1
  154. package/dist/src/utils/native-cli.d.ts +0 -19
  155. package/dist/src/utils/native-cli.js +2 -42
  156. package/dist/src/utils/native-cli.js.map +1 -1
  157. package/dist/src/utils/ownership.js +1 -1
  158. package/dist/src/utils/ownership.js.map +1 -1
  159. package/dist/src/utils/platform-empty-state.d.ts +1 -3
  160. package/dist/src/utils/platform-empty-state.js +1 -6
  161. package/dist/src/utils/platform-empty-state.js.map +1 -1
  162. package/dist/src/utils/plugin-config-write.d.ts +8 -0
  163. package/dist/src/utils/plugin-config-write.js +89 -25
  164. package/dist/src/utils/plugin-config-write.js.map +1 -1
  165. package/dist/src/utils/plugin-scripts.js +5 -0
  166. package/dist/src/utils/plugin-scripts.js.map +1 -1
  167. package/dist/src/utils/skill-invocation-warning.d.ts +15 -0
  168. package/dist/src/utils/skill-invocation-warning.js +42 -0
  169. package/dist/src/utils/skill-invocation-warning.js.map +1 -0
  170. package/package.json +3 -3
  171. package/dist/src/output/native-consent.d.ts +0 -2
  172. package/dist/src/output/native-consent.js +0 -5
  173. package/dist/src/output/native-consent.js.map +0 -1
  174. package/dist/src/platforms/gemini-activation.d.ts +0 -36
  175. package/dist/src/platforms/gemini-activation.js +0 -331
  176. package/dist/src/platforms/gemini-activation.js.map +0 -1
  177. package/dist/src/platforms/gemini-consent.d.ts +0 -8
  178. package/dist/src/platforms/gemini-consent.js +0 -81
  179. package/dist/src/platforms/gemini-consent.js.map +0 -1
@@ -1,4 +1,5 @@
1
1
  import type { RecoveryPlan } from '../recovery/coordinator.js';
2
+ import { RecoveryInterruptedError } from '../recovery/interruption.js';
2
3
  import type { PreApplyAuthorizationTarget, RebuildCommandRuntime } from '../commands/rebuild-command.js';
3
4
  import { type PlatformTarget } from '@lesliechan721/aw-plugin-core/manifest';
4
5
  import { syncWriteCommand } from '../commands/write-commands.js';
@@ -117,6 +118,13 @@ export interface PreparedPluginConfigApply {
117
118
  /** Prepare the same existing-output plan used by apply, without saving config or output. */
118
119
  export declare function preparePluginConfigApply(options: ApplyPluginConfigOptions): Promise<PreparedPluginConfigApply>;
119
120
  export declare function disposePluginConfigApply(plan: RecoveryPlan): Promise<void>;
121
+ export declare class ConfigApplyInterruptedError extends Error {
122
+ readonly apply: ConfigApplyResult;
123
+ readonly code: string;
124
+ readonly operationDiagnostic: import("./safe-operation-diagnostic.js").SafeOperationErrorMetadata;
125
+ configWrite: 'notStarted' | 'succeeded';
126
+ constructor(error: RecoveryInterruptedError, apply: ConfigApplyResult, signal?: AbortSignal);
127
+ }
120
128
  export declare function applyPluginConfig(options: ApplyPluginConfigOptions): Promise<{
121
129
  configWrite: 'notStarted';
122
130
  overallState: RebuildReceiptOverallState;
@@ -1,9 +1,12 @@
1
1
  import { resolveWorkContext } from '../intent/work-context.js';
2
+ import { RecoveryInterruptedError, recoveryInterruptionCode } from '../recovery/interruption.js';
2
3
  import { readDemand, demandNativeProjection } from '../recovery/demand.js';
3
4
  import { createScopeContext } from '../intent/scope-context.js';
5
+ import { nativeDeploymentHasVerifiedComponentWrite } from '../commands/rebuild-platform-integration.js';
4
6
  import { selectPluginConfigProfile, NATIVE_PLATFORM_TARGETS, getCommandPackageId } from '@lesliechan721/aw-plugin-core/manifest';
5
7
  import { readScopedRecoveryStatus } from '../recovery/status.js';
6
8
  import { syncWriteCommand } from '../commands/write-commands.js';
9
+ import { skillInvocationDiagnostics } from '../output/skill-invocation-notices.js';
7
10
  import { CONFIG_MUTATION_RECEIPT_SCHEMA_VERSION, } from '../types.js';
8
11
  import { getDefaultNativeCliRunner, prepareNativeCliExecution } from './native-cli.js';
9
12
  import { assertPluginConfigMutationCandidate, assertSafePluginConfigSegment, coercePluginConfigUpdates, patchPluginConfigStore, PluginConfigSchemaResolutionError, readPluginConfigStore, readNamespacedPluginConfigStoreIdentity, resetPluginConfigStore, resolveConfigRead, resolveEffectivePluginConfig, resolvePluginConfigStorePath, resolvePluginConfigSchemaAccess, summarizeEffectivePluginConfig, } from './plugin-config.js';
@@ -11,7 +14,7 @@ import { analyzePluginConfigMutationImpact, discoverPluginConfigManagedCommandPa
11
14
  import { collectPluginConfigReferenceEvidence, resolvePluginConfigReferencePlugins, resolvePluginConfigReferenceConsumers } from './plugin-config-references.js';
12
15
  import { orderPluginMetasByDependencies, resolvePluginMetaDependencyClosure } from './plugin-dependencies.js';
13
16
  import { assertManagedCommandPackageNativeToolsUnchanged, discoverInstalledPluginManagedCommandPackages, syncPluginManagedCommandPackage, } from './managed-command-materialization.js';
14
- import { listManagedCommandPackages, managedCommandDiagnostic, readInstalledCommandProducer } from './managed-command-store.js';
17
+ import { captureManagedCommandPackageEvidence, listManagedCommandPackages, managedCommandDiagnostic } from './managed-command-store.js';
15
18
  import { collectSensitivePluginConfigValues, redactPluginScriptOutput, } from './plugin-scripts.js';
16
19
  import { resolveClaudeProjectKey, resolveCodexProjectKey, resolveCliPackageRoot } from './paths.js';
17
20
  import { createProjectLocationKey, resolveRequiredCanonicalRepoRoot } from './state-paths.js';
@@ -20,7 +23,6 @@ import { withAwHomeMutationLock, } from './aw-home-mutation-lock.js';
20
23
  import fs from 'fs-extra';
21
24
  import path from 'node:path';
22
25
  import { parsePluginId } from './multi-source-catalog.js';
23
- import crypto from 'node:crypto';
24
26
  export function buildConfigMutationReceipt(command, receipt) {
25
27
  return {
26
28
  ...receipt,
@@ -38,6 +40,7 @@ function publicConfigApplyTargetResult(result) {
38
40
  },
39
41
  action: result.action,
40
42
  state: result.state,
43
+ ...(result.partialDelivery ? { partialDelivery: true } : {}),
41
44
  ...(result.message ? { message: result.message } : {}),
42
45
  ...(result.errorCode ? { errorCode: result.errorCode } : {}),
43
46
  ...(result.relation ? { relation: result.relation } : {}),
@@ -483,7 +486,7 @@ async function reinstallVisibleTargets(options) {
483
486
  try {
484
487
  result = await syncPluginManagedCommandPackage({
485
488
  plugin: options.plugin, packageKey: target.packageKey, scope: target.producer.scope,
486
- cwd: options.cwd, env: options.env, managedCommandProducerCache,
489
+ cwd: options.cwd, env: options.env, managedCommandProducerCache, expectedPackage: target.expectedPackage,
487
490
  referencePlugins: options.rebuildRuntime?.referencePlugins,
488
491
  event: options.changedConfigKeys?.length ? 'refresh' : 'install',
489
492
  changedConfigKeys: options.changedConfigKeys ?? [],
@@ -492,9 +495,7 @@ async function reinstallVisibleTargets(options) {
492
495
  });
493
496
  }
494
497
  catch (error) {
495
- if (options.rebuildRuntime?.signal?.aborted
496
- || error instanceof Error && error.name === 'AbortError'
497
- || readSafeOperationError(error))
498
+ if (recoveryInterruptionCode(error, options.rebuildRuntime?.signal) || readSafeOperationError(error))
498
499
  throw error;
499
500
  result = {
500
501
  producer: target.producer, state: 'failed', commandIds: [], removedCommandIds: [],
@@ -882,7 +883,7 @@ async function prepareConfigApplyPackages(options, plugins, plan, referencePlugi
882
883
  const entries = await Promise.all(packages.map(async (target) => {
883
884
  const plugin = plugins.find((entry) => entry.manifest.name === target.producer.pluginName);
884
885
  const installed = inventory.packages.find((entry) => entry.id === target.packageId);
885
- let recordDigest;
886
+ let expectedPackage;
886
887
  let blocker;
887
888
  if (!target.installed || !installed) {
888
889
  blocker = { code: 'configApplyRequiresExistingOutput', message: 'Configuration apply requires an existing command package. Run package sync first.' };
@@ -892,44 +893,46 @@ async function prepareConfigApplyPackages(options, plugins, plan, referencePlugi
892
893
  }
893
894
  else {
894
895
  try {
895
- const record = await readInstalledCommandProducer(installed.resourceRoot);
896
- recordDigest = `sha256:${crypto.createHash('sha256').update(JSON.stringify(record)).digest('hex')}`;
897
896
  await assertManagedCommandPackageNativeToolsUnchanged({ plugin, producer: target.producer, env });
897
+ expectedPackage = await captureManagedCommandPackageEvidence(installed, env);
898
898
  }
899
899
  catch (error) {
900
900
  blocker = managedCommandDiagnostic(error);
901
901
  }
902
902
  }
903
- return { target, recordDigest, blocker };
903
+ return { target, expectedPackage, blocker };
904
904
  }));
905
905
  const errors = [...new Map(discoveries.flatMap((discovery) => discovery.errors).map((error) => [JSON.stringify(error), error])).values()];
906
906
  const evidence = { packages: entries, errors };
907
- const targets = [...new Map(entries.map(({ target }) => {
908
- const plugin = plugins.find((entry) => entry.manifest.name === target.producer.pluginName);
909
- const pluginId = plugin.pluginId ?? plugin.manifest.name;
910
- const dependencies = resolvePluginMetaDependencyClosure(referencePlugins, [plugin.manifest.name])
911
- .filter((entry) => entry.manifest.name !== plugin.manifest.name).map((entry) => entry.pluginId ?? entry.manifest.name);
912
- return [`${pluginId}\0${target.producer.scope}`, { pluginId, scope: target.producer.scope, dependencies }];
913
- })).values()];
907
+ const targets = entries.map(({ target }) => {
908
+ const plugin = plugins.find((entry) => entry.manifest.name === target.producer.pluginName);
909
+ const pluginId = plugin.pluginId ?? plugin.manifest.name;
910
+ const dependencies = resolvePluginMetaDependencyClosure(referencePlugins, [plugin.manifest.name])
911
+ .filter((entry) => entry.manifest.name !== plugin.manifest.name).map((entry) => entry.pluginId ?? entry.manifest.name);
912
+ const declaration = plugin.manifest.managedCommands?.packages.find((item) => item.key === target.packageKey && item.scope === target.producer.scope);
913
+ return { pluginId, scope: target.producer.scope, packageId: target.packageId, platforms: declaration?.platforms ?? [], dependencies };
914
+ });
914
915
  const cache = plan.runtime.managedCommandProducerCache ??= new Map();
915
916
  const hook = { targets, evidence,
916
- blocked: (pluginId, scope, code) => {
917
+ blocked: (pluginId, scope, code, packageId) => {
917
918
  const plugin = plugins.find((entry) => (entry.pluginId ?? entry.manifest.name) === pluginId);
918
- return entries.filter(({ target }) => target.producer.pluginName === plugin.manifest.name && target.producer.scope === scope)
919
+ return entries.filter(({ target }) => target.producer.pluginName === plugin.manifest.name && target.producer.scope === scope
920
+ && (!packageId || target.packageId === packageId))
919
921
  .map(({ target }) => ({
920
922
  producer: target.producer, state: 'failed', commandIds: [], removedCommandIds: [],
921
- errors: [{ code, message: 'A required provider failed; the command package was not refreshed.' }],
923
+ errors: [{ code, message: 'The command package refresh did not complete.' }],
922
924
  recoveryActions: [`aw command package sync ${pluginId} ${target.packageKey} --scope ${scope} --yes`],
923
925
  }));
924
926
  },
925
- execute: async (pluginId, scope, token) => {
927
+ execute: async (pluginId, scope, token, packageId) => {
926
928
  const plugin = plugins.find((entry) => (entry.pluginId ?? entry.manifest.name) === pluginId);
927
- const selected = entries.filter(({ target }) => target.producer.pluginName === plugin.manifest.name && target.producer.scope === scope);
929
+ const selected = entries.filter(({ target }) => target.producer.pluginName === plugin.manifest.name && target.producer.scope === scope
930
+ && (!packageId || target.packageId === packageId));
928
931
  const results = [];
929
932
  let executionContext;
930
933
  try {
931
934
  executionContext = await createScopeContext({ scope, cwd: options.cwd, env });
932
- for (const { target, blocker } of selected) {
935
+ for (const { target, expectedPackage, blocker } of selected) {
933
936
  if (blocker) {
934
937
  const result = { producer: target.producer, state: 'failed', commandIds: [], removedCommandIds: [],
935
938
  errors: [blocker], recoveryActions: [target.declared
@@ -942,7 +945,7 @@ async function prepareConfigApplyPackages(options, plugins, plan, referencePlugi
942
945
  const applied = await reinstallVisibleTargets({ plugin, scope, cwd: executionContext.executionCwd, env: executionContext.env,
943
946
  changedConfigKeys: [...target.refreshKeys],
944
947
  rebuildRuntime: { ...options.rebuildRuntime, awHomeMutationToken: token, referencePlugins, managedCommandProducerCache: cache },
945
- discovered: { targets: [], failures: [], commandPackages: [target], commandDiscoveryErrors: [] } });
948
+ discovered: { targets: [], failures: [], commandPackages: [{ ...target, expectedPackage }], commandDiscoveryErrors: [] } });
946
949
  results.push(...('commandResults' in applied ? applied.commandResults ?? [] : []));
947
950
  }
948
951
  return results;
@@ -992,6 +995,7 @@ export async function preparePluginConfigApply(options) {
992
995
  context,
993
996
  cwd: options.cwd,
994
997
  env: options.env,
998
+ signal: options.rebuildRuntime?.signal,
995
999
  cliVersion: version,
996
1000
  existingOnly: true,
997
1001
  ...(exactTargets ? { exactTargets } : {}),
@@ -1043,6 +1047,41 @@ export async function disposePluginConfigApply(plan) {
1043
1047
  await disposePluginConfigApply(child);
1044
1048
  await plan.context.dispose();
1045
1049
  }
1050
+ export class ConfigApplyInterruptedError extends Error {
1051
+ apply;
1052
+ code;
1053
+ operationDiagnostic;
1054
+ configWrite = 'notStarted';
1055
+ constructor(error, apply, signal) {
1056
+ super(error.code === 'operationInterrupted' && signal?.reason instanceof Error ? signal.reason.message : error.message);
1057
+ this.apply = apply;
1058
+ this.code = error.code;
1059
+ this.operationDiagnostic = readSafeOperationError(error.cause) ?? error.operationDiagnostic;
1060
+ }
1061
+ }
1062
+ function configApplyHasPartialDelivery(target) {
1063
+ if (target.execution !== 'partial')
1064
+ return false;
1065
+ if (skillInvocationDiagnostics([target]).some(({ subject }) => subject?.pluginId === target.pluginId
1066
+ && subject.target === target.agent && subject.scope === target.scope))
1067
+ return true;
1068
+ if (target.delivery?.kind === 'native') {
1069
+ return target.deploymentReceipts?.some((receipt) => {
1070
+ const plan = target.deploymentPlans?.find(({ binding }) => binding.id === receipt.bindingId);
1071
+ return plan && nativeDeploymentHasVerifiedComponentWrite(plan, receipt);
1072
+ }) ?? false;
1073
+ }
1074
+ if (target.delivery?.kind !== 'agent-skills' || !Array.isArray(target.backend))
1075
+ return false;
1076
+ return target.backend.some((entry) => {
1077
+ if (!entry || typeof entry !== 'object')
1078
+ return false;
1079
+ const outcome = entry;
1080
+ return typeof outcome.skill === 'string' && outcome.observation === 'satisfied'
1081
+ && (outcome.execution === 'applied' || outcome.execution === 'no-op')
1082
+ && Array.isArray(outcome.blockers) && outcome.blockers.length === 0;
1083
+ });
1084
+ }
1046
1085
  export async function applyPluginConfig(options) {
1047
1086
  return withAwHomeMutationLock({ env: options.env, token: options.awHomeMutationToken, action: async (token) => {
1048
1087
  await options.reviewPreflight?.();
@@ -1068,9 +1107,15 @@ export async function applyPluginConfig(options) {
1068
1107
  const discoveryErrors = prepared.commandDiscoveryErrors.map((error) => ({
1069
1108
  stage: 'targetDiscovery', code: error.code, message: error.message,
1070
1109
  }));
1110
+ let interruption;
1071
1111
  const receipt = await executeRecovery(prepared.plan, {
1072
1112
  yes: options.sharedNativeApplyConfirmed === true || options.preApplyConfirmed === true,
1073
1113
  runtime: { ...options.rebuildRuntime, awHomeMutationToken: token, preApplyConfirmed: options.preApplyConfirmed },
1114
+ }).catch((error) => {
1115
+ if (!(error instanceof RecoveryInterruptedError))
1116
+ throw error;
1117
+ interruption = error;
1118
+ return error.receipt;
1074
1119
  });
1075
1120
  const retainedLegacyTargets = prepared.retainedLegacyTargets.filter((target) => !receipt.targetResults.some((result) => (target.pluginId ? result.pluginId === target.pluginId : result.pluginId.split('/').at(-1) === target.pluginName)
1076
1121
  && result.agent === target.platform && result.scope === target.scope));
@@ -1079,6 +1124,7 @@ export async function applyPluginConfig(options) {
1079
1124
  const errors = [...discoveryErrors, ...receipt.blockers, ...receipt.errors].map((error) => ({
1080
1125
  stage: 'stage' in error ? error.stage : 'apply', code: error.code, message: error.message,
1081
1126
  }));
1127
+ const diagnostics = skillInvocationDiagnostics(receipt.targetResults);
1082
1128
  const apply = {
1083
1129
  state: ok ? 'succeeded' : 'partial',
1084
1130
  targetResults: [...receipt.targetResults.filter((target) => target.satisfaction !== 'unsupported' && target.satisfaction !== 'excluded').map((target) => ({
@@ -1087,6 +1133,9 @@ export async function applyPluginConfig(options) {
1087
1133
  action: 'refresh',
1088
1134
  state: target.execution === 'applied' || target.execution === 'no-op' ? 'completed'
1089
1135
  : target.execution === 'not-run' ? 'skipped' : 'failed',
1136
+ ...(target.relation === 'root' ? { relation: 'requested' } : target.relation === 'dependency' ? { relation: 'dependency' } : {}),
1137
+ ...(target.requiredBy.length ? { requiredBy: target.requiredBy } : {}),
1138
+ ...(configApplyHasPartialDelivery(target) ? { partialDelivery: true } : {}),
1090
1139
  ...(target.blockers.length ? { errorCode: target.blockers[0].code,
1091
1140
  message: target.blockers.map((item) => item.message).join(' ') } : {}),
1092
1141
  })), ...retainedLegacyTargets.map((target) => ({
@@ -1094,8 +1143,12 @@ export async function applyPluginConfig(options) {
1094
1143
  message: 'The inactive legacy output was preserved. Configuration apply does not create an activation.',
1095
1144
  }))],
1096
1145
  commandResults: receipt.commandResults,
1146
+ ...(receipt.reviewedUserRoots !== undefined ? { reviewedUserRoots: receipt.reviewedUserRoots } : {}),
1097
1147
  ...(errors.length ? { errors } : {}),
1148
+ ...(diagnostics.length ? { diagnostics } : {}),
1098
1149
  };
1150
+ if (interruption)
1151
+ throw new ConfigApplyInterruptedError(interruption, apply, options.rebuildRuntime?.signal);
1099
1152
  return { configWrite: 'notStarted', overallState: ok ? 'succeeded' : 'partial', apply,
1100
1153
  otherProjectsMayRequireSync: true };
1101
1154
  }
@@ -1282,6 +1335,12 @@ export async function applyPluginConfigWrite(options) {
1282
1335
  'config.json',
1283
1336
  ].filter(Boolean).join('/')}`);
1284
1337
  }
1338
+ if (error instanceof ConfigApplyInterruptedError) {
1339
+ error.message = message;
1340
+ if (configCommitted)
1341
+ error.configWrite = 'succeeded';
1342
+ throw error;
1343
+ }
1285
1344
  const safeError = new Error(message);
1286
1345
  const code = error.code;
1287
1346
  safeError.code = typeof code === 'string' ? code
@@ -1383,7 +1442,12 @@ export async function resetPluginConfigWithHelper(options) {
1383
1442
  return saved;
1384
1443
  if (selection?.skipReason)
1385
1444
  return { ...saved, apply: skippedApply(selection.skipReason) };
1386
- const applied = await applyPluginConfig({ ...options, ...selection, plugin: options.plugin, awHomeMutationToken });
1445
+ const applied = await applyPluginConfig({ ...options, ...selection, plugin: options.plugin, awHomeMutationToken })
1446
+ .catch((error) => {
1447
+ if (error instanceof ConfigApplyInterruptedError)
1448
+ error.configWrite = 'succeeded';
1449
+ throw error;
1450
+ });
1387
1451
  return { ...saved, overallState: applied.overallState, apply: applied.apply };
1388
1452
  },
1389
1453
  });