@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.
- package/dist/authoring/assets/aw-runtime-config.mjs +1 -1
- package/dist/authoring/assets/aw-runtime-config.mjs.map +1 -1
- package/dist/src/commands/console.js +1 -0
- package/dist/src/commands/console.js.map +1 -1
- package/dist/src/commands/intent-command.d.ts +1 -0
- package/dist/src/commands/intent-command.js +6 -2
- package/dist/src/commands/intent-command.js.map +1 -1
- package/dist/src/commands/plugin-capabilities.js +3 -3
- package/dist/src/commands/plugin-capabilities.js.map +1 -1
- package/dist/src/commands/public-lifecycle-result.d.ts +11 -5
- package/dist/src/commands/public-lifecycle-result.js +131 -46
- package/dist/src/commands/public-lifecycle-result.js.map +1 -1
- package/dist/src/commands/public-lifecycle.d.ts +1 -2
- package/dist/src/commands/public-lifecycle.js +56 -34
- package/dist/src/commands/public-lifecycle.js.map +1 -1
- package/dist/src/commands/public-plugin-query.js +28 -11
- package/dist/src/commands/public-plugin-query.js.map +1 -1
- package/dist/src/commands/rebuild-command.d.ts +13 -3
- package/dist/src/commands/rebuild-command.js +647 -286
- package/dist/src/commands/rebuild-command.js.map +1 -1
- package/dist/src/commands/rebuild-integration.d.ts +5 -2
- package/dist/src/commands/rebuild-integration.js +55 -29
- package/dist/src/commands/rebuild-integration.js.map +1 -1
- package/dist/src/commands/rebuild-operations.d.ts +1 -0
- package/dist/src/commands/rebuild-operations.js +23 -4
- package/dist/src/commands/rebuild-operations.js.map +1 -1
- package/dist/src/commands/rebuild-platform-integration.d.ts +13 -3
- package/dist/src/commands/rebuild-platform-integration.js +229 -133
- package/dist/src/commands/rebuild-platform-integration.js.map +1 -1
- package/dist/src/index.js +105 -50
- package/dist/src/index.js.map +1 -1
- package/dist/src/output/public-result.d.ts +2 -0
- package/dist/src/output/public-result.js +43 -6
- package/dist/src/output/public-result.js.map +1 -1
- package/dist/src/output/rebuild-progress.d.ts +3 -0
- package/dist/src/output/rebuild-progress.js +12 -2
- package/dist/src/output/rebuild-progress.js.map +1 -1
- package/dist/src/output/receipt-projection.js +55 -18
- package/dist/src/output/receipt-projection.js.map +1 -1
- package/dist/src/output/skill-invocation-notices.d.ts +16 -0
- package/dist/src/output/skill-invocation-notices.js +48 -0
- package/dist/src/output/skill-invocation-notices.js.map +1 -0
- package/dist/src/platforms/capabilities.d.ts +2 -0
- package/dist/src/platforms/capabilities.js +73 -34
- package/dist/src/platforms/capabilities.js.map +1 -1
- package/dist/src/platforms/contracts.d.ts +9 -9
- package/dist/src/platforms/discovery.d.ts +0 -7
- package/dist/src/platforms/discovery.js +13 -53
- package/dist/src/platforms/discovery.js.map +1 -1
- package/dist/src/platforms/inspection-native.js +1 -80
- package/dist/src/platforms/inspection-native.js.map +1 -1
- package/dist/src/platforms/inspection-query.d.ts +2 -3
- package/dist/src/platforms/inspection-query.js +7 -18
- package/dist/src/platforms/inspection-query.js.map +1 -1
- package/dist/src/platforms/inspection.js +2 -2
- package/dist/src/platforms/inspection.js.map +1 -1
- package/dist/src/platforms/layout.js +1 -5
- package/dist/src/platforms/layout.js.map +1 -1
- package/dist/src/platforms/lifecycle-native-services.d.ts +1 -1
- package/dist/src/platforms/lifecycle-native-services.js +14 -14
- package/dist/src/platforms/lifecycle-native-services.js.map +1 -1
- package/dist/src/platforms/lifecycle-native.js +4 -88
- package/dist/src/platforms/lifecycle-native.js.map +1 -1
- package/dist/src/platforms/lifecycle.js +56 -56
- package/dist/src/platforms/lifecycle.js.map +1 -1
- package/dist/src/platforms/projection-code-extension.js +7 -3
- package/dist/src/platforms/projection-code-extension.js.map +1 -1
- package/dist/src/platforms/projection.d.ts +3 -0
- package/dist/src/platforms/projection.js +86 -54
- package/dist/src/platforms/projection.js.map +1 -1
- package/dist/src/portable/materializer.js +2 -2
- package/dist/src/portable/materializer.js.map +1 -1
- package/dist/src/portable/recovery.d.ts +29 -3
- package/dist/src/portable/recovery.js +220 -78
- package/dist/src/portable/recovery.js.map +1 -1
- package/dist/src/recovery/coordinator.d.ts +18 -4
- package/dist/src/recovery/coordinator.js +357 -165
- package/dist/src/recovery/coordinator.js.map +1 -1
- package/dist/src/recovery/install-concurrency.d.ts +48 -0
- package/dist/src/recovery/install-concurrency.js +195 -0
- package/dist/src/recovery/install-concurrency.js.map +1 -0
- package/dist/src/recovery/interruption.d.ts +19 -0
- package/dist/src/recovery/interruption.js +43 -0
- package/dist/src/recovery/interruption.js.map +1 -0
- package/dist/src/recovery/joint-coordinator.d.ts +11 -4
- package/dist/src/recovery/joint-coordinator.js +671 -333
- package/dist/src/recovery/joint-coordinator.js.map +1 -1
- package/dist/src/recovery/joint-demand.d.ts +8 -0
- package/dist/src/recovery/joint-demand.js +52 -1
- package/dist/src/recovery/joint-demand.js.map +1 -1
- package/dist/src/recovery/joint-install-execution.d.ts +19 -0
- package/dist/src/recovery/joint-install-execution.js +307 -0
- package/dist/src/recovery/joint-install-execution.js.map +1 -0
- package/dist/src/recovery/joint-install-native-rebase.d.ts +4 -0
- package/dist/src/recovery/joint-install-native-rebase.js +67 -0
- package/dist/src/recovery/joint-install-native-rebase.js.map +1 -0
- package/dist/src/recovery/receipt.d.ts +20 -0
- package/dist/src/recovery/receipt.js +67 -1
- package/dist/src/recovery/receipt.js.map +1 -1
- package/dist/src/recovery/retirement.js +1 -1
- package/dist/src/recovery/retirement.js.map +1 -1
- package/dist/src/recovery/status.js +26 -27
- package/dist/src/recovery/status.js.map +1 -1
- package/dist/src/review/platform-profile.d.ts +4 -1
- package/dist/src/review/platform-profile.js +13 -4
- package/dist/src/review/platform-profile.js.map +1 -1
- package/dist/src/review/skill-materialization.d.ts +1 -0
- package/dist/src/review/skill-materialization.js +28 -16
- package/dist/src/review/skill-materialization.js.map +1 -1
- package/dist/src/review/source-binding.js +6 -4
- package/dist/src/review/source-binding.js.map +1 -1
- package/dist/src/tui/console-app-v4.d.ts +1 -1
- package/dist/src/tui/console-app-v4.js +137 -57
- package/dist/src/tui/console-app-v4.js.map +1 -1
- package/dist/src/tui/controller-runtime.js +45 -9
- package/dist/src/tui/controller-runtime.js.map +1 -1
- package/dist/src/tui/controller.d.ts +13 -4
- package/dist/src/tui/controller.js +233 -102
- package/dist/src/tui/controller.js.map +1 -1
- package/dist/src/tui/deployment-view.js +6 -1
- package/dist/src/tui/deployment-view.js.map +1 -1
- package/dist/src/tui/diagnostic-projection.d.ts +4 -2
- package/dist/src/tui/diagnostic-projection.js +40 -4
- package/dist/src/tui/diagnostic-projection.js.map +1 -1
- package/dist/src/tui/operation-diagnostic-screens.d.ts +1 -1
- package/dist/src/tui/operation-diagnostic-screens.js +3 -1
- package/dist/src/tui/operation-diagnostic-screens.js.map +1 -1
- package/dist/src/tui/operation-history.d.ts +6 -3
- package/dist/src/tui/operation-history.js +15 -2
- package/dist/src/tui/operation-history.js.map +1 -1
- package/dist/src/tui/scoped-flow.d.ts +3 -1
- package/dist/src/tui/scoped-flow.js +99 -1
- package/dist/src/tui/scoped-flow.js.map +1 -1
- package/dist/src/tui/session-console-app.d.ts +2 -0
- package/dist/src/tui/session-console-app.js +11 -0
- package/dist/src/tui/session-console-app.js.map +1 -1
- package/dist/src/types.d.ts +8 -1
- package/dist/src/types.js.map +1 -1
- package/dist/src/utils/aw-home-mutation-lock.js +2 -1
- package/dist/src/utils/aw-home-mutation-lock.js.map +1 -1
- package/dist/src/utils/catalog-source-references.js +2 -14
- package/dist/src/utils/catalog-source-references.js.map +1 -1
- package/dist/src/utils/component-resources.js +1 -1
- package/dist/src/utils/component-resources.js.map +1 -1
- package/dist/src/utils/managed-command-materialization.d.ts +2 -1
- package/dist/src/utils/managed-command-materialization.js +3 -3
- package/dist/src/utils/managed-command-materialization.js.map +1 -1
- package/dist/src/utils/managed-command-store.d.ts +6 -0
- package/dist/src/utils/managed-command-store.js +90 -18
- package/dist/src/utils/managed-command-store.js.map +1 -1
- package/dist/src/utils/multi-source-catalog.d.ts +2 -0
- package/dist/src/utils/multi-source-catalog.js +3 -2
- package/dist/src/utils/multi-source-catalog.js.map +1 -1
- package/dist/src/utils/native-cli.d.ts +0 -19
- package/dist/src/utils/native-cli.js +2 -42
- package/dist/src/utils/native-cli.js.map +1 -1
- package/dist/src/utils/ownership.js +1 -1
- package/dist/src/utils/ownership.js.map +1 -1
- package/dist/src/utils/platform-empty-state.d.ts +1 -3
- package/dist/src/utils/platform-empty-state.js +1 -6
- package/dist/src/utils/platform-empty-state.js.map +1 -1
- package/dist/src/utils/plugin-config-write.d.ts +8 -0
- package/dist/src/utils/plugin-config-write.js +89 -25
- package/dist/src/utils/plugin-config-write.js.map +1 -1
- package/dist/src/utils/plugin-scripts.js +5 -0
- package/dist/src/utils/plugin-scripts.js.map +1 -1
- package/dist/src/utils/skill-invocation-warning.d.ts +15 -0
- package/dist/src/utils/skill-invocation-warning.js +42 -0
- package/dist/src/utils/skill-invocation-warning.js.map +1 -0
- package/package.json +3 -3
- package/dist/src/output/native-consent.d.ts +0 -2
- package/dist/src/output/native-consent.js +0 -5
- package/dist/src/output/native-consent.js.map +0 -1
- package/dist/src/platforms/gemini-activation.d.ts +0 -36
- package/dist/src/platforms/gemini-activation.js +0 -331
- package/dist/src/platforms/gemini-activation.js.map +0 -1
- package/dist/src/platforms/gemini-consent.d.ts +0 -8
- package/dist/src/platforms/gemini-consent.js +0 -81
- package/dist/src/platforms/gemini-consent.js.map +0 -1
|
@@ -11,14 +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 } from '../utils/catalog-operation-context.js';
|
|
14
|
+
import { CatalogPreparationReadScope, selectCatalogOperationContext } from '../utils/catalog-operation-context.js';
|
|
15
15
|
import { CatalogGenerationError } from '../utils/catalog-generation-error.js';
|
|
16
16
|
import { createCatalogPreparationStoreKey } from '../utils/catalog-generation-resolver.js';
|
|
17
17
|
import { activateCatalogSourceGeneration, probeCatalogSourceGeneration, } from '../utils/catalog-generation-service.js';
|
|
18
18
|
import { readCatalogGenerationState } from '../utils/catalog-generation-state.js';
|
|
19
19
|
import { readCatalogSourcesConfigSnapshot } from '../utils/catalog-sources.js';
|
|
20
20
|
import { calculateCatalogSourceImpactDigest, inspectCatalogSourceImpact, } from '../utils/catalog-source-impact.js';
|
|
21
|
-
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';
|
|
22
22
|
import { addRequirements } from '../commands/intent-command.js';
|
|
23
23
|
import { readDemand, demandNativeProjection, resolveDelivery } from './demand.js';
|
|
24
24
|
import { selectAgents, writePreferences } from '../intent/deployment-preferences.js';
|
|
@@ -30,6 +30,8 @@ import { createEmptyNativeDemandView } from '../utils/native-demand.js';
|
|
|
30
30
|
import { resolvePluginMetaDependencyClosure } from '../utils/plugin-dependencies.js';
|
|
31
31
|
import { runPreApplyScript } from '../utils/plugin-scripts.js';
|
|
32
32
|
import { readSafeOperationError } from '../utils/safe-operation-diagnostic.js';
|
|
33
|
+
import { RebuildInterruptedError, RecoveryInterruptedError, recoveryInterruptionCode } from './interruption.js';
|
|
34
|
+
import { mapInstallReads } from './install-concurrency.js';
|
|
33
35
|
import { measureRecoveryPerformanceStage } from './performance.js';
|
|
34
36
|
import { disposePreparedPlatformRebuildSession } from '../commands/rebuild-integration.js';
|
|
35
37
|
import { operationPlanNativeToolChanges } from '../commands/operation-plan.js';
|
|
@@ -147,6 +149,24 @@ function nativeTargetSelection(targets) {
|
|
|
147
149
|
return { pluginIds: [...new Set(targets.map((target) => target.pluginId))],
|
|
148
150
|
platform: platforms.size === 1 ? targets[0].platform : 'both', targets: [...targets] };
|
|
149
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
|
+
}
|
|
150
170
|
async function nativeOperation(plan, pluginIds, platform, preview, runtime = plan.runtime, command = plan.command, selectedTargets, catalogReadScope) {
|
|
151
171
|
if (!runtime.awHomeMutationToken) {
|
|
152
172
|
await prepareNativeCliExecution({ env: plan.context.env, runner: runtime.nativeCliRunner });
|
|
@@ -200,16 +220,16 @@ function nativeResults(plan, group, result, executed) {
|
|
|
200
220
|
...(plan.receipt.commandResults ?? []), ...result.commandResults,
|
|
201
221
|
].map((entry) => [getCommandPackageId(entry.producer), entry])).values()];
|
|
202
222
|
}
|
|
223
|
+
const backend = buildRebuildReceiptJson(group.command === 'install' ? 'sync' : group.command, result);
|
|
203
224
|
for (const { pluginId, platform } of nativeGroupTargets(group)) {
|
|
204
225
|
const agent = agentForPlatform(platform);
|
|
205
226
|
const target = pair(plan, pluginId, agent);
|
|
206
227
|
if (!target)
|
|
207
228
|
continue;
|
|
208
|
-
const backend = buildRebuildReceiptJson(group.command === 'install' ? 'sync' : group.command, result);
|
|
209
229
|
target.backend = backend;
|
|
210
|
-
target.
|
|
211
|
-
|
|
212
|
-
|
|
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);
|
|
213
233
|
const deploymentPlans = new Map([
|
|
214
234
|
...(group.preview.operationPlan?.deploymentPlans ?? []),
|
|
215
235
|
...(result.operationPlan?.deploymentPlans ?? []),
|
|
@@ -249,6 +269,12 @@ function nativeResults(plan, group, result, executed) {
|
|
|
249
269
|
&& target.target.scope === (result.dependencyPlan?.targets.find((dependency) => dependency.pluginId === producerPluginId && dependency.platform === platform)?.resolvedScope
|
|
250
270
|
?? plan.options.scope));
|
|
251
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;
|
|
252
278
|
for (const failure of backendTargets.filter((entry) => entry.state === 'failed')) {
|
|
253
279
|
block(target, failure.errorCode ?? 'nativeRecoveryFailed');
|
|
254
280
|
}
|
|
@@ -330,9 +356,10 @@ function nativeResults(plan, group, result, executed) {
|
|
|
330
356
|
}
|
|
331
357
|
}
|
|
332
358
|
/** All scopes share one final marketplace generation before Review is returned. */
|
|
333
|
-
export async function refreshRecoveryNativePreviews(plan, catalogReadScope) {
|
|
334
|
-
|
|
335
|
-
|
|
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];
|
|
336
363
|
nativeResults(plan, group, group.preview, false);
|
|
337
364
|
}
|
|
338
365
|
completeReceipt(plan.receipt);
|
|
@@ -375,6 +402,12 @@ function portableResults(plan, prepared) {
|
|
|
375
402
|
function portableOutcomes(plan, prepared, agent, outcomes, globalBlockers) {
|
|
376
403
|
const target = pair(plan, prepared.options.selector, agent);
|
|
377
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
|
+
}
|
|
378
411
|
const preparedTargets = prepared.targets.filter((entry) => entry.agent === agent);
|
|
379
412
|
const gaps = (prepared.unmet ?? []).filter((gap) => gap.agent === agent);
|
|
380
413
|
if (gaps.length)
|
|
@@ -421,20 +454,30 @@ function portableOutcomes(plan, prepared, agent, outcomes, globalBlockers) {
|
|
|
421
454
|
execution: entry.execution, blockers: entry.blockers }));
|
|
422
455
|
for (const code of [...globalBlockers, ...outcomes.flatMap((entry) => entry.blockers)])
|
|
423
456
|
block(target, code);
|
|
424
|
-
target.recoveryActions = portableRecoveryActions(plan, target.pluginId, outcomes.filter((entry) =>
|
|
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
|
+
}
|
|
425
461
|
}
|
|
426
462
|
function portablePluginClosure(plan, prepared) {
|
|
427
463
|
const { sourceId, pluginName } = parsePluginId(prepared.options.selector);
|
|
428
464
|
return resolvePluginMetaDependencyClosure(plan.demand.plugins.filter((plugin) => plugin.sourceId === sourceId), [pluginName])
|
|
429
465
|
.filter((plugin) => !prepared.options.excludedPluginIds?.includes(plugin.pluginId));
|
|
430
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
|
+
}
|
|
431
472
|
function preparePortablePreApplyAuthorization(plan) {
|
|
432
473
|
if (plan.command === 'cleanup' || plan.command === 'uninstall')
|
|
433
474
|
return;
|
|
434
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));
|
|
435
478
|
for (const prepared of plan.portableGroups) {
|
|
436
479
|
for (const plugin of portablePluginClosure(plan, prepared)) {
|
|
437
|
-
if (!plugin.manifest.scripts?.preApply)
|
|
480
|
+
if (!plugin.manifest.scripts?.preApply || verifiedProviders.has(plugin.pluginId))
|
|
438
481
|
continue;
|
|
439
482
|
for (const platform of prepared.options.agents) {
|
|
440
483
|
if (pair(plan, prepared.options.selector, platform)?.blockers.length)
|
|
@@ -469,6 +512,7 @@ async function executePreApplyAuthorization(plan, required, runtime) {
|
|
|
469
512
|
return 'preApplyAuthorizationRequired';
|
|
470
513
|
const cache = runtime.preApplyExecutionCache ??= new Map();
|
|
471
514
|
for (const target of required) {
|
|
515
|
+
runtime.signal?.throwIfAborted();
|
|
472
516
|
const plugin = plan.demand.plugins.find((entry) => entry.pluginId === target.pluginId);
|
|
473
517
|
if (!plugin || plugin.sourceIdentity !== target.sourceIdentity)
|
|
474
518
|
return 'sourceUnavailable';
|
|
@@ -489,9 +533,18 @@ async function executePreApplyAuthorization(plan, required, runtime) {
|
|
|
489
533
|
await execution;
|
|
490
534
|
}
|
|
491
535
|
catch (error) {
|
|
492
|
-
runtime.signal
|
|
493
|
-
if (
|
|
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;
|
|
494
546
|
throw error;
|
|
547
|
+
}
|
|
495
548
|
const operationDiagnostic = readSafeOperationError(error);
|
|
496
549
|
const affected = pair(plan, target.pluginId, target.platform);
|
|
497
550
|
if (affected) {
|
|
@@ -542,8 +595,7 @@ export async function executeRecoveryPreApply(plan, pluginId, agent, runtime) {
|
|
|
542
595
|
return executePreApplyAuthorization(plan, authorization.preApplyAuthorization, runtime);
|
|
543
596
|
}
|
|
544
597
|
catch (error) {
|
|
545
|
-
runtime.signal
|
|
546
|
-
if (error instanceof Error && error.name === 'AbortError')
|
|
598
|
+
if (recoveryInterruptionCode(error, runtime.signal))
|
|
547
599
|
throw error;
|
|
548
600
|
return readSafeOperationError(error)?.code ?? errorCode(error, 'nativePreparationFailed');
|
|
549
601
|
}
|
|
@@ -555,7 +607,7 @@ export async function executeRecoveryPreApply(plan, pluginId, agent, runtime) {
|
|
|
555
607
|
return executePortablePreApply(plan, prepared, agent, runtime);
|
|
556
608
|
}
|
|
557
609
|
}
|
|
558
|
-
async function checkFootprints(plan) {
|
|
610
|
+
export async function checkFootprints(plan) {
|
|
559
611
|
const footprints = [];
|
|
560
612
|
for (const [nativeGroup, group] of plan.nativeGroups.entries()) {
|
|
561
613
|
const actions = group.preview.operationPlan?.actions.filter((action) => (action.kind === 'writeOwnedArtifact' || action.kind === 'removeOwnedArtifact')
|
|
@@ -566,7 +618,7 @@ async function checkFootprints(plan) {
|
|
|
566
618
|
continue;
|
|
567
619
|
const consumers = group.preview.dependencyPlan?.targets.filter((target) => target.pluginId === action.pluginId)
|
|
568
620
|
.flatMap((target) => target.requiredBy ?? []) ?? [];
|
|
569
|
-
footprints.push({ path:
|
|
621
|
+
footprints.push({ path: action.path,
|
|
570
622
|
pluginIds: group.pluginIds.filter((id) => id === action.pluginId || consumers.includes(id)),
|
|
571
623
|
agent: agentForPlatform(action.platform), identity: `native:${action.platform}:${action.pluginId}`,
|
|
572
624
|
sharedNative: 'shared' in action && action.shared,
|
|
@@ -578,17 +630,23 @@ async function checkFootprints(plan) {
|
|
|
578
630
|
for (const prepared of plan.portableGroups) {
|
|
579
631
|
for (const target of prepared.targets)
|
|
580
632
|
footprints.push({
|
|
581
|
-
path:
|
|
633
|
+
path: target.physicalPath,
|
|
582
634
|
pluginIds: [prepared.options.selector], agent: target.agent,
|
|
583
|
-
identity:
|
|
635
|
+
identity: JSON.stringify(['agent-skills', prepared.logicalIdentity, target.providerPluginId, target.expectedDigest,
|
|
636
|
+
target.configDigest, target.disposition]),
|
|
584
637
|
});
|
|
585
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);
|
|
586
643
|
for (let index = 0; index < footprints.length; index += 1) {
|
|
587
644
|
const left = footprints[index];
|
|
588
645
|
for (const right of footprints.slice(index + 1)) {
|
|
589
|
-
|
|
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
|
|
590
648
|
|| (left.nativeGroup !== undefined && left.nativeGroup === right.nativeGroup)
|
|
591
|
-
|| (left.sharedMarketplaceSource !== undefined
|
|
649
|
+
|| (left.sharedMarketplaceSource !== undefined && left.agent === right.agent
|
|
592
650
|
&& left.sharedMarketplaceSource === right.sharedMarketplaceSource)
|
|
593
651
|
|| (left.sharedNative && right.sharedNative && left.agent === right.agent))
|
|
594
652
|
continue;
|
|
@@ -606,7 +664,7 @@ async function checkFootprints(plan) {
|
|
|
606
664
|
plan.changes.push(`${prepared.options.selector}:AW 写入所选 Agent 的 owned Skill 目录;准备目录 ${layout.generationRoot}。`);
|
|
607
665
|
}
|
|
608
666
|
}
|
|
609
|
-
export async function prepareScopedRecovery(command, selectors, options, runtime = {}, { catalogReadScope, nativeObservationBatch } = {}) {
|
|
667
|
+
export async function prepareScopedRecovery(command, selectors, options, runtime = {}, { catalogReadScope, nativeObservationBatch, portableGenerations = new Map() } = {}) {
|
|
610
668
|
runtime = { ...runtime, preparedArtifactRenderResults: runtime.preparedArtifactRenderResults ?? new Map() };
|
|
611
669
|
options.signal?.throwIfAborted();
|
|
612
670
|
const context = await createScopeContext({ scope: options.scope, cwd: options.cwd, env: options.env });
|
|
@@ -649,8 +707,7 @@ export async function prepareScopedRecovery(command, selectors, options, runtime
|
|
|
649
707
|
configDigest: config.digest, impact, impactDigest: calculateCatalogSourceImpactDigest(impact) });
|
|
650
708
|
}
|
|
651
709
|
catch (error) {
|
|
652
|
-
options.signal
|
|
653
|
-
if (error instanceof Error && error.name === 'AbortError')
|
|
710
|
+
if (recoveryInterruptionCode(error, options.signal))
|
|
654
711
|
throw error;
|
|
655
712
|
const code = errorCode(error, 'catalogGenerationRefreshFailed');
|
|
656
713
|
refreshFailures.set(sourceId, code.startsWith('catalog') ? code : 'catalogGenerationRefreshFailed');
|
|
@@ -769,15 +826,25 @@ export async function prepareScopedRecovery(command, selectors, options, runtime
|
|
|
769
826
|
group.targets.push({ pluginId: target.pluginId, platform: target.delivery.platform });
|
|
770
827
|
groups.set(key, group);
|
|
771
828
|
}
|
|
772
|
-
const preparationRuntime = { ...runtime, signal: options.signal,
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
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) => {
|
|
778
834
|
try {
|
|
779
835
|
const preview = await nativeOperation(plan, group.pluginIds, group.platform, true, preparationRuntime, group.command, group.targets, catalogReadScope);
|
|
780
|
-
|
|
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;
|
|
781
848
|
const nativeGroup = { ...group, preview };
|
|
782
849
|
plan.nativeGroups.push(nativeGroup);
|
|
783
850
|
nativeResults(plan, nativeGroup, preview, false);
|
|
@@ -799,10 +866,8 @@ export async function prepareScopedRecovery(command, selectors, options, runtime
|
|
|
799
866
|
}
|
|
800
867
|
plan.warnings.push(...preview.warnings);
|
|
801
868
|
}
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
if (error instanceof Error && error.name === 'AbortError')
|
|
805
|
-
throw error;
|
|
869
|
+
else {
|
|
870
|
+
const { error } = result;
|
|
806
871
|
if (error instanceof CatalogSourceInventoryIncompleteError) {
|
|
807
872
|
receipt.blockers.push(...error.inventory.errors.map(inventoryRecoveryDiagnostic));
|
|
808
873
|
}
|
|
@@ -811,26 +876,32 @@ export async function prepareScopedRecovery(command, selectors, options, runtime
|
|
|
811
876
|
}
|
|
812
877
|
}
|
|
813
878
|
}
|
|
814
|
-
|
|
879
|
+
const portableReads = receipt.requestedRoots.flatMap((pluginId) => {
|
|
815
880
|
const agents = receipt.targetResults.filter((target) => target.pluginId === pluginId
|
|
816
881
|
&& !target.blockers.length && target.delivery?.kind === 'agent-skills').map((target) => target.agent).filter(isPortableAgent);
|
|
817
|
-
|
|
818
|
-
|
|
882
|
+
return agents.length ? [{ pluginId, agents }] : [];
|
|
883
|
+
});
|
|
884
|
+
const preparedGroups = await mapInstallReads(portableReads, async ({ pluginId, agents }) => {
|
|
819
885
|
try {
|
|
820
886
|
const prepared = command === 'cleanup' || command === 'uninstall'
|
|
821
887
|
? await preparePortableCleanup({ scope: options.scope, context, selector: pluginId, agents, force: options.force, signal: options.signal })
|
|
822
888
|
: await preparePortableRecovery({ scope: options.scope, context, selector: pluginId, agents,
|
|
823
889
|
env: options.env, cliVersion: options.cliVersion, signal: options.signal,
|
|
824
|
-
catalogOperationContext: demand.catalogOperationContext, excludedPluginIds: options.excludedPluginIds }, catalogReadScope);
|
|
825
|
-
|
|
890
|
+
catalogOperationContext: demand.catalogOperationContext, excludedPluginIds: options.excludedPluginIds }, catalogReadScope, portableGenerations);
|
|
891
|
+
return { ok: true, prepared };
|
|
826
892
|
}
|
|
827
893
|
catch (error) {
|
|
828
|
-
options.signal
|
|
829
|
-
if (error instanceof Error && error.name === 'AbortError')
|
|
894
|
+
if (recoveryInterruptionCode(error, options.signal))
|
|
830
895
|
throw error;
|
|
831
|
-
|
|
832
|
-
block(pair(plan, pluginId, agent), errorCode(error, 'portablePreparationFailed'));
|
|
896
|
+
return { ok: false, agents, pluginId, code: errorCode(error, 'portablePreparationFailed') };
|
|
833
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);
|
|
834
905
|
}
|
|
835
906
|
for (const prepared of plan.portableGroups)
|
|
836
907
|
portableResults(plan, prepared);
|
|
@@ -839,31 +910,26 @@ export async function prepareScopedRecovery(command, selectors, options, runtime
|
|
|
839
910
|
// Complete scope demand protects copies contributed by unselected roots and their dependencies.
|
|
840
911
|
const desiredAgents = new Set([...receipt.selection.agents,
|
|
841
912
|
...(demand.preferences.state === 'valid' ? demand.preferences.value.targets : [])]);
|
|
842
|
-
const
|
|
843
|
-
for (const root of demand.roots ?? []) {
|
|
913
|
+
const protection = await mapInstallReads(demand.roots ?? [], async (root) => {
|
|
844
914
|
const portableAgents = [...desiredAgents].filter(isPortableAgent).filter((agent) => root.plugin
|
|
845
915
|
&& resolveDelivery(root.plugin.manifest, agent, options.scope)?.kind === 'agent-skills');
|
|
846
|
-
if (!portableAgents.length)
|
|
847
|
-
|
|
916
|
+
if (!portableAgents.length || plan.portableGroups.some((group) => group.options.selector === root.pluginId
|
|
917
|
+
&& portableAgents.every((agent) => group.options.agents.includes(agent))))
|
|
918
|
+
return;
|
|
848
919
|
try {
|
|
849
|
-
const prepared =
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
if (!prepared.globalBlockers.length) {
|
|
855
|
-
retainedPortableTargets.push(...prepared.targets.filter((target) => !target.blocker && ['satisfied', 'drifted'].includes(target.observation)));
|
|
856
|
-
if (!plan.portableGroups.includes(prepared))
|
|
857
|
-
plan.portableProtectionGroups.push(prepared);
|
|
858
|
-
}
|
|
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;
|
|
859
925
|
}
|
|
860
926
|
catch (error) {
|
|
861
|
-
options.signal
|
|
862
|
-
if (error instanceof Error && error.name === 'AbortError')
|
|
927
|
+
if (recoveryInterruptionCode(error, options.signal))
|
|
863
928
|
throw error;
|
|
864
929
|
// Missing current Portable evidence cannot protect historical residue.
|
|
865
930
|
}
|
|
866
|
-
}
|
|
931
|
+
}, { signal: options.signal });
|
|
932
|
+
plan.portableProtectionGroups = protection.filter((prepared) => prepared !== undefined);
|
|
867
933
|
}
|
|
868
934
|
options.signal?.throwIfAborted();
|
|
869
935
|
await checkFootprints(plan);
|
|
@@ -959,40 +1025,220 @@ function portablePrewriteBinding(context, sourceId) {
|
|
|
959
1025
|
return JSON.stringify([context.generationSetDigest,
|
|
960
1026
|
createCatalogPreparationStoreKey({ ...generation, requestedRef: source.requestedRef })]);
|
|
961
1027
|
}
|
|
962
|
-
async function recheckPortableRecovery(plan) {
|
|
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) ?? []));
|
|
963
1031
|
const inspections = [
|
|
964
|
-
...
|
|
1032
|
+
...executable,
|
|
965
1033
|
...plan.portableProtectionGroups,
|
|
1034
|
+
...providers,
|
|
966
1035
|
];
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
const
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
&&
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
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
|
+
}
|
|
981
1063
|
}
|
|
982
|
-
|
|
983
|
-
|
|
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))
|
|
984
1183
|
throw error;
|
|
985
|
-
|
|
986
|
-
|
|
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
|
+
}
|
|
987
1197
|
}
|
|
988
|
-
if (
|
|
989
|
-
|
|
1198
|
+
if (interruption)
|
|
1199
|
+
throw interruption.cause;
|
|
990
1200
|
}
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
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);
|
|
996
1242
|
}
|
|
997
1243
|
}
|
|
998
1244
|
export async function executeScopedRecovery(plan, execution = {}) {
|
|
@@ -1026,8 +1272,11 @@ export async function executeScopedRecovery(plan, execution = {}) {
|
|
|
1026
1272
|
}
|
|
1027
1273
|
return await withAwHomeMutationLock({ env: plan.options.env, token: plan.runtime.awHomeMutationToken,
|
|
1028
1274
|
action: async (token) => {
|
|
1029
|
-
const actualIntent = await
|
|
1030
|
-
|
|
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
|
+
]);
|
|
1031
1280
|
if (intentEvidence(actualIntent) !== plan.originalIntent || preferenceEvidence(current) !== plan.preferencesEvidence
|
|
1032
1281
|
|| current.catalogOperationContext?.generationSetDigest !== plan.demand.catalogOperationContext?.generationSetDigest) {
|
|
1033
1282
|
receipt.blockers.push(diagnostic('operationReviewStale'));
|
|
@@ -1047,23 +1296,26 @@ export async function executeScopedRecovery(plan, execution = {}) {
|
|
|
1047
1296
|
...(session ? { codexObservationSession: session } : {}) };
|
|
1048
1297
|
try {
|
|
1049
1298
|
// Freeze every backend before the first declaration or output write.
|
|
1050
|
-
const
|
|
1051
|
-
for (const group of plan.nativeGroups) {
|
|
1299
|
+
const recheckedGroups = await readNativeGroups(plan.nativeGroups, async (group) => {
|
|
1052
1300
|
const targets = nativeGroupTargets(group);
|
|
1053
1301
|
const executable = targets.filter(({ pluginId, platform }) => !pair(plan, pluginId, agentForPlatform(platform)).blockers.length);
|
|
1054
|
-
if (executable.length
|
|
1055
|
-
|
|
1302
|
+
if (!executable.length)
|
|
1303
|
+
return;
|
|
1056
1304
|
const checked = await nativeOperation(plan, group.pluginIds, group.platform, true, nativeRuntime, group.command, targets);
|
|
1057
|
-
if (checked.operationPlan?.planFingerprint !== group.preview.operationPlan?.planFingerprint)
|
|
1058
|
-
|
|
1059
|
-
return completeReceipt(receipt);
|
|
1060
|
-
}
|
|
1305
|
+
if (checked.operationPlan?.planFingerprint !== group.preview.operationPlan?.planFingerprint)
|
|
1306
|
+
return 'stale';
|
|
1061
1307
|
const selection = nativeTargetSelection(executable);
|
|
1062
1308
|
const preview = executable.length === targets.length ? checked
|
|
1063
1309
|
: await nativeOperation(plan, selection.pluginIds, selection.platform, true, nativeRuntime, group.command, executable);
|
|
1064
|
-
|
|
1310
|
+
return { ...group, ...selection, preview };
|
|
1311
|
+
}, nativeRuntime.signal);
|
|
1312
|
+
if (recheckedGroups.includes('stale')) {
|
|
1313
|
+
receipt.blockers.push(diagnostic('operationReviewStale'));
|
|
1314
|
+
return completeReceipt(receipt);
|
|
1065
1315
|
}
|
|
1066
|
-
const
|
|
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);
|
|
1067
1319
|
if (portableBlocker) {
|
|
1068
1320
|
receipt.blockers.push(portableBlocker);
|
|
1069
1321
|
return completeReceipt(receipt);
|
|
@@ -1097,71 +1349,9 @@ export async function executeScopedRecovery(plan, execution = {}) {
|
|
|
1097
1349
|
return completeReceipt(receipt);
|
|
1098
1350
|
}
|
|
1099
1351
|
}
|
|
1100
|
-
for (const group of executableNativeGroups)
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
...(group.preview.operationPlan
|
|
1104
|
-
? { expectedPlanFingerprint: group.preview.operationPlan.planFingerprint } : {}) }, group.command, nativeGroupTargets(group));
|
|
1105
|
-
receipt.outputsMayHaveChanged ||= result.rebuildResults.some((result) => result.actions.some((action) => action.name === 'stale.cleanup' || action.name === 'native.write' || action.name === 'artifacts.write'
|
|
1106
|
-
|| action.name === 'recovery.cleanup' || action.name === 'cleanup.owned'))
|
|
1107
|
-
|| ((result.commandResults?.length ?? 0) > 0
|
|
1108
|
-
&& result.operationPlan?.actions.some((action) => action.kind === 'syncManagedCommandPackage') === true);
|
|
1109
|
-
nativeResults(plan, group, result, true);
|
|
1110
|
-
}
|
|
1111
|
-
catch (error) {
|
|
1112
|
-
const code = errorCode(error, 'nativeRecoveryFailed');
|
|
1113
|
-
receipt.outputsMayHaveChanged ||= code !== 'preApplyAuthorizationRequired';
|
|
1114
|
-
for (const { pluginId, platform } of nativeGroupTargets(group)) {
|
|
1115
|
-
const target = pair(plan, pluginId, agentForPlatform(platform));
|
|
1116
|
-
target.execution = 'failed';
|
|
1117
|
-
block(target, code);
|
|
1118
|
-
}
|
|
1119
|
-
}
|
|
1120
|
-
}
|
|
1121
|
-
const completedFootprints = [];
|
|
1122
|
-
const failedFootprints = [];
|
|
1123
|
-
for (const prepared of plan.portableGroups) {
|
|
1124
|
-
const agents = [];
|
|
1125
|
-
for (const agent of prepared.options.agents) {
|
|
1126
|
-
if (pair(plan, prepared.options.selector, agent).blockers.length)
|
|
1127
|
-
continue;
|
|
1128
|
-
const outcomes = prepared.targets.filter((entry) => entry.agent === agent).map((entry) => {
|
|
1129
|
-
const failed = failedFootprints.find((failure) => failure.logicalIdentity === prepared.logicalIdentity
|
|
1130
|
-
&& failure.outcome.physicalPath === entry.physicalPath && failure.outcome.expectedDigest === entry.expectedDigest
|
|
1131
|
-
&& failure.outcome.providerPluginId === entry.providerPluginId);
|
|
1132
|
-
return failed ? { ...failed.outcome, agent } : { ...entry, execution: 'not-run', blockers: [] };
|
|
1133
|
-
});
|
|
1134
|
-
if (outcomes.some((entry) => entry.execution === 'failed')) {
|
|
1135
|
-
portableOutcomes(plan, prepared, agent, outcomes, []);
|
|
1136
|
-
continue;
|
|
1137
|
-
}
|
|
1138
|
-
const preApplyFailure = await executePortablePreApply(plan, prepared, agent, nativeRuntime);
|
|
1139
|
-
if (preApplyFailure) {
|
|
1140
|
-
const target = pair(plan, prepared.options.selector, agent);
|
|
1141
|
-
target.execution = 'failed';
|
|
1142
|
-
block(target, preApplyFailure);
|
|
1143
|
-
target.recoveryActions = [`aw plugin sync ${target.pluginId} --context ${target.scope} --target ${agent} --yes`];
|
|
1144
|
-
continue;
|
|
1145
|
-
}
|
|
1146
|
-
agents.push(agent);
|
|
1147
|
-
}
|
|
1148
|
-
if (!agents.length)
|
|
1149
|
-
continue;
|
|
1150
|
-
const result = await executePortableRecovery({ prepared, token, authorizeUpdate: plan.options.yes,
|
|
1151
|
-
action: plan.command === 'install' ? 'sync' : plan.command, force: plan.options.force,
|
|
1152
|
-
targets: prepared.targets.filter((target) => agents.includes(target.agent)).map(({ skill, agent }) => ({ skill, agent })),
|
|
1153
|
-
completedFootprints });
|
|
1154
|
-
receipt.outputsMayHaveChanged ||= result.outputsMayHaveChanged;
|
|
1155
|
-
for (const agent of agents) {
|
|
1156
|
-
portableOutcomes(plan, prepared, agent, result.targets.filter((entry) => entry.agent === agent), result.globalBlockers);
|
|
1157
|
-
}
|
|
1158
|
-
failedFootprints.push(...result.targets.filter((target) => target.execution === 'failed')
|
|
1159
|
-
.map((outcome) => ({ logicalIdentity: prepared.logicalIdentity, outcome })));
|
|
1160
|
-
completedFootprints.push(...result.targets.filter((target) => target.observation === 'satisfied'
|
|
1161
|
-
&& ['applied', 'no-op'].includes(target.execution) && target.blockers.length === 0)
|
|
1162
|
-
.map(({ physicalPath, expectedDigest, providerPluginId }) => ({ physicalPath, expectedDigest, providerPluginId,
|
|
1163
|
-
logicalIdentity: prepared.logicalIdentity })));
|
|
1164
|
-
}
|
|
1352
|
+
for (const group of executableNativeGroups)
|
|
1353
|
+
await executeNativeGroup(plan, group, nativeRuntime);
|
|
1354
|
+
await executePortableGroups(plan, plan.portableGroups, nativeRuntime, portableProgress);
|
|
1165
1355
|
for (const { kind, pluginId, observation } of plan.portableResidues) {
|
|
1166
1356
|
if (kind !== 'cleanup')
|
|
1167
1357
|
continue;
|
|
@@ -1283,6 +1473,8 @@ export function describeRecoveryPlan(plan) {
|
|
|
1283
1473
|
nativeActivationOnlyTargets: child.options.nativeActivationOnlyTargets,
|
|
1284
1474
|
nativePlannedRetirements: child.options.nativePlannedRetirements,
|
|
1285
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,
|
|
1286
1478
|
protectedPortable: child.portableProtectionGroups.map((group) => group.evidenceDigest),
|
|
1287
1479
|
residue: child.portableResidues, blockers: child.receipt.blockers,
|
|
1288
1480
|
targetBlockers: child.receipt.targetResults.map((target) => target.blockers),
|