@lesliechan721/aw 0.1.0-beta.73 → 0.1.0-beta.74
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 +65 -43
- package/dist/authoring/assets/aw-runtime-config.mjs.map +1 -1
- package/dist/authoring/scripts/add-skill.mjs +5 -14
- package/dist/authoring/scripts/add-skill.mjs.map +1 -1
- package/dist/authoring/scripts/init-plugin.mjs +4 -28
- package/dist/authoring/scripts/init-plugin.mjs.map +1 -1
- package/dist/authoring/scripts/lib/plugin-version-check.mjs +2 -2
- package/dist/authoring/scripts/lib/plugin-version-check.mjs.map +1 -1
- package/dist/authoring/scripts/lib/skill-scaffold.mjs +0 -1
- package/dist/authoring/scripts/lib/skill-scaffold.mjs.map +1 -1
- package/dist/authoring/scripts/validate-plugin.mjs +234 -1422
- package/dist/authoring/scripts/validate-plugin.mjs.map +1 -1
- package/dist/scripts/aw-skill-eval-materializer.d.ts +2 -0
- package/dist/scripts/aw-skill-eval-materializer.js +19 -80
- package/dist/scripts/aw-skill-eval-materializer.js.map +1 -1
- package/dist/scripts/bundle-plugins.js.map +1 -1
- package/dist/scripts/test-plugin-scripts.js +6 -8
- package/dist/scripts/test-plugin-scripts.js.map +1 -1
- package/dist/src/commands/aw-capabilities.d.ts +1 -1
- package/dist/src/commands/aw-capabilities.js +2 -2
- package/dist/src/commands/aw-capabilities.js.map +1 -1
- package/dist/src/commands/dependency-operation-plan.js +3 -3
- package/dist/src/commands/dependency-operation-plan.js.map +1 -1
- package/dist/src/commands/deployment-confirmation.d.ts +4 -0
- package/dist/src/commands/deployment-confirmation.js +20 -0
- package/dist/src/commands/deployment-confirmation.js.map +1 -0
- package/dist/src/commands/managed-commands.js +4 -2
- package/dist/src/commands/managed-commands.js.map +1 -1
- package/dist/src/commands/offline-cleanup-evidence.d.ts +3 -1
- package/dist/src/commands/offline-cleanup-evidence.js +9 -4
- package/dist/src/commands/offline-cleanup-evidence.js.map +1 -1
- package/dist/src/commands/operation-plan.d.ts +6 -0
- package/dist/src/commands/operation-plan.js +29 -2
- package/dist/src/commands/operation-plan.js.map +1 -1
- package/dist/src/commands/options.d.ts +6 -2
- package/dist/src/commands/options.js +5 -4
- package/dist/src/commands/options.js.map +1 -1
- package/dist/src/commands/plugin-capabilities.js +29 -41
- package/dist/src/commands/plugin-capabilities.js.map +1 -1
- package/dist/src/commands/public-config-confirmation.js +5 -5
- package/dist/src/commands/public-config-confirmation.js.map +1 -1
- package/dist/src/commands/public-lifecycle-result.d.ts +47 -0
- package/dist/src/commands/public-lifecycle-result.js +119 -4
- package/dist/src/commands/public-lifecycle-result.js.map +1 -1
- package/dist/src/commands/public-lifecycle.d.ts +1 -0
- package/dist/src/commands/public-lifecycle.js +15 -2
- package/dist/src/commands/public-lifecycle.js.map +1 -1
- package/dist/src/commands/public-plugin-query.d.ts +1 -0
- package/dist/src/commands/public-plugin-query.js +28 -8
- package/dist/src/commands/public-plugin-query.js.map +1 -1
- package/dist/src/commands/rebuild-command.d.ts +12 -11
- package/dist/src/commands/rebuild-command.js +529 -769
- package/dist/src/commands/rebuild-command.js.map +1 -1
- package/dist/src/commands/rebuild-integration.d.ts +21 -43
- package/dist/src/commands/rebuild-integration.js +306 -3600
- package/dist/src/commands/rebuild-integration.js.map +1 -1
- package/dist/src/commands/rebuild-operations.d.ts +13 -0
- package/dist/src/commands/rebuild-operations.js +60 -15
- package/dist/src/commands/rebuild-operations.js.map +1 -1
- package/dist/src/commands/rebuild-platform-integration.d.ts +59 -0
- package/dist/src/commands/rebuild-platform-integration.js +1200 -0
- package/dist/src/commands/rebuild-platform-integration.js.map +1 -0
- package/dist/src/commands/review-inspection.js +41 -4
- package/dist/src/commands/review-inspection.js.map +1 -1
- package/dist/src/commands/review-preparation.d.ts +2 -0
- package/dist/src/commands/review-preparation.js +23 -60
- package/dist/src/commands/review-preparation.js.map +1 -1
- package/dist/src/commands/skill-eval.js +1 -0
- package/dist/src/commands/skill-eval.js.map +1 -1
- package/dist/src/commands/status-v6.d.ts +3 -1
- package/dist/src/commands/status-v6.js +24 -15
- package/dist/src/commands/status-v6.js.map +1 -1
- package/dist/src/commands/targets-command.d.ts +9 -0
- package/dist/src/commands/targets-command.js +57 -6
- package/dist/src/commands/targets-command.js.map +1 -1
- package/dist/src/commands/write-commands.js +43 -28
- package/dist/src/commands/write-commands.js.map +1 -1
- package/dist/src/constants.d.ts +2 -2
- package/dist/src/constants.js +2 -2
- package/dist/src/constants.js.map +1 -1
- package/dist/src/generators/local-plugin.js +59 -248
- package/dist/src/generators/local-plugin.js.map +1 -1
- package/dist/src/index.js +40 -14
- package/dist/src/index.js.map +1 -1
- package/dist/src/output/command-receipt.d.ts +1 -1
- package/dist/src/output/command-receipt.js +3 -1
- package/dist/src/output/command-receipt.js.map +1 -1
- package/dist/src/output/native-consent.d.ts +2 -0
- package/dist/src/output/native-consent.js +5 -0
- package/dist/src/output/native-consent.js.map +1 -0
- package/dist/src/output/public-result.js +60 -0
- package/dist/src/output/public-result.js.map +1 -1
- package/dist/src/output/rebuild-progress.js +5 -5
- package/dist/src/output/rebuild-progress.js.map +1 -1
- package/dist/src/output/receipt-projection.js +19 -2
- package/dist/src/output/receipt-projection.js.map +1 -1
- package/dist/src/platforms/capabilities.d.ts +10 -0
- package/dist/src/platforms/capabilities.js +158 -0
- package/dist/src/platforms/capabilities.js.map +1 -0
- package/dist/src/platforms/contracts.d.ts +338 -0
- package/dist/src/platforms/contracts.js +2 -0
- package/dist/src/platforms/contracts.js.map +1 -0
- package/dist/src/platforms/cursor-workspace-hook.d.ts +22 -0
- package/dist/src/platforms/cursor-workspace-hook.js +185 -0
- package/dist/src/platforms/cursor-workspace-hook.js.map +1 -0
- package/dist/src/platforms/discovery.d.ts +74 -0
- package/dist/src/platforms/discovery.js +582 -0
- package/dist/src/platforms/discovery.js.map +1 -0
- package/dist/src/platforms/gemini-activation.d.ts +36 -0
- package/dist/src/platforms/gemini-activation.js +331 -0
- package/dist/src/platforms/gemini-activation.js.map +1 -0
- package/dist/src/platforms/gemini-consent.d.ts +8 -0
- package/dist/src/platforms/gemini-consent.js +79 -0
- package/dist/src/platforms/gemini-consent.js.map +1 -0
- package/dist/src/platforms/identity.d.ts +4 -0
- package/dist/src/platforms/identity.js +22 -0
- package/dist/src/platforms/identity.js.map +1 -0
- package/dist/src/platforms/inspection-grok.d.ts +4 -0
- package/dist/src/platforms/inspection-grok.js +173 -0
- package/dist/src/platforms/inspection-grok.js.map +1 -0
- package/dist/src/platforms/inspection-native.d.ts +6 -0
- package/dist/src/platforms/inspection-native.js +379 -0
- package/dist/src/platforms/inspection-native.js.map +1 -0
- package/dist/src/platforms/inspection-pi.d.ts +4 -0
- package/dist/src/platforms/inspection-pi.js +212 -0
- package/dist/src/platforms/inspection-pi.js.map +1 -0
- package/dist/src/platforms/inspection.d.ts +13 -0
- package/dist/src/platforms/inspection.js +189 -0
- package/dist/src/platforms/inspection.js.map +1 -0
- package/dist/src/platforms/layout.d.ts +21 -0
- package/dist/src/platforms/layout.js +239 -0
- package/dist/src/platforms/layout.js.map +1 -0
- package/dist/src/platforms/lifecycle-native-services.d.ts +3 -0
- package/dist/src/platforms/lifecycle-native-services.js +147 -0
- package/dist/src/platforms/lifecycle-native-services.js.map +1 -0
- package/dist/src/platforms/lifecycle-native.d.ts +9 -0
- package/dist/src/platforms/lifecycle-native.js +252 -0
- package/dist/src/platforms/lifecycle-native.js.map +1 -0
- package/dist/src/platforms/lifecycle.d.ts +25 -0
- package/dist/src/platforms/lifecycle.js +452 -0
- package/dist/src/platforms/lifecycle.js.map +1 -0
- package/dist/src/platforms/managed-command-placement.d.ts +8 -0
- package/dist/src/platforms/managed-command-placement.js +79 -0
- package/dist/src/platforms/managed-command-placement.js.map +1 -0
- package/dist/src/platforms/projection-code-extension.d.ts +8 -0
- package/dist/src/platforms/projection-code-extension.js +121 -0
- package/dist/src/platforms/projection-code-extension.js.map +1 -0
- package/dist/src/platforms/projection-command-resources.d.ts +7 -0
- package/dist/src/platforms/projection-command-resources.js +74 -0
- package/dist/src/platforms/projection-command-resources.js.map +1 -0
- package/dist/src/platforms/projection-files.d.ts +27 -0
- package/dist/src/platforms/projection-files.js +111 -0
- package/dist/src/platforms/projection-files.js.map +1 -0
- package/dist/src/platforms/projection-marketplace.d.ts +19 -0
- package/dist/src/platforms/projection-marketplace.js +42 -0
- package/dist/src/platforms/projection-marketplace.js.map +1 -0
- package/dist/src/platforms/projection.d.ts +10 -0
- package/dist/src/platforms/projection.js +446 -0
- package/dist/src/platforms/projection.js.map +1 -0
- package/dist/src/platforms/registry.d.ts +4 -0
- package/dist/src/platforms/registry.js +30 -0
- package/dist/src/platforms/registry.js.map +1 -0
- package/dist/src/platforms/supplement-layout.d.ts +16 -0
- package/dist/src/platforms/supplement-layout.js +31 -0
- package/dist/src/platforms/supplement-layout.js.map +1 -0
- package/dist/src/portable/commands.d.ts +7 -5
- package/dist/src/portable/commands.js +6 -1
- package/dist/src/portable/commands.js.map +1 -1
- package/dist/src/portable/materializer.d.ts +8 -6
- package/dist/src/portable/materializer.js +47 -245
- package/dist/src/portable/materializer.js.map +1 -1
- package/dist/src/portable/recovery-layout.js +2 -15
- package/dist/src/portable/recovery-layout.js.map +1 -1
- package/dist/src/portable/recovery.d.ts +10 -1
- package/dist/src/portable/recovery.js +34 -8
- package/dist/src/portable/recovery.js.map +1 -1
- package/dist/src/recovery/coordinator.d.ts +4 -7
- package/dist/src/recovery/coordinator.js +151 -119
- package/dist/src/recovery/coordinator.js.map +1 -1
- package/dist/src/recovery/demand.d.ts +1 -1
- package/dist/src/recovery/demand.js +10 -42
- package/dist/src/recovery/demand.js.map +1 -1
- package/dist/src/recovery/joint-coordinator.js +112 -52
- package/dist/src/recovery/joint-coordinator.js.map +1 -1
- package/dist/src/recovery/joint-demand.d.ts +4 -22
- package/dist/src/recovery/joint-demand.js +43 -40
- package/dist/src/recovery/joint-demand.js.map +1 -1
- package/dist/src/recovery/receipt.d.ts +23 -8
- package/dist/src/recovery/retirement.d.ts +1 -1
- package/dist/src/recovery/retirement.js +122 -29
- package/dist/src/recovery/retirement.js.map +1 -1
- package/dist/src/recovery/status.d.ts +13 -6
- package/dist/src/recovery/status.js +479 -79
- package/dist/src/recovery/status.js.map +1 -1
- package/dist/src/recovery/types.d.ts +3 -3
- package/dist/src/review/platform-profile.d.ts +3 -0
- package/dist/src/review/platform-profile.js +16 -0
- package/dist/src/review/platform-profile.js.map +1 -0
- package/dist/src/review/review-profile.d.ts +1 -0
- package/dist/src/review/review-profile.js +8 -2
- package/dist/src/review/review-profile.js.map +1 -1
- package/dist/src/review/review-selection.d.ts +2 -11
- package/dist/src/review/review-selection.js +97 -71
- package/dist/src/review/review-selection.js.map +1 -1
- package/dist/src/review/review-types.d.ts +3 -0
- package/dist/src/review/review-types.js.map +1 -1
- package/dist/src/review/skill-materialization.d.ts +44 -9
- package/dist/src/review/skill-materialization.js +112 -136
- package/dist/src/review/skill-materialization.js.map +1 -1
- package/dist/src/review/source-binding.d.ts +8 -5
- package/dist/src/review/source-binding.js +99 -41
- package/dist/src/review/source-binding.js.map +1 -1
- package/dist/src/tui/agent-management.js +112 -10
- package/dist/src/tui/agent-management.js.map +1 -1
- package/dist/src/tui/agent-settings.d.ts +3 -0
- package/dist/src/tui/agent-settings.js +10 -11
- package/dist/src/tui/agent-settings.js.map +1 -1
- package/dist/src/tui/console-app-v4.js +58 -20
- package/dist/src/tui/console-app-v4.js.map +1 -1
- package/dist/src/tui/content-item-card.js +2 -2
- package/dist/src/tui/content-item-card.js.map +1 -1
- package/dist/src/tui/controller-runtime.js +198 -152
- package/dist/src/tui/controller-runtime.js.map +1 -1
- package/dist/src/tui/controller.d.ts +5 -9
- package/dist/src/tui/controller.js +40 -18
- package/dist/src/tui/controller.js.map +1 -1
- package/dist/src/tui/deployment-view.d.ts +10 -0
- package/dist/src/tui/deployment-view.js +91 -0
- package/dist/src/tui/deployment-view.js.map +1 -0
- package/dist/src/tui/glossary.js +4 -4
- package/dist/src/tui/glossary.js.map +1 -1
- package/dist/src/tui/model.d.ts +5 -0
- package/dist/src/tui/model.js +73 -12
- package/dist/src/tui/model.js.map +1 -1
- package/dist/src/tui/operation-diagnostic-screens.js +2 -1
- package/dist/src/tui/operation-diagnostic-screens.js.map +1 -1
- package/dist/src/tui/operation-history.d.ts +5 -4
- package/dist/src/tui/operation-history.js.map +1 -1
- package/dist/src/tui/operation-review-planner.d.ts +7 -2
- package/dist/src/tui/operation-review-planner.js +97 -42
- package/dist/src/tui/operation-review-planner.js.map +1 -1
- package/dist/src/tui/plugin-content.d.ts +5 -3
- package/dist/src/tui/plugin-content.js +70 -508
- package/dist/src/tui/plugin-content.js.map +1 -1
- package/dist/src/tui/plugin-detail.d.ts +3 -2
- package/dist/src/tui/plugin-detail.js +33 -25
- package/dist/src/tui/plugin-detail.js.map +1 -1
- package/dist/src/tui/scoped-inventory.d.ts +10 -6
- package/dist/src/tui/scoped-inventory.js +34 -1
- package/dist/src/tui/scoped-inventory.js.map +1 -1
- package/dist/src/types.d.ts +4 -63
- package/dist/src/types.js.map +1 -1
- package/dist/src/utils/agent-version.d.ts +10 -4
- package/dist/src/utils/agent-version.js.map +1 -1
- package/dist/src/utils/artifact-plan.d.ts +26 -2
- package/dist/src/utils/artifact-plan.js +113 -489
- package/dist/src/utils/artifact-plan.js.map +1 -1
- package/dist/src/utils/artifact-renderer.d.ts +100 -93
- package/dist/src/utils/artifact-renderer.js +173 -346
- package/dist/src/utils/artifact-renderer.js.map +1 -1
- package/dist/src/utils/artifact-request.d.ts +21 -11
- package/dist/src/utils/artifact-request.js +56 -80
- package/dist/src/utils/artifact-request.js.map +1 -1
- package/dist/src/utils/bundle-layout.js +30 -146
- package/dist/src/utils/bundle-layout.js.map +1 -1
- package/dist/src/utils/catalog-digests.d.ts +2 -12
- package/dist/src/utils/catalog-digests.js +0 -39
- package/dist/src/utils/catalog-digests.js.map +1 -1
- package/dist/src/utils/catalog-source-references.d.ts +7 -0
- package/dist/src/utils/catalog-source-references.js +234 -19
- package/dist/src/utils/catalog-source-references.js.map +1 -1
- package/dist/src/utils/codex-config-observation.d.ts +19 -0
- package/dist/src/utils/codex-config-observation.js +145 -0
- package/dist/src/utils/codex-config-observation.js.map +1 -0
- package/dist/src/utils/codex-executable-discovery.d.ts +2 -0
- package/dist/src/utils/codex-executable-discovery.js +47 -13
- package/dist/src/utils/codex-executable-discovery.js.map +1 -1
- package/dist/src/utils/codex-manager.js +1 -1
- package/dist/src/utils/codex-manager.js.map +1 -1
- package/dist/src/utils/codex-native-observation.d.ts +3 -0
- package/dist/src/utils/codex-native-observation.js +53 -0
- package/dist/src/utils/codex-native-observation.js.map +1 -1
- package/dist/src/utils/codex-shared-native.d.ts +3 -1
- package/dist/src/utils/codex-shared-native.js +46 -5
- package/dist/src/utils/codex-shared-native.js.map +1 -1
- package/dist/src/utils/codex-skill-staging.d.ts +4 -3
- package/dist/src/utils/codex-skill-staging.js.map +1 -1
- package/dist/src/utils/codex-surface-analysis.d.ts +5 -2
- package/dist/src/utils/codex-surface-analysis.js +28 -57
- package/dist/src/utils/codex-surface-analysis.js.map +1 -1
- package/dist/src/utils/component-command-preparation.d.ts +34 -0
- package/dist/src/utils/component-command-preparation.js +228 -0
- package/dist/src/utils/component-command-preparation.js.map +1 -0
- package/dist/src/utils/component-resources.d.ts +43 -0
- package/dist/src/utils/component-resources.js +304 -0
- package/dist/src/utils/component-resources.js.map +1 -0
- package/dist/src/utils/dynamic-skill-tree.d.ts +17 -6
- package/dist/src/utils/dynamic-skill-tree.js +7 -3
- package/dist/src/utils/dynamic-skill-tree.js.map +1 -1
- package/dist/src/utils/local-marketplace.d.ts +11 -44
- package/dist/src/utils/local-marketplace.js +11 -638
- package/dist/src/utils/local-marketplace.js.map +1 -1
- package/dist/src/utils/managed-command-evidence.d.ts +2 -2
- package/dist/src/utils/managed-command-evidence.js +5 -81
- package/dist/src/utils/managed-command-evidence.js.map +1 -1
- package/dist/src/utils/managed-command-materialization.d.ts +5 -2
- package/dist/src/utils/managed-command-materialization.js +35 -35
- package/dist/src/utils/managed-command-materialization.js.map +1 -1
- package/dist/src/utils/managed-command-preparation.d.ts +67 -0
- package/dist/src/utils/managed-command-preparation.js +146 -0
- package/dist/src/utils/managed-command-preparation.js.map +1 -0
- package/dist/src/utils/managed-command-review.d.ts +26 -0
- package/dist/src/utils/managed-command-review.js +68 -0
- package/dist/src/utils/managed-command-review.js.map +1 -0
- package/dist/src/utils/managed-command-store.js +26 -15
- package/dist/src/utils/managed-command-store.js.map +1 -1
- package/dist/src/utils/native-cli.d.ts +19 -0
- package/dist/src/utils/native-cli.js +45 -2
- package/dist/src/utils/native-cli.js.map +1 -1
- package/dist/src/utils/native-demand.d.ts +20 -1
- package/dist/src/utils/native-demand.js.map +1 -1
- package/dist/src/utils/native-tool-review.d.ts +3 -6
- package/dist/src/utils/native-tool-review.js +25 -11
- package/dist/src/utils/native-tool-review.js.map +1 -1
- package/dist/src/utils/ownership.d.ts +26 -3
- package/dist/src/utils/ownership.js +95 -9
- package/dist/src/utils/ownership.js.map +1 -1
- package/dist/src/utils/paths.d.ts +1 -1
- package/dist/src/utils/paths.js +2 -0
- package/dist/src/utils/paths.js.map +1 -1
- package/dist/src/utils/platform-empty-state.d.ts +46 -0
- package/dist/src/utils/platform-empty-state.js +123 -0
- package/dist/src/utils/platform-empty-state.js.map +1 -0
- package/dist/src/utils/plugin-config-impact.d.ts +17 -11
- package/dist/src/utils/plugin-config-impact.js +46 -62
- package/dist/src/utils/plugin-config-impact.js.map +1 -1
- package/dist/src/utils/plugin-config-write.js +52 -53
- package/dist/src/utils/plugin-config-write.js.map +1 -1
- package/dist/src/utils/plugin-config.d.ts +0 -2
- package/dist/src/utils/plugin-config.js +0 -6
- package/dist/src/utils/plugin-config.js.map +1 -1
- package/dist/src/utils/plugin-dependencies.d.ts +1 -1
- package/dist/src/utils/plugin-dependencies.js.map +1 -1
- package/dist/src/utils/runtime-config.d.ts +5 -7
- package/dist/src/utils/runtime-config.js +12 -25
- package/dist/src/utils/runtime-config.js.map +1 -1
- package/dist/src/utils/windows-npm-shim.js +19 -2
- package/dist/src/utils/windows-npm-shim.js.map +1 -1
- package/package.json +3 -3
- package/dist/src/utils/claude-native-render-receipt.d.ts +0 -14
- package/dist/src/utils/claude-native-render-receipt.js +0 -26
- package/dist/src/utils/claude-native-render-receipt.js.map +0 -1
- package/dist/src/utils/claude-skills-root.d.ts +0 -8
- package/dist/src/utils/claude-skills-root.js +0 -87
- package/dist/src/utils/claude-skills-root.js.map +0 -1
- package/dist/src/utils/codex-native-render-receipt.d.ts +0 -40
- package/dist/src/utils/codex-native-render-receipt.js +0 -205
- package/dist/src/utils/codex-native-render-receipt.js.map +0 -1
- package/dist/src/utils/slash-commands.d.ts +0 -1
- package/dist/src/utils/slash-commands.js +0 -2
- package/dist/src/utils/slash-commands.js.map +0 -1
|
@@ -1,168 +1,107 @@
|
|
|
1
1
|
import crypto from 'node:crypto';
|
|
2
|
-
import { captureNativeToolChanges } from '../utils/native-tool-review.js';
|
|
3
|
-
import { forceOfflineCleanupEvidence } from './offline-cleanup-evidence.js';
|
|
4
2
|
import path from 'node:path';
|
|
3
|
+
import { captureNativeToolChanges } from '../utils/native-tool-review.js';
|
|
4
|
+
import { catalogFileMode } from '@lesliechan721/aw-plugin-core';
|
|
5
|
+
import { getCommandPackageId } from '@lesliechan721/aw-plugin-core/manifest';
|
|
5
6
|
import fs from 'fs-extra';
|
|
6
|
-
import { catalogFileMode, selectPluginConfigProfile } from '@lesliechan721/aw-plugin-core';
|
|
7
|
-
import { COMMAND_PRODUCER_RECORD_FILE, getManagedCommandArtifactTargets, getCommandPackageId } from '@lesliechan721/aw-plugin-core/manifest';
|
|
8
7
|
import os from 'node:os';
|
|
9
|
-
import {
|
|
10
|
-
import { assertManagedCommandBindingIdentities,
|
|
11
|
-
import {
|
|
12
|
-
import { resolveCodexSkillsRelativeRoot } from '../utils/codex-skills-root.js';
|
|
13
|
-
import { resolveClaudeSkillsRelativeRoot } from '../utils/claude-skills-root.js';
|
|
14
|
-
import { generateAgentArtifacts } from '../generators/agents.js';
|
|
15
|
-
import { generateInstructionArtifacts, renderCodexManagedInstructionBlock, } from '../generators/instructions.js';
|
|
16
|
-
import { generateCodexPermissionArtifacts, mergeClaudePermissions, } from '../generators/permissions.js';
|
|
8
|
+
import { discoverRetainedManagedCommandPackages, managedCommandProducerIdentity, prepareManagedCommandPackage, retainedManagedCommandPackageResult } from '../utils/managed-command-materialization.js';
|
|
9
|
+
import { assertManagedCommandBindingIdentities, listManagedCommands, managedCommandDiagnostic, ManagedCommandError, revokeManagedCommandBindings, syncManagedCommandPackage } from '../utils/managed-command-store.js';
|
|
10
|
+
import { readClaudeSettings, writeClaudeSettings } from '../adapters/helpers.js';
|
|
17
11
|
import { buildGeneratedName } from '../generators/shared.js';
|
|
18
|
-
import { applyConditionalCodexConfigTransactionFile, applyCodexConfigTransactionFile, composeManagedDeveloperInstructionsBlock, readCodexConfigFile, } from '../utils/codex-config.js';
|
|
19
|
-
import { canonicalizePathThroughExistingAncestor, resolveClaudeProjectKey, resolveCodexProjectKey, } from '../utils/state-paths.js';
|
|
20
|
-
import { createCodexSkillStagingTreeContentDigest, } from '../utils/codex-skill-staging.js';
|
|
21
|
-
import { AW_PLUGIN_REQUIREMENTS_RECEIPT_PATH, createDynamicSkillExpectedTree, createDynamicSkillTreeContentDigest, readDynamicSkillTree, validateSkillDirectory, writeDynamicSkillTree, } from '../utils/dynamic-skill-tree.js';
|
|
22
|
-
import { parseCodexSharedHooksFile, serializeTrackedHookGroupIdentity, } from '../utils/hooks-contract.js';
|
|
23
|
-
import { buildCodexMarketplaceAddInvocation, buildCodexMarketplaceRemoveInvocation, buildCodexPluginAddInvocation, buildCodexPluginRemoveInvocation, CodexProjectConfigNotEffectiveError, runNativeCliChecked, SYSTEM_CODEX_MANAGER, } from '../utils/native-cli.js';
|
|
24
|
-
import { attachSafeOperationError, readSafeOperationError } from '../utils/safe-operation-diagnostic.js';
|
|
25
|
-
import { OWNED_TEXT_HEADER_PREFIX, createSharedOwnerToken, createSkillOwnerMarkerContent, parseSharedOwnerToken, parseOwnedTextHeader, readSkillOwnerMarker, renderOwnedTextFile, inspectOwnedComponents, writeOwnedTextFile, } from '../utils/ownership.js';
|
|
26
|
-
import { resolveArtifactRenderConfig, resolveArtifactRendererTarget, runArtifactRenderer, } from '../utils/artifact-renderer.js';
|
|
27
|
-
import { createArtifactConfigDigest, validateArtifactPlan, } from '../utils/artifact-plan.js';
|
|
28
|
-
import { resolveAwDeliveredArtifactRequestBatches } from '../utils/artifact-request.js';
|
|
29
|
-
import { createAwPluginRequirementsReceipt, parseAwPluginRequirementsReceipt, readPluginManifest, tryParseStrictSemVer, } from '../utils/manifest.js';
|
|
30
|
-
import { resolvePlatformEntries } from '../utils/platform-entries.js';
|
|
31
|
-
import { resolveAwHome, resolveClaudePaths, resolveCodexPaths, resolveRepoRoot, getCodexHome, } from '../utils/paths.js';
|
|
32
|
-
import { assertNoSensitiveConfigInFiles, collectSensitivePluginConfigValues, runPreApplyScript, } from '../utils/plugin-scripts.js';
|
|
33
|
-
import { validateRuntimeSkillClosure } from '../utils/runtime-skill-closure.js';
|
|
34
|
-
import { findSensitiveTokenPath } from '../utils/sensitive-content.js';
|
|
35
|
-
import { atomicRemoveConfigFile, atomicReplaceConfigFile, withConfigFileMutation, } from '../utils/plugin-config.js';
|
|
36
12
|
import { readCatalogSourcesConfigSnapshot } from '../utils/catalog-sources.js';
|
|
37
|
-
import {
|
|
38
|
-
import { commitMarketplaceGenerationBackup } from '../utils/orphan-marketplace-cleanup.js';
|
|
39
|
-
import { readClaudeSettings, writeClaudeSettings } from '../adapters/helpers.js';
|
|
40
|
-
import { analyzeCodexSurface } from '../utils/codex-surface-analysis.js';
|
|
41
|
-
import { codexNativeRenderProjectionsEqual, createCodexNativeRenderProjection, createCodexNativeRenderReceipt, } from '../utils/codex-native-render-receipt.js';
|
|
42
|
-
import { createClaudeNativeRenderReceipt, nativeSkillRenderReceiptPath, parseNativeSkillRenderReceipt, serializeNativeSkillRenderReceipt, } from '../utils/claude-native-render-receipt.js';
|
|
43
|
-
import { inspectCodexSharedNative, } from '../utils/codex-shared-native.js';
|
|
44
|
-
import { calculateCodexNativeRenderPayloadDigest } from '../utils/catalog-digests.js';
|
|
45
|
-
import { createCodexNativeObservationSession, } from '../utils/codex-native-observation.js';
|
|
13
|
+
import { applyCodexConfigTransactionFile, applyConditionalCodexConfigTransactionFile, readCodexConfigFile } from '../utils/codex-config.js';
|
|
46
14
|
import { isSafeCodexMarketplaceRoot } from '../utils/codex-marketplace-path.js';
|
|
15
|
+
import { createCodexNativeObservationSession, } from '../utils/codex-native-observation.js';
|
|
16
|
+
import { inspectCodexSharedNative, isCanonicalCodexMarketplaceRegistration, } from '../utils/codex-shared-native.js';
|
|
17
|
+
import { validateSkillDirectory } from '../utils/dynamic-skill-tree.js';
|
|
18
|
+
import { parseCodexSharedHooksFile, serializeTrackedHookGroupIdentity, } from '../utils/hooks-contract.js';
|
|
19
|
+
import { assertSafeNamespacedMarketplacePluginRoot, readStrictNamespacedMarketplaceRoot } from '../utils/local-marketplace.js';
|
|
20
|
+
import { buildCodexMarketplaceRemoveInvocation, buildCodexPluginRemoveInvocation, CodexProjectConfigNotEffectiveError, runNativeCliChecked, SYSTEM_CODEX_MANAGER } from '../utils/native-cli.js';
|
|
21
|
+
import { inspectOwnedComponents, OWNED_TEXT_HEADER_PREFIX, parseOwnedTextHeader, parseSharedOwnerToken, readSkillOwnerMarker } from '../utils/ownership.js';
|
|
22
|
+
import { resolveAwHome, resolveClaudePaths, resolveCodexPaths, resolveRepoRoot } from '../utils/paths.js';
|
|
23
|
+
import { atomicRemoveConfigFile, atomicReplaceConfigFile, withConfigFileMutation, } from '../utils/plugin-config.js';
|
|
24
|
+
import { runPreApplyScript } from '../utils/plugin-scripts.js';
|
|
47
25
|
import { assertCanonicalProjectManagedRoots } from '../utils/project-boundary.js';
|
|
48
|
-
import {
|
|
26
|
+
import { attachSafeOperationError, readSafeOperationError } from '../utils/safe-operation-diagnostic.js';
|
|
27
|
+
import { createProjectLocationKey, resolveRequiredCanonicalRepoRoot, resolveClaudeProjectKey, resolveCodexProjectKey } from '../utils/state-paths.js';
|
|
28
|
+
import { platformOwnership, PlatformRebuildSession } from './rebuild-platform-integration.js';
|
|
49
29
|
const MARKETPLACE_NAME = 'aw';
|
|
50
30
|
const LEGACY_MCP_OWNER_ENV = 'AW_AGENT_WORKFLOWS_OWNER';
|
|
51
|
-
function requirementsReceipt(plugin) {
|
|
52
|
-
const receipt = createAwPluginRequirementsReceipt({ name: plugin.manifest.name, version: plugin.manifest.version }, plugin.manifest.requires?.aw.capabilities ?? []);
|
|
53
|
-
return Buffer.from(`${JSON.stringify(receipt, null, 2)}\n`, 'utf8');
|
|
54
|
-
}
|
|
55
|
-
function withoutVerifiedRequirementsReceipt(plugin, files) {
|
|
56
|
-
const receipt = files[AW_PLUGIN_REQUIREMENTS_RECEIPT_PATH];
|
|
57
|
-
if (!receipt)
|
|
58
|
-
return { ...files };
|
|
59
|
-
let actual;
|
|
60
|
-
let expected;
|
|
61
|
-
try {
|
|
62
|
-
actual = parseAwPluginRequirementsReceipt(JSON.parse(receipt.toString('utf8')));
|
|
63
|
-
expected = parseAwPluginRequirementsReceipt(JSON.parse(requirementsReceipt(plugin).toString('utf8')));
|
|
64
|
-
}
|
|
65
|
-
catch {
|
|
66
|
-
return { ...files };
|
|
67
|
-
}
|
|
68
|
-
if (JSON.stringify(actual) !== JSON.stringify(expected)) {
|
|
69
|
-
return { ...files };
|
|
70
|
-
}
|
|
71
|
-
const output = { ...files };
|
|
72
|
-
delete output[AW_PLUGIN_REQUIREMENTS_RECEIPT_PATH];
|
|
73
|
-
return output;
|
|
74
|
-
}
|
|
75
31
|
const commandPackagePreparationCaches = new WeakMap();
|
|
76
|
-
const
|
|
77
|
-
const
|
|
78
|
-
function
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
async function prepareStaticCommandArtifacts(options) {
|
|
89
|
-
const targets = getManagedCommandArtifactTargets(options.plugin.manifest).filter((target) => target.producer.kind === 'static-skill' && target.platform === options.platform);
|
|
90
|
-
if (!targets.length)
|
|
91
|
-
return [];
|
|
92
|
-
const config = await resolveArtifactRenderConfig({ sourceId: options.plugin.sourceId, sourceIdentity: options.plugin.sourceIdentity, logicalIdentity: options.plugin.catalogLogicalIdentity, pluginName: options.plugin.manifest.name, manifest: options.plugin.manifest, platform: options.platform, scope: 'user', cwd: options.plugin.rootDir, env: options.env, referencePlugins: options.context.referencePlugins });
|
|
93
|
-
const key = JSON.stringify([options.plugin.rootDir, options.platform, config]);
|
|
94
|
-
let cache = staticCommandPreparationCaches.get(options.context);
|
|
95
|
-
if (!cache) {
|
|
96
|
-
cache = new Map();
|
|
97
|
-
staticCommandPreparationCaches.set(options.context, cache);
|
|
98
|
-
}
|
|
99
|
-
let prepared = cache.get(key);
|
|
100
|
-
if (!prepared) {
|
|
101
|
-
prepared = (async () => {
|
|
102
|
-
const rendered = await runArtifactRenderer({ plugin: options.plugin, referencePlugins: options.context.referencePlugins, event: 'install', platform: options.platform, scope: 'user', configScope: 'user', cwd: options.plugin.rootDir, commandEnv: options.env, requestedArtifactIds: targets.map((target) => target.id), signal: options.context.signal, scriptTimeoutMs: options.context.scriptTimeoutMs });
|
|
103
|
-
return validateArtifactPlan({ manifest: options.plugin.manifest, plan: rendered.plan, platform: options.platform, scope: 'user', requestedArtifactIds: rendered.context.requestedArtifactIds, renderConfig: rendered.context.config, rendererDigest: rendered.target.rendererDigest, manifestDigest: rendered.target.manifestDigest }).artifacts;
|
|
104
|
-
})();
|
|
105
|
-
cache.set(key, prepared);
|
|
32
|
+
const platformRebuildSessions = new WeakMap();
|
|
33
|
+
const commandPackageCandidates = new WeakMap();
|
|
34
|
+
export function finalizePreparedPlatformRebuildSession(results) {
|
|
35
|
+
platformRebuildSessions.get(results)?.freezeMarketplaceCandidates();
|
|
36
|
+
}
|
|
37
|
+
export async function disposePreparedPlatformRebuildSession(results) {
|
|
38
|
+
const session = platformRebuildSessions.get(results);
|
|
39
|
+
platformRebuildSessions.delete(results);
|
|
40
|
+
const packages = commandPackageCandidates.get(results);
|
|
41
|
+
commandPackageCandidates.delete(results);
|
|
42
|
+
try {
|
|
43
|
+
await session?.dispose();
|
|
106
44
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return false;
|
|
114
|
-
const pluginRoot = path.join(options.marketplaceRoot, 'plugins', options.plugin.manifest.name);
|
|
115
|
-
const skillsRoot = path.join(pluginRoot, await resolveCodexSkillsRelativeRoot({ ...options.plugin, rootDir: pluginRoot }));
|
|
116
|
-
for (const set of options.plugin.manifest.managedCommands?.sets ?? []) {
|
|
117
|
-
if (set.producer.kind !== 'static-skill' || set.producer.platform !== 'codex' || set.mode !== 'dynamic')
|
|
118
|
-
continue;
|
|
119
|
-
const producer = await managedCommandProducerIdentity({ ...options, producer: set.producer, platform: 'codex', scope: 'user' });
|
|
120
|
-
const expected = commandSetsForProducer({ plugin: options.plugin, producer: set.producer, artifacts });
|
|
121
|
-
const previous = await readInstalledCommandProducer(path.join(skillsRoot, set.producer.skillKey)).catch(() => null);
|
|
122
|
-
if (!previous || JSON.stringify(previous.producer) !== JSON.stringify(producer) || JSON.stringify(previous.sets) !== JSON.stringify(expected))
|
|
123
|
-
return true;
|
|
45
|
+
finally {
|
|
46
|
+
if (packages)
|
|
47
|
+
await Promise.all([...packages.values()].map(async (candidate) => {
|
|
48
|
+
const prepared = await candidate.catch(() => undefined);
|
|
49
|
+
await prepared?.cleanup();
|
|
50
|
+
}));
|
|
124
51
|
}
|
|
125
|
-
return false;
|
|
126
52
|
}
|
|
127
53
|
async function commandPackageActions(options) {
|
|
128
54
|
const actions = [];
|
|
129
55
|
const candidates = [];
|
|
56
|
+
const packageCache = options.context.packagePreparationCache ??= new Map();
|
|
57
|
+
let cache = commandPackagePreparationCaches.get(options.context);
|
|
58
|
+
if (!cache) {
|
|
59
|
+
cache = new Map();
|
|
60
|
+
commandPackagePreparationCaches.set(options.context, cache);
|
|
61
|
+
}
|
|
130
62
|
for (const declaration of options.plugin.manifest.managedCommands?.packages ?? []) {
|
|
131
63
|
if (!declaration.platforms.includes(options.platform))
|
|
132
64
|
continue;
|
|
133
|
-
const producer = await managedCommandProducerIdentity({ ...options, scope: declaration.scope,
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
commandPackagePreparationCaches.set(options.context, cache);
|
|
138
|
-
}
|
|
139
|
-
let preparation = cache.get(getCommandPackageId(producer));
|
|
65
|
+
const producer = await managedCommandProducerIdentity({ ...options, scope: declaration.scope,
|
|
66
|
+
producer: { kind: 'package', packageKey: declaration.key } });
|
|
67
|
+
const key = getCommandPackageId(producer);
|
|
68
|
+
let preparation = cache.get(key);
|
|
140
69
|
if (!preparation) {
|
|
141
70
|
preparation = (async () => {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
71
|
+
let candidate = packageCache.get(key);
|
|
72
|
+
if (!candidate) {
|
|
73
|
+
candidate = prepareManagedCommandPackage({ ...options, referencePlugins: options.context.referencePlugins,
|
|
74
|
+
packageKey: declaration.key, scope: declaration.scope, signal: options.context.signal,
|
|
75
|
+
scriptTimeoutMs: options.context.scriptTimeoutMs });
|
|
76
|
+
packageCache.set(key, candidate);
|
|
77
|
+
}
|
|
78
|
+
const prepared = await candidate;
|
|
79
|
+
const files = [];
|
|
80
|
+
async function visit(directory, prefix) {
|
|
81
|
+
for (const entry of await fs.readdir(directory, { withFileTypes: true })) {
|
|
82
|
+
const relativePath = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
83
|
+
const absolute = path.join(directory, entry.name);
|
|
84
|
+
if (entry.isDirectory()) {
|
|
85
|
+
await visit(absolute, relativePath);
|
|
155
86
|
}
|
|
87
|
+
else if (entry.isFile()) {
|
|
88
|
+
const content = await fs.readFile(absolute);
|
|
89
|
+
files.push({ relativePath, contentBase64: content.toString('base64'),
|
|
90
|
+
contentDigest: `sha256:${crypto.createHash('sha256').update(content).digest('hex')}`,
|
|
91
|
+
mode: (await fs.stat(absolute)).mode & 0o777 });
|
|
92
|
+
}
|
|
93
|
+
else
|
|
94
|
+
throw new ManagedCommandError('commandResourceInvalid', 'The prepared package contains an unsafe resource.');
|
|
156
95
|
}
|
|
157
|
-
await visit(prepared.resourceRoot, '');
|
|
158
|
-
files.sort((left, right) => left.relativePath.localeCompare(right.relativePath));
|
|
159
|
-
return { action: { kind: 'syncManagedCommandPackage', pluginId: pluginActionId(options.plugin), scope: declaration.scope, producer: prepared.producer, sets: prepared.sets, nativeTools: prepared.nativeTools, files, contentDigest: `sha256:${crypto.createHash('sha256').update(JSON.stringify(files)).digest('hex')}` }, candidate: { producer: prepared.producer, sets: prepared.sets, nativeTools: prepared.nativeTools } };
|
|
160
|
-
}
|
|
161
|
-
finally {
|
|
162
|
-
await prepared.cleanup();
|
|
163
96
|
}
|
|
97
|
+
await visit(prepared.resourceRoot, '');
|
|
98
|
+
files.sort((left, right) => left.relativePath.localeCompare(right.relativePath));
|
|
99
|
+
return { action: { kind: 'syncManagedCommandPackage', pluginId: pluginActionId(options.plugin),
|
|
100
|
+
scope: declaration.scope, producer: prepared.producer, sets: prepared.sets, nativeTools: prepared.nativeTools,
|
|
101
|
+
files, contentDigest: `sha256:${crypto.createHash('sha256').update(JSON.stringify(files)).digest('hex')}` },
|
|
102
|
+
candidate: { producer: prepared.producer, sets: prepared.sets, nativeTools: prepared.nativeTools } };
|
|
164
103
|
})();
|
|
165
|
-
cache.set(
|
|
104
|
+
cache.set(key, preparation);
|
|
166
105
|
}
|
|
167
106
|
const prepared = await preparation;
|
|
168
107
|
actions.push(prepared.action);
|
|
@@ -170,69 +109,6 @@ async function commandPackageActions(options) {
|
|
|
170
109
|
}
|
|
171
110
|
return { actions, candidates };
|
|
172
111
|
}
|
|
173
|
-
async function prepareSkillCommandCandidate(options) {
|
|
174
|
-
const sets = options.sets ?? commandSetsForProducer(options);
|
|
175
|
-
if (sets.length === 0)
|
|
176
|
-
return undefined;
|
|
177
|
-
const producer = await managedCommandProducerIdentity(options);
|
|
178
|
-
if (Object.keys(options.tree.files).length === 0)
|
|
179
|
-
return { producer, sets: sets.map((set) => ({ ...set, state: 'disabled', entries: [] })) };
|
|
180
|
-
if (Object.hasOwn(options.tree.files, COMMAND_PRODUCER_RECORD_FILE))
|
|
181
|
-
throw new Error('commandProducerReservedResource: plugin cannot provide the command producer record.');
|
|
182
|
-
for (const set of sets)
|
|
183
|
-
for (const entry of set.entries) {
|
|
184
|
-
if (!options.tree.files[entry.entry])
|
|
185
|
-
throw new Error(`commandResourceInvalid: command entry ${entry.entry} is missing from the final Skill.`);
|
|
186
|
-
if (process.platform !== 'win32' && entry.runner === 'executable' && options.tree.fileModes?.[entry.entry] !== 0o755)
|
|
187
|
-
throw new Error(`commandRunnerUnsupported: command entry ${entry.entry} has no executable source file.`);
|
|
188
|
-
}
|
|
189
|
-
const nativeTools = injectNativeToolClosureFiles(options.tree.files, await nativeToolsForCommandSets(options.plugin, sets));
|
|
190
|
-
options.tree.files[COMMAND_PRODUCER_RECORD_FILE] = Buffer.from(`${JSON.stringify({ schemaVersion: 1, producer, sets, ...(nativeTools ? { nativeTools } : {}) }, null, 2)}\n`);
|
|
191
|
-
return { producer, sets, nativeTools };
|
|
192
|
-
}
|
|
193
|
-
async function prepareStaticNativeSkillActions(options) {
|
|
194
|
-
if (!options.plugin.manifest.skills)
|
|
195
|
-
return { actions: [], candidates: [] };
|
|
196
|
-
if (!options.plugin.manifest.requires?.aw.capabilities?.includes('aw.managed-commands.v1'))
|
|
197
|
-
return { actions: [], candidates: [] };
|
|
198
|
-
const scope = 'user';
|
|
199
|
-
const root = path.join(options.plugin.rootDir, options.platform, options.plugin.manifest.skills.replace(/^\.\//u, ''));
|
|
200
|
-
const trees = [];
|
|
201
|
-
const candidates = [];
|
|
202
|
-
let artifacts = [...options.artifacts];
|
|
203
|
-
const missingTargets = getManagedCommandArtifactTargets(options.plugin.manifest).filter((target) => {
|
|
204
|
-
const producer = target.producer;
|
|
205
|
-
return producer.kind === 'static-skill' && target.platform === options.platform && !artifacts.some((artifact) => artifact.id === target.id) && !options.commandCandidates.some((candidate) => candidate.producer.kind === 'static-skill' && candidate.producer.key === producer.skillKey && candidate.producer.platform === options.platform && candidate.producer.scope === scope);
|
|
206
|
-
});
|
|
207
|
-
if (missingTargets.length) {
|
|
208
|
-
const rendered = await runArtifactRenderer({ plugin: options.plugin, event: 'install', platform: options.platform, scope, configScope: scope, cwd: options.plugin.rootDir, commandEnv: options.env, requestedArtifactIds: missingTargets.map((target) => target.id), signal: options.signal, scriptTimeoutMs: options.scriptTimeoutMs });
|
|
209
|
-
artifacts.push(...validateArtifactPlan({ manifest: options.plugin.manifest, plan: rendered.plan, platform: options.platform, scope, requestedArtifactIds: rendered.context.requestedArtifactIds, renderConfig: rendered.context.config, rendererDigest: rendered.target.rendererDigest, manifestDigest: rendered.target.manifestDigest }).artifacts);
|
|
210
|
-
}
|
|
211
|
-
for (const entry of await fs.readdir(root, { withFileTypes: true })) {
|
|
212
|
-
if (!entry.isDirectory())
|
|
213
|
-
continue;
|
|
214
|
-
const tree = await readDynamicSkillTree(path.join(root, entry.name), `${options.platform}.skill`);
|
|
215
|
-
if (!tree)
|
|
216
|
-
continue;
|
|
217
|
-
const previous = options.commandCandidates.find((candidate) => candidate.producer.kind === 'static-skill' && candidate.producer.key === tree.skillKey && candidate.producer.platform === options.platform && candidate.producer.scope === scope);
|
|
218
|
-
const candidate = await prepareSkillCommandCandidate({ ...options, scope, producer: { kind: 'static-skill', platform: options.platform, skillKey: tree.skillKey }, tree, artifacts, ...(previous ? { sets: previous.sets } : {}) });
|
|
219
|
-
if (candidate)
|
|
220
|
-
candidates.push(candidate);
|
|
221
|
-
trees.push(tree);
|
|
222
|
-
}
|
|
223
|
-
const resolver = await createManagedCommandReferenceResolver({ ...options, scope, candidates: [...options.commandCandidates, ...candidates] });
|
|
224
|
-
const actions = [];
|
|
225
|
-
for (const tree of trees) {
|
|
226
|
-
const hasCommandReferences = Object.entries(tree.files).some(([relative, content]) => relative.endsWith('.md') && content.includes('{{aw.command:'));
|
|
227
|
-
const hasCommandProducer = Object.hasOwn(tree.files, COMMAND_PRODUCER_RECORD_FILE);
|
|
228
|
-
if (!hasCommandReferences && !hasCommandProducer)
|
|
229
|
-
continue;
|
|
230
|
-
resolveSkillManagedCommandReferences(tree, resolver);
|
|
231
|
-
const files = Object.entries(tree.files).map(([relativePath, content]) => ({ relativePath, contentBase64: content.toString('base64'), contentDigest: `sha256:${crypto.createHash('sha256').update(content).digest('hex')}`, ...(tree.fileModes?.[relativePath] ? { mode: tree.fileModes[relativePath] } : {}) })).sort((left, right) => left.relativePath.localeCompare(right.relativePath));
|
|
232
|
-
actions.push({ kind: 'materializeNativeSkill', pluginId: pluginActionId(options.plugin), platform: options.platform, scope, skillKey: tree.skillKey, files, contentDigest: `sha256:${crypto.createHash('sha256').update(JSON.stringify(files)).digest('hex')}` });
|
|
233
|
-
}
|
|
234
|
-
return { actions, candidates };
|
|
235
|
-
}
|
|
236
112
|
export class CodexActivationPostcheckError extends Error {
|
|
237
113
|
code = 'codexActivationPostcheckFailed';
|
|
238
114
|
codexPluginIds;
|
|
@@ -491,100 +367,9 @@ export async function postcheckCodexReconcileActivations(options) {
|
|
|
491
367
|
}
|
|
492
368
|
}
|
|
493
369
|
const CODEX_REMOVE_RECOVERY = 'Codex residue was retained. Retry cleanup or uninstall, upgrade AW, or install a compatible official Codex CLI.';
|
|
494
|
-
function ownerIdentity(plugin, artifactKey, platform, scope) {
|
|
495
|
-
return { owner: 'agent-workflows', plugin, artifactKey, platform, scope };
|
|
496
|
-
}
|
|
497
|
-
function pluginOwnerIdentity(plugin, artifactKey, platform, scope) {
|
|
498
|
-
return {
|
|
499
|
-
...ownerIdentity(plugin.manifest.name, artifactKey, platform, scope),
|
|
500
|
-
...(plugin.sourceId ? {
|
|
501
|
-
sourceId: plugin.sourceId,
|
|
502
|
-
pluginId: plugin.pluginId,
|
|
503
|
-
} : {}),
|
|
504
|
-
};
|
|
505
|
-
}
|
|
506
|
-
function bindNamespacedOwnerIdentity(components, source) {
|
|
507
|
-
if (!source.sourceId)
|
|
508
|
-
return;
|
|
509
|
-
for (const component of components) {
|
|
510
|
-
component.identity.sourceId = source.sourceId;
|
|
511
|
-
component.identity.pluginId = source.pluginId;
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
function internalArtifactKey(kind, value) {
|
|
515
|
-
return `${kind}-${crypto.createHash('sha256').update(value).digest('hex').slice(0, 20)}`;
|
|
516
|
-
}
|
|
517
|
-
function pathComponent(options) {
|
|
518
|
-
if (options.kind !== 'skill-directory')
|
|
519
|
-
return options;
|
|
520
|
-
return {
|
|
521
|
-
...options,
|
|
522
|
-
validateHealth: true,
|
|
523
|
-
};
|
|
524
|
-
}
|
|
525
370
|
function pluginActionId(plugin) {
|
|
526
371
|
return plugin.pluginId ?? plugin.manifest.name;
|
|
527
372
|
}
|
|
528
|
-
function finalizeOwnedArtifactActions(actions) {
|
|
529
|
-
for (const action of actions) {
|
|
530
|
-
if (action.kind !== 'writeOwnedArtifact' || !action.owner)
|
|
531
|
-
continue;
|
|
532
|
-
if (action.artifactKind === 'owned-text-file') {
|
|
533
|
-
if (action.sourceContent === undefined)
|
|
534
|
-
throw new Error('Owned text action is missing source content.');
|
|
535
|
-
action.content = renderOwnedTextFile(action.sourceContent, action.owner);
|
|
536
|
-
action.contentDigest = `sha256:${crypto.createHash('sha256').update(action.content).digest('hex')}`;
|
|
537
|
-
continue;
|
|
538
|
-
}
|
|
539
|
-
if (action.artifactKind === 'skill-directory') {
|
|
540
|
-
const markerContent = createSkillOwnerMarkerContent(action.owner);
|
|
541
|
-
const marker = {
|
|
542
|
-
relativePath: '.agent-workflows-owner.json',
|
|
543
|
-
contentBase64: Buffer.from(markerContent).toString('base64'),
|
|
544
|
-
contentDigest: `sha256:${crypto.createHash('sha256').update(markerContent).digest('hex')}`,
|
|
545
|
-
};
|
|
546
|
-
action.files = [
|
|
547
|
-
...(action.files ?? []).filter((file) => file.relativePath !== marker.relativePath),
|
|
548
|
-
marker,
|
|
549
|
-
].sort((left, right) => left.relativePath.localeCompare(right.relativePath));
|
|
550
|
-
action.contentDigest = `sha256:${crypto.createHash('sha256')
|
|
551
|
-
.update(JSON.stringify(action.files)).digest('hex')}`;
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
function generatedTextWrite(options) {
|
|
556
|
-
const artifactPath = path.join(options.configDir, options.relativePath);
|
|
557
|
-
const identity = ownerIdentity(options.plugin.manifest.name, options.artifactKey, options.platform, options.scope);
|
|
558
|
-
const component = pathComponent({
|
|
559
|
-
kind: 'owned-text-file',
|
|
560
|
-
path: artifactPath,
|
|
561
|
-
allowedRoot: options.configDir,
|
|
562
|
-
identity,
|
|
563
|
-
});
|
|
564
|
-
const content = options.content;
|
|
565
|
-
return {
|
|
566
|
-
artifact: {
|
|
567
|
-
path: artifactPath,
|
|
568
|
-
kind: options.kind,
|
|
569
|
-
platform: options.platform,
|
|
570
|
-
artifactKey: options.artifactKey,
|
|
571
|
-
},
|
|
572
|
-
component,
|
|
573
|
-
action: {
|
|
574
|
-
kind: 'writeOwnedArtifact',
|
|
575
|
-
pluginId: pluginActionId(options.plugin),
|
|
576
|
-
platform: options.platform,
|
|
577
|
-
scope: options.scope,
|
|
578
|
-
path: artifactPath,
|
|
579
|
-
allowedRoot: options.configDir,
|
|
580
|
-
owner: identity,
|
|
581
|
-
artifactKind: 'owned-text-file',
|
|
582
|
-
sourceContent: content,
|
|
583
|
-
content,
|
|
584
|
-
contentDigest: `sha256:${crypto.createHash('sha256').update(content).digest('hex')}`,
|
|
585
|
-
},
|
|
586
|
-
};
|
|
587
|
-
}
|
|
588
373
|
function mergePermissionStates(values) {
|
|
589
374
|
return {
|
|
590
375
|
allow: [...new Set(values.flatMap((value) => value?.allow ?? []))],
|
|
@@ -667,51 +452,6 @@ function rebuildClaudePermissions(settings, ownerKey, desired) {
|
|
|
667
452
|
delete settings.awGenerated;
|
|
668
453
|
}
|
|
669
454
|
}
|
|
670
|
-
function createClaudePermissionsComponent(options) {
|
|
671
|
-
const ownerKey = createSharedOwnerToken(options.identity);
|
|
672
|
-
return {
|
|
673
|
-
kind: 'shared-config',
|
|
674
|
-
identity: options.identity,
|
|
675
|
-
label: `${options.settingsPath}#awGenerated.permissions.${ownerKey}`,
|
|
676
|
-
locator: { kind: 'claude-permissions', settingsPath: options.settingsPath, ownerKey },
|
|
677
|
-
};
|
|
678
|
-
}
|
|
679
|
-
function createCodexInstructionComponent(options) {
|
|
680
|
-
const ownerKey = createSharedOwnerToken(options.identity);
|
|
681
|
-
return {
|
|
682
|
-
kind: 'managed-block',
|
|
683
|
-
identity: options.identity,
|
|
684
|
-
label: `${options.configPath}#developer_instructions:${ownerKey}`,
|
|
685
|
-
locator: { kind: 'codex-instruction', configPath: options.configPath, ownerKey },
|
|
686
|
-
};
|
|
687
|
-
}
|
|
688
|
-
function createCodexActivationComponent(options) {
|
|
689
|
-
return {
|
|
690
|
-
kind: 'shared-config',
|
|
691
|
-
identity: options.identity,
|
|
692
|
-
label: `${options.configPath}#plugins.${options.codexPluginId}.enabled`,
|
|
693
|
-
locator: {
|
|
694
|
-
kind: 'codex-activation',
|
|
695
|
-
configPath: options.configPath,
|
|
696
|
-
codexPluginId: options.codexPluginId,
|
|
697
|
-
desired: options.desired,
|
|
698
|
-
},
|
|
699
|
-
};
|
|
700
|
-
}
|
|
701
|
-
function createCodexActivationCleanupComponent(options) {
|
|
702
|
-
return {
|
|
703
|
-
kind: 'shared-config',
|
|
704
|
-
identity: options.identity,
|
|
705
|
-
label: `${options.configPath}#plugins.${options.codexPluginId}.enabled`,
|
|
706
|
-
locator: {
|
|
707
|
-
kind: 'codex-activation',
|
|
708
|
-
configPath: options.configPath,
|
|
709
|
-
codexPluginId: options.codexPluginId,
|
|
710
|
-
desired: options.disposition === 'remove' ? false : true,
|
|
711
|
-
disposition: options.disposition,
|
|
712
|
-
},
|
|
713
|
-
};
|
|
714
|
-
}
|
|
715
455
|
function legacyCodexMcpOwner(actual) {
|
|
716
456
|
const envValue = actual?.value?.env;
|
|
717
457
|
return envValue
|
|
@@ -721,20 +461,6 @@ function legacyCodexMcpOwner(actual) {
|
|
|
721
461
|
? envValue[LEGACY_MCP_OWNER_ENV]
|
|
722
462
|
: null;
|
|
723
463
|
}
|
|
724
|
-
function createLegacyCodexMcpCleanupComponent(options) {
|
|
725
|
-
const ownerKey = createSharedOwnerToken(options.identity);
|
|
726
|
-
return {
|
|
727
|
-
kind: 'shared-config',
|
|
728
|
-
identity: options.identity,
|
|
729
|
-
label: `${options.configPath}#mcp_servers.${options.serverKey}`,
|
|
730
|
-
locator: {
|
|
731
|
-
kind: 'legacy-codex-mcp',
|
|
732
|
-
configPath: options.configPath,
|
|
733
|
-
serverKey: options.serverKey,
|
|
734
|
-
ownerKey,
|
|
735
|
-
},
|
|
736
|
-
};
|
|
737
|
-
}
|
|
738
464
|
async function readLegacyCodexHooks(hooksPath) {
|
|
739
465
|
if (!await fs.pathExists(hooksPath))
|
|
740
466
|
return parseCodexSharedHooksFile({ hooks: {} });
|
|
@@ -774,19 +500,6 @@ async function applyLegacyCodexHookCleanupTransactionFile(hooksPath, update) {
|
|
|
774
500
|
},
|
|
775
501
|
});
|
|
776
502
|
}
|
|
777
|
-
function createLegacyCodexHookCleanupComponent(options) {
|
|
778
|
-
const serialized = serializeTrackedHookGroupIdentity(options.identity);
|
|
779
|
-
return {
|
|
780
|
-
kind: 'shared-config',
|
|
781
|
-
identity: ownerIdentity(options.pluginName, internalArtifactKey('hook', serialized), 'codex', options.scope),
|
|
782
|
-
label: `${options.hooksPath}#${serialized}`,
|
|
783
|
-
locator: {
|
|
784
|
-
kind: 'legacy-codex-hook',
|
|
785
|
-
hooksPath: options.hooksPath,
|
|
786
|
-
serializedIdentity: serialized,
|
|
787
|
-
},
|
|
788
|
-
};
|
|
789
|
-
}
|
|
790
503
|
async function codexRoleRegistrationOwned(options) {
|
|
791
504
|
if (!options.registration?.configFile)
|
|
792
505
|
return false;
|
|
@@ -825,1379 +538,138 @@ export async function removeForceCleanupCodexRoleRegistration(options) {
|
|
|
825
538
|
: null;
|
|
826
539
|
});
|
|
827
540
|
}
|
|
828
|
-
function createCodexRoleRegistrationComponent(options) {
|
|
829
|
-
return {
|
|
830
|
-
kind: 'shared-config',
|
|
831
|
-
identity: options.identity,
|
|
832
|
-
label: `${options.configPath}#agents.${options.roleKey}`,
|
|
833
|
-
locator: {
|
|
834
|
-
kind: 'codex-role-registration',
|
|
835
|
-
configPath: options.configPath,
|
|
836
|
-
roleKey: options.roleKey,
|
|
837
|
-
rolePath: options.rolePath,
|
|
838
|
-
fileIdentity: options.fileIdentity,
|
|
839
|
-
},
|
|
840
|
-
};
|
|
841
|
-
}
|
|
842
|
-
function sameOwnerIdentity(left, right) {
|
|
843
|
-
return left.owner === right.owner
|
|
844
|
-
&& left.sourceId === right.sourceId
|
|
845
|
-
&& left.pluginId === right.pluginId
|
|
846
|
-
&& left.plugin === right.plugin
|
|
847
|
-
&& left.artifactKey === right.artifactKey
|
|
848
|
-
&& left.platform === right.platform
|
|
849
|
-
&& left.scope === right.scope;
|
|
850
|
-
}
|
|
851
541
|
function sharedOwnerPluginName(value) {
|
|
852
542
|
return parseSharedOwnerToken(value)?.plugin ?? value;
|
|
853
543
|
}
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
544
|
+
function observedCodexNativeState(observation, operation) {
|
|
545
|
+
if (observation.state === 'observed') {
|
|
546
|
+
return observation.value === 'installed' ? 'present' : 'absent';
|
|
547
|
+
}
|
|
548
|
+
if (observation.state === 'unobserved')
|
|
549
|
+
return 'partial';
|
|
550
|
+
throw new Error(`codexNativeObservationFailed: ${operation} requires Codex plugin list evidence.`);
|
|
551
|
+
}
|
|
552
|
+
function requireObservedCodexNativeState(observation, operation) {
|
|
553
|
+
if (observation.state === 'observed')
|
|
554
|
+
return observation.value;
|
|
555
|
+
const code = observation.state === 'failed'
|
|
556
|
+
? 'codexNativeObservationFailed'
|
|
557
|
+
: 'codexNativeObservationUnavailable';
|
|
558
|
+
throw new Error(`${code}: ${operation} requires Codex plugin list evidence.`);
|
|
559
|
+
}
|
|
560
|
+
export async function inspectCodexPluginRegistrationLive(options) {
|
|
561
|
+
if (!options.nativeCliRunner) {
|
|
562
|
+
return {
|
|
563
|
+
observation: { state: 'unobserved' },
|
|
564
|
+
observations: { user: false, project: false },
|
|
565
|
+
activations: {},
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
const ownedSession = options.observationSession ? undefined
|
|
569
|
+
: await createCodexNativeObservationSession({
|
|
570
|
+
exactCwd: options.cwd,
|
|
571
|
+
env: options.env,
|
|
572
|
+
runner: options.nativeCliRunner,
|
|
573
|
+
manager: options.manager ?? SYSTEM_CODEX_MANAGER,
|
|
574
|
+
});
|
|
575
|
+
const session = options.observationSession ?? ownedSession;
|
|
576
|
+
try {
|
|
577
|
+
const inspected = await session.inspectPlugin({
|
|
860
578
|
pluginId: options.pluginId,
|
|
861
|
-
|
|
579
|
+
scope: options.scope ?? 'both',
|
|
580
|
+
});
|
|
581
|
+
return {
|
|
582
|
+
observation: inspected.observation,
|
|
583
|
+
observations: inspected.observations,
|
|
584
|
+
activations: inspected.activations,
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
finally {
|
|
588
|
+
await ownedSession?.dispose();
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
export async function removeCodexPluginActivation(options) {
|
|
592
|
+
await applyConditionalCodexConfigTransactionFile(options.configPath, (snapshot) => Object.hasOwn(snapshot.plugins, options.codexPluginId)
|
|
593
|
+
? { removePluginActivations: [options.codexPluginId] }
|
|
594
|
+
: null);
|
|
595
|
+
}
|
|
596
|
+
export async function removeNamespacedMarketplacePluginProjection(options) {
|
|
597
|
+
if (!await isSafeCodexMarketplaceRoot({
|
|
598
|
+
awHome: resolveAwHome(options.env),
|
|
599
|
+
sourceId: options.sourceId,
|
|
600
|
+
marketplaceRoot: options.rootDir,
|
|
601
|
+
})) {
|
|
602
|
+
throw new Error('marketplaceProjectionUnsafe: marketplace root is outside the canonical AW source path.');
|
|
603
|
+
}
|
|
604
|
+
const root = await readStrictNamespacedMarketplaceRoot({
|
|
605
|
+
rootDir: options.rootDir,
|
|
606
|
+
sourceId: options.sourceId,
|
|
607
|
+
sourceIdentity: options.sourceIdentity,
|
|
862
608
|
});
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
},
|
|
609
|
+
if (!root)
|
|
610
|
+
return;
|
|
611
|
+
const pluginRoot = await assertSafeNamespacedMarketplacePluginRoot(options.rootDir, options.pluginName);
|
|
612
|
+
const pluginStats = await fs.lstat(pluginRoot).catch((error) => {
|
|
613
|
+
if (error.code === 'ENOENT')
|
|
614
|
+
return null;
|
|
615
|
+
throw error;
|
|
871
616
|
});
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
617
|
+
if (pluginStats && (!pluginStats.isDirectory() || pluginStats.isSymbolicLink())) {
|
|
618
|
+
throw new Error('marketplaceProjectionUnsafe: plugin projection is not a regular directory.');
|
|
619
|
+
}
|
|
620
|
+
const manifests = [
|
|
621
|
+
{ value: root.agentsManifest, path: path.join(options.rootDir, '.agents', 'plugins', 'marketplace.json') },
|
|
622
|
+
...(root.claudeManifest
|
|
623
|
+
? [{ value: root.claudeManifest, path: path.join(options.rootDir, '.claude-plugin', 'marketplace.json') }]
|
|
624
|
+
: []),
|
|
625
|
+
];
|
|
626
|
+
const hasEntry = manifests.some(({ value }) => Array.isArray(value.plugins)
|
|
627
|
+
&& value.plugins.some((entry) => entry !== null && typeof entry === 'object'
|
|
628
|
+
&& entry.name === options.pluginName));
|
|
629
|
+
let hasIdentityManifest = false;
|
|
630
|
+
if (pluginStats) {
|
|
631
|
+
for (const manifestName of ['.agents-plugin/plugin.json', '.codex-plugin/plugin.json']) {
|
|
632
|
+
const manifestPath = path.join(pluginRoot, manifestName);
|
|
633
|
+
const manifest = await fs.readJson(manifestPath).catch((error) => {
|
|
634
|
+
if (error.code === 'ENOENT')
|
|
635
|
+
return null;
|
|
878
636
|
throw error;
|
|
879
|
-
|
|
880
|
-
if (
|
|
881
|
-
|
|
637
|
+
});
|
|
638
|
+
if (manifest && manifest.name !== options.pluginName) {
|
|
639
|
+
throw new Error('marketplaceProjectionIdentityMismatch: plugin projection has a foreign name.');
|
|
882
640
|
}
|
|
883
|
-
|
|
884
|
-
});
|
|
885
|
-
const instructionIdentity = expectedIdentity('developer-instructions');
|
|
886
|
-
const instructionOwnerKey = createSharedOwnerToken(instructionIdentity);
|
|
887
|
-
if (config?.snapshot.developerInstructions.managedBlocks[instructionOwnerKey]) {
|
|
888
|
-
output.push(createCodexInstructionComponent({
|
|
889
|
-
identity: instructionIdentity,
|
|
890
|
-
scope: options.scope,
|
|
891
|
-
configPath: options.paths.configTomlPath,
|
|
892
|
-
}));
|
|
641
|
+
hasIdentityManifest ||= manifest?.name === options.pluginName;
|
|
893
642
|
}
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
catch {
|
|
904
|
-
return null;
|
|
643
|
+
if (!hasEntry && !hasIdentityManifest) {
|
|
644
|
+
throw new Error('marketplaceProjectionIdentityUnavailable: plugin directory has no matching marketplace entry or plugin manifest.');
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
if (pluginStats) {
|
|
648
|
+
const inspectTree = async (directory) => {
|
|
649
|
+
for (const entry of await fs.readdir(directory, { withFileTypes: true })) {
|
|
650
|
+
if (entry.isSymbolicLink() || (!entry.isDirectory() && !entry.isFile())) {
|
|
651
|
+
throw new Error('marketplaceProjectionUnsafe: plugin projection contains an unsafe node.');
|
|
905
652
|
}
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
}
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
pluginId: options.pluginId,
|
|
927
|
-
} : {}),
|
|
928
|
-
};
|
|
929
|
-
return settings.awGenerated?.permissions?.[createSharedOwnerToken(identity)]
|
|
930
|
-
? [createClaudePermissionsComponent({ ...options, identity })]
|
|
931
|
-
: [];
|
|
932
|
-
}
|
|
933
|
-
async function scanOwnedTextFiles(options) {
|
|
934
|
-
if (!await fs.pathExists(options.root))
|
|
935
|
-
return [];
|
|
936
|
-
const output = [];
|
|
937
|
-
const pending = [options.root];
|
|
938
|
-
while (pending.length > 0) {
|
|
939
|
-
const current = pending.pop();
|
|
940
|
-
for (const entry of await fs.readdir(current, { withFileTypes: true })) {
|
|
941
|
-
const entryPath = path.join(current, entry.name);
|
|
942
|
-
if (entry.isSymbolicLink())
|
|
943
|
-
continue;
|
|
944
|
-
if (entry.isDirectory()) {
|
|
945
|
-
pending.push(entryPath);
|
|
946
|
-
continue;
|
|
947
|
-
}
|
|
948
|
-
if (!entry.isFile())
|
|
949
|
-
continue;
|
|
950
|
-
const raw = await fs.readFile(entryPath, 'utf8').catch(() => '');
|
|
951
|
-
if (!raw.includes(OWNED_TEXT_HEADER_PREFIX))
|
|
952
|
-
continue;
|
|
953
|
-
let parsed;
|
|
954
|
-
try {
|
|
955
|
-
parsed = parseOwnedTextHeader(raw);
|
|
956
|
-
}
|
|
957
|
-
catch {
|
|
958
|
-
continue;
|
|
959
|
-
}
|
|
960
|
-
if (parsed?.identity.plugin !== options.pluginName
|
|
961
|
-
|| (options.sourceId !== undefined && parsed.identity.sourceId !== options.sourceId)
|
|
962
|
-
|| parsed.identity.platform !== options.platform
|
|
963
|
-
|| parsed.identity.scope !== options.scope)
|
|
964
|
-
continue;
|
|
965
|
-
output.push(pathComponent({
|
|
966
|
-
kind: 'owned-text-file',
|
|
967
|
-
path: entryPath,
|
|
968
|
-
allowedRoot: options.root,
|
|
969
|
-
identity: parsed.identity,
|
|
970
|
-
}));
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
return output;
|
|
974
|
-
}
|
|
975
|
-
async function scanOwnedSkills(options) {
|
|
976
|
-
if (!await fs.pathExists(options.root))
|
|
977
|
-
return [];
|
|
978
|
-
const output = [];
|
|
979
|
-
const pending = [options.root];
|
|
980
|
-
while (pending.length > 0) {
|
|
981
|
-
const current = pending.pop();
|
|
982
|
-
for (const entry of await fs.readdir(current, { withFileTypes: true })) {
|
|
983
|
-
if (!entry.isDirectory() || entry.isSymbolicLink())
|
|
984
|
-
continue;
|
|
985
|
-
const skillRoot = path.join(current, entry.name);
|
|
986
|
-
const marker = await readSkillOwnerMarker({
|
|
987
|
-
skillRoot,
|
|
988
|
-
allowedRoot: current,
|
|
989
|
-
}).catch(() => null);
|
|
990
|
-
if (marker?.plugin === options.pluginName
|
|
991
|
-
&& (options.sourceId === undefined || marker.sourceId === options.sourceId)
|
|
992
|
-
&& marker.platform === options.platform
|
|
993
|
-
&& marker.scope === options.scope) {
|
|
994
|
-
output.push(pathComponent({
|
|
995
|
-
kind: 'skill-directory',
|
|
996
|
-
path: skillRoot,
|
|
997
|
-
allowedRoot: current,
|
|
998
|
-
identity: marker,
|
|
999
|
-
}));
|
|
1000
|
-
continue;
|
|
1001
|
-
}
|
|
1002
|
-
if (options.recursive !== false)
|
|
1003
|
-
pending.push(skillRoot);
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
return output;
|
|
1007
|
-
}
|
|
1008
|
-
function componentIdentityKey(component) {
|
|
1009
|
-
return [
|
|
1010
|
-
component.kind,
|
|
1011
|
-
component.identity.artifactKey,
|
|
1012
|
-
'path' in component ? path.resolve(component.path) : 'label' in component ? component.label : component.pluginId,
|
|
1013
|
-
].join('\0');
|
|
1014
|
-
}
|
|
1015
|
-
function dedupeComponents(components) {
|
|
1016
|
-
const seen = new Set();
|
|
1017
|
-
return components.filter((component) => {
|
|
1018
|
-
const key = componentIdentityKey(component);
|
|
1019
|
-
if (seen.has(key))
|
|
1020
|
-
return false;
|
|
1021
|
-
seen.add(key);
|
|
1022
|
-
return true;
|
|
1023
|
-
});
|
|
1024
|
-
}
|
|
1025
|
-
async function preflightCodexWriteSafety(options) {
|
|
1026
|
-
const pluginName = options.plugin.manifest.name;
|
|
1027
|
-
const userConfigPath = resolveCodexPaths(options.cwd, 'user', options.env).configTomlPath;
|
|
1028
|
-
const projectConfigPath = resolveCodexPaths(options.cwd, 'project', options.env).configTomlPath;
|
|
1029
|
-
const nativeSurface = analyzeCodexSurface(options.plugin.manifest).nativeKinds.length > 0;
|
|
1030
|
-
const needsUserConfig = options.scope === 'user'
|
|
1031
|
-
|| nativeSurface;
|
|
1032
|
-
let userConfig;
|
|
1033
|
-
if (needsUserConfig) {
|
|
1034
|
-
try {
|
|
1035
|
-
userConfig = await readCodexConfigFile(userConfigPath);
|
|
1036
|
-
}
|
|
1037
|
-
catch (error) {
|
|
1038
|
-
throw new Error(`codexProjectUserConfigUnreadable: 无法解析用户级 Codex 配置 ${userConfigPath}:${error instanceof Error ? error.message : String(error)}`);
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
|
-
if (options.scope === 'project' && userConfig) {
|
|
1042
|
-
const expectedPluginId = `${pluginName}@${options.plugin.marketplaceName ?? MARKETPLACE_NAME}`;
|
|
1043
|
-
for (const [key, plugin] of Object.entries(userConfig.snapshot.plugins)) {
|
|
1044
|
-
if (key !== expectedPluginId
|
|
1045
|
-
&& (key === pluginName || key.startsWith(`${pluginName}@`) || plugin.name === pluginName)) {
|
|
1046
|
-
throw new Error(`externalOwnershipPresent: 用户级 Codex 已存在同名外部插件 ${key}。`);
|
|
1047
|
-
}
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
const roleKeys = new Set((options.plugin.manifest.artifacts?.targets ?? [])
|
|
1051
|
-
.filter((target) => target.platform === 'codex'
|
|
1052
|
-
&& target.scopes.includes(options.scope)
|
|
1053
|
-
&& target.target === 'codex.agentRole'
|
|
1054
|
-
&& target.roleKey)
|
|
1055
|
-
.map((target) => target.roleKey));
|
|
1056
|
-
const needsProjectConfig = options.scope === 'project' && Boolean(nativeSurface
|
|
1057
|
-
|| resolvePlatformEntries(options.plugin.manifest.extensions?.instructions, 'codex').length > 0
|
|
1058
|
-
|| (options.plugin.manifest.artifacts?.targets ?? []).some((target) => target.platform === 'codex'
|
|
1059
|
-
&& target.scopes.includes('project')
|
|
1060
|
-
&& (target.target === 'codex.agentRole'
|
|
1061
|
-
|| target.target === 'codex.developerInstructionsBlock')));
|
|
1062
|
-
if (needsProjectConfig) {
|
|
1063
|
-
try {
|
|
1064
|
-
await readCodexConfigFile(projectConfigPath);
|
|
1065
|
-
}
|
|
1066
|
-
catch (error) {
|
|
1067
|
-
throw new Error(`projectConfigUnreadable: 无法解析项目级 Codex 配置 ${projectConfigPath}:${error instanceof Error ? error.message : String(error)}`);
|
|
1068
|
-
}
|
|
1069
|
-
}
|
|
1070
|
-
if (roleKeys.size === 0)
|
|
1071
|
-
return;
|
|
1072
|
-
for (const configPath of options.scope === 'project'
|
|
1073
|
-
? [projectConfigPath]
|
|
1074
|
-
: [userConfigPath]) {
|
|
1075
|
-
const configScope = configPath === userConfigPath ? 'user' : 'project';
|
|
1076
|
-
const ownedRolePaths = [];
|
|
1077
|
-
const ownedRoleKeys = [];
|
|
1078
|
-
for (const roleKey of roleKeys) {
|
|
1079
|
-
const rolePath = path.join(path.dirname(configPath), 'agents', `${buildGeneratedName(pluginName, roleKey)}.toml`);
|
|
1080
|
-
const raw = await fs.readFile(rolePath, 'utf8').catch(() => '');
|
|
1081
|
-
try {
|
|
1082
|
-
if (parseOwnedTextHeader(raw, pluginOwnerIdentity(options.plugin, roleKey, 'codex', configScope))) {
|
|
1083
|
-
ownedRolePaths.push(rolePath);
|
|
1084
|
-
ownedRoleKeys.push(roleKey);
|
|
1085
|
-
}
|
|
1086
|
-
}
|
|
1087
|
-
catch {
|
|
1088
|
-
// A foreign file remains external below.
|
|
1089
|
-
}
|
|
1090
|
-
}
|
|
1091
|
-
let namespace;
|
|
1092
|
-
try {
|
|
1093
|
-
namespace = await resolveCodexRoleNamespace(configPath, {
|
|
1094
|
-
strict: true,
|
|
1095
|
-
awManagedTableKeys: ownedRoleKeys,
|
|
1096
|
-
awManagedRoleLayerPaths: ownedRolePaths,
|
|
1097
|
-
});
|
|
1098
|
-
}
|
|
1099
|
-
catch (error) {
|
|
1100
|
-
throw new Error(`projectConfigUnreadable: 无法读取 Codex role namespace ${configPath}:${error instanceof Error ? error.message : String(error)}`);
|
|
1101
|
-
}
|
|
1102
|
-
for (const roleKey of roleKeys) {
|
|
1103
|
-
const tableCollision = namespace.roles.find((role) => role.source === 'registration' && role.tableKey === roleKey && !role.awManaged);
|
|
1104
|
-
const nameConflict = findCodexRoleNameConflict(namespace, roleKey);
|
|
1105
|
-
if (tableCollision || nameConflict?.conflict) {
|
|
1106
|
-
throw new Error(`roleNameConflict: Codex role "${roleKey}" 已由外部配置占用(${configPath})。`);
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
}
|
|
1111
|
-
function renderCodexRole(options) {
|
|
1112
|
-
const stringValue = (value) => JSON.stringify(value.trim());
|
|
1113
|
-
return [
|
|
1114
|
-
`name = ${stringValue(options.roleKey)}`,
|
|
1115
|
-
`description = ${stringValue(options.description)}`,
|
|
1116
|
-
`developer_instructions = ${JSON.stringify(options.developerInstructions)}`,
|
|
1117
|
-
...(options.model ? [`model = ${stringValue(options.model)}`] : []),
|
|
1118
|
-
...(options.modelReasoningEffort
|
|
1119
|
-
? [`model_reasoning_effort = ${stringValue(options.modelReasoningEffort)}`]
|
|
1120
|
-
: []),
|
|
1121
|
-
'',
|
|
1122
|
-
].join('\n');
|
|
1123
|
-
}
|
|
1124
|
-
async function resolveDynamicArtifacts(options) {
|
|
1125
|
-
const preparedArtifacts = options.context
|
|
1126
|
-
? await prepareStaticCommandArtifacts({ ...options, context: options.context }) : [];
|
|
1127
|
-
const preparedIds = new Set(preparedArtifacts.map((artifact) => artifact.id));
|
|
1128
|
-
const requestBatches = (options.requestedArtifactIds
|
|
1129
|
-
? [options.requestedArtifactIds]
|
|
1130
|
-
: resolveAwDeliveredArtifactRequestBatches({
|
|
1131
|
-
manifest: options.plugin.manifest,
|
|
1132
|
-
platform: options.platform,
|
|
1133
|
-
scope: options.scope,
|
|
1134
|
-
})).map((batch) => batch.filter((id) => !preparedIds.has(id))).filter((batch) => batch.length > 0);
|
|
1135
|
-
if (requestBatches.length === 0 && preparedArtifacts.length === 0) {
|
|
1136
|
-
return { artifacts: [], sourceDirs: () => [], sensitiveValues: [] };
|
|
1137
|
-
}
|
|
1138
|
-
const previousArtifacts = [...options.previousArtifacts];
|
|
1139
|
-
const preparedResults = options.context && artifactRenderResults(options.context);
|
|
1140
|
-
const renders = [];
|
|
1141
|
-
for (const requestedArtifactIds of requestBatches) {
|
|
1142
|
-
renders.push(await runArtifactRenderer({
|
|
1143
|
-
event: options.event,
|
|
1144
|
-
plugin: options.plugin,
|
|
1145
|
-
referencePlugins: options.referencePlugins ?? options.context?.referencePlugins,
|
|
1146
|
-
platform: options.platform,
|
|
1147
|
-
scope: options.scope,
|
|
1148
|
-
cwd: options.cwd,
|
|
1149
|
-
commandEnv: options.env,
|
|
1150
|
-
previousArtifacts,
|
|
1151
|
-
requestedArtifactIds,
|
|
1152
|
-
scriptTimeoutMs: options.scriptTimeoutMs,
|
|
1153
|
-
signal: options.signal,
|
|
1154
|
-
preparedResults,
|
|
1155
|
-
}));
|
|
1156
|
-
}
|
|
1157
|
-
const config = await resolveArtifactRenderConfig({
|
|
1158
|
-
sourceId: options.plugin.sourceId,
|
|
1159
|
-
sourceIdentity: options.plugin.sourceIdentity,
|
|
1160
|
-
logicalIdentity: options.plugin.catalogLogicalIdentity,
|
|
1161
|
-
pluginName: options.plugin.manifest.name,
|
|
1162
|
-
manifest: options.plugin.manifest,
|
|
1163
|
-
platform: options.platform,
|
|
1164
|
-
referencePlugins: options.referencePlugins ?? options.context?.referencePlugins,
|
|
1165
|
-
scope: options.scope,
|
|
1166
|
-
cwd: options.cwd,
|
|
1167
|
-
env: options.env,
|
|
1168
|
-
});
|
|
1169
|
-
const artifacts = [...preparedArtifacts];
|
|
1170
|
-
const sourceDirsByArtifact = new Map();
|
|
1171
|
-
for (const render of renders) {
|
|
1172
|
-
artifacts.push(...validateArtifactPlan({
|
|
1173
|
-
manifest: options.plugin.manifest,
|
|
1174
|
-
plan: render.plan,
|
|
1175
|
-
platform: options.platform,
|
|
1176
|
-
scope: options.scope,
|
|
1177
|
-
requestedArtifactIds: render.context.requestedArtifactIds,
|
|
1178
|
-
renderConfig: config,
|
|
1179
|
-
rendererDigest: render.target.rendererDigest,
|
|
1180
|
-
manifestDigest: render.target.manifestDigest,
|
|
1181
|
-
}).artifacts);
|
|
1182
|
-
for (const source of render.context.artifactSources) {
|
|
1183
|
-
sourceDirsByArtifact.set(`${source.id}\0${source.target}`, source.sourceDirs);
|
|
1184
|
-
}
|
|
1185
|
-
}
|
|
1186
|
-
return {
|
|
1187
|
-
artifacts,
|
|
1188
|
-
runtimeConfigSnapshots: Object.assign({}, ...renders.map((render) => render.runtimeConfigSnapshots)),
|
|
1189
|
-
sourceDirs: (artifact) => sourceDirsByArtifact.get(`${artifact.id}\0${artifact.target}`) ?? [],
|
|
1190
|
-
sensitiveValues: collectSensitivePluginConfigValues(options.plugin.manifest, config.values, options.platform),
|
|
1191
|
-
};
|
|
1192
|
-
}
|
|
1193
|
-
async function buildClaudeWrites(options) {
|
|
1194
|
-
const paths = resolveClaudePaths(options.cwd, options.scope, options.env);
|
|
1195
|
-
const writes = [];
|
|
1196
|
-
const dynamic = await resolveDynamicArtifacts({
|
|
1197
|
-
...options,
|
|
1198
|
-
platform: 'claude',
|
|
1199
|
-
previousArtifacts: options.historicalArtifacts,
|
|
1200
|
-
});
|
|
1201
|
-
const commandCandidates = [...(options.commandCandidates ?? [])];
|
|
1202
|
-
const staticSkills = await prepareStaticNativeSkillActions({ ...options, platform: 'claude', artifacts: dynamic.artifacts, commandCandidates });
|
|
1203
|
-
commandCandidates.push(...staticSkills.candidates);
|
|
1204
|
-
options.nativeSkillActions?.push(...staticSkills.actions);
|
|
1205
|
-
const commandResolver = await createManagedCommandReferenceResolver({ ...options, platform: 'claude', candidates: commandCandidates });
|
|
1206
|
-
for (const artifact of generateInstructionArtifacts(options.plugin.manifest.name, resolvePlatformEntries(options.plugin.manifest.extensions?.instructions, 'claude'), 'claude')) {
|
|
1207
|
-
writes.push(generatedTextWrite({
|
|
1208
|
-
...options,
|
|
1209
|
-
platform: 'claude',
|
|
1210
|
-
configDir: paths.configDir,
|
|
1211
|
-
relativePath: artifact.relativePath,
|
|
1212
|
-
artifactKey: artifact.artifactKey,
|
|
1213
|
-
content: artifact.content,
|
|
1214
|
-
kind: 'instruction',
|
|
1215
|
-
}));
|
|
1216
|
-
}
|
|
1217
|
-
const permissions = resolvePlatformEntries(options.plugin.manifest.extensions?.permissions, 'claude');
|
|
1218
|
-
if (permissions.length > 0) {
|
|
1219
|
-
const component = createClaudePermissionsComponent({
|
|
1220
|
-
identity: pluginOwnerIdentity(options.plugin, 'permissions', 'claude', options.scope),
|
|
1221
|
-
scope: options.scope,
|
|
1222
|
-
settingsPath: paths.settingsPath,
|
|
1223
|
-
});
|
|
1224
|
-
const desiredPermissions = mergeClaudePermissions(permissions, commandResolver);
|
|
1225
|
-
const mutation = { kind: 'claude-permissions', permissions: desiredPermissions };
|
|
1226
|
-
writes.push({
|
|
1227
|
-
artifact: { path: paths.settingsPath, kind: 'permission', platform: 'claude' },
|
|
1228
|
-
component,
|
|
1229
|
-
action: {
|
|
1230
|
-
kind: 'updateSharedConfig',
|
|
1231
|
-
pluginId: pluginActionId(options.plugin),
|
|
1232
|
-
platform: 'claude',
|
|
1233
|
-
scope: options.scope,
|
|
1234
|
-
owner: component.identity,
|
|
1235
|
-
locator: component.locator,
|
|
1236
|
-
mutation,
|
|
1237
|
-
contentDigest: `sha256:${crypto.createHash('sha256').update(JSON.stringify(mutation)).digest('hex')}`,
|
|
1238
|
-
},
|
|
1239
|
-
});
|
|
1240
|
-
}
|
|
1241
|
-
return writes;
|
|
1242
|
-
}
|
|
1243
|
-
async function buildCodexWrites(options) {
|
|
1244
|
-
const paths = resolveCodexPaths(options.cwd, options.scope, options.env);
|
|
1245
|
-
const writes = [];
|
|
1246
|
-
const dynamic = await resolveDynamicArtifacts({
|
|
1247
|
-
...options,
|
|
1248
|
-
platform: 'codex',
|
|
1249
|
-
previousArtifacts: options.historicalArtifacts,
|
|
1250
|
-
});
|
|
1251
|
-
const dynamicInstructions = dynamic.artifacts.filter((entry) => entry.target === 'codex.developerInstructionsBlock');
|
|
1252
|
-
const dynamicRoles = dynamic.artifacts.filter((entry) => entry.target === 'codex.agentRole');
|
|
1253
|
-
const commandCandidates = [...(options.commandCandidates ?? [])];
|
|
1254
|
-
const staticSkills = await prepareStaticNativeSkillActions({ ...options, platform: 'codex', artifacts: dynamic.artifacts, commandCandidates });
|
|
1255
|
-
commandCandidates.push(...staticSkills.candidates);
|
|
1256
|
-
options.nativeSkillActions?.push(...staticSkills.actions);
|
|
1257
|
-
const commandResolver = await createManagedCommandReferenceResolver({ ...options, platform: 'codex', candidates: commandCandidates });
|
|
1258
|
-
const staticInstructions = dynamicInstructions.length > 0
|
|
1259
|
-
? []
|
|
1260
|
-
: resolvePlatformEntries(options.plugin.manifest.extensions?.instructions, 'codex');
|
|
1261
|
-
const hasInstructionOutput = dynamicInstructions.length > 0 || staticInstructions.length > 0;
|
|
1262
|
-
if (hasInstructionOutput) {
|
|
1263
|
-
const component = createCodexInstructionComponent({
|
|
1264
|
-
identity: pluginOwnerIdentity(options.plugin, 'developer-instructions', 'codex', options.scope),
|
|
1265
|
-
scope: options.scope,
|
|
1266
|
-
configPath: paths.configTomlPath,
|
|
1267
|
-
});
|
|
1268
|
-
const dynamicBlock = dynamicInstructions.length > 0
|
|
1269
|
-
? composeManagedDeveloperInstructionsBlock(options.plugin.manifest.name, dynamicInstructions
|
|
1270
|
-
.filter((entry) => entry.state === 'present')
|
|
1271
|
-
.map((entry) => ({ artifactId: entry.id, value: entry.content })))
|
|
1272
|
-
: undefined;
|
|
1273
|
-
const block = dynamicBlock?.value
|
|
1274
|
-
? { ...dynamicBlock, pluginName: createSharedOwnerToken(component.identity) }
|
|
1275
|
-
: staticInstructions.length > 0
|
|
1276
|
-
? {
|
|
1277
|
-
pluginName: createSharedOwnerToken(component.identity),
|
|
1278
|
-
value: renderCodexManagedInstructionBlock(options.plugin.manifest.name, staticInstructions),
|
|
1279
|
-
}
|
|
1280
|
-
: undefined;
|
|
1281
|
-
const instructionMutation = { kind: 'codex-instruction', ...(block ? { block } : {}) };
|
|
1282
|
-
for (const artifact of dynamicInstructions.length > 0 ? dynamicInstructions : [{
|
|
1283
|
-
id: undefined,
|
|
1284
|
-
target: undefined,
|
|
1285
|
-
state: 'present',
|
|
1286
|
-
refreshKeys: [],
|
|
1287
|
-
configDigest: undefined,
|
|
1288
|
-
disabledReason: undefined,
|
|
1289
|
-
}]) {
|
|
1290
|
-
writes.push({
|
|
1291
|
-
artifact: {
|
|
1292
|
-
path: paths.configTomlPath,
|
|
1293
|
-
kind: 'instruction',
|
|
1294
|
-
platform: 'codex',
|
|
1295
|
-
...(artifact.id ? { id: artifact.id } : {}),
|
|
1296
|
-
...(artifact.target ? { target: artifact.target } : {}),
|
|
1297
|
-
state: artifact.state,
|
|
1298
|
-
refreshKeys: [...artifact.refreshKeys],
|
|
1299
|
-
...(artifact.configDigest ? { configDigest: artifact.configDigest } : {}),
|
|
1300
|
-
...(artifact.disabledReason ? { disabledReason: artifact.disabledReason } : {}),
|
|
1301
|
-
},
|
|
1302
|
-
...(block ? { component } : {}),
|
|
1303
|
-
action: {
|
|
1304
|
-
kind: 'updateSharedConfig',
|
|
1305
|
-
pluginId: pluginActionId(options.plugin),
|
|
1306
|
-
platform: 'codex',
|
|
1307
|
-
scope: options.scope,
|
|
1308
|
-
owner: component.identity,
|
|
1309
|
-
locator: component.locator,
|
|
1310
|
-
mutation: instructionMutation,
|
|
1311
|
-
contentDigest: `sha256:${crypto.createHash('sha256')
|
|
1312
|
-
.update(JSON.stringify(instructionMutation)).digest('hex')}`,
|
|
1313
|
-
},
|
|
1314
|
-
});
|
|
1315
|
-
}
|
|
1316
|
-
}
|
|
1317
|
-
for (const artifact of dynamicRoles) {
|
|
1318
|
-
const roleKey = artifact.roleKey;
|
|
1319
|
-
const rolePath = path.join(paths.configDir, 'agents', `${buildGeneratedName(options.plugin.manifest.name, roleKey)}.toml`);
|
|
1320
|
-
const roleComponent = pathComponent({
|
|
1321
|
-
kind: 'owned-text-file',
|
|
1322
|
-
path: rolePath,
|
|
1323
|
-
allowedRoot: paths.configDir,
|
|
1324
|
-
identity: pluginOwnerIdentity(options.plugin, roleKey, 'codex', options.scope),
|
|
1325
|
-
});
|
|
1326
|
-
const registrationComponent = createCodexRoleRegistrationComponent({
|
|
1327
|
-
identity: pluginOwnerIdentity(options.plugin, internalArtifactKey('role', roleKey), 'codex', options.scope),
|
|
1328
|
-
fileIdentity: roleComponent.identity,
|
|
1329
|
-
configPath: paths.configTomlPath,
|
|
1330
|
-
roleKey,
|
|
1331
|
-
rolePath,
|
|
1332
|
-
});
|
|
1333
|
-
const roleFile = artifact.content?.roleFile;
|
|
1334
|
-
const description = artifact.content?.registration?.description
|
|
1335
|
-
?? roleFile?.description;
|
|
1336
|
-
const present = artifact.state === 'present';
|
|
1337
|
-
if (present && (!description || !roleFile?.developer_instructions)) {
|
|
1338
|
-
throw new Error(`Artifact "${artifact.id}" 的 codex.agentRole 缺少 description 或 developer_instructions。`);
|
|
1339
|
-
}
|
|
1340
|
-
writes.push({
|
|
1341
|
-
artifact: {
|
|
1342
|
-
path: rolePath,
|
|
1343
|
-
paths: [paths.configTomlPath, rolePath],
|
|
1344
|
-
kind: 'agent',
|
|
1345
|
-
platform: 'codex',
|
|
1346
|
-
artifactKey: roleKey,
|
|
1347
|
-
roleKey,
|
|
1348
|
-
id: artifact.id,
|
|
1349
|
-
target: artifact.target,
|
|
1350
|
-
state: artifact.state,
|
|
1351
|
-
refreshKeys: [...artifact.refreshKeys],
|
|
1352
|
-
configDigest: artifact.configDigest,
|
|
1353
|
-
...(artifact.disabledReason ? { disabledReason: artifact.disabledReason } : {}),
|
|
1354
|
-
},
|
|
1355
|
-
...(present ? { component: roleComponent } : {}),
|
|
1356
|
-
...(present ? { additionalComponents: [registrationComponent] } : {}),
|
|
1357
|
-
...(present ? {
|
|
1358
|
-
action: (() => {
|
|
1359
|
-
const content = renderCodexRole({
|
|
1360
|
-
roleKey,
|
|
1361
|
-
description: description,
|
|
1362
|
-
developerInstructions: roleFile.developer_instructions,
|
|
1363
|
-
model: roleFile.model,
|
|
1364
|
-
modelReasoningEffort: roleFile.model_reasoning_effort,
|
|
1365
|
-
});
|
|
1366
|
-
return {
|
|
1367
|
-
kind: 'writeOwnedArtifact',
|
|
1368
|
-
pluginId: pluginActionId(options.plugin),
|
|
1369
|
-
platform: 'codex',
|
|
1370
|
-
scope: options.scope,
|
|
1371
|
-
path: rolePath,
|
|
1372
|
-
allowedRoot: paths.configDir,
|
|
1373
|
-
owner: roleComponent.identity,
|
|
1374
|
-
artifactKind: 'owned-text-file',
|
|
1375
|
-
sourceContent: content,
|
|
1376
|
-
content,
|
|
1377
|
-
contentDigest: `sha256:${crypto.createHash('sha256').update(content).digest('hex')}`,
|
|
1378
|
-
};
|
|
1379
|
-
})(),
|
|
1380
|
-
} : {}),
|
|
1381
|
-
...(present ? {
|
|
1382
|
-
additionalActions: [(() => {
|
|
1383
|
-
const mutation = {
|
|
1384
|
-
kind: 'codex-role-registration',
|
|
1385
|
-
roleKey,
|
|
1386
|
-
configFile: path.relative(path.dirname(paths.configTomlPath), rolePath),
|
|
1387
|
-
description: description,
|
|
1388
|
-
};
|
|
1389
|
-
return {
|
|
1390
|
-
kind: 'updateSharedConfig',
|
|
1391
|
-
pluginId: pluginActionId(options.plugin),
|
|
1392
|
-
platform: 'codex',
|
|
1393
|
-
scope: options.scope,
|
|
1394
|
-
owner: registrationComponent.identity,
|
|
1395
|
-
locator: registrationComponent.locator,
|
|
1396
|
-
mutation,
|
|
1397
|
-
contentDigest: `sha256:${crypto.createHash('sha256')
|
|
1398
|
-
.update(JSON.stringify(mutation)).digest('hex')}`,
|
|
1399
|
-
};
|
|
1400
|
-
})()],
|
|
1401
|
-
} : {}),
|
|
1402
|
-
});
|
|
1403
|
-
}
|
|
1404
|
-
for (const artifact of generateCodexPermissionArtifacts(options.plugin.manifest.name, resolvePlatformEntries(options.plugin.manifest.extensions?.permissions, 'codex'), commandResolver)) {
|
|
1405
|
-
writes.push(generatedTextWrite({
|
|
1406
|
-
...options,
|
|
1407
|
-
platform: 'codex',
|
|
1408
|
-
configDir: paths.configDir,
|
|
1409
|
-
relativePath: artifact.relativePath,
|
|
1410
|
-
artifactKey: artifact.artifactKey,
|
|
1411
|
-
content: artifact.content,
|
|
1412
|
-
kind: 'permission',
|
|
1413
|
-
}));
|
|
1414
|
-
}
|
|
1415
|
-
for (const artifact of generateAgentArtifacts(options.plugin.manifest.name, resolvePlatformEntries(options.plugin.manifest.extensions?.agents, 'codex'), 'codex')) {
|
|
1416
|
-
writes.push(generatedTextWrite({
|
|
1417
|
-
...options,
|
|
1418
|
-
platform: 'codex',
|
|
1419
|
-
configDir: paths.configDir,
|
|
1420
|
-
relativePath: artifact.relativePath,
|
|
1421
|
-
artifactKey: artifact.artifactKey,
|
|
1422
|
-
content: artifact.content,
|
|
1423
|
-
kind: 'agent',
|
|
1424
|
-
}));
|
|
1425
|
-
}
|
|
1426
|
-
const codexPluginId = `${options.plugin.manifest.name}@${options.marketplaceName ?? options.plugin.marketplaceName ?? MARKETPLACE_NAME}`;
|
|
1427
|
-
const nativeSurface = analyzeCodexSurface(options.plugin.manifest).nativeKinds.length > 0;
|
|
1428
|
-
const userActivationDesired = options.scope === 'user'
|
|
1429
|
-
|| options.userActivationDesired?.has(codexPluginId) === true;
|
|
1430
|
-
for (const activation of !nativeSurface ? [] : options.scope === 'project'
|
|
1431
|
-
? [
|
|
1432
|
-
{
|
|
1433
|
-
scope: 'user',
|
|
1434
|
-
desired: userActivationDesired,
|
|
1435
|
-
configPath: resolveCodexPaths(options.cwd, 'user', options.env).configTomlPath,
|
|
1436
|
-
},
|
|
1437
|
-
{ scope: 'project', desired: true, configPath: paths.configTomlPath },
|
|
1438
|
-
]
|
|
1439
|
-
: [{ scope: 'user', desired: true, configPath: paths.configTomlPath }]) {
|
|
1440
|
-
const component = createCodexActivationComponent({
|
|
1441
|
-
identity: pluginOwnerIdentity(options.plugin, internalArtifactKey('activation', activation.scope), 'codex', options.scope),
|
|
1442
|
-
configPath: activation.configPath,
|
|
1443
|
-
codexPluginId,
|
|
1444
|
-
desired: activation.desired,
|
|
1445
|
-
});
|
|
1446
|
-
writes.push({
|
|
1447
|
-
artifact: {
|
|
1448
|
-
path: activation.configPath,
|
|
1449
|
-
kind: 'instruction',
|
|
1450
|
-
platform: 'codex',
|
|
1451
|
-
artifactKey: internalArtifactKey('activation', activation.scope),
|
|
1452
|
-
},
|
|
1453
|
-
component,
|
|
1454
|
-
action: {
|
|
1455
|
-
kind: 'setActivation',
|
|
1456
|
-
pluginId: pluginActionId(options.plugin),
|
|
1457
|
-
platform: 'codex',
|
|
1458
|
-
scope: activation.scope,
|
|
1459
|
-
enabled: activation.desired,
|
|
1460
|
-
configPath: activation.configPath,
|
|
1461
|
-
registration: codexPluginId,
|
|
1462
|
-
},
|
|
1463
|
-
});
|
|
1464
|
-
}
|
|
1465
|
-
return writes;
|
|
1466
|
-
}
|
|
1467
|
-
async function buildInspectionWrites(options) {
|
|
1468
|
-
const writes = [];
|
|
1469
|
-
if (options.platform === 'claude') {
|
|
1470
|
-
const paths = resolveClaudePaths(options.cwd, options.scope, options.env);
|
|
1471
|
-
for (const artifact of generateInstructionArtifacts(options.plugin.manifest.name, resolvePlatformEntries(options.plugin.manifest.extensions?.instructions, 'claude'), 'claude')) {
|
|
1472
|
-
writes.push(generatedTextWrite({
|
|
1473
|
-
...options,
|
|
1474
|
-
configDir: paths.configDir,
|
|
1475
|
-
relativePath: artifact.relativePath,
|
|
1476
|
-
artifactKey: artifact.artifactKey,
|
|
1477
|
-
content: artifact.content,
|
|
1478
|
-
kind: 'instruction',
|
|
1479
|
-
}));
|
|
1480
|
-
}
|
|
1481
|
-
if (resolvePlatformEntries(options.plugin.manifest.extensions?.permissions, 'claude').length > 0) {
|
|
1482
|
-
writes.push({
|
|
1483
|
-
artifact: { path: paths.settingsPath, kind: 'permission', platform: 'claude' },
|
|
1484
|
-
component: createClaudePermissionsComponent({
|
|
1485
|
-
identity: pluginOwnerIdentity(options.plugin, 'permissions', 'claude', options.scope),
|
|
1486
|
-
scope: options.scope,
|
|
1487
|
-
settingsPath: paths.settingsPath,
|
|
1488
|
-
}),
|
|
1489
|
-
});
|
|
1490
|
-
}
|
|
1491
|
-
return writes;
|
|
1492
|
-
}
|
|
1493
|
-
const paths = resolveCodexPaths(options.cwd, options.scope, options.env);
|
|
1494
|
-
const instructions = resolvePlatformEntries(options.plugin.manifest.extensions?.instructions, 'codex');
|
|
1495
|
-
const targets = (options.plugin.manifest.artifacts?.targets ?? []).filter((target) => target.platform === 'codex' && target.scopes.includes(options.scope));
|
|
1496
|
-
const instructionTargets = targets.filter((target) => target.target === 'codex.developerInstructionsBlock');
|
|
1497
|
-
const presentCapableInstructionTargets = instructionTargets.filter((target) => target.states.includes('present'));
|
|
1498
|
-
const instructionDesired = presentCapableInstructionTargets.length > 0;
|
|
1499
|
-
const instructionOptional = presentCapableInstructionTargets.length > 0
|
|
1500
|
-
&& presentCapableInstructionTargets.every((target) => target.states.includes('disabled'));
|
|
1501
|
-
if (instructions.length > 0 || instructionDesired) {
|
|
1502
|
-
writes.push({
|
|
1503
|
-
artifact: { path: paths.configTomlPath, kind: 'instruction', platform: 'codex' },
|
|
1504
|
-
component: createCodexInstructionComponent({
|
|
1505
|
-
identity: pluginOwnerIdentity(options.plugin, 'developer-instructions', 'codex', options.scope),
|
|
1506
|
-
scope: options.scope,
|
|
1507
|
-
configPath: paths.configTomlPath,
|
|
1508
|
-
}),
|
|
1509
|
-
...(instructions.length === 0 && instructionOptional ? { optional: true } : {}),
|
|
1510
|
-
});
|
|
1511
|
-
}
|
|
1512
|
-
for (const target of targets) {
|
|
1513
|
-
const state = target.states.includes('present') ? 'present' : 'disabled';
|
|
1514
|
-
if (target.target === 'codex.agentRole' && target.roleKey) {
|
|
1515
|
-
const rolePath = path.join(paths.configDir, 'agents', `${buildGeneratedName(options.plugin.manifest.name, target.roleKey)}.toml`);
|
|
1516
|
-
const roleComponent = pathComponent({
|
|
1517
|
-
kind: 'owned-text-file',
|
|
1518
|
-
path: rolePath,
|
|
1519
|
-
allowedRoot: paths.configDir,
|
|
1520
|
-
identity: pluginOwnerIdentity(options.plugin, target.roleKey, 'codex', options.scope),
|
|
1521
|
-
});
|
|
1522
|
-
const registrationComponent = createCodexRoleRegistrationComponent({
|
|
1523
|
-
identity: pluginOwnerIdentity(options.plugin, internalArtifactKey('role', target.roleKey), 'codex', options.scope),
|
|
1524
|
-
fileIdentity: pluginOwnerIdentity(options.plugin, target.roleKey, 'codex', options.scope),
|
|
1525
|
-
configPath: paths.configTomlPath,
|
|
1526
|
-
roleKey: target.roleKey,
|
|
1527
|
-
rolePath,
|
|
1528
|
-
});
|
|
1529
|
-
writes.push({
|
|
1530
|
-
artifact: {
|
|
1531
|
-
path: rolePath,
|
|
1532
|
-
kind: 'agent',
|
|
1533
|
-
platform: 'codex',
|
|
1534
|
-
artifactKey: target.roleKey,
|
|
1535
|
-
roleKey: target.roleKey,
|
|
1536
|
-
id: target.id,
|
|
1537
|
-
target: target.target,
|
|
1538
|
-
state,
|
|
1539
|
-
},
|
|
1540
|
-
...(state === 'present'
|
|
1541
|
-
? { component: roleComponent, additionalComponents: [registrationComponent] }
|
|
1542
|
-
: {}),
|
|
1543
|
-
...(target.states.includes('present') && target.states.includes('disabled')
|
|
1544
|
-
? { optional: true }
|
|
1545
|
-
: {}),
|
|
1546
|
-
});
|
|
1547
|
-
}
|
|
1548
|
-
}
|
|
1549
|
-
for (const permission of resolvePlatformEntries(options.plugin.manifest.extensions?.permissions, 'codex')) {
|
|
1550
|
-
const artifactKey = buildGeneratedName(options.plugin.manifest.name, permission.name);
|
|
1551
|
-
const artifactPath = path.join(paths.configDir, 'rules', `${artifactKey}.rules`);
|
|
1552
|
-
writes.push({
|
|
1553
|
-
artifact: { path: artifactPath, kind: 'permission', platform: 'codex', artifactKey },
|
|
1554
|
-
component: pathComponent({
|
|
1555
|
-
kind: 'owned-text-file', path: artifactPath, allowedRoot: paths.configDir,
|
|
1556
|
-
identity: ownerIdentity(options.plugin.manifest.name, artifactKey, 'codex', options.scope),
|
|
1557
|
-
}),
|
|
1558
|
-
});
|
|
1559
|
-
}
|
|
1560
|
-
for (const artifact of generateAgentArtifacts(options.plugin.manifest.name, resolvePlatformEntries(options.plugin.manifest.extensions?.agents, 'codex'), 'codex')) {
|
|
1561
|
-
writes.push(generatedTextWrite({
|
|
1562
|
-
...options,
|
|
1563
|
-
configDir: paths.configDir,
|
|
1564
|
-
relativePath: artifact.relativePath,
|
|
1565
|
-
artifactKey: artifact.artifactKey,
|
|
1566
|
-
content: artifact.content,
|
|
1567
|
-
kind: 'agent',
|
|
1568
|
-
}));
|
|
1569
|
-
}
|
|
1570
|
-
const nativeSurface = analyzeCodexSurface(options.plugin.manifest).nativeKinds.length > 0;
|
|
1571
|
-
const codexPluginId = `${options.plugin.manifest.name}@${options.marketplaceName ?? options.plugin.marketplaceName ?? MARKETPLACE_NAME}`;
|
|
1572
|
-
const userActivationDesired = options.scope === 'user'
|
|
1573
|
-
|| options.userActivationDesired?.has(codexPluginId) === true;
|
|
1574
|
-
for (const activation of !nativeSurface ? [] : options.scope === 'project'
|
|
1575
|
-
? [
|
|
1576
|
-
{
|
|
1577
|
-
scope: 'user',
|
|
1578
|
-
desired: userActivationDesired,
|
|
1579
|
-
configPath: resolveCodexPaths(options.cwd, 'user', options.env).configTomlPath,
|
|
1580
|
-
},
|
|
1581
|
-
{ scope: 'project', desired: true, configPath: paths.configTomlPath },
|
|
1582
|
-
]
|
|
1583
|
-
: [{ scope: 'user', desired: true, configPath: paths.configTomlPath }]) {
|
|
1584
|
-
writes.push({
|
|
1585
|
-
artifact: {
|
|
1586
|
-
path: activation.configPath,
|
|
1587
|
-
kind: 'instruction',
|
|
1588
|
-
platform: 'codex',
|
|
1589
|
-
artifactKey: internalArtifactKey('activation', activation.scope),
|
|
1590
|
-
},
|
|
1591
|
-
component: createCodexActivationComponent({
|
|
1592
|
-
identity: pluginOwnerIdentity(options.plugin, internalArtifactKey('activation', activation.scope), 'codex', options.scope),
|
|
1593
|
-
configPath: activation.configPath,
|
|
1594
|
-
codexPluginId,
|
|
1595
|
-
desired: activation.desired,
|
|
1596
|
-
}),
|
|
1597
|
-
});
|
|
1598
|
-
}
|
|
1599
|
-
return writes;
|
|
1600
|
-
}
|
|
1601
|
-
async function buildHistoricalComponents(options) {
|
|
1602
|
-
const components = [];
|
|
1603
|
-
const paths = options.platform === 'codex'
|
|
1604
|
-
? resolveCodexPaths(options.cwd, options.scope, options.env)
|
|
1605
|
-
: resolveClaudePaths(options.cwd, options.scope, options.env);
|
|
1606
|
-
const historicalIdentity = (artifactKey) => ({
|
|
1607
|
-
...ownerIdentity(options.pluginName, artifactKey, options.platform, options.scope),
|
|
1608
|
-
...(options.sourceId ? {
|
|
1609
|
-
sourceId: options.sourceId,
|
|
1610
|
-
pluginId: options.pluginId,
|
|
1611
|
-
} : {}),
|
|
1612
|
-
});
|
|
1613
|
-
for (const artifact of options.artifacts) {
|
|
1614
|
-
if (artifact.platform !== options.platform)
|
|
1615
|
-
continue;
|
|
1616
|
-
if (artifact.state === 'disabled')
|
|
1617
|
-
continue;
|
|
1618
|
-
if (options.platform === 'codex'
|
|
1619
|
-
&& artifact.artifactKey !== undefined
|
|
1620
|
-
&& new Set([
|
|
1621
|
-
internalArtifactKey('activation', 'user'),
|
|
1622
|
-
internalArtifactKey('activation', 'project'),
|
|
1623
|
-
]).has(artifact.artifactKey)) {
|
|
1624
|
-
continue;
|
|
1625
|
-
}
|
|
1626
|
-
if (options.command === 'cleanup'
|
|
1627
|
-
&& artifact.kind === 'hook'
|
|
1628
|
-
&& options.platform === 'codex') {
|
|
1629
|
-
for (const identity of artifact.hookGroups ?? []) {
|
|
1630
|
-
components.push(createLegacyCodexHookCleanupComponent({
|
|
1631
|
-
pluginName: options.pluginName,
|
|
1632
|
-
scope: options.scope,
|
|
1633
|
-
hooksPath: path.join(resolveCodexPaths(options.cwd, options.scope, options.env).configDir, 'hooks.json'),
|
|
1634
|
-
identity,
|
|
1635
|
-
}));
|
|
1636
|
-
}
|
|
1637
|
-
continue;
|
|
1638
|
-
}
|
|
1639
|
-
if (options.command === 'cleanup'
|
|
1640
|
-
&& artifact.kind === 'mcpServer'
|
|
1641
|
-
&& options.platform === 'codex'
|
|
1642
|
-
&& artifact.artifactKey) {
|
|
1643
|
-
components.push(createLegacyCodexMcpCleanupComponent({
|
|
1644
|
-
identity: historicalIdentity(internalArtifactKey('mcp', artifact.artifactKey)),
|
|
1645
|
-
configPath: resolveCodexPaths(options.cwd, options.scope, options.env).configTomlPath,
|
|
1646
|
-
serverKey: artifact.artifactKey,
|
|
1647
|
-
}));
|
|
1648
|
-
continue;
|
|
1649
|
-
}
|
|
1650
|
-
if (artifact.kind === 'instruction' && options.platform === 'codex' && !artifact.artifactKey) {
|
|
1651
|
-
components.push(createCodexInstructionComponent({
|
|
1652
|
-
identity: historicalIdentity('developer-instructions'),
|
|
1653
|
-
scope: options.scope,
|
|
1654
|
-
configPath: resolveCodexPaths(options.cwd, options.scope, options.env).configTomlPath,
|
|
1655
|
-
}));
|
|
1656
|
-
continue;
|
|
1657
|
-
}
|
|
1658
|
-
if (artifact.kind === 'permission' && options.platform === 'claude') {
|
|
1659
|
-
components.push(createClaudePermissionsComponent({
|
|
1660
|
-
identity: historicalIdentity('permissions'),
|
|
1661
|
-
scope: options.scope,
|
|
1662
|
-
settingsPath: resolveClaudePaths(options.cwd, options.scope, options.env).settingsPath,
|
|
1663
|
-
}));
|
|
1664
|
-
continue;
|
|
1665
|
-
}
|
|
1666
|
-
if (artifact.target === 'codex.agentRole'
|
|
1667
|
-
&& options.platform === 'codex'
|
|
1668
|
-
&& (artifact.roleKey || artifact.artifactKey)) {
|
|
1669
|
-
const roleKey = artifact.roleKey ?? artifact.artifactKey;
|
|
1670
|
-
components.push(createCodexRoleRegistrationComponent({
|
|
1671
|
-
identity: historicalIdentity(internalArtifactKey('role', roleKey)),
|
|
1672
|
-
fileIdentity: historicalIdentity(roleKey),
|
|
1673
|
-
configPath: resolveCodexPaths(options.cwd, options.scope, options.env).configTomlPath,
|
|
1674
|
-
roleKey,
|
|
1675
|
-
rolePath: artifact.path,
|
|
1676
|
-
}));
|
|
1677
|
-
}
|
|
1678
|
-
if (!artifact.artifactKey)
|
|
1679
|
-
continue;
|
|
1680
|
-
const identity = ownerIdentity(options.pluginName, artifact.artifactKey, options.platform, options.scope);
|
|
1681
|
-
components.push(pathComponent({
|
|
1682
|
-
kind: artifact.kind === 'skill' ? 'skill-directory' : 'owned-text-file',
|
|
1683
|
-
path: artifact.path,
|
|
1684
|
-
allowedRoot: artifact.kind === 'skill' ? path.dirname(artifact.path) : paths.configDir,
|
|
1685
|
-
identity,
|
|
1686
|
-
}));
|
|
1687
|
-
}
|
|
1688
|
-
return components;
|
|
1689
|
-
}
|
|
1690
|
-
function isAbsentPath(error) {
|
|
1691
|
-
const code = error.code;
|
|
1692
|
-
return code === 'ENOENT';
|
|
1693
|
-
}
|
|
1694
|
-
async function lstatIfPresent(filePath) {
|
|
1695
|
-
return fs.lstat(filePath).catch((error) => {
|
|
1696
|
-
if (isAbsentPath(error))
|
|
1697
|
-
return null;
|
|
1698
|
-
throw error;
|
|
1699
|
-
});
|
|
1700
|
-
}
|
|
1701
|
-
async function lstatCodexResidueIfPresent(filePath) {
|
|
1702
|
-
return fs.lstat(filePath).catch((error) => {
|
|
1703
|
-
if (isAbsentPath(error))
|
|
1704
|
-
return null;
|
|
1705
|
-
throw error;
|
|
1706
|
-
});
|
|
1707
|
-
}
|
|
1708
|
-
function isPathWithin(root, candidate) {
|
|
1709
|
-
const relative = path.relative(path.resolve(root), path.resolve(candidate));
|
|
1710
|
-
return relative === '' || (!relative.startsWith(`..${path.sep}`) && relative !== '..' && !path.isAbsolute(relative));
|
|
1711
|
-
}
|
|
1712
|
-
async function codexReadPathSafe(root, candidate) {
|
|
1713
|
-
if (!isPathWithin(root, candidate))
|
|
1714
|
-
return false;
|
|
1715
|
-
const rootStats = await lstatCodexResidueIfPresent(root);
|
|
1716
|
-
if (rootStats && (!rootStats.isDirectory() || rootStats.isSymbolicLink()))
|
|
1717
|
-
return false;
|
|
1718
|
-
const [physicalRoot, physicalCandidate] = await Promise.all([
|
|
1719
|
-
canonicalizePathThroughExistingAncestor(root),
|
|
1720
|
-
canonicalizePathThroughExistingAncestor(candidate),
|
|
1721
|
-
]);
|
|
1722
|
-
return isPathWithin(physicalRoot, physicalCandidate);
|
|
1723
|
-
}
|
|
1724
|
-
async function codexPayloadPathSafe(payloadRoot, allowedRoot = payloadRoot) {
|
|
1725
|
-
if (!await codexReadPathSafe(allowedRoot, payloadRoot))
|
|
1726
|
-
return false;
|
|
1727
|
-
const rootStats = await lstatCodexResidueIfPresent(payloadRoot);
|
|
1728
|
-
if (!rootStats?.isDirectory() || rootStats.isSymbolicLink())
|
|
1729
|
-
return false;
|
|
1730
|
-
const pending = [payloadRoot];
|
|
1731
|
-
while (pending.length > 0) {
|
|
1732
|
-
const current = pending.pop();
|
|
1733
|
-
for (const entry of await fs.readdir(current, { withFileTypes: true })) {
|
|
1734
|
-
const entryPath = path.join(current, entry.name);
|
|
1735
|
-
if (entry.isSymbolicLink())
|
|
1736
|
-
return false;
|
|
1737
|
-
if (entry.isDirectory()) {
|
|
1738
|
-
pending.push(entryPath);
|
|
1739
|
-
}
|
|
1740
|
-
else if (!entry.isFile()) {
|
|
1741
|
-
return false;
|
|
1742
|
-
}
|
|
1743
|
-
}
|
|
1744
|
-
}
|
|
1745
|
-
return true;
|
|
1746
|
-
}
|
|
1747
|
-
class NativeSkillProjectionUnsafeError extends Error {
|
|
1748
|
-
}
|
|
1749
|
-
async function resolveNativeSkillsRoot(payloadRoot, rawSkillsRoot, platform) {
|
|
1750
|
-
const normalizedSeparators = rawSkillsRoot.replace(/\\/gu, '/');
|
|
1751
|
-
const relativeRoot = path.posix.normalize(normalizedSeparators.replace(/^\.\//u, ''));
|
|
1752
|
-
if (!relativeRoot
|
|
1753
|
-
|| relativeRoot === '.'
|
|
1754
|
-
|| relativeRoot === '..'
|
|
1755
|
-
|| relativeRoot.startsWith('../')
|
|
1756
|
-
|| path.posix.isAbsolute(normalizedSeparators)
|
|
1757
|
-
|| path.win32.isAbsolute(rawSkillsRoot)) {
|
|
1758
|
-
throw new NativeSkillProjectionUnsafeError(`${platform}NativeSkillsRootInvalid: Native Skills root is invalid.`);
|
|
1759
|
-
}
|
|
1760
|
-
const root = path.join(payloadRoot, ...relativeRoot.split('/'));
|
|
1761
|
-
if (!await codexReadPathSafe(payloadRoot, root)) {
|
|
1762
|
-
throw new NativeSkillProjectionUnsafeError(`${platform}NativeSkillsRootInvalid: Native Skills root is unsafe.`);
|
|
1763
|
-
}
|
|
1764
|
-
return { relativeRoot, root };
|
|
1765
|
-
}
|
|
1766
|
-
function codexNativeRenderTargets(plugin) {
|
|
1767
|
-
return (plugin.manifest.artifacts?.targets ?? []).filter((target) => target.platform === 'codex'
|
|
1768
|
-
&& target.target === 'codex.skill');
|
|
1769
|
-
}
|
|
1770
|
-
function nativeSkillRefreshKeys(plugin, target) {
|
|
1771
|
-
const commandKeys = getManagedCommandArtifactTargets(plugin.manifest).flatMap((command) => command.producer.kind === 'artifact'
|
|
1772
|
-
&& command.producer.artifactId === target.id
|
|
1773
|
-
&& command.platform === target.platform
|
|
1774
|
-
? command.refreshKeys
|
|
1775
|
-
: []);
|
|
1776
|
-
return [...new Set([...target.refreshKeys, ...commandKeys])];
|
|
1777
|
-
}
|
|
1778
|
-
function nativeSkillContentDigest(platform, tree) {
|
|
1779
|
-
return platform === 'codex'
|
|
1780
|
-
? createCodexSkillStagingTreeContentDigest(tree)
|
|
1781
|
-
: createDynamicSkillTreeContentDigest(tree);
|
|
1782
|
-
}
|
|
1783
|
-
async function readNativeSkillRenderReceiptEvidence(payloadRoot, platform) {
|
|
1784
|
-
const receiptPath = path.join(payloadRoot, nativeSkillRenderReceiptPath(platform));
|
|
1785
|
-
const stats = await lstatIfPresent(receiptPath);
|
|
1786
|
-
if (!stats)
|
|
1787
|
-
return { state: 'absent' };
|
|
1788
|
-
if (!stats.isFile() || stats.isSymbolicLink())
|
|
1789
|
-
return { state: 'unsafe' };
|
|
1790
|
-
let content;
|
|
1791
|
-
try {
|
|
1792
|
-
content = await fs.readFile(receiptPath, 'utf8');
|
|
1793
|
-
}
|
|
1794
|
-
catch {
|
|
1795
|
-
return { state: 'unreadable' };
|
|
1796
|
-
}
|
|
1797
|
-
try {
|
|
1798
|
-
return { state: 'present', receipt: parseNativeSkillRenderReceipt(platform, content) };
|
|
1799
|
-
}
|
|
1800
|
-
catch {
|
|
1801
|
-
return { state: 'invalid' };
|
|
1802
|
-
}
|
|
1803
|
-
}
|
|
1804
|
-
function nativeSkillRenderEvidenceIssue(reason, diagnostic) {
|
|
1805
|
-
return { state: 'issue', reason, diagnostic };
|
|
1806
|
-
}
|
|
1807
|
-
async function readNativeSkillProjectionManifest(manifestPath) {
|
|
1808
|
-
let stats;
|
|
1809
|
-
try {
|
|
1810
|
-
stats = await lstatIfPresent(manifestPath);
|
|
1811
|
-
}
|
|
1812
|
-
catch {
|
|
1813
|
-
return { state: 'unreadable' };
|
|
1814
|
-
}
|
|
1815
|
-
if (!stats)
|
|
1816
|
-
return { state: 'missing' };
|
|
1817
|
-
if (!stats.isFile() || stats.isSymbolicLink())
|
|
1818
|
-
return { state: 'unsafe' };
|
|
1819
|
-
try {
|
|
1820
|
-
const value = await fs.readJson(manifestPath);
|
|
1821
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
1822
|
-
? { state: 'present', value: value }
|
|
1823
|
-
: { state: 'invalid' };
|
|
1824
|
-
}
|
|
1825
|
-
catch (error) {
|
|
1826
|
-
return { state: error instanceof SyntaxError ? 'invalid' : 'unreadable' };
|
|
1827
|
-
}
|
|
1828
|
-
}
|
|
1829
|
-
async function resolveNativeSkillRenderExpectedEvidence(options) {
|
|
1830
|
-
const { platform } = options;
|
|
1831
|
-
const logicalPluginId = options.plugin.pluginId
|
|
1832
|
-
?? (options.plugin.sourceId ? `${options.plugin.sourceId}/${options.plugin.manifest.name}` : undefined);
|
|
1833
|
-
if (!logicalPluginId || !options.plugin.sourceId || !options.plugin.sourceIdentity) {
|
|
1834
|
-
throw new Error('Native Skill render projection requires namespaced source identity.');
|
|
1835
|
-
}
|
|
1836
|
-
const marketplace = await readStrictNamespacedMarketplaceRoot({
|
|
1837
|
-
trustedMarketplaceRoot: path.join(resolveAwHome(options.env), 'marketplaces'),
|
|
1838
|
-
rootDir: options.marketplaceRoot,
|
|
1839
|
-
});
|
|
1840
|
-
if (!marketplace) {
|
|
1841
|
-
return nativeSkillRenderEvidenceIssue('damaged', 'projectionReceiptMissing');
|
|
1842
|
-
}
|
|
1843
|
-
if (marketplace.config.sourceId !== options.plugin.sourceId
|
|
1844
|
-
|| marketplace.config.sourceIdentity !== options.plugin.sourceIdentity
|
|
1845
|
-
|| marketplace.config.marketplaceName !== options.marketplaceName) {
|
|
1846
|
-
return nativeSkillRenderEvidenceIssue('foreign', 'projectionReceiptIdentityMismatch');
|
|
1847
|
-
}
|
|
1848
|
-
const payloadRoot = path.join(options.marketplaceRoot, 'plugins', options.plugin.manifest.name);
|
|
1849
|
-
const payloadStats = await lstatIfPresent(payloadRoot);
|
|
1850
|
-
if (!payloadStats) {
|
|
1851
|
-
return nativeSkillRenderEvidenceIssue('damaged', 'projectionReceiptMissing');
|
|
1852
|
-
}
|
|
1853
|
-
if (!payloadStats.isDirectory() || payloadStats.isSymbolicLink()) {
|
|
1854
|
-
return nativeSkillRenderEvidenceIssue('foreign', 'payloadPathUnsafe');
|
|
1855
|
-
}
|
|
1856
|
-
if (!await codexPayloadPathSafe(payloadRoot, options.marketplaceRoot)) {
|
|
1857
|
-
return nativeSkillRenderEvidenceIssue('foreign', 'payloadPathUnsafe');
|
|
1858
|
-
}
|
|
1859
|
-
const platformManifestPath = path.join(payloadRoot, `.${platform}-plugin`, 'plugin.json');
|
|
1860
|
-
const [sourceManifestEvidence, platformManifestEvidence] = await Promise.all([
|
|
1861
|
-
readNativeSkillProjectionManifest(path.join(payloadRoot, '.agents-plugin', 'plugin.json')),
|
|
1862
|
-
readNativeSkillProjectionManifest(platformManifestPath),
|
|
1863
|
-
]);
|
|
1864
|
-
if (sourceManifestEvidence.state === 'unsafe'
|
|
1865
|
-
|| platformManifestEvidence.state === 'unsafe') {
|
|
1866
|
-
return nativeSkillRenderEvidenceIssue('foreign', 'payloadPathUnsafe');
|
|
1867
|
-
}
|
|
1868
|
-
if ((sourceManifestEvidence.state === 'present'
|
|
1869
|
-
&& sourceManifestEvidence.value.name !== options.plugin.manifest.name)
|
|
1870
|
-
|| (platformManifestEvidence.state === 'present'
|
|
1871
|
-
&& platformManifestEvidence.value.name !== options.plugin.manifest.name)
|
|
1872
|
-
|| (sourceManifestEvidence.state === 'present'
|
|
1873
|
-
&& platformManifestEvidence.state === 'present'
|
|
1874
|
-
&& sourceManifestEvidence.value.version !== platformManifestEvidence.value.version)) {
|
|
1875
|
-
return nativeSkillRenderEvidenceIssue('foreign', 'manifestIdentityMismatch');
|
|
1876
|
-
}
|
|
1877
|
-
if (sourceManifestEvidence.state === 'unreadable'
|
|
1878
|
-
|| platformManifestEvidence.state === 'unreadable') {
|
|
1879
|
-
return nativeSkillRenderEvidenceIssue('unreadable', 'manifestUnreadable');
|
|
1880
|
-
}
|
|
1881
|
-
if (sourceManifestEvidence.state === 'missing'
|
|
1882
|
-
|| platformManifestEvidence.state === 'missing') {
|
|
1883
|
-
return nativeSkillRenderEvidenceIssue('damaged', 'manifestMissing');
|
|
1884
|
-
}
|
|
1885
|
-
if (sourceManifestEvidence.state === 'invalid'
|
|
1886
|
-
|| platformManifestEvidence.state === 'invalid') {
|
|
1887
|
-
return nativeSkillRenderEvidenceIssue('damaged', 'manifestUnreadable');
|
|
1888
|
-
}
|
|
1889
|
-
if (sourceManifestEvidence.state !== 'present'
|
|
1890
|
-
|| platformManifestEvidence.state !== 'present') {
|
|
1891
|
-
return nativeSkillRenderEvidenceIssue('damaged', 'manifestUnreadable');
|
|
1892
|
-
}
|
|
1893
|
-
const sourceManifest = sourceManifestEvidence.value;
|
|
1894
|
-
const platformManifest = platformManifestEvidence.value;
|
|
1895
|
-
if (typeof sourceManifest.version !== 'string'
|
|
1896
|
-
|| !tryParseStrictSemVer(sourceManifest.version)) {
|
|
1897
|
-
return nativeSkillRenderEvidenceIssue('damaged', 'manifestVersionInvalid');
|
|
1898
|
-
}
|
|
1899
|
-
const defaultSkillsRoot = platform === 'codex'
|
|
1900
|
-
? './codex/skills'
|
|
1901
|
-
: `./claude/${(options.plugin.manifest.skills ?? './skills').replace(/^\.\//u, '')}`;
|
|
1902
|
-
const rawSkillsRoot = typeof platformManifest.skills === 'string' && platformManifest.skills.trim() !== ''
|
|
1903
|
-
? platformManifest.skills
|
|
1904
|
-
: defaultSkillsRoot;
|
|
1905
|
-
const { relativeRoot: skillsRelativeRoot } = await resolveNativeSkillsRoot(payloadRoot, rawSkillsRoot, platform);
|
|
1906
|
-
const skillsRoot = path.join(payloadRoot, ...skillsRelativeRoot.split('/'));
|
|
1907
|
-
const skillsRootStats = await lstatIfPresent(skillsRoot);
|
|
1908
|
-
if (skillsRootStats && (!skillsRootStats.isDirectory() || skillsRootStats.isSymbolicLink())) {
|
|
1909
|
-
return nativeSkillRenderEvidenceIssue('foreign', 'payloadPathUnsafe');
|
|
1910
|
-
}
|
|
1911
|
-
const targets = nativeSkillRenderTargets(options.plugin, platform);
|
|
1912
|
-
for (const target of targets) {
|
|
1913
|
-
if (await lstatIfPresent(path.join(skillsRoot, target.skillKey, '.agent-workflows-owner.json'))) {
|
|
1914
|
-
return nativeSkillRenderEvidenceIssue('foreign', 'payloadPathUnsafe');
|
|
1915
|
-
}
|
|
1916
|
-
}
|
|
1917
|
-
const receiptEvidence = await readNativeSkillRenderReceiptEvidence(payloadRoot, platform);
|
|
1918
|
-
if (receiptEvidence.state === 'absent') {
|
|
1919
|
-
return nativeSkillRenderEvidenceIssue('damaged', 'projectionReceiptMissing');
|
|
1920
|
-
}
|
|
1921
|
-
if (receiptEvidence.state === 'unsafe') {
|
|
1922
|
-
return nativeSkillRenderEvidenceIssue('foreign', 'payloadPathUnsafe');
|
|
1923
|
-
}
|
|
1924
|
-
if (receiptEvidence.state === 'invalid') {
|
|
1925
|
-
return nativeSkillRenderEvidenceIssue('damaged', 'projectionReceiptUnreadable');
|
|
1926
|
-
}
|
|
1927
|
-
if (receiptEvidence.state === 'unreadable') {
|
|
1928
|
-
return nativeSkillRenderEvidenceIssue('unreadable', 'projectionReceiptUnreadable');
|
|
1929
|
-
}
|
|
1930
|
-
const receipt = receiptEvidence.receipt;
|
|
1931
|
-
if (receipt.logicalPluginId !== logicalPluginId
|
|
1932
|
-
|| receipt.strategy !== 'shared-user'
|
|
1933
|
-
|| receipt.sourceIdentity !== marketplace.config.sourceIdentity
|
|
1934
|
-
|| receipt.pluginVersion !== sourceManifest.version) {
|
|
1935
|
-
return nativeSkillRenderEvidenceIssue('foreign', 'projectionReceiptIdentityMismatch');
|
|
1936
|
-
}
|
|
1937
|
-
const emptyArtifactDigest = nativeSkillContentDigest(platform, {
|
|
1938
|
-
skillKey: 'empty',
|
|
1939
|
-
files: {},
|
|
1940
|
-
});
|
|
1941
|
-
for (const receiptTarget of receipt.targets) {
|
|
1942
|
-
const skillRoot = path.join(payloadRoot, ...skillsRelativeRoot.split('/'), receiptTarget.skillKey);
|
|
1943
|
-
if (await lstatIfPresent(path.join(skillRoot, '.agent-workflows-owner.json'))) {
|
|
1944
|
-
return nativeSkillRenderEvidenceIssue('foreign', 'payloadPathUnsafe');
|
|
1945
|
-
}
|
|
1946
|
-
const skillStats = await lstatIfPresent(skillRoot);
|
|
1947
|
-
if (skillStats && (!skillStats.isDirectory() || skillStats.isSymbolicLink())) {
|
|
1948
|
-
return nativeSkillRenderEvidenceIssue('foreign', 'payloadPathUnsafe');
|
|
1949
|
-
}
|
|
1950
|
-
let tree;
|
|
1951
|
-
try {
|
|
1952
|
-
tree = skillStats ? await readDynamicSkillTree(skillRoot, `${platform}.skill`) : null;
|
|
1953
|
-
}
|
|
1954
|
-
catch (error) {
|
|
1955
|
-
return nativeSkillRenderEvidenceIssue(error instanceof Error && typeof error.code !== 'string'
|
|
1956
|
-
? 'damaged'
|
|
1957
|
-
: 'unreadable', 'projectionPayloadDigestMismatch');
|
|
1958
|
-
}
|
|
1959
|
-
const artifactDigest = tree
|
|
1960
|
-
? nativeSkillContentDigest(platform, tree)
|
|
1961
|
-
: emptyArtifactDigest;
|
|
1962
|
-
if (artifactDigest !== receiptTarget.artifactDigest) {
|
|
1963
|
-
return nativeSkillRenderEvidenceIssue('damaged', 'projectionPayloadDigestMismatch');
|
|
1964
|
-
}
|
|
1965
|
-
}
|
|
1966
|
-
const payloadDigest = await calculateCodexNativeRenderPayloadDigest(payloadRoot);
|
|
1967
|
-
if (payloadDigest !== receipt.payloadDigest) {
|
|
1968
|
-
return nativeSkillRenderEvidenceIssue('damaged', 'projectionPayloadDigestMismatch');
|
|
1969
|
-
}
|
|
1970
|
-
const receiptTargets = new Map(receipt.targets.map((target) => [target.id, target]));
|
|
1971
|
-
if (targets.length === 0
|
|
1972
|
-
|| targets.length !== receipt.targets.length
|
|
1973
|
-
|| targets.some((target) => receiptTargets.get(target.id)?.skillKey !== target.skillKey)) {
|
|
1974
|
-
return { state: 'present', payloadDigest, receipt, sourceProjection: 'drifted' };
|
|
1975
|
-
}
|
|
1976
|
-
const renderer = await resolveArtifactRendererTarget(options.plugin);
|
|
1977
|
-
if (renderer.noOp || !renderer.rendererDigest) {
|
|
1978
|
-
throw new Error('Native Skill render projection requires an artifact renderer.');
|
|
1979
|
-
}
|
|
1980
|
-
const config = await resolveArtifactRenderConfig({
|
|
1981
|
-
sourceId: options.plugin.sourceId,
|
|
1982
|
-
sourceIdentity: options.plugin.sourceIdentity,
|
|
1983
|
-
logicalIdentity: options.plugin.catalogLogicalIdentity,
|
|
1984
|
-
pluginName: options.plugin.manifest.name,
|
|
1985
|
-
manifest: options.plugin.manifest,
|
|
1986
|
-
platform,
|
|
1987
|
-
referencePlugins: options.referencePlugins,
|
|
1988
|
-
scope: 'user',
|
|
1989
|
-
cwd: options.plugin.rootDir,
|
|
1990
|
-
env: options.env,
|
|
1991
|
-
});
|
|
1992
|
-
if (config.issues.length > 0) {
|
|
1993
|
-
// Validated installed bytes remain live while configuration needs repair.
|
|
1994
|
-
return { state: 'present', payloadDigest, receipt, sourceProjection: 'drifted' };
|
|
1995
|
-
}
|
|
1996
|
-
const projection = createCodexNativeRenderProjection({
|
|
1997
|
-
logicalPluginId,
|
|
1998
|
-
sourceIdentity: options.plugin.sourceIdentity,
|
|
1999
|
-
pluginVersion: options.plugin.manifest.version,
|
|
2000
|
-
rendererDigest: renderer.rendererDigest,
|
|
2001
|
-
targets: targets.map((target) => ({
|
|
2002
|
-
id: target.id,
|
|
2003
|
-
skillKey: target.skillKey,
|
|
2004
|
-
configDigest: createArtifactConfigDigest({
|
|
2005
|
-
artifact: {
|
|
2006
|
-
id: target.id,
|
|
2007
|
-
platform,
|
|
2008
|
-
target: `${platform}.skill`,
|
|
2009
|
-
refreshKeys: nativeSkillRefreshKeys(options.plugin, target),
|
|
2010
|
-
},
|
|
2011
|
-
renderConfig: config,
|
|
2012
|
-
digestSalt: renderer.rendererDigest,
|
|
2013
|
-
}),
|
|
2014
|
-
artifactDigest: receiptTargets.get(target.id).artifactDigest,
|
|
2015
|
-
})),
|
|
2016
|
-
});
|
|
2017
|
-
return {
|
|
2018
|
-
state: 'present',
|
|
2019
|
-
receipt,
|
|
2020
|
-
projection,
|
|
2021
|
-
payloadDigest,
|
|
2022
|
-
sourceProjection: codexNativeRenderProjectionsEqual(receipt, projection)
|
|
2023
|
-
? 'current'
|
|
2024
|
-
: 'drifted',
|
|
2025
|
-
};
|
|
2026
|
-
}
|
|
2027
|
-
async function assertNoSensitiveValuesInCanonicalCodexNativePayload(options) {
|
|
2028
|
-
if (options.sensitiveValues.length === 0
|
|
2029
|
-
|| !pluginHasCodexNativeSkillSurface(options.plugin))
|
|
2030
|
-
return;
|
|
2031
|
-
const sourceId = options.plugin.sourceId;
|
|
2032
|
-
if (!sourceId) {
|
|
2033
|
-
throw new Error('Codex native sensitive scan requires namespaced source identity.');
|
|
2034
|
-
}
|
|
2035
|
-
const awHome = resolveAwHome(options.env);
|
|
2036
|
-
if (!await isSafeCodexMarketplaceRoot({
|
|
2037
|
-
awHome,
|
|
2038
|
-
sourceId,
|
|
2039
|
-
marketplaceRoot: options.marketplaceRoot,
|
|
2040
|
-
})) {
|
|
2041
|
-
throw new Error('Codex native sensitive scan canonical marketplace path is unsafe.');
|
|
2042
|
-
}
|
|
2043
|
-
const payloadRoot = path.join(options.marketplaceRoot, 'plugins', options.plugin.manifest.name);
|
|
2044
|
-
if (!await codexPayloadPathSafe(payloadRoot, options.marketplaceRoot)) {
|
|
2045
|
-
throw new Error('Codex native sensitive scan payload path is unsafe.');
|
|
2046
|
-
}
|
|
2047
|
-
const receiptEvidence = await readNativeSkillRenderReceiptEvidence(payloadRoot, 'codex');
|
|
2048
|
-
if (receiptEvidence.state === 'unsafe') {
|
|
2049
|
-
throw new Error('codexNativeRenderReceiptInvalid: Codex native render receipt path is unsafe.');
|
|
2050
|
-
}
|
|
2051
|
-
let verifiedRenderReceipt;
|
|
2052
|
-
if (receiptEvidence.state === 'present') {
|
|
2053
|
-
const expected = await resolveNativeSkillRenderExpectedEvidence({
|
|
2054
|
-
plugin: options.plugin,
|
|
2055
|
-
platform: 'codex',
|
|
2056
|
-
marketplaceRoot: options.marketplaceRoot,
|
|
2057
|
-
marketplaceName: options.marketplaceName,
|
|
2058
|
-
env: options.env,
|
|
2059
|
-
}).catch(() => undefined);
|
|
2060
|
-
if (expected?.state === 'present' && expected.sourceProjection === 'current') {
|
|
2061
|
-
verifiedRenderReceipt = expected.receipt;
|
|
2062
|
-
}
|
|
2063
|
-
}
|
|
2064
|
-
await assertNoSensitiveValuesInNativeSkillPayload({
|
|
2065
|
-
plugin: options.plugin,
|
|
2066
|
-
payloadRoot,
|
|
2067
|
-
allowedRoot: options.marketplaceRoot,
|
|
2068
|
-
sensitiveValues: options.sensitiveValues,
|
|
2069
|
-
verifiedRenderReceipt,
|
|
2070
|
-
});
|
|
2071
|
-
}
|
|
2072
|
-
function observedCodexNativeState(observation, operation) {
|
|
2073
|
-
if (observation.state === 'observed') {
|
|
2074
|
-
return observation.value === 'installed' ? 'present' : 'absent';
|
|
2075
|
-
}
|
|
2076
|
-
if (observation.state === 'unobserved')
|
|
2077
|
-
return 'partial';
|
|
2078
|
-
throw new Error(`codexNativeObservationFailed: ${operation} requires Codex plugin list evidence.`);
|
|
2079
|
-
}
|
|
2080
|
-
function requireObservedCodexNativeState(observation, operation) {
|
|
2081
|
-
if (observation.state === 'observed')
|
|
2082
|
-
return observation.value;
|
|
2083
|
-
const code = observation.state === 'failed'
|
|
2084
|
-
? 'codexNativeObservationFailed'
|
|
2085
|
-
: 'codexNativeObservationUnavailable';
|
|
2086
|
-
throw new Error(`${code}: ${operation} requires Codex plugin list evidence.`);
|
|
2087
|
-
}
|
|
2088
|
-
export async function inspectCodexPluginRegistrationLive(options) {
|
|
2089
|
-
if (!options.nativeCliRunner) {
|
|
2090
|
-
return {
|
|
2091
|
-
observation: { state: 'unobserved' },
|
|
2092
|
-
observations: { user: false, project: false },
|
|
2093
|
-
activations: {},
|
|
2094
|
-
};
|
|
2095
|
-
}
|
|
2096
|
-
const ownedSession = options.observationSession ? undefined
|
|
2097
|
-
: await createCodexNativeObservationSession({
|
|
2098
|
-
exactCwd: options.cwd,
|
|
2099
|
-
env: options.env,
|
|
2100
|
-
runner: options.nativeCliRunner,
|
|
2101
|
-
manager: options.manager ?? SYSTEM_CODEX_MANAGER,
|
|
2102
|
-
});
|
|
2103
|
-
const session = options.observationSession ?? ownedSession;
|
|
2104
|
-
try {
|
|
2105
|
-
const inspected = await session.inspectPlugin({
|
|
2106
|
-
pluginId: options.pluginId,
|
|
2107
|
-
scope: options.scope ?? 'both',
|
|
2108
|
-
});
|
|
2109
|
-
return {
|
|
2110
|
-
observation: inspected.observation,
|
|
2111
|
-
observations: inspected.observations,
|
|
2112
|
-
activations: inspected.activations,
|
|
2113
|
-
};
|
|
2114
|
-
}
|
|
2115
|
-
finally {
|
|
2116
|
-
await ownedSession?.dispose();
|
|
2117
|
-
}
|
|
2118
|
-
}
|
|
2119
|
-
export async function removeCodexPluginActivation(options) {
|
|
2120
|
-
await applyConditionalCodexConfigTransactionFile(options.configPath, (snapshot) => Object.hasOwn(snapshot.plugins, options.codexPluginId)
|
|
2121
|
-
? { removePluginActivations: [options.codexPluginId] }
|
|
2122
|
-
: null);
|
|
2123
|
-
}
|
|
2124
|
-
export async function removeNamespacedMarketplacePluginProjection(options) {
|
|
2125
|
-
if (!await isSafeCodexMarketplaceRoot({
|
|
2126
|
-
awHome: resolveAwHome(options.env),
|
|
2127
|
-
sourceId: options.sourceId,
|
|
2128
|
-
marketplaceRoot: options.rootDir,
|
|
2129
|
-
})) {
|
|
2130
|
-
throw new Error('marketplaceProjectionUnsafe: marketplace root is outside the canonical AW source path.');
|
|
2131
|
-
}
|
|
2132
|
-
const root = await readStrictNamespacedMarketplaceRoot({
|
|
2133
|
-
rootDir: options.rootDir,
|
|
2134
|
-
sourceId: options.sourceId,
|
|
2135
|
-
sourceIdentity: options.sourceIdentity,
|
|
2136
|
-
});
|
|
2137
|
-
if (!root)
|
|
2138
|
-
return;
|
|
2139
|
-
const pluginRoot = await assertSafeNamespacedMarketplacePluginRoot(options.rootDir, options.pluginName);
|
|
2140
|
-
const pluginStats = await fs.lstat(pluginRoot).catch((error) => {
|
|
2141
|
-
if (error.code === 'ENOENT')
|
|
2142
|
-
return null;
|
|
2143
|
-
throw error;
|
|
2144
|
-
});
|
|
2145
|
-
if (pluginStats && (!pluginStats.isDirectory() || pluginStats.isSymbolicLink())) {
|
|
2146
|
-
throw new Error('marketplaceProjectionUnsafe: plugin projection is not a regular directory.');
|
|
2147
|
-
}
|
|
2148
|
-
const manifests = [
|
|
2149
|
-
{ value: root.agentsManifest, path: path.join(options.rootDir, '.agents', 'plugins', 'marketplace.json') },
|
|
2150
|
-
...(root.claudeManifest
|
|
2151
|
-
? [{ value: root.claudeManifest, path: path.join(options.rootDir, '.claude-plugin', 'marketplace.json') }]
|
|
2152
|
-
: []),
|
|
2153
|
-
];
|
|
2154
|
-
const hasEntry = manifests.some(({ value }) => Array.isArray(value.plugins)
|
|
2155
|
-
&& value.plugins.some((entry) => entry !== null && typeof entry === 'object'
|
|
2156
|
-
&& entry.name === options.pluginName));
|
|
2157
|
-
let hasIdentityManifest = false;
|
|
2158
|
-
if (pluginStats) {
|
|
2159
|
-
for (const manifestName of ['.agents-plugin/plugin.json', '.codex-plugin/plugin.json']) {
|
|
2160
|
-
const manifestPath = path.join(pluginRoot, manifestName);
|
|
2161
|
-
const manifest = await fs.readJson(manifestPath).catch((error) => {
|
|
2162
|
-
if (error.code === 'ENOENT')
|
|
2163
|
-
return null;
|
|
2164
|
-
throw error;
|
|
2165
|
-
});
|
|
2166
|
-
if (manifest && manifest.name !== options.pluginName) {
|
|
2167
|
-
throw new Error('marketplaceProjectionIdentityMismatch: plugin projection has a foreign name.');
|
|
2168
|
-
}
|
|
2169
|
-
hasIdentityManifest ||= manifest?.name === options.pluginName;
|
|
2170
|
-
}
|
|
2171
|
-
if (!hasEntry && !hasIdentityManifest) {
|
|
2172
|
-
throw new Error('marketplaceProjectionIdentityUnavailable: plugin directory has no matching marketplace entry or plugin manifest.');
|
|
2173
|
-
}
|
|
2174
|
-
}
|
|
2175
|
-
if (pluginStats) {
|
|
2176
|
-
const inspectTree = async (directory) => {
|
|
2177
|
-
for (const entry of await fs.readdir(directory, { withFileTypes: true })) {
|
|
2178
|
-
if (entry.isSymbolicLink() || (!entry.isDirectory() && !entry.isFile())) {
|
|
2179
|
-
throw new Error('marketplaceProjectionUnsafe: plugin projection contains an unsafe node.');
|
|
2180
|
-
}
|
|
2181
|
-
if (entry.isDirectory())
|
|
2182
|
-
await inspectTree(path.join(directory, entry.name));
|
|
2183
|
-
}
|
|
2184
|
-
};
|
|
2185
|
-
await inspectTree(pluginRoot);
|
|
2186
|
-
await fs.remove(pluginRoot);
|
|
2187
|
-
}
|
|
2188
|
-
for (const manifest of manifests) {
|
|
2189
|
-
if (!Array.isArray(manifest.value.plugins)) {
|
|
2190
|
-
throw new Error('marketplaceProjectionInvalid: marketplace plugins are not an array.');
|
|
2191
|
-
}
|
|
2192
|
-
const plugins = manifest.value.plugins.filter((entry) => entry === null
|
|
2193
|
-
|| typeof entry !== 'object'
|
|
2194
|
-
|| entry.name !== options.pluginName);
|
|
2195
|
-
if (plugins.length !== manifest.value.plugins.length) {
|
|
2196
|
-
await atomicReplaceConfigFile({
|
|
2197
|
-
filePath: manifest.path,
|
|
2198
|
-
allowedRoot: options.rootDir,
|
|
2199
|
-
content: `${JSON.stringify({ ...manifest.value, plugins }, null, 2)}\n`,
|
|
2200
|
-
});
|
|
653
|
+
if (entry.isDirectory())
|
|
654
|
+
await inspectTree(path.join(directory, entry.name));
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
await inspectTree(pluginRoot);
|
|
658
|
+
await fs.remove(pluginRoot);
|
|
659
|
+
}
|
|
660
|
+
for (const manifest of manifests) {
|
|
661
|
+
if (!Array.isArray(manifest.value.plugins)) {
|
|
662
|
+
throw new Error('marketplaceProjectionInvalid: marketplace plugins are not an array.');
|
|
663
|
+
}
|
|
664
|
+
const plugins = manifest.value.plugins.filter((entry) => entry === null
|
|
665
|
+
|| typeof entry !== 'object'
|
|
666
|
+
|| entry.name !== options.pluginName);
|
|
667
|
+
if (plugins.length !== manifest.value.plugins.length) {
|
|
668
|
+
await atomicReplaceConfigFile({
|
|
669
|
+
filePath: manifest.path,
|
|
670
|
+
allowedRoot: options.rootDir,
|
|
671
|
+
content: `${JSON.stringify({ ...manifest.value, plugins }, null, 2)}\n`,
|
|
672
|
+
});
|
|
2201
673
|
}
|
|
2202
674
|
}
|
|
2203
675
|
}
|
|
@@ -2206,14 +678,6 @@ export async function removeNamespacedMarketplacePluginProjection(options) {
|
|
|
2206
678
|
* state. Filesystem validation is limited to the AW-owned marketplace source.
|
|
2207
679
|
*/
|
|
2208
680
|
export async function inspectCodexSharedNativeLive(options) {
|
|
2209
|
-
const inspectionMode = options.inspectionMode ?? 'payload';
|
|
2210
|
-
const dynamicProjectionExpected = options.nativeRenderPlugin !== undefined
|
|
2211
|
-
&& codexNativeRenderTargets(options.nativeRenderPlugin).length > 0;
|
|
2212
|
-
if (inspectionMode === 'payload'
|
|
2213
|
-
&& options.expectedPayloadDigest === undefined
|
|
2214
|
-
&& !dynamicProjectionExpected) {
|
|
2215
|
-
throw new Error('Payload inspection requires the expected shared native digest.');
|
|
2216
|
-
}
|
|
2217
681
|
const marketplaceName = options.marketplaceName ?? MARKETPLACE_NAME;
|
|
2218
682
|
const marketplaceRoot = options.marketplaceRoot ?? path.join(resolveAwHome(options.env), 'marketplaces', options.sourceId);
|
|
2219
683
|
const marketplacePathSafe = await isSafeCodexMarketplaceRoot({
|
|
@@ -2232,49 +696,7 @@ export async function inspectCodexSharedNativeLive(options) {
|
|
|
2232
696
|
scope: options.observationScope,
|
|
2233
697
|
observationSession: options.observationSession,
|
|
2234
698
|
});
|
|
2235
|
-
|
|
2236
|
-
let sourceProjection;
|
|
2237
|
-
let sourceProjectionIssue;
|
|
2238
|
-
const installed = pluginList.observation.state === 'observed'
|
|
2239
|
-
&& pluginList.observation.value === 'installed';
|
|
2240
|
-
if (installed && dynamicProjectionExpected && options.nativeRenderPlugin) {
|
|
2241
|
-
try {
|
|
2242
|
-
const expected = await resolveNativeSkillRenderExpectedEvidence({
|
|
2243
|
-
plugin: options.nativeRenderPlugin,
|
|
2244
|
-
platform: 'codex',
|
|
2245
|
-
marketplaceRoot,
|
|
2246
|
-
marketplaceName,
|
|
2247
|
-
env: options.env,
|
|
2248
|
-
});
|
|
2249
|
-
if (expected.state === 'issue') {
|
|
2250
|
-
sourceProjectionIssue = expected;
|
|
2251
|
-
}
|
|
2252
|
-
else {
|
|
2253
|
-
expectedPayloadDigest = expected.payloadDigest;
|
|
2254
|
-
sourceProjection = expected.sourceProjection;
|
|
2255
|
-
}
|
|
2256
|
-
}
|
|
2257
|
-
catch (error) {
|
|
2258
|
-
if (error instanceof MarketplaceRootValidationError) {
|
|
2259
|
-
sourceProjectionIssue = {
|
|
2260
|
-
reason: error.reason === 'unsafe'
|
|
2261
|
-
? 'foreign'
|
|
2262
|
-
: error.reason === 'invalid' ? 'damaged' : 'unreadable',
|
|
2263
|
-
diagnostic: error.reason === 'unsafe'
|
|
2264
|
-
? 'payloadPathUnsafe'
|
|
2265
|
-
: 'projectionReceiptUnreadable',
|
|
2266
|
-
};
|
|
2267
|
-
}
|
|
2268
|
-
else {
|
|
2269
|
-
sourceProjectionIssue = {
|
|
2270
|
-
reason: error instanceof NativeSkillProjectionUnsafeError ? 'foreign' : 'unreadable',
|
|
2271
|
-
diagnostic: error instanceof NativeSkillProjectionUnsafeError
|
|
2272
|
-
? 'payloadPathUnsafe'
|
|
2273
|
-
: 'projectionReceiptUnreadable',
|
|
2274
|
-
};
|
|
2275
|
-
}
|
|
2276
|
-
}
|
|
2277
|
-
}
|
|
699
|
+
const expectedPayloadDigest = options.expectedPayloadDigest;
|
|
2278
700
|
const sharedNative = inspectCodexSharedNative({
|
|
2279
701
|
pluginName: options.pluginName,
|
|
2280
702
|
pluginId,
|
|
@@ -2285,69 +707,12 @@ export async function inspectCodexSharedNativeLive(options) {
|
|
|
2285
707
|
marketplaceRegistration: config.snapshot.marketplaces[marketplaceName],
|
|
2286
708
|
marketplacePathSafe,
|
|
2287
709
|
observation: pluginList.observation,
|
|
2288
|
-
...(sourceProjection ? { sourceProjection } : {}),
|
|
2289
|
-
...(sourceProjectionIssue ? { sourceProjectionIssue } : {}),
|
|
2290
710
|
});
|
|
2291
711
|
return {
|
|
2292
712
|
sharedNative,
|
|
2293
713
|
...(expectedPayloadDigest ? { expectedPayloadDigest } : {}),
|
|
2294
714
|
};
|
|
2295
715
|
}
|
|
2296
|
-
async function ensureCodexActiveSkillsManifest(options) {
|
|
2297
|
-
const relativeSkillsRoot = await resolveCodexSkillsRelativeRoot(options.plugin);
|
|
2298
|
-
const skillsRoot = path.join(options.marketplaceRoot, 'plugins', options.plugin.manifest.name, ...relativeSkillsRoot.split('/'));
|
|
2299
|
-
if (options.hasRequiredSkills && !await fs.pathExists(skillsRoot)) {
|
|
2300
|
-
throw new Error(`Codex required Skills root 不存在:${skillsRoot}`);
|
|
2301
|
-
}
|
|
2302
|
-
const manifestPath = path.join(options.marketplaceRoot, 'plugins', options.plugin.manifest.name, '.codex-plugin', 'plugin.json');
|
|
2303
|
-
const manifest = await fs.readJson(manifestPath).catch((error) => {
|
|
2304
|
-
if (error.code === 'ENOENT')
|
|
2305
|
-
return {};
|
|
2306
|
-
throw error;
|
|
2307
|
-
});
|
|
2308
|
-
const updated = {
|
|
2309
|
-
...manifest,
|
|
2310
|
-
name: options.plugin.manifest.name,
|
|
2311
|
-
version: options.plugin.manifest.version,
|
|
2312
|
-
};
|
|
2313
|
-
if (options.hasRequiredSkills)
|
|
2314
|
-
updated.skills = `./${relativeSkillsRoot}`;
|
|
2315
|
-
else
|
|
2316
|
-
delete updated.skills;
|
|
2317
|
-
await fs.outputJson(manifestPath, updated, { spaces: 2 });
|
|
2318
|
-
return options.hasRequiredSkills ? relativeSkillsRoot : null;
|
|
2319
|
-
}
|
|
2320
|
-
async function ensureNativeActiveSkillsManifest(options) {
|
|
2321
|
-
if (options.platform === 'codex') {
|
|
2322
|
-
await ensureCodexActiveSkillsManifest(options);
|
|
2323
|
-
return;
|
|
2324
|
-
}
|
|
2325
|
-
const pluginRoot = path.join(options.marketplaceRoot, 'plugins', options.plugin.manifest.name);
|
|
2326
|
-
const manifestPath = path.join(pluginRoot, '.claude-plugin', 'plugin.json');
|
|
2327
|
-
const manifest = await fs.readJson(manifestPath);
|
|
2328
|
-
const updated = { ...manifest, name: options.plugin.manifest.name, version: options.plugin.manifest.version };
|
|
2329
|
-
if (options.hasRequiredSkills) {
|
|
2330
|
-
await fs.ensureDir(path.join(pluginRoot, ...options.relativeSkillsRoot.split('/')));
|
|
2331
|
-
updated.skills = `./${options.relativeSkillsRoot}`;
|
|
2332
|
-
}
|
|
2333
|
-
else
|
|
2334
|
-
delete updated.skills;
|
|
2335
|
-
await fs.outputJson(manifestPath, updated, { spaces: 2 });
|
|
2336
|
-
}
|
|
2337
|
-
function createCodexMarketplaceComponent(options) {
|
|
2338
|
-
const configPath = resolveCodexPaths(options.cwd, 'user', options.env).configTomlPath;
|
|
2339
|
-
return {
|
|
2340
|
-
kind: 'shared-config',
|
|
2341
|
-
identity: ownerIdentity(options.pluginName, `marketplace-${options.marketplaceName}`, 'codex', 'user'),
|
|
2342
|
-
label: `${configPath}#marketplaces.${options.marketplaceName}`,
|
|
2343
|
-
locator: {
|
|
2344
|
-
kind: 'codex-marketplace',
|
|
2345
|
-
marketplaceName: options.marketplaceName,
|
|
2346
|
-
marketplaceRoot: options.marketplaceRoot,
|
|
2347
|
-
desired: options.desired,
|
|
2348
|
-
},
|
|
2349
|
-
};
|
|
2350
|
-
}
|
|
2351
716
|
async function readJsonObjectIfExists(filePath, label) {
|
|
2352
717
|
let value;
|
|
2353
718
|
try {
|
|
@@ -2628,841 +993,39 @@ export async function inspectNativeMarketplaceRegistrations(options) {
|
|
|
2628
993
|
const codexMarketplace = codexConfig.snapshot.marketplaces[options.marketplaceName];
|
|
2629
994
|
const codexRegistration = codexMarketplace === undefined
|
|
2630
995
|
? 'absent'
|
|
2631
|
-
: codexMarketplace.
|
|
2632
|
-
&& !codexMarketplace.sourcePointsToManifest
|
|
2633
|
-
&& path.normalize(codexMarketplace.source ?? '') === path.normalize(options.marketplaceRoot)
|
|
996
|
+
: isCanonicalCodexMarketplaceRegistration(codexMarketplace, options.marketplaceRoot)
|
|
2634
997
|
? 'canonical'
|
|
2635
998
|
: 'foreign';
|
|
2636
|
-
const codexConsumerSuffix = `@${options.marketplaceName}`;
|
|
2637
|
-
const codex = codexRegistration === 'absent'
|
|
2638
|
-
&& Object.keys(codexConfig.snapshot.plugins).some((pluginId) => pluginId.length > codexConsumerSuffix.length && pluginId.endsWith(codexConsumerSuffix))
|
|
2639
|
-
? 'foreign'
|
|
2640
|
-
: codexRegistration;
|
|
2641
|
-
const claudeState = await readClaudeNativeState({
|
|
2642
|
-
pluginName: '__marketplace_preflight__',
|
|
2643
|
-
scope: 'user',
|
|
2644
|
-
cwd: options.cwd,
|
|
2645
|
-
env: options.env,
|
|
2646
|
-
marketplaceName: options.marketplaceName,
|
|
2647
|
-
marketplaceRoot: options.marketplaceRoot,
|
|
2648
|
-
});
|
|
2649
|
-
const claude = claudeState.marketplaceState === 'absent'
|
|
2650
|
-
&& claudeState.marketplaceConsumerEvidence
|
|
2651
|
-
? 'foreign'
|
|
2652
|
-
: claudeState.marketplaceState;
|
|
2653
|
-
return { codex, claude };
|
|
2654
|
-
}
|
|
2655
|
-
function createClaudeMarketplaceComponent(options) {
|
|
2656
|
-
return {
|
|
2657
|
-
kind: 'shared-config',
|
|
2658
|
-
identity: ownerIdentity(options.pluginName, `marketplace-${options.marketplaceName}`, 'claude', options.scope),
|
|
2659
|
-
label: `${resolveClaudePaths(options.cwd, options.scope, options.env).settingsPath}#marketplaces.${options.marketplaceName}`,
|
|
2660
|
-
locator: {
|
|
2661
|
-
kind: 'claude-marketplace',
|
|
2662
|
-
marketplaceName: options.marketplaceName,
|
|
2663
|
-
marketplaceRoot: options.marketplaceRoot,
|
|
2664
|
-
desired: options.desired,
|
|
2665
|
-
},
|
|
2666
|
-
};
|
|
2667
|
-
}
|
|
2668
|
-
const nativeSkillRenderPreparationCaches = new WeakMap();
|
|
2669
|
-
function nativeSkillRenderPreparationCache(context, platform) {
|
|
2670
|
-
let platforms = nativeSkillRenderPreparationCaches.get(context);
|
|
2671
|
-
if (!platforms) {
|
|
2672
|
-
platforms = new Map();
|
|
2673
|
-
nativeSkillRenderPreparationCaches.set(context, platforms);
|
|
2674
|
-
}
|
|
2675
|
-
let cache = platforms.get(platform);
|
|
2676
|
-
if (!cache) {
|
|
2677
|
-
cache = new WeakMap();
|
|
2678
|
-
platforms.set(platform, cache);
|
|
2679
|
-
}
|
|
2680
|
-
return cache;
|
|
2681
|
-
}
|
|
2682
|
-
function nativeSkillRenderTargets(plugin, platform) {
|
|
2683
|
-
return (plugin.manifest.artifacts?.targets ?? []).filter((target) => target.platform === platform && target.target === `${platform}.skill`);
|
|
2684
|
-
}
|
|
2685
|
-
function pluginHasCodexNativeSkillSurface(plugin) {
|
|
2686
|
-
return plugin.manifest.skills !== undefined
|
|
2687
|
-
|| codexNativeRenderTargets(plugin).length > 0;
|
|
2688
|
-
}
|
|
2689
|
-
async function resolveSensitiveUserConfigValues(plugin, env, referencePlugins, platform = 'codex') {
|
|
2690
|
-
const hasSensitiveFields = Object.values(plugin.manifest.config ? selectPluginConfigProfile(plugin.manifest.config, platform).fields : {}).some((field) => field.sensitive === true);
|
|
2691
|
-
if (!hasSensitiveFields)
|
|
2692
|
-
return [];
|
|
2693
|
-
const config = await resolveArtifactRenderConfig({
|
|
2694
|
-
sourceId: plugin.sourceId,
|
|
2695
|
-
sourceIdentity: plugin.sourceIdentity,
|
|
2696
|
-
pluginName: plugin.manifest.name,
|
|
2697
|
-
manifest: plugin.manifest,
|
|
2698
|
-
platform,
|
|
2699
|
-
referencePlugins,
|
|
2700
|
-
scope: 'user',
|
|
2701
|
-
cwd: plugin.rootDir,
|
|
2702
|
-
env,
|
|
2703
|
-
});
|
|
2704
|
-
return collectSensitivePluginConfigValues(plugin.manifest, config.values, platform);
|
|
2705
|
-
}
|
|
2706
|
-
async function assertNoSensitiveValuesInNativeSkillPayload(options) {
|
|
2707
|
-
if (options.sensitiveValues.length === 0)
|
|
2708
|
-
return;
|
|
2709
|
-
const platform = options.platform ?? 'codex';
|
|
2710
|
-
if (!await codexPayloadPathSafe(options.payloadRoot, options.allowedRoot)) {
|
|
2711
|
-
throw new Error('Codex native sensitive scan payload path is unsafe.');
|
|
2712
|
-
}
|
|
2713
|
-
const codexManifestPath = path.join(options.payloadRoot, `.${platform}-plugin`, 'plugin.json');
|
|
2714
|
-
const codexManifestStats = await lstatCodexResidueIfPresent(codexManifestPath);
|
|
2715
|
-
if (!codexManifestStats?.isFile()) {
|
|
2716
|
-
throw new Error('Codex native sensitive scan manifest is missing or unsafe.');
|
|
2717
|
-
}
|
|
2718
|
-
const codexManifest = await fs.readJson(codexManifestPath).catch(() => null);
|
|
2719
|
-
if (!codexManifest
|
|
2720
|
-
|| codexManifest.name !== options.plugin.manifest.name
|
|
2721
|
-
|| codexManifest.version !== options.plugin.manifest.version) {
|
|
2722
|
-
throw new Error('Codex native sensitive scan manifest identity is invalid.');
|
|
2723
|
-
}
|
|
2724
|
-
const rawSkillsRoot = codexManifest.skills;
|
|
2725
|
-
if (rawSkillsRoot !== undefined) {
|
|
2726
|
-
if (typeof rawSkillsRoot !== 'string' || rawSkillsRoot.trim() === '') {
|
|
2727
|
-
throw new Error('Codex native sensitive scan Skills root is invalid.');
|
|
2728
|
-
}
|
|
2729
|
-
const { root: skillsRoot } = await resolveNativeSkillsRoot(options.payloadRoot, rawSkillsRoot, platform);
|
|
2730
|
-
const skillsRootStats = await lstatCodexResidueIfPresent(skillsRoot);
|
|
2731
|
-
if (!skillsRootStats?.isDirectory()) {
|
|
2732
|
-
throw new Error('Codex native sensitive scan Skills root is missing or unsafe.');
|
|
2733
|
-
}
|
|
2734
|
-
for (const entry of await fs.readdir(skillsRoot, { withFileTypes: true })) {
|
|
2735
|
-
if (!entry.isDirectory())
|
|
2736
|
-
continue;
|
|
2737
|
-
const skillRoot = path.join(skillsRoot, entry.name);
|
|
2738
|
-
const skillFileStats = await lstatCodexResidueIfPresent(path.join(skillRoot, 'SKILL.md'));
|
|
2739
|
-
if (!skillFileStats)
|
|
2740
|
-
continue;
|
|
2741
|
-
if (!skillFileStats.isFile()) {
|
|
2742
|
-
throw new Error('Codex native sensitive scan Skill entry is unsafe.');
|
|
2743
|
-
}
|
|
2744
|
-
const tree = await readDynamicSkillTree(skillRoot, `${platform}.skill`);
|
|
2745
|
-
if (!tree)
|
|
2746
|
-
continue;
|
|
2747
|
-
const leakedPath = findSensitiveTokenPath(withoutVerifiedRequirementsReceipt(options.plugin, tree.files), options.sensitiveValues);
|
|
2748
|
-
if (leakedPath) {
|
|
2749
|
-
throw new Error(`codexNativeRenderSensitiveValue: Codex native Skill "${entry.name}" exposes ` +
|
|
2750
|
-
`sensitive config in "${leakedPath}".`);
|
|
2751
|
-
}
|
|
2752
|
-
}
|
|
2753
|
-
}
|
|
2754
|
-
const receiptPath = path.join(options.payloadRoot, nativeSkillRenderReceiptPath(platform));
|
|
2755
|
-
const receiptStats = await lstatCodexResidueIfPresent(receiptPath);
|
|
2756
|
-
if (receiptStats) {
|
|
2757
|
-
if (!receiptStats.isFile()) {
|
|
2758
|
-
throw new Error('Codex native sensitive scan render receipt path is unsafe.');
|
|
2759
|
-
}
|
|
2760
|
-
const receiptContent = await fs.readFile(receiptPath);
|
|
2761
|
-
let actualReceipt;
|
|
2762
|
-
try {
|
|
2763
|
-
actualReceipt = parseNativeSkillRenderReceipt(platform, receiptContent.toString('utf8'));
|
|
2764
|
-
}
|
|
2765
|
-
catch {
|
|
2766
|
-
actualReceipt = undefined;
|
|
2767
|
-
}
|
|
2768
|
-
const verified = options.verifiedRenderReceipt
|
|
2769
|
-
&& JSON.stringify(actualReceipt) === JSON.stringify(options.verifiedRenderReceipt);
|
|
2770
|
-
if (!verified) {
|
|
2771
|
-
const receiptLeak = findSensitiveTokenPath({ [nativeSkillRenderReceiptPath(platform)]: receiptContent }, options.sensitiveValues);
|
|
2772
|
-
if (receiptLeak) {
|
|
2773
|
-
throw new Error(`codexNativeRenderSensitiveValue: Codex native render receipt exposes sensitive config in ` +
|
|
2774
|
-
`"${receiptLeak}".`);
|
|
2775
|
-
}
|
|
2776
|
-
}
|
|
2777
|
-
}
|
|
2778
|
-
}
|
|
2779
|
-
async function prepareNativeSkillRender(options) {
|
|
2780
|
-
const requested = options.requestedArtifactIds
|
|
2781
|
-
? new Set(options.requestedArtifactIds)
|
|
2782
|
-
: undefined;
|
|
2783
|
-
const targets = nativeSkillRenderTargets(options.plugin, options.platform)
|
|
2784
|
-
.filter((target) => !requested || requested.has(target.id));
|
|
2785
|
-
if (targets.length === 0)
|
|
2786
|
-
return null;
|
|
2787
|
-
let commandCandidates = [...(options.commandCandidates ?? [])];
|
|
2788
|
-
if (!options.commandCandidates) {
|
|
2789
|
-
for (const declaration of options.plugin.manifest.managedCommands?.packages ?? []) {
|
|
2790
|
-
if (declaration.scope !== 'user' || !declaration.platforms.includes(options.platform))
|
|
2791
|
-
continue;
|
|
2792
|
-
const prepared = await prepareManagedCommandPackage({ ...options, packageKey: declaration.key, scope: 'user', cwd: options.plugin.rootDir });
|
|
2793
|
-
commandCandidates.push({ producer: prepared.producer, sets: prepared.sets });
|
|
2794
|
-
await prepared.cleanup();
|
|
2795
|
-
}
|
|
2796
|
-
}
|
|
2797
|
-
const skillsRelativeRoot = options.platform === 'codex'
|
|
2798
|
-
? await resolveCodexSkillsRelativeRoot(options.plugin)
|
|
2799
|
-
: `claude/${(options.plugin.manifest.skills ?? './skills').replace(/^\.\//u, '')}`;
|
|
2800
|
-
const receiptPath = nativeSkillRenderReceiptPath(options.platform);
|
|
2801
|
-
const nativeReceiptPath = `${'../'.repeat(skillsRelativeRoot.split('/').length + 1)}${receiptPath}`;
|
|
2802
|
-
const renderedArtifacts = [];
|
|
2803
|
-
const receiptTargets = [];
|
|
2804
|
-
const presentSkillKeys = [];
|
|
2805
|
-
let rendererDigest;
|
|
2806
|
-
{
|
|
2807
|
-
const scope = 'user';
|
|
2808
|
-
const group = targets;
|
|
2809
|
-
const rendered = await runArtifactRenderer({
|
|
2810
|
-
referencePlugins: options.referencePlugins,
|
|
2811
|
-
event: 'install',
|
|
2812
|
-
plugin: options.plugin,
|
|
2813
|
-
platform: options.platform,
|
|
2814
|
-
scope,
|
|
2815
|
-
configScope: 'user',
|
|
2816
|
-
cwd: options.plugin.rootDir,
|
|
2817
|
-
commandEnv: options.env,
|
|
2818
|
-
previousArtifacts: [],
|
|
2819
|
-
requestedArtifactIds: [...group.map((target) => target.id), ...getManagedCommandArtifactTargets(options.plugin.manifest).filter((target) => {
|
|
2820
|
-
const producer = target.producer;
|
|
2821
|
-
return producer.kind === 'artifact' && group.some((skill) => skill.id === producer.artifactId);
|
|
2822
|
-
}).map((target) => target.id)],
|
|
2823
|
-
preparedResults: options.preparedResults,
|
|
2824
|
-
scriptTimeoutMs: options.scriptTimeoutMs,
|
|
2825
|
-
signal: options.signal,
|
|
2826
|
-
});
|
|
2827
|
-
rendererDigest = rendered.target.rendererDigest;
|
|
2828
|
-
const validated = validateArtifactPlan({
|
|
2829
|
-
manifest: options.plugin.manifest,
|
|
2830
|
-
plan: rendered.plan,
|
|
2831
|
-
platform: options.platform,
|
|
2832
|
-
scope,
|
|
2833
|
-
requestedArtifactIds: rendered.context.requestedArtifactIds,
|
|
2834
|
-
renderConfig: rendered.context.config,
|
|
2835
|
-
rendererDigest: rendered.target.rendererDigest,
|
|
2836
|
-
manifestDigest: rendered.target.manifestDigest,
|
|
2837
|
-
});
|
|
2838
|
-
for (const artifact of validated.artifacts) {
|
|
2839
|
-
if (artifact.target === 'aw.command-set')
|
|
2840
|
-
continue;
|
|
2841
|
-
if ((artifact.target !== 'codex.skill' && artifact.target !== 'claude.skill')
|
|
2842
|
-
|| artifact.target !== `${options.platform}.skill`) {
|
|
2843
|
-
throw new Error(`Codex native renderer returned non-Skill artifact "${artifact.id}".`);
|
|
2844
|
-
}
|
|
2845
|
-
const sourceDirs = rendered.context.artifactSources.find((entry) => entry.id === artifact.id && entry.target === artifact.target)?.sourceDirs ?? [];
|
|
2846
|
-
const tree = await createDynamicSkillExpectedTree({
|
|
2847
|
-
artifact,
|
|
2848
|
-
sourceDirs,
|
|
2849
|
-
requireReadme: true,
|
|
2850
|
-
requirementsReceipt: requirementsReceipt(options.plugin),
|
|
2851
|
-
sourceRequirementsReceiptPolicy: 'allow',
|
|
2852
|
-
});
|
|
2853
|
-
await injectInstalledRuntimeConfig(tree, rendered.runtimeConfigSnapshots[artifact.id], { nativeReceiptPath });
|
|
2854
|
-
const candidate = await prepareSkillCommandCandidate({ plugin: options.plugin, producer: { kind: 'artifact', artifactId: artifact.id }, platform: options.platform, scope: 'user', cwd: options.plugin.rootDir, tree, artifacts: validated.artifacts });
|
|
2855
|
-
if (candidate)
|
|
2856
|
-
commandCandidates.push(candidate);
|
|
2857
|
-
assertNoSensitiveConfigInFiles(withoutVerifiedRequirementsReceipt(options.plugin, tree.files), collectSensitivePluginConfigValues(options.plugin.manifest, rendered.context.config.values, options.platform), 'artifactRendererSensitiveConfigExposed: Final dynamic Skill contains sensitive config.');
|
|
2858
|
-
const skillKey = artifact.skillKey;
|
|
2859
|
-
renderedArtifacts.push({
|
|
2860
|
-
artifact,
|
|
2861
|
-
skillKey,
|
|
2862
|
-
tree,
|
|
2863
|
-
});
|
|
2864
|
-
if (artifact.state === 'present')
|
|
2865
|
-
presentSkillKeys.push(skillKey);
|
|
2866
|
-
receiptTargets.push({
|
|
2867
|
-
id: artifact.id,
|
|
2868
|
-
skillKey,
|
|
2869
|
-
configDigest: createArtifactConfigDigest({
|
|
2870
|
-
artifact: { ...artifact, refreshKeys: nativeSkillRefreshKeys(options.plugin, artifact) },
|
|
2871
|
-
renderConfig: rendered.context.config,
|
|
2872
|
-
digestSalt: rendered.target.rendererDigest,
|
|
2873
|
-
}),
|
|
2874
|
-
artifactDigest: nativeSkillContentDigest(options.platform, tree),
|
|
2875
|
-
});
|
|
2876
|
-
}
|
|
2877
|
-
}
|
|
2878
|
-
if (!rendererDigest || renderedArtifacts.length !== targets.length) {
|
|
2879
|
-
throw new Error('Codex native renderer did not produce the complete declared target set.');
|
|
2880
|
-
}
|
|
2881
|
-
if (options.prepareCommandReferences)
|
|
2882
|
-
commandCandidates = await options.prepareCommandReferences(renderedArtifacts.map((entry) => entry.tree), commandCandidates);
|
|
2883
|
-
else {
|
|
2884
|
-
const staticSkills = await prepareStaticNativeSkillActions({ plugin: options.plugin, platform: options.platform, scope: 'user', cwd: options.plugin.rootDir, env: options.env, artifacts: [], commandCandidates, signal: options.signal, scriptTimeoutMs: options.scriptTimeoutMs });
|
|
2885
|
-
commandCandidates.push(...staticSkills.candidates);
|
|
2886
|
-
}
|
|
2887
|
-
const commandResolver = await createManagedCommandReferenceResolver({ plugin: options.plugin, platform: options.platform, scope: 'user', cwd: options.plugin.rootDir, env: options.env, candidates: commandCandidates });
|
|
2888
|
-
for (const rendered of renderedArtifacts) {
|
|
2889
|
-
resolveSkillManagedCommandReferences(rendered.tree, commandResolver);
|
|
2890
|
-
const receiptTarget = receiptTargets.find((target) => target.id === rendered.artifact.id);
|
|
2891
|
-
receiptTarget.artifactDigest = nativeSkillContentDigest(options.platform, rendered.tree);
|
|
2892
|
-
}
|
|
2893
|
-
const logicalPluginId = options.plugin.pluginId
|
|
2894
|
-
?? (options.plugin.sourceId ? `${options.plugin.sourceId}/${options.plugin.manifest.name}` : undefined);
|
|
2895
|
-
if (!logicalPluginId || !options.plugin.sourceIdentity) {
|
|
2896
|
-
throw new Error('Codex native render materialization requires namespaced source identity.');
|
|
2897
|
-
}
|
|
2898
|
-
const projection = createCodexNativeRenderProjection({
|
|
2899
|
-
logicalPluginId,
|
|
2900
|
-
sourceIdentity: options.plugin.sourceIdentity,
|
|
2901
|
-
pluginVersion: options.plugin.manifest.version,
|
|
2902
|
-
rendererDigest,
|
|
2903
|
-
targets: receiptTargets,
|
|
2904
|
-
});
|
|
2905
|
-
return {
|
|
2906
|
-
platform: options.platform,
|
|
2907
|
-
commandCandidates,
|
|
2908
|
-
logicalPluginId,
|
|
2909
|
-
sourceIdentity: options.plugin.sourceIdentity,
|
|
2910
|
-
rendererDigest,
|
|
2911
|
-
skillsRelativeRoot,
|
|
2912
|
-
renderedArtifacts,
|
|
2913
|
-
receiptTargets,
|
|
2914
|
-
projection,
|
|
2915
|
-
presentSkillKeys: presentSkillKeys.sort(),
|
|
2916
|
-
targetSkillKeys: targets.map((target) => target.skillKey).sort(),
|
|
2917
|
-
};
|
|
2918
|
-
}
|
|
2919
|
-
function prepareNativeSkillRenderCached(options) {
|
|
2920
|
-
const cache = nativeSkillRenderPreparationCache(options.context, options.platform);
|
|
2921
|
-
let preparation = cache.get(options.plugin);
|
|
2922
|
-
if (!preparation) {
|
|
2923
|
-
preparation = prepareNativeSkillRender({
|
|
2924
|
-
preparedResults: artifactRenderResults(options.context),
|
|
2925
|
-
referencePlugins: options.context.referencePlugins,
|
|
2926
|
-
plugin: options.plugin,
|
|
2927
|
-
platform: options.platform,
|
|
2928
|
-
env: options.context.env,
|
|
2929
|
-
signal: options.context.signal,
|
|
2930
|
-
scriptTimeoutMs: options.scriptTimeoutMs,
|
|
2931
|
-
commandCandidates: options.context.managedCommandCandidates?.get(pluginActionId(options.plugin)),
|
|
2932
|
-
});
|
|
2933
|
-
cache.set(options.plugin, preparation);
|
|
2934
|
-
}
|
|
2935
|
-
return preparation;
|
|
2936
|
-
}
|
|
2937
|
-
async function requirePreparedNativeSkillRender(options) {
|
|
2938
|
-
if (nativeSkillRenderTargets(options.plugin, options.platform).length === 0)
|
|
2939
|
-
return null;
|
|
2940
|
-
const preparation = nativeSkillRenderPreparationCache(options.context, options.platform).get(options.plugin);
|
|
2941
|
-
if (!preparation) {
|
|
2942
|
-
throw new Error('codexNativeRenderPreflightMissing: Codex native renderer was not prepared.');
|
|
2943
|
-
}
|
|
2944
|
-
return preparation;
|
|
2945
|
-
}
|
|
2946
|
-
async function materializeNativeSkillRender(options) {
|
|
2947
|
-
const skillsRoot = path.join(options.stagingRoot, 'plugins', options.plugin.manifest.name, ...options.prepared.skillsRelativeRoot.split('/'));
|
|
2948
|
-
for (const { artifact, skillKey, tree } of options.prepared.renderedArtifacts) {
|
|
2949
|
-
const skillRoot = path.join(skillsRoot, skillKey);
|
|
2950
|
-
if (artifact.state === 'present') {
|
|
2951
|
-
await writeDynamicSkillTree(skillRoot, tree);
|
|
2952
|
-
}
|
|
2953
|
-
else {
|
|
2954
|
-
await fs.remove(skillRoot);
|
|
2955
|
-
}
|
|
2956
|
-
}
|
|
2957
|
-
const platform = options.prepared.platform;
|
|
2958
|
-
await ensureNativeActiveSkillsManifest({
|
|
2959
|
-
plugin: options.plugin,
|
|
2960
|
-
platform,
|
|
2961
|
-
marketplaceRoot: options.stagingRoot,
|
|
2962
|
-
hasRequiredSkills: options.hasStaticSkills || options.prepared.presentSkillKeys.length > 0,
|
|
2963
|
-
relativeSkillsRoot: options.prepared.skillsRelativeRoot,
|
|
2964
|
-
});
|
|
2965
|
-
const pluginRoot = path.join(options.stagingRoot, 'plugins', options.plugin.manifest.name);
|
|
2966
|
-
const payloadDigest = await calculateCodexNativeRenderPayloadDigest(pluginRoot);
|
|
2967
|
-
const receipt = (platform === 'codex' ? createCodexNativeRenderReceipt : createClaudeNativeRenderReceipt)({
|
|
2968
|
-
logicalPluginId: options.prepared.logicalPluginId,
|
|
2969
|
-
sourceIdentity: options.prepared.sourceIdentity,
|
|
2970
|
-
pluginVersion: options.plugin.manifest.version,
|
|
2971
|
-
rendererDigest: options.prepared.rendererDigest,
|
|
2972
|
-
targets: options.prepared.receiptTargets,
|
|
2973
|
-
payloadDigest,
|
|
2974
|
-
});
|
|
2975
|
-
await fs.outputFile(path.join(pluginRoot, nativeSkillRenderReceiptPath(platform)), serializeNativeSkillRenderReceipt(receipt), 'utf8');
|
|
2976
|
-
return {
|
|
2977
|
-
payloadDigest,
|
|
2978
|
-
projection: options.prepared.projection,
|
|
2979
|
-
receipt,
|
|
2980
|
-
presentSkillKeys: options.prepared.presentSkillKeys,
|
|
2981
|
-
targetSkillKeys: options.prepared.targetSkillKeys,
|
|
2982
|
-
};
|
|
2983
|
-
}
|
|
2984
|
-
/**
|
|
2985
|
-
* Materialize only the selected Codex or Claude Skills into an isolated review root.
|
|
2986
|
-
* The caller owns outputRoot and is responsible for its cleanup.
|
|
2987
|
-
*/
|
|
2988
|
-
export async function materializeReviewNativeSkills(options) {
|
|
2989
|
-
if (options.skills.length === 0) {
|
|
2990
|
-
throw new Error('Review materialization requires at least one selected Skill.');
|
|
2991
|
-
}
|
|
2992
|
-
const { prepareIsolatedSkillCommandReferences } = await import('../review/skill-materialization.js');
|
|
2993
|
-
const skillsRoot = path.join(options.outputRoot, 'skills');
|
|
2994
|
-
await fs.ensureDir(skillsRoot);
|
|
2995
|
-
let commandCandidates = [];
|
|
2996
|
-
const staticTrees = [];
|
|
2997
|
-
const declarations = options.plugin.manifest.artifacts?.targets ?? [];
|
|
2998
|
-
const dynamicSelections = options.skills.filter((skill) => skill.targetId !== null);
|
|
2999
|
-
const selectedDeclarations = dynamicSelections.map((selection) => {
|
|
3000
|
-
const matches = declarations.filter((target) => target.id === selection.targetId
|
|
3001
|
-
&& target.platform === options.platform
|
|
3002
|
-
&& target.scopes.includes('user')
|
|
3003
|
-
&& target.skillKey === selection.skill
|
|
3004
|
-
&& target.target === `${options.platform}.skill`);
|
|
3005
|
-
if (matches.length !== 1) {
|
|
3006
|
-
throw new Error(`Selected ${options.platform} Skill target "${selection.targetId}" is missing or ambiguous.`);
|
|
3007
|
-
}
|
|
3008
|
-
return matches[0];
|
|
3009
|
-
});
|
|
3010
|
-
const requiredDeclarations = [...selectedDeclarations];
|
|
3011
|
-
const selectedNames = options.skills.map((skill) => skill.skill);
|
|
3012
|
-
const disabledNativeSkillNames = new Set();
|
|
3013
|
-
if (new Set(selectedNames).size !== selectedNames.length) {
|
|
3014
|
-
throw new Error('Review materialization selected the same Skill more than once.');
|
|
3015
|
-
}
|
|
3016
|
-
for (const selection of options.skills.filter((skill) => skill.targetId === null)) {
|
|
3017
|
-
const sourceRoot = path.join(options.plugin.rootDir, options.platform, 'skills', selection.skill);
|
|
3018
|
-
const destination = path.join(skillsRoot, selection.skill);
|
|
3019
|
-
await fs.copy(sourceRoot, destination, {
|
|
3020
|
-
overwrite: false,
|
|
3021
|
-
errorOnExist: true,
|
|
3022
|
-
dereference: false,
|
|
3023
|
-
});
|
|
3024
|
-
staticTrees.push(await validateSkillDirectory(destination, `${options.platform}.skill`, {
|
|
3025
|
-
requirementsReceiptPolicy: 'allow',
|
|
3026
|
-
}));
|
|
3027
|
-
}
|
|
3028
|
-
const prepareReferences = async (trees, scope, copy, candidates = commandCandidates) => prepareIsolatedSkillCommandReferences({
|
|
3029
|
-
...options, scope, candidates,
|
|
3030
|
-
trees: copy ? trees.map((tree) => ({ ...tree, files: { ...tree.files } })) : trees,
|
|
3031
|
-
});
|
|
3032
|
-
const staticScope = 'user';
|
|
3033
|
-
commandCandidates = await prepareReferences(staticTrees, staticScope, true);
|
|
3034
|
-
const nativeTargetIds = requiredDeclarations.map((target) => target.id);
|
|
3035
|
-
if (nativeTargetIds.length > 0) {
|
|
3036
|
-
const marketplaceRoot = path.join(options.outputRoot, '.native-marketplace');
|
|
3037
|
-
const payloadRoot = path.join(marketplaceRoot, 'plugins', options.plugin.manifest.name);
|
|
3038
|
-
await fs.copy(options.plugin.rootDir, payloadRoot, {
|
|
3039
|
-
overwrite: false,
|
|
3040
|
-
errorOnExist: true,
|
|
3041
|
-
dereference: false,
|
|
3042
|
-
});
|
|
3043
|
-
const prepared = await prepareNativeSkillRender({
|
|
3044
|
-
referencePlugins: options.plugins,
|
|
3045
|
-
plugin: options.plugin,
|
|
3046
|
-
platform: options.platform,
|
|
3047
|
-
env: options.env,
|
|
3048
|
-
requestedArtifactIds: nativeTargetIds,
|
|
3049
|
-
scriptTimeoutMs: options.scriptTimeoutMs,
|
|
3050
|
-
commandCandidates,
|
|
3051
|
-
prepareCommandReferences: (trees, candidates) => prepareReferences(trees, 'user', false, candidates),
|
|
3052
|
-
});
|
|
3053
|
-
if (!prepared) {
|
|
3054
|
-
throw new Error('Selected Codex native Skill targets did not produce a projection.');
|
|
3055
|
-
}
|
|
3056
|
-
commandCandidates = prepared.commandCandidates;
|
|
3057
|
-
const staged = await materializeNativeSkillRender({
|
|
3058
|
-
plugin: options.plugin,
|
|
3059
|
-
stagingRoot: marketplaceRoot,
|
|
3060
|
-
prepared,
|
|
3061
|
-
hasStaticSkills: options.plugin.manifest.skills !== undefined,
|
|
3062
|
-
});
|
|
3063
|
-
await assertNoSensitiveValuesInNativeSkillPayload({
|
|
3064
|
-
plugin: options.plugin,
|
|
3065
|
-
payloadRoot,
|
|
3066
|
-
allowedRoot: marketplaceRoot,
|
|
3067
|
-
platform: options.platform,
|
|
3068
|
-
sensitiveValues: await resolveSensitiveUserConfigValues(options.plugin, options.env, options.plugins, options.platform),
|
|
3069
|
-
verifiedRenderReceipt: staged.receipt,
|
|
3070
|
-
});
|
|
3071
|
-
const presentSkillKeys = new Set(staged.presentSkillKeys);
|
|
3072
|
-
if (options.allowDisabledNativeSkills) {
|
|
3073
|
-
for (const target of requiredDeclarations.filter((entry) => !presentSkillKeys.has(entry.skillKey))) {
|
|
3074
|
-
disabledNativeSkillNames.add(target.skillKey);
|
|
3075
|
-
}
|
|
3076
|
-
}
|
|
3077
|
-
for (const target of requiredDeclarations.filter((entry) => presentSkillKeys.has(entry.skillKey))) {
|
|
3078
|
-
const sourceRoot = path.join(payloadRoot, ...prepared.skillsRelativeRoot.split('/'), target.skillKey);
|
|
3079
|
-
await fs.copy(sourceRoot, path.join(skillsRoot, target.skillKey), {
|
|
3080
|
-
overwrite: false,
|
|
3081
|
-
errorOnExist: true,
|
|
3082
|
-
dereference: false,
|
|
3083
|
-
});
|
|
3084
|
-
await carryRuntimeConfigNativeReceipt(path.join(skillsRoot, target.skillKey), Buffer.from(serializeNativeSkillRenderReceipt(staged.receipt)));
|
|
3085
|
-
}
|
|
3086
|
-
await fs.remove(marketplaceRoot);
|
|
3087
|
-
}
|
|
3088
|
-
commandCandidates = await prepareReferences(staticTrees, staticScope, false);
|
|
3089
|
-
for (const tree of staticTrees) {
|
|
3090
|
-
for (const [relativePath, content] of Object.entries(tree.files)) {
|
|
3091
|
-
if (relativePath.endsWith('.md')) {
|
|
3092
|
-
await fs.writeFile(path.join(skillsRoot, tree.skillKey, ...relativePath.split('/')), content);
|
|
3093
|
-
}
|
|
3094
|
-
}
|
|
3095
|
-
}
|
|
3096
|
-
const skills = [];
|
|
3097
|
-
for (const skill of selectedNames.sort((left, right) => left.localeCompare(right))) {
|
|
3098
|
-
const skillRoot = path.join(skillsRoot, skill);
|
|
3099
|
-
if (disabledNativeSkillNames.has(skill))
|
|
3100
|
-
continue;
|
|
3101
|
-
await validateSkillDirectory(skillRoot, `${options.platform}.skill`, {
|
|
3102
|
-
requirementsReceiptPolicy: 'allow',
|
|
3103
|
-
});
|
|
3104
|
-
await validateRuntimeSkillClosure(skillRoot);
|
|
3105
|
-
skills.push({ skill, path: skillRoot });
|
|
3106
|
-
}
|
|
3107
|
-
return { rootDir: options.outputRoot, skills };
|
|
3108
|
-
}
|
|
3109
|
-
async function mirrorCatalog(catalog, env, target, logicalIdentity, prepareStaging, rematerializedPluginIds = new Set(), rematerializedPluginPlatforms) {
|
|
3110
|
-
if (!target?.sourceId || !target.marketplaceRoot) {
|
|
3111
|
-
const rootDir = resolveAwHome(env);
|
|
3112
|
-
await fs.ensureDir(rootDir);
|
|
3113
|
-
await fs.copy(catalog.rootDir, rootDir, { overwrite: true });
|
|
3114
|
-
await prepareStaging?.(rootDir);
|
|
3115
|
-
return { rootDir, commit: async () => undefined, rollback: async () => undefined };
|
|
3116
|
-
}
|
|
3117
|
-
const awHome = path.resolve(resolveAwHome(env));
|
|
3118
|
-
const destination = target.marketplaceRoot;
|
|
3119
|
-
const parent = path.dirname(destination);
|
|
3120
|
-
if (!await isSafeCodexMarketplaceRoot({
|
|
3121
|
-
awHome,
|
|
3122
|
-
sourceId: target.sourceId,
|
|
3123
|
-
marketplaceRoot: destination,
|
|
3124
|
-
})) {
|
|
3125
|
-
throw new Error(`marketplaceRootInvalid: marketplace root is unsafe: ${destination}`);
|
|
3126
|
-
}
|
|
3127
|
-
if (!await fs.pathExists(parent)) {
|
|
3128
|
-
await fs.mkdir(parent);
|
|
3129
|
-
}
|
|
3130
|
-
if (!await isSafeCodexMarketplaceRoot({
|
|
3131
|
-
awHome,
|
|
3132
|
-
sourceId: target.sourceId,
|
|
3133
|
-
marketplaceRoot: destination,
|
|
3134
|
-
})) {
|
|
3135
|
-
throw new Error(`marketplaceRootInvalid: marketplace root became unsafe: ${destination}`);
|
|
3136
|
-
}
|
|
3137
|
-
const staging = await fs.mkdtemp(path.join(parent, `.${target.sourceId}-staging-`));
|
|
3138
|
-
try {
|
|
3139
|
-
for (const entry of ['.agents', '.claude-plugin', 'plugins']) {
|
|
3140
|
-
await fs.copy(path.join(catalog.rootDir, entry), path.join(staging, entry));
|
|
3141
|
-
}
|
|
3142
|
-
const marketplaceName = target.marketplaceName ?? getNamespacedMarketplaceName(target.sourceId);
|
|
3143
|
-
for (const [platform, manifestPath] of [
|
|
3144
|
-
['codex', path.join(staging, '.agents', 'plugins', 'marketplace.json')],
|
|
3145
|
-
['claude', path.join(staging, '.claude-plugin', 'marketplace.json')],
|
|
3146
|
-
]) {
|
|
3147
|
-
const manifest = await fs.readJson(manifestPath);
|
|
3148
|
-
await fs.writeJson(manifestPath, {
|
|
3149
|
-
...projectMarketplaceManifestForPlatform(manifest, platform),
|
|
3150
|
-
name: marketplaceName,
|
|
3151
|
-
}, { spaces: 2 });
|
|
3152
|
-
}
|
|
3153
|
-
await fs.writeJson(path.join(staging, 'config.json'), {
|
|
3154
|
-
schemaVersion: 2,
|
|
3155
|
-
sourceId: target.sourceId,
|
|
3156
|
-
sourceIdentity: target.sourceIdentity,
|
|
3157
|
-
logicalIdentity,
|
|
3158
|
-
marketplaceName,
|
|
3159
|
-
}, { spaces: 2 });
|
|
3160
|
-
const destinationExists = await fs.lstat(destination).then(() => true, (error) => {
|
|
3161
|
-
if (error.code === 'ENOENT' || error.code === 'ENOTDIR')
|
|
3162
|
-
return false;
|
|
3163
|
-
throw error;
|
|
3164
|
-
});
|
|
3165
|
-
const retainedReceipts = [];
|
|
3166
|
-
if (destinationExists) {
|
|
3167
|
-
await replayNamespacedCodexSkillOverlays({
|
|
3168
|
-
sourceRoot: destination,
|
|
3169
|
-
stagingRoot: staging,
|
|
3170
|
-
sourceId: target.sourceId,
|
|
3171
|
-
sourceIdentity: target.sourceIdentity,
|
|
3172
|
-
marketplaceName,
|
|
3173
|
-
});
|
|
3174
|
-
await replayNamespacedMarketplacePluginProjections({
|
|
3175
|
-
sourceRoot: destination,
|
|
3176
|
-
stagingRoot: staging,
|
|
3177
|
-
sourceId: target.sourceId,
|
|
3178
|
-
sourceIdentity: target.sourceIdentity,
|
|
3179
|
-
marketplaceName,
|
|
3180
|
-
rematerializedPluginIds,
|
|
3181
|
-
rematerializedPluginPlatforms,
|
|
3182
|
-
onPreservedPlatformReceipt: (receipt) => retainedReceipts.push(receipt),
|
|
3183
|
-
});
|
|
3184
|
-
}
|
|
3185
|
-
await prepareStaging?.(staging);
|
|
3186
|
-
for (const receipt of retainedReceipts)
|
|
3187
|
-
await refreshPreservedPlatformReceipt(staging, receipt);
|
|
3188
|
-
const backup = `${destination}.backup-${crypto.randomUUID()}`;
|
|
3189
|
-
if (destinationExists)
|
|
3190
|
-
await fs.move(destination, backup);
|
|
3191
|
-
try {
|
|
3192
|
-
await fs.move(staging, destination);
|
|
3193
|
-
}
|
|
3194
|
-
catch (error) {
|
|
3195
|
-
const backupStats = await fs.lstat(backup).catch((inspectionError) => {
|
|
3196
|
-
if (inspectionError.code === 'ENOENT')
|
|
3197
|
-
return null;
|
|
3198
|
-
throw inspectionError;
|
|
3199
|
-
});
|
|
3200
|
-
const destinationStats = await fs.lstat(destination).catch((inspectionError) => {
|
|
3201
|
-
if (inspectionError.code === 'ENOENT')
|
|
3202
|
-
return null;
|
|
3203
|
-
throw inspectionError;
|
|
3204
|
-
});
|
|
3205
|
-
if (backupStats && !destinationStats) {
|
|
3206
|
-
await fs.move(backup, destination);
|
|
3207
|
-
}
|
|
3208
|
-
throw error;
|
|
3209
|
-
}
|
|
3210
|
-
let state = 'active';
|
|
3211
|
-
return {
|
|
3212
|
-
rootDir: destination,
|
|
3213
|
-
commit: async () => {
|
|
3214
|
-
if (state !== 'active')
|
|
3215
|
-
return;
|
|
3216
|
-
try {
|
|
3217
|
-
await commitMarketplaceGenerationBackup({
|
|
3218
|
-
backupRoot: backup,
|
|
3219
|
-
sourceId: target.sourceId,
|
|
3220
|
-
sourceIdentity: target.sourceIdentity,
|
|
3221
|
-
...(target.marketplaceName ? { marketplaceName: target.marketplaceName } : {}),
|
|
3222
|
-
env,
|
|
3223
|
-
});
|
|
3224
|
-
state = 'committed';
|
|
3225
|
-
}
|
|
3226
|
-
catch (error) {
|
|
3227
|
-
if (error.durableMaterializeCommit === true) {
|
|
3228
|
-
state = 'committed';
|
|
3229
|
-
}
|
|
3230
|
-
throw error;
|
|
3231
|
-
}
|
|
3232
|
-
},
|
|
3233
|
-
rollback: async () => {
|
|
3234
|
-
if (state !== 'active')
|
|
3235
|
-
return;
|
|
3236
|
-
const backupStats = await fs.lstat(backup).catch((error) => {
|
|
3237
|
-
if (error.code === 'ENOENT')
|
|
3238
|
-
return null;
|
|
3239
|
-
throw error;
|
|
3240
|
-
});
|
|
3241
|
-
await fs.remove(destination);
|
|
3242
|
-
if (backupStats)
|
|
3243
|
-
await fs.move(backup, destination);
|
|
3244
|
-
state = 'rolledBack';
|
|
3245
|
-
},
|
|
3246
|
-
};
|
|
3247
|
-
}
|
|
3248
|
-
catch (error) {
|
|
3249
|
-
await fs.remove(staging);
|
|
3250
|
-
throw error;
|
|
3251
|
-
}
|
|
999
|
+
const codexConsumerSuffix = `@${options.marketplaceName}`;
|
|
1000
|
+
const codex = codexRegistration === 'absent'
|
|
1001
|
+
&& Object.keys(codexConfig.snapshot.plugins).some((pluginId) => pluginId.length > codexConsumerSuffix.length && pluginId.endsWith(codexConsumerSuffix))
|
|
1002
|
+
? 'foreign'
|
|
1003
|
+
: codexRegistration;
|
|
1004
|
+
const claudeState = await readClaudeNativeState({
|
|
1005
|
+
pluginName: '__marketplace_preflight__',
|
|
1006
|
+
scope: 'user',
|
|
1007
|
+
cwd: options.cwd,
|
|
1008
|
+
env: options.env,
|
|
1009
|
+
marketplaceName: options.marketplaceName,
|
|
1010
|
+
marketplaceRoot: options.marketplaceRoot,
|
|
1011
|
+
});
|
|
1012
|
+
const claude = claudeState.marketplaceState === 'absent'
|
|
1013
|
+
&& claudeState.marketplaceConsumerEvidence
|
|
1014
|
+
? 'foreign'
|
|
1015
|
+
: claudeState.marketplaceState;
|
|
1016
|
+
return { codex, claude };
|
|
3252
1017
|
}
|
|
3253
|
-
async function applyPlannedOperationAction(action) {
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
throw new Error('Owned artifact action is missing owner or locator data.');
|
|
3258
|
-
}
|
|
3259
|
-
if (action.artifactKind === 'owned-text-file') {
|
|
3260
|
-
if (action.content === undefined)
|
|
3261
|
-
throw new Error('Owned text action is missing content.');
|
|
3262
|
-
const digest = `sha256:${crypto.createHash('sha256').update(action.content).digest('hex')}`;
|
|
3263
|
-
if (digest !== action.contentDigest)
|
|
3264
|
-
throw new Error('Owned text action content digest mismatch.');
|
|
3265
|
-
if (action.sourceContent === undefined)
|
|
3266
|
-
throw new Error('Owned text action is missing source content.');
|
|
3267
|
-
await fs.ensureDir(action.allowedRoot);
|
|
3268
|
-
await writeOwnedTextFile({
|
|
3269
|
-
path: action.path,
|
|
3270
|
-
allowedRoot: action.allowedRoot,
|
|
3271
|
-
identity: action.owner,
|
|
3272
|
-
content: action.sourceContent,
|
|
3273
|
-
});
|
|
3274
|
-
return;
|
|
3275
|
-
}
|
|
3276
|
-
const files = action.files ?? [];
|
|
3277
|
-
const digest = `sha256:${crypto.createHash('sha256').update(JSON.stringify(files)).digest('hex')}`;
|
|
3278
|
-
if (digest !== action.contentDigest)
|
|
3279
|
-
throw new Error('Skill action content digest mismatch.');
|
|
3280
|
-
const treeFiles = {};
|
|
3281
|
-
const fileModes = {};
|
|
3282
|
-
for (const file of files) {
|
|
3283
|
-
const content = Buffer.from(file.contentBase64, 'base64');
|
|
3284
|
-
if (`sha256:${crypto.createHash('sha256').update(content).digest('hex')}` !== file.contentDigest) {
|
|
3285
|
-
throw new Error(`Skill action file digest mismatch: ${file.relativePath}`);
|
|
3286
|
-
}
|
|
3287
|
-
if (file.relativePath !== '.agent-workflows-owner.json')
|
|
3288
|
-
treeFiles[file.relativePath] = content;
|
|
3289
|
-
if (file.mode !== undefined && file.mode !== 0o644 && file.mode !== 0o755)
|
|
3290
|
-
throw new Error('Skill action file mode is invalid.');
|
|
3291
|
-
if (file.mode === 0o755 && file.relativePath !== '.agent-workflows-owner.json')
|
|
3292
|
-
fileModes[file.relativePath] = 0o755;
|
|
3293
|
-
}
|
|
3294
|
-
await writeDynamicSkillTree(action.path, {
|
|
3295
|
-
skillKey: action.owner.artifactKey,
|
|
3296
|
-
files: treeFiles,
|
|
3297
|
-
...(Object.keys(fileModes).length > 0 ? { fileModes } : {}),
|
|
3298
|
-
}, {
|
|
3299
|
-
allowedRoot: action.allowedRoot,
|
|
3300
|
-
identity: action.owner,
|
|
3301
|
-
allowPristineUnowned: action.allowPristineUnowned === true,
|
|
3302
|
-
});
|
|
3303
|
-
return;
|
|
3304
|
-
}
|
|
3305
|
-
case 'updateSharedConfig': {
|
|
3306
|
-
const mutation = action.mutation;
|
|
3307
|
-
switch (mutation.kind) {
|
|
3308
|
-
case 'claude-permissions': {
|
|
3309
|
-
if (action.locator.kind !== 'claude-permissions')
|
|
3310
|
-
throw new Error('Claude permission locator mismatch.');
|
|
3311
|
-
const settings = await readClaudeSettings(action.locator.settingsPath);
|
|
3312
|
-
rebuildClaudePermissions(settings, action.locator.ownerKey, mutation.permissions);
|
|
3313
|
-
await writeClaudeSettings(action.locator.settingsPath, settings);
|
|
3314
|
-
return;
|
|
3315
|
-
}
|
|
3316
|
-
case 'codex-instruction': {
|
|
3317
|
-
if (action.locator.kind !== 'codex-instruction')
|
|
3318
|
-
throw new Error('Codex instruction locator mismatch.');
|
|
3319
|
-
await applyCodexConfigTransactionFile(action.locator.configPath, mutation.block
|
|
3320
|
-
? { upsertManagedInstructionBlock: mutation.block }
|
|
3321
|
-
: { removeManagedInstructionPluginName: action.locator.ownerKey });
|
|
3322
|
-
return;
|
|
3323
|
-
}
|
|
3324
|
-
case 'codex-role-registration': {
|
|
3325
|
-
if (action.locator.kind !== 'codex-role-registration')
|
|
3326
|
-
throw new Error('Codex role locator mismatch.');
|
|
3327
|
-
const locator = action.locator;
|
|
3328
|
-
const registration = {
|
|
3329
|
-
description: mutation.description,
|
|
3330
|
-
configFile: mutation.configFile.split(path.sep).join('/'),
|
|
3331
|
-
};
|
|
3332
|
-
await applyConditionalCodexConfigTransactionFile(locator.configPath, async (snapshot) => {
|
|
3333
|
-
const actual = snapshot.agents[mutation.roleKey];
|
|
3334
|
-
if (actual && !await codexRoleRegistrationOwned({
|
|
3335
|
-
fileIdentity: locator.fileIdentity,
|
|
3336
|
-
configPath: locator.configPath,
|
|
3337
|
-
roleKey: mutation.roleKey,
|
|
3338
|
-
rolePath: locator.rolePath,
|
|
3339
|
-
registration: actual,
|
|
3340
|
-
})) {
|
|
3341
|
-
throw new Error(`Codex agent registration "${mutation.roleKey}" is foreign and cannot be overwritten by plugin "${action.owner.plugin}".`);
|
|
3342
|
-
}
|
|
3343
|
-
return { upsertAgentRegistrations: { [mutation.roleKey]: registration } };
|
|
3344
|
-
});
|
|
3345
|
-
return;
|
|
3346
|
-
}
|
|
3347
|
-
case 'codex-activation':
|
|
3348
|
-
throw new Error('Codex activation must use a setActivation action.');
|
|
3349
|
-
}
|
|
3350
|
-
}
|
|
3351
|
-
case 'setActivation':
|
|
3352
|
-
if (!action.configPath || !action.registration) {
|
|
3353
|
-
throw new Error('Activation action is missing configPath or registration.');
|
|
3354
|
-
}
|
|
3355
|
-
await applyCodexConfigTransactionFile(action.configPath, {
|
|
3356
|
-
upsertPluginActivations: { [action.registration]: action.enabled },
|
|
3357
|
-
});
|
|
3358
|
-
return;
|
|
3359
|
-
default:
|
|
3360
|
-
throw new Error(`Operation action ${action.kind} is not an artifact write action.`);
|
|
1018
|
+
export async function applyPlannedOperationAction(action) {
|
|
1019
|
+
if (action.kind !== 'updateSharedConfig' || action.mutation.kind !== 'claude-permissions'
|
|
1020
|
+
|| action.locator.kind !== 'claude-permissions') {
|
|
1021
|
+
throw new Error('platformContributionUnsupported: expected a Claude permissions contribution.');
|
|
3361
1022
|
}
|
|
1023
|
+
const settings = await readClaudeSettings(action.locator.settingsPath);
|
|
1024
|
+
rebuildClaudePermissions(settings, action.locator.ownerKey, action.mutation.permissions);
|
|
1025
|
+
await writeClaudeSettings(action.locator.settingsPath, settings);
|
|
3362
1026
|
}
|
|
3363
1027
|
function createNativeDriver(options) {
|
|
3364
1028
|
const runner = options.context.nativeCliRunner;
|
|
3365
|
-
const nativeBindingRecoveryEvidence = new WeakMap();
|
|
3366
|
-
const captureNativeBindingRecoveryEvidence = async (target, producers) => {
|
|
3367
|
-
const captured = nativeBindingRecoveryEvidence.get(target);
|
|
3368
|
-
if (captured)
|
|
3369
|
-
return captured;
|
|
3370
|
-
const evidence = [];
|
|
3371
|
-
const finish = () => {
|
|
3372
|
-
nativeBindingRecoveryEvidence.set(target, evidence);
|
|
3373
|
-
return evidence;
|
|
3374
|
-
};
|
|
3375
|
-
const nativeProducers = producers.filter(({ producer }) => producer.sourceId === target.identity.sourceId
|
|
3376
|
-
&& producer.sourceIdentity === target.identity.sourceIdentity
|
|
3377
|
-
&& producer.pluginName === target.identity.pluginName
|
|
3378
|
-
&& producer.platform === target.identity.platform
|
|
3379
|
-
&& producer.scope === 'user' && producer.projectRoot === null
|
|
3380
|
-
&& producer.kind !== 'package');
|
|
3381
|
-
if (nativeProducers.length === 0)
|
|
3382
|
-
return finish();
|
|
3383
|
-
const marketplaceRoot = target.identity.marketplaceRoot ?? resolveAwHome(options.context.env);
|
|
3384
|
-
const marketplaceName = target.identity.marketplaceName ?? MARKETPLACE_NAME;
|
|
3385
|
-
const marketplace = await readStrictNamespacedMarketplaceRoot({
|
|
3386
|
-
rootDir: marketplaceRoot, sourceId: target.identity.sourceId,
|
|
3387
|
-
sourceIdentity: target.identity.sourceIdentity, marketplaceName,
|
|
3388
|
-
});
|
|
3389
|
-
if (!marketplace)
|
|
3390
|
-
return finish();
|
|
3391
|
-
const pluginRoot = await assertSafeNamespacedMarketplacePluginRoot(marketplaceRoot, target.identity.pluginName);
|
|
3392
|
-
const manifest = await readNativeSkillProjectionManifest(path.join(pluginRoot, `.${target.identity.platform}-plugin`, 'plugin.json'));
|
|
3393
|
-
if (manifest.state === 'unsafe' || manifest.state === 'unreadable') {
|
|
3394
|
-
throw new Error('commandOwnerMismatch: the previous Native platform manifest cannot authorize binding recovery.');
|
|
3395
|
-
}
|
|
3396
|
-
if (manifest.state !== 'present')
|
|
3397
|
-
return finish();
|
|
3398
|
-
if (manifest.value.name !== target.identity.pluginName) {
|
|
3399
|
-
throw new Error('commandOwnerMismatch: the previous Native platform belongs to another plugin.');
|
|
3400
|
-
}
|
|
3401
|
-
if (typeof manifest.value.skills !== 'string')
|
|
3402
|
-
return finish();
|
|
3403
|
-
const { root: skillsRoot } = await resolveNativeSkillsRoot(pluginRoot, manifest.value.skills, target.identity.platform);
|
|
3404
|
-
const dynamic = nativeProducers.some(({ producer }) => producer.kind === 'artifact')
|
|
3405
|
-
? await resolveNativeSkillRenderExpectedEvidence({
|
|
3406
|
-
plugin: target.plugin, platform: target.identity.platform,
|
|
3407
|
-
referencePlugins: options.context.referencePlugins,
|
|
3408
|
-
marketplaceRoot, marketplaceName, env: options.context.env,
|
|
3409
|
-
})
|
|
3410
|
-
: undefined;
|
|
3411
|
-
if (dynamic?.state === 'issue' && dynamic.reason !== 'damaged') {
|
|
3412
|
-
throw new Error(`commandOwnerMismatch: previous Native evidence is ${dynamic.reason}: ${dynamic.diagnostic}.`);
|
|
3413
|
-
}
|
|
3414
|
-
for (const { producer } of nativeProducers) {
|
|
3415
|
-
const skillKey = producer.kind === 'static-skill' ? producer.key
|
|
3416
|
-
: dynamic?.state === 'present'
|
|
3417
|
-
? dynamic.receipt.targets.find((entry) => entry.id === producer.key)?.skillKey
|
|
3418
|
-
: undefined;
|
|
3419
|
-
if (!skillKey)
|
|
3420
|
-
continue;
|
|
3421
|
-
const resourceRoot = path.join(skillsRoot, skillKey);
|
|
3422
|
-
if (!await lstatIfPresent(path.join(resourceRoot, COMMAND_PRODUCER_RECORD_FILE)))
|
|
3423
|
-
continue;
|
|
3424
|
-
evidence.push(await captureManagedCommandBindingRecoveryEvidence({
|
|
3425
|
-
producer, resourceRoot, env: options.context.env,
|
|
3426
|
-
}));
|
|
3427
|
-
}
|
|
3428
|
-
return finish();
|
|
3429
|
-
};
|
|
3430
|
-
const preflightCommandBindings = async (targets) => {
|
|
3431
|
-
const producers = [];
|
|
3432
|
-
for (const target of targets)
|
|
3433
|
-
for (const action of target.operationActions ?? []) {
|
|
3434
|
-
if (action.kind === 'syncManagedCommandPackage') {
|
|
3435
|
-
producers.push({ producer: action.producer, sets: action.sets, nativeTools: action.nativeTools });
|
|
3436
|
-
}
|
|
3437
|
-
else if (action.kind === 'materializeNativeSkill'
|
|
3438
|
-
|| (action.kind === 'writeOwnedArtifact' && action.artifactKind === 'skill-directory')) {
|
|
3439
|
-
const file = action.files?.find((entry) => entry.relativePath === COMMAND_PRODUCER_RECORD_FILE);
|
|
3440
|
-
if (file)
|
|
3441
|
-
producers.push(normalizeInstalledCommandProducer(JSON.parse(Buffer.from(file.contentBase64, 'base64').toString('utf8'))));
|
|
3442
|
-
}
|
|
3443
|
-
}
|
|
3444
|
-
const captured = targets.flatMap((target) => nativeBindingRecoveryEvidence.get(target) ?? []);
|
|
3445
|
-
try {
|
|
3446
|
-
await assertManagedCommandBindingIdentities({ producers, bindingRecoveryEvidence: captured, env: options.context.env });
|
|
3447
|
-
}
|
|
3448
|
-
catch (error) {
|
|
3449
|
-
if (!(error instanceof ManagedCommandError) || error.code !== 'commandBindingInvalid')
|
|
3450
|
-
throw error;
|
|
3451
|
-
const needsRecovery = [];
|
|
3452
|
-
for (const producer of producers) {
|
|
3453
|
-
try {
|
|
3454
|
-
await assertManagedCommandBindingIdentities({ producers: [producer], bindingRecoveryEvidence: captured, env: options.context.env });
|
|
3455
|
-
}
|
|
3456
|
-
catch (issue) {
|
|
3457
|
-
if (!(issue instanceof ManagedCommandError) || issue.code !== 'commandBindingInvalid')
|
|
3458
|
-
throw issue;
|
|
3459
|
-
needsRecovery.push(producer);
|
|
3460
|
-
}
|
|
3461
|
-
}
|
|
3462
|
-
const bindingRecoveryEvidence = (await Promise.all(targets.map((target) => captureNativeBindingRecoveryEvidence(target, needsRecovery)))).flat();
|
|
3463
|
-
await assertManagedCommandBindingIdentities({ producers, bindingRecoveryEvidence, env: options.context.env });
|
|
3464
|
-
}
|
|
3465
|
-
};
|
|
3466
1029
|
const revokeAtRoot = async (root, recursive = false, platform) => {
|
|
3467
1030
|
const listed = await listManagedCommands(options.context.env);
|
|
3468
1031
|
const producers = new Map();
|
|
@@ -3530,73 +1093,9 @@ function createNativeDriver(options) {
|
|
|
3530
1093
|
}
|
|
3531
1094
|
};
|
|
3532
1095
|
const currentCodexManager = () => options.context.codexManager;
|
|
3533
|
-
const requireClaudeActivationOnlyProvider = async (target) => {
|
|
3534
|
-
const marketplaceName = target.identity.marketplaceName ?? MARKETPLACE_NAME;
|
|
3535
|
-
const marketplaceRoot = target.identity.marketplaceRoot ?? resolveAwHome(options.context.env);
|
|
3536
|
-
const marketplace = await readStrictNamespacedMarketplaceRoot({
|
|
3537
|
-
trustedMarketplaceRoot: path.join(resolveAwHome(options.context.env), 'marketplaces'),
|
|
3538
|
-
rootDir: marketplaceRoot,
|
|
3539
|
-
});
|
|
3540
|
-
if (!marketplace
|
|
3541
|
-
|| marketplace.config.sourceId !== target.identity.sourceId
|
|
3542
|
-
|| marketplace.config.sourceIdentity !== target.identity.sourceIdentity
|
|
3543
|
-
|| marketplace.config.marketplaceName !== marketplaceName) {
|
|
3544
|
-
throw new Error('nativeActivationOnlyRequiresHealthySharedPackage: the Claude marketplace owner does not match the requested source.');
|
|
3545
|
-
}
|
|
3546
|
-
const provider = await readClaudeNativeState({
|
|
3547
|
-
pluginName: target.identity.pluginName,
|
|
3548
|
-
scope: 'user',
|
|
3549
|
-
cwd: target.identity.cwd,
|
|
3550
|
-
env: options.context.env,
|
|
3551
|
-
marketplaceName,
|
|
3552
|
-
marketplaceRoot,
|
|
3553
|
-
});
|
|
3554
|
-
if (provider.marketplaceDeclaredState !== 'canonical'
|
|
3555
|
-
|| provider.marketplaceMaterializedState !== 'canonical'
|
|
3556
|
-
|| provider.pluginState !== 'present'
|
|
3557
|
-
|| !provider.pluginEnabled
|
|
3558
|
-
|| provider.pluginVersions.length === 0
|
|
3559
|
-
|| provider.pluginVersions.some((version) => version !== target.identity.pluginVersion)) {
|
|
3560
|
-
throw new Error('nativeActivationOnlyRequiresHealthySharedPackage: an enabled current User Claude provider is required.');
|
|
3561
|
-
}
|
|
3562
|
-
const pluginRoot = await assertSafeNamespacedMarketplacePluginRoot(marketplaceRoot, target.identity.pluginName);
|
|
3563
|
-
if (!await codexPayloadPathSafe(pluginRoot, marketplaceRoot)) {
|
|
3564
|
-
throw new Error('nativeActivationOnlyRequiresHealthySharedPackage: the Claude package has an unsafe payload path.');
|
|
3565
|
-
}
|
|
3566
|
-
const installed = await readPluginManifest(pluginRoot, { mode: 'bundle' });
|
|
3567
|
-
const platformManifest = await readNativeSkillProjectionManifest(path.join(pluginRoot, '.claude-plugin', 'plugin.json'));
|
|
3568
|
-
if (installed.manifest.name !== target.identity.pluginName
|
|
3569
|
-
|| installed.manifest.version !== target.identity.pluginVersion
|
|
3570
|
-
|| platformManifest.state !== 'present'
|
|
3571
|
-
|| platformManifest.value.name !== target.identity.pluginName
|
|
3572
|
-
|| platformManifest.value.version !== target.identity.pluginVersion) {
|
|
3573
|
-
throw new Error('nativeActivationOnlyRequiresHealthySharedPackage: the Claude package manifest is missing or outdated.');
|
|
3574
|
-
}
|
|
3575
|
-
if (nativeSkillRenderTargets(target.plugin, 'claude').length > 0) {
|
|
3576
|
-
const evidence = await resolveNativeSkillRenderExpectedEvidence({
|
|
3577
|
-
plugin: target.plugin, platform: 'claude', referencePlugins: options.context.referencePlugins,
|
|
3578
|
-
marketplaceRoot, marketplaceName, env: options.context.env,
|
|
3579
|
-
});
|
|
3580
|
-
if (evidence.state !== 'present' || evidence.sourceProjection !== 'current') {
|
|
3581
|
-
throw new Error('nativeActivationOnlyRequiresHealthySharedPackage: the Claude Skill projection is not current.');
|
|
3582
|
-
}
|
|
3583
|
-
}
|
|
3584
|
-
const selected = await readClaudeNativeState({
|
|
3585
|
-
pluginName: target.identity.pluginName, scope: target.identity.scope,
|
|
3586
|
-
cwd: target.identity.cwd, env: options.context.env, marketplaceName, marketplaceRoot,
|
|
3587
|
-
});
|
|
3588
|
-
if (selected.marketplaceState === 'foreign' || selected.pluginState === 'foreign') {
|
|
3589
|
-
throw new Error('externalOwnershipPresent: the Claude activation target belongs to a foreign marketplace.');
|
|
3590
|
-
}
|
|
3591
|
-
return selected;
|
|
3592
|
-
};
|
|
3593
|
-
const nativeGroupPreparations = new Map();
|
|
3594
|
-
const nativeGroupPublications = new Map();
|
|
3595
|
-
const nativeTargetPreparations = new WeakMap();
|
|
3596
1096
|
const codexNativeStates = new Map();
|
|
3597
1097
|
const pendingCodexNativeStates = new Map();
|
|
3598
1098
|
const codexMutationMarketplaces = new Set();
|
|
3599
|
-
const committedNativeGroups = new Set();
|
|
3600
1099
|
let nativeMarketplaceEligibleTargets;
|
|
3601
1100
|
let deferredPostchecks = [];
|
|
3602
1101
|
const nativeGroupKey = (target) => [
|
|
@@ -3613,10 +1112,6 @@ function createNativeDriver(options) {
|
|
|
3613
1112
|
return options.targets.filter((candidate) => nativeGroupKey(candidate) === key
|
|
3614
1113
|
&& (nativeMarketplaceEligibleTargets?.has(candidate) ?? true));
|
|
3615
1114
|
};
|
|
3616
|
-
const asNativeGroupFailure = (error) => {
|
|
3617
|
-
const result = error instanceof Error ? error : new Error(String(error));
|
|
3618
|
-
return Object.assign(result, { nativeMarketplaceGroupFailure: true });
|
|
3619
|
-
};
|
|
3620
1115
|
const findTarget = (component) => {
|
|
3621
1116
|
const target = options.targets.find((entry) => entry.identity.pluginName === component.identity.plugin
|
|
3622
1117
|
&& entry.identity.sourceId === component.identity.sourceId
|
|
@@ -3634,152 +1129,19 @@ function createNativeDriver(options) {
|
|
|
3634
1129
|
: { observationSession: options.context.codexObservationSession }),
|
|
3635
1130
|
});
|
|
3636
1131
|
const prepareNativeGroup = async (target) => {
|
|
3637
|
-
const
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
const
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
const nativePluginIds = [...new Set(codexMembers.flatMap((candidate) => candidate.ownedComponents.flatMap((component) => component.kind === 'native-plugin' ? [component.pluginId] : [])))].sort();
|
|
3649
|
-
for (const pluginId of nativePluginIds) {
|
|
3650
|
-
const member = codexMembers.find((candidate) => candidate.ownedComponents.some((component) => component.kind === 'native-plugin' && component.pluginId === pluginId));
|
|
3651
|
-
const registration = await inspectCodexPluginRegistrationLive({
|
|
3652
|
-
pluginId,
|
|
3653
|
-
cwd: member.identity.cwd,
|
|
3654
|
-
env: options.context.env,
|
|
3655
|
-
nativeCliRunner: runner,
|
|
3656
|
-
manager: currentCodexManager(),
|
|
3657
|
-
scope: observationScope,
|
|
3658
|
-
observationSession: options.context.codexObservationSession,
|
|
3659
|
-
});
|
|
3660
|
-
codexNativeStates.set(codexStateKey(member, pluginId), requireObservedCodexNativeState(registration.observation, 'native group precheck') === 'installed' ? 'present' : 'absent');
|
|
3661
|
-
}
|
|
3662
|
-
}
|
|
3663
|
-
if (materializing.length === 0)
|
|
3664
|
-
return;
|
|
3665
|
-
await preflightCommandBindings(materializing);
|
|
3666
|
-
const first = materializing[0];
|
|
3667
|
-
if (!first.catalog)
|
|
3668
|
-
throw new Error('Missing rebuild target catalog data.');
|
|
3669
|
-
const catalogRoot = path.resolve(first.catalog.rootDir);
|
|
3670
|
-
if (materializing.some((candidate) => !candidate.catalog || path.resolve(candidate.catalog.rootDir) !== catalogRoot)) {
|
|
3671
|
-
throw new Error('nativeMarketplaceGroupInvalid: grouped targets do not share one Catalog root.');
|
|
3672
|
-
}
|
|
3673
|
-
const materializationTargets = [...materializing].sort((left, right) => [
|
|
3674
|
-
left.identity.pluginId ?? left.identity.pluginName,
|
|
3675
|
-
left.identity.scope,
|
|
3676
|
-
left.identity.cwd,
|
|
3677
|
-
].join('\0').localeCompare([
|
|
3678
|
-
right.identity.pluginId ?? right.identity.pluginName,
|
|
3679
|
-
right.identity.scope,
|
|
3680
|
-
right.identity.cwd,
|
|
3681
|
-
].join('\0'), 'en'));
|
|
3682
|
-
const requestedPlatforms = new Map();
|
|
3683
|
-
for (const candidate of materializationTargets) {
|
|
3684
|
-
const pluginId = candidate.identity.pluginId ?? `${candidate.identity.sourceId}/${candidate.identity.pluginName}`;
|
|
3685
|
-
const platforms = requestedPlatforms.get(pluginId) ?? new Set();
|
|
3686
|
-
platforms.add(candidate.identity.platform);
|
|
3687
|
-
requestedPlatforms.set(pluginId, platforms);
|
|
3688
|
-
}
|
|
3689
|
-
const transaction = await mirrorCatalog(first.catalog, options.context.env, first.identity, first.plugin.catalogLogicalIdentity, async (stagingRoot) => {
|
|
3690
|
-
const renderedReceipts = [];
|
|
3691
|
-
for (const candidate of materializationTargets) {
|
|
3692
|
-
for (const action of candidate.operationActions ?? []) {
|
|
3693
|
-
if (action.kind !== 'materializeNativeSkill' || action.artifactId !== undefined)
|
|
3694
|
-
continue;
|
|
3695
|
-
const skillsRoot = path.join(stagingRoot, 'plugins', candidate.identity.pluginName, action.platform, candidate.plugin.manifest.skills.replace(/^\.\//u, ''), action.skillKey);
|
|
3696
|
-
if (`sha256:${crypto.createHash('sha256').update(JSON.stringify(action.files)).digest('hex')}` !== action.contentDigest)
|
|
3697
|
-
throw new Error('commandResourceInvalid: prepared static Skill snapshot changed.');
|
|
3698
|
-
for (const file of action.files) {
|
|
3699
|
-
const content = Buffer.from(file.contentBase64, 'base64');
|
|
3700
|
-
if (`sha256:${crypto.createHash('sha256').update(content).digest('hex')}` !== file.contentDigest)
|
|
3701
|
-
throw new Error('commandResourceInvalid: prepared static Skill file digest changed.');
|
|
3702
|
-
if (file.mode !== undefined && file.mode !== 0o644 && file.mode !== 0o755)
|
|
3703
|
-
throw new Error('Skill action file mode is invalid.');
|
|
3704
|
-
const destination = path.join(skillsRoot, ...file.relativePath.split('/'));
|
|
3705
|
-
await fs.outputFile(destination, content);
|
|
3706
|
-
await fs.chmod(destination, file.mode ?? 0o644);
|
|
3707
|
-
}
|
|
3708
|
-
}
|
|
3709
|
-
const platform = candidate.identity.platform;
|
|
3710
|
-
const hasStaticSkills = candidate.plugin.manifest.skills !== undefined;
|
|
3711
|
-
const preparedNativeRender = await requirePreparedNativeSkillRender({
|
|
3712
|
-
context: options.context,
|
|
3713
|
-
plugin: candidate.plugin,
|
|
3714
|
-
platform,
|
|
3715
|
-
});
|
|
3716
|
-
const nativeRender = preparedNativeRender
|
|
3717
|
-
? await materializeNativeSkillRender({
|
|
3718
|
-
plugin: candidate.plugin,
|
|
3719
|
-
stagingRoot,
|
|
3720
|
-
prepared: preparedNativeRender,
|
|
3721
|
-
hasStaticSkills,
|
|
3722
|
-
})
|
|
3723
|
-
: null;
|
|
3724
|
-
if (nativeRender)
|
|
3725
|
-
renderedReceipts.push({ pluginName: candidate.identity.pluginName, receipt: nativeRender.receipt });
|
|
3726
|
-
if (!nativeRender && platform === 'codex') {
|
|
3727
|
-
await ensureCodexActiveSkillsManifest({
|
|
3728
|
-
plugin: candidate.plugin,
|
|
3729
|
-
marketplaceRoot: stagingRoot,
|
|
3730
|
-
hasRequiredSkills: hasStaticSkills,
|
|
3731
|
-
});
|
|
3732
|
-
}
|
|
3733
|
-
if (hasStaticSkills || nativeSkillRenderTargets(candidate.plugin, platform).length > 0) {
|
|
3734
|
-
await assertNoSensitiveValuesInNativeSkillPayload({
|
|
3735
|
-
plugin: candidate.plugin,
|
|
3736
|
-
platform,
|
|
3737
|
-
payloadRoot: path.join(stagingRoot, 'plugins', candidate.identity.pluginName),
|
|
3738
|
-
allowedRoot: stagingRoot,
|
|
3739
|
-
sensitiveValues: await resolveSensitiveUserConfigValues(candidate.plugin, options.context.env, options.context.referencePlugins, platform),
|
|
3740
|
-
...(nativeRender ? { verifiedRenderReceipt: nativeRender.receipt } : {}),
|
|
3741
|
-
});
|
|
3742
|
-
}
|
|
3743
|
-
}
|
|
3744
|
-
for (const receipt of renderedReceipts)
|
|
3745
|
-
await refreshPreservedPlatformReceipt(stagingRoot, receipt);
|
|
3746
|
-
if (first.identity.sourceId && first.identity.sourceIdentity && first.identity.marketplaceRoot) {
|
|
3747
|
-
nativeGroupPublications.set(key, await deferNativeMarketplacePublications({
|
|
3748
|
-
sourceRoot: first.identity.marketplaceRoot,
|
|
3749
|
-
stagingRoot,
|
|
3750
|
-
sourceId: first.identity.sourceId,
|
|
3751
|
-
sourceIdentity: first.identity.sourceIdentity,
|
|
3752
|
-
marketplaceName: first.identity.marketplaceName ?? MARKETPLACE_NAME,
|
|
3753
|
-
requestedPlatforms,
|
|
3754
|
-
}));
|
|
3755
|
-
}
|
|
3756
|
-
}, new Set(materializationTargets.map((candidate) => candidate.identity.pluginId ?? `${candidate.identity.sourceId}/${candidate.identity.pluginName}`)), requestedPlatforms);
|
|
3757
|
-
try {
|
|
3758
|
-
await transaction.commit();
|
|
3759
|
-
}
|
|
3760
|
-
catch (error) {
|
|
3761
|
-
if (error.durableMaterializeCommit !== true) {
|
|
3762
|
-
try {
|
|
3763
|
-
await transaction.rollback();
|
|
3764
|
-
}
|
|
3765
|
-
catch (rollbackError) {
|
|
3766
|
-
throw new AggregateError([error, rollbackError], 'nativeMarketplaceGroupCommitFailed: marketplace commit and rollback failed.');
|
|
3767
|
-
}
|
|
3768
|
-
}
|
|
3769
|
-
throw error;
|
|
3770
|
-
}
|
|
3771
|
-
committedNativeGroups.add(key);
|
|
3772
|
-
})().catch((error) => {
|
|
3773
|
-
throw asNativeGroupFailure(error);
|
|
3774
|
-
});
|
|
3775
|
-
if (options.operationScopedNativePhases) {
|
|
3776
|
-
nativeGroupPreparations.set(key, preparation);
|
|
3777
|
-
}
|
|
3778
|
-
else {
|
|
3779
|
-
nativeTargetPreparations.set(target, preparation);
|
|
1132
|
+
for (const member of groupTargets(target)) {
|
|
1133
|
+
if (member.identity.platform !== 'codex')
|
|
1134
|
+
continue;
|
|
1135
|
+
for (const component of member.ownedComponents) {
|
|
1136
|
+
if (component.kind !== 'native-plugin')
|
|
1137
|
+
continue;
|
|
1138
|
+
const registration = await inspectCodexPluginRegistrationLive({ pluginId: component.pluginId,
|
|
1139
|
+
cwd: member.identity.cwd, env: options.context.env, nativeCliRunner: runner,
|
|
1140
|
+
manager: currentCodexManager(), scope: observationScopeFor(member),
|
|
1141
|
+
observationSession: options.context.codexObservationSession });
|
|
1142
|
+
codexNativeStates.set(codexStateKey(member, component.pluginId), requireObservedCodexNativeState(registration.observation, 'native cleanup precheck') === 'installed' ? 'present' : 'absent');
|
|
3780
1143
|
}
|
|
3781
1144
|
}
|
|
3782
|
-
await preparation;
|
|
3783
1145
|
};
|
|
3784
1146
|
const inspectCodexMarketplace = async (component) => {
|
|
3785
1147
|
if (component.locator.kind !== 'codex-marketplace')
|
|
@@ -3790,9 +1152,7 @@ function createNativeDriver(options) {
|
|
|
3790
1152
|
const marketplace = config.snapshot.marketplaces[component.locator.marketplaceName];
|
|
3791
1153
|
const canonical = !marketplace
|
|
3792
1154
|
? 'absent'
|
|
3793
|
-
: marketplace.
|
|
3794
|
-
&& !marketplace.sourcePointsToManifest
|
|
3795
|
-
&& path.normalize(marketplace.source ?? '') === path.normalize(component.locator.marketplaceRoot)
|
|
1155
|
+
: isCanonicalCodexMarketplaceRegistration(marketplace, component.locator.marketplaceRoot)
|
|
3796
1156
|
? 'present'
|
|
3797
1157
|
: 'foreign';
|
|
3798
1158
|
if (component.locator.desired) {
|
|
@@ -3873,6 +1233,8 @@ function createNativeDriver(options) {
|
|
|
3873
1233
|
inspectShared: async (component) => {
|
|
3874
1234
|
const locator = component.locator;
|
|
3875
1235
|
switch (locator.kind) {
|
|
1236
|
+
case 'cursor-workspace-hook':
|
|
1237
|
+
return platformOwnership.inspectShared(component);
|
|
3876
1238
|
case 'claude-permissions':
|
|
3877
1239
|
return (await readClaudeSettings(locator.settingsPath)).awGenerated
|
|
3878
1240
|
?.permissions?.[locator.ownerKey] ? 'present' : 'absent';
|
|
@@ -3923,6 +1285,8 @@ function createNativeDriver(options) {
|
|
|
3923
1285
|
removeShared: async (component) => {
|
|
3924
1286
|
const locator = component.locator;
|
|
3925
1287
|
switch (locator.kind) {
|
|
1288
|
+
case 'cursor-workspace-hook':
|
|
1289
|
+
return platformOwnership.removeShared(component);
|
|
3926
1290
|
case 'claude-permissions': {
|
|
3927
1291
|
const settings = await readClaudeSettings(locator.settingsPath);
|
|
3928
1292
|
rebuildClaudePermissions(settings, locator.ownerKey);
|
|
@@ -4052,19 +1416,6 @@ function createNativeDriver(options) {
|
|
|
4052
1416
|
nativeMarketplaceEligibleTargets = new Set(eligibleTargets);
|
|
4053
1417
|
},
|
|
4054
1418
|
prepareNativeMarketplaceGroup: prepareNativeGroup,
|
|
4055
|
-
selectRecoveryCleanupComponents: (target, components) => {
|
|
4056
|
-
if (!committedNativeGroups.has(nativeGroupKey(target)))
|
|
4057
|
-
return components;
|
|
4058
|
-
const marketplaceRoot = path.resolve(target.identity.marketplaceRoot ?? resolveAwHome(options.context.env));
|
|
4059
|
-
return components.filter((component) => {
|
|
4060
|
-
if (!('path' in component))
|
|
4061
|
-
return true;
|
|
4062
|
-
const relative = path.relative(marketplaceRoot, path.resolve(component.path));
|
|
4063
|
-
return relative === '..'
|
|
4064
|
-
|| relative.startsWith(`..${path.sep}`)
|
|
4065
|
-
|| path.isAbsolute(relative);
|
|
4066
|
-
});
|
|
4067
|
-
},
|
|
4068
1419
|
...(options.operationScopedNativePhases ? {
|
|
4069
1420
|
deferPostcheck: (target, postcheck) => {
|
|
4070
1421
|
if (target.identity.platform !== 'codex')
|
|
@@ -4122,62 +1473,31 @@ function createNativeDriver(options) {
|
|
|
4122
1473
|
for (const marketplaceName of marketplaceNames) {
|
|
4123
1474
|
codexMutationMarketplaces.add(marketplaceName);
|
|
4124
1475
|
}
|
|
4125
|
-
|
|
1476
|
+
const changedMarketplaces = [...codexMutationMarketplaces];
|
|
1477
|
+
const marketplaces = [...new Set([...changedMarketplaces, ...deferredPostchecks.flatMap(({ target }) => (target.platformDeployment?.plans ?? []).flatMap((plan) => plan.evidence.layout.marketplaceName
|
|
1478
|
+
&& plan.projections.some((projection) => projection.bundle) ? [plan.evidence.layout.marketplaceName] : []))])].sort();
|
|
1479
|
+
if (marketplaces.length === 0)
|
|
4126
1480
|
return;
|
|
4127
1481
|
const session = options.context.codexObservationSession;
|
|
4128
1482
|
if (!session) {
|
|
4129
1483
|
throw new Error('codexNativeObservationUnavailable: grouped postcheck requires an observation session.');
|
|
4130
1484
|
}
|
|
4131
|
-
const marketplaces = [...codexMutationMarketplaces].sort();
|
|
4132
1485
|
codexMutationMarketplaces.clear();
|
|
4133
|
-
|
|
1486
|
+
// Platform mutations already invalidated and observed their generation.
|
|
1487
|
+
// Only legacy writes still deferred in the dirty set need invalidation.
|
|
1488
|
+
for (const marketplaceName of changedMarketplaces)
|
|
4134
1489
|
session.invalidate(marketplaceName);
|
|
4135
1490
|
await Promise.all(marketplaces.map((marketplaceName) => session.snapshot(marketplaceName, options.context.codexObservationScopeByMarketplace?.get(marketplaceName)
|
|
4136
1491
|
?? (options.targets.some((target) => (nativeMarketplaceEligibleTargets?.has(target) ?? true)
|
|
4137
1492
|
&& target.identity.platform === 'codex'
|
|
4138
|
-
&& (target.
|
|
4139
|
-
|
|
1493
|
+
&& (target.platformDeployment ? target.platformDeployment.plans.some((plan) => plan.evidence.layout.marketplaceName === marketplaceName && plan.binding.scope.kind === 'project')
|
|
1494
|
+
: (target.identity.marketplaceName ?? MARKETPLACE_NAME) === marketplaceName && target.identity.scope === 'project'))
|
|
4140
1495
|
? 'both'
|
|
4141
1496
|
: 'user'))));
|
|
4142
1497
|
},
|
|
4143
1498
|
preflightMutation: async (target) => {
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
await requireClaudeActivationOnlyProvider(target);
|
|
4147
|
-
return;
|
|
4148
|
-
}
|
|
4149
|
-
await preflightCommandBindings([target]);
|
|
4150
|
-
if (!target.codexNativeObservationExpectation
|
|
4151
|
-
&& !target.codexNativeSensitivePreflightRequired)
|
|
4152
|
-
return;
|
|
4153
|
-
const sensitiveValues = pluginHasCodexNativeSkillSurface(target.plugin)
|
|
4154
|
-
? await resolveSensitiveUserConfigValues(target.plugin, options.context.env, options.context.referencePlugins)
|
|
4155
|
-
: [];
|
|
4156
|
-
if (sensitiveValues.length > 0) {
|
|
4157
|
-
await assertNoSensitiveValuesInCanonicalCodexNativePayload({
|
|
4158
|
-
plugin: target.plugin,
|
|
4159
|
-
marketplaceRoot: target.identity.marketplaceRoot ?? resolveAwHome(options.context.env),
|
|
4160
|
-
marketplaceName: target.identity.marketplaceName ?? MARKETPLACE_NAME,
|
|
4161
|
-
env: options.context.env,
|
|
4162
|
-
sensitiveValues,
|
|
4163
|
-
});
|
|
4164
|
-
}
|
|
4165
|
-
if (!target.codexNativeObservationExpectation)
|
|
4166
|
-
return;
|
|
4167
|
-
const pluginId = `${target.identity.pluginName}@${target.identity.marketplaceName ?? MARKETPLACE_NAME}`;
|
|
4168
|
-
const registration = await inspectCodexPluginRegistrationLive({
|
|
4169
|
-
pluginId,
|
|
4170
|
-
cwd: target.identity.cwd,
|
|
4171
|
-
env: options.context.env,
|
|
4172
|
-
nativeCliRunner: runner,
|
|
4173
|
-
manager: currentCodexManager(),
|
|
4174
|
-
scope: observationScopeFor(target),
|
|
4175
|
-
observationSession: options.context.codexObservationSession,
|
|
4176
|
-
});
|
|
4177
|
-
const observed = requireObservedCodexNativeState(registration.observation, 'artifact write precheck');
|
|
4178
|
-
if (target.codexNativeObservationExpectation === 'installed' && observed !== 'installed') {
|
|
4179
|
-
throw new Error('codexNativeExpectedInstalled: artifact write precheck requires the reused Codex plugin to remain installed.');
|
|
4180
|
-
}
|
|
1499
|
+
await assertManagedCommandBindingIdentities({ producers: (target.operationActions ?? []).flatMap((action) => action.kind === 'syncManagedCommandPackage' ? [{ producer: action.producer, sets: action.sets, nativeTools: action.nativeTools }] : []),
|
|
1500
|
+
env: options.context.env });
|
|
4181
1501
|
},
|
|
4182
1502
|
preflightMaterialize: async (target) => {
|
|
4183
1503
|
if (target.identity.sourceId && options.context.expectedCatalogConfigDigest) {
|
|
@@ -4186,36 +1506,10 @@ function createNativeDriver(options) {
|
|
|
4186
1506
|
throw new Error('catalogSourceConflict: catalog source config changed before owner publication.');
|
|
4187
1507
|
}
|
|
4188
1508
|
}
|
|
4189
|
-
if (target.identity.platform === 'claude')
|
|
1509
|
+
if (target.identity.platform === 'claude')
|
|
4190
1510
|
await assertNoClaudeUnboundNativeNameCollision({
|
|
4191
|
-
pluginName: target.identity.pluginName,
|
|
4192
|
-
cwd: target.identity.cwd,
|
|
4193
|
-
env: options.context.env,
|
|
4194
|
-
});
|
|
4195
|
-
return;
|
|
4196
|
-
}
|
|
4197
|
-
const marketplaceName = target.identity.marketplaceName ?? MARKETPLACE_NAME;
|
|
4198
|
-
const marketplaceRoot = target.identity.marketplaceRoot ?? resolveAwHome(options.context.env);
|
|
4199
|
-
const config = await readCodexConfigFile(resolveCodexPaths(target.identity.cwd, 'user', options.context.env).configTomlPath);
|
|
4200
|
-
const marketplace = config.snapshot.marketplaces[marketplaceName];
|
|
4201
|
-
const canonical = marketplace?.sourceType === 'local'
|
|
4202
|
-
&& !marketplace.sourcePointsToManifest
|
|
4203
|
-
&& path.resolve(marketplace.source ?? '') === path.resolve(marketplaceRoot);
|
|
4204
|
-
const expectedPluginId = `${target.identity.pluginName}@${marketplaceName}`;
|
|
4205
|
-
if ((marketplace !== undefined && !canonical)
|
|
4206
|
-
|| (Object.hasOwn(config.snapshot.plugins, expectedPluginId) && !canonical)) {
|
|
4207
|
-
throw new Error(`externalOwnershipPresent: Codex marketplace ${marketplaceName} has a foreign source instead of its canonical namespaced root.`);
|
|
4208
|
-
}
|
|
4209
|
-
if (target.nativeOverlayDesired
|
|
4210
|
-
&& options.targets.some((candidate) => nativeGroupKey(candidate) === nativeGroupKey(target)
|
|
4211
|
-
&& (candidate.writeNativeRequired ?? candidate.requiresNative))) {
|
|
4212
|
-
await prepareNativeSkillRenderCached({
|
|
4213
|
-
context: options.context,
|
|
4214
|
-
plugin: target.plugin,
|
|
4215
|
-
platform: target.identity.platform,
|
|
4216
|
-
scriptTimeoutMs: options.scriptTimeoutMs,
|
|
1511
|
+
pluginName: target.identity.pluginName, cwd: target.identity.cwd, env: options.context.env
|
|
4217
1512
|
});
|
|
4218
|
-
}
|
|
4219
1513
|
},
|
|
4220
1514
|
finalizeCleanup: async (target) => {
|
|
4221
1515
|
for (const action of target.operationActions ?? []) {
|
|
@@ -4275,23 +1569,7 @@ function createNativeDriver(options) {
|
|
|
4275
1569
|
return state.pluginState;
|
|
4276
1570
|
if (!state.pluginEnabled)
|
|
4277
1571
|
return 'partial';
|
|
4278
|
-
|
|
4279
|
-
return 'present';
|
|
4280
|
-
const evidence = await resolveNativeSkillRenderExpectedEvidence({
|
|
4281
|
-
plugin: target.plugin,
|
|
4282
|
-
platform: 'claude',
|
|
4283
|
-
referencePlugins: options.context.referencePlugins,
|
|
4284
|
-
marketplaceRoot: target.identity.marketplaceRoot ?? resolveAwHome(options.context.env),
|
|
4285
|
-
marketplaceName: target.identity.marketplaceName ?? MARKETPLACE_NAME,
|
|
4286
|
-
env: options.context.env,
|
|
4287
|
-
});
|
|
4288
|
-
if (evidence.state === 'issue') {
|
|
4289
|
-
if (evidence.reason === 'unreadable') {
|
|
4290
|
-
throw new Error(`claudeNativeRenderEvidenceUnreadable: ${evidence.diagnostic}`);
|
|
4291
|
-
}
|
|
4292
|
-
return evidence.reason === 'foreign' ? 'foreign' : 'partial';
|
|
4293
|
-
}
|
|
4294
|
-
return evidence.sourceProjection === 'current' ? 'present' : 'partial';
|
|
1572
|
+
return 'present';
|
|
4295
1573
|
}
|
|
4296
1574
|
if (target.identity.platform === 'codex') {
|
|
4297
1575
|
const pluginId = `${target.identity.pluginName}@${target.identity.marketplaceName ?? MARKETPLACE_NAME}`;
|
|
@@ -4407,188 +1685,16 @@ function createNativeDriver(options) {
|
|
|
4407
1685
|
}
|
|
4408
1686
|
}
|
|
4409
1687
|
},
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
if (!target.catalog)
|
|
4413
|
-
throw new Error('Missing rebuild target catalog data.');
|
|
4414
|
-
const marketplaceName = target.identity.marketplaceName ?? MARKETPLACE_NAME;
|
|
4415
|
-
const expectedMarketplaceRoot = target.identity.marketplaceRoot ?? resolveAwHome(options.context.env);
|
|
4416
|
-
if (target.identity.platform === 'codex') {
|
|
4417
|
-
const config = await readCodexConfigFile(resolveCodexPaths(target.identity.cwd, 'user', options.context.env).configTomlPath);
|
|
4418
|
-
const marketplace = config.snapshot.marketplaces[marketplaceName];
|
|
4419
|
-
if (marketplace && (marketplace.sourceType !== 'local'
|
|
4420
|
-
|| marketplace.sourcePointsToManifest
|
|
4421
|
-
|| path.normalize(marketplace.source ?? '') !== path.normalize(expectedMarketplaceRoot))) {
|
|
4422
|
-
throw new Error(`externalOwnershipPresent: Codex marketplace ${marketplaceName} 已由 foreign source 占用,拒绝覆盖。`);
|
|
4423
|
-
}
|
|
4424
|
-
}
|
|
4425
|
-
else {
|
|
4426
|
-
const state = await readClaudeNativeState({
|
|
4427
|
-
pluginName: target.identity.pluginName,
|
|
4428
|
-
scope: target.identity.scope,
|
|
4429
|
-
cwd: target.identity.cwd,
|
|
4430
|
-
env: options.context.env,
|
|
4431
|
-
marketplaceName,
|
|
4432
|
-
marketplaceRoot: expectedMarketplaceRoot,
|
|
4433
|
-
});
|
|
4434
|
-
if (state.marketplaceState === 'foreign') {
|
|
4435
|
-
throw new Error(`Claude marketplace ${marketplaceName} 已由 foreign source 占用,拒绝覆盖。`);
|
|
4436
|
-
}
|
|
4437
|
-
}
|
|
4438
|
-
await prepareNativeGroup(target);
|
|
4439
|
-
const pluginId = `${target.identity.pluginName}@${marketplaceName}`;
|
|
4440
|
-
const publishPreparedPlatform = async () => {
|
|
4441
|
-
await revokeAtRoot(path.join(expectedMarketplaceRoot, 'plugins', target.identity.pluginName), true, target.identity.platform);
|
|
4442
|
-
await nativeGroupPublications.get(nativeGroupKey(target))?.publish(expectedMarketplaceRoot, target.identity.pluginName, target.identity.platform);
|
|
4443
|
-
};
|
|
4444
|
-
if (target.identity.platform === 'codex') {
|
|
4445
|
-
const stateKey = codexStateKey(target, pluginId);
|
|
4446
|
-
const codexRemovalRequired = pendingCodexNativeStates.get(stateKey)
|
|
4447
|
-
?? codexNativeStates.get(stateKey);
|
|
4448
|
-
if (!codexRemovalRequired) {
|
|
4449
|
-
throw new Error('codexNativeObservationUnavailable: native group precheck is missing.');
|
|
4450
|
-
}
|
|
4451
|
-
if (codexRemovalRequired === 'present') {
|
|
4452
|
-
codexMutationMarketplaces.add(marketplaceName);
|
|
4453
|
-
await runObservedCodexMutation({
|
|
4454
|
-
marketplaceName,
|
|
4455
|
-
mutation: () => runNativeCliChecked(buildCodexPluginRemoveInvocation(requireCodexManager(currentCodexManager()), pluginId, target.identity.cwd, options.context.env), runner),
|
|
4456
|
-
});
|
|
4457
|
-
pendingCodexNativeStates.set(stateKey, 'absent');
|
|
4458
|
-
}
|
|
4459
|
-
await publishPreparedPlatform();
|
|
4460
|
-
const config = await readCodexConfigFile(resolveCodexPaths(target.identity.cwd, 'user', options.context.env).configTomlPath);
|
|
4461
|
-
const marketplace = config.snapshot.marketplaces[marketplaceName];
|
|
4462
|
-
if (path.normalize(marketplace?.source ?? '') !== path.normalize(expectedMarketplaceRoot)) {
|
|
4463
|
-
codexMutationMarketplaces.add(marketplaceName);
|
|
4464
|
-
await runObservedCodexMutation({
|
|
4465
|
-
marketplaceName,
|
|
4466
|
-
mutation: () => runNativeCliChecked(buildCodexMarketplaceAddInvocation(requireCodexManager(currentCodexManager()), expectedMarketplaceRoot, target.identity.cwd, options.context.env), runner),
|
|
4467
|
-
});
|
|
4468
|
-
}
|
|
4469
|
-
codexMutationMarketplaces.add(marketplaceName);
|
|
4470
|
-
await runObservedCodexMutation({
|
|
4471
|
-
marketplaceName,
|
|
4472
|
-
mutation: () => runNativeCliChecked(buildCodexPluginAddInvocation(requireCodexManager(currentCodexManager()), pluginId, target.identity.cwd, options.context.env), runner),
|
|
4473
|
-
});
|
|
4474
|
-
pendingCodexNativeStates.set(stateKey, 'present');
|
|
4475
|
-
const installedConfig = await readCodexConfigFile(resolveCodexPaths(target.identity.cwd, 'user', options.context.env).configTomlPath);
|
|
4476
|
-
const installedMarketplace = installedConfig.snapshot.marketplaces[marketplaceName];
|
|
4477
|
-
if (installedMarketplace?.sourceType !== 'local'
|
|
4478
|
-
|| installedMarketplace.sourcePointsToManifest
|
|
4479
|
-
|| path.normalize(installedMarketplace.source ?? '') !== path.normalize(expectedMarketplaceRoot)
|
|
4480
|
-
|| installedConfig.snapshot.plugins[pluginId]?.enabled !== true) {
|
|
4481
|
-
throw new Error(`codexNativeInstallIncomplete: ${pluginId} public config is not canonical and enabled.`);
|
|
4482
|
-
}
|
|
4483
|
-
}
|
|
4484
|
-
else {
|
|
4485
|
-
await publishPreparedPlatform();
|
|
4486
|
-
await runNativeCliChecked({
|
|
4487
|
-
command: 'claude',
|
|
4488
|
-
args: ['plugin', 'marketplace', 'add', expectedMarketplaceRoot, '--scope', target.identity.scope],
|
|
4489
|
-
cwd: target.identity.cwd,
|
|
4490
|
-
env: options.context.env,
|
|
4491
|
-
}, runner);
|
|
4492
|
-
await runNativeCliChecked({
|
|
4493
|
-
command: 'claude',
|
|
4494
|
-
args: ['plugin', 'install', pluginId, '--scope', target.identity.scope],
|
|
4495
|
-
cwd: target.identity.cwd,
|
|
4496
|
-
env: options.context.env,
|
|
4497
|
-
}, runner);
|
|
4498
|
-
await runNativeCliChecked({
|
|
4499
|
-
command: 'claude',
|
|
4500
|
-
args: ['plugin', 'list'],
|
|
4501
|
-
cwd: target.identity.cwd,
|
|
4502
|
-
env: options.context.env,
|
|
4503
|
-
}, runner);
|
|
4504
|
-
const after = await readClaudeNativeState({
|
|
4505
|
-
pluginName: target.identity.pluginName,
|
|
4506
|
-
scope: target.identity.scope,
|
|
4507
|
-
cwd: target.identity.cwd,
|
|
4508
|
-
env: options.context.env,
|
|
4509
|
-
marketplaceName,
|
|
4510
|
-
marketplaceRoot: expectedMarketplaceRoot,
|
|
4511
|
-
});
|
|
4512
|
-
if (after.marketplaceDeclaredState !== 'canonical'
|
|
4513
|
-
|| after.marketplaceMaterializedState !== 'canonical'
|
|
4514
|
-
|| after.pluginState !== 'present'
|
|
4515
|
-
|| !after.pluginEnabled
|
|
4516
|
-
|| !after.pluginVersions.includes(target.identity.pluginVersion)) {
|
|
4517
|
-
throw new Error(`Claude native install postcheck 失败:declaredMarketplace=${after.marketplaceDeclaredState},materializedMarketplace=${after.marketplaceMaterializedState},plugin=${after.pluginState},enabled=${after.pluginEnabled},versions=${after.pluginVersions.join(',')}。`);
|
|
4518
|
-
}
|
|
4519
|
-
}
|
|
4520
|
-
const pluginRoot = path.join(expectedMarketplaceRoot, 'plugins', target.identity.pluginName);
|
|
4521
|
-
if (target.identity.platform === 'codex' || target.operationActions?.some((action) => action.kind === 'materializeNativeSkill' && action.platform === 'claude')) {
|
|
4522
|
-
const relativeRoot = target.identity.platform === 'codex'
|
|
4523
|
-
? await resolveCodexSkillsRelativeRoot(target.plugin, expectedMarketplaceRoot)
|
|
4524
|
-
: await resolveClaudeSkillsRelativeRoot(pluginRoot);
|
|
4525
|
-
const skillsRoot = path.join(pluginRoot, relativeRoot);
|
|
4526
|
-
for (const entry of await fs.readdir(skillsRoot, { withFileTypes: true }).catch(() => [])) {
|
|
4527
|
-
if (!entry.isDirectory())
|
|
4528
|
-
continue;
|
|
4529
|
-
const resourceRoot = path.join(skillsRoot, entry.name);
|
|
4530
|
-
const installed = await readInstalledCommandProducer(resourceRoot).catch(() => null);
|
|
4531
|
-
if (!installed)
|
|
4532
|
-
continue;
|
|
4533
|
-
const commandIds = await publishManagedCommandBindings({ ...installed, resourceRoot,
|
|
4534
|
-
bindingRecoveryEvidence: nativeBindingRecoveryEvidence.get(target), env: options.context.env });
|
|
4535
|
-
options.context.commandResults ??= [];
|
|
4536
|
-
options.context.commandResults.push({ producer: installed.producer, state: 'completed', commandIds, removedCommandIds: [], errors: [], recoveryActions: [] });
|
|
4537
|
-
}
|
|
4538
|
-
}
|
|
4539
|
-
},
|
|
1688
|
+
applyManagedCommands: publishPackages,
|
|
1689
|
+
writeNative: async () => { throw new Error('platformDeploymentRequired: native writes require a frozen platform deployment.'); },
|
|
4540
1690
|
writeArtifacts: async (target) => {
|
|
4541
|
-
if (target.
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
if (!before.pluginEnabled || !before.pluginVersions.includes(target.identity.pluginVersion)) {
|
|
4545
|
-
await runNativeCliChecked({
|
|
4546
|
-
command: 'claude',
|
|
4547
|
-
args: ['plugin', before.pluginVersions.includes(target.identity.pluginVersion) ? 'enable' : 'install',
|
|
4548
|
-
`${target.identity.pluginName}@${target.identity.marketplaceName ?? MARKETPLACE_NAME}`,
|
|
4549
|
-
'--scope', target.identity.scope],
|
|
4550
|
-
cwd: target.identity.cwd,
|
|
4551
|
-
env: options.context.env,
|
|
4552
|
-
}, runner);
|
|
4553
|
-
}
|
|
4554
|
-
const after = await readClaudeNativeState({
|
|
4555
|
-
pluginName: target.identity.pluginName, scope: target.identity.scope,
|
|
4556
|
-
cwd: target.identity.cwd, env: options.context.env,
|
|
4557
|
-
marketplaceName: target.identity.marketplaceName, marketplaceRoot: target.identity.marketplaceRoot,
|
|
4558
|
-
});
|
|
4559
|
-
if (after.pluginState !== 'present' || !after.pluginEnabled
|
|
4560
|
-
|| !after.pluginVersions.includes(target.identity.pluginVersion)) {
|
|
4561
|
-
throw new Error('claudeActivationPostcheckFailed: the requested scope is not enabled at the expected version.');
|
|
4562
|
-
}
|
|
4563
|
-
return [];
|
|
4564
|
-
}
|
|
4565
|
-
await preflightCommandBindings([target]);
|
|
4566
|
-
await publishPackages(target);
|
|
4567
|
-
for (const operationAction of target.operationActions ?? []) {
|
|
4568
|
-
if (operationAction.kind === 'writeOwnedArtifact'
|
|
4569
|
-
|| operationAction.kind === 'updateSharedConfig'
|
|
4570
|
-
|| operationAction.kind === 'setActivation') {
|
|
4571
|
-
if (operationAction.kind === 'writeOwnedArtifact' && operationAction.artifactKind === 'skill-directory') {
|
|
4572
|
-
const previous = await readInstalledCommandProducer(operationAction.path).catch(() => null);
|
|
4573
|
-
if (previous && (previous.producer.sourceId !== target.identity.sourceId || previous.producer.sourceIdentity !== target.identity.sourceIdentity || previous.producer.pluginName !== target.identity.pluginName))
|
|
4574
|
-
throw new Error('commandOwnerMismatch: installed command producer belongs to another source identity; clean up the previous owner first.');
|
|
4575
|
-
}
|
|
4576
|
-
await applyPlannedOperationAction(operationAction);
|
|
4577
|
-
if (operationAction.kind === 'writeOwnedArtifact' && operationAction.artifactKind === 'skill-directory') {
|
|
4578
|
-
const installed = await readInstalledCommandProducer(operationAction.path).catch(() => null);
|
|
4579
|
-
if (installed) {
|
|
4580
|
-
const commandIds = await publishManagedCommandBindings({ ...installed, resourceRoot: operationAction.path, env: options.context.env });
|
|
4581
|
-
options.context.commandResults ??= [];
|
|
4582
|
-
options.context.commandResults.push({ producer: installed.producer, state: 'completed', commandIds, removedCommandIds: [], errors: [], recoveryActions: [] });
|
|
4583
|
-
}
|
|
4584
|
-
else
|
|
4585
|
-
await revokeAtRoot(operationAction.path);
|
|
4586
|
-
}
|
|
4587
|
-
}
|
|
4588
|
-
}
|
|
4589
|
-
return target.artifacts;
|
|
1691
|
+
if (target.artifacts.length > 0)
|
|
1692
|
+
throw new Error('platformDeploymentRequired: platform output requires a frozen platform deployment.');
|
|
1693
|
+
return [];
|
|
4590
1694
|
},
|
|
4591
1695
|
runPreApply: async (invocation) => {
|
|
1696
|
+
if (isNativeActivationOnlyTarget(options.context, invocation.target.identity))
|
|
1697
|
+
return;
|
|
4592
1698
|
const run = () => runPreApplyScript({
|
|
4593
1699
|
plugin: invocation.plugin,
|
|
4594
1700
|
platform: invocation.target.identity.platform,
|
|
@@ -4613,7 +1719,9 @@ function createNativeDriver(options) {
|
|
|
4613
1719
|
const projectKey = identity.scope === 'project'
|
|
4614
1720
|
? identity.platform === 'codex'
|
|
4615
1721
|
? await resolveCodexProjectKey(identity.cwd)
|
|
4616
|
-
:
|
|
1722
|
+
: identity.platform === 'claude'
|
|
1723
|
+
? await resolveClaudeProjectKey(identity.cwd)
|
|
1724
|
+
: createProjectLocationKey(await resolveRequiredCanonicalRepoRoot(identity.cwd))
|
|
4617
1725
|
: '';
|
|
4618
1726
|
const key = [
|
|
4619
1727
|
sourceIdentity,
|
|
@@ -4640,452 +1748,52 @@ export function createRebuildIntegration(options) {
|
|
|
4640
1748
|
options.context.scriptTimeoutMs ??= options.scriptTimeoutMs;
|
|
4641
1749
|
const targets = [...(options.preparedTargets ?? [])];
|
|
4642
1750
|
const driver = createNativeDriver({ targets, ...options });
|
|
1751
|
+
const renderResults = options.context.preparedArtifactRenderResults ??= new Map();
|
|
1752
|
+
const packageCache = options.context.packagePreparationCache
|
|
1753
|
+
?? commandPackageCandidates.get(renderResults) ?? new Map();
|
|
1754
|
+
commandPackageCandidates.set(renderResults, packageCache);
|
|
1755
|
+
options.context.packagePreparationCache = packageCache;
|
|
1756
|
+
const platformSession = options.context.platformRebuildSession
|
|
1757
|
+
?? platformRebuildSessions.get(renderResults)
|
|
1758
|
+
?? new PlatformRebuildSession(options.context);
|
|
1759
|
+
platformRebuildSessions.set(renderResults, platformSession);
|
|
1760
|
+
options.context.platformRebuildSession = platformSession;
|
|
1761
|
+
platformSession.updateContext(options.context);
|
|
1762
|
+
platformSession.setOwnershipExecutor(driver.ownership);
|
|
4643
1763
|
return {
|
|
1764
|
+
resolvePlatformTargets: (inputs) => platformSession.resolveAll(inputs),
|
|
1765
|
+
sealMarketplaceGenerations: (eligible) => platformSession.sealMarketplaceGenerations(eligible),
|
|
4644
1766
|
driver,
|
|
4645
1767
|
setNativeMarketplaceEligibleTargets: driver.setNativeMarketplaceEligibleTargets,
|
|
4646
1768
|
prepareNativeMarketplaceGroup: driver.prepareNativeMarketplaceGroup,
|
|
4647
1769
|
captureCodexPostMutationSnapshots: driver.captureCodexPostMutationSnapshots,
|
|
4648
1770
|
buildTarget: async (input) => {
|
|
4649
|
-
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
&&
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
|
|
4670
|
-
|
|
4671
|
-
|
|
4672
|
-
});
|
|
4673
|
-
input = { ...input, cwd: canonicalRepoRoot };
|
|
4674
|
-
}
|
|
4675
|
-
if (materializing && input.platform === 'codex') {
|
|
4676
|
-
await preflightCodexWriteSafety({
|
|
4677
|
-
plugin: input.plugin,
|
|
4678
|
-
scope: input.scope,
|
|
4679
|
-
cwd: input.cwd,
|
|
4680
|
-
env: options.context.env,
|
|
4681
|
-
});
|
|
4682
|
-
}
|
|
4683
|
-
const event = 'install';
|
|
4684
|
-
const commands = materializing ? await commandPackageActions({ ...input, env: options.context.env, context: options.context }) : { actions: [], candidates: [] };
|
|
4685
|
-
options.context.managedCommandCandidates ??= new Map();
|
|
4686
|
-
options.context.managedCommandCandidates.set(pluginActionId(input.plugin), commands.candidates);
|
|
4687
|
-
const nativeSkillActions = [];
|
|
4688
|
-
if (materializing && nativeSkillRenderTargets(input.plugin, input.platform).length) {
|
|
4689
|
-
const native = await prepareNativeSkillRenderCached({ context: options.context, plugin: input.plugin, platform: input.platform, scriptTimeoutMs: options.scriptTimeoutMs });
|
|
4690
|
-
if (native) {
|
|
4691
|
-
commands.candidates.push(...native.commandCandidates);
|
|
4692
|
-
for (const { artifact, skillKey, tree } of native.renderedArtifacts) {
|
|
4693
|
-
const files = Object.entries(tree.files).map(([relativePath, content]) => ({
|
|
4694
|
-
relativePath, contentBase64: content.toString('base64'),
|
|
4695
|
-
contentDigest: `sha256:${crypto.createHash('sha256').update(content).digest('hex')}`,
|
|
4696
|
-
...(tree.fileModes?.[relativePath] ? { mode: tree.fileModes[relativePath] } : {}),
|
|
4697
|
-
})).sort((left, right) => left.relativePath.localeCompare(right.relativePath));
|
|
4698
|
-
nativeSkillActions.push({ kind: 'materializeNativeSkill', pluginId: pluginActionId(input.plugin),
|
|
4699
|
-
platform: input.platform, scope: 'user', artifactId: artifact.id, skillKey, files,
|
|
4700
|
-
contentDigest: `sha256:${crypto.createHash('sha256').update(JSON.stringify(files)).digest('hex')}` });
|
|
4701
|
-
}
|
|
4702
|
-
}
|
|
4703
|
-
}
|
|
4704
|
-
const historicalArtifacts = [];
|
|
4705
|
-
let writes = [];
|
|
4706
|
-
let currentRemovalComponents = [];
|
|
4707
|
-
if (input.command !== 'cleanup' && input.command !== 'uninstall') {
|
|
4708
|
-
if (input.readOnlyInspectionPlan) {
|
|
4709
|
-
writes = await buildInspectionWrites({
|
|
4710
|
-
plugin: input.plugin,
|
|
4711
|
-
platform: input.platform,
|
|
4712
|
-
scope: input.scope,
|
|
4713
|
-
cwd: input.cwd,
|
|
4714
|
-
env: options.context.env,
|
|
4715
|
-
marketplaceRoot: input.marketplaceRoot,
|
|
4716
|
-
marketplaceName: input.marketplaceName,
|
|
4717
|
-
userActivationDesired: options.context.codexUserActivationDesired,
|
|
4718
|
-
});
|
|
4719
|
-
}
|
|
4720
|
-
else if (input.platform === 'codex') {
|
|
4721
|
-
writes = await buildCodexWrites({
|
|
4722
|
-
...input,
|
|
4723
|
-
env: options.context.env,
|
|
4724
|
-
event,
|
|
4725
|
-
historicalArtifacts,
|
|
4726
|
-
signal: options.context.signal,
|
|
4727
|
-
scriptTimeoutMs: options.scriptTimeoutMs,
|
|
4728
|
-
marketplaceName: input.marketplaceName,
|
|
4729
|
-
userActivationDesired: options.context.codexUserActivationDesired,
|
|
4730
|
-
commandCandidates: commands.candidates,
|
|
4731
|
-
nativeSkillActions,
|
|
4732
|
-
context: options.context,
|
|
4733
|
-
});
|
|
4734
|
-
}
|
|
4735
|
-
else {
|
|
4736
|
-
writes = await buildClaudeWrites({
|
|
4737
|
-
...input,
|
|
4738
|
-
env: options.context.env,
|
|
4739
|
-
event,
|
|
4740
|
-
historicalArtifacts,
|
|
4741
|
-
signal: options.context.signal,
|
|
4742
|
-
scriptTimeoutMs: options.scriptTimeoutMs,
|
|
4743
|
-
commandCandidates: commands.candidates,
|
|
4744
|
-
nativeSkillActions,
|
|
4745
|
-
context: options.context,
|
|
4746
|
-
});
|
|
4747
|
-
}
|
|
4748
|
-
}
|
|
4749
|
-
else if (input.platform === 'codex' && input.scope === 'project') {
|
|
4750
|
-
const currentRemovalWrites = await buildInspectionWrites({
|
|
4751
|
-
plugin: input.plugin,
|
|
4752
|
-
platform: input.platform,
|
|
4753
|
-
scope: input.scope,
|
|
4754
|
-
cwd: input.cwd,
|
|
4755
|
-
env: options.context.env,
|
|
4756
|
-
marketplaceRoot: input.marketplaceRoot,
|
|
4757
|
-
marketplaceName: input.marketplaceName,
|
|
4758
|
-
userActivationDesired: options.context.codexUserActivationDesired,
|
|
4759
|
-
});
|
|
4760
|
-
currentRemovalComponents = currentRemovalWrites.flatMap((write) => [
|
|
4761
|
-
...(write.additionalComponents ?? []),
|
|
4762
|
-
...(write.component ? [write.component] : []),
|
|
4763
|
-
]);
|
|
4764
|
-
}
|
|
4765
|
-
if (activationOnly)
|
|
4766
|
-
writes = [];
|
|
4767
|
-
const desiredComponents = writes.filter((write) => !write.optional).flatMap((write) => [
|
|
4768
|
-
...(write.additionalComponents ?? []),
|
|
4769
|
-
...(write.component ? [write.component] : []),
|
|
4770
|
-
]);
|
|
4771
|
-
const optionalComponents = writes
|
|
4772
|
-
.filter((write) => write.optional)
|
|
4773
|
-
.flatMap((write) => [
|
|
4774
|
-
...(write.additionalComponents ?? []),
|
|
4775
|
-
...(write.component ? [write.component] : []),
|
|
4776
|
-
]);
|
|
4777
|
-
const optionalComponentKeys = new Set(optionalComponents.map(componentIdentityKey));
|
|
4778
|
-
const configDir = input.platform === 'codex'
|
|
4779
|
-
? resolveCodexPaths(input.cwd, input.scope, options.context.env).configDir
|
|
4780
|
-
: resolveClaudePaths(input.cwd, input.scope, options.context.env).configDir;
|
|
4781
|
-
const textRoots = input.platform === 'codex'
|
|
4782
|
-
? [path.join(configDir, 'rules'), path.join(configDir, 'agents')]
|
|
4783
|
-
: [path.join(configDir, 'rules'), path.join(configDir, 'agents')];
|
|
4784
|
-
const scannedText = (await Promise.all(textRoots.map((root) => scanOwnedTextFiles({
|
|
4785
|
-
sourceId: input.sourceId,
|
|
4786
|
-
sourceIdentity: input.sourceIdentity,
|
|
4787
|
-
root,
|
|
4788
|
-
pluginName: input.plugin.manifest.name,
|
|
4789
|
-
platform: input.platform,
|
|
4790
|
-
scope: input.scope,
|
|
4791
|
-
})))).flat();
|
|
4792
|
-
const skillRoots = input.platform === 'codex'
|
|
4793
|
-
? input.scope === 'project'
|
|
4794
|
-
? materializing
|
|
4795
|
-
|| ((input.command === 'cleanup' || input.command === 'uninstall')
|
|
4796
|
-
&& input.readOnlyInspectionPlan !== true)
|
|
4797
|
-
? [path.join(input.cwd, '.agents', 'skills')]
|
|
4798
|
-
: []
|
|
4799
|
-
: [path.join(getCodexHome(options.context.env), 'skills')]
|
|
4800
|
-
: [path.join(configDir, 'skills')];
|
|
4801
|
-
const scanSkills = () => Promise.all(skillRoots.map((root) => scanOwnedSkills({
|
|
4802
|
-
sourceId: input.sourceId,
|
|
4803
|
-
sourceIdentity: input.sourceIdentity,
|
|
4804
|
-
root,
|
|
4805
|
-
pluginName: input.plugin.manifest.name,
|
|
4806
|
-
platform: input.platform,
|
|
4807
|
-
scope: input.scope,
|
|
4808
|
-
recursive: !(input.platform === 'codex' && input.scope === 'project'),
|
|
4809
|
-
})));
|
|
4810
|
-
const scannedSkills = (await scanSkills()).flat();
|
|
4811
|
-
const legacyCodexNativeSkills = input.platform === 'codex'
|
|
4812
|
-
? (await (async () => {
|
|
4813
|
-
const skillKeys = [...new Set(codexNativeRenderTargets(input.plugin)
|
|
4814
|
-
.map((target) => target.skillKey))];
|
|
4815
|
-
if (skillKeys.length === 0)
|
|
4816
|
-
return [];
|
|
4817
|
-
const projectRoot = await assertCanonicalProjectManagedRoots({
|
|
4818
|
-
cwd: input.cwd,
|
|
4819
|
-
rootNames: ['.agents'],
|
|
4820
|
-
});
|
|
4821
|
-
const roots = [
|
|
4822
|
-
{
|
|
4823
|
-
root: path.join(getCodexHome(options.context.env), 'skills'),
|
|
4824
|
-
scope: 'user',
|
|
4825
|
-
},
|
|
4826
|
-
{
|
|
4827
|
-
root: path.join(projectRoot, '.agents', 'skills'),
|
|
4828
|
-
scope: 'project',
|
|
4829
|
-
},
|
|
4830
|
-
];
|
|
4831
|
-
return roots.flatMap(({ root, scope }) => skillKeys.map((skillKey) => pathComponent({
|
|
4832
|
-
kind: 'skill-directory',
|
|
4833
|
-
path: path.join(root, skillKey),
|
|
4834
|
-
allowedRoot: root,
|
|
4835
|
-
identity: ownerIdentity(input.plugin.manifest.name, skillKey, 'codex', scope),
|
|
4836
|
-
})));
|
|
4837
|
-
})())
|
|
4838
|
-
: [];
|
|
4839
|
-
let historicalComponents = await buildHistoricalComponents({
|
|
4840
|
-
sourceId: input.sourceId,
|
|
4841
|
-
sourceIdentity: input.sourceIdentity,
|
|
4842
|
-
pluginId: input.pluginId,
|
|
4843
|
-
pluginName: input.plugin.manifest.name,
|
|
4844
|
-
platform: input.platform,
|
|
4845
|
-
scope: input.scope,
|
|
4846
|
-
cwd: input.cwd,
|
|
4847
|
-
env: options.context.env,
|
|
4848
|
-
artifacts: historicalArtifacts,
|
|
4849
|
-
command: input.command,
|
|
4850
|
-
});
|
|
4851
|
-
if (input.platform === 'codex') {
|
|
4852
|
-
const nativePluginRoot = await canonicalizePathThroughExistingAncestor(path.join(input.marketplaceRoot ?? resolveAwHome(options.context.env), 'plugins', input.plugin.manifest.name));
|
|
4853
|
-
const privateCacheRoot = path.resolve(getCodexHome(options.context.env), 'plugins', 'cache');
|
|
4854
|
-
historicalComponents = historicalComponents.filter((component) => {
|
|
4855
|
-
if (!('path' in component))
|
|
4856
|
-
return true;
|
|
4857
|
-
const componentPath = path.resolve(component.path);
|
|
4858
|
-
return [nativePluginRoot, privateCacheRoot].every((protectedRoot) => {
|
|
4859
|
-
const relative = path.relative(protectedRoot, componentPath);
|
|
4860
|
-
return relative === '..'
|
|
4861
|
-
|| relative.startsWith(`..${path.sep}`)
|
|
4862
|
-
|| path.isAbsolute(relative);
|
|
4863
|
-
});
|
|
4864
|
-
});
|
|
4865
|
-
}
|
|
4866
|
-
const sharedComponents = input.platform === 'codex'
|
|
4867
|
-
? await scanCodexSharedComponents({
|
|
4868
|
-
sourceId: input.sourceId,
|
|
4869
|
-
sourceIdentity: input.sourceIdentity,
|
|
4870
|
-
pluginId: input.pluginId,
|
|
4871
|
-
pluginName: input.plugin.manifest.name,
|
|
4872
|
-
scope: input.scope,
|
|
4873
|
-
paths: resolveCodexPaths(input.cwd, input.scope, options.context.env),
|
|
4874
|
-
scanConfig: true,
|
|
4875
|
-
ignoreReadErrors: true,
|
|
4876
|
-
})
|
|
4877
|
-
: await scanClaudeSharedComponents({
|
|
4878
|
-
sourceId: input.sourceId,
|
|
4879
|
-
sourceIdentity: input.sourceIdentity,
|
|
4880
|
-
pluginId: input.pluginId,
|
|
4881
|
-
pluginName: input.plugin.manifest.name,
|
|
4882
|
-
scope: input.scope,
|
|
4883
|
-
settingsPath: resolveClaudePaths(input.cwd, input.scope, options.context.env).settingsPath,
|
|
4884
|
-
});
|
|
4885
|
-
const nativeRequired = input.platform === 'claude'
|
|
4886
|
-
|| analyzeCodexSurface(input.plugin.manifest).nativeKinds.length > 0;
|
|
4887
|
-
const nativeDesired = nativeRequired
|
|
4888
|
-
&& input.command !== 'cleanup'
|
|
4889
|
-
&& input.command !== 'uninstall';
|
|
4890
|
-
const codexRegistration = input.platform === 'codex'
|
|
4891
|
-
&& nativeDesired
|
|
4892
|
-
&& input.readOnlyInspectionPlan !== true
|
|
4893
|
-
? await inspectCodexPluginRegistrationLive({
|
|
4894
|
-
pluginId: `${input.plugin.manifest.name}@${input.marketplaceName ?? MARKETPLACE_NAME}`,
|
|
4895
|
-
cwd: input.cwd,
|
|
4896
|
-
env: options.context.env,
|
|
4897
|
-
nativeCliRunner: options.context.nativeCliRunner,
|
|
4898
|
-
manager: options.context.codexManager,
|
|
4899
|
-
scope: codexObservationScope(options.context, input.marketplaceName ?? MARKETPLACE_NAME, input.scope),
|
|
4900
|
-
observationSession: options.context.codexObservationSession,
|
|
4901
|
-
})
|
|
4902
|
-
: undefined;
|
|
4903
|
-
const codexNativeExact = codexRegistration?.observation.state === 'observed'
|
|
4904
|
-
&& codexRegistration.observation.value === 'installed'
|
|
4905
|
-
&& (codexRegistration.observation.entry.version === undefined
|
|
4906
|
-
|| codexRegistration.observation.entry.version === input.plugin.manifest.version);
|
|
4907
|
-
const materializeNativeRequired = !activationOnly && nativeDesired && (input.platform === 'claude'
|
|
4908
|
-
|| input.command === 'reinstall'
|
|
4909
|
-
|| !codexNativeExact
|
|
4910
|
-
|| (materializing && nativeSkillRenderTargets(input.plugin, input.platform).length > 0)
|
|
4911
|
-
|| (materializing && await hasPreparedStaticNativeCommandDrift({ plugin: input.plugin, cwd: input.cwd, env: options.context.env, context: options.context, marketplaceRoot: input.marketplaceRoot ?? resolveAwHome(options.context.env) })));
|
|
4912
|
-
const nativeCleanupCandidate = input.includeNativeCleanupCandidate !== false
|
|
4913
|
-
&& (input.command === 'cleanup' || input.command === 'uninstall')
|
|
4914
|
-
&& (input.platform === 'claude' || (input.platform === 'codex' && nativeRequired));
|
|
4915
|
-
const nativePlugin = (nativeDesired || nativeCleanupCandidate)
|
|
4916
|
-
? [{
|
|
4917
|
-
kind: 'native-plugin',
|
|
4918
|
-
identity: ownerIdentity(input.plugin.manifest.name, 'native', input.platform, input.scope),
|
|
4919
|
-
pluginId: `${input.plugin.manifest.name}@${input.marketplaceName ?? MARKETPLACE_NAME}`,
|
|
4920
|
-
}]
|
|
4921
|
-
: [];
|
|
4922
|
-
const marketplaceDesired = nativeRequired
|
|
4923
|
-
&& input.command !== 'cleanup'
|
|
4924
|
-
&& input.command !== 'uninstall';
|
|
4925
|
-
const marketplace = input.platform === 'codex'
|
|
4926
|
-
&& input.scope === 'user'
|
|
4927
|
-
&& nativeRequired
|
|
4928
|
-
&& input.readOnlyShallowInspectionPlan !== true
|
|
4929
|
-
? [createCodexMarketplaceComponent({
|
|
4930
|
-
pluginName: input.plugin.manifest.name,
|
|
4931
|
-
codexManager: options.context.codexManager,
|
|
4932
|
-
cwd: input.cwd,
|
|
4933
|
-
env: options.context.env,
|
|
4934
|
-
runner: options.context.nativeCliRunner,
|
|
4935
|
-
marketplaceName: input.marketplaceName ?? MARKETPLACE_NAME,
|
|
4936
|
-
marketplaceRoot: input.marketplaceRoot ?? resolveAwHome(options.context.env),
|
|
4937
|
-
desired: marketplaceDesired,
|
|
4938
|
-
})]
|
|
4939
|
-
: input.platform === 'claude' && marketplaceDesired
|
|
4940
|
-
? [createClaudeMarketplaceComponent({
|
|
4941
|
-
pluginName: input.plugin.manifest.name,
|
|
4942
|
-
scope: input.scope,
|
|
4943
|
-
cwd: input.cwd,
|
|
4944
|
-
env: options.context.env,
|
|
4945
|
-
runner: options.context.nativeCliRunner,
|
|
4946
|
-
marketplaceName: input.marketplaceName ?? MARKETPLACE_NAME,
|
|
4947
|
-
marketplaceRoot: input.marketplaceRoot ?? resolveAwHome(options.context.env),
|
|
4948
|
-
desired: marketplaceDesired,
|
|
4949
|
-
})]
|
|
4950
|
-
: [];
|
|
4951
|
-
if (nativeDesired)
|
|
4952
|
-
desiredComponents.push(...nativePlugin, ...marketplace);
|
|
4953
|
-
const activationCleanup = input.platform === 'codex'
|
|
4954
|
-
&& nativeRequired
|
|
4955
|
-
&& (input.command === 'cleanup' || input.command === 'uninstall')
|
|
4956
|
-
? (input.scope === 'project'
|
|
4957
|
-
? [
|
|
4958
|
-
createCodexActivationComponent({
|
|
4959
|
-
identity: ownerIdentity(input.plugin.manifest.name, internalArtifactKey('activation', 'project'), 'codex', input.scope),
|
|
4960
|
-
configPath: resolveCodexPaths(input.cwd, 'project', options.context.env).configTomlPath,
|
|
4961
|
-
codexPluginId: `${input.plugin.manifest.name}@${input.marketplaceName ?? MARKETPLACE_NAME}`,
|
|
4962
|
-
desired: true,
|
|
4963
|
-
}),
|
|
4964
|
-
]
|
|
4965
|
-
: [createCodexActivationComponent({
|
|
4966
|
-
identity: ownerIdentity(input.plugin.manifest.name, internalArtifactKey('activation', 'user'), 'codex', input.scope),
|
|
4967
|
-
configPath: resolveCodexPaths(input.cwd, 'user', options.context.env).configTomlPath,
|
|
4968
|
-
codexPluginId: `${input.plugin.manifest.name}@${input.marketplaceName ?? MARKETPLACE_NAME}`,
|
|
4969
|
-
desired: true,
|
|
4970
|
-
})])
|
|
4971
|
-
: [];
|
|
4972
|
-
const explicitActivationCleanup = input.platform === 'codex'
|
|
4973
|
-
? (input.codexActivationCleanup ?? []).map((activation) => createCodexActivationCleanupComponent({
|
|
4974
|
-
identity: ownerIdentity(input.plugin.manifest.name, internalArtifactKey('activation', activation.scope), 'codex', input.scope),
|
|
4975
|
-
configPath: resolveCodexPaths(input.cwd, activation.scope, options.context.env).configTomlPath,
|
|
4976
|
-
codexPluginId: activation.codexPluginId,
|
|
4977
|
-
disposition: activation.disposition,
|
|
4978
|
-
}))
|
|
4979
|
-
: [];
|
|
4980
|
-
const allComponents = dedupeComponents([
|
|
4981
|
-
...desiredComponents,
|
|
4982
|
-
...optionalComponents,
|
|
4983
|
-
...(input.platform === 'codex' ? sharedComponents : []),
|
|
4984
|
-
...scannedText,
|
|
4985
|
-
...scannedSkills,
|
|
4986
|
-
...legacyCodexNativeSkills,
|
|
4987
|
-
...currentRemovalComponents,
|
|
4988
|
-
...historicalComponents,
|
|
4989
|
-
...(input.platform === 'claude' ? sharedComponents : []),
|
|
4990
|
-
...nativePlugin,
|
|
4991
|
-
...marketplace,
|
|
4992
|
-
...activationCleanup,
|
|
4993
|
-
...explicitActivationCleanup,
|
|
4994
|
-
]).filter((component) => (!activationOnly
|
|
4995
|
-
|| component.kind === 'native-plugin'
|
|
4996
|
-
|| (input.platform === 'codex' && component.kind === 'shared-config'
|
|
4997
|
-
&& (component.identity.artifactKey.startsWith('marketplace-')
|
|
4998
|
-
|| component.identity.artifactKey.startsWith('activation-'))))
|
|
4999
|
-
&& (options.context.preserveLegacyNativeSkills !== true
|
|
5000
|
-
|| component.kind !== 'skill-directory'));
|
|
5001
|
-
bindNamespacedOwnerIdentity(allComponents, input);
|
|
5002
|
-
const desiredKeys = new Set(desiredComponents.map(componentIdentityKey));
|
|
5003
|
-
const retainedPackages = input.command === 'cleanup' || input.command === 'uninstall'
|
|
5004
|
-
? await discoverRetainedManagedCommandPackages({ selectors: [{ sourceId: input.sourceId, pluginName: input.plugin.manifest.name }], scope: input.scope, cwd: input.cwd, env: options.context.env })
|
|
5005
|
-
: [];
|
|
5006
|
-
const operationActions = [...commands.actions, ...nativeSkillActions,
|
|
5007
|
-
...retainedPackages.map((entry) => ({ ...entry, kind: 'retainManagedCommandPackage', pluginId: `${entry.producer.sourceId}/${entry.producer.pluginName}`, scope: entry.producer.scope }))];
|
|
5008
|
-
const preApply = input.plugin.manifest.scripts?.preApply;
|
|
5009
|
-
if (preApply && input.command !== 'cleanup' && input.command !== 'uninstall') {
|
|
5010
|
-
const script = path.resolve(input.plugin.rootDir, preApply.path.replace(/^\.\//u, ''));
|
|
5011
|
-
const scriptDigest = `sha256:${crypto.createHash('sha256')
|
|
5012
|
-
.update(await fs.readFile(script)).digest('hex')}`;
|
|
5013
|
-
operationActions.push({
|
|
5014
|
-
kind: 'runPreApply',
|
|
5015
|
-
pluginId: input.pluginId ?? pluginActionId(input.plugin),
|
|
5016
|
-
platform: input.platform,
|
|
5017
|
-
scope: input.scope,
|
|
5018
|
-
script: preApply.path,
|
|
5019
|
-
scriptDigest,
|
|
5020
|
-
});
|
|
5021
|
-
}
|
|
5022
|
-
if (nativeDesired) {
|
|
5023
|
-
operationActions.push({
|
|
5024
|
-
kind: 'ensureNativeRegistration',
|
|
5025
|
-
pluginId: input.pluginId ?? pluginActionId(input.plugin),
|
|
5026
|
-
platform: input.platform,
|
|
5027
|
-
scope: input.scope,
|
|
5028
|
-
registration: `${input.plugin.manifest.name}@${input.marketplaceName ?? MARKETPLACE_NAME}`,
|
|
5029
|
-
marketplaceName: input.marketplaceName ?? MARKETPLACE_NAME,
|
|
5030
|
-
marketplaceRoot: input.marketplaceRoot ?? resolveAwHome(options.context.env),
|
|
5031
|
-
});
|
|
5032
|
-
}
|
|
5033
|
-
operationActions.push(...writes.flatMap((write) => [
|
|
5034
|
-
...(write.action ? [write.action] : []),
|
|
5035
|
-
...(write.additionalActions ?? []),
|
|
5036
|
-
]));
|
|
5037
|
-
finalizeOwnedArtifactActions(operationActions);
|
|
5038
|
-
const removed = input.command === 'cleanup' || input.command === 'uninstall';
|
|
5039
|
-
if (input.readOnlyInspectionPlan !== true && (removed || operationActions.length > 0)) {
|
|
5040
|
-
let skillComponents = allComponents.filter((component) => component.kind === 'skill-directory');
|
|
5041
|
-
if (removed && skillComponents.length > 0) {
|
|
5042
|
-
const inspection = await inspectOwnedComponents({ components: skillComponents, executor: driver.ownership });
|
|
5043
|
-
skillComponents = inspection.components.flatMap((entry) => entry.state === 'present' && entry.component.kind === 'skill-directory' ? [entry.component] : []);
|
|
5044
|
-
}
|
|
5045
|
-
const nativeToolChanges = await captureNativeToolChanges({ actions: operationActions, sourceId: input.sourceId,
|
|
5046
|
-
pluginName: input.plugin.manifest.name, platform: input.platform, scope: input.scope, projectRoot: input.cwd,
|
|
5047
|
-
removed, env: options.context.env, resourceRoots: skillComponents.map((component) => component.path) });
|
|
5048
|
-
if (nativeToolChanges.length > 0 && removed && operationActions.length === 0) {
|
|
5049
|
-
// Ordinary owned Skill removal can have no renderer action. Reuse the
|
|
5050
|
-
// existing owner/path evidence so its native impact enters Review.
|
|
5051
|
-
const evidence = await forceOfflineCleanupEvidence({ reason: 'bundleUnavailable',
|
|
5052
|
-
pluginId: input.pluginId ?? pluginActionId(input.plugin), pluginName: input.plugin.manifest.name,
|
|
5053
|
-
sourceId: input.sourceId, sourceIdentity: input.sourceIdentity, platform: input.platform, scope: input.scope,
|
|
5054
|
-
components: skillComponents });
|
|
5055
|
-
operationActions.push(...evidence.plan.actions.map((action) => ({ kind: 'removeOwnedArtifact',
|
|
5056
|
-
pluginId: evidence.pluginId, platform: input.platform, scope: input.scope,
|
|
5057
|
-
path: action.target, ownerFingerprint: evidence.targetFingerprint })));
|
|
5058
|
-
}
|
|
5059
|
-
if (nativeToolChanges.length > 0)
|
|
1771
|
+
const target = await platformSession.buildTarget(input);
|
|
1772
|
+
if (!input.readOnlyInspectionPlan) {
|
|
1773
|
+
const removed = input.command === 'cleanup' || input.command === 'uninstall';
|
|
1774
|
+
const commands = removed ? { actions: [], candidates: [] }
|
|
1775
|
+
: await commandPackageActions({ ...input, env: options.context.env, context: options.context });
|
|
1776
|
+
const retained = removed ? await discoverRetainedManagedCommandPackages({
|
|
1777
|
+
selectors: [{ sourceId: input.sourceId ?? input.plugin.sourceId, pluginName: input.plugin.manifest.name }],
|
|
1778
|
+
scope: input.scope, cwd: input.cwd, env: options.context.env
|
|
1779
|
+
}) : [];
|
|
1780
|
+
const operationActions = [...commands.actions, ...retained.map((entry) => ({ ...entry,
|
|
1781
|
+
kind: 'retainManagedCommandPackage', pluginId: `${entry.producer.sourceId}/${entry.producer.pluginName}`,
|
|
1782
|
+
scope: entry.producer.scope }))];
|
|
1783
|
+
options.context.managedCommandCandidates ??= new Map();
|
|
1784
|
+
options.context.managedCommandCandidates.set(pluginActionId(input.plugin), commands.candidates);
|
|
1785
|
+
const preApply = input.plugin.manifest.scripts?.preApply;
|
|
1786
|
+
if (preApply && !removed && !isNativeActivationOnlyTarget(options.context, target.identity))
|
|
1787
|
+
operationActions.push({ kind: 'runPreApply',
|
|
1788
|
+
pluginId: input.pluginId ?? pluginActionId(input.plugin), platform: input.platform, scope: input.scope,
|
|
1789
|
+
script: preApply.path, scriptDigest: `sha256:${crypto.createHash('sha256')
|
|
1790
|
+
.update(await fs.readFile(path.resolve(input.plugin.rootDir, preApply.path.replace(/^\.\//u, '')))).digest('hex')}` });
|
|
1791
|
+
const nativeToolChanges = await captureNativeToolChanges({ actions: operationActions,
|
|
1792
|
+
producers: commands.candidates.map((candidate) => candidate.producer), removed, env: options.context.env });
|
|
1793
|
+
if (nativeToolChanges.length)
|
|
5060
1794
|
operationActions[0].nativeToolChanges = nativeToolChanges;
|
|
1795
|
+
target.operationActions = operationActions;
|
|
5061
1796
|
}
|
|
5062
|
-
const target = {
|
|
5063
|
-
plugin: input.plugin,
|
|
5064
|
-
identity: {
|
|
5065
|
-
...(input.sourceId ? {
|
|
5066
|
-
sourceId: input.sourceId,
|
|
5067
|
-
sourceIdentity: input.sourceIdentity,
|
|
5068
|
-
pluginId: input.pluginId,
|
|
5069
|
-
marketplaceName: input.marketplaceName,
|
|
5070
|
-
marketplaceRoot: input.marketplaceRoot,
|
|
5071
|
-
} : {}),
|
|
5072
|
-
pluginName: input.plugin.manifest.name,
|
|
5073
|
-
pluginVersion: input.plugin.manifest.version,
|
|
5074
|
-
platform: input.platform,
|
|
5075
|
-
scope: input.scope,
|
|
5076
|
-
cwd: input.cwd,
|
|
5077
|
-
},
|
|
5078
|
-
ownedComponents: allComponents,
|
|
5079
|
-
desiredOwnedComponents: allComponents.filter((component) => desiredKeys.has(componentIdentityKey(component))),
|
|
5080
|
-
optionalOwnedComponents: allComponents.filter((component) => optionalComponentKeys.has(componentIdentityKey(component))),
|
|
5081
|
-
requiresNative: nativeDesired,
|
|
5082
|
-
writeNativeRequired: materializeNativeRequired,
|
|
5083
|
-
nativeOverlayDesired: nativeDesired && !activationOnly,
|
|
5084
|
-
artifacts: writes.map((write) => write.artifact),
|
|
5085
|
-
operationActions,
|
|
5086
|
-
catalog: input.catalog,
|
|
5087
|
-
preApplySource: input.plugin,
|
|
5088
|
-
};
|
|
5089
1797
|
targets.push(target);
|
|
5090
1798
|
return target;
|
|
5091
1799
|
},
|
|
@@ -5281,9 +1989,7 @@ export async function discoverRebuildTargetNames(options) {
|
|
|
5281
1989
|
const marketplaceName = options.marketplaceName ?? MARKETPLACE_NAME;
|
|
5282
1990
|
const marketplaceRoot = options.marketplaceRoot ?? resolveAwHome(options.env);
|
|
5283
1991
|
const marketplace = config.snapshot.marketplaces[marketplaceName];
|
|
5284
|
-
const canonicalMarketplace = marketplace
|
|
5285
|
-
&& !marketplace.sourcePointsToManifest
|
|
5286
|
-
&& path.normalize(marketplace.source ?? '') === path.normalize(marketplaceRoot);
|
|
1992
|
+
const canonicalMarketplace = isCanonicalCodexMarketplaceRegistration(marketplace, marketplaceRoot);
|
|
5287
1993
|
const suffix = `@${marketplaceName}`;
|
|
5288
1994
|
const configuredPluginIds = Object.keys(config.snapshot.plugins)
|
|
5289
1995
|
.filter((pluginId) => pluginId.endsWith(suffix));
|