@lesliechan721/aw 0.1.0-beta.8 → 0.1.0-beta.81
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-config.mjs +100 -501
- package/dist/authoring/assets/aw-config.mjs.map +1 -1
- package/dist/authoring/assets/aw-runtime-config.d.mts +13 -0
- package/dist/authoring/assets/aw-runtime-config.mjs +221 -0
- package/dist/authoring/assets/aw-runtime-config.mjs.map +1 -0
- package/dist/authoring/scripts/add-skill.mjs +17 -40
- package/dist/authoring/scripts/add-skill.mjs.map +1 -1
- package/dist/authoring/scripts/init-plugin.mjs +74 -98
- package/dist/authoring/scripts/init-plugin.mjs.map +1 -1
- package/dist/authoring/scripts/lib/plugin-root.mjs +4 -4
- package/dist/authoring/scripts/lib/plugin-root.mjs.map +1 -1
- package/dist/authoring/scripts/lib/plugin-version-check.d.mts +1 -0
- package/dist/authoring/scripts/lib/plugin-version-check.mjs +230 -9
- package/dist/authoring/scripts/lib/plugin-version-check.mjs.map +1 -1
- package/dist/authoring/scripts/lib/skill-scaffold.d.mts +79 -92
- package/dist/authoring/scripts/lib/skill-scaffold.mjs +103 -127
- package/dist/authoring/scripts/lib/skill-scaffold.mjs.map +1 -1
- package/dist/authoring/scripts/remove-plugin.mjs +2 -2
- package/dist/authoring/scripts/remove-plugin.mjs.map +1 -1
- package/dist/authoring/scripts/validate-plugin.mjs +490 -2841
- package/dist/authoring/scripts/validate-plugin.mjs.map +1 -1
- package/dist/authoring/scripts/validate-skill.mjs +1 -1
- package/dist/native-runtime/reader-runtime.mjs +34 -0
- package/dist/native-runtime/reader.d.mts +6 -0
- package/dist/native-runtime/reader.mjs +11 -0
- package/dist/scripts/aw-skill-eval-materializer.d.ts +30 -0
- package/dist/scripts/aw-skill-eval-materializer.js +278 -0
- package/dist/scripts/aw-skill-eval-materializer.js.map +1 -0
- package/dist/scripts/bundle-plugins.d.ts +1 -0
- package/dist/scripts/bundle-plugins.js +27 -8
- package/dist/scripts/bundle-plugins.js.map +1 -1
- package/dist/scripts/plugin-staging.d.ts +7 -8
- package/dist/scripts/plugin-staging.js +16 -15
- package/dist/scripts/plugin-staging.js.map +1 -1
- package/dist/scripts/plugin-test-reporter.d.mts +2 -0
- package/dist/scripts/plugin-test-reporter.mjs +21 -0
- package/dist/scripts/plugin-test-reporter.mjs.map +1 -0
- package/dist/scripts/test-plugin-scripts.d.ts +5 -0
- package/dist/scripts/test-plugin-scripts.js +273 -78
- package/dist/scripts/test-plugin-scripts.js.map +1 -1
- package/dist/scripts/test-workers.d.mts +24 -0
- package/dist/scripts/test-workers.mjs +59 -0
- package/dist/scripts/test-workers.mjs.map +1 -0
- package/dist/src/adapters/helpers.d.ts +7 -0
- package/dist/src/adapters/helpers.js.map +1 -1
- package/dist/src/authoring/workspace-commands.d.ts +5 -1
- package/dist/src/authoring/workspace-commands.js +7 -2
- package/dist/src/authoring/workspace-commands.js.map +1 -1
- package/dist/src/commands/aw-capabilities.d.ts +2 -2
- package/dist/src/commands/aw-capabilities.js +41 -29
- package/dist/src/commands/aw-capabilities.js.map +1 -1
- package/dist/src/commands/catalog-dev-source.d.ts +58 -13
- package/dist/src/commands/catalog-dev-source.js +549 -305
- package/dist/src/commands/catalog-dev-source.js.map +1 -1
- package/dist/src/commands/catalog-generation.d.ts +14 -19
- package/dist/src/commands/catalog-generation.js +5 -10
- package/dist/src/commands/catalog-generation.js.map +1 -1
- package/dist/src/commands/catalog-publication-inspection.d.ts +70 -30
- package/dist/src/commands/catalog-publication-inspection.js +511 -91
- package/dist/src/commands/catalog-publication-inspection.js.map +1 -1
- package/dist/src/commands/catalog-publication-journal.d.ts +68 -0
- package/dist/src/commands/catalog-publication-journal.js +292 -0
- package/dist/src/commands/catalog-publication-journal.js.map +1 -0
- package/dist/src/commands/catalog-publication-target.d.ts +2 -1
- package/dist/src/commands/catalog-publication-target.js +37 -2
- package/dist/src/commands/catalog-publication-target.js.map +1 -1
- package/dist/src/commands/catalog-publish.d.ts +82 -15
- package/dist/src/commands/catalog-publish.js +722 -219
- package/dist/src/commands/catalog-publish.js.map +1 -1
- package/dist/src/commands/catalog-source.d.ts +55 -35
- package/dist/src/commands/catalog-source.js +298 -148
- package/dist/src/commands/catalog-source.js.map +1 -1
- package/dist/src/commands/catalog-status.d.ts +6 -26
- package/dist/src/commands/catalog-status.js +9 -147
- package/dist/src/commands/catalog-status.js.map +1 -1
- package/dist/src/commands/catalog-store.d.ts +104 -0
- package/dist/src/commands/catalog-store.js +685 -0
- package/dist/src/commands/catalog-store.js.map +1 -0
- package/dist/src/commands/catalog-workspace-resolution.d.ts +17 -0
- package/dist/src/commands/catalog-workspace-resolution.js +57 -0
- package/dist/src/commands/catalog-workspace-resolution.js.map +1 -0
- package/dist/src/commands/console.js +32 -20
- package/dist/src/commands/console.js.map +1 -1
- package/dist/src/commands/dependency-operation-plan.d.ts +52 -15
- package/dist/src/commands/dependency-operation-plan.js +289 -7
- 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/init.d.ts +5 -11
- package/dist/src/commands/init.js +30 -51
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/commands/intent-command.d.ts +32 -0
- package/dist/src/commands/intent-command.js +171 -0
- package/dist/src/commands/intent-command.js.map +1 -0
- package/dist/src/commands/managed-commands.d.ts +35 -0
- package/dist/src/commands/managed-commands.js +361 -0
- package/dist/src/commands/managed-commands.js.map +1 -0
- package/dist/src/commands/offline-cleanup-evidence.d.ts +46 -0
- package/dist/src/commands/offline-cleanup-evidence.js +158 -10
- package/dist/src/commands/offline-cleanup-evidence.js.map +1 -1
- package/dist/src/commands/operation-plan.d.ts +190 -0
- package/dist/src/commands/operation-plan.js +99 -0
- package/dist/src/commands/operation-plan.js.map +1 -0
- package/dist/src/commands/operation-planner.d.ts +47 -0
- package/dist/src/commands/operation-planner.js +142 -0
- package/dist/src/commands/operation-planner.js.map +1 -0
- package/dist/src/commands/options.d.ts +16 -20
- package/dist/src/commands/options.js +94 -41
- package/dist/src/commands/options.js.map +1 -1
- package/dist/src/commands/plugin-capabilities.js +88 -45
- package/dist/src/commands/plugin-capabilities.js.map +1 -1
- package/dist/src/commands/public-config-confirmation.d.ts +8 -0
- package/dist/src/commands/public-config-confirmation.js +56 -0
- package/dist/src/commands/public-config-confirmation.js.map +1 -0
- package/dist/src/commands/public-interruption.d.ts +9 -0
- package/dist/src/commands/public-interruption.js +23 -0
- package/dist/src/commands/public-interruption.js.map +1 -0
- package/dist/src/commands/public-lifecycle-result.d.ts +102 -0
- package/dist/src/commands/public-lifecycle-result.js +307 -0
- package/dist/src/commands/public-lifecycle-result.js.map +1 -0
- package/dist/src/commands/public-lifecycle.d.ts +28 -0
- package/dist/src/commands/public-lifecycle.js +492 -0
- package/dist/src/commands/public-lifecycle.js.map +1 -0
- package/dist/src/commands/public-plugin-query.d.ts +16 -0
- package/dist/src/commands/public-plugin-query.js +193 -0
- package/dist/src/commands/public-plugin-query.js.map +1 -0
- package/dist/src/commands/rebuild-command.d.ts +166 -28
- package/dist/src/commands/rebuild-command.js +3745 -813
- package/dist/src/commands/rebuild-command.js.map +1 -1
- package/dist/src/commands/rebuild-integration.d.ts +137 -25
- package/dist/src/commands/rebuild-integration.js +1343 -2535
- package/dist/src/commands/rebuild-integration.js.map +1 -1
- package/dist/src/commands/rebuild-operations.d.ts +73 -22
- package/dist/src/commands/rebuild-operations.js +313 -216
- package/dist/src/commands/rebuild-operations.js.map +1 -1
- package/dist/src/commands/rebuild-platform-integration.d.ts +62 -0
- package/dist/src/commands/rebuild-platform-integration.js +1317 -0
- package/dist/src/commands/rebuild-platform-integration.js.map +1 -0
- package/dist/src/commands/reconcile-operation-plan.d.ts +28 -0
- package/dist/src/commands/reconcile-operation-plan.js +47 -0
- package/dist/src/commands/reconcile-operation-plan.js.map +1 -0
- package/dist/src/commands/review-inspection.d.ts +60 -0
- package/dist/src/commands/review-inspection.js +436 -0
- package/dist/src/commands/review-inspection.js.map +1 -0
- package/dist/src/commands/review-preparation.d.ts +51 -0
- package/dist/src/commands/review-preparation.js +400 -0
- package/dist/src/commands/review-preparation.js.map +1 -0
- package/dist/src/commands/runtime.d.ts +6 -6
- package/dist/src/commands/runtime.js +44 -24
- package/dist/src/commands/runtime.js.map +1 -1
- package/dist/src/commands/skill-eval.d.ts +41 -0
- package/dist/src/commands/skill-eval.js +407 -0
- package/dist/src/commands/skill-eval.js.map +1 -0
- package/dist/src/commands/status-v6.d.ts +319 -0
- package/dist/src/commands/status-v6.js +2979 -0
- package/dist/src/commands/status-v6.js.map +1 -0
- package/dist/src/commands/targets-command.d.ts +38 -0
- package/dist/src/commands/targets-command.js +182 -0
- package/dist/src/commands/targets-command.js.map +1 -0
- package/dist/src/commands/wizard.d.ts +8 -5
- package/dist/src/commands/wizard.js +7 -4
- package/dist/src/commands/wizard.js.map +1 -1
- package/dist/src/commands/write-commands.d.ts +9 -3
- package/dist/src/commands/write-commands.js +143 -85
- package/dist/src/commands/write-commands.js.map +1 -1
- package/dist/src/constants.d.ts +6 -6
- package/dist/src/constants.js +6 -6
- package/dist/src/constants.js.map +1 -1
- package/dist/src/eval/manifest-v1.d.ts +70 -0
- package/dist/src/eval/manifest-v1.js +358 -0
- package/dist/src/eval/manifest-v1.js.map +1 -0
- package/dist/src/generators/local-plugin.d.ts +7 -2
- package/dist/src/generators/local-plugin.js +313 -389
- package/dist/src/generators/local-plugin.js.map +1 -1
- package/dist/src/generators/permissions.d.ts +5 -2
- package/dist/src/generators/permissions.js +28 -15
- package/dist/src/generators/permissions.js.map +1 -1
- package/dist/src/index.d.ts +2 -31
- package/dist/src/index.js +1666 -1827
- package/dist/src/index.js.map +1 -1
- package/dist/src/intent/deployment-preferences.d.ts +63 -0
- package/dist/src/intent/deployment-preferences.js +170 -0
- package/dist/src/intent/deployment-preferences.js.map +1 -0
- package/dist/src/intent/diagnostics.d.ts +11 -0
- package/dist/src/intent/diagnostics.js +14 -0
- package/dist/src/intent/diagnostics.js.map +1 -0
- package/dist/src/intent/intent-codec.d.ts +19 -0
- package/dist/src/intent/intent-codec.js +117 -0
- package/dist/src/intent/intent-codec.js.map +1 -0
- package/dist/src/intent/intent-store.d.ts +43 -0
- package/dist/src/intent/intent-store.js +118 -0
- package/dist/src/intent/intent-store.js.map +1 -0
- package/dist/src/intent/scope-context.d.ts +33 -0
- package/dist/src/intent/scope-context.js +149 -0
- package/dist/src/intent/scope-context.js.map +1 -0
- package/dist/src/intent/work-context.d.ts +13 -0
- package/dist/src/intent/work-context.js +22 -0
- package/dist/src/intent/work-context.js.map +1 -0
- package/dist/src/output/command-receipt.d.ts +47 -46
- package/dist/src/output/command-receipt.js +286 -79
- package/dist/src/output/command-receipt.js.map +1 -1
- package/dist/src/output/model.d.ts +3 -11
- 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.d.ts +49 -0
- package/dist/src/output/public-result.js +240 -0
- package/dist/src/output/public-result.js.map +1 -0
- package/dist/src/output/rebuild-progress.js +20 -15
- package/dist/src/output/rebuild-progress.js.map +1 -1
- package/dist/src/output/receipt-projection.d.ts +7 -0
- package/dist/src/output/receipt-projection.js +592 -0
- package/dist/src/output/receipt-projection.js.map +1 -0
- package/dist/src/platforms/capabilities.d.ts +12 -0
- package/dist/src/platforms/capabilities.js +205 -0
- package/dist/src/platforms/capabilities.js.map +1 -0
- package/dist/src/platforms/contracts.d.ts +358 -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 +28 -0
- package/dist/src/platforms/cursor-workspace-hook.js +198 -0
- package/dist/src/platforms/cursor-workspace-hook.js.map +1 -0
- package/dist/src/platforms/discovery.d.ts +91 -0
- package/dist/src/platforms/discovery.js +653 -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 +81 -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 +212 -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 +406 -0
- package/dist/src/platforms/inspection-native.js.map +1 -0
- package/dist/src/platforms/inspection-opencode.d.ts +4 -0
- package/dist/src/platforms/inspection-opencode.js +98 -0
- package/dist/src/platforms/inspection-opencode.js.map +1 -0
- package/dist/src/platforms/inspection-pi.d.ts +3 -0
- package/dist/src/platforms/inspection-pi.js +282 -0
- package/dist/src/platforms/inspection-pi.js.map +1 -0
- package/dist/src/platforms/inspection-query.d.ts +12 -0
- package/dist/src/platforms/inspection-query.js +96 -0
- package/dist/src/platforms/inspection-query.js.map +1 -0
- package/dist/src/platforms/inspection.d.ts +17 -0
- package/dist/src/platforms/inspection.js +227 -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 +13 -0
- package/dist/src/platforms/lifecycle-native.js +283 -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 +494 -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/platforms/supplement-state.d.ts +13 -0
- package/dist/src/platforms/supplement-state.js +82 -0
- package/dist/src/platforms/supplement-state.js.map +1 -0
- package/dist/src/portable/commands.d.ts +58 -11
- package/dist/src/portable/commands.js +94 -350
- package/dist/src/portable/commands.js.map +1 -1
- package/dist/src/portable/historical-materialization.d.ts +22 -0
- package/dist/src/portable/historical-materialization.js +124 -0
- package/dist/src/portable/historical-materialization.js.map +1 -0
- package/dist/src/portable/materializer.d.ts +24 -4
- package/dist/src/portable/materializer.js +189 -259
- package/dist/src/portable/materializer.js.map +1 -1
- package/dist/src/portable/recovery-layout.d.ts +17 -0
- package/dist/src/portable/recovery-layout.js +42 -0
- package/dist/src/portable/recovery-layout.js.map +1 -0
- package/dist/src/portable/recovery.d.ts +153 -0
- package/dist/src/portable/recovery.js +367 -0
- package/dist/src/portable/recovery.js.map +1 -0
- package/dist/src/portable/writer.d.ts +67 -0
- package/dist/src/portable/writer.js +321 -0
- package/dist/src/portable/writer.js.map +1 -0
- package/dist/src/recovery/coordinator.d.ts +141 -0
- package/dist/src/recovery/coordinator.js +1254 -0
- package/dist/src/recovery/coordinator.js.map +1 -0
- package/dist/src/recovery/demand.d.ts +51 -0
- package/dist/src/recovery/demand.js +159 -0
- package/dist/src/recovery/demand.js.map +1 -0
- package/dist/src/recovery/joint-coordinator.d.ts +25 -0
- package/dist/src/recovery/joint-coordinator.js +991 -0
- package/dist/src/recovery/joint-coordinator.js.map +1 -0
- package/dist/src/recovery/joint-demand.d.ts +50 -0
- package/dist/src/recovery/joint-demand.js +197 -0
- package/dist/src/recovery/joint-demand.js.map +1 -0
- package/dist/src/recovery/performance.d.ts +4 -0
- package/dist/src/recovery/performance.js +26 -0
- package/dist/src/recovery/performance.js.map +1 -0
- package/dist/src/recovery/receipt.d.ts +98 -0
- package/dist/src/recovery/receipt.js +2 -0
- package/dist/src/recovery/receipt.js.map +1 -0
- package/dist/src/recovery/retirement.d.ts +47 -0
- package/dist/src/recovery/retirement.js +469 -0
- package/dist/src/recovery/retirement.js.map +1 -0
- package/dist/src/recovery/status.d.ts +126 -0
- package/dist/src/recovery/status.js +1073 -0
- package/dist/src/recovery/status.js.map +1 -0
- package/dist/src/recovery/types.d.ts +85 -0
- package/dist/src/recovery/types.js +2 -0
- package/dist/src/recovery/types.js.map +1 -0
- package/dist/src/review/eval-source-input.d.ts +43 -0
- package/dist/src/review/eval-source-input.js +207 -0
- package/dist/src/review/eval-source-input.js.map +1 -0
- package/dist/src/review/platform-profile.d.ts +3 -0
- package/dist/src/review/platform-profile.js +14 -0
- package/dist/src/review/platform-profile.js.map +1 -0
- package/dist/src/review/review-profile.d.ts +20 -0
- package/dist/src/review/review-profile.js +276 -0
- package/dist/src/review/review-profile.js.map +1 -0
- package/dist/src/review/review-selection.d.ts +20 -0
- package/dist/src/review/review-selection.js +495 -0
- package/dist/src/review/review-selection.js.map +1 -0
- package/dist/src/review/review-types.d.ts +71 -0
- package/dist/src/review/review-types.js +16 -0
- package/dist/src/review/review-types.js.map +1 -0
- package/dist/src/review/skill-materialization.d.ts +62 -0
- package/dist/src/review/skill-materialization.js +205 -0
- package/dist/src/review/skill-materialization.js.map +1 -0
- package/dist/src/review/source-binding.d.ts +201 -0
- package/dist/src/review/source-binding.js +773 -0
- package/dist/src/review/source-binding.js.map +1 -0
- package/dist/src/tui/agent-management.d.ts +23 -0
- package/dist/src/tui/agent-management.js +319 -0
- package/dist/src/tui/agent-management.js.map +1 -0
- package/dist/src/tui/agent-settings.d.ts +47 -0
- package/dist/src/tui/agent-settings.js +97 -0
- package/dist/src/tui/agent-settings.js.map +1 -0
- package/dist/src/tui/catalog-freshness.d.ts +1 -0
- package/dist/src/tui/catalog-freshness.js +2 -0
- package/dist/src/tui/catalog-freshness.js.map +1 -0
- package/dist/src/tui/catalog-generation.d.ts +18 -53
- package/dist/src/tui/catalog-generation.js +136 -224
- package/dist/src/tui/catalog-generation.js.map +1 -1
- package/dist/src/tui/catalog-sources/projection.d.ts +4 -0
- package/dist/src/tui/catalog-sources/projection.js +17 -0
- package/dist/src/tui/catalog-sources/projection.js.map +1 -0
- package/dist/src/tui/catalog-sources/review.d.ts +3 -0
- package/dist/src/tui/catalog-sources/review.js +13 -0
- package/dist/src/tui/catalog-sources/review.js.map +1 -0
- package/dist/src/tui/catalog-sources/screens.d.ts +12 -0
- package/dist/src/tui/catalog-sources/screens.js +40 -0
- package/dist/src/tui/catalog-sources/screens.js.map +1 -0
- package/dist/src/tui/catalog-sources/session.d.ts +32 -0
- package/dist/src/tui/catalog-sources/session.js +300 -0
- package/dist/src/tui/catalog-sources/session.js.map +1 -0
- package/dist/src/tui/catalog-sources/types.d.ts +54 -0
- package/dist/src/tui/catalog-sources/types.js +2 -0
- package/dist/src/tui/catalog-sources/types.js.map +1 -0
- package/dist/src/tui/catalog-store-task.d.ts +16 -0
- package/dist/src/tui/catalog-store-task.js +19 -0
- package/dist/src/tui/catalog-store-task.js.map +1 -0
- package/dist/src/tui/clipboard.d.ts +13 -0
- package/dist/src/tui/clipboard.js +95 -0
- package/dist/src/tui/clipboard.js.map +1 -0
- package/dist/src/tui/components.d.ts +113 -3
- package/dist/src/tui/components.js +201 -36
- package/dist/src/tui/components.js.map +1 -1
- package/dist/src/tui/config-array-draft.d.ts +29 -0
- package/dist/src/tui/config-array-draft.js +48 -0
- package/dist/src/tui/config-array-draft.js.map +1 -0
- package/dist/src/tui/config-leaf-editor.d.ts +43 -0
- package/dist/src/tui/config-leaf-editor.js +224 -0
- package/dist/src/tui/config-leaf-editor.js.map +1 -0
- package/dist/src/tui/config-references.d.ts +38 -0
- package/dist/src/tui/config-references.js +82 -0
- package/dist/src/tui/config-references.js.map +1 -0
- package/dist/src/tui/config-value-presentation.d.ts +20 -0
- package/dist/src/tui/config-value-presentation.js +104 -0
- package/dist/src/tui/config-value-presentation.js.map +1 -0
- package/dist/src/tui/console-app-v4.d.ts +13 -4
- package/dist/src/tui/console-app-v4.js +9764 -2210
- package/dist/src/tui/console-app-v4.js.map +1 -1
- package/dist/src/tui/content-item-card.d.ts +13 -0
- package/dist/src/tui/content-item-card.js +51 -0
- package/dist/src/tui/content-item-card.js.map +1 -0
- package/dist/src/tui/controller-runtime.d.ts +7 -4
- package/dist/src/tui/controller-runtime.js +2064 -779
- package/dist/src/tui/controller-runtime.js.map +1 -1
- package/dist/src/tui/controller.d.ts +669 -106
- package/dist/src/tui/controller.js +3617 -971
- package/dist/src/tui/controller.js.map +1 -1
- package/dist/src/tui/dependency-graph-view.d.ts +39 -0
- package/dist/src/tui/dependency-graph-view.js +121 -0
- package/dist/src/tui/dependency-graph-view.js.map +1 -0
- package/dist/src/tui/dependency-graph.d.ts +81 -0
- package/dist/src/tui/dependency-graph.js +452 -0
- package/dist/src/tui/dependency-graph.js.map +1 -0
- package/dist/src/tui/deployment-view.d.ts +10 -0
- package/dist/src/tui/deployment-view.js +108 -0
- package/dist/src/tui/deployment-view.js.map +1 -0
- package/dist/src/tui/diagnostic-projection.d.ts +23 -0
- package/dist/src/tui/diagnostic-projection.js +595 -0
- package/dist/src/tui/diagnostic-projection.js.map +1 -0
- package/dist/src/tui/diagnostics.d.ts +6 -3
- package/dist/src/tui/diagnostics.js +14 -2
- package/dist/src/tui/diagnostics.js.map +1 -1
- package/dist/src/tui/entity-cards.d.ts +55 -0
- package/dist/src/tui/entity-cards.js +298 -0
- package/dist/src/tui/entity-cards.js.map +1 -0
- package/dist/src/tui/glossary.d.ts +25 -0
- package/dist/src/tui/glossary.js +72 -0
- package/dist/src/tui/glossary.js.map +1 -0
- package/dist/src/tui/index.d.ts +6 -2
- package/dist/src/tui/index.js +5 -2
- package/dist/src/tui/index.js.map +1 -1
- package/dist/src/tui/input-display.d.ts +1 -0
- package/dist/src/tui/input-display.js +23 -1
- package/dist/src/tui/input-display.js.map +1 -1
- package/dist/src/tui/keys.d.ts +44 -0
- package/dist/src/tui/keys.js +43 -15
- package/dist/src/tui/keys.js.map +1 -1
- package/dist/src/tui/lifecycle-action-view.d.ts +6 -0
- package/dist/src/tui/lifecycle-action-view.js +36 -0
- package/dist/src/tui/lifecycle-action-view.js.map +1 -0
- package/dist/src/tui/model.d.ts +243 -45
- package/dist/src/tui/model.js +1402 -415
- package/dist/src/tui/model.js.map +1 -1
- package/dist/src/tui/operation-diagnostic-screens.d.ts +8 -0
- package/dist/src/tui/operation-diagnostic-screens.js +72 -0
- package/dist/src/tui/operation-diagnostic-screens.js.map +1 -0
- package/dist/src/tui/operation-history.d.ts +82 -0
- package/dist/src/tui/operation-history.js +136 -0
- package/dist/src/tui/operation-history.js.map +1 -0
- package/dist/src/tui/operation-review-planner.d.ts +28 -0
- package/dist/src/tui/operation-review-planner.js +1396 -0
- package/dist/src/tui/operation-review-planner.js.map +1 -0
- package/dist/src/tui/plugin-content.d.ts +33 -0
- package/dist/src/tui/plugin-content.js +245 -0
- package/dist/src/tui/plugin-content.js.map +1 -0
- package/dist/src/tui/plugin-detail.d.ts +72 -0
- package/dist/src/tui/plugin-detail.js +260 -0
- package/dist/src/tui/plugin-detail.js.map +1 -0
- package/dist/src/tui/plugin-write-task.d.ts +69 -0
- package/dist/src/tui/plugin-write-task.js +286 -0
- package/dist/src/tui/plugin-write-task.js.map +1 -0
- package/dist/src/tui/prompt.js +4 -15
- package/dist/src/tui/prompt.js.map +1 -1
- package/dist/src/tui/query-header.d.ts +30 -0
- package/dist/src/tui/query-header.js +40 -0
- package/dist/src/tui/query-header.js.map +1 -0
- package/dist/src/tui/reader.d.ts +38 -0
- package/dist/src/tui/reader.js +49 -0
- package/dist/src/tui/reader.js.map +1 -0
- package/dist/src/tui/router.d.ts +186 -35
- package/dist/src/tui/router.js +338 -50
- package/dist/src/tui/router.js.map +1 -1
- package/dist/src/tui/scoped-flow.d.ts +45 -0
- package/dist/src/tui/scoped-flow.js +96 -0
- package/dist/src/tui/scoped-flow.js.map +1 -0
- package/dist/src/tui/scoped-inventory.d.ts +126 -0
- package/dist/src/tui/scoped-inventory.js +258 -0
- package/dist/src/tui/scoped-inventory.js.map +1 -0
- package/dist/src/tui/screen-registry.d.ts +701 -0
- package/dist/src/tui/screen-registry.js +226 -0
- package/dist/src/tui/screen-registry.js.map +1 -0
- package/dist/src/tui/session-console-app.d.ts +6 -0
- package/dist/src/tui/session-console-app.js +13 -0
- package/dist/src/tui/session-console-app.js.map +1 -0
- package/dist/src/tui/session-host.d.ts +45 -0
- package/dist/src/tui/session-host.js +219 -0
- package/dist/src/tui/session-host.js.map +1 -0
- package/dist/src/tui/source-detail-card.d.ts +29 -0
- package/dist/src/tui/source-detail-card.js +45 -0
- package/dist/src/tui/source-detail-card.js.map +1 -0
- package/dist/src/tui/theme.d.ts +12 -0
- package/dist/src/tui/theme.js +12 -0
- package/dist/src/tui/theme.js.map +1 -1
- package/dist/src/tui/viewport.d.ts +1 -0
- package/dist/src/tui/viewport.js +23 -0
- package/dist/src/tui/viewport.js.map +1 -1
- package/dist/src/tui/wizard.js +37 -13
- package/dist/src/tui/wizard.js.map +1 -1
- package/dist/src/types.d.ts +220 -118
- package/dist/src/types.js +1 -0
- package/dist/src/types.js.map +1 -1
- package/dist/src/utils/agent-version.d.ts +13 -4
- package/dist/src/utils/agent-version.js +27 -4
- package/dist/src/utils/agent-version.js.map +1 -1
- package/dist/src/utils/artifact-plan.d.ts +33 -7
- package/dist/src/utils/artifact-plan.js +115 -430
- package/dist/src/utils/artifact-plan.js.map +1 -1
- package/dist/src/utils/artifact-renderer.d.ts +114 -83
- package/dist/src/utils/artifact-renderer.js +213 -364
- package/dist/src/utils/artifact-renderer.js.map +1 -1
- package/dist/src/utils/artifact-request.d.ts +44 -0
- package/dist/src/utils/artifact-request.js +80 -0
- package/dist/src/utils/artifact-request.js.map +1 -0
- package/dist/src/utils/artifact-sources.d.ts +6 -2
- package/dist/src/utils/artifact-sources.js +17 -0
- package/dist/src/utils/artifact-sources.js.map +1 -1
- package/dist/src/utils/bundle-layout.js +57 -173
- package/dist/src/utils/bundle-layout.js.map +1 -1
- package/dist/src/utils/catalog-capability-projection.d.ts +8 -0
- package/dist/src/utils/catalog-capability-projection.js +14 -0
- package/dist/src/utils/catalog-capability-projection.js.map +1 -0
- package/dist/src/utils/catalog-digests.d.ts +2 -2
- package/dist/src/utils/catalog-digests.js +7 -18
- package/dist/src/utils/catalog-digests.js.map +1 -1
- package/dist/src/utils/catalog-generation-control-snapshot.d.ts +11 -0
- package/dist/src/utils/catalog-generation-control-snapshot.js +45 -0
- package/dist/src/utils/catalog-generation-control-snapshot.js.map +1 -0
- package/dist/src/utils/catalog-generation-error.d.ts +5 -1
- package/dist/src/utils/catalog-generation-error.js +14 -0
- package/dist/src/utils/catalog-generation-error.js.map +1 -1
- package/dist/src/utils/catalog-generation-resolver.d.ts +36 -5
- package/dist/src/utils/catalog-generation-resolver.js +221 -77
- package/dist/src/utils/catalog-generation-resolver.js.map +1 -1
- package/dist/src/utils/catalog-generation-service.d.ts +159 -28
- package/dist/src/utils/catalog-generation-service.js +1186 -525
- package/dist/src/utils/catalog-generation-service.js.map +1 -1
- package/dist/src/utils/catalog-generation-state.d.ts +9 -0
- package/dist/src/utils/catalog-generation-state.js +97 -106
- package/dist/src/utils/catalog-generation-state.js.map +1 -1
- package/dist/src/utils/catalog-generation-store.d.ts +38 -24
- package/dist/src/utils/catalog-generation-store.js +337 -272
- package/dist/src/utils/catalog-generation-store.js.map +1 -1
- package/dist/src/utils/catalog-manifest-v7.d.ts +5 -0
- package/dist/src/utils/{catalog-manifest-v5.js → catalog-manifest-v7.js} +23 -35
- package/dist/src/utils/catalog-manifest-v7.js.map +1 -0
- package/dist/src/utils/catalog-operation-context.d.ts +6 -14
- package/dist/src/utils/catalog-operation-context.js +69 -169
- package/dist/src/utils/catalog-operation-context.js.map +1 -1
- package/dist/src/utils/catalog-public-error.js +8 -4
- package/dist/src/utils/catalog-public-error.js.map +1 -1
- package/dist/src/utils/catalog-runtime-projection.d.ts +7 -3
- package/dist/src/utils/catalog-runtime-projection.js +5 -40
- package/dist/src/utils/catalog-runtime-projection.js.map +1 -1
- package/dist/src/utils/catalog-snapshot.d.ts +2 -2
- package/dist/src/utils/catalog-source-impact.d.ts +21 -0
- package/dist/src/utils/catalog-source-impact.js +344 -0
- package/dist/src/utils/catalog-source-impact.js.map +1 -0
- package/dist/src/utils/catalog-source-references.d.ts +23 -2
- package/dist/src/utils/catalog-source-references.js +456 -382
- package/dist/src/utils/catalog-source-references.js.map +1 -1
- package/dist/src/utils/catalog-sources.d.ts +14 -1
- package/dist/src/utils/catalog-sources.js +178 -18
- package/dist/src/utils/catalog-sources.js.map +1 -1
- package/dist/src/utils/codex-config.d.ts +2 -0
- package/dist/src/utils/codex-config.js +22 -1
- package/dist/src/utils/codex-config.js.map +1 -1
- package/dist/src/utils/codex-executable-discovery.d.ts +28 -0
- package/dist/src/utils/codex-executable-discovery.js +431 -0
- package/dist/src/utils/codex-executable-discovery.js.map +1 -0
- package/dist/src/utils/codex-manager.d.ts +47 -18
- package/dist/src/utils/codex-manager.js +88 -622
- package/dist/src/utils/codex-manager.js.map +1 -1
- package/dist/src/utils/codex-marketplace-path.d.ts +5 -0
- package/dist/src/utils/codex-marketplace-path.js +45 -0
- package/dist/src/utils/codex-marketplace-path.js.map +1 -0
- package/dist/src/utils/codex-native-observation.d.ts +49 -0
- package/dist/src/utils/codex-native-observation.js +169 -0
- package/dist/src/utils/codex-native-observation.js.map +1 -0
- package/dist/src/utils/codex-reconciler.d.ts +123 -0
- package/dist/src/utils/codex-reconciler.js +322 -0
- package/dist/src/utils/codex-reconciler.js.map +1 -0
- package/dist/src/utils/codex-shared-native.d.ts +45 -0
- package/dist/src/utils/codex-shared-native.js +122 -0
- package/dist/src/utils/codex-shared-native.js.map +1 -0
- 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-skills-root.d.ts +4 -0
- package/dist/src/utils/codex-skills-root.js +25 -0
- package/dist/src/utils/codex-skills-root.js.map +1 -0
- package/dist/src/utils/codex-surface-analysis.d.ts +49 -0
- package/dist/src/utils/codex-surface-analysis.js +220 -0
- package/dist/src/utils/codex-surface-analysis.js.map +1 -0
- 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 +51 -0
- package/dist/src/utils/component-resources.js +322 -0
- package/dist/src/utils/component-resources.js.map +1 -0
- package/dist/src/utils/dynamic-skill-tree.d.ts +18 -6
- package/dist/src/utils/dynamic-skill-tree.js +32 -9
- package/dist/src/utils/dynamic-skill-tree.js.map +1 -1
- package/dist/src/utils/git-catalog-provider.d.ts +16 -0
- package/dist/src/utils/git-catalog-provider.js +167 -120
- package/dist/src/utils/git-catalog-provider.js.map +1 -1
- package/dist/src/utils/inventory-recovery-diagnostic.d.ts +4 -0
- package/dist/src/utils/inventory-recovery-diagnostic.js +15 -0
- package/dist/src/utils/inventory-recovery-diagnostic.js.map +1 -0
- package/dist/src/utils/local-marketplace.d.ts +17 -12
- package/dist/src/utils/local-marketplace.js +85 -195
- package/dist/src/utils/local-marketplace.js.map +1 -1
- package/dist/src/utils/managed-command-closure.d.ts +3 -0
- package/dist/src/utils/managed-command-closure.js +35 -0
- package/dist/src/utils/managed-command-closure.js.map +1 -0
- package/dist/src/utils/managed-command-evidence.d.ts +7 -0
- package/dist/src/utils/managed-command-evidence.js +10 -0
- package/dist/src/utils/managed-command-evidence.js.map +1 -0
- package/dist/src/utils/managed-command-materialization.d.ts +124 -0
- package/dist/src/utils/managed-command-materialization.js +369 -0
- package/dist/src/utils/managed-command-materialization.js.map +1 -0
- 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-runtime.d.ts +33 -0
- package/dist/src/utils/managed-command-runtime.js +121 -0
- package/dist/src/utils/managed-command-runtime.js.map +1 -0
- package/dist/src/utils/managed-command-store.d.ts +143 -0
- package/dist/src/utils/managed-command-store.js +665 -0
- package/dist/src/utils/managed-command-store.js.map +1 -0
- package/dist/src/utils/manifest.d.ts +1 -3
- package/dist/src/utils/manifest.js +1 -3
- package/dist/src/utils/manifest.js.map +1 -1
- package/dist/src/utils/multi-source-catalog.d.ts +1 -10
- package/dist/src/utils/multi-source-catalog.js +9 -175
- package/dist/src/utils/multi-source-catalog.js.map +1 -1
- package/dist/src/utils/native-cli.d.ts +74 -5
- package/dist/src/utils/native-cli.js +479 -31
- package/dist/src/utils/native-cli.js.map +1 -1
- package/dist/src/utils/native-demand.d.ts +29 -0
- package/dist/src/utils/native-demand.js +4 -0
- package/dist/src/utils/native-demand.js.map +1 -0
- package/dist/src/utils/native-tool-context.d.ts +14 -0
- package/dist/src/utils/native-tool-context.js +38 -0
- package/dist/src/utils/native-tool-context.js.map +1 -0
- package/dist/src/utils/native-tool-review.d.ts +18 -0
- package/dist/src/utils/native-tool-review.js +116 -0
- package/dist/src/utils/native-tool-review.js.map +1 -0
- package/dist/src/utils/orphan-marketplace-cleanup.js +0 -1
- package/dist/src/utils/orphan-marketplace-cleanup.js.map +1 -1
- package/dist/src/utils/ownership.d.ts +103 -21
- package/dist/src/utils/ownership.js +232 -210
- package/dist/src/utils/ownership.js.map +1 -1
- package/dist/src/utils/path-catalog-provider.d.ts +1 -1
- package/dist/src/utils/path-catalog-provider.js +47 -62
- package/dist/src/utils/path-catalog-provider.js.map +1 -1
- package/dist/src/utils/paths.d.ts +1 -2
- package/dist/src/utils/paths.js +5 -3
- package/dist/src/utils/paths.js.map +1 -1
- package/dist/src/utils/platform-empty-state.d.ts +45 -0
- package/dist/src/utils/platform-empty-state.js +159 -0
- package/dist/src/utils/platform-empty-state.js.map +1 -0
- package/dist/src/utils/platform-support.d.ts +1 -1
- package/dist/src/utils/platform-support.js +1 -1
- package/dist/src/utils/platform-support.js.map +1 -1
- package/dist/src/utils/plugin-config-impact.d.ts +64 -0
- package/dist/src/utils/plugin-config-impact.js +307 -0
- package/dist/src/utils/plugin-config-impact.js.map +1 -0
- package/dist/src/utils/plugin-config-references.d.ts +89 -0
- package/dist/src/utils/plugin-config-references.js +335 -0
- package/dist/src/utils/plugin-config-references.js.map +1 -0
- package/dist/src/utils/plugin-config-write.d.ts +109 -27
- package/dist/src/utils/plugin-config-write.js +1242 -348
- package/dist/src/utils/plugin-config-write.js.map +1 -1
- package/dist/src/utils/plugin-config.d.ts +187 -109
- package/dist/src/utils/plugin-config.js +916 -1147
- 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/plugin-scripts.d.ts +78 -127
- package/dist/src/utils/plugin-scripts.js +566 -524
- package/dist/src/utils/plugin-scripts.js.map +1 -1
- package/dist/src/utils/process-lock.js +14 -5
- package/dist/src/utils/process-lock.js.map +1 -1
- package/dist/src/utils/process-tree.d.ts +2 -2
- package/dist/src/utils/process-tree.js +1 -1
- package/dist/src/utils/process-tree.js.map +1 -1
- package/dist/src/utils/project-boundary.d.ts +11 -13
- package/dist/src/utils/project-boundary.js +28 -34
- package/dist/src/utils/project-boundary.js.map +1 -1
- package/dist/src/utils/rendered-contract.js +18 -1
- package/dist/src/utils/rendered-contract.js.map +1 -1
- package/dist/src/utils/runtime-config.d.ts +18 -0
- package/dist/src/utils/runtime-config.js +64 -0
- package/dist/src/utils/runtime-config.js.map +1 -0
- package/dist/src/utils/runtime-skill-closure.d.ts +2 -2
- package/dist/src/utils/runtime-skill-closure.js +47 -6
- package/dist/src/utils/runtime-skill-closure.js.map +1 -1
- package/dist/src/utils/safe-fs.d.ts +21 -0
- package/dist/src/utils/safe-fs.js +111 -0
- package/dist/src/utils/safe-fs.js.map +1 -0
- package/dist/src/utils/safe-operation-diagnostic.d.ts +15 -0
- package/dist/src/utils/safe-operation-diagnostic.js +33 -0
- package/dist/src/utils/safe-operation-diagnostic.js.map +1 -0
- package/dist/src/utils/sensitive-content.d.ts +4 -0
- package/dist/src/utils/sensitive-content.js +36 -0
- package/dist/src/utils/sensitive-content.js.map +1 -0
- package/dist/src/utils/state-paths.d.ts +8 -3
- package/dist/src/utils/state-paths.js +53 -16
- package/dist/src/utils/state-paths.js.map +1 -1
- package/dist/src/utils/target-eligibility.d.ts +4 -3
- package/dist/src/utils/target-eligibility.js +12 -6
- package/dist/src/utils/target-eligibility.js.map +1 -1
- package/dist/src/utils/windows-claude-shim.d.ts +7 -0
- package/dist/src/utils/windows-claude-shim.js +10 -0
- package/dist/src/utils/windows-claude-shim.js.map +1 -0
- package/dist/src/utils/windows-npm-shim.d.ts +16 -0
- package/dist/src/utils/windows-npm-shim.js +155 -0
- package/dist/src/utils/windows-npm-shim.js.map +1 -0
- package/dist/vitest.config.js +105 -9
- package/dist/vitest.config.js.map +1 -1
- package/package.json +30 -21
- package/dist/scripts/aw-skill-eval-engine.d.ts +0 -13
- package/dist/scripts/aw-skill-eval-engine.js +0 -31
- package/dist/scripts/aw-skill-eval-engine.js.map +0 -1
- package/dist/scripts/codex-eval-app-server.d.ts +0 -91
- package/dist/scripts/codex-eval-app-server.js +0 -1334
- package/dist/scripts/codex-eval-app-server.js.map +0 -1
- package/dist/scripts/codex-eval-isolation.d.ts +0 -61
- package/dist/scripts/codex-eval-isolation.js +0 -318
- package/dist/scripts/codex-eval-isolation.js.map +0 -1
- package/dist/scripts/codex-eval-process-management.d.ts +0 -8
- package/dist/scripts/codex-eval-process-management.js +0 -69
- package/dist/scripts/codex-eval-process-management.js.map +0 -1
- package/dist/scripts/codex-eval-process-tree.d.ts +0 -38
- package/dist/scripts/codex-eval-process-tree.js +0 -803
- package/dist/scripts/codex-eval-process-tree.js.map +0 -1
- package/dist/scripts/codex-eval-runtime-config.d.ts +0 -62
- package/dist/scripts/codex-eval-runtime-config.js +0 -843
- package/dist/scripts/codex-eval-runtime-config.js.map +0 -1
- package/dist/scripts/codex-trigger-eval.d.ts +0 -84
- package/dist/scripts/codex-trigger-eval.js +0 -968
- package/dist/scripts/codex-trigger-eval.js.map +0 -1
- package/dist/scripts/eval-plugin-skills-audited.d.ts +0 -6
- package/dist/scripts/eval-plugin-skills-audited.js +0 -261
- package/dist/scripts/eval-plugin-skills-audited.js.map +0 -1
- package/dist/scripts/eval-plugin-skills.d.ts +0 -45
- package/dist/scripts/eval-plugin-skills.js +0 -1589
- package/dist/scripts/eval-plugin-skills.js.map +0 -1
- package/dist/scripts/eval-run-layout.d.ts +0 -17
- package/dist/scripts/eval-run-layout.js +0 -26
- package/dist/scripts/eval-run-layout.js.map +0 -1
- package/dist/scripts/plugin-eval-contract.d.ts +0 -189
- package/dist/scripts/plugin-eval-contract.js +0 -745
- package/dist/scripts/plugin-eval-contract.js.map +0 -1
- package/dist/scripts/plugin-eval-materializer.d.ts +0 -13
- package/dist/scripts/plugin-eval-materializer.js +0 -421
- package/dist/scripts/plugin-eval-materializer.js.map +0 -1
- package/dist/scripts/skill-reporting.d.ts +0 -212
- package/dist/scripts/skill-reporting.js +0 -922
- package/dist/scripts/skill-reporting.js.map +0 -1
- package/dist/src/commands/catalog-context.d.ts +0 -52
- package/dist/src/commands/catalog-context.js +0 -156
- package/dist/src/commands/catalog-context.js.map +0 -1
- package/dist/src/commands/review-publication.d.ts +0 -99
- package/dist/src/commands/review-publication.js +0 -904
- package/dist/src/commands/review-publication.js.map +0 -1
- package/dist/src/commands/status-v5.d.ts +0 -169
- package/dist/src/commands/status-v5.js +0 -1135
- package/dist/src/commands/status-v5.js.map +0 -1
- package/dist/src/portable/skills-cli.d.ts +0 -43
- package/dist/src/portable/skills-cli.js +0 -148
- package/dist/src/portable/skills-cli.js.map +0 -1
- package/dist/src/utils/catalog-manifest-v5.d.ts +0 -5
- package/dist/src/utils/catalog-manifest-v5.js.map +0 -1
- package/dist/src/utils/catalog-source-cache.d.ts +0 -62
- package/dist/src/utils/catalog-source-cache.js +0 -321
- package/dist/src/utils/catalog-source-cache.js.map +0 -1
- package/dist/src/utils/codex-project-surface.d.ts +0 -3
- package/dist/src/utils/codex-project-surface.js +0 -49
- package/dist/src/utils/codex-project-surface.js.map +0 -1
- package/dist/src/utils/lifecycle-active-store.d.ts +0 -147
- package/dist/src/utils/lifecycle-active-store.js +0 -1064
- package/dist/src/utils/lifecycle-active-store.js.map +0 -1
- package/dist/src/utils/plugin-release.d.ts +0 -2
- package/dist/src/utils/plugin-release.js +0 -2
- package/dist/src/utils/plugin-release.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,36 +1,135 @@
|
|
|
1
1
|
import crypto from 'node:crypto';
|
|
2
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';
|
|
3
6
|
import fs from 'fs-extra';
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
7
|
+
import os from 'node:os';
|
|
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';
|
|
8
11
|
import { buildGeneratedName } from '../generators/shared.js';
|
|
9
|
-
import { applyConditionalCodexConfigTransactionFile, applyCodexConfigTransactionFile, composeManagedDeveloperInstructionsBlock, readCodexConfigFile, readRenderedCodexMcpServersFile, } from '../utils/codex-config.js';
|
|
10
|
-
import { createCodexSkillExpectedTree, createCodexSkillStagingTreeContentDigest, } from '../utils/codex-skill-staging.js';
|
|
11
|
-
import { createDynamicSkillExpectedTree, createDynamicSkillTreeContentDigest, skillDirectoryMatchesExpectedTree, validateSkillDirectory, writeDynamicSkillTree, } from '../utils/dynamic-skill-tree.js';
|
|
12
|
-
import { parseCodexSharedHooksFile, renderTrackedHookGroupIdentity, resolvePlatformHookDefinitions, serializeTrackedHookGroupIdentity, } from '../utils/hooks-contract.js';
|
|
13
|
-
import { buildCodexMarketplaceAddInvocation, buildCodexMarketplaceListInvocation, buildCodexMarketplaceRemoveInvocation, buildCodexPluginAddInvocation, buildCodexPluginListInvocation, buildCodexPluginRemoveInvocation, runNativeCliChecked, } from '../utils/native-cli.js';
|
|
14
|
-
import { OWNED_TEXT_HEADER_PREFIX, createSharedOwnerToken, createSkillOwnerMarkerContent, parseSharedOwnerToken, parseOwnedTextHeader, readSkillOwnerMarker, inspectOwnedComponents, writeOwnedTextFile, } from '../utils/ownership.js';
|
|
15
|
-
import { resolveArtifactRenderConfig, runArtifactRenderer } from '../utils/artifact-renderer.js';
|
|
16
|
-
import { validateArtifactPlan } from '../utils/artifact-plan.js';
|
|
17
|
-
import { createAwPluginRequirementsReceipt, readPluginManifest, } from '../utils/manifest.js';
|
|
18
|
-
import { resolvePlatformEntries } from '../utils/platform-entries.js';
|
|
19
|
-
import { resolveAwHome, resolveClaudePaths, resolveCodexPaths, resolveRepoRoot, getCodexHome, } from '../utils/paths.js';
|
|
20
|
-
import { runLifecycleScript } from '../utils/plugin-scripts.js';
|
|
21
|
-
import { atomicRemoveConfigFile, atomicReplaceConfigFile, withConfigFileMutation, } from '../utils/plugin-config.js';
|
|
22
12
|
import { readCatalogSourcesConfigSnapshot } from '../utils/catalog-sources.js';
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
13
|
+
import { applyCodexConfigTransactionFile, applyConditionalCodexConfigTransactionFile, readCodexConfigFile } from '../utils/codex-config.js';
|
|
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';
|
|
27
25
|
import { assertCanonicalProjectManagedRoots } from '../utils/project-boundary.js';
|
|
28
|
-
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';
|
|
29
29
|
const MARKETPLACE_NAME = 'aw';
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
const LEGACY_MCP_OWNER_ENV = 'AW_AGENT_WORKFLOWS_OWNER';
|
|
31
|
+
const commandPackagePreparationCaches = new WeakMap();
|
|
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();
|
|
44
|
+
}
|
|
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
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async function commandPackageActions(options) {
|
|
54
|
+
const actions = [];
|
|
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
|
+
}
|
|
62
|
+
for (const declaration of options.plugin.manifest.managedCommands?.packages ?? []) {
|
|
63
|
+
if (!declaration.platforms.includes(options.platform))
|
|
64
|
+
continue;
|
|
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);
|
|
69
|
+
if (!preparation) {
|
|
70
|
+
preparation = (async () => {
|
|
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);
|
|
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.');
|
|
95
|
+
}
|
|
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 } };
|
|
103
|
+
})();
|
|
104
|
+
cache.set(key, preparation);
|
|
105
|
+
}
|
|
106
|
+
const prepared = await preparation;
|
|
107
|
+
actions.push(prepared.action);
|
|
108
|
+
candidates.push(prepared.candidate);
|
|
109
|
+
}
|
|
110
|
+
return { actions, candidates };
|
|
111
|
+
}
|
|
112
|
+
export class CodexActivationPostcheckError extends Error {
|
|
113
|
+
code = 'codexActivationPostcheckFailed';
|
|
114
|
+
codexPluginIds;
|
|
115
|
+
constructor(codexPluginIds, detail) {
|
|
116
|
+
super(`codexActivationPostcheckFailed: ${detail}`);
|
|
117
|
+
this.name = 'CodexActivationPostcheckError';
|
|
118
|
+
this.codexPluginIds = [...new Set(typeof codexPluginIds === 'string' ? [codexPluginIds] : codexPluginIds)];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function codexObservationScope(context, marketplaceName, fallbackScope) {
|
|
122
|
+
return context.codexObservationScopeByMarketplace?.get(marketplaceName)
|
|
123
|
+
?? (fallbackScope === 'user' ? 'user' : 'both');
|
|
124
|
+
}
|
|
125
|
+
function codexMarketplaceFromPluginId(pluginId) {
|
|
126
|
+
return pluginId.slice(pluginId.lastIndexOf('@') + 1);
|
|
127
|
+
}
|
|
128
|
+
function requireCodexObservationCoverage(registration, scope, operation) {
|
|
129
|
+
if (!registration.observations.user
|
|
130
|
+
|| (scope === 'both' && !registration.observations.project)) {
|
|
131
|
+
throw new Error(`codexNativeObservationUnavailable: ${operation} requires ${scope === 'user' ? 'neutral' : 'exact and neutral'} Codex plugin list evidence.`);
|
|
132
|
+
}
|
|
34
133
|
}
|
|
35
134
|
function requireCodexManager(manager) {
|
|
36
135
|
if (!manager) {
|
|
@@ -38,75 +137,247 @@ function requireCodexManager(manager) {
|
|
|
38
137
|
}
|
|
39
138
|
return manager;
|
|
40
139
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
140
|
+
async function runCodexMutationWithInvalidation(options) {
|
|
141
|
+
try {
|
|
142
|
+
return await options.mutation();
|
|
143
|
+
}
|
|
144
|
+
finally {
|
|
145
|
+
options.observationSession?.invalidate(options.marketplaceName);
|
|
146
|
+
}
|
|
44
147
|
}
|
|
45
|
-
function
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
sourceId: plugin.sourceId,
|
|
50
|
-
sourceIdentity: plugin.sourceIdentity,
|
|
51
|
-
pluginId: plugin.pluginId,
|
|
52
|
-
} : {}),
|
|
148
|
+
async function executeCodexReconcileActivationsInSession(options) {
|
|
149
|
+
const byScope = {
|
|
150
|
+
user: { upserts: {}, removals: new Set() },
|
|
151
|
+
project: { upserts: {}, removals: new Set() },
|
|
53
152
|
};
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
153
|
+
for (const plan of options.plans) {
|
|
154
|
+
const rewrittenPluginIds = new Set(plan.sharedNativeActions
|
|
155
|
+
.filter((action) => action.action === 'install'
|
|
156
|
+
|| action.action === 'replace'
|
|
157
|
+
|| action.action === 'repair')
|
|
158
|
+
.map((action) => action.codexPluginId));
|
|
159
|
+
for (const scope of ['user', 'project']) {
|
|
160
|
+
for (const action of plan.activationActions[scope]) {
|
|
161
|
+
if (action.action === 'enable' || action.action === 'disable') {
|
|
162
|
+
byScope[scope].upserts[action.codexPluginId] = action.desired;
|
|
163
|
+
byScope[scope].removals.delete(action.codexPluginId);
|
|
164
|
+
}
|
|
165
|
+
else if (action.action === 'remove') {
|
|
166
|
+
byScope[scope].removals.add(action.codexPluginId);
|
|
167
|
+
}
|
|
168
|
+
else if (rewrittenPluginIds.has(action.codexPluginId)
|
|
169
|
+
&& (action.desired || scope === 'user')) {
|
|
170
|
+
byScope[scope].upserts[action.codexPluginId] = action.desired;
|
|
171
|
+
byScope[scope].removals.delete(action.codexPluginId);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
for (const removal of plan.staleActivationRemovals) {
|
|
176
|
+
if (!Object.hasOwn(byScope[removal.scope].upserts, removal.codexPluginId)) {
|
|
177
|
+
byScope[removal.scope].removals.add(removal.codexPluginId);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const recordActivationMutations = (pluginIds) => {
|
|
182
|
+
if (!options.mutationMarketplaces)
|
|
183
|
+
return;
|
|
184
|
+
for (const pluginId of pluginIds) {
|
|
185
|
+
options.mutationMarketplaces.add(pluginId.slice(pluginId.lastIndexOf('@') + 1));
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
const observedActivationPluginIds = [...new Set(options.plans.flatMap((plan) => plan.postcheck.support === 'observed'
|
|
189
|
+
? plan.postcheck.plugins.map((plugin) => plugin.codexPluginId)
|
|
190
|
+
: []))];
|
|
191
|
+
if (!options.preflightCompleted && observedActivationPluginIds.length > 0) {
|
|
192
|
+
const manager = requireCodexManager(options.manager);
|
|
193
|
+
for (const pluginId of observedActivationPluginIds) {
|
|
194
|
+
const marketplaceName = codexMarketplaceFromPluginId(pluginId);
|
|
195
|
+
const observationScope = options.observationScopeByMarketplace?.get(marketplaceName)
|
|
196
|
+
?? (options.plans.some((plan) => plan.requirement.scope === 'project')
|
|
197
|
+
? 'both'
|
|
198
|
+
: 'user');
|
|
199
|
+
const registration = await inspectCodexPluginRegistrationLive({
|
|
200
|
+
pluginId,
|
|
201
|
+
cwd: options.cwd,
|
|
202
|
+
env: options.env,
|
|
203
|
+
nativeCliRunner: options.runner,
|
|
204
|
+
manager,
|
|
205
|
+
scope: observationScope,
|
|
206
|
+
observationSession: options.observationSession,
|
|
207
|
+
});
|
|
208
|
+
const observedState = requireObservedCodexNativeState(registration.observation, 'activation precheck');
|
|
209
|
+
requireCodexObservationCoverage(registration, observationScope, 'activation precheck');
|
|
210
|
+
if (observedState !== 'installed') {
|
|
211
|
+
throw new Error('codexNativeObservationFailed: activation precheck did not observe the installed Codex plugin.');
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
for (const scope of ['user', 'project']) {
|
|
216
|
+
const enables = Object.fromEntries(Object.entries(byScope[scope].upserts)
|
|
217
|
+
.filter(([, desired]) => desired));
|
|
218
|
+
if (Object.keys(enables).length === 0)
|
|
219
|
+
continue;
|
|
220
|
+
const configPath = resolveCodexPaths(options.cwd, scope, options.env).configTomlPath;
|
|
221
|
+
const update = await applyCodexConfigTransactionFile(configPath, { upsertPluginActivations: enables });
|
|
222
|
+
if (update.wrote)
|
|
223
|
+
recordActivationMutations(Object.keys(enables));
|
|
224
|
+
const enabledConfig = await readCodexConfigFile(configPath);
|
|
225
|
+
const missingEnables = Object.keys(enables).filter((pluginId) => enabledConfig.snapshot.plugins[pluginId]?.enabled !== true);
|
|
226
|
+
if (missingEnables.length > 0) {
|
|
227
|
+
throw new CodexActivationPostcheckError(missingEnables, `${missingEnables.join(', ')} ${scope} activation was not enabled before obsolete activation removal.`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
for (const scope of ['user', 'project']) {
|
|
231
|
+
const transaction = byScope[scope];
|
|
232
|
+
const disables = Object.fromEntries(Object.entries(transaction.upserts)
|
|
233
|
+
.filter(([, desired]) => !desired));
|
|
234
|
+
if (Object.keys(disables).length === 0 && transaction.removals.size === 0)
|
|
235
|
+
continue;
|
|
236
|
+
const update = await applyCodexConfigTransactionFile(resolveCodexPaths(options.cwd, scope, options.env).configTomlPath, {
|
|
237
|
+
...(transaction.removals.size > 0
|
|
238
|
+
? { removePluginActivations: [...transaction.removals].sort() }
|
|
239
|
+
: {}),
|
|
240
|
+
...(Object.keys(disables).length > 0
|
|
241
|
+
? { upsertPluginActivations: disables }
|
|
242
|
+
: {}),
|
|
243
|
+
});
|
|
244
|
+
if (update.wrote) {
|
|
245
|
+
recordActivationMutations([
|
|
246
|
+
...Object.keys(disables),
|
|
247
|
+
...transaction.removals,
|
|
248
|
+
]);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
const [userConfig, projectConfig] = await Promise.all([
|
|
252
|
+
readCodexConfigFile(resolveCodexPaths(options.cwd, 'user', options.env).configTomlPath),
|
|
253
|
+
readCodexConfigFile(resolveCodexPaths(options.cwd, 'project', options.env).configTomlPath),
|
|
254
|
+
]);
|
|
255
|
+
const configMismatchIds = [];
|
|
256
|
+
const configMismatchDetails = [];
|
|
257
|
+
for (const plan of options.plans) {
|
|
258
|
+
for (const scope of ['user', 'project']) {
|
|
259
|
+
const snapshot = scope === 'user' ? userConfig.snapshot : projectConfig.snapshot;
|
|
260
|
+
for (const action of plan.activationActions[scope]) {
|
|
261
|
+
const actual = snapshot.plugins[action.codexPluginId]?.enabled;
|
|
262
|
+
const expected = action.desired
|
|
263
|
+
? true
|
|
264
|
+
: action.action === 'disable' || actual === false ? false : undefined;
|
|
265
|
+
if (actual !== expected) {
|
|
266
|
+
configMismatchIds.push(action.codexPluginId);
|
|
267
|
+
configMismatchDetails.push(`${action.codexPluginId} ${scope} activation is ${String(actual)}; expected ${String(expected)}.`);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
for (const removal of plan.staleActivationRemovals.filter((entry) => entry.scope === scope)) {
|
|
271
|
+
if (snapshot.plugins[removal.codexPluginId]?.enabled !== undefined) {
|
|
272
|
+
configMismatchIds.push(removal.codexPluginId);
|
|
273
|
+
configMismatchDetails.push(`stale ${removal.codexPluginId} ${scope} activation remains.`);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (configMismatchIds.length > 0) {
|
|
279
|
+
throw new CodexActivationPostcheckError(configMismatchIds, configMismatchDetails.join(' '));
|
|
280
|
+
}
|
|
281
|
+
const observedActivationChecks = options.plans.flatMap((plan) => plan.postcheck.support === 'observed'
|
|
282
|
+
? plan.postcheck.plugins
|
|
283
|
+
: []);
|
|
284
|
+
if (observedActivationChecks.length === 0)
|
|
57
285
|
return;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
286
|
+
const ineffectivePlugins = [];
|
|
287
|
+
const ineffectiveDetails = [];
|
|
288
|
+
for (const plugin of observedActivationChecks) {
|
|
289
|
+
const userActive = userConfig.snapshot.plugins[plugin.codexPluginId]?.enabled === true;
|
|
290
|
+
const projectActive = projectConfig.snapshot.plugins[plugin.codexPluginId]?.enabled === true;
|
|
291
|
+
if ((userActive || projectActive) !== (plugin.expectedUserEnabled || plugin.expectedProjectEnabled)
|
|
292
|
+
|| userActive !== plugin.expectedUserEnabled) {
|
|
293
|
+
ineffectivePlugins.push(plugin.codexPluginId);
|
|
294
|
+
ineffectiveDetails.push(new CodexProjectConfigNotEffectiveError(plugin.codexPluginId).message);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (ineffectivePlugins.length > 0) {
|
|
298
|
+
throw new CodexActivationPostcheckError(ineffectivePlugins, ineffectiveDetails.join(' '));
|
|
62
299
|
}
|
|
63
300
|
}
|
|
64
|
-
function
|
|
65
|
-
|
|
301
|
+
export async function executeCodexReconcileActivations(options) {
|
|
302
|
+
const ownedSession = options.observationSession ? undefined
|
|
303
|
+
: await createCodexNativeObservationSession({
|
|
304
|
+
exactCwd: options.cwd,
|
|
305
|
+
env: options.env,
|
|
306
|
+
runner: options.runner,
|
|
307
|
+
manager: options.manager,
|
|
308
|
+
});
|
|
309
|
+
try {
|
|
310
|
+
await executeCodexReconcileActivationsInSession({
|
|
311
|
+
...options,
|
|
312
|
+
observationSession: options.observationSession ?? ownedSession,
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
finally {
|
|
316
|
+
await ownedSession?.dispose();
|
|
317
|
+
}
|
|
66
318
|
}
|
|
67
|
-
function
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
319
|
+
export async function postcheckCodexReconcileActivations(options) {
|
|
320
|
+
const checks = options.plans.flatMap((plan) => plan.postcheck.support === 'observed' ? plan.postcheck.plugins : []);
|
|
321
|
+
if (checks.length === 0)
|
|
322
|
+
return;
|
|
323
|
+
const ownedSession = options.observationSession ? undefined
|
|
324
|
+
: await createCodexNativeObservationSession({
|
|
325
|
+
exactCwd: options.cwd,
|
|
326
|
+
env: options.env,
|
|
327
|
+
runner: options.runner,
|
|
328
|
+
manager: options.manager,
|
|
329
|
+
});
|
|
330
|
+
const session = options.observationSession ?? ownedSession;
|
|
331
|
+
try {
|
|
332
|
+
const failedPluginIds = [];
|
|
333
|
+
const failureDetails = [];
|
|
334
|
+
for (const check of checks) {
|
|
335
|
+
try {
|
|
336
|
+
const marketplaceName = codexMarketplaceFromPluginId(check.codexPluginId);
|
|
337
|
+
const observationScope = options.observationScopeByMarketplace?.get(marketplaceName)
|
|
338
|
+
?? (options.plans.some((plan) => plan.requirement.scope === 'project')
|
|
339
|
+
? 'both'
|
|
340
|
+
: 'user');
|
|
341
|
+
const registration = await inspectCodexPluginRegistrationLive({
|
|
342
|
+
pluginId: check.codexPluginId,
|
|
343
|
+
cwd: options.cwd,
|
|
344
|
+
env: options.env,
|
|
345
|
+
nativeCliRunner: options.runner,
|
|
346
|
+
manager: options.manager,
|
|
347
|
+
scope: observationScope,
|
|
348
|
+
observationSession: session,
|
|
349
|
+
});
|
|
350
|
+
const state = requireObservedCodexNativeState(registration.observation, 'activation postcheck');
|
|
351
|
+
requireCodexObservationCoverage(registration, observationScope, 'activation postcheck');
|
|
352
|
+
if (state !== 'installed') {
|
|
353
|
+
throw new Error(`codexNativeObservationFailed: ${check.codexPluginId} was not observed after Codex activation mutation.`);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
catch (error) {
|
|
357
|
+
failedPluginIds.push(check.codexPluginId);
|
|
358
|
+
failureDetails.push(error instanceof Error ? error.message : String(error));
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
if (failedPluginIds.length > 0) {
|
|
362
|
+
throw new CodexActivationPostcheckError(failedPluginIds, failureDetails.join(' '));
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
finally {
|
|
366
|
+
await ownedSession?.dispose();
|
|
367
|
+
}
|
|
76
368
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const component = pathComponent({
|
|
81
|
-
kind: 'owned-text-file',
|
|
82
|
-
path: artifactPath,
|
|
83
|
-
allowedRoot: options.configDir,
|
|
84
|
-
identity,
|
|
85
|
-
});
|
|
86
|
-
return {
|
|
87
|
-
artifact: {
|
|
88
|
-
path: artifactPath,
|
|
89
|
-
kind: options.kind,
|
|
90
|
-
platform: options.platform,
|
|
91
|
-
artifactKey: options.artifactKey,
|
|
92
|
-
},
|
|
93
|
-
component,
|
|
94
|
-
write: async () => {
|
|
95
|
-
await fs.ensureDir(options.configDir);
|
|
96
|
-
await writeOwnedTextFile({
|
|
97
|
-
path: artifactPath,
|
|
98
|
-
allowedRoot: options.configDir,
|
|
99
|
-
identity,
|
|
100
|
-
content: options.content,
|
|
101
|
-
});
|
|
102
|
-
},
|
|
103
|
-
};
|
|
369
|
+
const CODEX_REMOVE_RECOVERY = 'Codex residue was retained. Retry cleanup or uninstall, upgrade AW, or install a compatible official Codex CLI.';
|
|
370
|
+
function pluginActionId(plugin) {
|
|
371
|
+
return plugin.pluginId ?? plugin.manifest.name;
|
|
104
372
|
}
|
|
105
373
|
function mergePermissionStates(values) {
|
|
106
374
|
return {
|
|
107
375
|
allow: [...new Set(values.flatMap((value) => value?.allow ?? []))],
|
|
108
376
|
ask: [...new Set(values.flatMap((value) => value?.ask ?? []))],
|
|
109
377
|
deny: [...new Set(values.flatMap((value) => value?.deny ?? []))],
|
|
378
|
+
...(values.some((value) => value?.excludedCommands !== undefined) ? {
|
|
379
|
+
excludedCommands: [...new Set(values.flatMap((value) => value?.excludedCommands ?? []))],
|
|
380
|
+
} : {}),
|
|
110
381
|
};
|
|
111
382
|
}
|
|
112
383
|
function subtractPermissionState(value, generated) {
|
|
@@ -119,6 +390,9 @@ function subtractPermissionState(value, generated) {
|
|
|
119
390
|
allow: (value?.allow ?? []).filter((entry) => !remove.allow.has(entry)),
|
|
120
391
|
ask: (value?.ask ?? []).filter((entry) => !remove.ask.has(entry)),
|
|
121
392
|
deny: (value?.deny ?? []).filter((entry) => !remove.deny.has(entry)),
|
|
393
|
+
...(value?.excludedCommands ? {
|
|
394
|
+
excludedCommands: value.excludedCommands.filter((entry) => !generated.excludedCommands?.includes(entry)),
|
|
395
|
+
} : {}),
|
|
122
396
|
};
|
|
123
397
|
}
|
|
124
398
|
function intersectPermissionState(value, generated) {
|
|
@@ -131,11 +405,17 @@ function intersectPermissionState(value, generated) {
|
|
|
131
405
|
allow: (value?.allow ?? []).filter((entry) => keep.allow.has(entry)),
|
|
132
406
|
ask: (value?.ask ?? []).filter((entry) => keep.ask.has(entry)),
|
|
133
407
|
deny: (value?.deny ?? []).filter((entry) => keep.deny.has(entry)),
|
|
408
|
+
...(value?.excludedCommands ? {
|
|
409
|
+
excludedCommands: value.excludedCommands.filter((entry) => generated.excludedCommands?.includes(entry)),
|
|
410
|
+
} : {}),
|
|
134
411
|
};
|
|
135
412
|
}
|
|
136
413
|
function rebuildClaudePermissions(settings, ownerKey, desired) {
|
|
137
414
|
const previousGenerated = mergePermissionStates(Object.values(settings.awGenerated?.permissions ?? {}));
|
|
138
|
-
const currentPermissions = mergePermissionStates([
|
|
415
|
+
const currentPermissions = mergePermissionStates([{
|
|
416
|
+
...settings.permissions,
|
|
417
|
+
...(settings.sandbox?.excludedCommands ? { excludedCommands: settings.sandbox.excludedCommands } : {}),
|
|
418
|
+
}]);
|
|
139
419
|
const manual = mergePermissionStates([
|
|
140
420
|
subtractPermissionState(currentPermissions, previousGenerated),
|
|
141
421
|
intersectPermissionState(intersectPermissionState(settings.awGenerated?.manualPermissions, previousGenerated), currentPermissions),
|
|
@@ -149,1814 +429,289 @@ function rebuildClaudePermissions(settings, ownerKey, desired) {
|
|
|
149
429
|
if (Object.keys(settings.awGenerated.permissions).length === 0) {
|
|
150
430
|
delete settings.awGenerated.permissions;
|
|
151
431
|
}
|
|
152
|
-
if (manual.allow.length || manual.ask.length || manual.deny.length) {
|
|
432
|
+
if (manual.allow.length || manual.ask.length || manual.deny.length || manual.excludedCommands?.length) {
|
|
153
433
|
settings.awGenerated.manualPermissions = manual;
|
|
154
434
|
}
|
|
155
435
|
else {
|
|
156
436
|
delete settings.awGenerated.manualPermissions;
|
|
157
437
|
}
|
|
158
|
-
|
|
438
|
+
const combined = mergePermissionStates([
|
|
159
439
|
manual,
|
|
160
|
-
...Object.values(settings.awGenerated.permissions ?? {}),
|
|
161
|
-
]);
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
function createClaudePermissionsComponent(options) {
|
|
170
|
-
const ownerKey = createSharedOwnerToken(options.identity);
|
|
171
|
-
return {
|
|
172
|
-
kind: 'shared-config',
|
|
173
|
-
identity: options.identity,
|
|
174
|
-
label: `${options.settingsPath}#awGenerated.permissions.${ownerKey}`,
|
|
175
|
-
inspect: async () => {
|
|
176
|
-
const settings = await readClaudeSettings(options.settingsPath);
|
|
177
|
-
return settings.awGenerated?.permissions?.[ownerKey] ? 'present' : 'absent';
|
|
178
|
-
},
|
|
179
|
-
remove: async () => {
|
|
180
|
-
const settings = await readClaudeSettings(options.settingsPath);
|
|
181
|
-
rebuildClaudePermissions(settings, ownerKey);
|
|
182
|
-
await writeClaudeSettings(options.settingsPath, settings);
|
|
183
|
-
},
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
function createCodexInstructionComponent(options) {
|
|
187
|
-
const ownerKey = createSharedOwnerToken(options.identity);
|
|
188
|
-
return {
|
|
189
|
-
kind: 'managed-block',
|
|
190
|
-
identity: options.identity,
|
|
191
|
-
label: `${options.configPath}#developer_instructions:${ownerKey}`,
|
|
192
|
-
inspect: async () => {
|
|
193
|
-
const config = await readCodexConfigFile(options.configPath);
|
|
194
|
-
return config.snapshot.developerInstructions.managedBlocks[ownerKey]
|
|
195
|
-
? 'present'
|
|
196
|
-
: 'absent';
|
|
197
|
-
},
|
|
198
|
-
remove: async () => {
|
|
199
|
-
await applyCodexConfigTransactionFile(options.configPath, {
|
|
200
|
-
removeManagedInstructionPluginName: ownerKey,
|
|
201
|
-
});
|
|
202
|
-
},
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
function codexMcpOwner(actual) {
|
|
206
|
-
const envValue = actual?.value?.env;
|
|
207
|
-
return envValue
|
|
208
|
-
&& typeof envValue === 'object'
|
|
209
|
-
&& !Array.isArray(envValue)
|
|
210
|
-
&& typeof envValue[MCP_OWNER_ENV] === 'string'
|
|
211
|
-
? envValue[MCP_OWNER_ENV]
|
|
212
|
-
: null;
|
|
213
|
-
}
|
|
214
|
-
function createCodexMcpComponent(options) {
|
|
215
|
-
const ownerKey = createSharedOwnerToken(options.identity);
|
|
216
|
-
return {
|
|
217
|
-
kind: 'shared-config',
|
|
218
|
-
identity: options.identity,
|
|
219
|
-
label: `${options.configPath}#mcp_servers.${options.serverKey}`,
|
|
220
|
-
inspect: async () => {
|
|
221
|
-
const config = await readCodexConfigFile(options.configPath);
|
|
222
|
-
const actual = config.snapshot.mcpServers[options.serverKey];
|
|
223
|
-
if (!actual)
|
|
224
|
-
return 'absent';
|
|
225
|
-
return codexMcpOwner(actual) === ownerKey ? 'present' : 'foreign';
|
|
226
|
-
},
|
|
227
|
-
remove: async () => {
|
|
228
|
-
await applyConditionalCodexConfigTransactionFile(options.configPath, (snapshot) => {
|
|
229
|
-
const actual = snapshot.mcpServers[options.serverKey];
|
|
230
|
-
return codexMcpOwner(actual) === ownerKey
|
|
231
|
-
? { removeMcpServers: [options.serverKey] }
|
|
232
|
-
: null;
|
|
233
|
-
});
|
|
234
|
-
},
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
async function codexRoleRegistrationOwned(options) {
|
|
238
|
-
if (!options.registration?.configFile)
|
|
239
|
-
return false;
|
|
240
|
-
const expected = path.normalize(path.relative(path.dirname(options.configPath), options.rolePath));
|
|
241
|
-
const actual = path.normalize(path.relative(path.dirname(options.configPath), path.resolve(path.dirname(options.configPath), options.registration.configFile)));
|
|
242
|
-
if (actual !== expected)
|
|
243
|
-
return false;
|
|
244
|
-
const raw = await fs.readFile(options.rolePath, 'utf8').catch(() => '');
|
|
245
|
-
try {
|
|
246
|
-
return Boolean(parseOwnedTextHeader(raw, options.fileIdentity));
|
|
247
|
-
}
|
|
248
|
-
catch {
|
|
249
|
-
return false;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
function createCodexRoleRegistrationComponent(options) {
|
|
253
|
-
const inspect = async () => {
|
|
254
|
-
const config = await readCodexConfigFile(options.configPath);
|
|
255
|
-
const registration = config.snapshot.agents[options.roleKey];
|
|
256
|
-
if (!registration)
|
|
257
|
-
return 'absent';
|
|
258
|
-
return await codexRoleRegistrationOwned({ ...options, registration })
|
|
259
|
-
? 'present'
|
|
260
|
-
: 'foreign';
|
|
261
|
-
};
|
|
262
|
-
return {
|
|
263
|
-
kind: 'shared-config',
|
|
264
|
-
identity: options.identity,
|
|
265
|
-
label: `${options.configPath}#agents.${options.roleKey}`,
|
|
266
|
-
inspect,
|
|
267
|
-
remove: async () => {
|
|
268
|
-
await applyConditionalCodexConfigTransactionFile(options.configPath, async (snapshot) => {
|
|
269
|
-
const registration = snapshot.agents[options.roleKey];
|
|
270
|
-
return await codexRoleRegistrationOwned({ ...options, registration })
|
|
271
|
-
? { removeAgentRegistrations: [options.roleKey] }
|
|
272
|
-
: null;
|
|
273
|
-
});
|
|
274
|
-
},
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
async function readCodexHooks(hooksPath) {
|
|
278
|
-
if (!await fs.pathExists(hooksPath))
|
|
279
|
-
return parseCodexSharedHooksFile({ hooks: {} });
|
|
280
|
-
return parseCodexSharedHooksFile(await fs.readJson(hooksPath));
|
|
281
|
-
}
|
|
282
|
-
function renderCodexHookGroups(groups) {
|
|
283
|
-
const hooks = {};
|
|
284
|
-
for (const group of groups) {
|
|
285
|
-
hooks[group.event] ??= [];
|
|
286
|
-
hooks[group.event].push(group.rawGroup);
|
|
287
|
-
}
|
|
288
|
-
return `${JSON.stringify({ hooks }, null, 2)}\n`;
|
|
289
|
-
}
|
|
290
|
-
export async function applyCodexHookGroupsTransactionFile(hooksPath, update, testHooks) {
|
|
291
|
-
return withConfigFileMutation({
|
|
292
|
-
filePath: hooksPath,
|
|
293
|
-
allowedRoot: path.dirname(hooksPath),
|
|
294
|
-
action: async () => {
|
|
295
|
-
const parsed = await readCodexHooks(hooksPath);
|
|
296
|
-
const groups = update(parsed);
|
|
297
|
-
if (!groups)
|
|
298
|
-
return false;
|
|
299
|
-
await testHooks?.beforeCommit?.();
|
|
300
|
-
if (groups.length === 0) {
|
|
301
|
-
await atomicRemoveConfigFile({
|
|
302
|
-
filePath: hooksPath,
|
|
303
|
-
allowedRoot: path.dirname(hooksPath),
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
else {
|
|
307
|
-
await atomicReplaceConfigFile({
|
|
308
|
-
filePath: hooksPath,
|
|
309
|
-
allowedRoot: path.dirname(hooksPath),
|
|
310
|
-
content: renderCodexHookGroups(groups),
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
return true;
|
|
314
|
-
},
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
function renderCodexSharedHookGroup(identity) {
|
|
318
|
-
const rendered = renderTrackedHookGroupIdentity(identity);
|
|
319
|
-
const rawGroup = {
|
|
320
|
-
...(rendered.matcher === undefined ? {} : { matcher: rendered.matcher }),
|
|
321
|
-
hooks: rendered.hooks,
|
|
322
|
-
};
|
|
323
|
-
return {
|
|
324
|
-
event: rendered.event,
|
|
325
|
-
matcher: rendered.matcher,
|
|
326
|
-
hooks: rendered.hooks,
|
|
327
|
-
rawGroup,
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
function createCodexHookComponent(options) {
|
|
331
|
-
const serialized = serializeTrackedHookGroupIdentity(options.identity);
|
|
332
|
-
return {
|
|
333
|
-
kind: 'shared-config',
|
|
334
|
-
identity: ownerIdentity(options.pluginName, internalArtifactKey('hook', serialized), 'codex', options.scope),
|
|
335
|
-
label: `${options.hooksPath}#${serialized}`,
|
|
336
|
-
inspect: async () => {
|
|
337
|
-
const parsed = await readCodexHooks(options.hooksPath);
|
|
338
|
-
return parsed.managedIdentities.some((entry) => serializeTrackedHookGroupIdentity(entry) === serialized)
|
|
339
|
-
? 'present'
|
|
340
|
-
: 'absent';
|
|
341
|
-
},
|
|
342
|
-
remove: async () => {
|
|
343
|
-
await applyCodexHookGroupsTransactionFile(options.hooksPath, (parsed) => {
|
|
344
|
-
let removed = false;
|
|
345
|
-
const remaining = parsed.groups.flatMap((entry) => {
|
|
346
|
-
if (!removed
|
|
347
|
-
&& entry.managedIdentity
|
|
348
|
-
&& serializeTrackedHookGroupIdentity(entry.managedIdentity) === serialized) {
|
|
349
|
-
removed = true;
|
|
350
|
-
return [];
|
|
351
|
-
}
|
|
352
|
-
return [entry.rawGroup];
|
|
353
|
-
});
|
|
354
|
-
return removed ? remaining : null;
|
|
355
|
-
});
|
|
356
|
-
},
|
|
357
|
-
};
|
|
358
|
-
}
|
|
359
|
-
function ownedCodexHookIdentity(options) {
|
|
360
|
-
const artifactKey = internalArtifactKey('hook', serializeTrackedHookGroupIdentity(options.identity));
|
|
361
|
-
const identity = {
|
|
362
|
-
...ownerIdentity(options.pluginName, artifactKey, 'codex', options.scope),
|
|
363
|
-
...(options.sourceId ? {
|
|
364
|
-
sourceId: options.sourceId,
|
|
365
|
-
sourceIdentity: options.sourceIdentity,
|
|
366
|
-
pluginId: options.pluginId,
|
|
367
|
-
} : {}),
|
|
368
|
-
};
|
|
369
|
-
return {
|
|
370
|
-
...options.identity,
|
|
371
|
-
command: `${OWNED_TEXT_HEADER_PREFIX}${JSON.stringify(JSON.parse(createSkillOwnerMarkerContent(identity)))}\n${options.identity.command}`,
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
function sameOwnerIdentity(left, right) {
|
|
375
|
-
return left.owner === right.owner
|
|
376
|
-
&& left.sourceId === right.sourceId
|
|
377
|
-
&& left.sourceIdentity === right.sourceIdentity
|
|
378
|
-
&& left.pluginId === right.pluginId
|
|
379
|
-
&& left.plugin === right.plugin
|
|
380
|
-
&& left.artifactKey === right.artifactKey
|
|
381
|
-
&& left.platform === right.platform
|
|
382
|
-
&& left.scope === right.scope;
|
|
383
|
-
}
|
|
384
|
-
function readOwnedHookIdentity(identity, scope) {
|
|
385
|
-
try {
|
|
386
|
-
const parsed = parseOwnedTextHeader(identity.command);
|
|
387
|
-
return parsed?.identity.platform === 'codex' && parsed.identity.scope === scope
|
|
388
|
-
? parsed.identity
|
|
389
|
-
: null;
|
|
390
|
-
}
|
|
391
|
-
catch {
|
|
392
|
-
return null;
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
function sharedOwnerPluginName(value) {
|
|
396
|
-
return parseSharedOwnerToken(value)?.plugin ?? value;
|
|
397
|
-
}
|
|
398
|
-
async function scanCodexSharedComponents(options) {
|
|
399
|
-
const output = [];
|
|
400
|
-
const expectedIdentity = (artifactKey) => ({
|
|
401
|
-
...ownerIdentity(options.pluginName, artifactKey, 'codex', options.scope),
|
|
402
|
-
...(options.sourceId ? {
|
|
403
|
-
sourceId: options.sourceId,
|
|
404
|
-
sourceIdentity: options.sourceIdentity,
|
|
405
|
-
pluginId: options.pluginId,
|
|
406
|
-
} : {}),
|
|
407
|
-
});
|
|
408
|
-
const corruptedComponent = (filePath, error) => ({
|
|
409
|
-
kind: 'shared-config',
|
|
410
|
-
identity: ownerIdentity(options.pluginName, internalArtifactKey('corrupted-shared-config', filePath), 'codex', options.scope),
|
|
411
|
-
label: filePath,
|
|
412
|
-
inspect: async () => {
|
|
413
|
-
throw new Error(`包含 ${options.pluginName} 的 AW ownership 证据,但共享配置无法解析:${error instanceof Error ? error.message : String(error)}`);
|
|
414
|
-
},
|
|
415
|
-
remove: async () => undefined,
|
|
416
|
-
});
|
|
417
|
-
const containsOwnedEvidence = (raw) => raw.includes(options.pluginName) && (raw.includes('[[aw-managed:start plugin=')
|
|
418
|
-
|| raw.includes(MCP_OWNER_ENV)
|
|
419
|
-
|| raw.includes(OWNED_TEXT_HEADER_PREFIX)
|
|
420
|
-
|| raw.includes('agent-workflows'));
|
|
421
|
-
if (options.scanConfig) {
|
|
422
|
-
const config = await readCodexConfigFile(options.paths.configTomlPath).catch(async (error) => {
|
|
423
|
-
if (!options.ignoreReadErrors)
|
|
424
|
-
throw error;
|
|
425
|
-
const raw = await fs.readFile(options.paths.configTomlPath, 'utf8').catch(() => '');
|
|
426
|
-
if (containsOwnedEvidence(raw)) {
|
|
427
|
-
output.push(corruptedComponent(options.paths.configTomlPath, error));
|
|
428
|
-
}
|
|
429
|
-
return null;
|
|
430
|
-
});
|
|
431
|
-
const instructionIdentity = expectedIdentity('developer-instructions');
|
|
432
|
-
const instructionOwnerKey = createSharedOwnerToken(instructionIdentity);
|
|
433
|
-
if (config?.snapshot.developerInstructions.managedBlocks[instructionOwnerKey]) {
|
|
434
|
-
output.push(createCodexInstructionComponent({
|
|
435
|
-
identity: instructionIdentity,
|
|
436
|
-
scope: options.scope,
|
|
437
|
-
configPath: options.paths.configTomlPath,
|
|
438
|
-
}));
|
|
439
|
-
}
|
|
440
|
-
for (const [serverKey, server] of Object.entries(config?.snapshot.mcpServers ?? {})) {
|
|
441
|
-
const envValue = server.value?.env;
|
|
442
|
-
if (envValue
|
|
443
|
-
&& typeof envValue === 'object'
|
|
444
|
-
&& !Array.isArray(envValue)
|
|
445
|
-
&& parseSharedOwnerToken(String(envValue[MCP_OWNER_ENV]))?.pluginId === options.pluginId) {
|
|
446
|
-
const identity = expectedIdentity(internalArtifactKey('mcp', serverKey));
|
|
447
|
-
if (createSharedOwnerToken(identity) !== envValue[MCP_OWNER_ENV])
|
|
448
|
-
continue;
|
|
449
|
-
output.push(createCodexMcpComponent({
|
|
450
|
-
identity,
|
|
451
|
-
scope: options.scope,
|
|
452
|
-
configPath: options.paths.configTomlPath,
|
|
453
|
-
serverKey,
|
|
454
|
-
owned: true,
|
|
455
|
-
}));
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
for (const [roleKey, registration] of Object.entries(config?.snapshot.agents ?? {})) {
|
|
459
|
-
if (!registration.configFile)
|
|
460
|
-
continue;
|
|
461
|
-
const rolePath = path.resolve(path.dirname(options.paths.configTomlPath), registration.configFile);
|
|
462
|
-
const raw = await fs.readFile(rolePath, 'utf8').catch(() => '');
|
|
463
|
-
const parsed = (() => {
|
|
464
|
-
try {
|
|
465
|
-
return parseOwnedTextHeader(raw);
|
|
466
|
-
}
|
|
467
|
-
catch {
|
|
468
|
-
return null;
|
|
469
|
-
}
|
|
470
|
-
})();
|
|
471
|
-
if (!parsed || !sameOwnerIdentity(parsed.identity, expectedIdentity(roleKey)))
|
|
472
|
-
continue;
|
|
473
|
-
output.push(createCodexRoleRegistrationComponent({
|
|
474
|
-
identity: expectedIdentity(internalArtifactKey('role', roleKey)),
|
|
475
|
-
fileIdentity: expectedIdentity(roleKey),
|
|
476
|
-
configPath: options.paths.configTomlPath,
|
|
477
|
-
roleKey,
|
|
478
|
-
rolePath,
|
|
479
|
-
}));
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
if (options.scope === 'project' && options.scanHooks) {
|
|
483
|
-
const hooks = await readCodexHooks(options.paths.hooksPath).catch(async (error) => {
|
|
484
|
-
if (!options.ignoreReadErrors)
|
|
485
|
-
throw error;
|
|
486
|
-
const raw = await fs.readFile(options.paths.hooksPath, 'utf8').catch(() => '');
|
|
487
|
-
if (containsOwnedEvidence(raw)) {
|
|
488
|
-
output.push(corruptedComponent(options.paths.hooksPath, error));
|
|
489
|
-
}
|
|
490
|
-
return null;
|
|
491
|
-
});
|
|
492
|
-
for (const identity of hooks?.managedIdentities ?? []) {
|
|
493
|
-
const parsedIdentity = readOwnedHookIdentity(identity, options.scope);
|
|
494
|
-
if (!parsedIdentity || !sameOwnerIdentity(parsedIdentity, expectedIdentity(parsedIdentity.artifactKey)))
|
|
495
|
-
continue;
|
|
496
|
-
output.push(createCodexHookComponent({
|
|
497
|
-
pluginName: options.pluginName,
|
|
498
|
-
scope: options.scope,
|
|
499
|
-
hooksPath: options.paths.hooksPath,
|
|
500
|
-
identity,
|
|
501
|
-
}));
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
return output;
|
|
505
|
-
}
|
|
506
|
-
async function scanClaudeSharedComponents(options) {
|
|
507
|
-
const settings = await readClaudeSettings(options.settingsPath);
|
|
508
|
-
const identity = {
|
|
509
|
-
...ownerIdentity(options.pluginName, 'permissions', 'claude', options.scope),
|
|
510
|
-
...(options.sourceId ? {
|
|
511
|
-
sourceId: options.sourceId,
|
|
512
|
-
sourceIdentity: options.sourceIdentity,
|
|
513
|
-
pluginId: options.pluginId,
|
|
514
|
-
} : {}),
|
|
515
|
-
};
|
|
516
|
-
return settings.awGenerated?.permissions?.[createSharedOwnerToken(identity)]
|
|
517
|
-
? [createClaudePermissionsComponent({ ...options, identity })]
|
|
518
|
-
: [];
|
|
519
|
-
}
|
|
520
|
-
async function scanOwnedTextFiles(options) {
|
|
521
|
-
if (!await fs.pathExists(options.root))
|
|
522
|
-
return [];
|
|
523
|
-
const output = [];
|
|
524
|
-
const pending = [options.root];
|
|
525
|
-
while (pending.length > 0) {
|
|
526
|
-
const current = pending.pop();
|
|
527
|
-
for (const entry of await fs.readdir(current, { withFileTypes: true })) {
|
|
528
|
-
const entryPath = path.join(current, entry.name);
|
|
529
|
-
if (entry.isSymbolicLink())
|
|
530
|
-
continue;
|
|
531
|
-
if (entry.isDirectory()) {
|
|
532
|
-
pending.push(entryPath);
|
|
533
|
-
continue;
|
|
534
|
-
}
|
|
535
|
-
if (!entry.isFile())
|
|
536
|
-
continue;
|
|
537
|
-
const raw = await fs.readFile(entryPath, 'utf8').catch(() => '');
|
|
538
|
-
if (!raw.includes(OWNED_TEXT_HEADER_PREFIX))
|
|
539
|
-
continue;
|
|
540
|
-
let parsed;
|
|
541
|
-
try {
|
|
542
|
-
parsed = parseOwnedTextHeader(raw);
|
|
543
|
-
}
|
|
544
|
-
catch {
|
|
545
|
-
continue;
|
|
546
|
-
}
|
|
547
|
-
if (parsed?.identity.plugin !== options.pluginName
|
|
548
|
-
|| (options.sourceId !== undefined && parsed.identity.sourceId !== options.sourceId)
|
|
549
|
-
|| (options.sourceIdentity !== undefined
|
|
550
|
-
&& parsed.identity.sourceIdentity !== options.sourceIdentity)
|
|
551
|
-
|| parsed.identity.platform !== options.platform
|
|
552
|
-
|| parsed.identity.scope !== options.scope)
|
|
553
|
-
continue;
|
|
554
|
-
output.push(pathComponent({
|
|
555
|
-
kind: 'owned-text-file',
|
|
556
|
-
path: entryPath,
|
|
557
|
-
allowedRoot: options.root,
|
|
558
|
-
identity: parsed.identity,
|
|
559
|
-
}));
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
return output;
|
|
563
|
-
}
|
|
564
|
-
async function scanOwnedSkills(options) {
|
|
565
|
-
if (!await fs.pathExists(options.root))
|
|
566
|
-
return [];
|
|
567
|
-
const output = [];
|
|
568
|
-
const pending = [options.root];
|
|
569
|
-
while (pending.length > 0) {
|
|
570
|
-
const current = pending.pop();
|
|
571
|
-
for (const entry of await fs.readdir(current, { withFileTypes: true })) {
|
|
572
|
-
if (!entry.isDirectory() || entry.isSymbolicLink())
|
|
573
|
-
continue;
|
|
574
|
-
const skillRoot = path.join(current, entry.name);
|
|
575
|
-
const marker = await readSkillOwnerMarker({
|
|
576
|
-
skillRoot,
|
|
577
|
-
allowedRoot: current,
|
|
578
|
-
}).catch(() => null);
|
|
579
|
-
if (marker?.plugin === options.pluginName
|
|
580
|
-
&& (options.sourceId === undefined || marker.sourceId === options.sourceId)
|
|
581
|
-
&& (options.sourceIdentity === undefined || marker.sourceIdentity === options.sourceIdentity)
|
|
582
|
-
&& marker.platform === options.platform
|
|
583
|
-
&& marker.scope === options.scope) {
|
|
584
|
-
output.push(pathComponent({
|
|
585
|
-
kind: 'skill-directory',
|
|
586
|
-
path: skillRoot,
|
|
587
|
-
allowedRoot: current,
|
|
588
|
-
identity: marker,
|
|
589
|
-
}));
|
|
590
|
-
continue;
|
|
591
|
-
}
|
|
592
|
-
pending.push(skillRoot);
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
return output;
|
|
596
|
-
}
|
|
597
|
-
function componentIdentityKey(component) {
|
|
598
|
-
return [
|
|
599
|
-
component.kind,
|
|
600
|
-
component.identity.artifactKey,
|
|
601
|
-
'path' in component ? path.resolve(component.path) : 'label' in component ? component.label : component.pluginId,
|
|
602
|
-
].join('\0');
|
|
603
|
-
}
|
|
604
|
-
function dedupeComponents(components) {
|
|
605
|
-
const seen = new Set();
|
|
606
|
-
return components.filter((component) => {
|
|
607
|
-
const key = componentIdentityKey(component);
|
|
608
|
-
if (seen.has(key))
|
|
609
|
-
return false;
|
|
610
|
-
seen.add(key);
|
|
611
|
-
return true;
|
|
612
|
-
});
|
|
613
|
-
}
|
|
614
|
-
async function preflightCodexWriteSafety(options) {
|
|
615
|
-
const pluginName = options.plugin.manifest.name;
|
|
616
|
-
const userConfigPath = resolveCodexPaths(options.cwd, 'user', options.env).configTomlPath;
|
|
617
|
-
const projectConfigPath = resolveCodexPaths(options.cwd, 'project', options.env).configTomlPath;
|
|
618
|
-
let userConfig;
|
|
619
|
-
try {
|
|
620
|
-
userConfig = await readCodexConfigFile(userConfigPath);
|
|
621
|
-
}
|
|
622
|
-
catch (error) {
|
|
623
|
-
throw new Error(`codexProjectUserConfigUnreadable: 无法解析用户级 Codex 配置 ${userConfigPath}:${error instanceof Error ? error.message : String(error)}`);
|
|
624
|
-
}
|
|
625
|
-
if (options.scope === 'project') {
|
|
626
|
-
const expectedPluginId = `${pluginName}@${options.plugin.marketplaceName ?? MARKETPLACE_NAME}`;
|
|
627
|
-
for (const [key, plugin] of Object.entries(userConfig.snapshot.plugins)) {
|
|
628
|
-
if (key !== expectedPluginId
|
|
629
|
-
&& (key === pluginName || key.startsWith(`${pluginName}@`) || plugin.name === pluginName)) {
|
|
630
|
-
throw new Error(`externalOwnershipPresent: 用户级 Codex 已存在同名外部插件 ${key}。`);
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
const roleKeys = new Set((options.plugin.manifest.artifacts?.targets ?? [])
|
|
635
|
-
.filter((target) => target.platform === 'codex'
|
|
636
|
-
&& target.scopes.includes(options.scope)
|
|
637
|
-
&& target.target === 'codex.agentRole'
|
|
638
|
-
&& target.roleKey)
|
|
639
|
-
.map((target) => target.roleKey));
|
|
640
|
-
const needsProjectConfig = options.scope === 'project' && Boolean(options.plugin.manifest.mcpServers
|
|
641
|
-
|| resolvePlatformEntries(options.plugin.manifest.extensions?.instructions, 'codex').length > 0
|
|
642
|
-
|| (options.plugin.manifest.artifacts?.targets ?? []).some((target) => target.platform === 'codex'
|
|
643
|
-
&& target.scopes.includes('project')
|
|
644
|
-
&& (target.target === 'codex.agentRole'
|
|
645
|
-
|| target.target === 'codex.developerInstructionsBlock')));
|
|
646
|
-
if (needsProjectConfig) {
|
|
647
|
-
try {
|
|
648
|
-
await readCodexConfigFile(projectConfigPath);
|
|
649
|
-
}
|
|
650
|
-
catch (error) {
|
|
651
|
-
throw new Error(`projectConfigUnreadable: 无法解析项目级 Codex 配置 ${projectConfigPath}:${error instanceof Error ? error.message : String(error)}`);
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
if (roleKeys.size === 0)
|
|
655
|
-
return;
|
|
656
|
-
for (const configPath of options.scope === 'project'
|
|
657
|
-
? [userConfigPath, projectConfigPath]
|
|
658
|
-
: [userConfigPath]) {
|
|
659
|
-
const configScope = configPath === userConfigPath ? 'user' : 'project';
|
|
660
|
-
const ownedRolePaths = [];
|
|
661
|
-
const ownedRoleKeys = [];
|
|
662
|
-
for (const roleKey of roleKeys) {
|
|
663
|
-
const rolePath = path.join(path.dirname(configPath), 'agents', `${buildGeneratedName(pluginName, roleKey)}.toml`);
|
|
664
|
-
const raw = await fs.readFile(rolePath, 'utf8').catch(() => '');
|
|
665
|
-
try {
|
|
666
|
-
if (parseOwnedTextHeader(raw, pluginOwnerIdentity(options.plugin, roleKey, 'codex', configScope))) {
|
|
667
|
-
ownedRolePaths.push(rolePath);
|
|
668
|
-
ownedRoleKeys.push(roleKey);
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
catch {
|
|
672
|
-
// A foreign file remains external below.
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
let namespace;
|
|
676
|
-
try {
|
|
677
|
-
namespace = await resolveCodexRoleNamespace(configPath, {
|
|
678
|
-
strict: true,
|
|
679
|
-
awManagedTableKeys: ownedRoleKeys,
|
|
680
|
-
awManagedRoleLayerPaths: ownedRolePaths,
|
|
681
|
-
});
|
|
682
|
-
}
|
|
683
|
-
catch (error) {
|
|
684
|
-
throw new Error(`projectConfigUnreadable: 无法读取 Codex role namespace ${configPath}:${error instanceof Error ? error.message : String(error)}`);
|
|
685
|
-
}
|
|
686
|
-
for (const roleKey of roleKeys) {
|
|
687
|
-
const tableCollision = namespace.roles.find((role) => role.source === 'registration' && role.tableKey === roleKey && !role.awManaged);
|
|
688
|
-
const nameConflict = findCodexRoleNameConflict(namespace, roleKey);
|
|
689
|
-
if (tableCollision || nameConflict?.conflict) {
|
|
690
|
-
throw new Error(`roleNameConflict: Codex role "${roleKey}" 已由外部配置占用(${configPath})。`);
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
function renderCodexRole(options) {
|
|
696
|
-
const stringValue = (value) => JSON.stringify(value.trim());
|
|
697
|
-
return [
|
|
698
|
-
`name = ${stringValue(options.roleKey)}`,
|
|
699
|
-
`description = ${stringValue(options.description)}`,
|
|
700
|
-
`developer_instructions = ${stringValue(options.developerInstructions)}`,
|
|
701
|
-
...(options.model ? [`model = ${stringValue(options.model)}`] : []),
|
|
702
|
-
...(options.modelReasoningEffort
|
|
703
|
-
? [`model_reasoning_effort = ${stringValue(options.modelReasoningEffort)}`]
|
|
704
|
-
: []),
|
|
705
|
-
'',
|
|
706
|
-
].join('\n');
|
|
707
|
-
}
|
|
708
|
-
async function resolveCodexMcpServers(plugin, scope) {
|
|
709
|
-
if (!plugin.manifest.mcpServers)
|
|
710
|
-
return {};
|
|
711
|
-
const relative = plugin.manifest.mcpServers.replace(/^\.\//u, '');
|
|
712
|
-
const direct = path.resolve(plugin.rootDir, relative);
|
|
713
|
-
const mcpPath = await fs.pathExists(direct)
|
|
714
|
-
? direct
|
|
715
|
-
: path.resolve(plugin.rootDir, 'codex', relative);
|
|
716
|
-
const servers = await readRenderedCodexMcpServersFile(mcpPath);
|
|
717
|
-
return Object.fromEntries(Object.entries(servers).map(([key, server]) => {
|
|
718
|
-
const existingEnv = server.env;
|
|
719
|
-
if (existingEnv !== undefined && (typeof existingEnv !== 'object' || Array.isArray(existingEnv))) {
|
|
720
|
-
throw new Error(`MCP server ${key} 的 env 必须是 object。`);
|
|
721
|
-
}
|
|
722
|
-
const env = (existingEnv ?? {});
|
|
723
|
-
const ownerKey = createSharedOwnerToken(pluginOwnerIdentity(plugin, internalArtifactKey('mcp', key), 'codex', scope));
|
|
724
|
-
if (env[MCP_OWNER_ENV] !== undefined
|
|
725
|
-
&& env[MCP_OWNER_ENV] !== plugin.manifest.name
|
|
726
|
-
&& env[MCP_OWNER_ENV] !== ownerKey) {
|
|
727
|
-
throw new Error(`MCP server ${key} 不能覆盖保留的 ${MCP_OWNER_ENV} owner marker。`);
|
|
728
|
-
}
|
|
729
|
-
return [key, {
|
|
730
|
-
...server,
|
|
731
|
-
env: { ...env, [MCP_OWNER_ENV]: ownerKey },
|
|
732
|
-
}];
|
|
733
|
-
}));
|
|
734
|
-
}
|
|
735
|
-
async function resolveDynamicArtifacts(options) {
|
|
736
|
-
const declarations = (options.plugin.manifest.artifacts?.targets ?? []).filter((target) => target.platform === options.platform && target.scopes.includes(options.scope));
|
|
737
|
-
if (declarations.length === 0)
|
|
738
|
-
return { artifacts: [], sourceDirs: () => [] };
|
|
739
|
-
const render = await runArtifactRenderer({
|
|
740
|
-
event: options.event,
|
|
741
|
-
plugin: options.plugin,
|
|
742
|
-
platform: options.platform,
|
|
743
|
-
scope: options.scope,
|
|
744
|
-
cwd: options.cwd,
|
|
745
|
-
commandEnv: options.env,
|
|
746
|
-
previousArtifacts: [...options.previousArtifacts],
|
|
747
|
-
scriptTimeoutMs: options.scriptTimeoutMs,
|
|
748
|
-
});
|
|
749
|
-
const config = await resolveArtifactRenderConfig({
|
|
750
|
-
sourceId: options.plugin.sourceId,
|
|
751
|
-
sourceIdentity: options.plugin.sourceIdentity,
|
|
752
|
-
pluginName: options.plugin.manifest.name,
|
|
753
|
-
manifest: options.plugin.manifest,
|
|
754
|
-
scope: options.scope,
|
|
755
|
-
cwd: options.cwd,
|
|
756
|
-
env: options.env,
|
|
757
|
-
});
|
|
758
|
-
const artifacts = validateArtifactPlan({
|
|
759
|
-
manifest: options.plugin.manifest,
|
|
760
|
-
plan: render.plan,
|
|
761
|
-
platform: options.platform,
|
|
762
|
-
scope: options.scope,
|
|
763
|
-
renderConfig: config,
|
|
764
|
-
rendererDigest: render.target.rendererDigest,
|
|
765
|
-
manifestDigest: render.target.manifestDigest,
|
|
766
|
-
}).artifacts;
|
|
767
|
-
return {
|
|
768
|
-
artifacts,
|
|
769
|
-
sourceDirs: (artifact) => render.context.artifactSources.find((entry) => entry.id === artifact.id && entry.target === artifact.target)?.sourceDirs ?? [],
|
|
770
|
-
};
|
|
771
|
-
}
|
|
772
|
-
function dynamicSkillWrite(options) {
|
|
773
|
-
const skillKey = 'skillKey' in options.artifact ? options.artifact.skillKey : '';
|
|
774
|
-
const identity = ownerIdentity(options.plugin.manifest.name, skillKey, options.platform, options.scope);
|
|
775
|
-
const component = pathComponent({
|
|
776
|
-
kind: 'skill-directory',
|
|
777
|
-
path: options.skillPath,
|
|
778
|
-
allowedRoot: options.allowedRoot,
|
|
779
|
-
identity,
|
|
780
|
-
...(options.platform === 'codex' && options.scope === 'user'
|
|
781
|
-
? {
|
|
782
|
-
unownedIsPristine: (actualPath) => skillDirectoryMatchesExpectedTree(actualPath, options.tree),
|
|
783
|
-
}
|
|
784
|
-
: {}),
|
|
785
|
-
});
|
|
786
|
-
return {
|
|
787
|
-
artifact: {
|
|
788
|
-
path: options.skillPath,
|
|
789
|
-
paths: Object.keys(options.tree.files).map((relativePath) => path.join(options.skillPath, relativePath.split('/').join(path.sep))),
|
|
790
|
-
kind: 'skill',
|
|
791
|
-
platform: options.platform,
|
|
792
|
-
artifactKey: skillKey,
|
|
793
|
-
id: options.artifact.id,
|
|
794
|
-
target: options.artifact.target,
|
|
795
|
-
state: options.artifact.state,
|
|
796
|
-
...(options.artifact.disabledReason
|
|
797
|
-
? { disabledReason: options.artifact.disabledReason }
|
|
798
|
-
: {}),
|
|
799
|
-
refreshKeys: [...options.artifact.refreshKeys],
|
|
800
|
-
configDigest: options.artifact.configDigest,
|
|
801
|
-
contentDigest: options.platform === 'codex'
|
|
802
|
-
? createCodexSkillStagingTreeContentDigest(options.tree)
|
|
803
|
-
: createDynamicSkillTreeContentDigest(options.tree),
|
|
804
|
-
},
|
|
805
|
-
...(options.artifact.state === 'present' ? { component } : {}),
|
|
806
|
-
write: async () => {
|
|
807
|
-
if (options.artifact.state === 'disabled') {
|
|
808
|
-
return;
|
|
809
|
-
}
|
|
810
|
-
await writeDynamicSkillTree(options.skillPath, options.tree, {
|
|
811
|
-
allowedRoot: options.allowedRoot,
|
|
812
|
-
identity,
|
|
813
|
-
allowPristineUnowned: options.platform === 'codex' && options.scope === 'user',
|
|
814
|
-
});
|
|
815
|
-
},
|
|
816
|
-
};
|
|
817
|
-
}
|
|
818
|
-
async function resolveCodexSkillsRelativeRoot(plugin, marketplaceFallbackRoot) {
|
|
819
|
-
const manifestPaths = [
|
|
820
|
-
path.join(plugin.rootDir, '.codex-plugin', 'plugin.json'),
|
|
821
|
-
...(marketplaceFallbackRoot
|
|
822
|
-
? [path.join(marketplaceFallbackRoot, '.codex-plugin', 'plugin.json')]
|
|
823
|
-
: []),
|
|
824
|
-
];
|
|
825
|
-
let manifest = null;
|
|
826
|
-
for (const manifestPath of manifestPaths) {
|
|
827
|
-
manifest = await fs.readJson(manifestPath).catch(() => null);
|
|
828
|
-
if (manifest)
|
|
829
|
-
break;
|
|
830
|
-
}
|
|
831
|
-
const raw = typeof manifest?.skills === 'string' && manifest.skills.trim() !== ''
|
|
832
|
-
? manifest.skills
|
|
833
|
-
: plugin.manifest.skills ?? './codex/skills';
|
|
834
|
-
const normalized = path.posix.normalize(raw.replace(/^\.\//u, ''));
|
|
835
|
-
if (normalized === '..' || normalized.startsWith('../') || path.isAbsolute(normalized)) {
|
|
836
|
-
throw new Error(`Codex plugin skills root 越界:${raw}`);
|
|
837
|
-
}
|
|
838
|
-
return normalized;
|
|
839
|
-
}
|
|
840
|
-
async function buildBundledCodexSkillWrites(options) {
|
|
841
|
-
const relativeRoot = await resolveCodexSkillsRelativeRoot(options.plugin);
|
|
842
|
-
const sourceRoot = path.join(options.plugin.rootDir, ...relativeRoot.split('/'));
|
|
843
|
-
if (!await fs.pathExists(sourceRoot))
|
|
844
|
-
return [];
|
|
845
|
-
const dynamicKeys = new Set((options.plugin.manifest.artifacts?.targets ?? [])
|
|
846
|
-
.filter((target) => target.target === 'codex.skill' && target.skillKey)
|
|
847
|
-
.map((target) => target.skillKey));
|
|
848
|
-
const targetRoot = options.scope === 'project'
|
|
849
|
-
? path.join(options.repoRoot, '.agents', 'skills')
|
|
850
|
-
: path.join(options.marketplaceRoot ?? resolveAwHome(options.env), 'plugins', options.plugin.manifest.name, ...relativeRoot.split('/'));
|
|
851
|
-
const writes = [];
|
|
852
|
-
for (const entry of await fs.readdir(sourceRoot, { withFileTypes: true })) {
|
|
853
|
-
if (entry.isSymbolicLink()) {
|
|
854
|
-
throw new Error(`Codex skills source 不能包含符号链接:${entry.name}`);
|
|
855
|
-
}
|
|
856
|
-
if (!entry.isDirectory() || dynamicKeys.has(entry.name))
|
|
857
|
-
continue;
|
|
858
|
-
const skillSource = path.join(sourceRoot, entry.name);
|
|
859
|
-
if (!await fs.pathExists(path.join(skillSource, 'SKILL.md')))
|
|
860
|
-
continue;
|
|
861
|
-
const tree = await createCodexSkillExpectedTree({
|
|
862
|
-
artifact: {
|
|
863
|
-
target: 'codex.skill',
|
|
864
|
-
skillKey: entry.name,
|
|
865
|
-
state: 'present',
|
|
866
|
-
content: { files: {} },
|
|
867
|
-
},
|
|
868
|
-
sourceDirs: [skillSource],
|
|
869
|
-
sourceRequirementsReceiptPolicy: 'allow',
|
|
870
|
-
});
|
|
871
|
-
const skillPath = path.join(targetRoot, entry.name);
|
|
872
|
-
const canRecoverPristine = options.scope === 'user'
|
|
873
|
-
&& path.resolve(skillSource) !== path.resolve(skillPath);
|
|
874
|
-
const identity = ownerIdentity(options.plugin.manifest.name, entry.name, 'codex', options.scope);
|
|
875
|
-
const component = pathComponent({
|
|
876
|
-
kind: 'skill-directory',
|
|
877
|
-
path: skillPath,
|
|
878
|
-
allowedRoot: targetRoot,
|
|
879
|
-
identity,
|
|
880
|
-
...(canRecoverPristine
|
|
881
|
-
? {
|
|
882
|
-
unownedIsPristine: (actualPath) => skillDirectoryMatchesExpectedTree(actualPath, tree),
|
|
883
|
-
}
|
|
884
|
-
: {}),
|
|
885
|
-
});
|
|
886
|
-
writes.push({
|
|
887
|
-
artifact: {
|
|
888
|
-
path: skillPath,
|
|
889
|
-
paths: Object.keys(tree.files).map((relativePath) => path.join(skillPath, relativePath)),
|
|
890
|
-
kind: 'skill',
|
|
891
|
-
platform: 'codex',
|
|
892
|
-
artifactKey: entry.name,
|
|
893
|
-
},
|
|
894
|
-
component,
|
|
895
|
-
write: async () => {
|
|
896
|
-
await writeDynamicSkillTree(skillPath, tree, {
|
|
897
|
-
allowedRoot: targetRoot,
|
|
898
|
-
identity,
|
|
899
|
-
allowPristineUnowned: canRecoverPristine,
|
|
900
|
-
});
|
|
901
|
-
},
|
|
902
|
-
});
|
|
903
|
-
}
|
|
904
|
-
return writes;
|
|
905
|
-
}
|
|
906
|
-
async function buildClaudeWrites(options) {
|
|
907
|
-
const paths = resolveClaudePaths(options.cwd, options.scope, options.env);
|
|
908
|
-
const writes = [];
|
|
909
|
-
const dynamic = await resolveDynamicArtifacts({
|
|
910
|
-
...options,
|
|
911
|
-
platform: 'claude',
|
|
912
|
-
previousArtifacts: options.historicalArtifacts,
|
|
913
|
-
});
|
|
914
|
-
for (const artifact of dynamic.artifacts.filter((entry) => entry.target === 'claude.skill')) {
|
|
915
|
-
const skillKey = artifact.skillKey;
|
|
916
|
-
const tree = await createDynamicSkillExpectedTree({
|
|
917
|
-
artifact,
|
|
918
|
-
sourceDirs: dynamic.sourceDirs(artifact),
|
|
919
|
-
requireReadme: true,
|
|
920
|
-
requirementsReceipt: requirementsReceipt(options.plugin),
|
|
921
|
-
sourceRequirementsReceiptPolicy: 'allow',
|
|
922
|
-
});
|
|
923
|
-
writes.push(dynamicSkillWrite({
|
|
924
|
-
...options,
|
|
925
|
-
platform: 'claude',
|
|
926
|
-
artifact,
|
|
927
|
-
skillPath: path.join(paths.configDir, 'skills', skillKey),
|
|
928
|
-
allowedRoot: path.join(paths.configDir, 'skills'),
|
|
929
|
-
tree,
|
|
930
|
-
}));
|
|
931
|
-
}
|
|
932
|
-
for (const artifact of generateInstructionArtifacts(options.plugin.manifest.name, resolvePlatformEntries(options.plugin.manifest.extensions?.instructions, 'claude'), 'claude')) {
|
|
933
|
-
writes.push(generatedTextWrite({
|
|
934
|
-
...options,
|
|
935
|
-
platform: 'claude',
|
|
936
|
-
configDir: paths.configDir,
|
|
937
|
-
relativePath: artifact.relativePath,
|
|
938
|
-
artifactKey: artifact.artifactKey,
|
|
939
|
-
content: artifact.content,
|
|
940
|
-
kind: 'instruction',
|
|
941
|
-
}));
|
|
942
|
-
}
|
|
943
|
-
const permissions = resolvePlatformEntries(options.plugin.manifest.extensions?.permissions, 'claude');
|
|
944
|
-
if (permissions.length > 0) {
|
|
945
|
-
const component = createClaudePermissionsComponent({
|
|
946
|
-
identity: pluginOwnerIdentity(options.plugin, 'permissions', 'claude', options.scope),
|
|
947
|
-
scope: options.scope,
|
|
948
|
-
settingsPath: paths.settingsPath,
|
|
949
|
-
});
|
|
950
|
-
writes.push({
|
|
951
|
-
artifact: { path: paths.settingsPath, kind: 'permission', platform: 'claude' },
|
|
952
|
-
component,
|
|
953
|
-
write: async () => {
|
|
954
|
-
const settings = await readClaudeSettings(paths.settingsPath);
|
|
955
|
-
rebuildClaudePermissions(settings, createSharedOwnerToken(component.identity), mergeClaudePermissions(permissions));
|
|
956
|
-
await writeClaudeSettings(paths.settingsPath, settings);
|
|
957
|
-
},
|
|
958
|
-
});
|
|
959
|
-
}
|
|
960
|
-
return writes;
|
|
961
|
-
}
|
|
962
|
-
async function buildCodexWrites(options) {
|
|
963
|
-
const paths = resolveCodexPaths(options.cwd, options.scope, options.env);
|
|
964
|
-
const writes = [];
|
|
965
|
-
const dynamic = await resolveDynamicArtifacts({
|
|
966
|
-
...options,
|
|
967
|
-
platform: 'codex',
|
|
968
|
-
previousArtifacts: options.historicalArtifacts,
|
|
969
|
-
});
|
|
970
|
-
const dynamicInstructions = dynamic.artifacts.filter((entry) => entry.target === 'codex.developerInstructionsBlock');
|
|
971
|
-
const dynamicRoles = dynamic.artifacts.filter((entry) => entry.target === 'codex.agentRole');
|
|
972
|
-
const dynamicSkills = dynamic.artifacts.filter((entry) => entry.target === 'codex.skill');
|
|
973
|
-
const repoRoot = await resolveRepoRoot(options.cwd);
|
|
974
|
-
writes.push(...await buildBundledCodexSkillWrites({
|
|
975
|
-
plugin: options.plugin,
|
|
976
|
-
scope: options.scope,
|
|
977
|
-
repoRoot,
|
|
978
|
-
env: options.env,
|
|
979
|
-
marketplaceRoot: options.marketplaceRoot,
|
|
980
|
-
}));
|
|
981
|
-
const relativeSkillsRoot = await resolveCodexSkillsRelativeRoot(options.plugin);
|
|
982
|
-
const skillRoot = options.scope === 'user'
|
|
983
|
-
? path.join(options.marketplaceRoot ?? resolveAwHome(options.env), 'plugins', options.plugin.manifest.name, ...relativeSkillsRoot.split('/'))
|
|
984
|
-
: path.join(repoRoot, '.agents', 'skills');
|
|
985
|
-
for (const artifact of dynamicSkills) {
|
|
986
|
-
const tree = await createCodexSkillExpectedTree({
|
|
987
|
-
artifact,
|
|
988
|
-
sourceDirs: dynamic.sourceDirs(artifact),
|
|
989
|
-
requireReadme: true,
|
|
990
|
-
requirementsReceipt: requirementsReceipt(options.plugin),
|
|
991
|
-
sourceRequirementsReceiptPolicy: 'allow',
|
|
992
|
-
});
|
|
993
|
-
writes.push(dynamicSkillWrite({
|
|
994
|
-
...options,
|
|
995
|
-
platform: 'codex',
|
|
996
|
-
artifact,
|
|
997
|
-
skillPath: path.join(skillRoot, artifact.skillKey),
|
|
998
|
-
allowedRoot: skillRoot,
|
|
999
|
-
tree,
|
|
1000
|
-
}));
|
|
1001
|
-
}
|
|
1002
|
-
const staticInstructions = dynamicInstructions.length > 0
|
|
1003
|
-
? []
|
|
1004
|
-
: resolvePlatformEntries(options.plugin.manifest.extensions?.instructions, 'codex');
|
|
1005
|
-
const mcpServers = await resolveCodexMcpServers(options.plugin, options.scope);
|
|
1006
|
-
const hasInstructionOutput = dynamicInstructions.length > 0 || staticInstructions.length > 0;
|
|
1007
|
-
if (hasInstructionOutput) {
|
|
1008
|
-
const component = createCodexInstructionComponent({
|
|
1009
|
-
identity: pluginOwnerIdentity(options.plugin, 'developer-instructions', 'codex', options.scope),
|
|
1010
|
-
scope: options.scope,
|
|
1011
|
-
configPath: paths.configTomlPath,
|
|
1012
|
-
});
|
|
1013
|
-
const dynamicBlock = dynamicInstructions.length > 0
|
|
1014
|
-
? composeManagedDeveloperInstructionsBlock(options.plugin.manifest.name, dynamicInstructions
|
|
1015
|
-
.filter((entry) => entry.state === 'present')
|
|
1016
|
-
.map((entry) => ({ artifactId: entry.id, value: entry.content })))
|
|
1017
|
-
: undefined;
|
|
1018
|
-
const block = dynamicBlock?.value
|
|
1019
|
-
? { ...dynamicBlock, pluginName: createSharedOwnerToken(component.identity) }
|
|
1020
|
-
: staticInstructions.length > 0
|
|
1021
|
-
? {
|
|
1022
|
-
pluginName: createSharedOwnerToken(component.identity),
|
|
1023
|
-
value: renderCodexManagedInstructionBlock(options.plugin.manifest.name, staticInstructions),
|
|
1024
|
-
}
|
|
1025
|
-
: undefined;
|
|
1026
|
-
for (const artifact of dynamicInstructions.length > 0 ? dynamicInstructions : [{
|
|
1027
|
-
id: undefined,
|
|
1028
|
-
target: undefined,
|
|
1029
|
-
state: 'present',
|
|
1030
|
-
refreshKeys: [],
|
|
1031
|
-
configDigest: undefined,
|
|
1032
|
-
disabledReason: undefined,
|
|
1033
|
-
}]) {
|
|
1034
|
-
writes.push({
|
|
1035
|
-
artifact: {
|
|
1036
|
-
path: paths.configTomlPath,
|
|
1037
|
-
kind: 'instruction',
|
|
1038
|
-
platform: 'codex',
|
|
1039
|
-
...(artifact.id ? { id: artifact.id } : {}),
|
|
1040
|
-
...(artifact.target ? { target: artifact.target } : {}),
|
|
1041
|
-
state: artifact.state,
|
|
1042
|
-
refreshKeys: [...artifact.refreshKeys],
|
|
1043
|
-
...(artifact.configDigest ? { configDigest: artifact.configDigest } : {}),
|
|
1044
|
-
...(artifact.disabledReason ? { disabledReason: artifact.disabledReason } : {}),
|
|
1045
|
-
},
|
|
1046
|
-
...(block ? { component } : {}),
|
|
1047
|
-
write: async () => {
|
|
1048
|
-
await applyCodexConfigTransactionFile(paths.configTomlPath, block
|
|
1049
|
-
? { upsertManagedInstructionBlock: block }
|
|
1050
|
-
: { removeManagedInstructionPluginName: createSharedOwnerToken(component.identity) });
|
|
1051
|
-
},
|
|
1052
|
-
});
|
|
1053
|
-
}
|
|
1054
|
-
}
|
|
1055
|
-
for (const [serverKey, server] of Object.entries(mcpServers)) {
|
|
1056
|
-
const component = createCodexMcpComponent({
|
|
1057
|
-
identity: pluginOwnerIdentity(options.plugin, internalArtifactKey('mcp', serverKey), 'codex', options.scope),
|
|
1058
|
-
scope: options.scope,
|
|
1059
|
-
configPath: paths.configTomlPath,
|
|
1060
|
-
serverKey,
|
|
1061
|
-
owned: false,
|
|
1062
|
-
});
|
|
1063
|
-
writes.push({
|
|
1064
|
-
artifact: {
|
|
1065
|
-
path: paths.configTomlPath,
|
|
1066
|
-
kind: 'mcpServer',
|
|
1067
|
-
platform: 'codex',
|
|
1068
|
-
artifactKey: serverKey,
|
|
1069
|
-
},
|
|
1070
|
-
component,
|
|
1071
|
-
write: async () => {
|
|
1072
|
-
await applyConditionalCodexConfigTransactionFile(paths.configTomlPath, (snapshot) => {
|
|
1073
|
-
const actual = snapshot.mcpServers[serverKey];
|
|
1074
|
-
const actualOwner = codexMcpOwner(actual);
|
|
1075
|
-
if (actual && actualOwner !== createSharedOwnerToken(component.identity)) {
|
|
1076
|
-
throw new Error(`Codex MCP server "${serverKey}" is foreign and cannot be overwritten by plugin "${options.plugin.manifest.name}".`);
|
|
1077
|
-
}
|
|
1078
|
-
return { upsertMcpServers: { [serverKey]: server } };
|
|
1079
|
-
});
|
|
1080
|
-
},
|
|
1081
|
-
});
|
|
1082
|
-
}
|
|
1083
|
-
for (const artifact of dynamicRoles) {
|
|
1084
|
-
const roleKey = artifact.roleKey;
|
|
1085
|
-
const rolePath = path.join(paths.configDir, 'agents', `${buildGeneratedName(options.plugin.manifest.name, roleKey)}.toml`);
|
|
1086
|
-
const roleComponent = pathComponent({
|
|
1087
|
-
kind: 'owned-text-file',
|
|
1088
|
-
path: rolePath,
|
|
1089
|
-
allowedRoot: paths.configDir,
|
|
1090
|
-
identity: pluginOwnerIdentity(options.plugin, roleKey, 'codex', options.scope),
|
|
1091
|
-
});
|
|
1092
|
-
const registrationComponent = createCodexRoleRegistrationComponent({
|
|
1093
|
-
identity: pluginOwnerIdentity(options.plugin, internalArtifactKey('role', roleKey), 'codex', options.scope),
|
|
1094
|
-
fileIdentity: roleComponent.identity,
|
|
1095
|
-
configPath: paths.configTomlPath,
|
|
1096
|
-
roleKey,
|
|
1097
|
-
rolePath,
|
|
1098
|
-
});
|
|
1099
|
-
const roleFile = artifact.content?.roleFile;
|
|
1100
|
-
const description = artifact.content?.registration?.description
|
|
1101
|
-
?? roleFile?.description;
|
|
1102
|
-
const present = artifact.state === 'present';
|
|
1103
|
-
if (present && (!description || !roleFile?.developer_instructions)) {
|
|
1104
|
-
throw new Error(`Artifact "${artifact.id}" 的 codex.agentRole 缺少 description 或 developer_instructions。`);
|
|
1105
|
-
}
|
|
1106
|
-
writes.push({
|
|
1107
|
-
artifact: {
|
|
1108
|
-
path: rolePath,
|
|
1109
|
-
paths: [paths.configTomlPath, rolePath],
|
|
1110
|
-
kind: 'agent',
|
|
1111
|
-
platform: 'codex',
|
|
1112
|
-
artifactKey: roleKey,
|
|
1113
|
-
roleKey,
|
|
1114
|
-
id: artifact.id,
|
|
1115
|
-
target: artifact.target,
|
|
1116
|
-
state: artifact.state,
|
|
1117
|
-
refreshKeys: [...artifact.refreshKeys],
|
|
1118
|
-
configDigest: artifact.configDigest,
|
|
1119
|
-
...(artifact.disabledReason ? { disabledReason: artifact.disabledReason } : {}),
|
|
1120
|
-
},
|
|
1121
|
-
...(present ? { component: roleComponent } : {}),
|
|
1122
|
-
...(present ? { additionalComponents: [registrationComponent] } : {}),
|
|
1123
|
-
write: async () => {
|
|
1124
|
-
if (!present) {
|
|
1125
|
-
return;
|
|
1126
|
-
}
|
|
1127
|
-
await fs.ensureDir(paths.configDir);
|
|
1128
|
-
await writeOwnedTextFile({
|
|
1129
|
-
path: rolePath,
|
|
1130
|
-
allowedRoot: paths.configDir,
|
|
1131
|
-
identity: roleComponent.identity,
|
|
1132
|
-
content: renderCodexRole({
|
|
1133
|
-
roleKey,
|
|
1134
|
-
description: description,
|
|
1135
|
-
developerInstructions: roleFile.developer_instructions,
|
|
1136
|
-
model: roleFile.model,
|
|
1137
|
-
modelReasoningEffort: roleFile.model_reasoning_effort,
|
|
1138
|
-
}),
|
|
1139
|
-
});
|
|
1140
|
-
const registration = {
|
|
1141
|
-
description,
|
|
1142
|
-
configFile: path.relative(path.dirname(paths.configTomlPath), rolePath).split(path.sep).join('/'),
|
|
1143
|
-
};
|
|
1144
|
-
await applyConditionalCodexConfigTransactionFile(paths.configTomlPath, async (snapshot) => {
|
|
1145
|
-
const actual = snapshot.agents[roleKey];
|
|
1146
|
-
if (actual && !await codexRoleRegistrationOwned({
|
|
1147
|
-
fileIdentity: roleComponent.identity,
|
|
1148
|
-
configPath: paths.configTomlPath,
|
|
1149
|
-
roleKey,
|
|
1150
|
-
rolePath,
|
|
1151
|
-
registration: actual,
|
|
1152
|
-
})) {
|
|
1153
|
-
throw new Error(`Codex agent registration "${roleKey}" is foreign and cannot be overwritten by plugin "${options.plugin.manifest.name}".`);
|
|
1154
|
-
}
|
|
1155
|
-
return { upsertAgentRegistrations: { [roleKey]: registration } };
|
|
1156
|
-
});
|
|
1157
|
-
},
|
|
1158
|
-
});
|
|
1159
|
-
}
|
|
1160
|
-
for (const artifact of generateCodexPermissionArtifacts(options.plugin.manifest.name, resolvePlatformEntries(options.plugin.manifest.extensions?.permissions, 'codex'))) {
|
|
1161
|
-
writes.push(generatedTextWrite({
|
|
1162
|
-
...options,
|
|
1163
|
-
platform: 'codex',
|
|
1164
|
-
configDir: paths.configDir,
|
|
1165
|
-
relativePath: artifact.relativePath,
|
|
1166
|
-
artifactKey: artifact.artifactKey,
|
|
1167
|
-
content: artifact.content,
|
|
1168
|
-
kind: 'permission',
|
|
1169
|
-
}));
|
|
1170
|
-
}
|
|
1171
|
-
for (const artifact of generateAgentArtifacts(options.plugin.manifest.name, resolvePlatformEntries(options.plugin.manifest.extensions?.agents, 'codex'), 'codex')) {
|
|
1172
|
-
writes.push(generatedTextWrite({
|
|
1173
|
-
...options,
|
|
1174
|
-
platform: 'codex',
|
|
1175
|
-
configDir: paths.configDir,
|
|
1176
|
-
relativePath: artifact.relativePath,
|
|
1177
|
-
artifactKey: artifact.artifactKey,
|
|
1178
|
-
content: artifact.content,
|
|
1179
|
-
kind: 'agent',
|
|
1180
|
-
}));
|
|
1181
|
-
}
|
|
1182
|
-
if (options.scope === 'project') {
|
|
1183
|
-
const hooks = resolvePlatformHookDefinitions(options.plugin.manifest, 'codex');
|
|
1184
|
-
for (const rawIdentity of extractCodexHookGroups(hooks)) {
|
|
1185
|
-
const identity = ownedCodexHookIdentity({
|
|
1186
|
-
pluginName: options.plugin.manifest.name,
|
|
1187
|
-
sourceId: options.plugin.sourceId,
|
|
1188
|
-
sourceIdentity: options.plugin.sourceIdentity,
|
|
1189
|
-
pluginId: options.plugin.pluginId,
|
|
1190
|
-
scope: options.scope,
|
|
1191
|
-
identity: rawIdentity,
|
|
1192
|
-
});
|
|
1193
|
-
const component = createCodexHookComponent({
|
|
1194
|
-
pluginName: options.plugin.manifest.name,
|
|
1195
|
-
scope: options.scope,
|
|
1196
|
-
hooksPath: paths.hooksPath,
|
|
1197
|
-
identity,
|
|
1198
|
-
});
|
|
1199
|
-
writes.push({
|
|
1200
|
-
artifact: {
|
|
1201
|
-
path: paths.hooksPath,
|
|
1202
|
-
kind: 'hook',
|
|
1203
|
-
platform: 'codex',
|
|
1204
|
-
hookGroups: [identity],
|
|
1205
|
-
},
|
|
1206
|
-
component,
|
|
1207
|
-
write: async () => {
|
|
1208
|
-
await applyCodexHookGroupsTransactionFile(paths.hooksPath, (parsed) => {
|
|
1209
|
-
const serialized = serializeTrackedHookGroupIdentity(identity);
|
|
1210
|
-
const exists = parsed.managedIdentities.some((entry) => serializeTrackedHookGroupIdentity(entry) === serialized);
|
|
1211
|
-
return exists
|
|
1212
|
-
? null
|
|
1213
|
-
: [...parsed.rawGroups, renderCodexSharedHookGroup(identity)];
|
|
1214
|
-
});
|
|
1215
|
-
},
|
|
1216
|
-
});
|
|
1217
|
-
}
|
|
1218
|
-
}
|
|
1219
|
-
return writes;
|
|
1220
|
-
}
|
|
1221
|
-
async function buildInspectionWrites(options) {
|
|
1222
|
-
const writes = [];
|
|
1223
|
-
if (options.platform === 'claude') {
|
|
1224
|
-
const paths = resolveClaudePaths(options.cwd, options.scope, options.env);
|
|
1225
|
-
for (const artifact of generateInstructionArtifacts(options.plugin.manifest.name, resolvePlatformEntries(options.plugin.manifest.extensions?.instructions, 'claude'), 'claude')) {
|
|
1226
|
-
writes.push(generatedTextWrite({
|
|
1227
|
-
...options,
|
|
1228
|
-
configDir: paths.configDir,
|
|
1229
|
-
relativePath: artifact.relativePath,
|
|
1230
|
-
artifactKey: artifact.artifactKey,
|
|
1231
|
-
content: artifact.content,
|
|
1232
|
-
kind: 'instruction',
|
|
1233
|
-
}));
|
|
1234
|
-
}
|
|
1235
|
-
if (resolvePlatformEntries(options.plugin.manifest.extensions?.permissions, 'claude').length > 0) {
|
|
1236
|
-
writes.push({
|
|
1237
|
-
artifact: { path: paths.settingsPath, kind: 'permission', platform: 'claude' },
|
|
1238
|
-
component: createClaudePermissionsComponent({
|
|
1239
|
-
identity: pluginOwnerIdentity(options.plugin, 'permissions', 'claude', options.scope),
|
|
1240
|
-
scope: options.scope,
|
|
1241
|
-
settingsPath: paths.settingsPath,
|
|
1242
|
-
}),
|
|
1243
|
-
write: async () => undefined,
|
|
1244
|
-
});
|
|
1245
|
-
}
|
|
1246
|
-
for (const target of options.plugin.manifest.artifacts?.targets ?? []) {
|
|
1247
|
-
if (target.platform !== 'claude'
|
|
1248
|
-
|| !target.scopes.includes(options.scope)
|
|
1249
|
-
|| target.target !== 'claude.skill'
|
|
1250
|
-
|| !target.skillKey)
|
|
1251
|
-
continue;
|
|
1252
|
-
const state = target.states.includes('present') ? 'present' : 'disabled';
|
|
1253
|
-
const skillPath = path.join(paths.configDir, 'skills', target.skillKey);
|
|
1254
|
-
const component = pathComponent({
|
|
1255
|
-
kind: 'skill-directory',
|
|
1256
|
-
path: skillPath,
|
|
1257
|
-
allowedRoot: path.dirname(skillPath),
|
|
1258
|
-
identity: ownerIdentity(options.plugin.manifest.name, target.skillKey, 'claude', options.scope),
|
|
1259
|
-
});
|
|
1260
|
-
writes.push({
|
|
1261
|
-
artifact: {
|
|
1262
|
-
path: skillPath,
|
|
1263
|
-
kind: 'skill',
|
|
1264
|
-
platform: 'claude',
|
|
1265
|
-
artifactKey: target.skillKey,
|
|
1266
|
-
id: target.id,
|
|
1267
|
-
target: target.target,
|
|
1268
|
-
state,
|
|
1269
|
-
},
|
|
1270
|
-
...(state === 'present' ? { component } : {}),
|
|
1271
|
-
...(target.states.includes('present') && target.states.includes('disabled')
|
|
1272
|
-
? { optional: true }
|
|
1273
|
-
: {}),
|
|
1274
|
-
write: async () => undefined,
|
|
1275
|
-
});
|
|
1276
|
-
}
|
|
1277
|
-
return writes;
|
|
1278
|
-
}
|
|
1279
|
-
const paths = resolveCodexPaths(options.cwd, options.scope, options.env);
|
|
1280
|
-
const repoRoot = await resolveRepoRoot(options.cwd);
|
|
1281
|
-
writes.push(...await buildBundledCodexSkillWrites({
|
|
1282
|
-
plugin: options.plugin,
|
|
1283
|
-
scope: options.scope,
|
|
1284
|
-
repoRoot,
|
|
1285
|
-
env: options.env,
|
|
1286
|
-
marketplaceRoot: options.marketplaceRoot,
|
|
1287
|
-
}));
|
|
1288
|
-
const instructions = resolvePlatformEntries(options.plugin.manifest.extensions?.instructions, 'codex');
|
|
1289
|
-
const targets = (options.plugin.manifest.artifacts?.targets ?? []).filter((target) => target.platform === 'codex' && target.scopes.includes(options.scope));
|
|
1290
|
-
const instructionTargets = targets.filter((target) => target.target === 'codex.developerInstructionsBlock');
|
|
1291
|
-
const presentCapableInstructionTargets = instructionTargets.filter((target) => target.states.includes('present'));
|
|
1292
|
-
const instructionDesired = presentCapableInstructionTargets.length > 0;
|
|
1293
|
-
const instructionOptional = presentCapableInstructionTargets.length > 0
|
|
1294
|
-
&& presentCapableInstructionTargets.every((target) => target.states.includes('disabled'));
|
|
1295
|
-
if (instructions.length > 0 || instructionDesired) {
|
|
1296
|
-
writes.push({
|
|
1297
|
-
artifact: { path: paths.configTomlPath, kind: 'instruction', platform: 'codex' },
|
|
1298
|
-
component: createCodexInstructionComponent({
|
|
1299
|
-
identity: pluginOwnerIdentity(options.plugin, 'developer-instructions', 'codex', options.scope),
|
|
1300
|
-
scope: options.scope,
|
|
1301
|
-
configPath: paths.configTomlPath,
|
|
1302
|
-
}),
|
|
1303
|
-
...(instructions.length === 0 && instructionOptional ? { optional: true } : {}),
|
|
1304
|
-
write: async () => undefined,
|
|
1305
|
-
});
|
|
1306
|
-
}
|
|
1307
|
-
const mcpServers = await resolveCodexMcpServers(options.plugin, options.scope);
|
|
1308
|
-
for (const serverKey of Object.keys(mcpServers)) {
|
|
1309
|
-
writes.push({
|
|
1310
|
-
artifact: {
|
|
1311
|
-
path: paths.configTomlPath,
|
|
1312
|
-
kind: 'mcpServer',
|
|
1313
|
-
platform: 'codex',
|
|
1314
|
-
artifactKey: serverKey,
|
|
1315
|
-
},
|
|
1316
|
-
component: createCodexMcpComponent({
|
|
1317
|
-
identity: pluginOwnerIdentity(options.plugin, internalArtifactKey('mcp', serverKey), 'codex', options.scope),
|
|
1318
|
-
scope: options.scope,
|
|
1319
|
-
configPath: paths.configTomlPath,
|
|
1320
|
-
serverKey,
|
|
1321
|
-
owned: false,
|
|
1322
|
-
}),
|
|
1323
|
-
write: async () => undefined,
|
|
1324
|
-
});
|
|
1325
|
-
}
|
|
1326
|
-
const relativeSkillsRoot = await resolveCodexSkillsRelativeRoot(options.plugin);
|
|
1327
|
-
const dynamicSkillRoot = options.scope === 'user'
|
|
1328
|
-
? path.join(options.marketplaceRoot ?? resolveAwHome(options.env), 'plugins', options.plugin.manifest.name, ...relativeSkillsRoot.split('/'))
|
|
1329
|
-
: path.join(repoRoot, '.agents', 'skills');
|
|
1330
|
-
for (const target of targets) {
|
|
1331
|
-
const state = target.states.includes('present') ? 'present' : 'disabled';
|
|
1332
|
-
if (target.target === 'codex.skill' && target.skillKey) {
|
|
1333
|
-
const skillPath = path.join(dynamicSkillRoot, target.skillKey);
|
|
1334
|
-
const component = pathComponent({
|
|
1335
|
-
kind: 'skill-directory',
|
|
1336
|
-
path: skillPath,
|
|
1337
|
-
allowedRoot: dynamicSkillRoot,
|
|
1338
|
-
identity: ownerIdentity(options.plugin.manifest.name, target.skillKey, 'codex', options.scope),
|
|
1339
|
-
});
|
|
1340
|
-
writes.push({
|
|
1341
|
-
artifact: {
|
|
1342
|
-
path: skillPath,
|
|
1343
|
-
kind: 'skill',
|
|
1344
|
-
platform: 'codex',
|
|
1345
|
-
artifactKey: target.skillKey,
|
|
1346
|
-
id: target.id,
|
|
1347
|
-
target: target.target,
|
|
1348
|
-
state,
|
|
1349
|
-
},
|
|
1350
|
-
...(state === 'present' ? { component } : {}),
|
|
1351
|
-
...(target.states.includes('present') && target.states.includes('disabled')
|
|
1352
|
-
? { optional: true }
|
|
1353
|
-
: {}),
|
|
1354
|
-
write: async () => undefined,
|
|
1355
|
-
});
|
|
1356
|
-
}
|
|
1357
|
-
if (target.target === 'codex.agentRole' && target.roleKey) {
|
|
1358
|
-
const rolePath = path.join(paths.configDir, 'agents', `${buildGeneratedName(options.plugin.manifest.name, target.roleKey)}.toml`);
|
|
1359
|
-
const roleComponent = pathComponent({
|
|
1360
|
-
kind: 'owned-text-file',
|
|
1361
|
-
path: rolePath,
|
|
1362
|
-
allowedRoot: paths.configDir,
|
|
1363
|
-
identity: pluginOwnerIdentity(options.plugin, target.roleKey, 'codex', options.scope),
|
|
1364
|
-
});
|
|
1365
|
-
const registrationComponent = createCodexRoleRegistrationComponent({
|
|
1366
|
-
identity: pluginOwnerIdentity(options.plugin, internalArtifactKey('role', target.roleKey), 'codex', options.scope),
|
|
1367
|
-
fileIdentity: pluginOwnerIdentity(options.plugin, target.roleKey, 'codex', options.scope),
|
|
1368
|
-
configPath: paths.configTomlPath,
|
|
1369
|
-
roleKey: target.roleKey,
|
|
1370
|
-
rolePath,
|
|
1371
|
-
});
|
|
1372
|
-
writes.push({
|
|
1373
|
-
artifact: {
|
|
1374
|
-
path: rolePath,
|
|
1375
|
-
kind: 'agent',
|
|
1376
|
-
platform: 'codex',
|
|
1377
|
-
artifactKey: target.roleKey,
|
|
1378
|
-
roleKey: target.roleKey,
|
|
1379
|
-
id: target.id,
|
|
1380
|
-
target: target.target,
|
|
1381
|
-
state,
|
|
1382
|
-
},
|
|
1383
|
-
...(state === 'present'
|
|
1384
|
-
? { component: roleComponent, additionalComponents: [registrationComponent] }
|
|
1385
|
-
: {}),
|
|
1386
|
-
...(target.states.includes('present') && target.states.includes('disabled')
|
|
1387
|
-
? { optional: true }
|
|
1388
|
-
: {}),
|
|
1389
|
-
write: async () => undefined,
|
|
1390
|
-
});
|
|
1391
|
-
}
|
|
1392
|
-
}
|
|
1393
|
-
for (const artifact of generateCodexPermissionArtifacts(options.plugin.manifest.name, resolvePlatformEntries(options.plugin.manifest.extensions?.permissions, 'codex'))) {
|
|
1394
|
-
writes.push(generatedTextWrite({
|
|
1395
|
-
...options,
|
|
1396
|
-
configDir: paths.configDir,
|
|
1397
|
-
relativePath: artifact.relativePath,
|
|
1398
|
-
artifactKey: artifact.artifactKey,
|
|
1399
|
-
content: artifact.content,
|
|
1400
|
-
kind: 'permission',
|
|
1401
|
-
}));
|
|
1402
|
-
}
|
|
1403
|
-
for (const artifact of generateAgentArtifacts(options.plugin.manifest.name, resolvePlatformEntries(options.plugin.manifest.extensions?.agents, 'codex'), 'codex')) {
|
|
1404
|
-
writes.push(generatedTextWrite({
|
|
1405
|
-
...options,
|
|
1406
|
-
configDir: paths.configDir,
|
|
1407
|
-
relativePath: artifact.relativePath,
|
|
1408
|
-
artifactKey: artifact.artifactKey,
|
|
1409
|
-
content: artifact.content,
|
|
1410
|
-
kind: 'agent',
|
|
1411
|
-
}));
|
|
440
|
+
...Object.values(settings.awGenerated.permissions ?? {}),
|
|
441
|
+
]);
|
|
442
|
+
settings.permissions = {
|
|
443
|
+
...settings.permissions, allow: combined.allow, ask: combined.ask, deny: combined.deny,
|
|
444
|
+
};
|
|
445
|
+
if (combined.excludedCommands !== undefined) {
|
|
446
|
+
settings.sandbox = { ...settings.sandbox, excludedCommands: combined.excludedCommands };
|
|
1412
447
|
}
|
|
1413
|
-
if (
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
sourceIdentity: options.plugin.sourceIdentity,
|
|
1419
|
-
pluginId: options.plugin.pluginId,
|
|
1420
|
-
scope: options.scope,
|
|
1421
|
-
identity: rawIdentity,
|
|
1422
|
-
});
|
|
1423
|
-
writes.push({
|
|
1424
|
-
artifact: {
|
|
1425
|
-
path: paths.hooksPath,
|
|
1426
|
-
kind: 'hook',
|
|
1427
|
-
platform: 'codex',
|
|
1428
|
-
hookGroups: [identity],
|
|
1429
|
-
},
|
|
1430
|
-
component: createCodexHookComponent({
|
|
1431
|
-
pluginName: options.plugin.manifest.name,
|
|
1432
|
-
scope: options.scope,
|
|
1433
|
-
hooksPath: paths.hooksPath,
|
|
1434
|
-
identity,
|
|
1435
|
-
}),
|
|
1436
|
-
write: async () => undefined,
|
|
1437
|
-
});
|
|
1438
|
-
}
|
|
448
|
+
if (settings.awGenerated.permissions === undefined
|
|
449
|
+
&& settings.awGenerated.manualPermissions === undefined
|
|
450
|
+
&& settings.awGenerated.hooks === undefined
|
|
451
|
+
&& settings.awGenerated.manualHooks === undefined) {
|
|
452
|
+
delete settings.awGenerated;
|
|
1439
453
|
}
|
|
1440
|
-
return writes;
|
|
1441
|
-
}
|
|
1442
|
-
async function buildHistoricalComponents(options) {
|
|
1443
|
-
const components = [];
|
|
1444
|
-
const paths = options.platform === 'codex'
|
|
1445
|
-
? resolveCodexPaths(options.cwd, options.scope, options.env)
|
|
1446
|
-
: resolveClaudePaths(options.cwd, options.scope, options.env);
|
|
1447
|
-
const historicalIdentity = (artifactKey) => ({
|
|
1448
|
-
...ownerIdentity(options.pluginName, artifactKey, options.platform, options.scope),
|
|
1449
|
-
...(options.sourceId ? {
|
|
1450
|
-
sourceId: options.sourceId,
|
|
1451
|
-
sourceIdentity: options.sourceIdentity,
|
|
1452
|
-
pluginId: options.pluginId,
|
|
1453
|
-
} : {}),
|
|
1454
|
-
});
|
|
1455
|
-
for (const artifact of options.artifacts) {
|
|
1456
|
-
if (artifact.platform !== options.platform)
|
|
1457
|
-
continue;
|
|
1458
|
-
if (artifact.state === 'disabled')
|
|
1459
|
-
continue;
|
|
1460
|
-
if (artifact.kind === 'hook' && options.platform === 'codex') {
|
|
1461
|
-
for (const identity of artifact.hookGroups ?? []) {
|
|
1462
|
-
components.push(createCodexHookComponent({
|
|
1463
|
-
pluginName: options.pluginName,
|
|
1464
|
-
scope: options.scope,
|
|
1465
|
-
hooksPath: resolveCodexPaths(options.cwd, options.scope, options.env).hooksPath,
|
|
1466
|
-
identity,
|
|
1467
|
-
}));
|
|
1468
|
-
}
|
|
1469
|
-
continue;
|
|
1470
|
-
}
|
|
1471
|
-
if (artifact.kind === 'mcpServer' && options.platform === 'codex' && artifact.artifactKey) {
|
|
1472
|
-
components.push(createCodexMcpComponent({
|
|
1473
|
-
identity: historicalIdentity(internalArtifactKey('mcp', artifact.artifactKey)),
|
|
1474
|
-
scope: options.scope,
|
|
1475
|
-
configPath: resolveCodexPaths(options.cwd, options.scope, options.env).configTomlPath,
|
|
1476
|
-
serverKey: artifact.artifactKey,
|
|
1477
|
-
owned: false,
|
|
1478
|
-
}));
|
|
1479
|
-
continue;
|
|
1480
|
-
}
|
|
1481
|
-
if (artifact.kind === 'instruction' && options.platform === 'codex' && !artifact.artifactKey) {
|
|
1482
|
-
components.push(createCodexInstructionComponent({
|
|
1483
|
-
identity: historicalIdentity('developer-instructions'),
|
|
1484
|
-
scope: options.scope,
|
|
1485
|
-
configPath: resolveCodexPaths(options.cwd, options.scope, options.env).configTomlPath,
|
|
1486
|
-
}));
|
|
1487
|
-
continue;
|
|
1488
|
-
}
|
|
1489
|
-
if (artifact.kind === 'permission' && options.platform === 'claude') {
|
|
1490
|
-
components.push(createClaudePermissionsComponent({
|
|
1491
|
-
identity: historicalIdentity('permissions'),
|
|
1492
|
-
scope: options.scope,
|
|
1493
|
-
settingsPath: resolveClaudePaths(options.cwd, options.scope, options.env).settingsPath,
|
|
1494
|
-
}));
|
|
1495
|
-
continue;
|
|
1496
|
-
}
|
|
1497
|
-
if (artifact.target === 'codex.agentRole'
|
|
1498
|
-
&& options.platform === 'codex'
|
|
1499
|
-
&& (artifact.roleKey || artifact.artifactKey)) {
|
|
1500
|
-
const roleKey = artifact.roleKey ?? artifact.artifactKey;
|
|
1501
|
-
components.push(createCodexRoleRegistrationComponent({
|
|
1502
|
-
identity: historicalIdentity(internalArtifactKey('role', roleKey)),
|
|
1503
|
-
fileIdentity: historicalIdentity(roleKey),
|
|
1504
|
-
configPath: resolveCodexPaths(options.cwd, options.scope, options.env).configTomlPath,
|
|
1505
|
-
roleKey,
|
|
1506
|
-
rolePath: artifact.path,
|
|
1507
|
-
}));
|
|
1508
|
-
}
|
|
1509
|
-
if (!artifact.artifactKey)
|
|
1510
|
-
continue;
|
|
1511
|
-
const identity = ownerIdentity(options.pluginName, artifact.artifactKey, options.platform, options.scope);
|
|
1512
|
-
components.push(pathComponent({
|
|
1513
|
-
kind: artifact.kind === 'skill' ? 'skill-directory' : 'owned-text-file',
|
|
1514
|
-
path: artifact.path,
|
|
1515
|
-
allowedRoot: artifact.kind === 'skill' ? path.dirname(artifact.path) : paths.configDir,
|
|
1516
|
-
identity,
|
|
1517
|
-
}));
|
|
1518
|
-
}
|
|
1519
|
-
return components;
|
|
1520
454
|
}
|
|
1521
|
-
function
|
|
1522
|
-
const
|
|
1523
|
-
return
|
|
455
|
+
function legacyCodexMcpOwner(actual) {
|
|
456
|
+
const envValue = actual?.value?.env;
|
|
457
|
+
return envValue
|
|
458
|
+
&& typeof envValue === 'object'
|
|
459
|
+
&& !Array.isArray(envValue)
|
|
460
|
+
&& typeof envValue[LEGACY_MCP_OWNER_ENV] === 'string'
|
|
461
|
+
? envValue[LEGACY_MCP_OWNER_ENV]
|
|
462
|
+
: null;
|
|
1524
463
|
}
|
|
1525
|
-
async function
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
throw error;
|
|
1530
|
-
});
|
|
464
|
+
async function readLegacyCodexHooks(hooksPath) {
|
|
465
|
+
if (!await fs.pathExists(hooksPath))
|
|
466
|
+
return parseCodexSharedHooksFile({ hooks: {} });
|
|
467
|
+
return parseCodexSharedHooksFile(await fs.readJson(hooksPath));
|
|
1531
468
|
}
|
|
1532
|
-
|
|
1533
|
-
const
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
throw new Error(`Codex residue root is not a canonical directory: ${directory}`);
|
|
469
|
+
function renderLegacyCodexHookGroups(groups) {
|
|
470
|
+
const hooks = {};
|
|
471
|
+
for (const group of groups) {
|
|
472
|
+
hooks[group.event] ??= [];
|
|
473
|
+
hooks[group.event].push(group.rawGroup);
|
|
1538
474
|
}
|
|
1539
|
-
return
|
|
475
|
+
return `${JSON.stringify({ hooks }, null, 2)}\n`;
|
|
1540
476
|
}
|
|
1541
|
-
async function
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
}
|
|
1563
|
-
const inspectManifest = async (manifestPath, kind, directoryVersion) => {
|
|
1564
|
-
const stats = await lstatCodexResidueIfPresent(manifestPath);
|
|
1565
|
-
if (!stats)
|
|
1566
|
-
return;
|
|
1567
|
-
if (!stats.isFile() || stats.isSymbolicLink()) {
|
|
1568
|
-
foreignLabels.push(manifestPath);
|
|
1569
|
-
return;
|
|
1570
|
-
}
|
|
1571
|
-
const manifest = await fs.readJson(manifestPath);
|
|
1572
|
-
const identity = manifest?.id ?? manifest?.name;
|
|
1573
|
-
const version = typeof manifest?.version === 'string' ? manifest.version : null;
|
|
1574
|
-
if (!canonicalMarketplace
|
|
1575
|
-
|| (identity !== options.pluginName && identity !== pluginId)
|
|
1576
|
-
|| !version
|
|
1577
|
-
|| (directoryVersion !== undefined && version !== directoryVersion)) {
|
|
1578
|
-
foreignLabels.push(manifestPath);
|
|
1579
|
-
return;
|
|
1580
|
-
}
|
|
1581
|
-
labels.push(manifestPath);
|
|
1582
|
-
versions.add(version);
|
|
1583
|
-
(kind === 'installed' ? installedVersions : cacheVersions).add(version);
|
|
1584
|
-
};
|
|
1585
|
-
for (const entry of await readdirCodexResidueIfPresent(cacheRoot)) {
|
|
1586
|
-
if (!entry.isDirectory() || entry.isSymbolicLink()) {
|
|
1587
|
-
foreignLabels.push(path.join(cacheRoot, entry.name));
|
|
1588
|
-
continue;
|
|
1589
|
-
}
|
|
1590
|
-
const versionRoot = path.join(cacheRoot, entry.name);
|
|
1591
|
-
const candidates = [
|
|
1592
|
-
path.join(versionRoot, 'plugin.json'),
|
|
1593
|
-
path.join(versionRoot, '.codex-plugin', 'plugin.json'),
|
|
1594
|
-
];
|
|
1595
|
-
const existing = [];
|
|
1596
|
-
for (const candidate of candidates) {
|
|
1597
|
-
if (await lstatCodexResidueIfPresent(candidate))
|
|
1598
|
-
existing.push(candidate);
|
|
1599
|
-
}
|
|
1600
|
-
if (existing.length === 0)
|
|
1601
|
-
foreignLabels.push(versionRoot);
|
|
1602
|
-
for (const candidate of existing)
|
|
1603
|
-
await inspectManifest(candidate, 'cache', entry.name);
|
|
1604
|
-
}
|
|
1605
|
-
const installedStats = await lstatCodexResidueIfPresent(installedRoot);
|
|
1606
|
-
if (installedStats && (!installedStats.isDirectory() || installedStats.isSymbolicLink())) {
|
|
1607
|
-
foreignLabels.push(installedRoot);
|
|
1608
|
-
}
|
|
1609
|
-
else if (installedStats) {
|
|
1610
|
-
await inspectManifest(installedManifest, 'installed');
|
|
1611
|
-
}
|
|
1612
|
-
return foreignLabels.length > 0
|
|
1613
|
-
? {
|
|
1614
|
-
state: 'foreign', labels: [...labels, ...foreignLabels], versions: [...versions],
|
|
1615
|
-
installedVersions: [...installedVersions], cacheVersions: [...cacheVersions],
|
|
1616
|
-
enabled: configEntry?.enabled === true,
|
|
1617
|
-
}
|
|
1618
|
-
: labels.length > 0
|
|
1619
|
-
? {
|
|
1620
|
-
state: 'present', labels, versions: [...versions],
|
|
1621
|
-
installedVersions: [...installedVersions], cacheVersions: [...cacheVersions],
|
|
1622
|
-
enabled: configEntry?.enabled === true,
|
|
477
|
+
async function applyLegacyCodexHookCleanupTransactionFile(hooksPath, update) {
|
|
478
|
+
return withConfigFileMutation({
|
|
479
|
+
filePath: hooksPath,
|
|
480
|
+
allowedRoot: path.dirname(hooksPath),
|
|
481
|
+
action: async () => {
|
|
482
|
+
const parsed = await readLegacyCodexHooks(hooksPath);
|
|
483
|
+
const groups = update(parsed);
|
|
484
|
+
if (!groups)
|
|
485
|
+
return false;
|
|
486
|
+
if (groups.length === 0) {
|
|
487
|
+
await atomicRemoveConfigFile({
|
|
488
|
+
filePath: hooksPath,
|
|
489
|
+
allowedRoot: path.dirname(hooksPath),
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
else {
|
|
493
|
+
await atomicReplaceConfigFile({
|
|
494
|
+
filePath: hooksPath,
|
|
495
|
+
allowedRoot: path.dirname(hooksPath),
|
|
496
|
+
content: renderLegacyCodexHookGroups(groups),
|
|
497
|
+
});
|
|
1623
498
|
}
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
};
|
|
499
|
+
return true;
|
|
500
|
+
},
|
|
501
|
+
});
|
|
1628
502
|
}
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
if (residue.state === 'present')
|
|
1632
|
-
return true;
|
|
1633
|
-
if (residue.state === 'foreign')
|
|
503
|
+
async function codexRoleRegistrationOwned(options) {
|
|
504
|
+
if (!options.registration?.configFile)
|
|
1634
505
|
return false;
|
|
1635
|
-
const
|
|
1636
|
-
const
|
|
1637
|
-
|
|
1638
|
-
const marketplace = config.snapshot.marketplaces[marketplaceName];
|
|
1639
|
-
const canonical = marketplace?.sourceType === 'local'
|
|
1640
|
-
&& !marketplace.sourcePointsToManifest
|
|
1641
|
-
&& path.normalize(marketplace.source ?? '') === path.normalize(marketplaceRoot);
|
|
1642
|
-
if (!canonical)
|
|
506
|
+
const expected = path.normalize(path.relative(path.dirname(options.configPath), options.rolePath));
|
|
507
|
+
const actual = path.normalize(path.relative(path.dirname(options.configPath), path.resolve(path.dirname(options.configPath), options.registration.configFile)));
|
|
508
|
+
if (actual !== expected)
|
|
1643
509
|
return false;
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
const marketplaceName = options.marketplaceName ?? MARKETPLACE_NAME;
|
|
1648
|
-
const marketplaceRoot = options.marketplaceRoot ?? resolveAwHome(options.env);
|
|
1649
|
-
const names = new Set();
|
|
1650
|
-
const config = await readCodexConfigFile(resolveCodexPaths(options.cwd, 'user', options.env).configTomlPath);
|
|
1651
|
-
const marketplace = config.snapshot.marketplaces[marketplaceName];
|
|
1652
|
-
const canonicalMarketplace = marketplace?.sourceType === 'local'
|
|
1653
|
-
&& !marketplace.sourcePointsToManifest
|
|
1654
|
-
&& path.normalize(marketplace.source ?? '') === path.normalize(marketplaceRoot);
|
|
1655
|
-
const probeFailure = (location, cause, pluginName) => {
|
|
1656
|
-
if (cause instanceof CodexNativeResidueProbeError)
|
|
1657
|
-
throw cause;
|
|
1658
|
-
throw new CodexNativeResidueProbeError(location, cause, pluginName);
|
|
1659
|
-
};
|
|
1660
|
-
for (const pluginId of canonicalMarketplace ? Object.keys(config.snapshot.plugins) : []) {
|
|
1661
|
-
const suffix = `@${marketplaceName}`;
|
|
1662
|
-
const match = pluginId.endsWith(suffix)
|
|
1663
|
-
? /^([a-z0-9]+(?:-[a-z0-9]+)*)$/u.exec(pluginId.slice(0, -suffix.length))
|
|
1664
|
-
: null;
|
|
1665
|
-
if (match)
|
|
1666
|
-
names.add(match[1]);
|
|
510
|
+
const raw = await fs.readFile(options.rolePath, 'utf8').catch(() => '');
|
|
511
|
+
try {
|
|
512
|
+
return Boolean(parseOwnedTextHeader(raw, options.fileIdentity));
|
|
1667
513
|
}
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
for (const entry of cacheEntries) {
|
|
1671
|
-
if (entry.isFile())
|
|
1672
|
-
continue;
|
|
1673
|
-
const entryPath = path.join(cacheRoot, entry.name);
|
|
1674
|
-
const pluginName = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u.test(entry.name)
|
|
1675
|
-
? entry.name
|
|
1676
|
-
: probeFailure(entryPath, new Error('Codex cache residue has an invalid plugin identity.'));
|
|
1677
|
-
if (!entry.isDirectory() || entry.isSymbolicLink()) {
|
|
1678
|
-
probeFailure(entryPath, new Error('Codex cache residue is not a canonical plugin directory.'), pluginName);
|
|
1679
|
-
}
|
|
1680
|
-
let versionEntries;
|
|
1681
|
-
try {
|
|
1682
|
-
versionEntries = await fs.readdir(entryPath, { withFileTypes: true });
|
|
1683
|
-
}
|
|
1684
|
-
catch (error) {
|
|
1685
|
-
throw new CodexNativeResidueProbeError(entryPath, error, pluginName);
|
|
1686
|
-
}
|
|
1687
|
-
if (versionEntries.length === 0) {
|
|
1688
|
-
if (names.has(pluginName)) {
|
|
1689
|
-
probeFailure(entryPath, new Error('Codex cache residue manifest is missing.'), pluginName);
|
|
1690
|
-
}
|
|
1691
|
-
continue;
|
|
1692
|
-
}
|
|
1693
|
-
let residue;
|
|
1694
|
-
try {
|
|
1695
|
-
residue = await inspectCodexNativeResidue({ ...options, pluginName: entry.name });
|
|
1696
|
-
}
|
|
1697
|
-
catch (error) {
|
|
1698
|
-
throw new CodexNativeResidueProbeError(entryPath, error, pluginName);
|
|
1699
|
-
}
|
|
1700
|
-
if (residue.state !== 'present') {
|
|
1701
|
-
probeFailure(entryPath, new Error('Codex cache residue has foreign or incomplete manifest evidence.'), pluginName);
|
|
1702
|
-
}
|
|
1703
|
-
names.add(pluginName);
|
|
514
|
+
catch {
|
|
515
|
+
return false;
|
|
1704
516
|
}
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
517
|
+
}
|
|
518
|
+
export async function removeForceCleanupCodexRoleRegistration(options) {
|
|
519
|
+
const component = options.component;
|
|
520
|
+
if (component.kind !== 'owned-text-file' || component.identity.platform !== 'codex')
|
|
521
|
+
return;
|
|
522
|
+
const paths = resolveCodexPaths(options.cwd, component.identity.scope, options.env);
|
|
523
|
+
const roleKey = component.identity.artifactKey;
|
|
524
|
+
const expectedPath = path.join(paths.agentsDir, `${buildGeneratedName(component.identity.plugin, roleKey)}.toml`);
|
|
525
|
+
if (path.resolve(component.path) !== path.resolve(expectedPath))
|
|
526
|
+
return;
|
|
527
|
+
await applyConditionalCodexConfigTransactionFile(paths.configTomlPath, async (snapshot) => {
|
|
528
|
+
const registration = snapshot.agents[roleKey];
|
|
529
|
+
if (!registration?.configFile
|
|
530
|
+
|| path.resolve(path.dirname(paths.configTomlPath), registration.configFile)
|
|
531
|
+
!== path.resolve(component.path))
|
|
532
|
+
return null;
|
|
533
|
+
// Force authorizes the existing exclusive file. The matching registration is
|
|
534
|
+
// removed before that evidence disappears; missing or foreign files grant no authority.
|
|
535
|
+
const inspected = await inspectOwnedComponents({ components: [component], forceExclusive: true });
|
|
536
|
+
return inspected.components[0]?.state === 'present'
|
|
537
|
+
? { removeAgentRegistrations: [roleKey] }
|
|
1711
538
|
: null;
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
probeFailure(installedRoot, new Error('Codex installed residue is not a canonical plugin directory.'), match[1]);
|
|
1721
|
-
}
|
|
1722
|
-
const manifestPath = path.join(pluginsRoot, entry.name, 'manifest.json');
|
|
1723
|
-
const stats = await lstatCodexResidueIfPresent(manifestPath);
|
|
1724
|
-
if (!stats?.isFile() || stats.isSymbolicLink()) {
|
|
1725
|
-
probeFailure(manifestPath, new Error('Codex installed residue manifest is missing or nonregular.'), match[1]);
|
|
1726
|
-
}
|
|
1727
|
-
let rawManifest;
|
|
1728
|
-
try {
|
|
1729
|
-
rawManifest = await fs.readJson(manifestPath);
|
|
1730
|
-
}
|
|
1731
|
-
catch (error) {
|
|
1732
|
-
throw new CodexNativeResidueProbeError(manifestPath, error, match[1]);
|
|
1733
|
-
}
|
|
1734
|
-
if (!rawManifest || typeof rawManifest !== 'object' || Array.isArray(rawManifest)) {
|
|
1735
|
-
probeFailure(manifestPath, new Error('Codex installed residue manifest must be an object.'), match[1]);
|
|
1736
|
-
}
|
|
1737
|
-
const manifest = rawManifest;
|
|
1738
|
-
const identity = manifest.id ?? manifest.name;
|
|
1739
|
-
if (!canonicalMarketplace
|
|
1740
|
-
|| (identity !== match[1] && identity !== entry.name)
|
|
1741
|
-
|| typeof manifest.version !== 'string'
|
|
1742
|
-
|| manifest.version.trim() === '') {
|
|
1743
|
-
probeFailure(manifestPath, new Error('Codex installed residue manifest has foreign identity or version.'), match[1]);
|
|
1744
|
-
}
|
|
1745
|
-
names.add(match[1]);
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
function sharedOwnerPluginName(value) {
|
|
542
|
+
return parseSharedOwnerToken(value)?.plugin ?? value;
|
|
543
|
+
}
|
|
544
|
+
function observedCodexNativeState(observation, operation) {
|
|
545
|
+
if (observation.state === 'observed') {
|
|
546
|
+
return observation.value === 'installed' ? 'present' : 'absent';
|
|
1746
547
|
}
|
|
1747
|
-
|
|
548
|
+
if (observation.state === 'unobserved')
|
|
549
|
+
return 'partial';
|
|
550
|
+
throw new Error(`codexNativeObservationFailed: ${operation} requires Codex plugin list evidence.`);
|
|
1748
551
|
}
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
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({
|
|
578
|
+
pluginId: options.pluginId,
|
|
579
|
+
scope: options.scope ?? 'both',
|
|
1756
580
|
});
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
581
|
+
return {
|
|
582
|
+
observation: inspected.observation,
|
|
583
|
+
observations: inspected.observations,
|
|
584
|
+
activations: inspected.activations,
|
|
585
|
+
};
|
|
1760
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);
|
|
1761
595
|
}
|
|
1762
|
-
async function
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
}
|
|
1768
|
-
|
|
1769
|
-
|
|
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,
|
|
608
|
+
});
|
|
609
|
+
if (!root)
|
|
610
|
+
return;
|
|
611
|
+
const pluginRoot = await assertSafeNamespacedMarketplacePluginRoot(options.rootDir, options.pluginName);
|
|
612
|
+
const pluginStats = await fs.lstat(pluginRoot).catch((error) => {
|
|
1770
613
|
if (error.code === 'ENOENT')
|
|
1771
|
-
return
|
|
614
|
+
return null;
|
|
1772
615
|
throw error;
|
|
1773
616
|
});
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
delete updated.skills;
|
|
1783
|
-
await fs.outputJson(manifestPath, updated, { spaces: 2 });
|
|
1784
|
-
return options.hasRequiredSkills ? relativeSkillsRoot : null;
|
|
1785
|
-
}
|
|
1786
|
-
function createCodexMarketplaceComponent(options) {
|
|
1787
|
-
const configPath = resolveCodexPaths(options.cwd, 'user', options.env).configTomlPath;
|
|
1788
|
-
const inspectCanonicalMarketplace = async () => {
|
|
1789
|
-
const config = await readCodexConfigFile(configPath);
|
|
1790
|
-
const marketplace = config.snapshot.marketplaces[options.marketplaceName];
|
|
1791
|
-
if (!marketplace)
|
|
1792
|
-
return 'absent';
|
|
1793
|
-
if (marketplace.sourceType !== 'local'
|
|
1794
|
-
|| marketplace.sourcePointsToManifest
|
|
1795
|
-
|| path.normalize(marketplace.source ?? '') !== path.normalize(options.marketplaceRoot))
|
|
1796
|
-
return 'foreign';
|
|
1797
|
-
return 'present';
|
|
1798
|
-
};
|
|
1799
|
-
const hasRemainingPlugins = async () => {
|
|
1800
|
-
return (await discoverCodexNativeResidueNames({
|
|
1801
|
-
cwd: options.cwd,
|
|
1802
|
-
env: options.env,
|
|
1803
|
-
marketplaceName: options.marketplaceName,
|
|
1804
|
-
marketplaceRoot: options.marketplaceRoot,
|
|
1805
|
-
})).some((name) => name !== options.pluginName);
|
|
1806
|
-
};
|
|
1807
|
-
const inspect = async () => {
|
|
1808
|
-
const canonical = await inspectCanonicalMarketplace();
|
|
1809
|
-
const plugin = await inspectCodexNativeResidue({
|
|
1810
|
-
pluginName: options.pluginName,
|
|
1811
|
-
cwd: options.cwd,
|
|
1812
|
-
env: options.env,
|
|
1813
|
-
marketplaceName: options.marketplaceName,
|
|
1814
|
-
marketplaceRoot: options.marketplaceRoot,
|
|
1815
|
-
});
|
|
1816
|
-
if (plugin.state === 'foreign')
|
|
1817
|
-
return 'foreign';
|
|
1818
|
-
if (options.desired) {
|
|
1819
|
-
return canonical === 'present' && plugin.state === 'present' && plugin.enabled
|
|
1820
|
-
? 'present'
|
|
1821
|
-
: 'absent';
|
|
1822
|
-
}
|
|
1823
|
-
if (canonical !== 'present')
|
|
1824
|
-
return canonical;
|
|
1825
|
-
return await hasRemainingPlugins() ? 'absent' : 'present';
|
|
1826
|
-
};
|
|
1827
|
-
return {
|
|
1828
|
-
kind: 'shared-config',
|
|
1829
|
-
identity: ownerIdentity(options.pluginName, `marketplace-${options.marketplaceName}`, 'codex', 'user'),
|
|
1830
|
-
label: `${configPath}#marketplaces.${options.marketplaceName}`,
|
|
1831
|
-
inspect,
|
|
1832
|
-
remove: async () => {
|
|
1833
|
-
const currentResidue = await inspectCodexNativeResidue({
|
|
1834
|
-
pluginName: options.pluginName,
|
|
1835
|
-
cwd: options.cwd,
|
|
1836
|
-
env: options.env,
|
|
1837
|
-
marketplaceName: options.marketplaceName,
|
|
1838
|
-
marketplaceRoot: options.marketplaceRoot,
|
|
1839
|
-
});
|
|
1840
|
-
if (currentResidue.state === 'foreign') {
|
|
1841
|
-
throw new Error(`Codex native owner 为 foreign,拒绝移除 marketplace:${currentResidue.labels.join(',')}`);
|
|
1842
|
-
}
|
|
1843
|
-
if (await inspectCanonicalMarketplace() !== 'present'
|
|
1844
|
-
|| currentResidue.state === 'present'
|
|
1845
|
-
|| await hasRemainingPlugins())
|
|
1846
|
-
return;
|
|
1847
|
-
try {
|
|
1848
|
-
await runNativeCliChecked(buildCodexMarketplaceRemoveInvocation(requireCodexManager(options.codexManager), options.marketplaceName, options.cwd, options.env), options.runner);
|
|
1849
|
-
await runNativeCliChecked(buildCodexMarketplaceListInvocation(requireCodexManager(options.codexManager), options.cwd, options.env), options.runner);
|
|
1850
|
-
}
|
|
1851
|
-
catch {
|
|
1852
|
-
throw new Error(`codexNativeRemoveFailed: ${CODEX_REMOVE_RECOVERY}`);
|
|
1853
|
-
}
|
|
1854
|
-
},
|
|
1855
|
-
};
|
|
1856
|
-
}
|
|
1857
|
-
async function assertCodexNativeInstallState(options) {
|
|
1858
|
-
const marketplaceName = options.marketplaceName ?? MARKETPLACE_NAME;
|
|
1859
|
-
const pluginId = `${options.pluginName}@${marketplaceName}`;
|
|
1860
|
-
const configPath = resolveCodexPaths(options.cwd, 'user', options.env).configTomlPath;
|
|
1861
|
-
const config = await readCodexConfigFile(configPath);
|
|
1862
|
-
const marketplace = config.snapshot.marketplaces[marketplaceName];
|
|
1863
|
-
if (marketplace?.sourceType !== 'local'
|
|
1864
|
-
|| marketplace.sourcePointsToManifest
|
|
1865
|
-
|| path.normalize(marketplace.source ?? '') !== path.normalize(options.marketplaceRoot)) {
|
|
1866
|
-
throw new Error(`Codex marketplace aw 未指向当前 AW_HOME:${options.marketplaceRoot}`);
|
|
1867
|
-
}
|
|
1868
|
-
if (config.snapshot.plugins[pluginId]?.enabled !== true) {
|
|
1869
|
-
throw new Error(`Codex enabled config 缺少 ${pluginId}。`);
|
|
1870
|
-
}
|
|
1871
|
-
const cacheRoot = path.join(getCodexHome(options.env), 'plugins', 'cache', marketplaceName, options.pluginName, options.pluginVersion);
|
|
1872
|
-
const candidates = [
|
|
1873
|
-
path.join(cacheRoot, 'plugin.json'),
|
|
1874
|
-
path.join(cacheRoot, '.codex-plugin', 'plugin.json'),
|
|
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
|
+
: []),
|
|
1875
625
|
];
|
|
1876
|
-
const
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
else if (entry.isFile())
|
|
1891
|
-
output.push(relativePath);
|
|
1892
|
-
else
|
|
1893
|
-
throw new Error(`Codex native payload 包含不支持的节点:${path.join(root, relativePath)}`);
|
|
1894
|
-
}
|
|
1895
|
-
}
|
|
1896
|
-
return output;
|
|
1897
|
-
};
|
|
1898
|
-
const manifestPaths = new Set(['plugin.json', path.join('.codex-plugin', 'plugin.json')]);
|
|
1899
|
-
const allowedMetadata = new Set(['metadata.json', '.metadata.json']);
|
|
1900
|
-
const [expectedFiles, actualFiles] = await Promise.all([
|
|
1901
|
-
collectFiles(expectedRoot),
|
|
1902
|
-
collectFiles(cacheRoot),
|
|
1903
|
-
]);
|
|
1904
|
-
const expectedSet = new Set(expectedFiles);
|
|
1905
|
-
for (const relativePath of expectedFiles) {
|
|
1906
|
-
if (manifestPaths.has(relativePath))
|
|
1907
|
-
continue;
|
|
1908
|
-
const expectedPath = path.join(expectedRoot, relativePath);
|
|
1909
|
-
const actualPath = path.join(cacheRoot, relativePath);
|
|
1910
|
-
const actualStats = await fs.lstat(actualPath).catch(() => null);
|
|
1911
|
-
if (!actualStats?.isFile() || actualStats.isSymbolicLink()) {
|
|
1912
|
-
throw new Error(`Codex native cache 缺少 expected payload:${actualPath}`);
|
|
1913
|
-
}
|
|
1914
|
-
const [expectedContent, actualContent] = await Promise.all([
|
|
1915
|
-
fs.readFile(expectedPath),
|
|
1916
|
-
fs.readFile(actualPath),
|
|
1917
|
-
]);
|
|
1918
|
-
if (!expectedContent.equals(actualContent)) {
|
|
1919
|
-
throw new Error(`Codex native cache expected payload digest 不匹配:${actualPath}`);
|
|
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;
|
|
636
|
+
throw error;
|
|
637
|
+
});
|
|
638
|
+
if (manifest && manifest.name !== options.pluginName) {
|
|
639
|
+
throw new Error('marketplaceProjectionIdentityMismatch: plugin projection has a foreign name.');
|
|
1920
640
|
}
|
|
641
|
+
hasIdentityManifest ||= manifest?.name === options.pluginName;
|
|
1921
642
|
}
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|| manifestPaths.has(relativePath)
|
|
1925
|
-
|| allowedMetadata.has(relativePath))
|
|
1926
|
-
continue;
|
|
1927
|
-
throw new Error(`Codex native cache 包含 unexpected loadable payload:${path.join(cacheRoot, relativePath)}`);
|
|
1928
|
-
}
|
|
1929
|
-
};
|
|
1930
|
-
let matchedManifest = false;
|
|
1931
|
-
for (const candidate of candidates) {
|
|
1932
|
-
if (!await fs.pathExists(candidate))
|
|
1933
|
-
continue;
|
|
1934
|
-
const manifest = await fs.readJson(candidate).catch(() => null);
|
|
1935
|
-
if (!manifest) {
|
|
1936
|
-
throw new Error(`Codex native cache manifest 无法解析:${candidate}`);
|
|
643
|
+
if (!hasEntry && !hasIdentityManifest) {
|
|
644
|
+
throw new Error('marketplaceProjectionIdentityUnavailable: plugin directory has no matching marketplace entry or plugin manifest.');
|
|
1937
645
|
}
|
|
1938
|
-
const identity = manifest.id ?? manifest.name;
|
|
1939
|
-
const matches = ((identity === options.pluginName || identity === pluginId)
|
|
1940
|
-
&& manifest.version === options.pluginVersion
|
|
1941
|
-
&& (options.skillsRelativeRoot === null
|
|
1942
|
-
? typeof manifest.skills !== 'string'
|
|
1943
|
-
: typeof manifest.skills === 'string'
|
|
1944
|
-
&& path.posix.normalize(manifest.skills.replace(/^\.\//u, '')) === options.skillsRelativeRoot));
|
|
1945
|
-
if (!matches) {
|
|
1946
|
-
throw new Error(`Codex native cache manifest 不匹配:${candidate}`);
|
|
1947
|
-
}
|
|
1948
|
-
matchedManifest = true;
|
|
1949
|
-
}
|
|
1950
|
-
if (!matchedManifest) {
|
|
1951
|
-
throw new Error(`Codex native cache 缺少匹配 ${pluginId}@${options.pluginVersion} 的 manifest:${cacheRoot}`);
|
|
1952
646
|
}
|
|
1953
|
-
|
|
1954
|
-
const
|
|
1955
|
-
|
|
1956
|
-
|
|
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.');
|
|
652
|
+
}
|
|
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
|
+
});
|
|
1957
673
|
}
|
|
1958
674
|
}
|
|
1959
|
-
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* Read-only shared-native inspection. Official Codex list evidence owns installation
|
|
678
|
+
* state. Filesystem validation is limited to the AW-owned marketplace source.
|
|
679
|
+
*/
|
|
680
|
+
export async function inspectCodexSharedNativeLive(options) {
|
|
681
|
+
const marketplaceName = options.marketplaceName ?? MARKETPLACE_NAME;
|
|
682
|
+
const marketplaceRoot = options.marketplaceRoot ?? path.join(resolveAwHome(options.env), 'marketplaces', options.sourceId);
|
|
683
|
+
const marketplacePathSafe = await isSafeCodexMarketplaceRoot({
|
|
684
|
+
awHome: resolveAwHome(options.env),
|
|
685
|
+
sourceId: options.sourceId,
|
|
686
|
+
marketplaceRoot,
|
|
687
|
+
});
|
|
688
|
+
const pluginId = `${options.pluginName}@${marketplaceName}`;
|
|
689
|
+
const config = await readCodexConfigFile(resolveCodexPaths(options.cwd, 'user', options.env).configTomlPath);
|
|
690
|
+
const pluginList = options.pluginRegistration ?? await inspectCodexPluginRegistrationLive({
|
|
691
|
+
pluginId,
|
|
692
|
+
cwd: options.cwd,
|
|
693
|
+
env: options.env,
|
|
694
|
+
nativeCliRunner: options.nativeCliRunner,
|
|
695
|
+
manager: options.manager,
|
|
696
|
+
scope: options.observationScope,
|
|
697
|
+
observationSession: options.observationSession,
|
|
698
|
+
});
|
|
699
|
+
const expectedPayloadDigest = options.expectedPayloadDigest;
|
|
700
|
+
const sharedNative = inspectCodexSharedNative({
|
|
701
|
+
pluginName: options.pluginName,
|
|
702
|
+
pluginId,
|
|
703
|
+
marketplaceName,
|
|
704
|
+
canonicalMarketplaceRoot: marketplaceRoot,
|
|
705
|
+
desiredVersion: options.desiredVersion,
|
|
706
|
+
expectedPayloadDigest,
|
|
707
|
+
marketplaceRegistration: config.snapshot.marketplaces[marketplaceName],
|
|
708
|
+
marketplacePathSafe,
|
|
709
|
+
observation: pluginList.observation,
|
|
710
|
+
});
|
|
711
|
+
return {
|
|
712
|
+
sharedNative,
|
|
713
|
+
...(expectedPayloadDigest ? { expectedPayloadDigest } : {}),
|
|
714
|
+
};
|
|
1960
715
|
}
|
|
1961
716
|
async function readJsonObjectIfExists(filePath, label) {
|
|
1962
717
|
let value;
|
|
@@ -2238,9 +993,7 @@ export async function inspectNativeMarketplaceRegistrations(options) {
|
|
|
2238
993
|
const codexMarketplace = codexConfig.snapshot.marketplaces[options.marketplaceName];
|
|
2239
994
|
const codexRegistration = codexMarketplace === undefined
|
|
2240
995
|
? 'absent'
|
|
2241
|
-
: codexMarketplace.
|
|
2242
|
-
&& !codexMarketplace.sourcePointsToManifest
|
|
2243
|
-
&& path.normalize(codexMarketplace.source ?? '') === path.normalize(options.marketplaceRoot)
|
|
996
|
+
: isCanonicalCodexMarketplaceRegistration(codexMarketplace, options.marketplaceRoot)
|
|
2244
997
|
? 'canonical'
|
|
2245
998
|
: 'foreign';
|
|
2246
999
|
const codexConsumerSuffix = `@${options.marketplaceName}`;
|
|
@@ -2256,18 +1009,209 @@ export async function inspectNativeMarketplaceRegistrations(options) {
|
|
|
2256
1009
|
marketplaceName: options.marketplaceName,
|
|
2257
1010
|
marketplaceRoot: options.marketplaceRoot,
|
|
2258
1011
|
});
|
|
2259
|
-
const claude = claudeState.marketplaceState === 'absent'
|
|
2260
|
-
&& claudeState.marketplaceConsumerEvidence
|
|
2261
|
-
? 'foreign'
|
|
2262
|
-
: claudeState.marketplaceState;
|
|
2263
|
-
return { codex, claude };
|
|
2264
|
-
}
|
|
2265
|
-
function
|
|
2266
|
-
|
|
2267
|
-
|
|
1012
|
+
const claude = claudeState.marketplaceState === 'absent'
|
|
1013
|
+
&& claudeState.marketplaceConsumerEvidence
|
|
1014
|
+
? 'foreign'
|
|
1015
|
+
: claudeState.marketplaceState;
|
|
1016
|
+
return { codex, claude };
|
|
1017
|
+
}
|
|
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.');
|
|
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);
|
|
1026
|
+
}
|
|
1027
|
+
function createNativeDriver(options) {
|
|
1028
|
+
const runner = options.context.nativeCliRunner;
|
|
1029
|
+
const revokeAtRoot = async (root, recursive = false, platform) => {
|
|
1030
|
+
const listed = await listManagedCommands(options.context.env);
|
|
1031
|
+
const producers = new Map();
|
|
1032
|
+
for (const command of listed.commands) {
|
|
1033
|
+
if (command.owner.kind !== 'plugin' || !command.resourceRoot)
|
|
1034
|
+
continue;
|
|
1035
|
+
if (platform && command.owner.producer.platform !== platform)
|
|
1036
|
+
continue;
|
|
1037
|
+
const relative = path.relative(path.resolve(root), path.resolve(command.resourceRoot));
|
|
1038
|
+
if (relative !== '' && (!recursive || relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)))
|
|
1039
|
+
continue;
|
|
1040
|
+
producers.set(getCommandPackageId(command.owner.producer), command.owner.producer);
|
|
1041
|
+
}
|
|
1042
|
+
for (const producer of producers.values()) {
|
|
1043
|
+
const removedCommandIds = await revokeManagedCommandBindings(producer, options.context.env);
|
|
1044
|
+
options.context.commandResults ??= [];
|
|
1045
|
+
options.context.commandResults.push({ producer, state: 'completed', commandIds: [], removedCommandIds, errors: [], recoveryActions: [] });
|
|
1046
|
+
}
|
|
1047
|
+
};
|
|
1048
|
+
const publishPackages = async (target) => {
|
|
1049
|
+
const cache = options.context.managedCommandProducerCache ??= new Map();
|
|
1050
|
+
for (const action of target.operationActions ?? []) {
|
|
1051
|
+
if (action.kind !== 'syncManagedCommandPackage')
|
|
1052
|
+
continue;
|
|
1053
|
+
const key = getCommandPackageId(action.producer);
|
|
1054
|
+
let publication = cache.get(key);
|
|
1055
|
+
if (!publication) {
|
|
1056
|
+
publication = (async () => {
|
|
1057
|
+
await options.context.reporter.event({ type: 'managed-command:producer', source: { plugin: action.producer.pluginName, scope: action.producer.scope }, data: { packageKey: action.producer.key, phase: 'start' } });
|
|
1058
|
+
const temporary = await fs.mkdtemp(path.join(os.tmpdir(), 'aw-command-publish-'));
|
|
1059
|
+
try {
|
|
1060
|
+
const digest = `sha256:${crypto.createHash('sha256').update(JSON.stringify(action.files)).digest('hex')}`;
|
|
1061
|
+
if (digest !== action.contentDigest)
|
|
1062
|
+
throw new ManagedCommandError('commandResourceInvalid', 'The prepared command package digest changed.');
|
|
1063
|
+
const resourceRoot = path.join(temporary, 'resource');
|
|
1064
|
+
await fs.ensureDir(resourceRoot);
|
|
1065
|
+
for (const file of action.files) {
|
|
1066
|
+
const content = Buffer.from(file.contentBase64, 'base64');
|
|
1067
|
+
if (`sha256:${crypto.createHash('sha256').update(content).digest('hex')}` !== file.contentDigest)
|
|
1068
|
+
throw new ManagedCommandError('commandResourceInvalid', 'The prepared command package file digest changed.');
|
|
1069
|
+
const destination = path.join(resourceRoot, ...file.relativePath.split('/'));
|
|
1070
|
+
await fs.outputFile(destination, content);
|
|
1071
|
+
await fs.chmod(destination, file.mode);
|
|
1072
|
+
}
|
|
1073
|
+
const result = await syncManagedCommandPackage({ producer: action.producer, sourceDirectory: resourceRoot, sets: action.sets, nativeTools: action.nativeTools, env: options.context.env });
|
|
1074
|
+
await options.context.reporter.event({ type: 'managed-command:producer', source: { plugin: action.producer.pluginName, scope: action.producer.scope }, data: { packageKey: action.producer.key, phase: 'success' } });
|
|
1075
|
+
return { producer: action.producer, state: 'completed', commandIds: result.commandIds, removedCommandIds: result.removedCommandIds, errors: [], recoveryActions: [] };
|
|
1076
|
+
}
|
|
1077
|
+
catch (error) {
|
|
1078
|
+
await options.context.reporter.event({ type: 'managed-command:producer', source: { plugin: action.producer.pluginName, scope: action.producer.scope }, data: { packageKey: action.producer.key, phase: 'failure' } });
|
|
1079
|
+
return { producer: action.producer, state: 'failed', commandIds: [], removedCommandIds: [], errors: [managedCommandDiagnostic(error)], recoveryActions: [`aw command package sync ${action.producer.sourceId}/${action.producer.pluginName} ${action.producer.key} --scope ${action.producer.scope} --yes`] };
|
|
1080
|
+
}
|
|
1081
|
+
finally {
|
|
1082
|
+
await fs.remove(temporary);
|
|
1083
|
+
}
|
|
1084
|
+
})();
|
|
1085
|
+
cache.set(key, publication);
|
|
1086
|
+
}
|
|
1087
|
+
const result = await publication;
|
|
1088
|
+
options.context.commandResults ??= [];
|
|
1089
|
+
if (!options.context.commandResults.some((entry) => getCommandPackageId(entry.producer) === key))
|
|
1090
|
+
options.context.commandResults.push(result);
|
|
1091
|
+
if (result.state !== 'completed')
|
|
1092
|
+
throw new Error('commandPackagePublishFailed: sync the command package and retry the plugin operation.');
|
|
1093
|
+
}
|
|
1094
|
+
};
|
|
1095
|
+
const currentCodexManager = () => options.context.codexManager;
|
|
1096
|
+
const codexNativeStates = new Map();
|
|
1097
|
+
const pendingCodexNativeStates = new Map();
|
|
1098
|
+
const codexMutationMarketplaces = new Set();
|
|
1099
|
+
let nativeMarketplaceEligibleTargets;
|
|
1100
|
+
let deferredPostchecks = [];
|
|
1101
|
+
const nativeGroupKey = (target) => [
|
|
1102
|
+
target.identity.sourceId ?? '',
|
|
1103
|
+
target.identity.sourceIdentity ?? '',
|
|
1104
|
+
target.identity.marketplaceName ?? MARKETPLACE_NAME,
|
|
1105
|
+
path.normalize(path.resolve(target.identity.marketplaceRoot ?? resolveAwHome(options.context.env))),
|
|
1106
|
+
].join('\0');
|
|
1107
|
+
const observationScopeFor = (target) => codexObservationScope(options.context, target.identity.marketplaceName ?? MARKETPLACE_NAME, target.identity.scope);
|
|
1108
|
+
const groupTargets = (target) => {
|
|
1109
|
+
if (!options.operationScopedNativePhases)
|
|
1110
|
+
return [target];
|
|
1111
|
+
const key = nativeGroupKey(target);
|
|
1112
|
+
return options.targets.filter((candidate) => nativeGroupKey(candidate) === key
|
|
1113
|
+
&& (nativeMarketplaceEligibleTargets?.has(candidate) ?? true));
|
|
1114
|
+
};
|
|
1115
|
+
const findTarget = (component) => {
|
|
1116
|
+
const target = options.targets.find((entry) => entry.identity.pluginName === component.identity.plugin
|
|
1117
|
+
&& entry.identity.sourceId === component.identity.sourceId
|
|
1118
|
+
&& entry.identity.platform === component.identity.platform
|
|
1119
|
+
&& entry.identity.scope === component.identity.scope);
|
|
1120
|
+
if (!target)
|
|
1121
|
+
throw new Error('Ownership executor cannot resolve its desired target.');
|
|
1122
|
+
return target;
|
|
1123
|
+
};
|
|
1124
|
+
const codexStateKey = (target, pluginId) => `${nativeGroupKey(target)}\0${pluginId}`;
|
|
1125
|
+
const runObservedCodexMutation = async (options_) => runCodexMutationWithInvalidation({
|
|
1126
|
+
...options_,
|
|
1127
|
+
...(options.operationScopedNativePhases
|
|
1128
|
+
? {}
|
|
1129
|
+
: { observationSession: options.context.codexObservationSession }),
|
|
1130
|
+
});
|
|
1131
|
+
const prepareNativeGroup = async (target) => {
|
|
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');
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
};
|
|
1146
|
+
const inspectCodexMarketplace = async (component) => {
|
|
1147
|
+
if (component.locator.kind !== 'codex-marketplace')
|
|
1148
|
+
throw new Error('Invalid Codex marketplace locator.');
|
|
1149
|
+
const target = findTarget(component);
|
|
1150
|
+
const configPath = resolveCodexPaths(target.identity.cwd, 'user', options.context.env).configTomlPath;
|
|
1151
|
+
const config = await readCodexConfigFile(configPath);
|
|
1152
|
+
const marketplace = config.snapshot.marketplaces[component.locator.marketplaceName];
|
|
1153
|
+
const canonical = !marketplace
|
|
1154
|
+
? 'absent'
|
|
1155
|
+
: isCanonicalCodexMarketplaceRegistration(marketplace, component.locator.marketplaceRoot)
|
|
1156
|
+
? 'present'
|
|
1157
|
+
: 'foreign';
|
|
1158
|
+
if (component.locator.desired) {
|
|
1159
|
+
if (canonical !== 'present')
|
|
1160
|
+
return canonical;
|
|
1161
|
+
const pluginId = `${component.identity.plugin}@${component.locator.marketplaceName}`;
|
|
1162
|
+
return config.snapshot.plugins[pluginId]?.enabled === true ? 'present' : 'absent';
|
|
1163
|
+
}
|
|
1164
|
+
if (canonical !== 'present')
|
|
1165
|
+
return canonical;
|
|
1166
|
+
const suffix = `@${component.locator.marketplaceName}`;
|
|
1167
|
+
const currentPluginId = `${component.identity.plugin}${suffix}`;
|
|
1168
|
+
const projectConfig = await readCodexConfigFile(resolveCodexPaths(target.identity.cwd, 'project', options.context.env).configTomlPath);
|
|
1169
|
+
const configuredPluginIds = [
|
|
1170
|
+
...Object.keys(config.snapshot.plugins),
|
|
1171
|
+
...Object.keys(projectConfig.snapshot.plugins),
|
|
1172
|
+
].filter((pluginId) => pluginId.endsWith(suffix));
|
|
1173
|
+
if (configuredPluginIds.some((pluginId) => pluginId !== currentPluginId))
|
|
1174
|
+
return 'absent';
|
|
1175
|
+
const ownedSession = options.context.codexObservationSession ? undefined
|
|
1176
|
+
: await createCodexNativeObservationSession({
|
|
1177
|
+
exactCwd: target.identity.cwd,
|
|
1178
|
+
env: options.context.env,
|
|
1179
|
+
runner,
|
|
1180
|
+
manager: currentCodexManager() ?? SYSTEM_CODEX_MANAGER,
|
|
1181
|
+
});
|
|
1182
|
+
const session = options.context.codexObservationSession ?? ownedSession;
|
|
1183
|
+
try {
|
|
1184
|
+
const observationScope = observationScopeFor(target);
|
|
1185
|
+
const snapshot = await session.snapshot(component.locator.marketplaceName, observationScope);
|
|
1186
|
+
if (!snapshot.neutral || (observationScope === 'both' && !snapshot.exact))
|
|
1187
|
+
return 'absent';
|
|
1188
|
+
const officialPluginIds = new Set([
|
|
1189
|
+
...(snapshot.exact?.keys() ?? []),
|
|
1190
|
+
...snapshot.neutral.keys(),
|
|
1191
|
+
]);
|
|
1192
|
+
return [...officialPluginIds].some((pluginId) => pluginId !== currentPluginId)
|
|
1193
|
+
? 'absent'
|
|
1194
|
+
: 'present';
|
|
1195
|
+
}
|
|
1196
|
+
finally {
|
|
1197
|
+
await ownedSession?.dispose();
|
|
1198
|
+
}
|
|
1199
|
+
};
|
|
1200
|
+
const inspectClaudeMarketplace = async (component) => {
|
|
1201
|
+
if (component.locator.kind !== 'claude-marketplace')
|
|
1202
|
+
throw new Error('Invalid Claude marketplace locator.');
|
|
1203
|
+
const target = findTarget(component);
|
|
1204
|
+
const state = await readClaudeNativeState({
|
|
1205
|
+
pluginName: component.identity.plugin,
|
|
1206
|
+
scope: component.identity.scope,
|
|
1207
|
+
cwd: target.identity.cwd,
|
|
1208
|
+
env: options.context.env,
|
|
1209
|
+
marketplaceName: component.locator.marketplaceName,
|
|
1210
|
+
marketplaceRoot: component.locator.marketplaceRoot,
|
|
1211
|
+
});
|
|
2268
1212
|
if (state.pluginState === 'foreign')
|
|
2269
1213
|
return 'foreign';
|
|
2270
|
-
if (
|
|
1214
|
+
if (component.locator.desired) {
|
|
2271
1215
|
return state.marketplaceDeclaredState === 'canonical'
|
|
2272
1216
|
&& state.marketplaceMaterializedState === 'canonical'
|
|
2273
1217
|
&& state.pluginState === 'present'
|
|
@@ -2277,198 +1221,284 @@ function createClaudeMarketplaceComponent(options) {
|
|
|
2277
1221
|
}
|
|
2278
1222
|
if (state.marketplaceState !== 'canonical')
|
|
2279
1223
|
return state.marketplaceState;
|
|
2280
|
-
const projectPath =
|
|
2281
|
-
? path.normalize(await resolveRepoRoot(
|
|
1224
|
+
const projectPath = component.identity.scope === 'project'
|
|
1225
|
+
? path.normalize(await resolveRepoRoot(target.identity.cwd))
|
|
2282
1226
|
: undefined;
|
|
2283
|
-
return state.marketplaceConsumers.some((consumer) => !(consumer.name ===
|
|
2284
|
-
&& consumer.scope ===
|
|
2285
|
-
&& (
|
|
2286
|
-
|
|
2287
|
-
: 'present';
|
|
1227
|
+
return state.marketplaceConsumers.some((consumer) => !(consumer.name === component.identity.plugin
|
|
1228
|
+
&& consumer.scope === component.identity.scope
|
|
1229
|
+
&& (component.identity.scope === 'user'
|
|
1230
|
+
|| path.normalize(consumer.projectPath ?? '') === projectPath))) ? 'absent' : 'present';
|
|
2288
1231
|
};
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
1232
|
+
const ownership = {
|
|
1233
|
+
inspectShared: async (component) => {
|
|
1234
|
+
const locator = component.locator;
|
|
1235
|
+
switch (locator.kind) {
|
|
1236
|
+
case 'cursor-workspace-hook':
|
|
1237
|
+
return platformOwnership.inspectShared(component);
|
|
1238
|
+
case 'claude-permissions':
|
|
1239
|
+
return (await readClaudeSettings(locator.settingsPath)).awGenerated
|
|
1240
|
+
?.permissions?.[locator.ownerKey] ? 'present' : 'absent';
|
|
1241
|
+
case 'codex-instruction':
|
|
1242
|
+
return (await readCodexConfigFile(locator.configPath)).snapshot
|
|
1243
|
+
.developerInstructions.managedBlocks[locator.ownerKey] ? 'present' : 'absent';
|
|
1244
|
+
case 'codex-activation': {
|
|
1245
|
+
const actual = (await readCodexConfigFile(locator.configPath))
|
|
1246
|
+
.snapshot.plugins[locator.codexPluginId]?.enabled;
|
|
1247
|
+
if (locator.disposition === 'remove')
|
|
1248
|
+
return actual === undefined ? 'absent' : 'present';
|
|
1249
|
+
if (locator.disposition === 'disable')
|
|
1250
|
+
return actual === true ? 'present' : 'absent';
|
|
1251
|
+
return actual === locator.desired ? 'present' : 'absent';
|
|
1252
|
+
}
|
|
1253
|
+
case 'legacy-codex-mcp': {
|
|
1254
|
+
const actual = (await readCodexConfigFile(locator.configPath))
|
|
1255
|
+
.snapshot.mcpServers[locator.serverKey];
|
|
1256
|
+
if (!actual)
|
|
1257
|
+
return 'absent';
|
|
1258
|
+
return legacyCodexMcpOwner(actual) === locator.ownerKey ? 'present' : 'foreign';
|
|
1259
|
+
}
|
|
1260
|
+
case 'legacy-codex-hook':
|
|
1261
|
+
return (await readLegacyCodexHooks(locator.hooksPath)).managedIdentities.some((entry) => serializeTrackedHookGroupIdentity(entry) === locator.serializedIdentity)
|
|
1262
|
+
? 'present'
|
|
1263
|
+
: 'absent';
|
|
1264
|
+
case 'codex-role-registration': {
|
|
1265
|
+
const registration = (await readCodexConfigFile(locator.configPath))
|
|
1266
|
+
.snapshot.agents[locator.roleKey];
|
|
1267
|
+
if (!registration)
|
|
1268
|
+
return 'absent';
|
|
1269
|
+
return await codexRoleRegistrationOwned({
|
|
1270
|
+
fileIdentity: locator.fileIdentity,
|
|
1271
|
+
configPath: locator.configPath,
|
|
1272
|
+
roleKey: locator.roleKey,
|
|
1273
|
+
rolePath: locator.rolePath,
|
|
1274
|
+
registration,
|
|
1275
|
+
}) ? 'present' : 'foreign';
|
|
1276
|
+
}
|
|
1277
|
+
case 'codex-marketplace':
|
|
1278
|
+
return inspectCodexMarketplace(component);
|
|
1279
|
+
case 'claude-marketplace':
|
|
1280
|
+
return inspectClaudeMarketplace(component);
|
|
1281
|
+
case 'corrupted':
|
|
1282
|
+
throw new Error(locator.message);
|
|
2311
1283
|
}
|
|
2312
1284
|
},
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
const awHome = path.resolve(resolveAwHome(env));
|
|
2323
|
-
const awHomeStats = await fs.lstat(awHome).catch((error) => {
|
|
2324
|
-
if (error.code === 'ENOENT')
|
|
2325
|
-
return null;
|
|
2326
|
-
throw error;
|
|
2327
|
-
});
|
|
2328
|
-
if (!awHomeStats?.isDirectory() || awHomeStats.isSymbolicLink()) {
|
|
2329
|
-
throw new Error(`marketplaceRootInvalid: AW_HOME must be a regular directory: ${awHome}`);
|
|
2330
|
-
}
|
|
2331
|
-
const canonicalAwHome = await fs.realpath(awHome);
|
|
2332
|
-
const expectedParent = path.join(canonicalAwHome, 'marketplaces');
|
|
2333
|
-
const destination = target.marketplaceRoot;
|
|
2334
|
-
const parent = path.dirname(destination);
|
|
2335
|
-
if (path.resolve(parent) !== path.join(awHome, 'marketplaces')) {
|
|
2336
|
-
throw new Error(`marketplaceRootInvalid: marketplace parent is not under canonical AW_HOME: ${parent}`);
|
|
2337
|
-
}
|
|
2338
|
-
let parentStats = await fs.lstat(parent).catch((error) => {
|
|
2339
|
-
if (error.code === 'ENOENT')
|
|
2340
|
-
return null;
|
|
2341
|
-
throw error;
|
|
2342
|
-
});
|
|
2343
|
-
if (!parentStats) {
|
|
2344
|
-
await fs.mkdir(parent);
|
|
2345
|
-
parentStats = await fs.lstat(parent);
|
|
2346
|
-
}
|
|
2347
|
-
if (!parentStats.isDirectory() || parentStats.isSymbolicLink()) {
|
|
2348
|
-
throw new Error(`marketplaceRootInvalid: marketplace parent must be a regular directory: ${parent}`);
|
|
2349
|
-
}
|
|
2350
|
-
const canonicalParent = await fs.realpath(parent);
|
|
2351
|
-
if (canonicalParent !== expectedParent) {
|
|
2352
|
-
throw new Error(`marketplaceRootInvalid: marketplace parent is outside canonical AW_HOME: ${parent}`);
|
|
2353
|
-
}
|
|
2354
|
-
const staging = await fs.mkdtemp(path.join(parent, `.${target.sourceId}-staging-`));
|
|
2355
|
-
try {
|
|
2356
|
-
for (const entry of ['.agents', '.claude-plugin', 'plugins']) {
|
|
2357
|
-
await fs.copy(path.join(catalog.rootDir, entry), path.join(staging, entry));
|
|
2358
|
-
}
|
|
2359
|
-
const marketplaceName = target.marketplaceName ?? getNamespacedMarketplaceName(target.sourceId);
|
|
2360
|
-
for (const [platform, manifestPath] of [
|
|
2361
|
-
['codex', path.join(staging, '.agents', 'plugins', 'marketplace.json')],
|
|
2362
|
-
['claude', path.join(staging, '.claude-plugin', 'marketplace.json')],
|
|
2363
|
-
]) {
|
|
2364
|
-
const manifest = await fs.readJson(manifestPath);
|
|
2365
|
-
await fs.writeJson(manifestPath, {
|
|
2366
|
-
...projectMarketplaceManifestForPlatform(manifest, platform),
|
|
2367
|
-
name: marketplaceName,
|
|
2368
|
-
}, { spaces: 2 });
|
|
2369
|
-
}
|
|
2370
|
-
await fs.writeJson(path.join(staging, 'config.json'), {
|
|
2371
|
-
schemaVersion: 2,
|
|
2372
|
-
sourceId: target.sourceId,
|
|
2373
|
-
sourceIdentity: target.sourceIdentity,
|
|
2374
|
-
marketplaceName,
|
|
2375
|
-
}, { spaces: 2 });
|
|
2376
|
-
const destinationExists = await fs.lstat(destination).then(() => true, (error) => {
|
|
2377
|
-
if (error.code === 'ENOENT' || error.code === 'ENOTDIR')
|
|
2378
|
-
return false;
|
|
2379
|
-
throw error;
|
|
2380
|
-
});
|
|
2381
|
-
if (destinationExists) {
|
|
2382
|
-
await replayNamespacedCodexSkillOverlays({
|
|
2383
|
-
sourceRoot: destination,
|
|
2384
|
-
stagingRoot: staging,
|
|
2385
|
-
sourceId: target.sourceId,
|
|
2386
|
-
sourceIdentity: target.sourceIdentity,
|
|
2387
|
-
marketplaceName,
|
|
2388
|
-
});
|
|
2389
|
-
}
|
|
2390
|
-
const backup = `${destination}.backup-${crypto.randomUUID()}`;
|
|
2391
|
-
if (destinationExists)
|
|
2392
|
-
await fs.move(destination, backup);
|
|
2393
|
-
try {
|
|
2394
|
-
await fs.move(staging, destination);
|
|
2395
|
-
}
|
|
2396
|
-
catch (error) {
|
|
2397
|
-
const backupStats = await fs.lstat(backup).catch((inspectionError) => {
|
|
2398
|
-
if (inspectionError.code === 'ENOENT')
|
|
2399
|
-
return null;
|
|
2400
|
-
throw inspectionError;
|
|
2401
|
-
});
|
|
2402
|
-
const destinationStats = await fs.lstat(destination).catch((inspectionError) => {
|
|
2403
|
-
if (inspectionError.code === 'ENOENT')
|
|
2404
|
-
return null;
|
|
2405
|
-
throw inspectionError;
|
|
2406
|
-
});
|
|
2407
|
-
if (backupStats && !destinationStats) {
|
|
2408
|
-
await fs.move(backup, destination);
|
|
2409
|
-
}
|
|
2410
|
-
throw error;
|
|
2411
|
-
}
|
|
2412
|
-
let state = 'active';
|
|
2413
|
-
return {
|
|
2414
|
-
rootDir: destination,
|
|
2415
|
-
commit: async () => {
|
|
2416
|
-
if (state !== 'active')
|
|
1285
|
+
removeShared: async (component) => {
|
|
1286
|
+
const locator = component.locator;
|
|
1287
|
+
switch (locator.kind) {
|
|
1288
|
+
case 'cursor-workspace-hook':
|
|
1289
|
+
return platformOwnership.removeShared(component);
|
|
1290
|
+
case 'claude-permissions': {
|
|
1291
|
+
const settings = await readClaudeSettings(locator.settingsPath);
|
|
1292
|
+
rebuildClaudePermissions(settings, locator.ownerKey);
|
|
1293
|
+
await writeClaudeSettings(locator.settingsPath, settings);
|
|
2417
1294
|
return;
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
sourceIdentity: target.sourceIdentity,
|
|
2423
|
-
...(target.marketplaceName ? { marketplaceName: target.marketplaceName } : {}),
|
|
2424
|
-
env,
|
|
1295
|
+
}
|
|
1296
|
+
case 'codex-instruction':
|
|
1297
|
+
await applyCodexConfigTransactionFile(locator.configPath, {
|
|
1298
|
+
removeManagedInstructionPluginName: locator.ownerKey,
|
|
2425
1299
|
});
|
|
2426
|
-
|
|
1300
|
+
return;
|
|
1301
|
+
case 'codex-activation':
|
|
1302
|
+
await applyConditionalCodexConfigTransactionFile(locator.configPath, (snapshot) => {
|
|
1303
|
+
const actual = snapshot.plugins[locator.codexPluginId]?.enabled;
|
|
1304
|
+
if (locator.disposition === 'remove') {
|
|
1305
|
+
return actual === undefined ? null : { removePluginActivations: [locator.codexPluginId] };
|
|
1306
|
+
}
|
|
1307
|
+
if (locator.disposition === 'disable') {
|
|
1308
|
+
return actual === true
|
|
1309
|
+
? { upsertPluginActivations: { [locator.codexPluginId]: false } }
|
|
1310
|
+
: null;
|
|
1311
|
+
}
|
|
1312
|
+
return { removePluginActivations: [locator.codexPluginId] };
|
|
1313
|
+
});
|
|
1314
|
+
return;
|
|
1315
|
+
case 'legacy-codex-mcp':
|
|
1316
|
+
await applyConditionalCodexConfigTransactionFile(locator.configPath, (snapshot) => legacyCodexMcpOwner(snapshot.mcpServers[locator.serverKey]) === locator.ownerKey
|
|
1317
|
+
? { removeMcpServers: [locator.serverKey] }
|
|
1318
|
+
: null);
|
|
1319
|
+
return;
|
|
1320
|
+
case 'legacy-codex-hook':
|
|
1321
|
+
await applyLegacyCodexHookCleanupTransactionFile(locator.hooksPath, (parsed) => {
|
|
1322
|
+
let removed = false;
|
|
1323
|
+
const remaining = parsed.groups.flatMap((entry) => {
|
|
1324
|
+
if (!removed && entry.managedIdentity
|
|
1325
|
+
&& serializeTrackedHookGroupIdentity(entry.managedIdentity) === locator.serializedIdentity) {
|
|
1326
|
+
removed = true;
|
|
1327
|
+
return [];
|
|
1328
|
+
}
|
|
1329
|
+
return [entry.rawGroup];
|
|
1330
|
+
});
|
|
1331
|
+
return removed ? remaining : null;
|
|
1332
|
+
});
|
|
1333
|
+
return;
|
|
1334
|
+
case 'codex-role-registration':
|
|
1335
|
+
await applyConditionalCodexConfigTransactionFile(locator.configPath, async (snapshot) => await codexRoleRegistrationOwned({
|
|
1336
|
+
fileIdentity: locator.fileIdentity,
|
|
1337
|
+
configPath: locator.configPath,
|
|
1338
|
+
roleKey: locator.roleKey,
|
|
1339
|
+
rolePath: locator.rolePath,
|
|
1340
|
+
registration: snapshot.agents[locator.roleKey],
|
|
1341
|
+
}) ? { removeAgentRegistrations: [locator.roleKey] } : null);
|
|
1342
|
+
return;
|
|
1343
|
+
case 'codex-marketplace': {
|
|
1344
|
+
if (locator.desired)
|
|
1345
|
+
return;
|
|
1346
|
+
const target = findTarget(component);
|
|
1347
|
+
await prepareNativeGroup(target);
|
|
1348
|
+
const pluginId = `${target.identity.pluginName}@${locator.marketplaceName}`;
|
|
1349
|
+
const stateKey = codexStateKey(target, pluginId);
|
|
1350
|
+
if (codexNativeStates.get(stateKey) === 'present'
|
|
1351
|
+
&& pendingCodexNativeStates.get(stateKey) !== 'absent')
|
|
1352
|
+
return;
|
|
1353
|
+
codexMutationMarketplaces.add(locator.marketplaceName);
|
|
1354
|
+
await runObservedCodexMutation({
|
|
1355
|
+
marketplaceName: locator.marketplaceName,
|
|
1356
|
+
mutation: () => runNativeCliChecked(buildCodexMarketplaceRemoveInvocation(currentCodexManager() ?? SYSTEM_CODEX_MANAGER, locator.marketplaceName, target.identity.cwd, options.context.env), runner),
|
|
1357
|
+
});
|
|
1358
|
+
return;
|
|
2427
1359
|
}
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
1360
|
+
case 'claude-marketplace': {
|
|
1361
|
+
return;
|
|
1362
|
+
}
|
|
1363
|
+
case 'corrupted':
|
|
1364
|
+
throw new Error(locator.message);
|
|
1365
|
+
}
|
|
1366
|
+
},
|
|
1367
|
+
validateSkillDirectory: async (component) => {
|
|
1368
|
+
await validateSkillDirectory(component.path, component.identity.platform === 'codex' ? 'codex.skill' : 'claude.skill', { ownerMarkerPolicy: 'ignore', requirementsReceiptPolicy: 'allow' });
|
|
1369
|
+
},
|
|
1370
|
+
skillDirectoryMatchesPristineTree: async ({ actualPath, files }) => {
|
|
1371
|
+
const expectedFiles = new Map(files.map((entry) => [entry.relativePath, entry]));
|
|
1372
|
+
const expectedDirectories = new Set(['']);
|
|
1373
|
+
for (const relativePath of expectedFiles.keys()) {
|
|
1374
|
+
const segments = relativePath.split('/');
|
|
1375
|
+
for (let index = 1; index < segments.length; index += 1) {
|
|
1376
|
+
expectedDirectories.add(segments.slice(0, index).join('/'));
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
const seen = new Set();
|
|
1380
|
+
const pending = [{ absolutePath: actualPath, relativePath: '' }];
|
|
1381
|
+
while (pending.length > 0) {
|
|
1382
|
+
const current = pending.pop();
|
|
1383
|
+
for (const entry of await fs.readdir(current.absolutePath, { withFileTypes: true })) {
|
|
1384
|
+
const relativePath = current.relativePath ? `${current.relativePath}/${entry.name}` : entry.name;
|
|
1385
|
+
if (entry.isSymbolicLink())
|
|
1386
|
+
return false;
|
|
1387
|
+
const absolutePath = path.join(current.absolutePath, entry.name);
|
|
1388
|
+
if (entry.isDirectory()) {
|
|
1389
|
+
if (!expectedDirectories.has(relativePath))
|
|
1390
|
+
return false;
|
|
1391
|
+
pending.push({ absolutePath, relativePath });
|
|
1392
|
+
continue;
|
|
2431
1393
|
}
|
|
2432
|
-
|
|
1394
|
+
if (!entry.isFile())
|
|
1395
|
+
return false;
|
|
1396
|
+
const digest = `sha256:${crypto.createHash('sha256').update(await fs.readFile(absolutePath)).digest('hex')}`;
|
|
1397
|
+
const expected = expectedFiles.get(relativePath);
|
|
1398
|
+
if (expected?.contentDigest !== digest)
|
|
1399
|
+
return false;
|
|
1400
|
+
if (catalogFileMode(relativePath, (await fs.stat(absolutePath)).mode)
|
|
1401
|
+
!== catalogFileMode(relativePath, expected.mode ?? 0o644))
|
|
1402
|
+
return false;
|
|
1403
|
+
seen.add(relativePath);
|
|
2433
1404
|
}
|
|
2434
|
-
}
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
return;
|
|
2438
|
-
const backupStats = await fs.lstat(backup).catch((error) => {
|
|
2439
|
-
if (error.code === 'ENOENT')
|
|
2440
|
-
return null;
|
|
2441
|
-
throw error;
|
|
2442
|
-
});
|
|
2443
|
-
await fs.remove(destination);
|
|
2444
|
-
if (backupStats)
|
|
2445
|
-
await fs.move(backup, destination);
|
|
2446
|
-
state = 'rolledBack';
|
|
2447
|
-
},
|
|
2448
|
-
};
|
|
2449
|
-
}
|
|
2450
|
-
catch (error) {
|
|
2451
|
-
await fs.remove(staging);
|
|
2452
|
-
throw error;
|
|
2453
|
-
}
|
|
2454
|
-
}
|
|
2455
|
-
function createNativeDriver(options) {
|
|
2456
|
-
const runner = options.context.nativeCliRunner;
|
|
2457
|
-
const codexManager = options.context.codexManager;
|
|
2458
|
-
const mirrorTransactions = new WeakMap();
|
|
2459
|
-
const finalizeNamespacedCleanup = async (target) => {
|
|
2460
|
-
const { sourceId, sourceIdentity, marketplaceRoot, marketplaceName } = target.identity;
|
|
2461
|
-
if (!sourceId || !sourceIdentity || !marketplaceRoot)
|
|
2462
|
-
return;
|
|
2463
|
-
await cleanupOrphanNamespacedMarketplaceRoot({
|
|
2464
|
-
sourceId,
|
|
2465
|
-
sourceIdentity,
|
|
2466
|
-
...(marketplaceName ? { marketplaceName } : {}),
|
|
2467
|
-
cwd: target.identity.cwd,
|
|
2468
|
-
env: options.context.env,
|
|
2469
|
-
});
|
|
1405
|
+
}
|
|
1406
|
+
return seen.size === expectedFiles.size;
|
|
1407
|
+
},
|
|
2470
1408
|
};
|
|
2471
1409
|
return {
|
|
1410
|
+
ownership,
|
|
1411
|
+
beforeCleanupMutation: async (component) => {
|
|
1412
|
+
if (component.kind === 'skill-directory')
|
|
1413
|
+
await revokeAtRoot(component.path);
|
|
1414
|
+
},
|
|
1415
|
+
setNativeMarketplaceEligibleTargets: (eligibleTargets) => {
|
|
1416
|
+
nativeMarketplaceEligibleTargets = new Set(eligibleTargets);
|
|
1417
|
+
},
|
|
1418
|
+
prepareNativeMarketplaceGroup: prepareNativeGroup,
|
|
1419
|
+
...(options.operationScopedNativePhases ? {
|
|
1420
|
+
deferPostcheck: (target, postcheck) => {
|
|
1421
|
+
if (target.identity.platform !== 'codex')
|
|
1422
|
+
return false;
|
|
1423
|
+
deferredPostchecks.push({
|
|
1424
|
+
target,
|
|
1425
|
+
postcheck: async () => {
|
|
1426
|
+
if (target.requiresNative) {
|
|
1427
|
+
const marketplaceName = target.identity.marketplaceName ?? MARKETPLACE_NAME;
|
|
1428
|
+
const pluginId = `${target.identity.pluginName}@${marketplaceName}`;
|
|
1429
|
+
const registration = await inspectCodexPluginRegistrationLive({
|
|
1430
|
+
pluginId,
|
|
1431
|
+
cwd: target.identity.cwd,
|
|
1432
|
+
env: options.context.env,
|
|
1433
|
+
nativeCliRunner: runner,
|
|
1434
|
+
manager: currentCodexManager(),
|
|
1435
|
+
scope: observationScopeFor(target),
|
|
1436
|
+
observationSession: options.context.codexObservationSession,
|
|
1437
|
+
});
|
|
1438
|
+
const state = requireObservedCodexNativeState(registration.observation, 'native install postcheck');
|
|
1439
|
+
requireCodexObservationCoverage(registration, observationScopeFor(target), 'native install postcheck');
|
|
1440
|
+
if (state !== 'installed') {
|
|
1441
|
+
throw new Error(`codexNativeInstallIncomplete: ${pluginId} is absent from Codex plugin list.`);
|
|
1442
|
+
}
|
|
1443
|
+
const installedEntry = registration.observation.state === 'observed'
|
|
1444
|
+
&& registration.observation.value === 'installed'
|
|
1445
|
+
? registration.observation.entry
|
|
1446
|
+
: undefined;
|
|
1447
|
+
if (installedEntry?.version !== undefined
|
|
1448
|
+
&& installedEntry.version !== target.identity.pluginVersion) {
|
|
1449
|
+
throw new Error(`codexNativeInstallIncomplete: ${pluginId} version is ${installedEntry.version}; expected ${target.identity.pluginVersion}.`);
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
await postcheck();
|
|
1453
|
+
},
|
|
1454
|
+
});
|
|
1455
|
+
return true;
|
|
1456
|
+
},
|
|
1457
|
+
completePostchecks: async () => {
|
|
1458
|
+
const pending = deferredPostchecks;
|
|
1459
|
+
deferredPostchecks = [];
|
|
1460
|
+
const failures = [];
|
|
1461
|
+
for (const entry of pending) {
|
|
1462
|
+
try {
|
|
1463
|
+
await entry.postcheck();
|
|
1464
|
+
}
|
|
1465
|
+
catch (error) {
|
|
1466
|
+
failures.push({ target: entry.target, error });
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
return failures;
|
|
1470
|
+
},
|
|
1471
|
+
} : {}),
|
|
1472
|
+
captureCodexPostMutationSnapshots: async (marketplaceNames = []) => {
|
|
1473
|
+
for (const marketplaceName of marketplaceNames) {
|
|
1474
|
+
codexMutationMarketplaces.add(marketplaceName);
|
|
1475
|
+
}
|
|
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)
|
|
1480
|
+
return;
|
|
1481
|
+
const session = options.context.codexObservationSession;
|
|
1482
|
+
if (!session) {
|
|
1483
|
+
throw new Error('codexNativeObservationUnavailable: grouped postcheck requires an observation session.');
|
|
1484
|
+
}
|
|
1485
|
+
codexMutationMarketplaces.clear();
|
|
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)
|
|
1489
|
+
session.invalidate(marketplaceName);
|
|
1490
|
+
await Promise.all(marketplaces.map((marketplaceName) => session.snapshot(marketplaceName, options.context.codexObservationScopeByMarketplace?.get(marketplaceName)
|
|
1491
|
+
?? (options.targets.some((target) => (nativeMarketplaceEligibleTargets?.has(target) ?? true)
|
|
1492
|
+
&& target.identity.platform === 'codex'
|
|
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'))
|
|
1495
|
+
? 'both'
|
|
1496
|
+
: 'user'))));
|
|
1497
|
+
},
|
|
1498
|
+
preflightMutation: async (target) => {
|
|
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 });
|
|
1501
|
+
},
|
|
2472
1502
|
preflightMaterialize: async (target) => {
|
|
2473
1503
|
if (target.identity.sourceId && options.context.expectedCatalogConfigDigest) {
|
|
2474
1504
|
const current = await readCatalogSourcesConfigSnapshot(options.context.env);
|
|
@@ -2476,47 +1506,22 @@ function createNativeDriver(options) {
|
|
|
2476
1506
|
throw new Error('catalogSourceConflict: catalog source config changed before owner publication.');
|
|
2477
1507
|
}
|
|
2478
1508
|
}
|
|
2479
|
-
if (target.identity.platform === 'claude')
|
|
1509
|
+
if (target.identity.platform === 'claude')
|
|
2480
1510
|
await assertNoClaudeUnboundNativeNameCollision({
|
|
2481
|
-
pluginName: target.identity.pluginName,
|
|
2482
|
-
cwd: target.identity.cwd,
|
|
2483
|
-
env: options.context.env,
|
|
1511
|
+
pluginName: target.identity.pluginName, cwd: target.identity.cwd, env: options.context.env
|
|
2484
1512
|
});
|
|
2485
|
-
return;
|
|
2486
|
-
}
|
|
2487
|
-
const marketplaceName = target.identity.marketplaceName ?? MARKETPLACE_NAME;
|
|
2488
|
-
const marketplaceRoot = target.identity.marketplaceRoot ?? resolveAwHome(options.context.env);
|
|
2489
|
-
const config = await readCodexConfigFile(resolveCodexPaths(target.identity.cwd, 'user', options.context.env).configTomlPath);
|
|
2490
|
-
const marketplace = config.snapshot.marketplaces[marketplaceName];
|
|
2491
|
-
const canonical = marketplace?.sourceType === 'local'
|
|
2492
|
-
&& !marketplace.sourcePointsToManifest
|
|
2493
|
-
&& path.resolve(marketplace.source ?? '') === path.resolve(marketplaceRoot);
|
|
2494
|
-
const expectedPluginId = `${target.identity.pluginName}@${marketplaceName}`;
|
|
2495
|
-
if ((marketplace !== undefined && !canonical)
|
|
2496
|
-
|| (Object.hasOwn(config.snapshot.plugins, expectedPluginId) && !canonical)) {
|
|
2497
|
-
throw new Error(`externalOwnershipPresent: Codex marketplace ${marketplaceName} has a foreign source instead of its canonical namespaced root.`);
|
|
2498
|
-
}
|
|
2499
|
-
},
|
|
2500
|
-
commitMaterialize: async (target) => {
|
|
2501
|
-
const transaction = mirrorTransactions.get(target);
|
|
2502
|
-
if (!transaction)
|
|
2503
|
-
return;
|
|
2504
|
-
await transaction.commit();
|
|
2505
|
-
mirrorTransactions.delete(target);
|
|
2506
1513
|
},
|
|
2507
|
-
|
|
2508
|
-
const
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
1514
|
+
finalizeCleanup: async (target) => {
|
|
1515
|
+
for (const action of target.operationActions ?? []) {
|
|
1516
|
+
if (action.kind !== 'retainManagedCommandPackage')
|
|
1517
|
+
continue;
|
|
1518
|
+
options.context.commandResults ??= [];
|
|
1519
|
+
if (!options.context.commandResults.some((result) => getCommandPackageId(result.producer) === action.packageId))
|
|
1520
|
+
options.context.commandResults.push(retainedManagedCommandPackageResult(action));
|
|
1521
|
+
}
|
|
2513
1522
|
},
|
|
2514
|
-
finalizeCleanup: finalizeNamespacedCleanup,
|
|
2515
1523
|
probeNative: async (component) => {
|
|
2516
|
-
const target =
|
|
2517
|
-
&& entry.target.identity.sourceId === component.identity.sourceId
|
|
2518
|
-
&& entry.target.identity.platform === component.identity.platform
|
|
2519
|
-
&& entry.target.identity.scope === component.identity.scope)?.target;
|
|
1524
|
+
const target = findTarget(component);
|
|
2520
1525
|
if (!target)
|
|
2521
1526
|
throw new Error('Native ownership probe cannot resolve its desired target.');
|
|
2522
1527
|
if (target.identity.platform === 'claude') {
|
|
@@ -2530,23 +1535,25 @@ function createNativeDriver(options) {
|
|
|
2530
1535
|
});
|
|
2531
1536
|
return state.pluginState;
|
|
2532
1537
|
}
|
|
2533
|
-
if (target.identity.platform === 'codex'
|
|
2534
|
-
const
|
|
2535
|
-
|
|
1538
|
+
if (target.identity.platform === 'codex') {
|
|
1539
|
+
const pending = pendingCodexNativeStates.get(codexStateKey(target, component.pluginId));
|
|
1540
|
+
if (pending)
|
|
1541
|
+
return pending;
|
|
1542
|
+
const registration = await inspectCodexPluginRegistrationLive({
|
|
1543
|
+
pluginId: component.pluginId,
|
|
2536
1544
|
cwd: target.identity.cwd,
|
|
2537
1545
|
env: options.context.env,
|
|
2538
|
-
|
|
2539
|
-
|
|
1546
|
+
nativeCliRunner: runner,
|
|
1547
|
+
manager: currentCodexManager(),
|
|
1548
|
+
scope: observationScopeFor(target),
|
|
1549
|
+
observationSession: options.context.codexObservationSession,
|
|
2540
1550
|
});
|
|
2541
|
-
return
|
|
1551
|
+
return observedCodexNativeState(registration.observation, 'native probe');
|
|
2542
1552
|
}
|
|
2543
1553
|
return 'absent';
|
|
2544
1554
|
},
|
|
2545
1555
|
probeNativeHealth: async (component) => {
|
|
2546
|
-
const target =
|
|
2547
|
-
&& entry.target.identity.sourceId === component.identity.sourceId
|
|
2548
|
-
&& entry.target.identity.platform === component.identity.platform
|
|
2549
|
-
&& entry.target.identity.scope === component.identity.scope)?.target;
|
|
1556
|
+
const target = findTarget(component);
|
|
2550
1557
|
if (!target)
|
|
2551
1558
|
throw new Error('Native health probe cannot resolve its desired target.');
|
|
2552
1559
|
if (target.identity.platform === 'claude') {
|
|
@@ -2560,57 +1567,96 @@ function createNativeDriver(options) {
|
|
|
2560
1567
|
});
|
|
2561
1568
|
if (state.pluginState !== 'present')
|
|
2562
1569
|
return state.pluginState;
|
|
2563
|
-
|
|
1570
|
+
if (!state.pluginEnabled)
|
|
1571
|
+
return 'partial';
|
|
1572
|
+
return 'present';
|
|
2564
1573
|
}
|
|
2565
|
-
if (target.identity.platform === 'codex'
|
|
2566
|
-
const
|
|
2567
|
-
|
|
1574
|
+
if (target.identity.platform === 'codex') {
|
|
1575
|
+
const pluginId = `${target.identity.pluginName}@${target.identity.marketplaceName ?? MARKETPLACE_NAME}`;
|
|
1576
|
+
const registration = await inspectCodexPluginRegistrationLive({
|
|
1577
|
+
pluginId,
|
|
2568
1578
|
cwd: target.identity.cwd,
|
|
2569
1579
|
env: options.context.env,
|
|
2570
|
-
|
|
2571
|
-
|
|
1580
|
+
nativeCliRunner: runner,
|
|
1581
|
+
manager: currentCodexManager(),
|
|
1582
|
+
scope: observationScopeFor(target),
|
|
1583
|
+
observationSession: options.context.codexObservationSession,
|
|
2572
1584
|
});
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
1585
|
+
const nativeState = observedCodexNativeState(registration.observation, 'native health postcheck');
|
|
1586
|
+
if (nativeState !== 'present')
|
|
1587
|
+
return nativeState;
|
|
1588
|
+
const userConfig = await readCodexConfigFile(resolveCodexPaths(target.identity.cwd, 'user', options.context.env).configTomlPath);
|
|
1589
|
+
const userEnabled = userConfig.snapshot.plugins[pluginId]?.enabled === true;
|
|
1590
|
+
if (target.identity.scope === 'user')
|
|
1591
|
+
return userEnabled ? 'present' : 'partial';
|
|
1592
|
+
const projectConfig = await readCodexConfigFile(resolveCodexPaths(target.identity.cwd, 'project', options.context.env).configTomlPath);
|
|
1593
|
+
return userEnabled || projectConfig.snapshot.plugins[pluginId]?.enabled === true
|
|
1594
|
+
? 'present'
|
|
1595
|
+
: 'partial';
|
|
2576
1596
|
}
|
|
2577
1597
|
return 'absent';
|
|
2578
1598
|
},
|
|
2579
1599
|
removeNative: async (component) => {
|
|
2580
|
-
const target =
|
|
2581
|
-
&& entry.target.identity.sourceId === component.identity.sourceId
|
|
2582
|
-
&& entry.target.identity.platform === component.identity.platform
|
|
2583
|
-
&& entry.target.identity.scope === component.identity.scope)?.target;
|
|
1600
|
+
const target = findTarget(component);
|
|
2584
1601
|
if (!target)
|
|
2585
1602
|
throw new Error('Native ownership removal cannot resolve its desired target.');
|
|
1603
|
+
await prepareNativeGroup(target);
|
|
2586
1604
|
if (target.identity.platform === 'codex') {
|
|
2587
|
-
const
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
marketplaceRoot: target.identity.marketplaceRoot,
|
|
2593
|
-
});
|
|
2594
|
-
if (before.state === 'foreign') {
|
|
2595
|
-
throw new Error(`Codex native owner 为 foreign,拒绝调用 plugin remove:${before.labels.join(',')}`);
|
|
1605
|
+
const marketplaceName = component.pluginId.slice(component.pluginId.lastIndexOf('@') + 1);
|
|
1606
|
+
const stateKey = codexStateKey(target, component.pluginId);
|
|
1607
|
+
const before = pendingCodexNativeStates.get(stateKey) ?? codexNativeStates.get(stateKey);
|
|
1608
|
+
if (!before) {
|
|
1609
|
+
throw new Error('codexNativeObservationUnavailable: native group precheck is missing.');
|
|
2596
1610
|
}
|
|
2597
|
-
|
|
1611
|
+
const removalRequired = before === 'present';
|
|
1612
|
+
if (!removalRequired) {
|
|
1613
|
+
await revokeAtRoot(path.join(target.identity.marketplaceRoot ?? resolveAwHome(options.context.env), 'plugins', target.identity.pluginName), true, 'codex');
|
|
2598
1614
|
return;
|
|
1615
|
+
}
|
|
2599
1616
|
try {
|
|
2600
|
-
|
|
1617
|
+
codexMutationMarketplaces.add(marketplaceName);
|
|
1618
|
+
await runObservedCodexMutation({
|
|
1619
|
+
marketplaceName,
|
|
1620
|
+
mutation: () => runNativeCliChecked(buildCodexPluginRemoveInvocation(requireCodexManager(currentCodexManager()), component.pluginId, target.identity.cwd, options.context.env), runner),
|
|
1621
|
+
});
|
|
2601
1622
|
}
|
|
2602
|
-
catch {
|
|
2603
|
-
|
|
1623
|
+
catch (error) {
|
|
1624
|
+
const diagnostic = readSafeOperationError(error);
|
|
1625
|
+
throw attachSafeOperationError(new Error(`codexNativeRemoveFailed: ${CODEX_REMOVE_RECOVERY}`), {
|
|
1626
|
+
code: 'codexNativeRemoveFailed',
|
|
1627
|
+
safeMessage: `Codex plugin removal did not complete. ${CODEX_REMOVE_RECOVERY}`,
|
|
1628
|
+
...(diagnostic?.exitCode === undefined ? {} : { exitCode: diagnostic.exitCode }),
|
|
1629
|
+
...(diagnostic ? {
|
|
1630
|
+
cause: { code: diagnostic.code, safeMessage: diagnostic.safeMessage },
|
|
1631
|
+
} : {}),
|
|
1632
|
+
});
|
|
2604
1633
|
}
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
1634
|
+
pendingCodexNativeStates.set(stateKey, 'absent');
|
|
1635
|
+
const postcheck = async () => {
|
|
1636
|
+
const after = await inspectCodexPluginRegistrationLive({
|
|
1637
|
+
pluginId: component.pluginId,
|
|
1638
|
+
cwd: target.identity.cwd,
|
|
1639
|
+
env: options.context.env,
|
|
1640
|
+
nativeCliRunner: runner,
|
|
1641
|
+
manager: currentCodexManager(),
|
|
1642
|
+
scope: observationScopeFor(target),
|
|
1643
|
+
observationSession: options.context.codexObservationSession,
|
|
1644
|
+
});
|
|
1645
|
+
const expected = pendingCodexNativeStates.get(stateKey) ?? 'absent';
|
|
1646
|
+
const observed = requireObservedCodexNativeState(after.observation, 'native mutation postcheck');
|
|
1647
|
+
if ((observed === 'installed' ? 'present' : 'absent') !== expected) {
|
|
1648
|
+
throw new Error(expected === 'absent'
|
|
1649
|
+
? `codexNativeRemoveIncomplete: ${CODEX_REMOVE_RECOVERY}`
|
|
1650
|
+
: `codexNativeInstallIncomplete: ${component.pluginId} is absent from Codex plugin list.`);
|
|
1651
|
+
}
|
|
1652
|
+
if (expected === 'absent')
|
|
1653
|
+
await revokeAtRoot(path.join(target.identity.marketplaceRoot ?? resolveAwHome(options.context.env), 'plugins', target.identity.pluginName), true, 'codex');
|
|
1654
|
+
};
|
|
1655
|
+
if (options.operationScopedNativePhases) {
|
|
1656
|
+
deferredPostchecks.push({ target, postcheck });
|
|
1657
|
+
}
|
|
1658
|
+
else {
|
|
1659
|
+
await postcheck();
|
|
2614
1660
|
}
|
|
2615
1661
|
}
|
|
2616
1662
|
else {
|
|
@@ -2639,390 +1685,128 @@ function createNativeDriver(options) {
|
|
|
2639
1685
|
}
|
|
2640
1686
|
}
|
|
2641
1687
|
},
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
if (!plan)
|
|
2645
|
-
throw new Error('Missing rebuild integration plan.');
|
|
2646
|
-
const marketplaceName = target.identity.marketplaceName ?? MARKETPLACE_NAME;
|
|
2647
|
-
const expectedMarketplaceRoot = target.identity.marketplaceRoot ?? resolveAwHome(options.context.env);
|
|
2648
|
-
const writeGeneration = async () => {
|
|
2649
|
-
if (mirrorTransactions.has(target)) {
|
|
2650
|
-
throw new Error('Marketplace mirror transaction is already active for this target.');
|
|
2651
|
-
}
|
|
2652
|
-
{
|
|
2653
|
-
if (target.identity.platform === 'codex') {
|
|
2654
|
-
const config = await readCodexConfigFile(resolveCodexPaths(target.identity.cwd, 'user', options.context.env).configTomlPath);
|
|
2655
|
-
const marketplace = config.snapshot.marketplaces[marketplaceName];
|
|
2656
|
-
if (marketplace && (marketplace.sourceType !== 'local'
|
|
2657
|
-
|| marketplace.sourcePointsToManifest
|
|
2658
|
-
|| path.normalize(marketplace.source ?? '') !== path.normalize(expectedMarketplaceRoot))) {
|
|
2659
|
-
throw new Error(`externalOwnershipPresent: Codex marketplace ${marketplaceName} 已由 foreign source 占用,拒绝覆盖。`);
|
|
2660
|
-
}
|
|
2661
|
-
}
|
|
2662
|
-
else {
|
|
2663
|
-
const state = await readClaudeNativeState({
|
|
2664
|
-
pluginName: target.identity.pluginName,
|
|
2665
|
-
scope: target.identity.scope,
|
|
2666
|
-
cwd: target.identity.cwd,
|
|
2667
|
-
env: options.context.env,
|
|
2668
|
-
marketplaceName,
|
|
2669
|
-
marketplaceRoot: expectedMarketplaceRoot,
|
|
2670
|
-
});
|
|
2671
|
-
if (state.marketplaceState === 'foreign') {
|
|
2672
|
-
throw new Error(`Claude marketplace ${marketplaceName} 已由 foreign source 占用,拒绝覆盖。`);
|
|
2673
|
-
}
|
|
2674
|
-
}
|
|
2675
|
-
const mirrored = await mirrorCatalog(plan.catalog, options.context.env, target.identity);
|
|
2676
|
-
mirrorTransactions.set(target, mirrored);
|
|
2677
|
-
const marketplaceRoot = mirrored.rootDir;
|
|
2678
|
-
const pluginId = `${target.identity.pluginName}@${marketplaceName}`;
|
|
2679
|
-
if (target.identity.platform === 'codex') {
|
|
2680
|
-
const requiredSkillWrites = plan.writes.filter((entry) => !entry.optional
|
|
2681
|
-
&& entry.component?.kind === 'skill-directory'
|
|
2682
|
-
&& entry.artifact.kind === 'skill'
|
|
2683
|
-
&& entry.artifact.state !== 'disabled'
|
|
2684
|
-
&& target.identity.scope === 'user');
|
|
2685
|
-
for (const write of requiredSkillWrites) {
|
|
2686
|
-
await write.write();
|
|
2687
|
-
}
|
|
2688
|
-
const skillsRelativeRoot = await ensureCodexActiveSkillsManifest({
|
|
2689
|
-
plugin: target.plugin,
|
|
2690
|
-
marketplaceRoot,
|
|
2691
|
-
hasRequiredSkills: requiredSkillWrites.length > 0,
|
|
2692
|
-
});
|
|
2693
|
-
const config = await readCodexConfigFile(resolveCodexPaths(target.identity.cwd, 'user', options.context.env).configTomlPath);
|
|
2694
|
-
const marketplace = config.snapshot.marketplaces[marketplaceName];
|
|
2695
|
-
if (path.normalize(marketplace?.source ?? '') !== path.normalize(marketplaceRoot)) {
|
|
2696
|
-
await runNativeCliChecked(buildCodexMarketplaceAddInvocation(requireCodexManager(codexManager), marketplaceRoot, target.identity.cwd, options.context.env), runner);
|
|
2697
|
-
}
|
|
2698
|
-
await runNativeCliChecked(buildCodexMarketplaceListInvocation(requireCodexManager(codexManager), target.identity.cwd, options.context.env), runner);
|
|
2699
|
-
await runNativeCliChecked(buildCodexPluginAddInvocation(requireCodexManager(codexManager), pluginId, target.identity.cwd, options.context.env), runner);
|
|
2700
|
-
await runNativeCliChecked(buildCodexPluginListInvocation(requireCodexManager(codexManager), target.identity.cwd, options.context.env), runner);
|
|
2701
|
-
await assertCodexNativeInstallState({
|
|
2702
|
-
pluginName: target.identity.pluginName,
|
|
2703
|
-
pluginVersion: target.identity.pluginVersion,
|
|
2704
|
-
cwd: target.identity.cwd,
|
|
2705
|
-
env: options.context.env,
|
|
2706
|
-
marketplaceRoot,
|
|
2707
|
-
marketplaceName,
|
|
2708
|
-
skillsRelativeRoot,
|
|
2709
|
-
requiredSkillKeys: requiredSkillWrites.flatMap((write) => write.artifact.artifactKey ? [write.artifact.artifactKey] : []),
|
|
2710
|
-
});
|
|
2711
|
-
}
|
|
2712
|
-
else {
|
|
2713
|
-
await runNativeCliChecked({
|
|
2714
|
-
command: 'claude',
|
|
2715
|
-
args: ['plugin', 'marketplace', 'add', marketplaceRoot, '--scope', target.identity.scope],
|
|
2716
|
-
cwd: target.identity.cwd,
|
|
2717
|
-
env: options.context.env,
|
|
2718
|
-
}, runner);
|
|
2719
|
-
await runNativeCliChecked({
|
|
2720
|
-
command: 'claude',
|
|
2721
|
-
args: ['plugin', 'install', pluginId, '--scope', target.identity.scope],
|
|
2722
|
-
cwd: target.identity.cwd,
|
|
2723
|
-
env: options.context.env,
|
|
2724
|
-
}, runner);
|
|
2725
|
-
await runNativeCliChecked({
|
|
2726
|
-
command: 'claude',
|
|
2727
|
-
args: ['plugin', 'list'],
|
|
2728
|
-
cwd: target.identity.cwd,
|
|
2729
|
-
env: options.context.env,
|
|
2730
|
-
}, runner);
|
|
2731
|
-
const after = await readClaudeNativeState({
|
|
2732
|
-
pluginName: target.identity.pluginName,
|
|
2733
|
-
scope: target.identity.scope,
|
|
2734
|
-
cwd: target.identity.cwd,
|
|
2735
|
-
env: options.context.env,
|
|
2736
|
-
marketplaceName,
|
|
2737
|
-
marketplaceRoot,
|
|
2738
|
-
});
|
|
2739
|
-
if (after.marketplaceDeclaredState !== 'canonical'
|
|
2740
|
-
|| after.marketplaceMaterializedState !== 'canonical'
|
|
2741
|
-
|| after.pluginState !== 'present'
|
|
2742
|
-
|| !after.pluginEnabled
|
|
2743
|
-
|| !after.pluginVersions.includes(target.identity.pluginVersion)) {
|
|
2744
|
-
throw new Error(`Claude native install postcheck 失败:declaredMarketplace=${after.marketplaceDeclaredState},materializedMarketplace=${after.marketplaceMaterializedState},plugin=${after.pluginState},enabled=${after.pluginEnabled},versions=${after.pluginVersions.join(',')}。`);
|
|
2745
|
-
}
|
|
2746
|
-
}
|
|
2747
|
-
}
|
|
2748
|
-
};
|
|
2749
|
-
await writeGeneration();
|
|
2750
|
-
},
|
|
1688
|
+
applyManagedCommands: publishPackages,
|
|
1689
|
+
writeNative: async () => { throw new Error('platformDeploymentRequired: native writes require a frozen platform deployment.'); },
|
|
2751
1690
|
writeArtifacts: async (target) => {
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
const writeAll = async () => {
|
|
2756
|
-
for (const write of plan.writes)
|
|
2757
|
-
await write.write();
|
|
2758
|
-
return plan.writes.map((write) => write.artifact);
|
|
2759
|
-
};
|
|
2760
|
-
return writeAll();
|
|
1691
|
+
if (target.artifacts.length > 0)
|
|
1692
|
+
throw new Error('platformDeploymentRequired: platform output requires a frozen platform deployment.');
|
|
1693
|
+
return [];
|
|
2761
1694
|
},
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
1695
|
+
runPreApply: async (invocation) => {
|
|
1696
|
+
if (isNativeActivationOnlyTarget(options.context, invocation.target.identity))
|
|
1697
|
+
return;
|
|
1698
|
+
const run = () => runPreApplyScript({
|
|
1699
|
+
plugin: invocation.plugin,
|
|
2766
1700
|
platform: invocation.target.identity.platform,
|
|
2767
1701
|
scope: invocation.target.identity.scope,
|
|
2768
1702
|
cwd: invocation.target.identity.cwd,
|
|
2769
1703
|
context: options.context,
|
|
2770
|
-
|
|
2771
|
-
artifacts: [...invocation.artifacts],
|
|
1704
|
+
referencePlugins: options.context.referencePlugins,
|
|
2772
1705
|
scriptTimeoutMs: options.scriptTimeoutMs,
|
|
2773
1706
|
});
|
|
1707
|
+
const cache = options.context.preApplyExecutionCache;
|
|
1708
|
+
if (!cache) {
|
|
1709
|
+
await run();
|
|
1710
|
+
return;
|
|
1711
|
+
}
|
|
1712
|
+
const { identity } = invocation.target;
|
|
1713
|
+
const sourceIdentity = invocation.plugin.sourceIdentity ?? identity.sourceIdentity;
|
|
1714
|
+
const pluginId = invocation.plugin.pluginId ?? identity.pluginId;
|
|
1715
|
+
if (!sourceIdentity || !pluginId) {
|
|
1716
|
+
await run();
|
|
1717
|
+
return;
|
|
1718
|
+
}
|
|
1719
|
+
const projectKey = identity.scope === 'project'
|
|
1720
|
+
? identity.platform === 'codex'
|
|
1721
|
+
? await resolveCodexProjectKey(identity.cwd)
|
|
1722
|
+
: identity.platform === 'claude'
|
|
1723
|
+
? await resolveClaudeProjectKey(identity.cwd)
|
|
1724
|
+
: createProjectLocationKey(await resolveRequiredCanonicalRepoRoot(identity.cwd))
|
|
1725
|
+
: '';
|
|
1726
|
+
const key = [
|
|
1727
|
+
sourceIdentity,
|
|
1728
|
+
pluginId,
|
|
1729
|
+
identity.platform,
|
|
1730
|
+
identity.scope,
|
|
1731
|
+
projectKey,
|
|
1732
|
+
].join('\0');
|
|
1733
|
+
let execution = cache.get(key);
|
|
1734
|
+
if (!execution) {
|
|
1735
|
+
execution = run();
|
|
1736
|
+
cache.set(key, execution);
|
|
1737
|
+
}
|
|
1738
|
+
await execution;
|
|
2774
1739
|
},
|
|
2775
1740
|
};
|
|
2776
1741
|
}
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
return plan ? [{ target, plan }] : [];
|
|
2782
|
-
});
|
|
1742
|
+
export function isNativeActivationOnlyTarget(context, identity) {
|
|
1743
|
+
return context.nativeActivationOnlyTargets?.some((target) => target.pluginId === identity.pluginId
|
|
1744
|
+
&& target.platform === identity.platform
|
|
1745
|
+
&& target.scope === identity.scope) === true;
|
|
2783
1746
|
}
|
|
2784
1747
|
export function createRebuildIntegration(options) {
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
const driver = createNativeDriver({
|
|
1748
|
+
options.context.scriptTimeoutMs ??= options.scriptTimeoutMs;
|
|
1749
|
+
const targets = [...(options.preparedTargets ?? [])];
|
|
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);
|
|
2788
1763
|
return {
|
|
1764
|
+
resolvePlatformTargets: (inputs) => platformSession.resolveAll(inputs),
|
|
1765
|
+
sealMarketplaceGenerations: (eligible) => platformSession.sealMarketplaceGenerations(eligible),
|
|
2789
1766
|
driver,
|
|
1767
|
+
setNativeMarketplaceEligibleTargets: driver.setNativeMarketplaceEligibleTargets,
|
|
1768
|
+
prepareNativeMarketplaceGroup: driver.prepareNativeMarketplaceGroup,
|
|
1769
|
+
captureCodexPostMutationSnapshots: driver.captureCodexPostMutationSnapshots,
|
|
2790
1770
|
buildTarget: async (input) => {
|
|
2791
|
-
const
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
env: options.context.env
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
let historicalArtifacts = [];
|
|
2817
|
-
if (input.includeHistoricalLifecycleArtifacts) {
|
|
2818
|
-
const loadPlugin = (bundleRoot) => readPluginManifest(bundleRoot, { mode: 'bundle' });
|
|
2819
|
-
const { readLifecycleActiveSnapshot } = await import('../utils/lifecycle-active-store.js');
|
|
2820
|
-
const active = await readLifecycleActiveSnapshot({
|
|
2821
|
-
...(input.sourceId ? {
|
|
2822
|
-
sourceId: input.sourceId,
|
|
2823
|
-
sourceIdentity: input.sourceIdentity,
|
|
2824
|
-
} : {}),
|
|
2825
|
-
pluginName: input.plugin.manifest.name,
|
|
2826
|
-
platform: input.platform,
|
|
2827
|
-
scope: input.scope,
|
|
2828
|
-
cwd: input.cwd,
|
|
2829
|
-
env: options.context.env,
|
|
2830
|
-
loadPlugin,
|
|
2831
|
-
});
|
|
2832
|
-
historicalArtifacts = active?.artifacts ?? [];
|
|
2833
|
-
}
|
|
2834
|
-
let writes = [];
|
|
2835
|
-
if (input.command !== 'cleanup' && input.command !== 'uninstall') {
|
|
2836
|
-
if (input.readOnlyInspectionPlan) {
|
|
2837
|
-
writes = await buildInspectionWrites({
|
|
2838
|
-
plugin: input.plugin,
|
|
2839
|
-
platform: input.platform,
|
|
2840
|
-
scope: input.scope,
|
|
2841
|
-
cwd: input.cwd,
|
|
2842
|
-
env: options.context.env,
|
|
2843
|
-
marketplaceRoot: input.marketplaceRoot,
|
|
2844
|
-
});
|
|
2845
|
-
}
|
|
2846
|
-
else if (input.platform === 'codex') {
|
|
2847
|
-
writes = await buildCodexWrites({
|
|
2848
|
-
...input,
|
|
2849
|
-
env: options.context.env,
|
|
2850
|
-
event,
|
|
2851
|
-
historicalArtifacts,
|
|
2852
|
-
scriptTimeoutMs: options.scriptTimeoutMs,
|
|
2853
|
-
});
|
|
2854
|
-
}
|
|
2855
|
-
else {
|
|
2856
|
-
writes = await buildClaudeWrites({
|
|
2857
|
-
...input,
|
|
2858
|
-
env: options.context.env,
|
|
2859
|
-
event,
|
|
2860
|
-
historicalArtifacts,
|
|
2861
|
-
scriptTimeoutMs: options.scriptTimeoutMs,
|
|
2862
|
-
});
|
|
2863
|
-
}
|
|
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)
|
|
1794
|
+
operationActions[0].nativeToolChanges = nativeToolChanges;
|
|
1795
|
+
target.operationActions = operationActions;
|
|
2864
1796
|
}
|
|
2865
|
-
|
|
2866
|
-
...(write.additionalComponents ?? []),
|
|
2867
|
-
...(write.component ? [write.component] : []),
|
|
2868
|
-
]);
|
|
2869
|
-
const optionalComponents = writes
|
|
2870
|
-
.filter((write) => write.optional)
|
|
2871
|
-
.flatMap((write) => [
|
|
2872
|
-
...(write.additionalComponents ?? []),
|
|
2873
|
-
...(write.component ? [write.component] : []),
|
|
2874
|
-
]);
|
|
2875
|
-
const optionalComponentKeys = new Set(optionalComponents.map(componentIdentityKey));
|
|
2876
|
-
const configDir = input.platform === 'codex'
|
|
2877
|
-
? resolveCodexPaths(input.cwd, input.scope, options.context.env).configDir
|
|
2878
|
-
: resolveClaudePaths(input.cwd, input.scope, options.context.env).configDir;
|
|
2879
|
-
const textRoots = input.platform === 'codex'
|
|
2880
|
-
? [path.join(configDir, 'rules'), path.join(configDir, 'agents')]
|
|
2881
|
-
: [path.join(configDir, 'rules'), path.join(configDir, 'agents')];
|
|
2882
|
-
const scannedText = (await Promise.all(textRoots.map((root) => scanOwnedTextFiles({
|
|
2883
|
-
sourceId: input.sourceId,
|
|
2884
|
-
sourceIdentity: input.sourceIdentity,
|
|
2885
|
-
root,
|
|
2886
|
-
pluginName: input.plugin.manifest.name,
|
|
2887
|
-
platform: input.platform,
|
|
2888
|
-
scope: input.scope,
|
|
2889
|
-
})))).flat();
|
|
2890
|
-
const skillRoots = input.platform === 'codex'
|
|
2891
|
-
? input.scope === 'project'
|
|
2892
|
-
? [path.join(await resolveRepoRoot(input.cwd), '.agents', 'skills')]
|
|
2893
|
-
: [path.join(input.marketplaceRoot ?? resolveAwHome(options.context.env), 'plugins', input.plugin.manifest.name)]
|
|
2894
|
-
: [path.join(configDir, 'skills')];
|
|
2895
|
-
const scanSkills = () => Promise.all(skillRoots.map((root) => scanOwnedSkills({
|
|
2896
|
-
sourceId: input.sourceId,
|
|
2897
|
-
sourceIdentity: input.sourceIdentity,
|
|
2898
|
-
root,
|
|
2899
|
-
pluginName: input.plugin.manifest.name,
|
|
2900
|
-
platform: input.platform,
|
|
2901
|
-
scope: input.scope,
|
|
2902
|
-
})));
|
|
2903
|
-
const scannedSkills = (await scanSkills()).flat();
|
|
2904
|
-
const historicalComponents = await buildHistoricalComponents({
|
|
2905
|
-
sourceId: input.sourceId,
|
|
2906
|
-
sourceIdentity: input.sourceIdentity,
|
|
2907
|
-
pluginId: input.pluginId,
|
|
2908
|
-
pluginName: input.plugin.manifest.name,
|
|
2909
|
-
platform: input.platform,
|
|
2910
|
-
scope: input.scope,
|
|
2911
|
-
cwd: input.cwd,
|
|
2912
|
-
env: options.context.env,
|
|
2913
|
-
artifacts: historicalArtifacts,
|
|
2914
|
-
});
|
|
2915
|
-
const sharedComponents = input.platform === 'codex'
|
|
2916
|
-
? await scanCodexSharedComponents({
|
|
2917
|
-
sourceId: input.sourceId,
|
|
2918
|
-
sourceIdentity: input.sourceIdentity,
|
|
2919
|
-
pluginId: input.pluginId,
|
|
2920
|
-
pluginName: input.plugin.manifest.name,
|
|
2921
|
-
scope: input.scope,
|
|
2922
|
-
paths: resolveCodexPaths(input.cwd, input.scope, options.context.env),
|
|
2923
|
-
scanConfig: true,
|
|
2924
|
-
scanHooks: true,
|
|
2925
|
-
ignoreReadErrors: true,
|
|
2926
|
-
})
|
|
2927
|
-
: await scanClaudeSharedComponents({
|
|
2928
|
-
sourceId: input.sourceId,
|
|
2929
|
-
sourceIdentity: input.sourceIdentity,
|
|
2930
|
-
pluginId: input.pluginId,
|
|
2931
|
-
pluginName: input.plugin.manifest.name,
|
|
2932
|
-
scope: input.scope,
|
|
2933
|
-
settingsPath: resolveClaudePaths(input.cwd, input.scope, options.context.env).settingsPath,
|
|
2934
|
-
});
|
|
2935
|
-
const nativeRequired = input.platform === 'claude'
|
|
2936
|
-
|| (input.scope === 'user' && requiresCodexNativePlugin(input.plugin, input.scope));
|
|
2937
|
-
const nativeCleanupCandidate = (input.platform === 'claude' || input.scope === 'user')
|
|
2938
|
-
&& input.includeNativeCleanupCandidate !== false;
|
|
2939
|
-
const nativePlugin = (nativeRequired || nativeCleanupCandidate)
|
|
2940
|
-
? [{
|
|
2941
|
-
kind: 'native-plugin',
|
|
2942
|
-
identity: ownerIdentity(input.plugin.manifest.name, 'native', input.platform, input.scope),
|
|
2943
|
-
pluginId: `${input.plugin.manifest.name}@${input.marketplaceName ?? MARKETPLACE_NAME}`,
|
|
2944
|
-
}]
|
|
2945
|
-
: [];
|
|
2946
|
-
const marketplaceDesired = nativeRequired
|
|
2947
|
-
&& input.command !== 'cleanup'
|
|
2948
|
-
&& input.command !== 'uninstall';
|
|
2949
|
-
const marketplace = input.platform === 'codex' && input.scope === 'user'
|
|
2950
|
-
? [createCodexMarketplaceComponent({
|
|
2951
|
-
pluginName: input.plugin.manifest.name,
|
|
2952
|
-
codexManager: options.context.codexManager,
|
|
2953
|
-
cwd: input.cwd,
|
|
2954
|
-
env: options.context.env,
|
|
2955
|
-
runner: options.context.nativeCliRunner,
|
|
2956
|
-
marketplaceName: input.marketplaceName ?? MARKETPLACE_NAME,
|
|
2957
|
-
marketplaceRoot: input.marketplaceRoot ?? resolveAwHome(options.context.env),
|
|
2958
|
-
desired: marketplaceDesired,
|
|
2959
|
-
})]
|
|
2960
|
-
: input.platform === 'claude'
|
|
2961
|
-
? [createClaudeMarketplaceComponent({
|
|
2962
|
-
pluginName: input.plugin.manifest.name,
|
|
2963
|
-
scope: input.scope,
|
|
2964
|
-
cwd: input.cwd,
|
|
2965
|
-
env: options.context.env,
|
|
2966
|
-
runner: options.context.nativeCliRunner,
|
|
2967
|
-
marketplaceName: input.marketplaceName ?? MARKETPLACE_NAME,
|
|
2968
|
-
marketplaceRoot: input.marketplaceRoot ?? resolveAwHome(options.context.env),
|
|
2969
|
-
desired: marketplaceDesired,
|
|
2970
|
-
})]
|
|
2971
|
-
: [];
|
|
2972
|
-
if (nativeRequired
|
|
2973
|
-
&& input.command !== 'cleanup'
|
|
2974
|
-
&& input.command !== 'uninstall')
|
|
2975
|
-
desiredComponents.push(...nativePlugin, ...marketplace);
|
|
2976
|
-
const allComponents = dedupeComponents([
|
|
2977
|
-
...desiredComponents,
|
|
2978
|
-
...optionalComponents,
|
|
2979
|
-
...(input.platform === 'codex' ? sharedComponents : []),
|
|
2980
|
-
...scannedText,
|
|
2981
|
-
...scannedSkills,
|
|
2982
|
-
...historicalComponents,
|
|
2983
|
-
...(input.platform === 'claude' ? sharedComponents : []),
|
|
2984
|
-
...nativePlugin,
|
|
2985
|
-
...marketplace,
|
|
2986
|
-
]);
|
|
2987
|
-
bindNamespacedOwnerIdentity(allComponents, input);
|
|
2988
|
-
const desiredKeys = new Set(desiredComponents.map(componentIdentityKey));
|
|
2989
|
-
const target = {
|
|
2990
|
-
plugin: input.plugin,
|
|
2991
|
-
identity: {
|
|
2992
|
-
...(input.sourceId ? {
|
|
2993
|
-
sourceId: input.sourceId,
|
|
2994
|
-
sourceIdentity: input.sourceIdentity,
|
|
2995
|
-
pluginId: input.pluginId,
|
|
2996
|
-
marketplaceName: input.marketplaceName,
|
|
2997
|
-
marketplaceRoot: input.marketplaceRoot,
|
|
2998
|
-
} : {}),
|
|
2999
|
-
pluginName: input.plugin.manifest.name,
|
|
3000
|
-
pluginVersion: input.plugin.manifest.version,
|
|
3001
|
-
platform: input.platform,
|
|
3002
|
-
scope: input.scope,
|
|
3003
|
-
cwd: input.cwd,
|
|
3004
|
-
},
|
|
3005
|
-
ownedComponents: allComponents,
|
|
3006
|
-
desiredOwnedComponents: allComponents.filter((component) => desiredKeys.has(componentIdentityKey(component))),
|
|
3007
|
-
optionalOwnedComponents: allComponents.filter((component) => optionalComponentKeys.has(componentIdentityKey(component))),
|
|
3008
|
-
requiresNative: nativeRequired
|
|
3009
|
-
&& input.command !== 'cleanup'
|
|
3010
|
-
&& input.command !== 'uninstall',
|
|
3011
|
-
artifacts: writes.map((write) => write.artifact),
|
|
3012
|
-
lifecycleSource: input.plugin,
|
|
3013
|
-
};
|
|
3014
|
-
plans.set(target, {
|
|
3015
|
-
catalog: input.catalog,
|
|
3016
|
-
event,
|
|
3017
|
-
writes,
|
|
3018
|
-
});
|
|
3019
|
-
planTargets.get(plans).push(target);
|
|
1797
|
+
targets.push(target);
|
|
3020
1798
|
return target;
|
|
3021
1799
|
},
|
|
3022
1800
|
};
|
|
3023
1801
|
}
|
|
3024
1802
|
export async function inspectRebuildTarget(options) {
|
|
3025
|
-
const integration = createRebuildIntegration({
|
|
1803
|
+
const integration = createRebuildIntegration({
|
|
1804
|
+
context: {
|
|
1805
|
+
...options.context,
|
|
1806
|
+
codexUserActivationDesired: options.userActivationDesired
|
|
1807
|
+
?? options.context.codexUserActivationDesired,
|
|
1808
|
+
},
|
|
1809
|
+
});
|
|
3026
1810
|
const target = await integration.buildTarget({
|
|
3027
1811
|
...(options.sourceId ? {
|
|
3028
1812
|
sourceId: options.sourceId,
|
|
@@ -3037,35 +1821,36 @@ export async function inspectRebuildTarget(options) {
|
|
|
3037
1821
|
cwd: options.cwd,
|
|
3038
1822
|
command: 'install',
|
|
3039
1823
|
catalog: options.catalog,
|
|
3040
|
-
includeHistoricalLifecycleArtifacts: false,
|
|
3041
1824
|
readOnlyInspectionPlan: true,
|
|
1825
|
+
readOnlyShallowInspectionPlan: options.shallow,
|
|
3042
1826
|
});
|
|
3043
1827
|
const inspection = await inspectOwnedComponents({
|
|
3044
1828
|
components: target.ownedComponents,
|
|
3045
|
-
|
|
1829
|
+
executor: integration.driver.ownership,
|
|
1830
|
+
nativeProbe: options.nativeProbe
|
|
1831
|
+
?? integration.driver.probeNativeHealth
|
|
1832
|
+
?? integration.driver.probeNative,
|
|
3046
1833
|
verifyHealth: true,
|
|
3047
1834
|
});
|
|
3048
1835
|
if (!target.requiresNative)
|
|
3049
1836
|
return { target, inspection };
|
|
3050
1837
|
if (target.identity.platform === 'codex') {
|
|
3051
|
-
const
|
|
3052
|
-
|
|
1838
|
+
const nativeInspection = inspection.components.find((component) => component.component.kind === 'native-plugin');
|
|
1839
|
+
if (nativeInspection?.state !== 'present')
|
|
1840
|
+
return { target, inspection };
|
|
1841
|
+
const registration = await inspectCodexPluginRegistrationLive({
|
|
1842
|
+
pluginId: `${target.identity.pluginName}@${target.identity.marketplaceName ?? MARKETPLACE_NAME}`,
|
|
3053
1843
|
cwd: target.identity.cwd,
|
|
3054
1844
|
env: options.context.env,
|
|
3055
|
-
|
|
3056
|
-
|
|
1845
|
+
nativeCliRunner: options.context.nativeCliRunner,
|
|
1846
|
+
manager: options.context.codexManager,
|
|
1847
|
+
scope: target.identity.scope,
|
|
1848
|
+
observationSession: options.context.codexObservationSession,
|
|
3057
1849
|
});
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
return installed.length === 1
|
|
3063
|
-
? { target, inspection, installedVersion: installed[0] }
|
|
3064
|
-
: { target, inspection };
|
|
3065
|
-
}
|
|
3066
|
-
const cached = [...new Set(residue.cacheVersions)];
|
|
3067
|
-
return cached.length === 1
|
|
3068
|
-
? { target, inspection, installedVersion: cached[0] }
|
|
1850
|
+
return registration.observation.state === 'observed'
|
|
1851
|
+
&& registration.observation.value === 'installed'
|
|
1852
|
+
&& registration.observation.entry.version !== undefined
|
|
1853
|
+
? { target, inspection, installedVersion: registration.observation.entry.version }
|
|
3069
1854
|
: { target, inspection };
|
|
3070
1855
|
}
|
|
3071
1856
|
const native = await readClaudeNativeState({
|
|
@@ -3141,7 +1926,7 @@ export async function discoverRebuildTargetNames(options) {
|
|
|
3141
1926
|
cwd: options.cwd,
|
|
3142
1927
|
rootNames: options.platform === 'codex' ? ['.agents', '.codex'] : ['.claude'],
|
|
3143
1928
|
managedPaths: options.platform === 'codex'
|
|
3144
|
-
? ['.codex/config.toml'
|
|
1929
|
+
? ['.codex/config.toml']
|
|
3145
1930
|
: ['.claude/settings.json'],
|
|
3146
1931
|
});
|
|
3147
1932
|
options = { ...options, cwd: canonicalRepoRoot };
|
|
@@ -3155,7 +1940,7 @@ export async function discoverRebuildTargetNames(options) {
|
|
|
3155
1940
|
names.add(name);
|
|
3156
1941
|
const skillRoots = options.platform === 'codex'
|
|
3157
1942
|
? options.scope === 'project'
|
|
3158
|
-
? [
|
|
1943
|
+
? []
|
|
3159
1944
|
: [path.join(resolveAwHome(options.env), 'plugins')]
|
|
3160
1945
|
: [path.join(paths.configDir, 'skills')];
|
|
3161
1946
|
if (options.platform === 'codex' && options.scope === 'user') {
|
|
@@ -3190,34 +1975,57 @@ export async function discoverRebuildTargetNames(options) {
|
|
|
3190
1975
|
for (const name of Object.keys(config.snapshot.developerInstructions.managedBlocks)) {
|
|
3191
1976
|
names.add(sharedOwnerPluginName(name));
|
|
3192
1977
|
}
|
|
3193
|
-
for (const server of Object.values(config.snapshot.mcpServers)) {
|
|
3194
|
-
const envValue = server.value?.env;
|
|
3195
|
-
const owner = envValue
|
|
3196
|
-
&& typeof envValue === 'object'
|
|
3197
|
-
&& !Array.isArray(envValue)
|
|
3198
|
-
&& typeof envValue[MCP_OWNER_ENV] === 'string'
|
|
3199
|
-
? envValue[MCP_OWNER_ENV]
|
|
3200
|
-
: null;
|
|
3201
|
-
if (owner)
|
|
3202
|
-
names.add(sharedOwnerPluginName(owner));
|
|
3203
|
-
}
|
|
3204
1978
|
if (options.scope === 'project') {
|
|
3205
|
-
const
|
|
3206
|
-
const
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
1979
|
+
const suffix = `@${options.marketplaceName ?? MARKETPLACE_NAME}`;
|
|
1980
|
+
for (const pluginId of Object.keys(config.snapshot.plugins)) {
|
|
1981
|
+
if (!pluginId.endsWith(suffix))
|
|
1982
|
+
continue;
|
|
1983
|
+
const name = pluginId.slice(0, -suffix.length);
|
|
1984
|
+
if (/^[a-z0-9]+(?:-[a-z0-9]+)*$/u.test(name))
|
|
1985
|
+
names.add(name);
|
|
3211
1986
|
}
|
|
3212
1987
|
}
|
|
3213
1988
|
else {
|
|
3214
|
-
|
|
3215
|
-
|
|
1989
|
+
const marketplaceName = options.marketplaceName ?? MARKETPLACE_NAME;
|
|
1990
|
+
const marketplaceRoot = options.marketplaceRoot ?? resolveAwHome(options.env);
|
|
1991
|
+
const marketplace = config.snapshot.marketplaces[marketplaceName];
|
|
1992
|
+
const canonicalMarketplace = isCanonicalCodexMarketplaceRegistration(marketplace, marketplaceRoot);
|
|
1993
|
+
const suffix = `@${marketplaceName}`;
|
|
1994
|
+
const configuredPluginIds = Object.keys(config.snapshot.plugins)
|
|
1995
|
+
.filter((pluginId) => pluginId.endsWith(suffix));
|
|
1996
|
+
if (configuredPluginIds.length > 0 && !canonicalMarketplace) {
|
|
1997
|
+
throw new Error(`externalOwnershipPresent: Codex marketplace ${marketplaceName} has a foreign public config source.`);
|
|
1998
|
+
}
|
|
1999
|
+
for (const pluginId of canonicalMarketplace ? configuredPluginIds : []) {
|
|
2000
|
+
const name = pluginId.slice(0, -suffix.length);
|
|
2001
|
+
if (/^[a-z0-9]+(?:-[a-z0-9]+)*$/u.test(name))
|
|
2002
|
+
names.add(name);
|
|
2003
|
+
}
|
|
2004
|
+
const session = await createCodexNativeObservationSession({
|
|
2005
|
+
exactCwd: options.cwd,
|
|
3216
2006
|
env: options.env,
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
2007
|
+
runner: options.nativeCliRunner,
|
|
2008
|
+
});
|
|
2009
|
+
try {
|
|
2010
|
+
const snapshot = await session.snapshot(marketplaceName, 'user');
|
|
2011
|
+
if (!snapshot.neutral) {
|
|
2012
|
+
if (options.nativeFailureMode !== 'ignore') {
|
|
2013
|
+
throw new Error('codexNativeObservationFailed: cannot discover official Codex plugins.');
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
else {
|
|
2017
|
+
for (const pluginId of snapshot.neutral.keys()) {
|
|
2018
|
+
if (!pluginId.endsWith(suffix))
|
|
2019
|
+
continue;
|
|
2020
|
+
const name = pluginId.slice(0, -suffix.length);
|
|
2021
|
+
if (/^[a-z0-9]+(?:-[a-z0-9]+)*$/u.test(name))
|
|
2022
|
+
names.add(name);
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
finally {
|
|
2027
|
+
await session.dispose();
|
|
2028
|
+
}
|
|
3221
2029
|
}
|
|
3222
2030
|
}
|
|
3223
2031
|
else {
|