@lesliechan721/aw 0.1.0-beta.83 → 0.1.0-beta.85
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/index.js +2 -6
- package/dist/index.js.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 +14 -13
- package/dist/src/commands/public-lifecycle-result.js +204 -64
- 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 +44 -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 +665 -288
- package/dist/src/commands/rebuild-command.js.map +1 -1
- package/dist/src/commands/rebuild-integration.d.ts +6 -2
- package/dist/src/commands/rebuild-integration.js +60 -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 +28 -6
- package/dist/src/commands/rebuild-operations.js.map +1 -1
- package/dist/src/commands/rebuild-platform-integration.d.ts +20 -5
- package/dist/src/commands/rebuild-platform-integration.js +752 -182
- package/dist/src/commands/rebuild-platform-integration.js.map +1 -1
- package/dist/src/generators/permissions.d.ts +7 -1
- package/dist/src/generators/permissions.js +56 -0
- package/dist/src/generators/permissions.js.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +112 -54
- package/dist/src/index.js.map +1 -1
- package/dist/src/intent/scope-context.d.ts +4 -2
- package/dist/src/intent/scope-context.js +37 -7
- package/dist/src/intent/scope-context.js.map +1 -1
- package/dist/src/output/component-delivery.d.ts +21 -0
- package/dist/src/output/component-delivery.js +82 -0
- package/dist/src/output/component-delivery.js.map +1 -0
- package/dist/src/output/public-result.d.ts +4 -0
- package/dist/src/output/public-result.js +85 -15
- 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 +64 -19
- package/dist/src/output/receipt-projection.js.map +1 -1
- package/dist/src/output/skill-invocation-notices.d.ts +18 -0
- package/dist/src/output/skill-invocation-notices.js +84 -0
- package/dist/src/output/skill-invocation-notices.js.map +1 -0
- package/dist/src/platforms/capabilities.d.ts +6 -1
- package/dist/src/platforms/capabilities.js +161 -38
- package/dist/src/platforms/capabilities.js.map +1 -1
- package/dist/src/platforms/contracts.d.ts +45 -10
- package/dist/src/platforms/discovery.d.ts +11 -7
- package/dist/src/platforms/discovery.js +176 -76
- package/dist/src/platforms/discovery.js.map +1 -1
- package/dist/src/platforms/inspection-grok.js +121 -9
- package/dist/src/platforms/inspection-grok.js.map +1 -1
- package/dist/src/platforms/inspection-native.js +53 -97
- package/dist/src/platforms/inspection-native.js.map +1 -1
- package/dist/src/platforms/inspection-pi.d.ts +7 -1
- package/dist/src/platforms/inspection-pi.js +295 -95
- package/dist/src/platforms/inspection-pi.js.map +1 -1
- package/dist/src/platforms/inspection-query.d.ts +6 -5
- package/dist/src/platforms/inspection-query.js +30 -25
- package/dist/src/platforms/inspection-query.js.map +1 -1
- package/dist/src/platforms/inspection.d.ts +4 -1
- package/dist/src/platforms/inspection.js +38 -6
- package/dist/src/platforms/inspection.js.map +1 -1
- package/dist/src/platforms/layout.d.ts +6 -0
- package/dist/src/platforms/layout.js +45 -12
- 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.d.ts +1 -0
- package/dist/src/platforms/lifecycle-native.js +29 -89
- package/dist/src/platforms/lifecycle-native.js.map +1 -1
- package/dist/src/platforms/lifecycle.d.ts +2 -0
- package/dist/src/platforms/lifecycle.js +120 -69
- package/dist/src/platforms/lifecycle.js.map +1 -1
- package/dist/src/platforms/projection-code-extension.js +9 -4
- 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 +152 -72
- package/dist/src/platforms/projection.js.map +1 -1
- package/dist/src/platforms/supplement-layout.d.ts +5 -1
- package/dist/src/platforms/supplement-layout.js +23 -1
- package/dist/src/platforms/supplement-layout.js.map +1 -1
- package/dist/src/platforms/supplement-state.d.ts +1 -1
- package/dist/src/platforms/supplement-state.js +18 -7
- package/dist/src/platforms/supplement-state.js.map +1 -1
- package/dist/src/portable/commands.js +1 -1
- package/dist/src/portable/commands.js.map +1 -1
- package/dist/src/portable/materializer.d.ts +4 -0
- package/dist/src/portable/materializer.js +9 -2
- package/dist/src/portable/materializer.js.map +1 -1
- package/dist/src/portable/recovery.d.ts +31 -3
- package/dist/src/portable/recovery.js +261 -82
- package/dist/src/portable/recovery.js.map +1 -1
- package/dist/src/recovery/coordinator.d.ts +19 -5
- package/dist/src/recovery/coordinator.js +433 -174
- 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 +196 -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 +18 -4
- package/dist/src/recovery/joint-coordinator.js +829 -341
- package/dist/src/recovery/joint-coordinator.js.map +1 -1
- package/dist/src/recovery/joint-demand.d.ts +22 -2
- package/dist/src/recovery/joint-demand.js +104 -6
- 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 +35 -4
- package/dist/src/recovery/receipt.js +90 -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.d.ts +20 -8
- package/dist/src/recovery/status.js +405 -116
- 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 +14 -4
- package/dist/src/review/platform-profile.js.map +1 -1
- package/dist/src/review/skill-materialization.d.ts +2 -0
- package/dist/src/review/skill-materialization.js +68 -50
- package/dist/src/review/skill-materialization.js.map +1 -1
- package/dist/src/review/source-binding.js +11 -5
- 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 +180 -63
- package/dist/src/tui/console-app-v4.js.map +1 -1
- package/dist/src/tui/controller-runtime.js +46 -10
- package/dist/src/tui/controller-runtime.js.map +1 -1
- package/dist/src/tui/controller.d.ts +15 -5
- package/dist/src/tui/controller.js +246 -102
- package/dist/src/tui/controller.js.map +1 -1
- package/dist/src/tui/deployment-view.d.ts +6 -3
- package/dist/src/tui/deployment-view.js +43 -9
- package/dist/src/tui/deployment-view.js.map +1 -1
- package/dist/src/tui/diagnostic-projection.d.ts +11 -3
- package/dist/src/tui/diagnostic-projection.js +85 -4
- package/dist/src/tui/diagnostic-projection.js.map +1 -1
- package/dist/src/tui/entity-cards.d.ts +2 -1
- package/dist/src/tui/entity-cards.js +34 -11
- package/dist/src/tui/entity-cards.js.map +1 -1
- package/dist/src/tui/glossary.js +5 -0
- package/dist/src/tui/glossary.js.map +1 -1
- package/dist/src/tui/model.js +2 -1
- package/dist/src/tui/model.js.map +1 -1
- package/dist/src/tui/operation-diagnostic-screens.d.ts +1 -1
- package/dist/src/tui/operation-diagnostic-screens.js +6 -2
- package/dist/src/tui/operation-diagnostic-screens.js.map +1 -1
- package/dist/src/tui/operation-history.d.ts +12 -3
- package/dist/src/tui/operation-history.js +34 -3
- package/dist/src/tui/operation-history.js.map +1 -1
- package/dist/src/tui/plugin-detail.d.ts +4 -1
- package/dist/src/tui/plugin-detail.js +9 -2
- package/dist/src/tui/plugin-detail.js.map +1 -1
- package/dist/src/tui/scoped-flow.d.ts +3 -1
- package/dist/src/tui/scoped-flow.js +117 -1
- package/dist/src/tui/scoped-flow.js.map +1 -1
- package/dist/src/tui/scoped-inventory.d.ts +6 -2
- package/dist/src/tui/scoped-inventory.js +29 -7
- package/dist/src/tui/scoped-inventory.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 +10 -2
- package/dist/src/types.js.map +1 -1
- package/dist/src/utils/artifact-plan.js +5 -1
- package/dist/src/utils/artifact-plan.js.map +1 -1
- package/dist/src/utils/artifact-renderer.d.ts +1 -1
- package/dist/src/utils/artifact-renderer.js +29 -8
- package/dist/src/utils/artifact-renderer.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 +14 -17
- package/dist/src/utils/catalog-source-references.js.map +1 -1
- package/dist/src/utils/codex-native-observation.d.ts +6 -0
- package/dist/src/utils/codex-native-observation.js +32 -3
- package/dist/src/utils/codex-native-observation.js.map +1 -1
- package/dist/src/utils/component-command-preparation.d.ts +2 -0
- package/dist/src/utils/component-command-preparation.js +23 -4
- package/dist/src/utils/component-command-preparation.js.map +1 -1
- package/dist/src/utils/component-gap.d.ts +4 -0
- package/dist/src/utils/component-gap.js +20 -0
- package/dist/src/utils/component-gap.js.map +1 -0
- package/dist/src/utils/component-resources.js +2 -4
- package/dist/src/utils/component-resources.js.map +1 -1
- package/dist/src/utils/dynamic-skill-tree.js +2 -32
- package/dist/src/utils/dynamic-skill-tree.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-interruption.d.ts +8 -0
- package/dist/src/utils/native-cli-interruption.js +65 -0
- package/dist/src/utils/native-cli-interruption.js.map +1 -0
- package/dist/src/utils/native-cli.d.ts +5 -19
- package/dist/src/utils/native-cli.js +168 -95
- package/dist/src/utils/native-cli.js.map +1 -1
- package/dist/src/utils/ownership.d.ts +1 -0
- package/dist/src/utils/ownership.js +18 -4
- package/dist/src/utils/ownership.js.map +1 -1
- package/dist/src/utils/package-content.d.ts +7 -0
- package/dist/src/utils/package-content.js +70 -0
- package/dist/src/utils/package-content.js.map +1 -0
- package/dist/src/utils/platform-empty-state.d.ts +32 -9
- package/dist/src/utils/platform-empty-state.js +135 -70
- 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 +93 -25
- package/dist/src/utils/plugin-config-write.js.map +1 -1
- package/dist/src/utils/plugin-scripts.js +24 -8
- package/dist/src/utils/plugin-scripts.js.map +1 -1
- package/dist/src/utils/process-tree.d.ts +1 -1
- package/dist/src/utils/process-tree.js +1 -1
- package/dist/src/utils/process-tree.js.map +1 -1
- package/dist/src/utils/skill-invocation-warning.d.ts +20 -0
- package/dist/src/utils/skill-invocation-warning.js +68 -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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getCommandPackageId } from '@lesliechan721/aw-plugin-core/manifest';
|
|
2
|
-
import { finalizePreparedPlatformRebuildSession } from '../commands/rebuild-integration.js';
|
|
2
|
+
import { finalizePreparedPlatformRebuildSession, recordPreparedGrokProjectRetirement } from '../commands/rebuild-integration.js';
|
|
3
3
|
import { addRequirements } from '../commands/intent-command.js';
|
|
4
4
|
import { createEmptyIntent, calculateIntentDigest, removeIntentRoot } from '../intent/intent-codec.js';
|
|
5
5
|
import { observeIntent, writeIntent, resolveIntentPath } from '../intent/intent-store.js';
|
|
@@ -17,10 +17,16 @@ import { CatalogPreparationReadScope } from '../utils/catalog-operation-context.
|
|
|
17
17
|
import { readCatalogGenerationState } from '../utils/catalog-generation-state.js';
|
|
18
18
|
import { readCatalogSourcesConfigSnapshot } from '../utils/catalog-sources.js';
|
|
19
19
|
import { parsePluginId } from '../utils/multi-source-catalog.js';
|
|
20
|
-
import { readDemand } from './demand.js';
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
20
|
+
import { readDemand, resolveDelivery } from './demand.js';
|
|
21
|
+
import { hasSharedUserPackage } from '../platforms/layout.js';
|
|
22
|
+
import { preparePortableRecovery } from '../portable/recovery.js';
|
|
23
|
+
import { canReuseProviderAcrossScopes, hasInheritableSkills, isInstalledSkillProvider, projectSkillCandidates, readJointDemand, deriveJointDemand, deriveSharedReferenceView, indexJointDependencies } from './joint-demand.js';
|
|
24
|
+
import { checkFootprints, prepareScopedRecovery, executeScopedRecovery, executeRecoveryPreApply, refreshRecoveryNativePreviews, describeRecoveryPlan, errorCode } from './coordinator.js';
|
|
23
25
|
import { isTargetObservationReadError, readScopedRecoveryStatus, readRecoveryStatus } from './status.js';
|
|
26
|
+
import { recoveryRetryDispositions, recoveryStatusContext, retriesFromRequestedRoots } from './receipt.js';
|
|
27
|
+
import { limitInstallNativeRunner, mapInstallReads } from './install-concurrency.js';
|
|
28
|
+
import { executeJointInstall } from './joint-install-execution.js';
|
|
29
|
+
import { RecoveryInterruptedError, recoveryInterruptionCode } from './interruption.js';
|
|
24
30
|
import { measureRecoveryPerformanceStage, recordRecoveryPerformanceStage } from './performance.js';
|
|
25
31
|
import { resolvePluginMetaDependencyClosure } from '../utils/plugin-dependencies.js';
|
|
26
32
|
const diagnostic = (code, message = code) => ({ code, message });
|
|
@@ -31,6 +37,9 @@ function intentReceipt(observation) {
|
|
|
31
37
|
...('digest' in observation ? { digest: observation.digest } : {}),
|
|
32
38
|
};
|
|
33
39
|
}
|
|
40
|
+
function isInstallBatch(command) {
|
|
41
|
+
return command === 'install' || command === 'sync';
|
|
42
|
+
}
|
|
34
43
|
const observationEvidence = (value) => 'rawDigest' in value ? `${value.state}:${value.rawDigest}` : value.state;
|
|
35
44
|
function snapshotEvidence(snapshot) {
|
|
36
45
|
return JSON.stringify([observationEvidence(snapshot.user.intent),
|
|
@@ -42,42 +51,118 @@ function asObservation(value) {
|
|
|
42
51
|
const rawBytes = Buffer.from(JSON.stringify(value));
|
|
43
52
|
return { state: 'valid', value, digest: calculateIntentDigest(value), rawDigest: calculateIntentDigest(value), rawBytes };
|
|
44
53
|
}
|
|
54
|
+
function targetKey(target) {
|
|
55
|
+
return [target.pluginId, target.agent, target.scope].join('\0');
|
|
56
|
+
}
|
|
57
|
+
function matchesExactContribution(placement, contribution, exact, reaches) {
|
|
58
|
+
return placement.target === exact.agent && contribution.scope === exact.scope
|
|
59
|
+
&& reaches(contribution.root, exact.pluginId) && reaches(exact.pluginId, placement.pluginId);
|
|
60
|
+
}
|
|
61
|
+
function useDeclaredRetryRoots(receipt) {
|
|
62
|
+
const status = `aw plugin status --context ${recoveryStatusContext(receipt)} --json`;
|
|
63
|
+
const results = new Map(receipt.targetResults.map((target) => [targetKey(target), target]));
|
|
64
|
+
const pending = new Set(receipt.remainingTargets.map(targetKey));
|
|
65
|
+
const revise = (action) => {
|
|
66
|
+
if (/^aw plugin status --context (?:user|project) --json$/u.test(action))
|
|
67
|
+
return [status];
|
|
68
|
+
// Only rewrite the known command at the end of a backend action. Paths and instructions preceding it stay display text.
|
|
69
|
+
const match = /aw plugin sync (\S+) (?:--context (user|project) --target ([\w-]+)|--target ([\w-]+) --context (user|project))((?: --(?:rebuild|yes))*)([.。]?)$/u.exec(action);
|
|
70
|
+
if (!match)
|
|
71
|
+
return [action];
|
|
72
|
+
const prefix = action.slice(0, match.index);
|
|
73
|
+
if (prefix && !/(?:^|\s)run $|然后重试 $/iu.test(prefix))
|
|
74
|
+
return [action];
|
|
75
|
+
const context = prefix.replace(/(?:then run |run |然后重试 )$/iu, '').trimEnd();
|
|
76
|
+
const target = results.get([match[1], match[3] ?? match[4], match[2] ?? match[5]].join('\0'));
|
|
77
|
+
if (!target || !pending.has(targetKey(target)))
|
|
78
|
+
return context ? [context] : [];
|
|
79
|
+
const dispositions = recoveryRetryDispositions(receipt, [target]);
|
|
80
|
+
if (!dispositions.length)
|
|
81
|
+
return [context ? `${context} ${status}` : status];
|
|
82
|
+
return dispositions.map((root) => {
|
|
83
|
+
if (root.kind === 'exact-project') {
|
|
84
|
+
const exact = `请在 TUI 当前项目中选择 ${root.pluginId} 的 ${root.agent} 位置重新检查。`;
|
|
85
|
+
return context ? `${context} ${exact}` : exact;
|
|
86
|
+
}
|
|
87
|
+
const command = `aw plugin sync ${root.pluginId} --context ${root.scope} --target ${root.agent}${match[6]}`;
|
|
88
|
+
return prefix && prefix !== 'run ' ? `${prefix}${command}${match[7]}` : command;
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
for (const target of receipt.targetResults) {
|
|
92
|
+
if (target.recoveryActions)
|
|
93
|
+
target.recoveryActions = [...new Set(target.recoveryActions.flatMap(revise))];
|
|
94
|
+
}
|
|
95
|
+
receipt.recoveryActions = [...new Set(receipt.recoveryActions.flatMap(revise))];
|
|
96
|
+
}
|
|
45
97
|
function mergeReceipts(plan, receipts) {
|
|
98
|
+
const joint = plan.joint;
|
|
46
99
|
const receipt = structuredClone(plan.receipt);
|
|
47
100
|
receipt.targetResults = receipts.flatMap((item) => item.targetResults);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
receipt.targetResults.push({ pluginId: root.pluginId, agent: root.target, scope: root.scope,
|
|
53
|
-
requirementScope: root.scope, delivery: null, execution: 'no-op', observation: 'verified', content: 'satisfied',
|
|
54
|
-
satisfaction: root.state, requiredBy: [root.pluginId], blockers: [],
|
|
55
|
-
...(root.reasons?.length ? { reasons: root.reasons } : {}) });
|
|
56
|
-
}
|
|
57
|
-
receipt.requestedTargets = receipt.targetResults.map(({ pluginId, agent, scope, delivery }) => ({ pluginId, agent, scope, delivery }));
|
|
101
|
+
receipt.remainingTargets = receipts.flatMap((item) => item.remainingTargets);
|
|
102
|
+
const actions = receipts.flatMap((item) => item.recoveryActions);
|
|
103
|
+
const reviewedOrder = joint.targetOrder;
|
|
104
|
+
const byPosition = (a, b) => (reviewedOrder?.get(targetKey(a)) ?? Number.MAX_SAFE_INTEGER) - (reviewedOrder?.get(targetKey(b)) ?? Number.MAX_SAFE_INTEGER);
|
|
58
105
|
for (const target of receipt.targetResults) {
|
|
59
|
-
const placements =
|
|
60
|
-
const activationOnly =
|
|
106
|
+
const placements = joint.demand.placements;
|
|
107
|
+
const activationOnly = joint.children.some((child) => child.options.nativeActivationOnlyTargets?.some((item) => item.pluginId === target.pluginId && item.platform === target.agent && item.scope === target.scope));
|
|
61
108
|
const placement = placements.find((item) => item.pluginId === target.pluginId && item.target === target.agent && item.scope === target.scope)
|
|
62
109
|
?? (target.scope === 'project' && activationOnly ? placements.find((item) => item.pluginId === target.pluginId && item.target === target.agent && item.scope === 'user'
|
|
63
110
|
&& item.contributions.some((contribution) => contribution.scope === target.scope)) : undefined);
|
|
64
111
|
if (placement) {
|
|
65
112
|
const contributions = placement.scope === target.scope ? placement.contributions
|
|
66
113
|
: placement.contributions.filter((item) => item.scope === target.scope);
|
|
114
|
+
const selectedContributions = retriesFromRequestedRoots(receipt)
|
|
115
|
+
? contributions.filter((item) => joint.selectedContributions.get(placement)?.includes(item)) : contributions;
|
|
67
116
|
target.requiredBy = [...new Set(contributions.map((item) => item.root))];
|
|
68
117
|
target.providerScope = placement.scope;
|
|
118
|
+
if (plan.command !== 'uninstall' || placement.scope !== target.scope)
|
|
119
|
+
target.relation = selectedContributions.some((item) => item.root === target.pluginId && item.scope === target.scope) ? 'root' : 'dependency';
|
|
120
|
+
if (target.relation === 'dependency')
|
|
121
|
+
target.contributions = selectedContributions;
|
|
69
122
|
if (placement.scope !== target.scope) {
|
|
70
123
|
target.requirementScope = target.scope;
|
|
71
|
-
target.
|
|
124
|
+
if (target.satisfaction === 'installed' && placement.scope === 'user')
|
|
125
|
+
target.satisfaction = 'inherited-user';
|
|
72
126
|
}
|
|
73
127
|
}
|
|
74
128
|
}
|
|
75
|
-
|
|
129
|
+
const executed = new Set(receipt.targetResults.map(targetKey));
|
|
130
|
+
const skipped = [];
|
|
131
|
+
for (const root of joint.unplacedRoots) {
|
|
132
|
+
const position = { pluginId: root.pluginId, agent: root.target, scope: root.scope };
|
|
133
|
+
if (executed.has(targetKey(position)))
|
|
134
|
+
continue;
|
|
135
|
+
const common = { ...position, relation: 'root', requiredBy: [root.pluginId], requirementScope: root.scope,
|
|
136
|
+
blockers: root.blockers, ...(root.reasons?.length ? { reasons: root.reasons } : {}) };
|
|
137
|
+
if (root.state === 'excluded' || root.state === 'unsupported') {
|
|
138
|
+
const results = plan.options.exactTargets ? receipt.targetResults : skipped;
|
|
139
|
+
results.push({ ...common, delivery: null, execution: 'no-op', observation: 'verified',
|
|
140
|
+
content: 'satisfied', satisfaction: root.state });
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const plugin = joint.snapshot[root.scope]?.roots?.find((item) => item.pluginId === root.pluginId)?.plugin;
|
|
144
|
+
const delivery = plugin ? resolveDelivery(plugin.manifest, root.target, root.scope) ?? null : null;
|
|
145
|
+
const recoveryActions = [
|
|
146
|
+
...root.blockers.filter((blocker) => blocker.code === 'dependencyExcluded' && blocker.pluginId)
|
|
147
|
+
.map((blocker) => `aw target include ${blocker.pluginId} --target ${root.target}`),
|
|
148
|
+
`aw plugin sync ${root.pluginId} --context ${root.scope} --target ${root.target}`,
|
|
149
|
+
];
|
|
150
|
+
receipt.targetResults.push({ ...common, delivery, execution: 'not-run', observation: 'unknown',
|
|
151
|
+
content: 'unknown', satisfaction: 'unknown', recoveryActions });
|
|
152
|
+
receipt.remainingTargets.push({ ...position, delivery });
|
|
153
|
+
actions.push(...recoveryActions);
|
|
154
|
+
}
|
|
155
|
+
if (reviewedOrder)
|
|
156
|
+
receipt.targetResults.sort(byPosition);
|
|
157
|
+
receipt.targetResults.push(...skipped);
|
|
158
|
+
receipt.requestedTargets = receipt.targetResults.map(({ pluginId, agent, scope, delivery }) => ({ pluginId, agent, scope, delivery }));
|
|
159
|
+
if (reviewedOrder)
|
|
160
|
+
receipt.remainingTargets.sort(byPosition);
|
|
76
161
|
receipt.errors = [...receipt.blockers, ...receipts.flatMap((item) => [...item.blockers, ...item.errors])];
|
|
77
162
|
receipt.outputsMayHaveChanged = receipts.some((item) => item.outputsMayHaveChanged);
|
|
78
163
|
receipt.commandResults = receipts.flatMap((item) => item.commandResults ?? []);
|
|
79
164
|
receipt.nativeToolChanges = receipts.flatMap((item) => item.nativeToolChanges ?? []);
|
|
80
|
-
receipt.recoveryActions = [...new Set(
|
|
165
|
+
receipt.recoveryActions = [...new Set(actions)];
|
|
81
166
|
receipt.ok = receipt.blockers.length === 0 && receipts.every((item) => item.ok);
|
|
82
167
|
return receipt;
|
|
83
168
|
}
|
|
@@ -100,9 +185,37 @@ function finalStatusReadFailure(status, receipt) {
|
|
|
100
185
|
}
|
|
101
186
|
return undefined;
|
|
102
187
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
188
|
+
function blockedBeforeDeployment(plan, blocker = diagnostic('operationReviewStale'), savedState) {
|
|
189
|
+
if (!isInstallBatch(plan.command)) {
|
|
190
|
+
plan.receipt.blockers.push(blocker);
|
|
191
|
+
return mergeReceipts(plan, []);
|
|
192
|
+
}
|
|
193
|
+
const receipt = structuredClone(plan.receipt);
|
|
194
|
+
receipt.ok = false;
|
|
195
|
+
receipt.blockers.push(blocker);
|
|
196
|
+
receipt.errors = [...receipt.blockers];
|
|
197
|
+
receipt.commandResults = [];
|
|
198
|
+
receipt.nativeToolChanges = [];
|
|
199
|
+
receipt.remainingTargets = [];
|
|
200
|
+
receipt.recoveryActions = savedState
|
|
201
|
+
? [`aw plugin status --context ${recoveryStatusContext(receipt)} --json`,
|
|
202
|
+
`请核对当前${savedState === 'intent' ? '插件声明' : '本机 Agent 偏好'}。确认需要的范围后重新准备本次操作。`]
|
|
203
|
+
: ['确认依据已改变,请重新准备本次操作。'];
|
|
204
|
+
if (savedState)
|
|
205
|
+
receipt.unconfirmedSavedState = savedState;
|
|
206
|
+
receipt.targetResults = receipt.targetResults.map((target) => {
|
|
207
|
+
if (target.satisfaction === 'excluded' || target.satisfaction === 'unsupported')
|
|
208
|
+
return target;
|
|
209
|
+
const { pluginId, agent, scope, delivery, relation, requiredBy, requirementScope, providerScope } = target;
|
|
210
|
+
receipt.remainingTargets.push({ pluginId, agent, scope, delivery });
|
|
211
|
+
return { pluginId, agent, scope, delivery, relation, requiredBy, requirementScope, providerScope,
|
|
212
|
+
execution: 'not-run', observation: 'unknown', content: 'unknown', satisfaction: 'unknown', blockers: [blocker] };
|
|
213
|
+
});
|
|
214
|
+
return receipt;
|
|
215
|
+
}
|
|
216
|
+
async function readJointPreparation(command, options, locked = false, suppliedReads) {
|
|
217
|
+
const catalogReadScope = isInstallBatch(command)
|
|
218
|
+
? (locked ? undefined : suppliedReads) ?? new CatalogPreparationReadScope(options) : undefined;
|
|
106
219
|
if (locked && catalogReadScope && options.catalogOperationContext) {
|
|
107
220
|
// A caller may have reviewed a subset of sources. Rebind just those IDs under
|
|
108
221
|
// the lock so a changed or removed source makes the existing Review stale.
|
|
@@ -111,16 +224,22 @@ async function readJointPreparation(command, options, locked = false) {
|
|
|
111
224
|
const sourceIds = configSnapshot.config.sources.map((source) => source.id).filter((id) => reviewed.has(id));
|
|
112
225
|
options = { ...options, catalogOperationContext: await catalogReadScope.resolve({ configSnapshot, sourceIds }) };
|
|
113
226
|
}
|
|
114
|
-
const
|
|
115
|
-
|
|
227
|
+
const manifestReads = isInstallBatch(command) ? new Map() : undefined;
|
|
228
|
+
const snapshot = await readJointDemand({ ...options, catalogReadScope, manifestReads });
|
|
229
|
+
return { options, snapshot, catalogReadScope, manifestReads };
|
|
116
230
|
}
|
|
117
231
|
/** Complete requirements determine placement before execution selectors are applied. */
|
|
118
232
|
export async function prepareJointRecovery(command, selectors, options, runtime, preparation) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
233
|
+
const originalRunner = runtime.nativeCliRunner ?? getDefaultNativeCliRunner();
|
|
234
|
+
runtime = { ...runtime, ...(isInstallBatch(command) ? { nativeCliRunner: limitInstallNativeRunner(originalRunner) } : {}),
|
|
235
|
+
preparedArtifactRenderResults: runtime.preparedArtifactRenderResults ?? new Map() };
|
|
236
|
+
const { snapshot, catalogReadScope, manifestReads } = preparation ?? await readJointPreparation(command, options, false, runtime.catalogReadScope);
|
|
237
|
+
const prepare = async (current) => {
|
|
238
|
+
const read = (nativeObservationBatch) => prepareJointRecoveryInSession(command, selectors, options, current, snapshot, { catalogReadScope, nativeObservationBatch }, manifestReads);
|
|
239
|
+
const plan = isInstallBatch(command)
|
|
240
|
+
? await withNativeObservationBatch({ runner: current.nativeCliRunner, signal: options.signal }, read) : await read();
|
|
241
|
+
plan.joint.originalNativeRunner = originalRunner;
|
|
242
|
+
return plan;
|
|
124
243
|
};
|
|
125
244
|
if (runtime.codexObservationSession)
|
|
126
245
|
return prepare(runtime);
|
|
@@ -131,6 +250,7 @@ export async function prepareJointRecovery(command, selectors, options, runtime,
|
|
|
131
250
|
env: observationContext.env, runner: (invocation) => sessionRunner(invocation), manager: runtime.codexManager });
|
|
132
251
|
try {
|
|
133
252
|
const plan = await prepare({ ...runtime, codexObservationSession: session });
|
|
253
|
+
plan.joint.bindExecutionSignal = (signal) => { sessionRunner = bindNativeCliRunnerSignal(executionRunner, signal); };
|
|
134
254
|
const dispose = plan.context.dispose;
|
|
135
255
|
plan.context.dispose = async () => {
|
|
136
256
|
try {
|
|
@@ -158,10 +278,10 @@ export async function prepareJointRecovery(command, selectors, options, runtime,
|
|
|
158
278
|
}
|
|
159
279
|
finally {
|
|
160
280
|
// The same observation session also serves confirmed writes, which cannot use preparation cancellation.
|
|
161
|
-
sessionRunner = executionRunner;
|
|
281
|
+
sessionRunner = bindNativeCliRunnerSignal(executionRunner, runtime.signal);
|
|
162
282
|
}
|
|
163
283
|
}
|
|
164
|
-
async function prepareJointRecoveryInSession(command, selectors, { checkInstallCatalog, ...options }, runtime, snapshot, { catalogReadScope, nativeObservationBatch }) {
|
|
284
|
+
async function prepareJointRecoveryInSession(command, selectors, { checkInstallCatalog, ...options }, runtime, snapshot, { catalogReadScope, nativeObservationBatch }, manifestReads) {
|
|
165
285
|
// Status observes saved requirements, before projecting proposed declarations.
|
|
166
286
|
// Reuse them only within this preparation; execution reads them again under the lock.
|
|
167
287
|
const savedDemand = snapshot;
|
|
@@ -171,6 +291,9 @@ async function prepareJointRecoveryInSession(command, selectors, { checkInstallC
|
|
|
171
291
|
let observedStatus;
|
|
172
292
|
const evidence = snapshotEvidence(snapshot);
|
|
173
293
|
const scope = options.scope ?? snapshot.context.context;
|
|
294
|
+
if (options.exactTargets && command !== 'uninstall') {
|
|
295
|
+
options = { ...options, exactTargets: options.exactTargets.map((entry) => ({ ...entry, scope: entry.scope ?? scope })) };
|
|
296
|
+
}
|
|
174
297
|
const observedIntent = (scope === 'project' ? snapshot.project : snapshot.user).intent;
|
|
175
298
|
if (options.existingOnly) {
|
|
176
299
|
// Existing owned deployments can be refreshed without converting them into declarations.
|
|
@@ -195,14 +318,21 @@ async function prepareJointRecoveryInSession(command, selectors, { checkInstallC
|
|
|
195
318
|
value.sources[sourceId] = { logicalIdentity: identity };
|
|
196
319
|
value.roots.push({ pluginId: item.pluginId });
|
|
197
320
|
}
|
|
198
|
-
snapshot = { ...snapshot, [currentScope]: await readDemand({ ...options, catalogReadScope, preferences: undefined, scope: currentScope, intent: asObservation(value) }) };
|
|
321
|
+
snapshot = { ...snapshot, [currentScope]: await readDemand({ ...options, catalogReadScope, manifestReads, preferences: undefined, scope: currentScope, intent: asObservation(value) }) };
|
|
199
322
|
}
|
|
200
323
|
if (snapshot.preferences)
|
|
201
324
|
snapshot.preferences = { ...snapshot.preferences,
|
|
202
325
|
targets: normalizeAgents([...snapshot.preferences.targets, ...installed.map((item) => item.agent)]) };
|
|
203
326
|
}
|
|
204
327
|
}
|
|
205
|
-
|
|
328
|
+
let previousDemand = deriveJointDemand(snapshot);
|
|
329
|
+
const previousCandidates = projectSkillCandidates(previousDemand);
|
|
330
|
+
if (command === 'uninstall' && previousCandidates.length) {
|
|
331
|
+
observedStatus ??= await readRecoveryStatus({ ...options, catalogReadScope, ...initialNativeReads, targets: undefined }, savedDemand);
|
|
332
|
+
previousDemand = deriveJointDemand(snapshot, observedStatus.projectSkillProviders);
|
|
333
|
+
}
|
|
334
|
+
const previousUserProvided = (pluginId, target) => previousDemand.placements.some((item) => item.pluginId === pluginId && item.target === target && item.scope === 'user'
|
|
335
|
+
&& item.contributions.some((entry) => entry.scope === 'project'));
|
|
206
336
|
const previousPlugins = [...new Map([...(snapshot.user.plugins), ...(snapshot.project?.plugins ?? [])]
|
|
207
337
|
.map((plugin) => [plugin.pluginId, plugin])).values()];
|
|
208
338
|
const dependencyClosures = new Map();
|
|
@@ -234,7 +364,7 @@ async function prepareJointRecoveryInSession(command, selectors, { checkInstallC
|
|
|
234
364
|
requested = proposed.roots;
|
|
235
365
|
if (proposed.changed)
|
|
236
366
|
declaration = { scope, value: proposed.state };
|
|
237
|
-
const demand = await readDemand({ ...options, catalogReadScope, preferences: undefined, scope, intent: asObservation(proposed.state) });
|
|
367
|
+
const demand = await readDemand({ ...options, catalogReadScope, manifestReads, preferences: undefined, scope, intent: asObservation(proposed.state) });
|
|
238
368
|
checkInstallCatalog?.(demand.catalogOperationContext, requested);
|
|
239
369
|
snapshot = { ...snapshot, [scope]: demand };
|
|
240
370
|
}
|
|
@@ -290,8 +420,31 @@ async function prepareJointRecoveryInSession(command, selectors, { checkInstallC
|
|
|
290
420
|
}
|
|
291
421
|
}
|
|
292
422
|
}
|
|
293
|
-
|
|
294
|
-
|
|
423
|
+
let demand = deriveJointDemand(snapshot);
|
|
424
|
+
const pendingUserSkills = [];
|
|
425
|
+
const candidates = projectSkillCandidates(demand).filter((item) => !options.targets || options.targets.includes(item.target));
|
|
426
|
+
if (candidates.length) {
|
|
427
|
+
observedStatus ??= await readRecoveryStatus({ ...options, catalogReadScope, ...initialNativeReads, targets: undefined,
|
|
428
|
+
projectSkillProbes: candidates }, savedDemand);
|
|
429
|
+
const providers = observedStatus.projectSkillProviders?.map((provider) => {
|
|
430
|
+
if ((!provider.userNeedsRepair && !provider.userAbsent) || provider.projectCopy === 'blocked' || command !== 'sync' || options.existingOnly)
|
|
431
|
+
return provider;
|
|
432
|
+
// A joint sync can repair its selected, owned User package before the Project consumer runs.
|
|
433
|
+
const owned = observedStatus.observedTargets?.some((target) => target.pluginId === provider.pluginId && target.agent === provider.target
|
|
434
|
+
&& target.scope === 'user' && target.content === 'drifted' && !target.blockers.length
|
|
435
|
+
&& target.deploymentObservations?.every(({ after }) => after.ownership === 'aw'));
|
|
436
|
+
const selectedUserRoot = demand.placements.some((item) => item.scope === 'user' && item.pluginId === provider.pluginId
|
|
437
|
+
&& item.target === provider.target && item.contributions.some((entry) => entry.scope === 'user'
|
|
438
|
+
&& (!selectors.length || selectors.some((id) => id === entry.root || id === parsePluginId(entry.root).pluginName))
|
|
439
|
+
&& (!options.exactTargets || options.exactTargets.some((exact) => exact.scope === 'user'
|
|
440
|
+
&& exact.agent === item.target && exact.pluginId === entry.root))));
|
|
441
|
+
if (!selectedUserRoot || !owned && !provider.userAbsent)
|
|
442
|
+
return provider;
|
|
443
|
+
pendingUserSkills.push({ pluginId: provider.pluginId, target: provider.target, sourceIdentity: provider.sourceIdentity });
|
|
444
|
+
return { ...provider, userNeedsRepair: false, userAbsent: false };
|
|
445
|
+
});
|
|
446
|
+
demand = deriveJointDemand(snapshot, providers);
|
|
447
|
+
}
|
|
295
448
|
const rootIds = [...new Set([...(snapshot.user.roots ?? []), ...(snapshot.project?.roots ?? [])]
|
|
296
449
|
.map((root) => root.pluginId))];
|
|
297
450
|
if (command !== 'install' && command !== 'uninstall') {
|
|
@@ -304,6 +457,15 @@ async function prepareJointRecoveryInSession(command, selectors, { checkInstallC
|
|
|
304
457
|
}) : rootIds;
|
|
305
458
|
}
|
|
306
459
|
const targets = options.targets ? normalizeAgents(options.targets) : snapshot.preferences?.targets ?? [];
|
|
460
|
+
const unplacedRoots = demand.roots.filter((root) => root.state !== 'required'
|
|
461
|
+
&& requested.includes(root.pluginId) && targets.includes(root.target)
|
|
462
|
+
&& (!options.exactTargets || options.exactTargets.some((exact) => exact.pluginId === root.pluginId
|
|
463
|
+
&& exact.agent === root.target && (exact.scope ?? scope) === root.scope))
|
|
464
|
+
&& (command !== 'uninstall' || root.state === 'excluded' || root.state === 'unsupported'));
|
|
465
|
+
// Global diagnostics gate shared preparation. A blocked install root cannot prevent
|
|
466
|
+
// an independent selected root from checking its Project activation.
|
|
467
|
+
const rootErrors = new Set(demand.roots.flatMap((root) => root.blockers));
|
|
468
|
+
errors.push(...demand.errors.filter((error) => command === 'uninstall' || !rootErrors.has(error)));
|
|
307
469
|
const explicitlyRemoves = (item) => item.scope === scope && requested.includes(item.pluginId) && (!options.exactTargets
|
|
308
470
|
|| options.exactTargets.some((exact) => exact.pluginId === item.pluginId && exact.agent === item.agent
|
|
309
471
|
&& (!exact.scope || exact.scope === item.scope)));
|
|
@@ -325,23 +487,37 @@ async function prepareJointRecoveryInSession(command, selectors, { checkInstallC
|
|
|
325
487
|
&& (requested.includes(placement.pluginId) || placement.contributions.some((item) => requested.includes(item.root))))))) {
|
|
326
488
|
errors.push(diagnostic('invalidExactTargets', '精确重试目标不属于当前请求,请重新检查并选择。'));
|
|
327
489
|
}
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
&&
|
|
339
|
-
|
|
340
|
-
|
|
490
|
+
const dependencyGraph = indexJointDependencies(demand);
|
|
491
|
+
const { reaches } = dependencyGraph;
|
|
492
|
+
const requestedIds = new Set(requested);
|
|
493
|
+
const selectedContributions = new Map();
|
|
494
|
+
const selected = demand.placements.filter((placement) => {
|
|
495
|
+
if (!targets.includes(placement.target))
|
|
496
|
+
return false;
|
|
497
|
+
if (command === 'uninstall')
|
|
498
|
+
return (canReuseProviderAcrossScopes(placement.target) || previousUserProvided(placement.pluginId, placement.target))
|
|
499
|
+
&& !(options.force && requestedIds.has(placement.pluginId))
|
|
500
|
+
&& previousDemand.placements.some((previous) => previous.pluginId === placement.pluginId && previous.target === placement.target
|
|
501
|
+
&& previous.scope !== placement.scope && previous.contributions.some((item) => item.scope === scope && requestedIds.has(item.root))
|
|
502
|
+
&& (!options.exactTargets || options.exactTargets.some((exact) => exact.agent === placement.target
|
|
503
|
+
&& previous.contributions.some((item) => item.path.includes(exact.pluginId) && (!exact.scope || item.scope === exact.scope)))));
|
|
504
|
+
const contributions = placement.contributions.filter((item) => {
|
|
505
|
+
const selects = (pluginId) => !options.exactTargets || options.exactTargets.some((exact) => matchesExactContribution(placement, item, exact, reaches)
|
|
506
|
+
&& (reaches(pluginId, exact.pluginId) || reaches(exact.pluginId, pluginId)));
|
|
507
|
+
if (requestedIds.has(item.root) || options.existingOnly && requestedIds.has(placement.pluginId))
|
|
508
|
+
return selects(item.root);
|
|
509
|
+
return options.allowDependencySelectors && requested.some((id) => reaches(item.root, id)
|
|
510
|
+
&& reaches(id, placement.pluginId) && selects(id));
|
|
511
|
+
});
|
|
512
|
+
if (!contributions.length)
|
|
513
|
+
return false;
|
|
514
|
+
selectedContributions.set(placement, contributions);
|
|
515
|
+
return true;
|
|
516
|
+
});
|
|
341
517
|
const activationOnlyTargets = [];
|
|
342
518
|
if (snapshot.project && !errors.length) {
|
|
343
|
-
const sharedNative = selected.filter((item) => item.scope === 'user' &&
|
|
344
|
-
&& item.contributions.some((entry) => entry.scope === 'project'));
|
|
519
|
+
const sharedNative = selected.filter((item) => item.scope === 'user' && hasSharedUserPackage(item.target)
|
|
520
|
+
&& (command === 'uninstall' ? item.contributions : selectedContributions.get(item))?.some((entry) => entry.scope === 'project'));
|
|
345
521
|
if (sharedNative.length) {
|
|
346
522
|
const expanded = { ...snapshot.project, roots: [...new Map(sharedNative.map((item) => [item.pluginId, {
|
|
347
523
|
pluginId: item.pluginId, sourceId: item.plugin.sourceId, sourceState: 'ready', blockers: [], plugin: item.plugin,
|
|
@@ -350,6 +526,11 @@ async function prepareJointRecoveryInSession(command, selectors, { checkInstallC
|
|
|
350
526
|
const observation = await readScopedRecoveryStatus({ ...options, catalogReadScope, ...initialNativeReads, scope: 'project', demandOverride: expanded,
|
|
351
527
|
cwd: snapshot.context.projectRoot, targets: undefined });
|
|
352
528
|
for (const item of sharedNative) {
|
|
529
|
+
const addProjectActivation = () => {
|
|
530
|
+
const activation = { ...item, scope: 'project' };
|
|
531
|
+
selected.push(activation);
|
|
532
|
+
selectedContributions.set(activation, selectedContributions.get(item)?.filter((entry) => entry.scope === 'project') ?? []);
|
|
533
|
+
};
|
|
353
534
|
const actual = observation.inventory?.find((entry) => entry.pluginId === item.pluginId)?.targetResults
|
|
354
535
|
.find((entry) => entry.agent === item.target);
|
|
355
536
|
if (item.target === 'codex') {
|
|
@@ -364,20 +545,23 @@ async function prepareJointRecoveryInSession(command, selectors, { checkInstallC
|
|
|
364
545
|
if (!surface.nativeKinds.length || !explicitlyDisabled && !retiringProjectComponents)
|
|
365
546
|
continue;
|
|
366
547
|
activationOnlyTargets.push({ pluginId: item.pluginId, platform: 'codex', scope: 'project' });
|
|
367
|
-
|
|
548
|
+
addProjectActivation();
|
|
368
549
|
continue;
|
|
369
550
|
}
|
|
370
551
|
}
|
|
371
552
|
if (actual?.content !== 'satisfied') {
|
|
372
553
|
if (item.target !== 'generic')
|
|
373
554
|
activationOnlyTargets.push({ pluginId: item.pluginId, platform: item.target, scope: 'project' });
|
|
374
|
-
|
|
555
|
+
addProjectActivation();
|
|
375
556
|
}
|
|
376
557
|
}
|
|
377
558
|
}
|
|
378
559
|
}
|
|
379
560
|
const context = await createScopeContext({ ...options, scope });
|
|
561
|
+
if (command !== 'uninstall')
|
|
562
|
+
errors.push(...unplacedRoots.flatMap((root) => root.blockers));
|
|
380
563
|
const baseDemand = scope === 'project' ? snapshot.project : snapshot.user;
|
|
564
|
+
const rebuildsRequestedRoots = command === 'reinstall' && !options.allowDependencySelectors && !options.existingOnly;
|
|
381
565
|
const receipt = {
|
|
382
566
|
schemaVersion: 1, kind: 'aw-recovery', command, scope, ok: false,
|
|
383
567
|
intent: intentReceipt(observedIntent),
|
|
@@ -385,11 +569,16 @@ async function prepareJointRecoveryInSession(command, selectors, { checkInstallC
|
|
|
385
569
|
selection: { agents: targets, origin: options.targets ? 'argument' : targets.length ? 'preference' : 'none', preferences: snapshot.user.preferences.state },
|
|
386
570
|
blockers: errors, errors, recoveryActions: [], declarationChanged: false, preferencesChanged: false,
|
|
387
571
|
configChanged: false, outputsMayHaveChanged: false,
|
|
572
|
+
...(rebuildsRequestedRoots ? { rebuildsRequestedRoots: true } : {}),
|
|
573
|
+
...((isInstallBatch(command) || rebuildsRequestedRoots) && snapshot.context.scopes.includes('project') ? {
|
|
574
|
+
reviewedUserRoots: intentReceipt(options.existingOnly ? savedDemand.user.intent : snapshot.user.intent)
|
|
575
|
+
.roots?.filter((id) => requested.includes(id)) ?? null,
|
|
576
|
+
} : {}),
|
|
388
577
|
coverage: { scopes: snapshot.context.scopes, ...(snapshot.context.projectRoot ? { projectRoot: snapshot.context.projectRoot } : {}) },
|
|
389
578
|
};
|
|
390
579
|
const children = [];
|
|
391
580
|
const { signal: _signal, ...executionOptions } = options;
|
|
392
|
-
const joint = { snapshot, demand, removalDependencies: dependencyClosures, children, originalOptions: executionOptions,
|
|
581
|
+
const joint = { snapshot, demand, unplacedRoots, removalDependencies: dependencyClosures, selectedContributions, children, originalOptions: executionOptions, pendingUserSkills, providerRetirements: new Set(),
|
|
393
582
|
selectors: [...selectors], declaration, evidence };
|
|
394
583
|
const plan = { command, options: { ...executionOptions, scope }, receipt, context, demand: baseDemand,
|
|
395
584
|
originalIntent: observationEvidence(original.intent), preferencesEvidence: observationEvidence(snapshot.user.preferences),
|
|
@@ -400,7 +589,11 @@ async function prepareJointRecoveryInSession(command, selectors, { checkInstallC
|
|
|
400
589
|
|| error.code === 'targetsNotConfigured' && !options.retireUnselectedTargets)
|
|
401
590
|
|| !snapshot.preferences || snapshot.user.roots === null || snapshot.project?.roots === null, joint };
|
|
402
591
|
const dispose = context.dispose;
|
|
403
|
-
|
|
592
|
+
let portableUserContext;
|
|
593
|
+
context.dispose = async () => {
|
|
594
|
+
await Promise.all([...children.map((child) => child.context.dispose()), portableUserContext?.dispose()]);
|
|
595
|
+
await dispose();
|
|
596
|
+
};
|
|
404
597
|
if (plan.blockExecution)
|
|
405
598
|
return plan;
|
|
406
599
|
try {
|
|
@@ -408,9 +601,10 @@ async function prepareJointRecoveryInSession(command, selectors, { checkInstallC
|
|
|
408
601
|
const sharedReferenceView = deriveSharedReferenceView(snapshot, demand, currentStatus);
|
|
409
602
|
const ownsOutput = (item) => currentStatus.ownedTargets?.some((owned) => owned.pluginId === item.pluginId
|
|
410
603
|
&& owned.agent === item.agent && owned.scope === item.scope) === true;
|
|
411
|
-
const
|
|
604
|
+
const liveTargets = currentStatus.existingTargets ?? [];
|
|
605
|
+
const liveConsumers = [...liveTargets, ...(currentStatus.retainedProjectPackages ?? [])];
|
|
412
606
|
const sameProvider = (consumer, provider) => consumer.agent === provider.agent && (consumer.scope === provider.scope
|
|
413
|
-
|| provider.scope === 'user' && canReuseProviderAcrossScopes(consumer.agent));
|
|
607
|
+
|| provider.scope === 'user' && (canReuseProviderAcrossScopes(consumer.agent) || previousUserProvided(provider.pluginId, consumer.agent)));
|
|
414
608
|
const automaticRetirements = command === 'uninstall' && !options.keepDependencies && demand.complete
|
|
415
609
|
? previousDemand.placements.filter((placement) => placement.scope === scope && targets.includes(placement.target)
|
|
416
610
|
&& (placement.target !== 'generic' ? currentStatus.coverage.native : currentStatus.coverage.portable)
|
|
@@ -419,20 +613,36 @@ async function prepareJointRecoveryInSession(command, selectors, { checkInstallC
|
|
|
419
613
|
: snapshot[placement.scope]?.roots?.some((root) => root.pluginId === placement.pluginId))
|
|
420
614
|
&& placement.contributions.some((item) => explicitlyRemoves({ pluginId: item.root, agent: placement.target, scope: item.scope }))
|
|
421
615
|
&& !demand.placements.some((item) => item.pluginId === placement.pluginId && item.target === placement.target
|
|
422
|
-
&& (item.scope === placement.scope || canReuseProviderAcrossScopes(placement.target)))
|
|
616
|
+
&& (item.scope === placement.scope || canReuseProviderAcrossScopes(placement.target) || previousUserProvided(placement.pluginId, placement.target)))
|
|
423
617
|
&& ownsOutput({ pluginId: placement.pluginId, agent: placement.target, scope: placement.scope })) : [];
|
|
424
618
|
// A live consumer can outlast its Intent or its Active catalog entry.
|
|
425
619
|
const retainedConsumerFor = (provider) => liveConsumers.find((consumer) => {
|
|
426
620
|
if (explicitlyRemoves(consumer) && ownsOutput(consumer) || automaticRetirements.some((item) => item.pluginId === consumer.pluginId && item.target === consumer.agent && item.scope === consumer.scope))
|
|
427
621
|
return false;
|
|
428
|
-
|
|
622
|
+
const sourceIdentity = consumer.nativePackage?.sourceIdentity;
|
|
623
|
+
const providerManifest = sourceIdentity && previousPlugins.find((plugin) => plugin.pluginId === provider.pluginId && plugin.sourceIdentity === sourceIdentity);
|
|
624
|
+
if (consumer.dependencies !== undefined && !providerManifest)
|
|
625
|
+
return false;
|
|
626
|
+
const liveNativeInheritance = provider.scope === 'user' && consumer.scope === 'project' && consumer.agent === provider.agent
|
|
627
|
+
&& providerManifest && !canReuseProviderAcrossScopes(consumer.agent) && hasInheritableSkills(providerManifest)
|
|
628
|
+
&& liveTargets.some((item) => item.pluginId === provider.pluginId && item.agent === provider.agent && item.scope === 'user'
|
|
629
|
+
&& item.nativePackage?.sourceIdentity === sourceIdentity);
|
|
630
|
+
if (!sameProvider(consumer, provider) && !liveNativeInheritance)
|
|
429
631
|
return false;
|
|
430
|
-
const closure = dependencies(consumer.pluginId);
|
|
632
|
+
const closure = consumer.dependencies === undefined ? dependencies(consumer.pluginId) : consumer.dependencies;
|
|
431
633
|
if (!closure?.includes(provider.pluginId) && !(closure === null
|
|
432
634
|
&& parsePluginId(consumer.pluginId).sourceId === parsePluginId(provider.pluginId).sourceId))
|
|
433
635
|
return false;
|
|
636
|
+
if (liveNativeInheritance) {
|
|
637
|
+
const projectCopyReady = liveTargets.some((item) => item.pluginId === provider.pluginId
|
|
638
|
+
&& item.agent === provider.agent && item.scope === 'project' && item.nativePackage?.sourceIdentity === sourceIdentity
|
|
639
|
+
&& item.nativePackage?.skillsReady);
|
|
640
|
+
const stagedReplacement = selected.some((item) => item.pluginId === provider.pluginId
|
|
641
|
+
&& item.target === provider.agent && item.scope === 'project' && item.plugin.sourceIdentity === sourceIdentity);
|
|
642
|
+
return !projectCopyReady && !stagedReplacement;
|
|
643
|
+
}
|
|
434
644
|
return !demand.placements.some((item) => item.pluginId === provider.pluginId && item.target === provider.agent
|
|
435
|
-
&& item.scope !== provider.scope && sameProvider(consumer, { agent: item.target, scope: item.scope }));
|
|
645
|
+
&& item.scope !== provider.scope && sameProvider(consumer, { pluginId: item.pluginId, agent: item.target, scope: item.scope }));
|
|
436
646
|
});
|
|
437
647
|
for (let index = automaticRetirements.length - 1; index >= 0; index--) {
|
|
438
648
|
const candidate = automaticRetirements[index];
|
|
@@ -487,16 +697,42 @@ async function prepareJointRecoveryInSession(command, selectors, { checkInstallC
|
|
|
487
697
|
}
|
|
488
698
|
plan.dependencyCleanupTargets = automaticRetirements.map((item) => ({ pluginId: item.pluginId, agent: item.target, scope: item.scope }));
|
|
489
699
|
const nativeTargets = targets.filter((target) => target !== 'generic');
|
|
490
|
-
const
|
|
491
|
-
|
|
700
|
+
const batch = isInstallBatch(command);
|
|
701
|
+
const hasSelectedScripts = selected.some((item) => item.plugin.manifest.scripts?.preApply);
|
|
702
|
+
if (batch && nativeObservationBatch && [...demand.placements, ...selected].every(({ plugin }) => {
|
|
703
|
+
const scripts = plugin.manifest.scripts;
|
|
704
|
+
return !scripts?.artifacts?.render && !scripts?.preApply && !scripts?.node?.build;
|
|
705
|
+
}))
|
|
706
|
+
nativeObservationBatch.scriptFreePlacement = true;
|
|
707
|
+
const portableGenerations = new Map();
|
|
708
|
+
const targetGroups = batch ? [...nativeTargets, ...targets.filter((target) => target === 'generic')].map((target) => [target])
|
|
709
|
+
: [...(nativeTargets.length ? [nativeTargets] : []), ...targets.filter((target) => target === 'generic').map((target) => [target])];
|
|
492
710
|
for (const currentScope of snapshot.context.scopes) {
|
|
493
|
-
|
|
711
|
+
const prepareGroup = async (groupTargets) => {
|
|
712
|
+
const inheritedScripts = currentScope === 'user' && command === 'sync' && !options.existingOnly
|
|
713
|
+
? selected.filter((item) => {
|
|
714
|
+
if (item.scope !== 'user' || !groupTargets.includes(item.target) || !item.plugin.manifest.scripts?.preApply)
|
|
715
|
+
return false;
|
|
716
|
+
const contributions = selectedContributions.get(item);
|
|
717
|
+
return !contributions.some((entry) => entry.scope === 'user')
|
|
718
|
+
&& contributions.some((entry) => entry.scope === 'project' && entry.root !== item.pluginId)
|
|
719
|
+
&& !(requestedIds.has(item.pluginId) && (!options.exactTargets || options.exactTargets.some((exact) => exact.pluginId === item.pluginId && exact.agent === item.target && contributions.some((entry) => entry.scope === exact.scope))));
|
|
720
|
+
}) : [];
|
|
721
|
+
const inheritedPortableProviderIds = inheritedScripts.filter((item) => item.target === 'generic').map((item) => item.pluginId);
|
|
494
722
|
const placements = selected.filter((item) => item.scope === currentScope && groupTargets.includes(item.target)
|
|
723
|
+
&& !(item.scope === 'user' && !canReuseProviderAcrossScopes(item.target)
|
|
724
|
+
&& selectedContributions.get(item)?.every((entry) => entry.scope === 'project')
|
|
725
|
+
&& currentStatus.observedTargets?.some((actual) => actual.pluginId === item.pluginId
|
|
726
|
+
&& actual.agent === item.target && isInstalledSkillProvider(actual)))
|
|
495
727
|
&& !(command === 'install' && scope === 'project' && currentScope === 'user'
|
|
496
728
|
&& currentStatus.observedTargets?.some((observed) => observed.pluginId === item.pluginId
|
|
497
|
-
&& observed.agent === item.target && observed.scope === 'user' && observed.content === 'satisfied'))
|
|
729
|
+
&& observed.agent === item.target && observed.scope === 'user' && observed.content === 'satisfied'))
|
|
730
|
+
&& !(hasSharedUserPackage(item.target) && inheritedScripts.includes(item)
|
|
731
|
+
&& currentStatus.observedTargets?.some((observed) => observed.pluginId === item.pluginId
|
|
732
|
+
&& observed.agent === item.target && observed.scope === 'user' && observed.providerScope === 'user'
|
|
733
|
+
&& observed.observation === 'verified' && observed.content === 'satisfied' && !observed.blockers.length)));
|
|
498
734
|
if (!placements.length)
|
|
499
|
-
|
|
735
|
+
return;
|
|
500
736
|
const sourceDemand = currentScope === 'project' ? snapshot.project : snapshot.user;
|
|
501
737
|
const childPlacements = [
|
|
502
738
|
...demand.placements.filter((item) => item.scope === currentScope && groupTargets.includes(item.target)),
|
|
@@ -511,7 +747,7 @@ async function prepareJointRecoveryInSession(command, selectors, { checkInstallC
|
|
|
511
747
|
roots: [...new Map(childPlacements.map((item) => [item.pluginId, { pluginId: item.pluginId, sourceId: item.plugin.sourceId,
|
|
512
748
|
sourceState: 'ready', blockers: [], plugin: item.plugin }])).values()] };
|
|
513
749
|
const child = await prepareScopedRecovery(command === 'reinstall' ? 'reinstall' : 'sync', [...new Set(placements.map((item) => item.pluginId))], { ...options, scope: currentScope, targets: groupTargets, all: false,
|
|
514
|
-
sharedReferenceView,
|
|
750
|
+
sharedReferenceView, inheritedPortableProviderIds,
|
|
515
751
|
cwd: snapshot.context.projectRoot ?? options.cwd, demandOverride: childDemand,
|
|
516
752
|
exactTargets: placements.map((item) => ({ pluginId: item.pluginId, agent: item.target })),
|
|
517
753
|
nativeActivationOnlyTargets: activationOnlyTargets.filter((item) => item.scope === currentScope
|
|
@@ -526,7 +762,10 @@ async function prepareJointRecoveryInSession(command, selectors, { checkInstallC
|
|
|
526
762
|
? userProviders.filter((provider) => provider.target !== 'generic'
|
|
527
763
|
&& !placements.some((item) => item.pluginId === provider.pluginId && item.target === provider.target))
|
|
528
764
|
.map((item) => ({ pluginId: item.pluginId, platform: item.target, scope: 'user' })) : [],
|
|
529
|
-
},
|
|
765
|
+
}, batch && groupTargets[0] !== 'generic'
|
|
766
|
+
? { ...runtime, batchInstallPlatform: groupTargets[0] } : runtime, { catalogReadScope, portableGenerations, nativeObservationBatch: batch || children.length === 0 ? nativeObservationBatch : undefined });
|
|
767
|
+
// Track contexts as soon as acquired, including a sibling that finishes after cancellation.
|
|
768
|
+
children.push(child);
|
|
530
769
|
// Synthetic roots are only an execution projection, never persisted Intent.
|
|
531
770
|
child.originalIntent = observationEvidence(sourceDemand.intent);
|
|
532
771
|
if (options.existingOnly) {
|
|
@@ -538,9 +777,56 @@ async function prepareJointRecoveryInSession(command, selectors, { checkInstallC
|
|
|
538
777
|
}
|
|
539
778
|
}
|
|
540
779
|
}
|
|
541
|
-
|
|
780
|
+
return child;
|
|
781
|
+
};
|
|
782
|
+
if (batch) {
|
|
783
|
+
const start = children.length;
|
|
784
|
+
const ordered = await mapInstallReads(targetGroups, prepareGroup, { signal: options.signal });
|
|
785
|
+
children.splice(start, children.length - start, ...ordered.filter((child) => child !== undefined));
|
|
542
786
|
}
|
|
787
|
+
else
|
|
788
|
+
for (const groupTargets of targetGroups)
|
|
789
|
+
await prepareGroup(groupTargets);
|
|
543
790
|
}
|
|
791
|
+
if (hasSelectedScripts && (batch || command === 'reinstall')) {
|
|
792
|
+
const projectPortable = children.find((child) => child.options.scope === 'project' && child.portableGroups.length);
|
|
793
|
+
const consumers = (projectPortable?.portableGroups ?? []).map((group) => ({ pluginId: group.options.selector,
|
|
794
|
+
providers: [...dependencyGraph.providers({ pluginId: group.options.selector, target: 'generic', scope: 'project' })]
|
|
795
|
+
.filter((item) => item.scope === 'user').map((item) => item.pluginId) }));
|
|
796
|
+
const required = [...new Set(consumers.flatMap((item) => item.providers))];
|
|
797
|
+
if (projectPortable && required.length) {
|
|
798
|
+
const userPortable = children.find((child) => child.options.scope === 'user' && child.options.targets?.includes('generic'));
|
|
799
|
+
const reviewed = new Map([...(userPortable?.portableProtectionGroups ?? []), ...(userPortable?.portableGroups ?? [])]
|
|
800
|
+
.map((group) => [group.options.selector, group]));
|
|
801
|
+
const providerContext = userPortable?.context ?? (portableUserContext = await createScopeContext({ ...options, scope: 'user' }));
|
|
802
|
+
// First Project install can reuse a healthy User provider without creating a User execution row.
|
|
803
|
+
await mapInstallReads(required.filter((id) => !reviewed.has(id)), async (selector) => {
|
|
804
|
+
const provider = await preparePortableRecovery({ scope: 'user', context: providerContext, selector, agents: ['generic'],
|
|
805
|
+
cliVersion: options.cliVersion, catalogOperationContext: snapshot.user.catalogOperationContext,
|
|
806
|
+
signal: options.signal }, catalogReadScope, portableGenerations);
|
|
807
|
+
delete provider.options.signal;
|
|
808
|
+
reviewed.set(selector, provider);
|
|
809
|
+
}, { signal: options.signal });
|
|
810
|
+
const checks = new Map();
|
|
811
|
+
for (const consumer of consumers)
|
|
812
|
+
if (consumer.providers.length) {
|
|
813
|
+
checks.set(consumer.pluginId, consumer.providers.map((id) => reviewed.get(id)));
|
|
814
|
+
}
|
|
815
|
+
projectPortable.options.portableProviderChecks = checks;
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
if (batch)
|
|
819
|
+
for (const currentScope of snapshot.context.scopes) {
|
|
820
|
+
const scoped = children.filter((child) => child.options.scope === currentScope);
|
|
821
|
+
if (scoped.length < 2)
|
|
822
|
+
continue;
|
|
823
|
+
const first = scoped[0];
|
|
824
|
+
await checkFootprints({ ...first, changes: [],
|
|
825
|
+
nativeGroups: scoped.flatMap((child) => child.nativeGroups),
|
|
826
|
+
portableGroups: scoped.flatMap((child) => child.portableGroups),
|
|
827
|
+
receipt: { ...first.receipt, targetResults: scoped.flatMap((child) => child.receipt.targetResults) },
|
|
828
|
+
});
|
|
829
|
+
}
|
|
544
830
|
const portableCandidates = children.flatMap((child) => child.portableGroups.flatMap((prepared) => prepared.targets
|
|
545
831
|
.filter((target) => target.disposition !== 'remove')
|
|
546
832
|
.map((target) => ({ child, prepared, target }))));
|
|
@@ -566,7 +852,7 @@ async function prepareJointRecoveryInSession(command, selectors, { checkInstallC
|
|
|
566
852
|
const scopedExtensions = (backend?.live?.components ?? backend?.components ?? []).some((component) => component.kind === 'ownership' && component.key !== 'native'
|
|
567
853
|
&& !component.key.startsWith('activation-') && !component.key.startsWith('marketplace-')
|
|
568
854
|
&& ['present', 'partial'].includes(component.state));
|
|
569
|
-
if (item.scope !== 'project' || !item.agent || !['codex', 'claude', '
|
|
855
|
+
if (item.scope !== 'project' || !item.agent || !['codex', 'claude', 'copilot'].includes(item.agent))
|
|
570
856
|
return false;
|
|
571
857
|
return demand.placements.some((placement) => {
|
|
572
858
|
if (placement.pluginId !== item.pluginId || placement.target !== item.agent)
|
|
@@ -597,13 +883,29 @@ async function prepareJointRecoveryInSession(command, selectors, { checkInstallC
|
|
|
597
883
|
|| selected.some((placement) => canReuseProviderAcrossScopes(placement.target)
|
|
598
884
|
&& placement.pluginId === item.pluginId && placement.target === item.agent && placement.scope !== item.scope
|
|
599
885
|
&& (item.delivery?.kind !== 'agent-skills' || item.backend?.logicalIdentity === placement.plugin.catalogLogicalIdentity))));
|
|
886
|
+
if (scope === 'project')
|
|
887
|
+
for (const provider of currentStatus.projectSkillProviders ?? []) {
|
|
888
|
+
if (provider.target === 'generic' || provider.projectCopy !== 'owned' || !selected.some((placement) => placement.pluginId === provider.pluginId
|
|
889
|
+
&& placement.target === provider.target && placement.scope === 'user'
|
|
890
|
+
&& selectedContributions.get(placement)?.some((entry) => entry.scope === 'project')))
|
|
891
|
+
continue;
|
|
892
|
+
const position = { pluginId: provider.pluginId, agent: provider.target, scope: 'project' };
|
|
893
|
+
if (ownsOutput(position)) {
|
|
894
|
+
joint.providerRetirements.add(targetKey(position));
|
|
895
|
+
retire.push({ ...position, delivery: { kind: 'native', platform: provider.target }, observation: 'verified' });
|
|
896
|
+
}
|
|
897
|
+
}
|
|
600
898
|
for (const item of currentStatus.observedTargets ?? []) {
|
|
601
|
-
if (ownsOutput(item) && !requiredNativeActivation(item) && selected.some((placement) => canReuseProviderAcrossScopes(placement.target)
|
|
899
|
+
if (ownsOutput(item) && !requiredNativeActivation(item) && selected.some((placement) => (canReuseProviderAcrossScopes(placement.target)
|
|
900
|
+
|| command === 'uninstall' && item.scope === scope && previousUserProvided(placement.pluginId, placement.target))
|
|
602
901
|
&& placement.pluginId === item.pluginId
|
|
603
902
|
&& placement.target === item.agent && placement.scope !== item.scope)
|
|
604
903
|
&& !demand.placements.some((placement) => placement.pluginId === item.pluginId
|
|
605
|
-
&& placement.target === item.agent && placement.scope === item.scope))
|
|
904
|
+
&& placement.target === item.agent && placement.scope === item.scope)) {
|
|
606
905
|
retire.push(item);
|
|
906
|
+
if (item.agent && !canReuseProviderAcrossScopes(item.agent))
|
|
907
|
+
joint.providerRetirements.add(targetKey(item));
|
|
908
|
+
}
|
|
607
909
|
}
|
|
608
910
|
// A removed declaration is still present in the observed snapshot, so include its exact old outputs.
|
|
609
911
|
if (command === 'uninstall')
|
|
@@ -658,12 +960,44 @@ async function prepareJointRecoveryInSession(command, selectors, { checkInstallC
|
|
|
658
960
|
}
|
|
659
961
|
children.unshift(...cleanups);
|
|
660
962
|
}
|
|
963
|
+
if ((batch || command === 'reinstall' && options.exactTargets) && !children.some((child) => child.command === 'cleanup')) {
|
|
964
|
+
const order = new Map();
|
|
965
|
+
if (options.exactTargets) {
|
|
966
|
+
// The caller ordered exact pairs. Insert their actual providers once, before the consuming pair.
|
|
967
|
+
for (const exact of options.exactTargets) {
|
|
968
|
+
for (const item of selected.filter((placement) => selectedContributions.get(placement)?.some((contribution) => matchesExactContribution(placement, contribution, exact, reaches)))) {
|
|
969
|
+
const key = targetKey({ pluginId: item.pluginId, agent: item.target, scope: item.scope });
|
|
970
|
+
if (!order.has(key))
|
|
971
|
+
order.set(key, order.size);
|
|
972
|
+
}
|
|
973
|
+
const key = targetKey({ ...exact, scope: exact.scope ?? scope });
|
|
974
|
+
if (!order.has(key))
|
|
975
|
+
order.set(key, order.size);
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
else {
|
|
979
|
+
// Ordinary batches list each scope's Native roots across clients, then Portable roots.
|
|
980
|
+
const deliveries = [nativeTargets, targets.filter((agent) => agent === 'generic')];
|
|
981
|
+
for (const scope of snapshot.context.scopes)
|
|
982
|
+
for (const agents of deliveries) {
|
|
983
|
+
const roots = new Set(selected.filter((item) => item.scope === scope && agents.includes(item.target)).map((item) => item.pluginId));
|
|
984
|
+
for (const root of unplacedRoots)
|
|
985
|
+
if (root.scope === scope && agents.includes(root.target)
|
|
986
|
+
&& (root.state === 'blocked' || root.state === 'unknown'))
|
|
987
|
+
roots.add(root.pluginId);
|
|
988
|
+
for (const pluginId of roots)
|
|
989
|
+
for (const agent of agents)
|
|
990
|
+
order.set(targetKey({ pluginId, agent, scope }), order.size);
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
joint.targetOrder = order;
|
|
994
|
+
}
|
|
661
995
|
// The first preview already seals every target in its native group. A lone
|
|
662
|
-
//
|
|
996
|
+
// Copilot ensure group has no later sibling contribution to refresh here.
|
|
663
997
|
const onlyChild = children.length === 1 ? children[0] : undefined;
|
|
664
998
|
const onlyGroup = onlyChild?.nativeGroups.length === 1 ? onlyChild.nativeGroups[0] : undefined;
|
|
665
999
|
const singleNativePreviewComplete = !plan.blockExecution && onlyChild !== undefined && !onlyChild.blockExecution
|
|
666
|
-
&& onlyChild.command === 'sync' &&
|
|
1000
|
+
&& onlyChild.command === 'sync' && onlyGroup?.platform === 'copilot'
|
|
667
1001
|
&& onlyGroup.command === 'sync'
|
|
668
1002
|
&& onlyGroup.preview.operationPlan !== undefined
|
|
669
1003
|
&& (onlyGroup.preview.operationPlan.deploymentPlans?.length ?? 0) > 0
|
|
@@ -674,32 +1008,44 @@ async function prepareJointRecoveryInSession(command, selectors, { checkInstallC
|
|
|
674
1008
|
&& onlyChild.portableResidues.length === 0;
|
|
675
1009
|
// Other scopes and groups can change shared descriptors, preApply actions
|
|
676
1010
|
// or retained packages. Refresh those previews before exposing Review.
|
|
677
|
-
if (!singleNativePreviewComplete)
|
|
678
|
-
|
|
679
|
-
|
|
1011
|
+
if (!singleNativePreviewComplete) {
|
|
1012
|
+
if (batch) {
|
|
1013
|
+
const nativeChildren = children.filter((child) => child.nativeGroups.length);
|
|
1014
|
+
const platforms = [...new Set(nativeChildren.map((child) => child.runtime.batchInstallPlatform))];
|
|
1015
|
+
await mapInstallReads(platforms, async (platform) => {
|
|
1016
|
+
const scoped = nativeChildren.filter((item) => item.runtime.batchInstallPlatform === platform);
|
|
1017
|
+
// One complete ensure plan owns this platform session. Its initial preview already sealed
|
|
1018
|
+
// every candidate; only another source or scope can contribute a later shared descriptor.
|
|
1019
|
+
const only = scoped.length === 1 ? scoped[0] : undefined;
|
|
1020
|
+
const preview = only?.nativeGroups.length === 1 ? only.nativeGroups[0].preview : undefined;
|
|
1021
|
+
if (platform && only && !only.blockExecution && only.receipt.targetResults.every((target) => target.blockers.length === 0)
|
|
1022
|
+
&& preview?.operationPlan?.deploymentPlans?.length
|
|
1023
|
+
&& preview.operationPlan.deploymentPlans.every((deployment) => deployment.operation === 'ensure'))
|
|
1024
|
+
return;
|
|
1025
|
+
for (const child of scoped)
|
|
1026
|
+
await refreshRecoveryNativePreviews(child, catalogReadScope, options.signal);
|
|
1027
|
+
}, { signal: options.signal });
|
|
1028
|
+
}
|
|
1029
|
+
else
|
|
1030
|
+
for (const child of children)
|
|
1031
|
+
await refreshRecoveryNativePreviews(child, catalogReadScope, options.signal);
|
|
1032
|
+
}
|
|
680
1033
|
const preparedNativeTargets = children.flatMap((child) => child.receipt.targetResults)
|
|
681
1034
|
.filter((target) => target.delivery?.kind === 'native');
|
|
682
|
-
const failedProviders = preparedNativeTargets.filter((target) => target.blockers.length > 0)
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
&& parent.path.every((pluginId, index) => pluginId === contribution.path[index]))))
|
|
696
|
-
continue;
|
|
697
|
-
for (const blocker of provider.blockers)
|
|
698
|
-
if (!target.blockers.some((entry) => entry.code === blocker.code && entry.pluginId === provider.pluginId)) {
|
|
699
|
-
target.blockers.push({ ...blocker, pluginId: provider.pluginId });
|
|
700
|
-
}
|
|
1035
|
+
const failedProviders = new Map(preparedNativeTargets.filter((target) => target.blockers.length > 0)
|
|
1036
|
+
.map((target) => [targetKey(target), target]));
|
|
1037
|
+
if (failedProviders.size)
|
|
1038
|
+
for (const target of preparedNativeTargets) {
|
|
1039
|
+
for (const dependency of dependencyGraph.providers({ pluginId: target.pluginId, target: target.agent, scope: target.scope })) {
|
|
1040
|
+
const provider = failedProviders.get(targetKey({ ...dependency, agent: dependency.target }));
|
|
1041
|
+
if (!provider)
|
|
1042
|
+
continue;
|
|
1043
|
+
for (const blocker of provider.blockers)
|
|
1044
|
+
if (!target.blockers.some((entry) => entry.code === blocker.code && entry.pluginId === provider.pluginId)) {
|
|
1045
|
+
target.blockers.push({ ...blocker, pluginId: provider.pluginId });
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
701
1048
|
}
|
|
702
|
-
}
|
|
703
1049
|
finalizePreparedPlatformRebuildSession(runtime.preparedArtifactRenderResults);
|
|
704
1050
|
plan.sourceRefreshes = [...new Map(children.flatMap((child) => child.sourceRefreshes).map((item) => [item.sourceId, item])).values()];
|
|
705
1051
|
plan.sourceRefreshFailures = [...new Map(children.flatMap((child) => child.sourceRefreshFailures).map((item) => [item.sourceId, item])).values()];
|
|
@@ -707,6 +1053,8 @@ async function prepareJointRecoveryInSession(command, selectors, { checkInstallC
|
|
|
707
1053
|
plan.warnings.push(...children.flatMap((child) => child.warnings));
|
|
708
1054
|
plan.plannedImpact.outputs = children.some((child) => child.plannedImpact.outputs);
|
|
709
1055
|
plan.receipt = mergeReceipts(plan, children.map((child) => child.receipt));
|
|
1056
|
+
if (retriesFromRequestedRoots(plan.receipt) && plan.receipt.remainingTargets.length)
|
|
1057
|
+
useDeclaredRetryRoots(plan.receipt);
|
|
710
1058
|
const observedManager = children.flatMap((child) => child.nativeGroups)
|
|
711
1059
|
.map((group) => group.preview.codexManagerPreview)
|
|
712
1060
|
.find((entry) => entry?.state === 'system');
|
|
@@ -723,20 +1071,36 @@ async function prepareJointRecoveryInSession(command, selectors, { checkInstallC
|
|
|
723
1071
|
export async function executeJointRecovery(plan, execution) {
|
|
724
1072
|
const joint = plan.joint;
|
|
725
1073
|
const performanceRuntime = { ...plan.runtime, ...execution.runtime };
|
|
1074
|
+
if (isInstallBatch(plan.command)) {
|
|
1075
|
+
const override = execution.runtime?.nativeCliRunner;
|
|
1076
|
+
if (!override || override === joint.originalNativeRunner || override === plan.runtime.nativeCliRunner) {
|
|
1077
|
+
performanceRuntime.nativeCliRunner = plan.runtime.nativeCliRunner;
|
|
1078
|
+
joint.bindExecutionSignal?.(performanceRuntime.signal);
|
|
1079
|
+
}
|
|
1080
|
+
else {
|
|
1081
|
+
performanceRuntime.nativeCliRunner = limitInstallNativeRunner(override);
|
|
1082
|
+
performanceRuntime.codexObservationSession = execution.runtime?.codexObservationSession;
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
let lockedPlan;
|
|
1086
|
+
let completedReceipt;
|
|
726
1087
|
let lockWaitStartedAt;
|
|
727
1088
|
try {
|
|
728
1089
|
if (plan.sourceRefreshes.length) {
|
|
729
1090
|
plan.receipt.blockers.push(diagnostic('sourceRefreshConfirmationRequired'));
|
|
730
|
-
|
|
1091
|
+
const receipt = mergeReceipts(plan, joint.children.map((child) => child.receipt));
|
|
1092
|
+
if (retriesFromRequestedRoots(receipt))
|
|
1093
|
+
useDeclaredRetryRoots(receipt);
|
|
1094
|
+
return receipt;
|
|
731
1095
|
}
|
|
732
1096
|
lockWaitStartedAt = performance.now();
|
|
733
1097
|
await recordRecoveryPerformanceStage(performanceRuntime, 'recovery.lock.wait', 'start', lockWaitStartedAt);
|
|
734
|
-
return await withAwHomeMutationLock({ env: plan.options.env, token: execution.runtime?.awHomeMutationToken ?? plan.runtime.awHomeMutationToken,
|
|
1098
|
+
return await withAwHomeMutationLock({ env: plan.options.env, signal: performanceRuntime.signal, token: execution.runtime?.awHomeMutationToken ?? plan.runtime.awHomeMutationToken,
|
|
735
1099
|
action: async (token) => {
|
|
736
1100
|
const acquiredAt = lockWaitStartedAt;
|
|
737
1101
|
lockWaitStartedAt = undefined;
|
|
738
1102
|
await recordRecoveryPerformanceStage(performanceRuntime, 'recovery.lock.wait', 'success', acquiredAt);
|
|
739
|
-
const preparation = await measureRecoveryPerformanceStage(performanceRuntime, 'recovery.locked.demand', () => readJointPreparation(plan.command, joint.originalOptions, true));
|
|
1103
|
+
const preparation = await measureRecoveryPerformanceStage(performanceRuntime, 'recovery.locked.demand', () => readJointPreparation(plan.command, { ...joint.originalOptions, signal: performanceRuntime.signal }, true));
|
|
740
1104
|
const actual = preparation.snapshot;
|
|
741
1105
|
const currentIntent = (plan.options.scope === 'project' ? actual.project : actual.user).intent;
|
|
742
1106
|
plan.receipt.intent = intentReceipt(currentIntent);
|
|
@@ -744,30 +1108,33 @@ export async function executeJointRecovery(plan, execution) {
|
|
|
744
1108
|
plan.receipt.blockers.push(describeStrongStateProblem({ kind: 'intent', scope: plan.options.scope,
|
|
745
1109
|
state: currentIntent.state, filePath: await resolveIntentPath(plan.options) }));
|
|
746
1110
|
}
|
|
747
|
-
if (snapshotEvidence(actual) !== joint.evidence)
|
|
748
|
-
plan
|
|
749
|
-
return mergeReceipts(plan, []);
|
|
750
|
-
}
|
|
1111
|
+
if (snapshotEvidence(actual) !== joint.evidence)
|
|
1112
|
+
return blockedBeforeDeployment(plan);
|
|
751
1113
|
if (plan.blockExecution)
|
|
752
1114
|
return plan.receipt;
|
|
753
1115
|
// Recheck all backend candidates before any strong-state or output write.
|
|
754
1116
|
(execution.runtime?.codexObservationSession ?? plan.runtime.codexObservationSession)?.invalidate();
|
|
755
|
-
const checked = await measureRecoveryPerformanceStage(performanceRuntime, 'recovery.locked.recheck', () => prepareJointRecovery(plan.command, joint.selectors, preparation.options, { ...
|
|
1117
|
+
const checked = await measureRecoveryPerformanceStage(performanceRuntime, 'recovery.locked.recheck', () => prepareJointRecovery(plan.command, joint.selectors, preparation.options, { ...performanceRuntime, awHomeMutationToken: token }, preparation.catalogReadScope ? preparation : undefined));
|
|
756
1118
|
const stable = !checked.blockExecution && JSON.stringify(describeRecoveryPlan(plan)) === JSON.stringify(describeRecoveryPlan(checked));
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
1119
|
+
lockedPlan = checked;
|
|
1120
|
+
const parallel = isInstallBatch(plan.command) && !joint.pendingUserSkills.length && !joint.children.some((child) => child.command === 'cleanup');
|
|
1121
|
+
const children = parallel ? checked.joint.children : joint.children;
|
|
1122
|
+
if (!stable)
|
|
1123
|
+
return blockedBeforeDeployment(plan);
|
|
1124
|
+
performanceRuntime.signal?.throwIfAborted();
|
|
762
1125
|
if (joint.originalOptions.preferences) {
|
|
763
1126
|
const saved = await writePreferences({ ...plan.options, scope: 'user', token }, joint.originalOptions.preferences);
|
|
764
1127
|
plan.receipt.preferencesChanged = saved.changed;
|
|
765
1128
|
const committed = await observePreferences({ ...plan.options, scope: 'user' });
|
|
1129
|
+
plan.receipt.selection.preferences = committed.state;
|
|
766
1130
|
if (committed.state !== 'valid') {
|
|
767
|
-
plan
|
|
768
|
-
|
|
1131
|
+
return blockedBeforeDeployment(plan, diagnostic(committed.state === 'invalid'
|
|
1132
|
+
? 'deploymentPreferencesInvalid' : 'deploymentPreferencesUnavailable'), 'preferences');
|
|
769
1133
|
}
|
|
770
|
-
|
|
1134
|
+
if (JSON.stringify(committed.value) !== JSON.stringify(saved.value)) {
|
|
1135
|
+
return blockedBeforeDeployment(plan, diagnostic('operationReviewStale'), 'preferences');
|
|
1136
|
+
}
|
|
1137
|
+
for (const child of children) {
|
|
771
1138
|
child.demand.preferences = committed;
|
|
772
1139
|
if (child.options.demandOverride)
|
|
773
1140
|
child.options.demandOverride.preferences = committed;
|
|
@@ -780,11 +1147,13 @@ export async function executeJointRecovery(plan, execution) {
|
|
|
780
1147
|
const committed = await observeIntent({ ...plan.options, scope: joint.declaration.scope });
|
|
781
1148
|
plan.receipt.intent = intentReceipt(committed);
|
|
782
1149
|
if (committed.state !== 'valid') {
|
|
783
|
-
plan
|
|
1150
|
+
return blockedBeforeDeployment(plan, committed.state === 'absent'
|
|
784
1151
|
? diagnostic('pluginIntentStateUnavailable', '保存后未找到插件声明,未执行输出变更。')
|
|
785
1152
|
: describeStrongStateProblem({ kind: 'intent', scope: joint.declaration.scope,
|
|
786
|
-
state: committed.state, filePath: await resolveIntentPath({ ...plan.options, scope: joint.declaration.scope }) }));
|
|
787
|
-
|
|
1153
|
+
state: committed.state, filePath: await resolveIntentPath({ ...plan.options, scope: joint.declaration.scope }) }), 'intent');
|
|
1154
|
+
}
|
|
1155
|
+
if (calculateIntentDigest(committed.value) !== calculateIntentDigest(saved.value)) {
|
|
1156
|
+
return blockedBeforeDeployment(plan, diagnostic('operationReviewStale'), 'intent');
|
|
788
1157
|
}
|
|
789
1158
|
}
|
|
790
1159
|
const results = joint.children.filter((child) => child.blockExecution
|
|
@@ -793,249 +1162,336 @@ export async function executeJointRecovery(plan, execution) {
|
|
|
793
1162
|
const failedPackages = new Set();
|
|
794
1163
|
const failedNodes = new Set();
|
|
795
1164
|
const packageResults = [];
|
|
796
|
-
const runtime = { ...
|
|
1165
|
+
const runtime = { ...performanceRuntime, awHomeMutationToken: token };
|
|
797
1166
|
runtime.preApplyExecutionCache ??= new Map();
|
|
798
1167
|
runtime.managedCommandProducerCache ??= new Map();
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
1168
|
+
let interrupted;
|
|
1169
|
+
if (parallel) {
|
|
1170
|
+
const installed = await executeJointInstall({ children, demand: checked.joint.demand, runtime, token,
|
|
1171
|
+
yes: execution.yes ?? plan.options.yes, existingOnly: joint.originalOptions.existingOnly });
|
|
1172
|
+
interrupted = installed.interruption;
|
|
1173
|
+
results.push(...installed.receipts);
|
|
1174
|
+
packageResults.push(...installed.commands);
|
|
1175
|
+
plan.receipt.blockers.push(...installed.blockers);
|
|
1176
|
+
for (const result of installed.commands)
|
|
1177
|
+
if (result.state !== 'completed')
|
|
1178
|
+
failedPackages.add(getCommandPackageId(result.producer));
|
|
1179
|
+
}
|
|
1180
|
+
else {
|
|
1181
|
+
const packages = runtime.configApplyPackages;
|
|
1182
|
+
const dependencyGraph = indexJointDependencies(joint.demand);
|
|
1183
|
+
const readCurrentProviders = (plugins, targets) => {
|
|
1184
|
+
const { cwd, env, cliVersion } = joint.originalOptions;
|
|
1185
|
+
return readRecoveryStatus({ cwd, env, cliVersion, context: joint.snapshot.context.context,
|
|
1186
|
+
expectedProjectRoot: joint.snapshot.context.projectRoot, plugins: [...new Set(plugins)], targets: [...new Set(targets)],
|
|
1187
|
+
nativeCliRunner: runtime.nativeCliRunner, signal: runtime.signal });
|
|
1188
|
+
};
|
|
1189
|
+
const portableProgress = { completed: [], failed: [] };
|
|
1190
|
+
const failedCleanups = [];
|
|
1191
|
+
const executeChild = async (child, pluginIds, agent) => {
|
|
1192
|
+
const childRuntime = { ...runtime, batchInstallPlatform: child.runtime.batchInstallPlatform };
|
|
1193
|
+
const currentIntent = await observeIntent(child.options);
|
|
1194
|
+
if (!joint.originalOptions.existingOnly)
|
|
1195
|
+
child.demand.intent = currentIntent;
|
|
1196
|
+
const fresh = await measureRecoveryPerformanceStage(runtime, 'recovery.child.plan', () => prepareScopedRecovery(child.command, typeof pluginIds === 'string' ? [pluginIds] : pluginIds, {
|
|
1197
|
+
...child.options, targets: agent !== 'generic' ? child.options.targets : [agent], all: false,
|
|
1198
|
+
exactTargets: child.options.exactTargets?.filter((target) => (typeof pluginIds === 'string' ? [pluginIds] : pluginIds).includes(target.pluginId)),
|
|
1199
|
+
}, childRuntime));
|
|
1200
|
+
fresh.originalIntent = observationEvidence(currentIntent);
|
|
1201
|
+
for (const target of fresh.receipt.targetResults) {
|
|
1202
|
+
const reviewed = child.receipt.targetResults.find((entry) => entry.pluginId === target.pluginId && entry.agent === target.agent);
|
|
1203
|
+
if (reviewed?.relation === 'dependency') {
|
|
1204
|
+
target.relation = 'dependency';
|
|
1205
|
+
target.requiredBy = [...reviewed.requiredBy];
|
|
1206
|
+
}
|
|
1207
|
+
// Native/provider observations are refreshed after preceding nodes.
|
|
1208
|
+
// Keep only joint constraints and an already failed script gate.
|
|
1209
|
+
target.blockers.push(...(reviewed?.blockers ?? []).filter((error) => reviewed?.execution === 'failed'
|
|
1210
|
+
|| ['configApplyRequiresExistingOutput', 'crossScopeSkillCollision', 'targetPlacementConflict',
|
|
1211
|
+
'preApplyAuthorizationRequired', 'nativeToolAuthorizationRequired', 'providerSwitchPreApplyFailed', 'providerSwitchVerificationFailed', 'dependencyStillRequired'].includes(error.code)));
|
|
1212
|
+
if (reviewed?.execution === 'failed') {
|
|
1213
|
+
target.execution = 'failed';
|
|
1214
|
+
if (reviewed.backend)
|
|
1215
|
+
target.backend = reviewed.backend;
|
|
1216
|
+
}
|
|
1217
|
+
if (child.command !== 'cleanup' && failedCleanups.some((failed) => failed.agent === target.agent && (failed.pluginId === target.pluginId || joint.demand.roots.some((root) => root.pluginId === target.pluginId && root.target === target.agent && root.dependencies.includes(failed.pluginId))))) {
|
|
1218
|
+
target.blockers.push(diagnostic('providerSwitchCleanupFailed'));
|
|
1219
|
+
}
|
|
1220
|
+
const dependencies = [...dependencyGraph.providers({ pluginId: target.pluginId, target: target.agent, scope: target.scope })];
|
|
1221
|
+
if (failedPackages.has(`${target.pluginId}\0${target.scope}`) || failedPackages.has(`${target.pluginId}\0user`)
|
|
1222
|
+
|| dependencies.some((item) => failedPackages.has(`${item.pluginId}\0${item.scope}`))) {
|
|
1223
|
+
target.blockers.push(diagnostic('commandPackageProviderNotSatisfied'));
|
|
1224
|
+
}
|
|
1225
|
+
const failedDependency = dependencies.find((placement) => failedProviders.has(`${placement.pluginId}\0${placement.target}\0${placement.scope}`));
|
|
1226
|
+
if (failedDependency) {
|
|
1227
|
+
target.blockers.push({ code: target.scope === 'project' && failedDependency.scope === 'user'
|
|
1228
|
+
? 'userProviderNotSatisfied' : 'dependencyApplyFailed',
|
|
1229
|
+
pluginId: failedDependency.pluginId,
|
|
1230
|
+
message: `依赖提供者 ${failedDependency.pluginId}(${failedDependency.target}/${failedDependency.scope})未完成。` });
|
|
1231
|
+
}
|
|
834
1232
|
}
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
1233
|
+
if (child.command !== 'cleanup' && child.options.scope === 'project') {
|
|
1234
|
+
const required = joint.pendingUserSkills.filter((item) => fresh.receipt.targetResults.some((target) => target.agent === item.target && dependencyGraph.reaches(target.pluginId, item.pluginId)));
|
|
1235
|
+
if (required.length) {
|
|
1236
|
+
const verified = await readCurrentProviders(required.map((item) => item.pluginId), required.map((item) => item.target));
|
|
1237
|
+
for (const provider of required) {
|
|
1238
|
+
if (verified.projectSkillProviders?.some((item) => item.pluginId === provider.pluginId && item.target === provider.target
|
|
1239
|
+
&& item.sourceIdentity === provider.sourceIdentity && !item.userAbsent && !item.userNeedsRepair && item.projectCopy !== 'blocked'))
|
|
1240
|
+
continue;
|
|
1241
|
+
for (const target of fresh.receipt.targetResults.filter((item) => item.agent === provider.target
|
|
1242
|
+
&& dependencyGraph.reaches(item.pluginId, provider.pluginId)))
|
|
1243
|
+
target.blockers.push(diagnostic('userProviderNotSatisfied'));
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
839
1246
|
}
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
1247
|
+
const result = await measureRecoveryPerformanceStage(runtime, 'recovery.child.execute', () => executeScopedRecovery(fresh, { ...execution, runtime: childRuntime,
|
|
1248
|
+
...(plan.command !== 'uninstall' && child.command !== 'cleanup' ? { portableProgress } : {}) }));
|
|
1249
|
+
if (joint.originalOptions.existingOnly)
|
|
1250
|
+
for (const target of result.targetResults) {
|
|
1251
|
+
if (!target.blockers.some((error) => error.code === 'dependencyInstallFailed'))
|
|
1252
|
+
continue;
|
|
1253
|
+
target.blockers = target.blockers.map((error) => error.code === 'dependencyInstallFailed'
|
|
1254
|
+
? { ...error, code: 'dependencyApplyFailed', message: '依赖提供者未完成。请检查其执行结果。' }
|
|
1255
|
+
: error);
|
|
1256
|
+
if (target.execution === 'failed')
|
|
1257
|
+
target.execution = 'not-run';
|
|
1258
|
+
}
|
|
1259
|
+
results.push(result);
|
|
1260
|
+
return result;
|
|
1261
|
+
};
|
|
1262
|
+
// Provider changes can remove a working output. Complete the replacement's
|
|
1263
|
+
// authorization and scripts first, sharing the normal execution cache.
|
|
1264
|
+
const cleanups = joint.children.filter((child) => child.command === 'cleanup');
|
|
1265
|
+
const deferred = cleanups.filter((child) => child.receipt.requestedTargets.some((target) => joint.providerRetirements.has(targetKey(target))));
|
|
1266
|
+
const cleanupChildren = cleanups.filter((child) => !deferred.includes(child));
|
|
1267
|
+
const replacementFailures = new Set();
|
|
1268
|
+
for (const child of joint.children.filter((child) => child.command !== 'cleanup')) {
|
|
1269
|
+
for (const target of child.receipt.targetResults) {
|
|
1270
|
+
if (replacementFailures.has(`${target.pluginId}\0${target.agent}`)) {
|
|
1271
|
+
target.blockers.push(diagnostic('dependencyApplyFailed'));
|
|
845
1272
|
continue;
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
target.
|
|
863
|
-
continue;
|
|
1273
|
+
}
|
|
1274
|
+
if (child.options.nativeActivationOnlyTargets?.some((item) => item.pluginId === target.pluginId
|
|
1275
|
+
&& item.platform === target.agent && item.scope === target.scope))
|
|
1276
|
+
continue;
|
|
1277
|
+
if (!cleanupChildren.some((cleanup) => cleanup.receipt.requestedTargets.some((old) => old.pluginId === target.pluginId)))
|
|
1278
|
+
continue;
|
|
1279
|
+
const failure = target.blockers[0]?.code ?? await executeRecoveryPreApply({ ...child,
|
|
1280
|
+
options: { ...child.options, yes: execution.yes ?? plan.options.yes },
|
|
1281
|
+
}, target.pluginId, target.agent, runtime);
|
|
1282
|
+
if (!failure)
|
|
1283
|
+
continue;
|
|
1284
|
+
target.blockers.push(diagnostic(failure));
|
|
1285
|
+
if (failure !== 'preApplyAuthorizationRequired' && failure !== 'nativeToolAuthorizationRequired')
|
|
1286
|
+
target.execution = 'failed';
|
|
1287
|
+
replacementFailures.add(`${target.pluginId}\0${target.agent}`);
|
|
1288
|
+
failedProviders.add(`${target.pluginId}\0${target.agent}\0${target.scope}`);
|
|
1289
|
+
failedNodes.add(`${target.pluginId}\0${target.scope}`);
|
|
864
1290
|
}
|
|
865
|
-
if (child.options.nativeActivationOnlyTargets?.some((item) => item.pluginId === target.pluginId
|
|
866
|
-
&& item.platform === target.agent && item.scope === target.scope))
|
|
867
|
-
continue;
|
|
868
|
-
if (!cleanupChildren.some((cleanup) => cleanup.receipt.requestedTargets.some((old) => old.pluginId === target.pluginId)))
|
|
869
|
-
continue;
|
|
870
|
-
const failure = target.blockers[0]?.code ?? await executeRecoveryPreApply({ ...child,
|
|
871
|
-
options: { ...child.options, yes: execution.yes ?? plan.options.yes },
|
|
872
|
-
}, target.pluginId, target.agent, runtime);
|
|
873
|
-
if (!failure)
|
|
874
|
-
continue;
|
|
875
|
-
target.blockers.push(diagnostic(failure));
|
|
876
|
-
if (failure !== 'preApplyAuthorizationRequired' && failure !== 'nativeToolAuthorizationRequired')
|
|
877
|
-
target.execution = 'failed';
|
|
878
|
-
replacementFailures.add(`${target.pluginId}\0${target.agent}`);
|
|
879
|
-
failedProviders.add(`${target.pluginId}\0${target.agent}\0${target.scope}`);
|
|
880
|
-
failedNodes.add(`${target.pluginId}\0${target.scope}`);
|
|
881
1291
|
}
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
1292
|
+
// Target exits can replace one Agent with another. Preserve the reviewed
|
|
1293
|
+
// old output when its corresponding replacement cannot run.
|
|
1294
|
+
const clean = async (child, verified = true, onSuccess) => {
|
|
1295
|
+
for (const target of child.receipt.requestedTargets) {
|
|
1296
|
+
if (!verified)
|
|
1297
|
+
child.receipt.targetResults.find((entry) => entry.pluginId === target.pluginId && entry.agent === target.agent)
|
|
1298
|
+
.blockers.push(diagnostic('providerSwitchVerificationFailed', '替代位置尚未确认就绪,保留原输出。'));
|
|
1299
|
+
if ((plan.command === 'uninstall' || deferred.includes(child)) && failedCleanups.some((failed) => {
|
|
1300
|
+
if (failed.agent !== target.agent)
|
|
1301
|
+
return false;
|
|
1302
|
+
const required = joint.removalDependencies.get(failed.pluginId);
|
|
1303
|
+
return required?.includes(target.pluginId) || required === null
|
|
1304
|
+
&& parsePluginId(failed.pluginId).sourceId === parsePluginId(target.pluginId).sourceId;
|
|
1305
|
+
})) {
|
|
1306
|
+
child.receipt.targetResults.find((entry) => entry.pluginId === target.pluginId && entry.agent === target.agent)
|
|
1307
|
+
.blockers.push(diagnostic('dependencyStillRequired', '依赖者未完成删除,保留其依赖输出。'));
|
|
1308
|
+
}
|
|
1309
|
+
if ([...replacementFailures].some((failed) => failed.startsWith(`${target.pluginId}\0`)
|
|
1310
|
+
&& (failed === `${target.pluginId}\0${target.agent}`
|
|
1311
|
+
|| !joint.children.some((replacement) => replacement.command !== 'cleanup'
|
|
1312
|
+
&& replacement.receipt.requestedTargets.some((entry) => entry.pluginId === target.pluginId && entry.agent === target.agent))))) {
|
|
1313
|
+
child.receipt.targetResults.find((entry) => entry.pluginId === target.pluginId && entry.agent === target.agent)
|
|
1314
|
+
.blockers.push(diagnostic('providerSwitchPreApplyFailed'));
|
|
1315
|
+
}
|
|
1316
|
+
const result = await executeChild(child, target.pluginId, target.agent);
|
|
1317
|
+
if (!result.ok)
|
|
1318
|
+
failedCleanups.push(...result.requestedTargets);
|
|
1319
|
+
else
|
|
1320
|
+
onSuccess?.(result);
|
|
896
1321
|
}
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
1322
|
+
};
|
|
1323
|
+
for (const child of cleanupChildren)
|
|
1324
|
+
await clean(child);
|
|
1325
|
+
const retireVerified = async (oldScope) => {
|
|
1326
|
+
const retiring = deferred.filter((child) => child.options.scope === oldScope);
|
|
1327
|
+
if (!retiring.length)
|
|
1328
|
+
return;
|
|
1329
|
+
const old = retiring.flatMap((child) => child.receipt.requestedTargets);
|
|
1330
|
+
const verified = await readCurrentProviders(old.map((item) => item.pluginId), old.map((item) => item.agent));
|
|
1331
|
+
for (const child of retiring) {
|
|
1332
|
+
const target = child.receipt.requestedTargets[0];
|
|
1333
|
+
const replacement = { ...target, scope: oldScope === 'user' ? 'project' : 'user' };
|
|
1334
|
+
const reviewedSource = joint.demand.placements.find((item) => item.pluginId === replacement.pluginId
|
|
1335
|
+
&& item.scope === replacement.scope && item.target === replacement.agent)?.plugin.sourceIdentity;
|
|
1336
|
+
const confirmed = reviewedSource && !failedProviders.has(targetKey(replacement)) && (oldScope === 'project'
|
|
1337
|
+
? verified.projectSkillProviders?.some((item) => item.pluginId === target.pluginId && item.target === target.agent
|
|
1338
|
+
&& item.sourceIdentity === reviewedSource && !item.userAbsent && !item.userNeedsRepair && item.projectCopy === 'owned')
|
|
1339
|
+
: verified.observedTargets?.some((item) => targetKey(item) === targetKey(replacement)
|
|
1340
|
+
&& item.observation === 'verified' && item.content === 'satisfied' && !item.blockers.length)
|
|
1341
|
+
&& verified.existingTargets?.some((item) => targetKey(item) === targetKey(replacement)
|
|
1342
|
+
&& item.nativePackage?.sourceIdentity === reviewedSource && item.nativePackage.skillsReady));
|
|
1343
|
+
await clean(child, Boolean(confirmed), (receipt) => {
|
|
1344
|
+
const projectRoot = joint.snapshot.context.projectRoot;
|
|
1345
|
+
if (!confirmed || !projectRoot || oldScope !== 'project' || target.agent !== 'grok' || !runtime.preparedArtifactRenderResults)
|
|
1346
|
+
return;
|
|
1347
|
+
const project = verified.extraObserved.find((item) => item.pluginId === target.pluginId && item.agent === 'grok' && item.scope === 'project')
|
|
1348
|
+
?.deploymentObservations?.find(({ after }) => after.nativeIdentity?.route === 'grok-directory')?.after;
|
|
1349
|
+
const user = verified.observedTargets?.find((item) => targetKey(item) === targetKey(replacement))
|
|
1350
|
+
?.deploymentObservations?.find(({ after }) => after.nativeIdentity?.route === 'grok-cli')?.after;
|
|
1351
|
+
const backend = receipt.targetResults.find((item) => targetKey(item) === targetKey(target))?.backend;
|
|
1352
|
+
const removed = backend?.command === 'cleanup' && backend.ok ? backend.targetResults.find(({ target: item }) => item.pluginId === target.pluginId && item.platform === 'grok' && item.scope === 'project')?.removed : undefined;
|
|
1353
|
+
const reviewedRemoval = child.nativeGroups.some(({ preview }) => preview.operationPlan?.actions.some((action) => action.kind === 'removeOwnedArtifact' && action.pluginId === target.pluginId && action.platform === 'grok'
|
|
1354
|
+
&& action.scope === 'project' && action.path === project?.nativeIdentity?.sourceLocation));
|
|
1355
|
+
if (project && user && reviewedRemoval && removed?.length) {
|
|
1356
|
+
recordPreparedGrokProjectRetirement(runtime.preparedArtifactRenderResults, projectRoot, project, user, removed);
|
|
1357
|
+
}
|
|
1358
|
+
});
|
|
903
1359
|
}
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
if (!node) {
|
|
914
|
-
node = { pluginId, scope, targets: [], dependencies: new Set() };
|
|
915
|
-
nodes.set(key, node);
|
|
916
|
-
}
|
|
917
|
-
return node;
|
|
918
|
-
};
|
|
919
|
-
for (const child of joint.children.filter((child) => child.command !== 'cleanup')) {
|
|
920
|
-
for (const target of child.receipt.requestedTargets)
|
|
921
|
-
nodeFor(target.pluginId, target.scope).targets.push({ child, agent: target.agent });
|
|
922
|
-
}
|
|
923
|
-
const hasNative = (node) => node.targets.some(({ agent }) => agent !== 'generic');
|
|
924
|
-
for (const target of packages?.targets ?? []) {
|
|
925
|
-
const sameScope = nodes.get(`${target.pluginId}\0${target.scope}`);
|
|
926
|
-
const native = sameScope && hasNative(sameScope) ? sameScope
|
|
927
|
-
: [...nodes.values()].find((node) => node.pluginId === target.pluginId && hasNative(node));
|
|
928
|
-
const node = native ?? nodeFor(target.pluginId, target.scope);
|
|
929
|
-
(node.packages ??= []).push(target);
|
|
930
|
-
}
|
|
931
|
-
for (const node of nodes.values()) {
|
|
932
|
-
for (const { agent } of node.targets) {
|
|
933
|
-
const plugin = joint.demand.placements.find((item) => item.pluginId === node.pluginId && item.target === agent && item.scope === node.scope)?.plugin;
|
|
934
|
-
for (const name of plugin?.manifest.dependencies ?? []) {
|
|
935
|
-
const pluginId = `${plugin.sourceId}/${name}`;
|
|
936
|
-
const providers = joint.demand.placements.filter((item) => item.pluginId === pluginId && item.target === agent);
|
|
937
|
-
const provider = providers.find((item) => item.scope === node.scope) ?? providers.find((item) => item.scope === 'user');
|
|
938
|
-
if (provider)
|
|
939
|
-
node.dependencies.add(`${pluginId}\0${provider.scope}`);
|
|
1360
|
+
};
|
|
1361
|
+
let retiredProjectCopies = false;
|
|
1362
|
+
const nodes = new Map();
|
|
1363
|
+
const nodeFor = (pluginId, scope) => {
|
|
1364
|
+
const key = `${pluginId}\0${scope}`;
|
|
1365
|
+
let node = nodes.get(key);
|
|
1366
|
+
if (!node) {
|
|
1367
|
+
node = { pluginId, scope, targets: [], dependencies: new Set() };
|
|
1368
|
+
nodes.set(key, node);
|
|
940
1369
|
}
|
|
1370
|
+
return node;
|
|
1371
|
+
};
|
|
1372
|
+
for (const child of joint.children.filter((child) => child.command !== 'cleanup')) {
|
|
1373
|
+
for (const target of child.receipt.requestedTargets)
|
|
1374
|
+
nodeFor(target.pluginId, target.scope).targets.push({ child, agent: target.agent });
|
|
941
1375
|
}
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
1376
|
+
const hasNative = (node) => node.targets.some(({ agent }) => agent !== 'generic');
|
|
1377
|
+
for (const target of packages?.targets ?? []) {
|
|
1378
|
+
const sameScope = nodes.get(`${target.pluginId}\0${target.scope}`);
|
|
1379
|
+
const native = sameScope && hasNative(sameScope) ? sameScope
|
|
1380
|
+
: [...nodes.values()].find((node) => node.pluginId === target.pluginId && hasNative(node));
|
|
1381
|
+
const node = native ?? nodeFor(target.pluginId, target.scope);
|
|
1382
|
+
(node.packages ??= []).push(target);
|
|
949
1383
|
}
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
};
|
|
965
|
-
const applyPackages = async (pluginId, scope) => {
|
|
966
|
-
const key = `${pluginId}\0${scope}`;
|
|
967
|
-
const previous = completedPackages.get(key);
|
|
968
|
-
if (previous)
|
|
969
|
-
return previous;
|
|
970
|
-
return recordPackages(pluginId, scope, await packages.execute(pluginId, scope, token));
|
|
971
|
-
};
|
|
972
|
-
const blockPackages = (pluginId, scope, code) => completedPackages.get(`${pluginId}\0${scope}`)
|
|
973
|
-
?? recordPackages(pluginId, scope, packages?.blocked?.(pluginId, scope, code) ?? []);
|
|
974
|
-
if (packages)
|
|
975
|
-
runtime.nativeTargetExecution = {
|
|
976
|
-
beforeApply: async (identity) => {
|
|
977
|
-
const results = [];
|
|
978
|
-
for (const target of packages.targets.filter((target) => target.pluginId === identity.pluginId
|
|
979
|
-
&& (target.scope === 'user' || target.scope === identity.scope)))
|
|
980
|
-
results.push(...await applyPackages(target.pluginId, target.scope));
|
|
981
|
-
return results;
|
|
982
|
-
},
|
|
983
|
-
blocked: (identity, code) => packages.targets.filter((target) => target.pluginId === identity.pluginId
|
|
984
|
-
&& (target.scope === 'user' || target.scope === identity.scope)).flatMap((target) => blockPackages(target.pluginId, target.scope, code === 'dependencyInstallFailed' ? 'dependencyApplyFailed' : code)),
|
|
985
|
-
};
|
|
986
|
-
while (pending.length) {
|
|
987
|
-
const index = pending.findIndex((node) => {
|
|
988
|
-
const groups = node.targets.filter(({ child, agent }) => agent !== 'generic' && !executedNativeChildren.has(child));
|
|
989
|
-
const members = new Set([node, ...groups.flatMap(({ child }) => pending.filter((candidate) => candidate.targets.some((target) => target.child === child)))]);
|
|
990
|
-
return [...members].every((member) => [...member.dependencies].every((key) => !pending.some((candidate) => !members.has(candidate) && `${candidate.pluginId}\0${candidate.scope}` === key)));
|
|
991
|
-
});
|
|
992
|
-
if (index < 0) {
|
|
993
|
-
plan.receipt.blockers.push(diagnostic('dependencyContractInvalid'));
|
|
994
|
-
break;
|
|
1384
|
+
for (const node of nodes.values()) {
|
|
1385
|
+
for (const { agent } of node.targets) {
|
|
1386
|
+
for (const provider of dependencyGraph.directProviders({ pluginId: node.pluginId, target: agent, scope: node.scope })) {
|
|
1387
|
+
node.dependencies.add(`${provider.pluginId}\0${provider.scope}`);
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
if (node.scope === 'project' && node.targets.some(({ agent }) => ['codex', 'claude', 'copilot'].includes(agent))
|
|
1391
|
+
&& nodes.has(`${node.pluginId}\0user`))
|
|
1392
|
+
node.dependencies.add(`${node.pluginId}\0user`);
|
|
1393
|
+
for (const dependency of node.packages?.flatMap((item) => item.dependencies) ?? []) {
|
|
1394
|
+
for (const provider of nodes.values())
|
|
1395
|
+
if (provider.pluginId === dependency)
|
|
1396
|
+
node.dependencies.add(`${dependency}\0${provider.scope}`);
|
|
1397
|
+
}
|
|
995
1398
|
}
|
|
996
|
-
const
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1399
|
+
const pending = [...nodes.values()].sort((left, right) => left.scope === right.scope
|
|
1400
|
+
? left.pluginId.localeCompare(right.pluginId) : left.scope === 'user' ? -1 : 1);
|
|
1401
|
+
const executedNativeChildren = new Set();
|
|
1402
|
+
const completedPackages = new Map();
|
|
1403
|
+
const recordPackages = (pluginId, scope, produced) => {
|
|
1404
|
+
const key = `${pluginId}\0${scope}`;
|
|
1405
|
+
completedPackages.set(key, produced);
|
|
1406
|
+
packageResults.push(...produced);
|
|
1407
|
+
if (produced.some((result) => result.state !== 'completed')) {
|
|
1000
1408
|
failedPackages.add(key);
|
|
1001
1409
|
failedNodes.add(key);
|
|
1002
|
-
for (const target of node.packages)
|
|
1003
|
-
blockPackages(target.pluginId, target.scope, 'dependencyApplyFailed');
|
|
1004
|
-
plan.receipt.blockers.push(diagnostic('commandPackageProviderNotSatisfied', node.pluginId));
|
|
1005
1410
|
}
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1411
|
+
return produced;
|
|
1412
|
+
};
|
|
1413
|
+
const applyPackages = async (pluginId, scope) => {
|
|
1414
|
+
const key = `${pluginId}\0${scope}`;
|
|
1415
|
+
const previous = completedPackages.get(key);
|
|
1416
|
+
if (previous)
|
|
1417
|
+
return previous;
|
|
1418
|
+
return recordPackages(pluginId, scope, await packages.execute(pluginId, scope, token));
|
|
1419
|
+
};
|
|
1420
|
+
const blockPackages = (pluginId, scope, code) => completedPackages.get(`${pluginId}\0${scope}`)
|
|
1421
|
+
?? recordPackages(pluginId, scope, packages?.blocked?.(pluginId, scope, code) ?? []);
|
|
1422
|
+
if (packages)
|
|
1423
|
+
runtime.nativeTargetExecution = {
|
|
1424
|
+
beforeApply: async (identity) => {
|
|
1425
|
+
const results = [];
|
|
1426
|
+
for (const target of packages.targets.filter((target) => target.pluginId === identity.pluginId
|
|
1427
|
+
&& (target.scope === 'user' || target.scope === identity.scope)))
|
|
1428
|
+
results.push(...await applyPackages(target.pluginId, target.scope));
|
|
1429
|
+
return results;
|
|
1430
|
+
},
|
|
1431
|
+
blocked: (identity, code) => packages.targets.filter((target) => target.pluginId === identity.pluginId
|
|
1432
|
+
&& (target.scope === 'user' || target.scope === identity.scope)).flatMap((target) => blockPackages(target.pluginId, target.scope, code === 'dependencyInstallFailed' ? 'dependencyApplyFailed' : code)),
|
|
1433
|
+
};
|
|
1434
|
+
while (pending.length) {
|
|
1435
|
+
const index = pending.findIndex((node) => {
|
|
1436
|
+
const groups = node.targets.filter(({ child, agent }) => agent !== 'generic' && !executedNativeChildren.has(child));
|
|
1437
|
+
const members = new Set([node, ...groups.flatMap(({ child }) => pending.filter((candidate) => candidate.targets.some((target) => target.child === child)))]);
|
|
1438
|
+
return [...members].every((member) => [...member.dependencies].every((key) => !pending.some((candidate) => !members.has(candidate) && `${candidate.pluginId}\0${candidate.scope}` === key)));
|
|
1439
|
+
});
|
|
1440
|
+
if (index < 0) {
|
|
1441
|
+
plan.receipt.blockers.push(diagnostic('dependencyContractInvalid'));
|
|
1442
|
+
break;
|
|
1443
|
+
}
|
|
1444
|
+
const node = pending.splice(index, 1)[0];
|
|
1445
|
+
if (node.scope === 'project' && !retiredProjectCopies) {
|
|
1446
|
+
await retireVerified('project');
|
|
1447
|
+
retiredProjectCopies = true;
|
|
1448
|
+
}
|
|
1449
|
+
const key = `${node.pluginId}\0${node.scope}`;
|
|
1450
|
+
if (node.packages?.length && packages && !hasNative(node)) {
|
|
1451
|
+
if (failedNodes.has(key) || [...node.dependencies].some((dependency) => failedNodes.has(dependency))) {
|
|
1452
|
+
failedPackages.add(key);
|
|
1453
|
+
failedNodes.add(key);
|
|
1009
1454
|
for (const target of node.packages)
|
|
1010
|
-
|
|
1011
|
-
|
|
1455
|
+
blockPackages(target.pluginId, target.scope, 'dependencyApplyFailed');
|
|
1456
|
+
plan.receipt.blockers.push(diagnostic('commandPackageProviderNotSatisfied', node.pluginId));
|
|
1457
|
+
}
|
|
1458
|
+
else {
|
|
1459
|
+
try {
|
|
1460
|
+
const produced = [];
|
|
1461
|
+
for (const target of node.packages)
|
|
1462
|
+
produced.push(...await applyPackages(target.pluginId, target.scope));
|
|
1463
|
+
if (produced.some((result) => result.state !== 'completed')) {
|
|
1464
|
+
failedPackages.add(key);
|
|
1465
|
+
failedNodes.add(key);
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
catch (error) {
|
|
1469
|
+
runtime.signal?.throwIfAborted();
|
|
1470
|
+
if (error instanceof Error && error.name === 'AbortError' || readSafeOperationError(error))
|
|
1471
|
+
throw error;
|
|
1012
1472
|
failedPackages.add(key);
|
|
1013
1473
|
failedNodes.add(key);
|
|
1474
|
+
plan.receipt.blockers.push(diagnostic('commandPackageApplyFailed', node.pluginId));
|
|
1014
1475
|
}
|
|
1015
1476
|
}
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1477
|
+
}
|
|
1478
|
+
for (const { child, agent } of node.targets) {
|
|
1479
|
+
const native = agent !== 'generic';
|
|
1480
|
+
if (native && executedNativeChildren.has(child))
|
|
1481
|
+
continue;
|
|
1482
|
+
if (native)
|
|
1483
|
+
executedNativeChildren.add(child);
|
|
1484
|
+
const result = await executeChild(child, native ? child.receipt.requestedTargets.map((target) => target.pluginId) : node.pluginId, agent);
|
|
1485
|
+
for (const target of result.targetResults)
|
|
1486
|
+
if (target.blockers.length || !['applied', 'no-op'].includes(target.execution)) {
|
|
1487
|
+
failedNodes.add(`${target.pluginId}\0${target.scope}`);
|
|
1488
|
+
failedProviders.add(`${target.pluginId}\0${target.agent}\0${target.scope}`);
|
|
1489
|
+
}
|
|
1024
1490
|
}
|
|
1025
1491
|
}
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
continue;
|
|
1030
|
-
if (native)
|
|
1031
|
-
executedNativeChildren.add(child);
|
|
1032
|
-
const result = await executeChild(child, native ? child.receipt.requestedTargets.map((target) => target.pluginId) : node.pluginId, agent);
|
|
1033
|
-
for (const target of result.targetResults)
|
|
1034
|
-
if (target.blockers.length || !['applied', 'no-op'].includes(target.execution)) {
|
|
1035
|
-
failedNodes.add(`${target.pluginId}\0${target.scope}`);
|
|
1036
|
-
failedProviders.add(`${target.pluginId}\0${target.agent}\0${target.scope}`);
|
|
1037
|
-
}
|
|
1038
|
-
}
|
|
1492
|
+
if (!retiredProjectCopies)
|
|
1493
|
+
await retireVerified('project');
|
|
1494
|
+
await retireVerified('user');
|
|
1039
1495
|
}
|
|
1040
1496
|
const receipt = mergeReceipts(plan, results);
|
|
1041
1497
|
receipt.commandResults = [...new Map([...packageResults, ...(receipt.commandResults ?? [])]
|
|
@@ -1045,29 +1501,44 @@ export async function executeJointRecovery(plan, execution) {
|
|
|
1045
1501
|
receipt.ok &&= failedPackages.size === 0;
|
|
1046
1502
|
receipt.outputsMayHaveChanged ||= packageResults.some((result) => result.state === 'completed');
|
|
1047
1503
|
receipt.errors.push(...results.flatMap((result) => result.targetResults.flatMap((target) => target.blockers)));
|
|
1504
|
+
if (!receipt.ok && retriesFromRequestedRoots(receipt))
|
|
1505
|
+
useDeclaredRetryRoots(receipt);
|
|
1506
|
+
completedReceipt = receipt;
|
|
1507
|
+
if (interrupted)
|
|
1508
|
+
throw interrupted;
|
|
1509
|
+
runtime.signal?.throwIfAborted();
|
|
1048
1510
|
const { cwd, scope, env, cliVersion } = joint.originalOptions;
|
|
1049
1511
|
const context = joint.snapshot.context.context;
|
|
1050
1512
|
let statusFailure;
|
|
1513
|
+
let statusFailureMessage = 'Could not read the final plugin status.';
|
|
1051
1514
|
try {
|
|
1052
1515
|
// The reviewed Catalog may still be readable after Active has moved. Bind the
|
|
1053
1516
|
// final read to the current sources, once per binding across both scopes.
|
|
1054
1517
|
const status = await measureRecoveryPerformanceStage(runtime, 'recovery.status', () => readRecoveryStatus({ cwd, scope, context, env, cliVersion, expectedProjectRoot: joint.snapshot.context.projectRoot,
|
|
1055
|
-
catalogReadScope: new CatalogPreparationReadScope({ env }),
|
|
1056
|
-
nativeCliRunner: runtime.nativeCliRunner, codexObservationSession: runtime.codexObservationSession }));
|
|
1518
|
+
catalogReadScope: new CatalogPreparationReadScope({ env, signal: runtime.signal }), signal: runtime.signal,
|
|
1519
|
+
nativeCliRunner: runtime.nativeCliRunner, ...(isInstallBatch(plan.command) ? {} : { codexObservationSession: runtime.codexObservationSession }) }));
|
|
1057
1520
|
receipt.allSatisfied = status.allSatisfied;
|
|
1058
1521
|
receipt.inSync = status.inSync;
|
|
1059
1522
|
statusFailure = finalStatusReadFailure(status, receipt);
|
|
1060
1523
|
}
|
|
1061
1524
|
catch (error) {
|
|
1525
|
+
const interruption = recoveryInterruptionCode(error, runtime.signal);
|
|
1526
|
+
if (runtime.signal?.aborted || interruption === 'operationInterrupted')
|
|
1527
|
+
throw error;
|
|
1528
|
+
// All writes have settled. A failed final query leaves its own cleanup
|
|
1529
|
+
// uncertain without invalidating the previously verified target receipts.
|
|
1530
|
+
if (interruption === 'processCleanupUnconfirmed') {
|
|
1531
|
+
statusFailureMessage = 'Could not read the final plugin status. The status query process cleanup could not be confirmed.';
|
|
1532
|
+
}
|
|
1062
1533
|
receipt.allSatisfied = null;
|
|
1063
1534
|
receipt.inSync = null;
|
|
1064
1535
|
statusFailure = diagnostic(readSafeOperationError(error)?.code ?? errorCode(error, 'statusUnavailable'));
|
|
1065
1536
|
}
|
|
1066
1537
|
if (statusFailure) {
|
|
1067
1538
|
receipt.ok = false;
|
|
1068
|
-
receipt.errors.push({ code: 'statusUnavailable', message:
|
|
1539
|
+
receipt.errors.push({ code: 'statusUnavailable', message: statusFailureMessage,
|
|
1069
1540
|
subject: statusFailure.subject, detail: { reasonCode: statusFailure.code } });
|
|
1070
|
-
receipt.recoveryActions.push(`aw plugin status --context ${
|
|
1541
|
+
receipt.recoveryActions.push(`aw plugin status --context ${recoveryStatusContext(receipt)} --json`);
|
|
1071
1542
|
}
|
|
1072
1543
|
return receipt;
|
|
1073
1544
|
} });
|
|
@@ -1076,10 +1547,27 @@ export async function executeJointRecovery(plan, execution) {
|
|
|
1076
1547
|
if (lockWaitStartedAt !== undefined) {
|
|
1077
1548
|
await recordRecoveryPerformanceStage(performanceRuntime, 'recovery.lock.wait', 'failure', lockWaitStartedAt);
|
|
1078
1549
|
}
|
|
1550
|
+
const code = recoveryInterruptionCode(error, performanceRuntime.signal);
|
|
1551
|
+
if (code) {
|
|
1552
|
+
const receipt = completedReceipt ?? structuredClone(plan.receipt);
|
|
1553
|
+
receipt.ok = false;
|
|
1554
|
+
receipt.allSatisfied = null;
|
|
1555
|
+
receipt.inSync = null;
|
|
1556
|
+
if (!receipt.errors.some((entry) => entry.code === code))
|
|
1557
|
+
receipt.errors.push(diagnostic(code));
|
|
1558
|
+
receipt.remainingTargets = receipt.targetResults.filter((target) => target.blockers.length || !['applied', 'no-op'].includes(target.execution))
|
|
1559
|
+
.map(({ pluginId, agent, scope, delivery }) => ({ pluginId, agent, scope, delivery }));
|
|
1560
|
+
throw new RecoveryInterruptedError(receipt, error);
|
|
1561
|
+
}
|
|
1079
1562
|
throw error;
|
|
1080
1563
|
}
|
|
1081
1564
|
finally {
|
|
1082
|
-
|
|
1565
|
+
try {
|
|
1566
|
+
await lockedPlan?.context.dispose();
|
|
1567
|
+
}
|
|
1568
|
+
finally {
|
|
1569
|
+
await plan.context.dispose();
|
|
1570
|
+
}
|
|
1083
1571
|
}
|
|
1084
1572
|
}
|
|
1085
1573
|
//# sourceMappingURL=joint-coordinator.js.map
|