@lesliechan721/aw 0.1.0-beta.9 → 0.1.0-beta.91
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/assets/command-runtime-config.d.mts +9 -0
- package/dist/authoring/assets/command-runtime-config.mjs +134 -0
- package/dist/authoring/assets/command-runtime-config.mjs.map +1 -0
- package/dist/authoring/scripts/add-skill.mjs +15 -38
- package/dist/authoring/scripts/add-skill.mjs.map +1 -1
- package/dist/authoring/scripts/init-plugin.mjs +72 -96
- 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 +2 -2
- package/dist/authoring/scripts/lib/skill-scaffold.mjs +4 -7
- package/dist/authoring/scripts/lib/skill-scaffold.mjs.map +1 -1
- package/dist/authoring/scripts/remove-plugin.mjs +1 -1
- package/dist/authoring/scripts/remove-plugin.mjs.map +1 -1
- package/dist/authoring/scripts/validate-plugin.mjs +416 -1995
- package/dist/authoring/scripts/validate-plugin.mjs.map +1 -1
- package/dist/authoring/scripts/validate-skill.mjs +1 -1
- package/dist/index.js +2 -6
- package/dist/index.js.map +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 +11 -1
- package/dist/scripts/aw-skill-eval-materializer.js +118 -115
- package/dist/scripts/aw-skill-eval-materializer.js.map +1 -1
- package/dist/scripts/bundle-plugins.js +25 -7
- package/dist/scripts/bundle-plugins.js.map +1 -1
- package/dist/scripts/plugin-staging.d.ts +7 -7
- package/dist/scripts/plugin-staging.js +10 -8
- 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 +284 -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 +3 -0
- 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 +1 -1
- package/dist/src/commands/aw-capabilities.js +42 -21
- package/dist/src/commands/aw-capabilities.js.map +1 -1
- package/dist/src/commands/catalog-dev-source.d.ts +42 -3
- package/dist/src/commands/catalog-dev-source.js +351 -43
- package/dist/src/commands/catalog-dev-source.js.map +1 -1
- package/dist/src/commands/catalog-generation.d.ts +8 -0
- package/dist/src/commands/catalog-generation.js +1 -5
- package/dist/src/commands/catalog-generation.js.map +1 -1
- package/dist/src/commands/catalog-publication-inspection.d.ts +42 -3
- package/dist/src/commands/catalog-publication-inspection.js +379 -48
- package/dist/src/commands/catalog-publication-inspection.js.map +1 -1
- package/dist/src/commands/catalog-publication-journal.d.ts +23 -4
- package/dist/src/commands/catalog-publication-journal.js +165 -20
- package/dist/src/commands/catalog-publication-journal.js.map +1 -1
- package/dist/src/commands/catalog-publish.d.ts +34 -3
- package/dist/src/commands/catalog-publish.js +311 -165
- package/dist/src/commands/catalog-publish.js.map +1 -1
- package/dist/src/commands/catalog-source.d.ts +54 -8
- package/dist/src/commands/catalog-source.js +277 -15
- package/dist/src/commands/catalog-source.js.map +1 -1
- package/dist/src/commands/catalog-status.js +2 -2
- 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 +4 -0
- package/dist/src/commands/catalog-workspace-resolution.js +18 -3
- package/dist/src/commands/catalog-workspace-resolution.js.map +1 -1
- package/dist/src/commands/console.js +33 -20
- package/dist/src/commands/console.js.map +1 -1
- package/dist/src/commands/dependency-operation-plan.d.ts +14 -56
- package/dist/src/commands/dependency-operation-plan.js +90 -133
- package/dist/src/commands/dependency-operation-plan.js.map +1 -1
- package/dist/src/commands/deployment-confirmation.d.ts +11 -0
- package/dist/src/commands/deployment-confirmation.js +88 -0
- package/dist/src/commands/deployment-confirmation.js.map +1 -0
- package/dist/src/commands/init.js +1 -1
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/commands/intent-command.d.ts +34 -0
- package/dist/src/commands/intent-command.js +174 -0
- package/dist/src/commands/intent-command.js.map +1 -0
- package/dist/src/commands/lifecycle-command-package.d.ts +45 -0
- package/dist/src/commands/lifecycle-command-package.js +199 -0
- package/dist/src/commands/lifecycle-command-package.js.map +1 -0
- package/dist/src/commands/managed-commands.d.ts +41 -0
- package/dist/src/commands/managed-commands.js +404 -0
- package/dist/src/commands/managed-commands.js.map +1 -0
- package/dist/src/commands/offline-cleanup-evidence.d.ts +29 -3
- package/dist/src/commands/offline-cleanup-evidence.js +80 -10
- package/dist/src/commands/offline-cleanup-evidence.js.map +1 -1
- package/dist/src/commands/operation-plan.d.ts +191 -0
- package/dist/src/commands/operation-plan.js +96 -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 +11 -20
- package/dist/src/commands/options.js +31 -36
- package/dist/src/commands/options.js.map +1 -1
- package/dist/src/commands/permission-batch.d.ts +5 -0
- package/dist/src/commands/permission-batch.js +80 -0
- package/dist/src/commands/permission-batch.js.map +1 -0
- package/dist/src/commands/plugin-capabilities.js +96 -46
- package/dist/src/commands/plugin-capabilities.js.map +1 -1
- package/dist/src/commands/public-config-confirmation.d.ts +14 -0
- package/dist/src/commands/public-config-confirmation.js +73 -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 +106 -0
- package/dist/src/commands/public-lifecycle-result.js +518 -0
- package/dist/src/commands/public-lifecycle-result.js.map +1 -0
- package/dist/src/commands/public-lifecycle.d.ts +27 -0
- package/dist/src/commands/public-lifecycle.js +563 -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 +230 -0
- package/dist/src/commands/public-plugin-query.js.map +1 -0
- package/dist/src/commands/rebuild-command.d.ts +176 -25
- package/dist/src/commands/rebuild-command.js +3989 -1392
- package/dist/src/commands/rebuild-command.js.map +1 -1
- package/dist/src/commands/rebuild-integration.d.ts +133 -52
- package/dist/src/commands/rebuild-integration.js +1097 -2692
- package/dist/src/commands/rebuild-integration.js.map +1 -1
- package/dist/src/commands/rebuild-operations.d.ts +74 -23
- package/dist/src/commands/rebuild-operations.js +334 -227
- package/dist/src/commands/rebuild-operations.js.map +1 -1
- package/dist/src/commands/rebuild-platform-integration.d.ts +81 -0
- package/dist/src/commands/rebuild-platform-integration.js +1992 -0
- package/dist/src/commands/rebuild-platform-integration.js.map +1 -0
- package/dist/src/commands/reconcile-operation-plan.d.ts +31 -0
- package/dist/src/commands/reconcile-operation-plan.js +48 -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 +8 -0
- package/dist/src/commands/skill-eval.js +126 -73
- package/dist/src/commands/skill-eval.js.map +1 -1
- package/dist/src/commands/status-v6.d.ts +185 -68
- package/dist/src/commands/status-v6.js +1592 -499
- package/dist/src/commands/status-v6.js.map +1 -1
- 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 +144 -44
- package/dist/src/commands/write-commands.js.map +1 -1
- package/dist/src/constants.d.ts +2 -3
- package/dist/src/constants.js +2 -3
- package/dist/src/constants.js.map +1 -1
- package/dist/src/eval/manifest-v1.d.ts +6 -2
- package/dist/src/eval/manifest-v1.js +58 -26
- package/dist/src/eval/manifest-v1.js.map +1 -1
- package/dist/src/generators/local-plugin.d.ts +4 -2
- package/dist/src/generators/local-plugin.js +207 -346
- package/dist/src/generators/local-plugin.js.map +1 -1
- package/dist/src/generators/permissions.d.ts +20 -2
- package/dist/src/generators/permissions.js +82 -15
- package/dist/src/generators/permissions.js.map +1 -1
- package/dist/src/index.d.ts +3 -33
- package/dist/src/index.js +1786 -1945
- 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 +35 -0
- package/dist/src/intent/scope-context.js +179 -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 +37 -86
- package/dist/src/output/command-receipt.js +257 -179
- package/dist/src/output/command-receipt.js.map +1 -1
- package/dist/src/output/component-delivery.d.ts +28 -0
- package/dist/src/output/component-delivery.js +138 -0
- package/dist/src/output/component-delivery.js.map +1 -0
- package/dist/src/output/public-result.d.ts +69 -0
- package/dist/src/output/public-result.js +403 -0
- package/dist/src/output/public-result.js.map +1 -0
- package/dist/src/output/rebuild-progress.d.ts +3 -0
- package/dist/src/output/rebuild-progress.js +34 -16
- 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 +664 -0
- package/dist/src/output/receipt-projection.js.map +1 -0
- package/dist/src/output/skill-invocation-notices.d.ts +18 -0
- package/dist/src/output/skill-invocation-notices.js +84 -0
- package/dist/src/output/skill-invocation-notices.js.map +1 -0
- package/dist/src/platforms/antigravity-permissions.d.ts +50 -0
- package/dist/src/platforms/antigravity-permissions.js +388 -0
- package/dist/src/platforms/antigravity-permissions.js.map +1 -0
- package/dist/src/platforms/capabilities.d.ts +17 -0
- package/dist/src/platforms/capabilities.js +328 -0
- package/dist/src/platforms/capabilities.js.map +1 -0
- package/dist/src/platforms/contracts.d.ts +402 -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 +98 -0
- package/dist/src/platforms/discovery.js +777 -0
- package/dist/src/platforms/discovery.js.map +1 -0
- package/dist/src/platforms/grok-permission-config.d.ts +23 -0
- package/dist/src/platforms/grok-permission-config.js +184 -0
- package/dist/src/platforms/grok-permission-config.js.map +1 -0
- package/dist/src/platforms/grok-permission-document.d.ts +4 -0
- package/dist/src/platforms/grok-permission-document.js +145 -0
- package/dist/src/platforms/grok-permission-document.js.map +1 -0
- package/dist/src/platforms/grok-permissions.d.ts +17 -0
- package/dist/src/platforms/grok-permissions.js +311 -0
- package/dist/src/platforms/grok-permissions.js.map +1 -0
- package/dist/src/platforms/host-permission-policy.d.ts +38 -0
- package/dist/src/platforms/host-permission-policy.js +86 -0
- package/dist/src/platforms/host-permission-policy.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 +366 -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 +373 -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 +9 -0
- package/dist/src/platforms/inspection-pi.js +482 -0
- package/dist/src/platforms/inspection-pi.js.map +1 -0
- package/dist/src/platforms/inspection-query.d.ts +24 -0
- package/dist/src/platforms/inspection-query.js +119 -0
- package/dist/src/platforms/inspection-query.js.map +1 -0
- package/dist/src/platforms/inspection.d.ts +20 -0
- package/dist/src/platforms/inspection.js +259 -0
- package/dist/src/platforms/inspection.js.map +1 -0
- package/dist/src/platforms/layout.d.ts +35 -0
- package/dist/src/platforms/layout.js +317 -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 +14 -0
- package/dist/src/platforms/lifecycle-native.js +223 -0
- package/dist/src/platforms/lifecycle-native.js.map +1 -0
- package/dist/src/platforms/lifecycle.d.ts +27 -0
- package/dist/src/platforms/lifecycle.js +567 -0
- package/dist/src/platforms/lifecycle.js.map +1 -0
- package/dist/src/platforms/opencode-permission-config.d.ts +13 -0
- package/dist/src/platforms/opencode-permission-config.js +253 -0
- package/dist/src/platforms/opencode-permission-config.js.map +1 -0
- package/dist/src/platforms/opencode-permissions.d.ts +39 -0
- package/dist/src/platforms/opencode-permissions.js +212 -0
- package/dist/src/platforms/opencode-permissions.js.map +1 -0
- package/dist/src/platforms/opencode-related-permissions.d.ts +40 -0
- package/dist/src/platforms/opencode-related-permissions.js +177 -0
- package/dist/src/platforms/opencode-related-permissions.js.map +1 -0
- package/dist/src/platforms/permission-ownership.d.ts +89 -0
- package/dist/src/platforms/permission-ownership.js +543 -0
- package/dist/src/platforms/permission-ownership.js.map +1 -0
- package/dist/src/platforms/permission-sidecar.d.ts +70 -0
- package/dist/src/platforms/permission-sidecar.js +215 -0
- package/dist/src/platforms/permission-sidecar.js.map +1 -0
- package/dist/src/platforms/projection-code-extension.d.ts +8 -0
- package/dist/src/platforms/projection-code-extension.js +126 -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 +13 -0
- package/dist/src/platforms/projection.js +576 -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 +20 -0
- package/dist/src/platforms/supplement-layout.js +53 -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 +93 -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 +99 -345
- 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 +29 -1
- package/dist/src/portable/materializer.js +197 -258
- 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 +176 -0
- package/dist/src/portable/recovery.js +556 -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 +168 -0
- package/dist/src/recovery/coordinator.js +1558 -0
- package/dist/src/recovery/coordinator.js.map +1 -0
- package/dist/src/recovery/demand.d.ts +53 -0
- package/dist/src/recovery/demand.js +189 -0
- package/dist/src/recovery/demand.js.map +1 -0
- package/dist/src/recovery/install-concurrency.d.ts +48 -0
- package/dist/src/recovery/install-concurrency.js +196 -0
- package/dist/src/recovery/install-concurrency.js.map +1 -0
- package/dist/src/recovery/interruption.d.ts +19 -0
- package/dist/src/recovery/interruption.js +43 -0
- package/dist/src/recovery/interruption.js.map +1 -0
- package/dist/src/recovery/joint-coordinator.d.ts +46 -0
- package/dist/src/recovery/joint-coordinator.js +1641 -0
- package/dist/src/recovery/joint-coordinator.js.map +1 -0
- package/dist/src/recovery/joint-demand.d.ts +72 -0
- package/dist/src/recovery/joint-demand.js +332 -0
- package/dist/src/recovery/joint-demand.js.map +1 -0
- package/dist/src/recovery/joint-install-execution.d.ts +19 -0
- package/dist/src/recovery/joint-install-execution.js +308 -0
- package/dist/src/recovery/joint-install-execution.js.map +1 -0
- package/dist/src/recovery/joint-install-native-rebase.d.ts +4 -0
- package/dist/src/recovery/joint-install-native-rebase.js +67 -0
- package/dist/src/recovery/joint-install-native-rebase.js.map +1 -0
- package/dist/src/recovery/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 +129 -0
- package/dist/src/recovery/receipt.js +91 -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 +463 -0
- package/dist/src/recovery/retirement.js.map +1 -0
- package/dist/src/recovery/status.d.ts +143 -0
- package/dist/src/recovery/status.js +1517 -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 +44 -0
- package/dist/src/review/eval-source-input.js +213 -0
- package/dist/src/review/eval-source-input.js.map +1 -0
- package/dist/src/review/platform-profile.d.ts +6 -0
- package/dist/src/review/platform-profile.js +24 -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 +502 -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 +65 -0
- package/dist/src/review/skill-materialization.js +228 -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 +782 -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 +8 -16
- package/dist/src/tui/catalog-generation.js +97 -10
- 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 -34
- package/dist/src/tui/components.js.map +1 -1
- package/dist/src/tui/config-array-draft.d.ts +30 -0
- package/dist/src/tui/config-array-draft.js +51 -0
- package/dist/src/tui/config-array-draft.js.map +1 -0
- package/dist/src/tui/config-leaf-editor.d.ts +44 -0
- package/dist/src/tui/config-leaf-editor.js +227 -0
- package/dist/src/tui/config-leaf-editor.js.map +1 -0
- package/dist/src/tui/config-object-suggestions.d.ts +15 -0
- package/dist/src/tui/config-object-suggestions.js +71 -0
- package/dist/src/tui/config-object-suggestions.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-suggestions.d.ts +27 -0
- package/dist/src/tui/config-suggestions.js +62 -0
- package/dist/src/tui/config-suggestions.js.map +1 -0
- package/dist/src/tui/config-value-presentation.d.ts +21 -0
- package/dist/src/tui/config-value-presentation.js +129 -0
- package/dist/src/tui/config-value-presentation.js.map +1 -0
- package/dist/src/tui/console-app-v4.d.ts +14 -5
- package/dist/src/tui/console-app-v4.js +10344 -2133
- 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 +8 -3
- package/dist/src/tui/controller-runtime.js +2301 -842
- package/dist/src/tui/controller-runtime.js.map +1 -1
- package/dist/src/tui/controller.d.ts +664 -79
- package/dist/src/tui/controller.js +3670 -830
- 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 +13 -0
- package/dist/src/tui/deployment-view.js +155 -0
- package/dist/src/tui/deployment-view.js.map +1 -0
- package/dist/src/tui/diagnostic-projection.d.ts +31 -0
- package/dist/src/tui/diagnostic-projection.js +681 -0
- package/dist/src/tui/diagnostic-projection.js.map +1 -0
- package/dist/src/tui/diagnostics.d.ts +6 -2
- 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 +56 -0
- package/dist/src/tui/entity-cards.js +321 -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 +78 -0
- package/dist/src/tui/glossary.js.map +1 -0
- package/dist/src/tui/guided-setup.d.ts +25 -0
- package/dist/src/tui/guided-setup.js +101 -0
- package/dist/src/tui/guided-setup.js.map +1 -0
- package/dist/src/tui/index.d.ts +5 -1
- package/dist/src/tui/index.js +4 -1
- 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 +187 -52
- package/dist/src/tui/model.js +1202 -426
- 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 +76 -0
- package/dist/src/tui/operation-diagnostic-screens.js.map +1 -0
- package/dist/src/tui/operation-history.d.ts +91 -0
- package/dist/src/tui/operation-history.js +167 -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 +1456 -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 +75 -0
- package/dist/src/tui/plugin-detail.js +267 -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 +182 -39
- 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 +49 -0
- package/dist/src/tui/scoped-flow.js +212 -0
- package/dist/src/tui/scoped-flow.js.map +1 -0
- package/dist/src/tui/scoped-inventory.d.ts +131 -0
- package/dist/src/tui/scoped-inventory.js +280 -0
- package/dist/src/tui/scoped-inventory.js.map +1 -0
- package/dist/src/tui/screen-registry.d.ts +696 -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 +8 -0
- package/dist/src/tui/session-console-app.js +24 -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 +177 -85
- package/dist/src/types.js +1 -0
- package/dist/src/types.js.map +1 -1
- package/dist/src/utils/agent-version.d.ts +10 -4
- package/dist/src/utils/agent-version.js +6 -8
- package/dist/src/utils/agent-version.js.map +1 -1
- package/dist/src/utils/artifact-plan.d.ts +17 -24
- package/dist/src/utils/artifact-plan.js +59 -436
- package/dist/src/utils/artifact-plan.js.map +1 -1
- package/dist/src/utils/artifact-renderer.d.ts +61 -89
- package/dist/src/utils/artifact-renderer.js +187 -364
- package/dist/src/utils/artifact-renderer.js.map +1 -1
- package/dist/src/utils/artifact-request.d.ts +21 -0
- package/dist/src/utils/artifact-request.js +57 -0
- package/dist/src/utils/artifact-request.js.map +1 -0
- package/dist/src/utils/artifact-sources.d.ts +4 -8
- package/dist/src/utils/artifact-sources.js +15 -6
- package/dist/src/utils/artifact-sources.js.map +1 -1
- package/dist/src/utils/aw-home-mutation-lock.js +2 -1
- package/dist/src/utils/aw-home-mutation-lock.js.map +1 -1
- package/dist/src/utils/bundle-layout.js +59 -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 -9
- package/dist/src/utils/catalog-digests.js +7 -45
- package/dist/src/utils/catalog-digests.js.map +1 -1
- package/dist/src/utils/catalog-generation-error.d.ts +4 -1
- package/dist/src/utils/catalog-generation-error.js +2 -0
- package/dist/src/utils/catalog-generation-error.js.map +1 -1
- package/dist/src/utils/catalog-generation-resolver.d.ts +32 -3
- package/dist/src/utils/catalog-generation-resolver.js +182 -40
- package/dist/src/utils/catalog-generation-resolver.js.map +1 -1
- package/dist/src/utils/catalog-generation-service.d.ts +142 -2
- package/dist/src/utils/catalog-generation-service.js +1146 -171
- package/dist/src/utils/catalog-generation-service.js.map +1 -1
- package/dist/src/utils/catalog-generation-state.d.ts +5 -0
- package/dist/src/utils/catalog-generation-state.js +25 -1
- package/dist/src/utils/catalog-generation-state.js.map +1 -1
- package/dist/src/utils/catalog-generation-store.d.ts +29 -2
- package/dist/src/utils/catalog-generation-store.js +240 -36
- 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-v6.js → catalog-manifest-v7.js} +23 -23
- package/dist/src/utils/{catalog-manifest-v6.js.map → catalog-manifest-v7.js.map} +1 -1
- package/dist/src/utils/catalog-operation-context.d.ts +27 -3
- package/dist/src/utils/catalog-operation-context.js +75 -4
- package/dist/src/utils/catalog-operation-context.js.map +1 -1
- package/dist/src/utils/catalog-public-error.js +7 -0
- package/dist/src/utils/catalog-public-error.js.map +1 -1
- package/dist/src/utils/catalog-runtime-projection.d.ts +4 -3
- package/dist/src/utils/catalog-runtime-projection.js.map +1 -1
- package/dist/src/utils/catalog-snapshot.d.ts +5 -2
- package/dist/src/utils/catalog-snapshot.js +4 -1
- package/dist/src/utils/catalog-snapshot.js.map +1 -1
- 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 +22 -8
- package/dist/src/utils/catalog-source-references.js +457 -365
- 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 +155 -11
- package/dist/src/utils/catalog-sources.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 +23 -42
- package/dist/src/utils/codex-manager.js +79 -767
- 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 +55 -0
- package/dist/src/utils/codex-native-observation.js +198 -0
- package/dist/src/utils/codex-native-observation.js.map +1 -0
- package/dist/src/utils/codex-reconciler.d.ts +6 -14
- package/dist/src/utils/codex-reconciler.js +45 -50
- package/dist/src/utils/codex-reconciler.js.map +1 -1
- package/dist/src/utils/codex-shared-native.d.ts +28 -39
- package/dist/src/utils/codex-shared-native.js +92 -57
- package/dist/src/utils/codex-shared-native.js.map +1 -1
- package/dist/src/utils/codex-skill-staging.d.ts +4 -3
- package/dist/src/utils/codex-skill-staging.js.map +1 -1
- package/dist/src/utils/codex-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 +8 -3
- package/dist/src/utils/codex-surface-analysis.js +35 -62
- package/dist/src/utils/codex-surface-analysis.js.map +1 -1
- package/dist/src/utils/component-command-preparation.d.ts +31 -0
- package/dist/src/utils/component-command-preparation.js +127 -0
- package/dist/src/utils/component-command-preparation.js.map +1 -0
- package/dist/src/utils/component-gap.d.ts +4 -0
- package/dist/src/utils/component-gap.js +20 -0
- package/dist/src/utils/component-gap.js.map +1 -0
- package/dist/src/utils/component-resources.d.ts +51 -0
- package/dist/src/utils/component-resources.js +320 -0
- package/dist/src/utils/component-resources.js.map +1 -0
- package/dist/src/utils/config-platforms.d.ts +21 -0
- package/dist/src/utils/config-platforms.js +51 -0
- package/dist/src/utils/config-platforms.js.map +1 -0
- package/dist/src/utils/dynamic-skill-tree.d.ts +18 -6
- package/dist/src/utils/dynamic-skill-tree.js +33 -40
- 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 +112 -6
- 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-cli-review.d.ts +53 -0
- package/dist/src/utils/managed-command-cli-review.js +431 -0
- package/dist/src/utils/managed-command-cli-review.js.map +1 -0
- package/dist/src/utils/managed-command-closure.d.ts +14 -0
- package/dist/src/utils/managed-command-closure.js +156 -0
- package/dist/src/utils/managed-command-closure.js.map +1 -0
- package/dist/src/utils/managed-command-errors.d.ts +5 -0
- package/dist/src/utils/managed-command-errors.js +10 -0
- package/dist/src/utils/managed-command-errors.js.map +1 -0
- package/dist/src/utils/managed-command-materialization.d.ts +90 -0
- package/dist/src/utils/managed-command-materialization.js +375 -0
- package/dist/src/utils/managed-command-materialization.js.map +1 -0
- package/dist/src/utils/managed-command-preparation.d.ts +30 -0
- package/dist/src/utils/managed-command-preparation.js +39 -0
- package/dist/src/utils/managed-command-preparation.js.map +1 -0
- package/dist/src/utils/managed-command-review.d.ts +33 -0
- package/dist/src/utils/managed-command-review.js +80 -0
- package/dist/src/utils/managed-command-review.js.map +1 -0
- package/dist/src/utils/managed-command-runtime.d.ts +36 -0
- package/dist/src/utils/managed-command-runtime.js +126 -0
- package/dist/src/utils/managed-command-runtime.js.map +1 -0
- package/dist/src/utils/managed-command-snapshots.d.ts +24 -0
- package/dist/src/utils/managed-command-snapshots.js +89 -0
- package/dist/src/utils/managed-command-snapshots.js.map +1 -0
- package/dist/src/utils/managed-command-store.d.ts +141 -0
- package/dist/src/utils/managed-command-store.js +839 -0
- package/dist/src/utils/managed-command-store.js.map +1 -0
- package/dist/src/utils/multi-source-catalog.d.ts +4 -0
- package/dist/src/utils/multi-source-catalog.js +7 -3
- package/dist/src/utils/multi-source-catalog.js.map +1 -1
- package/dist/src/utils/native-cli-interruption.d.ts +8 -0
- package/dist/src/utils/native-cli-interruption.js +65 -0
- package/dist/src/utils/native-cli-interruption.js.map +1 -0
- package/dist/src/utils/native-cli.d.ts +37 -6
- package/dist/src/utils/native-cli.js +523 -60
- 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 +17 -0
- package/dist/src/utils/native-tool-context.js +40 -0
- package/dist/src/utils/native-tool-context.js.map +1 -0
- package/dist/src/utils/native-tool-review.d.ts +8 -0
- package/dist/src/utils/native-tool-review.js +14 -0
- package/dist/src/utils/native-tool-review.js.map +1 -0
- package/dist/src/utils/orphan-marketplace-cleanup.js +0 -2
- package/dist/src/utils/orphan-marketplace-cleanup.js.map +1 -1
- package/dist/src/utils/ownership.d.ts +111 -11
- package/dist/src/utils/ownership.js +247 -126
- package/dist/src/utils/ownership.js.map +1 -1
- package/dist/src/utils/package-content.d.ts +7 -0
- package/dist/src/utils/package-content.js +70 -0
- package/dist/src/utils/package-content.js.map +1 -0
- package/dist/src/utils/path-catalog-provider.js +2 -0
- package/dist/src/utils/path-catalog-provider.js.map +1 -1
- package/dist/src/utils/paths.d.ts +1 -1
- package/dist/src/utils/paths.js +5 -2
- package/dist/src/utils/paths.js.map +1 -1
- package/dist/src/utils/platform-empty-state.d.ts +69 -0
- package/dist/src/utils/platform-empty-state.js +226 -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-command-apply.d.ts +33 -0
- package/dist/src/utils/plugin-config-command-apply.js +142 -0
- package/dist/src/utils/plugin-config-command-apply.js.map +1 -0
- package/dist/src/utils/plugin-config-diagnostics.d.ts +16 -0
- package/dist/src/utils/plugin-config-diagnostics.js +44 -0
- package/dist/src/utils/plugin-config-diagnostics.js.map +1 -0
- package/dist/src/utils/plugin-config-impact.d.ts +75 -0
- package/dist/src/utils/plugin-config-impact.js +355 -0
- package/dist/src/utils/plugin-config-impact.js.map +1 -0
- package/dist/src/utils/plugin-config-references.d.ts +96 -0
- package/dist/src/utils/plugin-config-references.js +357 -0
- package/dist/src/utils/plugin-config-references.js.map +1 -0
- package/dist/src/utils/plugin-config-suggestion-runner.d.ts +83 -0
- package/dist/src/utils/plugin-config-suggestion-runner.js +308 -0
- package/dist/src/utils/plugin-config-suggestion-runner.js.map +1 -0
- package/dist/src/utils/plugin-config-suggestions.d.ts +50 -0
- package/dist/src/utils/plugin-config-suggestions.js +302 -0
- package/dist/src/utils/plugin-config-suggestions.js.map +1 -0
- package/dist/src/utils/plugin-config-write.d.ts +123 -31
- package/dist/src/utils/plugin-config-write.js +828 -399
- package/dist/src/utils/plugin-config-write.js.map +1 -1
- package/dist/src/utils/plugin-config.d.ts +192 -109
- package/dist/src/utils/plugin-config.js +970 -1150
- 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 +80 -127
- package/dist/src/utils/plugin-scripts.js +655 -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 +24 -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/skill-invocation-warning.d.ts +20 -0
- package/dist/src/utils/skill-invocation-warning.js +68 -0
- package/dist/src/utils/skill-invocation-warning.js.map +1 -0
- package/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 +3 -3
- package/dist/src/utils/target-eligibility.js +11 -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 +106 -9
- package/dist/vitest.config.js.map +1 -1
- package/package.json +30 -21
- 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/sync-command.d.ts +0 -21
- package/dist/src/commands/sync-command.js +0 -206
- package/dist/src/commands/sync-command.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-v6.d.ts +0 -5
- 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-intent-state.d.ts +0 -39
- package/dist/src/utils/plugin-intent-state.js +0 -325
- package/dist/src/utils/plugin-intent-state.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,39 +1,82 @@
|
|
|
1
1
|
import crypto from 'node:crypto';
|
|
2
|
-
import os from 'node:os';
|
|
3
2
|
import path from 'node:path';
|
|
3
|
+
import { catalogFileMode } from '@lesliechan721/aw-plugin-core';
|
|
4
4
|
import fs from 'fs-extra';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
5
|
+
import { ManagedCommandError } from '../utils/managed-command-store.js';
|
|
6
|
+
import { prepareLifecycleCommandPackage, publishLifecycleCommandPackages, retainedManagedCommandPackageResult } from './lifecycle-command-package.js';
|
|
7
|
+
import { readClaudeSettings, writeClaudeSettings } from '../adapters/helpers.js';
|
|
8
8
|
import { buildGeneratedName } from '../generators/shared.js';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
9
|
+
import { readCatalogSourcesConfigSnapshot } from '../utils/catalog-sources.js';
|
|
10
|
+
import { applyCodexConfigTransactionFile, applyConditionalCodexConfigTransactionFile, readCodexConfigFile } from '../utils/codex-config.js';
|
|
11
|
+
import { isSafeCodexMarketplaceRoot } from '../utils/codex-marketplace-path.js';
|
|
12
|
+
import { createCodexNativeObservationSession, } from '../utils/codex-native-observation.js';
|
|
13
|
+
import { inspectCodexSharedNative, isCanonicalCodexMarketplaceRegistration, } from '../utils/codex-shared-native.js';
|
|
14
|
+
import { validateSkillDirectory } from '../utils/dynamic-skill-tree.js';
|
|
13
15
|
import { parseCodexSharedHooksFile, serializeTrackedHookGroupIdentity, } from '../utils/hooks-contract.js';
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import { createAwPluginRequirementsReceipt, readPluginManifest, } from '../utils/manifest.js';
|
|
19
|
-
import { resolvePlatformEntries } from '../utils/platform-entries.js';
|
|
20
|
-
import { resolveAwHome, resolveClaudePaths, resolveCodexPaths, resolveRepoRoot, getCodexHome, } from '../utils/paths.js';
|
|
21
|
-
import { runLifecycleScript } from '../utils/plugin-scripts.js';
|
|
16
|
+
import { assertSafeNamespacedMarketplacePluginRoot, readStrictNamespacedMarketplaceRoot } from '../utils/local-marketplace.js';
|
|
17
|
+
import { buildCodexMarketplaceRemoveInvocation, buildCodexPluginRemoveInvocation, CodexProjectConfigNotEffectiveError, runNativeCliChecked, SYSTEM_CODEX_MANAGER } from '../utils/native-cli.js';
|
|
18
|
+
import { inspectOwnedComponents, OWNED_TEXT_HEADER_PREFIX, parseOwnedTextHeader, parseSharedOwnerToken, readSkillOwnerMarker } from '../utils/ownership.js';
|
|
19
|
+
import { resolveAwHome, resolveClaudePaths, resolveCodexPaths, resolveRepoRoot } from '../utils/paths.js';
|
|
22
20
|
import { atomicRemoveConfigFile, atomicReplaceConfigFile, withConfigFileMutation, } from '../utils/plugin-config.js';
|
|
23
|
-
import {
|
|
24
|
-
import { getNamespacedMarketplaceName, projectMarketplaceManifestForPlatform, replayNamespacedCodexSkillOverlays, } from '../utils/local-marketplace.js';
|
|
25
|
-
import { cleanupOrphanNamespacedMarketplaceRoot, commitMarketplaceGenerationBackup, } from '../utils/orphan-marketplace-cleanup.js';
|
|
26
|
-
import { readClaudeSettings, writeClaudeSettings } from '../adapters/helpers.js';
|
|
27
|
-
import { analyzeCodexSurface } from '../utils/codex-surface-analysis.js';
|
|
28
|
-
import { inspectCodexSharedNative, } from '../utils/codex-shared-native.js';
|
|
29
|
-
import { calculateCodexSharedNativePayloadDigest } from '../utils/catalog-digests.js';
|
|
21
|
+
import { runPreApplyScript } from '../utils/plugin-scripts.js';
|
|
30
22
|
import { assertCanonicalProjectManagedRoots } from '../utils/project-boundary.js';
|
|
31
|
-
import {
|
|
23
|
+
import { attachSafeOperationError, readSafeOperationError } from '../utils/safe-operation-diagnostic.js';
|
|
24
|
+
import { createProjectLocationKey, resolveRequiredCanonicalRepoRoot, resolveClaudeProjectKey, resolveCodexProjectKey } from '../utils/state-paths.js';
|
|
25
|
+
import { hasPermissionOwner, updateHostPermissions } from '../platforms/permission-ownership.js';
|
|
26
|
+
import { resolvePlatformConfigRoot } from '../platforms/discovery.js';
|
|
27
|
+
import { canonicalNamespaceRoot } from '../platforms/identity.js';
|
|
28
|
+
import { getManagedPlatformRoot } from '../platforms/layout.js';
|
|
29
|
+
import { platformOwnership, PlatformRebuildSession } from './rebuild-platform-integration.js';
|
|
32
30
|
const MARKETPLACE_NAME = 'aw';
|
|
33
31
|
const LEGACY_MCP_OWNER_ENV = 'AW_AGENT_WORKFLOWS_OWNER';
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
const platformRebuildSessions = new WeakMap();
|
|
33
|
+
const commandPackageCandidates = new WeakMap();
|
|
34
|
+
export function finalizePreparedPlatformRebuildSession(results) {
|
|
35
|
+
for (const session of platformRebuildSessions.get(results)?.values() ?? [])
|
|
36
|
+
session.freezeMarketplaceCandidates();
|
|
37
|
+
}
|
|
38
|
+
export function recordPreparedGrokProjectRetirement(results, ...retirement) {
|
|
39
|
+
const sessions = platformRebuildSessions.get(results);
|
|
40
|
+
sessions?.get('grok')?.recordGrokProjectRetirement(...retirement);
|
|
41
|
+
sessions?.get(undefined)?.recordGrokProjectRetirement(...retirement);
|
|
42
|
+
}
|
|
43
|
+
export async function disposePreparedPlatformRebuildSession(results) {
|
|
44
|
+
const sessions = platformRebuildSessions.get(results);
|
|
45
|
+
platformRebuildSessions.delete(results);
|
|
46
|
+
const packages = commandPackageCandidates.get(results);
|
|
47
|
+
commandPackageCandidates.delete(results);
|
|
48
|
+
try {
|
|
49
|
+
await Promise.all([...(sessions?.values() ?? [])].map((session) => session.dispose()));
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
if (packages)
|
|
53
|
+
await Promise.all([...packages.values()].map(async (candidate) => {
|
|
54
|
+
const prepared = await candidate.catch(() => undefined);
|
|
55
|
+
await prepared?.cleanup();
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export class CodexActivationPostcheckError extends Error {
|
|
60
|
+
code = 'codexActivationPostcheckFailed';
|
|
61
|
+
codexPluginIds;
|
|
62
|
+
constructor(codexPluginIds, detail) {
|
|
63
|
+
super(`codexActivationPostcheckFailed: ${detail}`);
|
|
64
|
+
this.name = 'CodexActivationPostcheckError';
|
|
65
|
+
this.codexPluginIds = [...new Set(typeof codexPluginIds === 'string' ? [codexPluginIds] : codexPluginIds)];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function codexObservationScope(context, marketplaceName, fallbackScope) {
|
|
69
|
+
return context.codexObservationScopeByMarketplace?.get(marketplaceName)
|
|
70
|
+
?? (fallbackScope === 'user' ? 'user' : 'both');
|
|
71
|
+
}
|
|
72
|
+
function codexMarketplaceFromPluginId(pluginId) {
|
|
73
|
+
return pluginId.slice(pluginId.lastIndexOf('@') + 1);
|
|
74
|
+
}
|
|
75
|
+
function requireCodexObservationCoverage(registration, scope, operation) {
|
|
76
|
+
if (!registration.observations.user
|
|
77
|
+
|| (scope === 'both' && !registration.observations.project)) {
|
|
78
|
+
throw new Error(`codexNativeObservationUnavailable: ${operation} requires ${scope === 'user' ? 'neutral' : 'exact and neutral'} Codex plugin list evidence.`);
|
|
79
|
+
}
|
|
37
80
|
}
|
|
38
81
|
function requireCodexManager(manager) {
|
|
39
82
|
if (!manager) {
|
|
@@ -41,12 +84,25 @@ function requireCodexManager(manager) {
|
|
|
41
84
|
}
|
|
42
85
|
return manager;
|
|
43
86
|
}
|
|
44
|
-
|
|
87
|
+
async function runCodexMutationWithInvalidation(options) {
|
|
88
|
+
try {
|
|
89
|
+
return await options.mutation();
|
|
90
|
+
}
|
|
91
|
+
finally {
|
|
92
|
+
options.observationSession?.invalidate(options.marketplaceName);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async function executeCodexReconcileActivationsInSession(options) {
|
|
45
96
|
const byScope = {
|
|
46
97
|
user: { upserts: {}, removals: new Set() },
|
|
47
98
|
project: { upserts: {}, removals: new Set() },
|
|
48
99
|
};
|
|
49
100
|
for (const plan of options.plans) {
|
|
101
|
+
const rewrittenPluginIds = new Set(plan.sharedNativeActions
|
|
102
|
+
.filter((action) => action.action === 'install'
|
|
103
|
+
|| action.action === 'replace'
|
|
104
|
+
|| action.action === 'repair')
|
|
105
|
+
.map((action) => action.codexPluginId));
|
|
50
106
|
for (const scope of ['user', 'project']) {
|
|
51
107
|
for (const action of plan.activationActions[scope]) {
|
|
52
108
|
if (action.action === 'enable' || action.action === 'disable') {
|
|
@@ -56,6 +112,11 @@ export async function executeCodexReconcileActivations(options) {
|
|
|
56
112
|
else if (action.action === 'remove') {
|
|
57
113
|
byScope[scope].removals.add(action.codexPluginId);
|
|
58
114
|
}
|
|
115
|
+
else if (rewrittenPluginIds.has(action.codexPluginId)
|
|
116
|
+
&& (action.desired || scope === 'user')) {
|
|
117
|
+
byScope[scope].upserts[action.codexPluginId] = action.desired;
|
|
118
|
+
byScope[scope].removals.delete(action.codexPluginId);
|
|
119
|
+
}
|
|
59
120
|
}
|
|
60
121
|
}
|
|
61
122
|
for (const removal of plan.staleActivationRemovals) {
|
|
@@ -64,18 +125,53 @@ export async function executeCodexReconcileActivations(options) {
|
|
|
64
125
|
}
|
|
65
126
|
}
|
|
66
127
|
}
|
|
128
|
+
const recordActivationMutations = (pluginIds) => {
|
|
129
|
+
if (!options.mutationMarketplaces)
|
|
130
|
+
return;
|
|
131
|
+
for (const pluginId of pluginIds) {
|
|
132
|
+
options.mutationMarketplaces.add(pluginId.slice(pluginId.lastIndexOf('@') + 1));
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
const observedActivationPluginIds = [...new Set(options.plans.flatMap((plan) => plan.postcheck.support === 'observed'
|
|
136
|
+
? plan.postcheck.plugins.map((plugin) => plugin.codexPluginId)
|
|
137
|
+
: []))];
|
|
138
|
+
if (!options.preflightCompleted && observedActivationPluginIds.length > 0) {
|
|
139
|
+
const manager = requireCodexManager(options.manager);
|
|
140
|
+
for (const pluginId of observedActivationPluginIds) {
|
|
141
|
+
const marketplaceName = codexMarketplaceFromPluginId(pluginId);
|
|
142
|
+
const observationScope = options.observationScopeByMarketplace?.get(marketplaceName)
|
|
143
|
+
?? (options.plans.some((plan) => plan.requirement.scope === 'project')
|
|
144
|
+
? 'both'
|
|
145
|
+
: 'user');
|
|
146
|
+
const registration = await inspectCodexPluginRegistrationLive({
|
|
147
|
+
pluginId,
|
|
148
|
+
cwd: options.cwd,
|
|
149
|
+
env: options.env,
|
|
150
|
+
nativeCliRunner: options.runner,
|
|
151
|
+
manager,
|
|
152
|
+
scope: observationScope,
|
|
153
|
+
observationSession: options.observationSession,
|
|
154
|
+
});
|
|
155
|
+
const observedState = requireObservedCodexNativeState(registration.observation, 'activation precheck');
|
|
156
|
+
requireCodexObservationCoverage(registration, observationScope, 'activation precheck');
|
|
157
|
+
if (observedState !== 'installed') {
|
|
158
|
+
throw new Error('codexNativeObservationFailed: activation precheck did not observe the installed Codex plugin.');
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
67
162
|
for (const scope of ['user', 'project']) {
|
|
68
163
|
const enables = Object.fromEntries(Object.entries(byScope[scope].upserts)
|
|
69
164
|
.filter(([, desired]) => desired));
|
|
70
165
|
if (Object.keys(enables).length === 0)
|
|
71
166
|
continue;
|
|
72
167
|
const configPath = resolveCodexPaths(options.cwd, scope, options.env).configTomlPath;
|
|
73
|
-
await applyCodexConfigTransactionFile(configPath, { upsertPluginActivations: enables });
|
|
168
|
+
const update = await applyCodexConfigTransactionFile(configPath, { upsertPluginActivations: enables });
|
|
169
|
+
if (update.wrote)
|
|
170
|
+
recordActivationMutations(Object.keys(enables));
|
|
74
171
|
const enabledConfig = await readCodexConfigFile(configPath);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
172
|
+
const missingEnables = Object.keys(enables).filter((pluginId) => enabledConfig.snapshot.plugins[pluginId]?.enabled !== true);
|
|
173
|
+
if (missingEnables.length > 0) {
|
|
174
|
+
throw new CodexActivationPostcheckError(missingEnables, `${missingEnables.join(', ')} ${scope} activation was not enabled before obsolete activation removal.`);
|
|
79
175
|
}
|
|
80
176
|
}
|
|
81
177
|
for (const scope of ['user', 'project']) {
|
|
@@ -84,7 +180,7 @@ export async function executeCodexReconcileActivations(options) {
|
|
|
84
180
|
.filter(([, desired]) => !desired));
|
|
85
181
|
if (Object.keys(disables).length === 0 && transaction.removals.size === 0)
|
|
86
182
|
continue;
|
|
87
|
-
await applyCodexConfigTransactionFile(resolveCodexPaths(options.cwd, scope, options.env).configTomlPath, {
|
|
183
|
+
const update = await applyCodexConfigTransactionFile(resolveCodexPaths(options.cwd, scope, options.env).configTomlPath, {
|
|
88
184
|
...(transaction.removals.size > 0
|
|
89
185
|
? { removePluginActivations: [...transaction.removals].sort() }
|
|
90
186
|
: {}),
|
|
@@ -92,11 +188,19 @@ export async function executeCodexReconcileActivations(options) {
|
|
|
92
188
|
? { upsertPluginActivations: disables }
|
|
93
189
|
: {}),
|
|
94
190
|
});
|
|
191
|
+
if (update.wrote) {
|
|
192
|
+
recordActivationMutations([
|
|
193
|
+
...Object.keys(disables),
|
|
194
|
+
...transaction.removals,
|
|
195
|
+
]);
|
|
196
|
+
}
|
|
95
197
|
}
|
|
96
198
|
const [userConfig, projectConfig] = await Promise.all([
|
|
97
199
|
readCodexConfigFile(resolveCodexPaths(options.cwd, 'user', options.env).configTomlPath),
|
|
98
200
|
readCodexConfigFile(resolveCodexPaths(options.cwd, 'project', options.env).configTomlPath),
|
|
99
201
|
]);
|
|
202
|
+
const configMismatchIds = [];
|
|
203
|
+
const configMismatchDetails = [];
|
|
100
204
|
for (const plan of options.plans) {
|
|
101
205
|
for (const scope of ['user', 'project']) {
|
|
102
206
|
const snapshot = scope === 'user' ? userConfig.snapshot : projectConfig.snapshot;
|
|
@@ -106,116 +210,121 @@ export async function executeCodexReconcileActivations(options) {
|
|
|
106
210
|
? true
|
|
107
211
|
: action.action === 'disable' || actual === false ? false : undefined;
|
|
108
212
|
if (actual !== expected) {
|
|
109
|
-
|
|
213
|
+
configMismatchIds.push(action.codexPluginId);
|
|
214
|
+
configMismatchDetails.push(`${action.codexPluginId} ${scope} activation is ${String(actual)}; expected ${String(expected)}.`);
|
|
110
215
|
}
|
|
111
216
|
}
|
|
112
217
|
for (const removal of plan.staleActivationRemovals.filter((entry) => entry.scope === scope)) {
|
|
113
218
|
if (snapshot.plugins[removal.codexPluginId]?.enabled !== undefined) {
|
|
114
|
-
|
|
219
|
+
configMismatchIds.push(removal.codexPluginId);
|
|
220
|
+
configMismatchDetails.push(`stale ${removal.codexPluginId} ${scope} activation remains.`);
|
|
115
221
|
}
|
|
116
222
|
}
|
|
117
223
|
}
|
|
118
224
|
}
|
|
119
|
-
|
|
120
|
-
|
|
225
|
+
if (configMismatchIds.length > 0) {
|
|
226
|
+
throw new CodexActivationPostcheckError(configMismatchIds, configMismatchDetails.join(' '));
|
|
227
|
+
}
|
|
228
|
+
const observedActivationChecks = options.plans.flatMap((plan) => plan.postcheck.support === 'observed'
|
|
229
|
+
? plan.postcheck.plugins
|
|
121
230
|
: []);
|
|
122
|
-
if (
|
|
231
|
+
if (observedActivationChecks.length === 0)
|
|
123
232
|
return;
|
|
124
|
-
const
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
const
|
|
233
|
+
const ineffectivePlugins = [];
|
|
234
|
+
const ineffectiveDetails = [];
|
|
235
|
+
for (const plugin of observedActivationChecks) {
|
|
236
|
+
const userActive = userConfig.snapshot.plugins[plugin.codexPluginId]?.enabled === true;
|
|
237
|
+
const projectActive = projectConfig.snapshot.plugins[plugin.codexPluginId]?.enabled === true;
|
|
238
|
+
if ((userActive || projectActive) !== (plugin.expectedUserEnabled || plugin.expectedProjectEnabled)
|
|
239
|
+
|| userActive !== plugin.expectedUserEnabled) {
|
|
240
|
+
ineffectivePlugins.push(plugin.codexPluginId);
|
|
241
|
+
ineffectiveDetails.push(new CodexProjectConfigNotEffectiveError(plugin.codexPluginId).message);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (ineffectivePlugins.length > 0) {
|
|
245
|
+
throw new CodexActivationPostcheckError(ineffectivePlugins, ineffectiveDetails.join(' '));
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
export async function executeCodexReconcileActivations(options) {
|
|
249
|
+
const ownedSession = options.observationSession ? undefined
|
|
250
|
+
: await createCodexNativeObservationSession({
|
|
128
251
|
exactCwd: options.cwd,
|
|
129
|
-
neutralCwd,
|
|
130
252
|
env: options.env,
|
|
253
|
+
runner: options.runner,
|
|
254
|
+
manager: options.manager,
|
|
255
|
+
});
|
|
256
|
+
try {
|
|
257
|
+
await executeCodexReconcileActivationsInSession({
|
|
258
|
+
...options,
|
|
259
|
+
observationSession: options.observationSession ?? ownedSession,
|
|
131
260
|
});
|
|
132
|
-
const [exactResult, neutralResult] = await Promise.all([
|
|
133
|
-
runNativeCliChecked(invocations.exact, options.runner),
|
|
134
|
-
runNativeCliChecked(invocations.neutral, options.runner),
|
|
135
|
-
]);
|
|
136
|
-
for (const plugin of observedProjectChecks) {
|
|
137
|
-
postcheckCodexProjectPluginActivation({
|
|
138
|
-
pluginId: plugin.codexPluginId,
|
|
139
|
-
userEnabled: plugin.expectedUserEnabled,
|
|
140
|
-
projectEnabled: plugin.expectedProjectEnabled,
|
|
141
|
-
exactResult,
|
|
142
|
-
neutralResult,
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
261
|
}
|
|
146
262
|
finally {
|
|
147
|
-
await
|
|
263
|
+
await ownedSession?.dispose();
|
|
148
264
|
}
|
|
149
265
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
function pluginOwnerIdentity(plugin, artifactKey, platform, scope) {
|
|
155
|
-
return {
|
|
156
|
-
...ownerIdentity(plugin.manifest.name, artifactKey, platform, scope),
|
|
157
|
-
...(plugin.sourceId ? {
|
|
158
|
-
sourceId: plugin.sourceId,
|
|
159
|
-
sourceIdentity: plugin.sourceIdentity,
|
|
160
|
-
pluginId: plugin.pluginId,
|
|
161
|
-
} : {}),
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
function bindNamespacedOwnerIdentity(components, source) {
|
|
165
|
-
if (!source.sourceId)
|
|
266
|
+
export async function postcheckCodexReconcileActivations(options) {
|
|
267
|
+
const checks = options.plans.flatMap((plan) => plan.postcheck.support === 'observed' ? plan.postcheck.plugins : []);
|
|
268
|
+
if (checks.length === 0)
|
|
166
269
|
return;
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
270
|
+
const ownedSession = options.observationSession ? undefined
|
|
271
|
+
: await createCodexNativeObservationSession({
|
|
272
|
+
exactCwd: options.cwd,
|
|
273
|
+
env: options.env,
|
|
274
|
+
runner: options.runner,
|
|
275
|
+
manager: options.manager,
|
|
276
|
+
});
|
|
277
|
+
const session = options.observationSession ?? ownedSession;
|
|
278
|
+
try {
|
|
279
|
+
const failedPluginIds = [];
|
|
280
|
+
const failureDetails = [];
|
|
281
|
+
for (const check of checks) {
|
|
282
|
+
try {
|
|
283
|
+
const marketplaceName = codexMarketplaceFromPluginId(check.codexPluginId);
|
|
284
|
+
const observationScope = options.observationScopeByMarketplace?.get(marketplaceName)
|
|
285
|
+
?? (options.plans.some((plan) => plan.requirement.scope === 'project')
|
|
286
|
+
? 'both'
|
|
287
|
+
: 'user');
|
|
288
|
+
const registration = await inspectCodexPluginRegistrationLive({
|
|
289
|
+
pluginId: check.codexPluginId,
|
|
290
|
+
cwd: options.cwd,
|
|
291
|
+
env: options.env,
|
|
292
|
+
nativeCliRunner: options.runner,
|
|
293
|
+
manager: options.manager,
|
|
294
|
+
scope: observationScope,
|
|
295
|
+
observationSession: session,
|
|
296
|
+
});
|
|
297
|
+
const state = requireObservedCodexNativeState(registration.observation, 'activation postcheck');
|
|
298
|
+
requireCodexObservationCoverage(registration, observationScope, 'activation postcheck');
|
|
299
|
+
if (state !== 'installed') {
|
|
300
|
+
throw new Error(`codexNativeObservationFailed: ${check.codexPluginId} was not observed after Codex activation mutation.`);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
failedPluginIds.push(check.codexPluginId);
|
|
305
|
+
failureDetails.push(error instanceof Error ? error.message : String(error));
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
if (failedPluginIds.length > 0) {
|
|
309
|
+
throw new CodexActivationPostcheckError(failedPluginIds, failureDetails.join(' '));
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
finally {
|
|
313
|
+
await ownedSession?.dispose();
|
|
171
314
|
}
|
|
172
315
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
function pathComponent(options) {
|
|
177
|
-
if (options.kind !== 'skill-directory')
|
|
178
|
-
return options;
|
|
179
|
-
return {
|
|
180
|
-
...options,
|
|
181
|
-
validateHealth: async () => {
|
|
182
|
-
await validateSkillDirectory(options.path, options.identity.platform === 'codex' ? 'codex.skill' : 'claude.skill', { ownerMarkerPolicy: 'ignore', requirementsReceiptPolicy: 'allow' });
|
|
183
|
-
},
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
function generatedTextWrite(options) {
|
|
187
|
-
const artifactPath = path.join(options.configDir, options.relativePath);
|
|
188
|
-
const identity = ownerIdentity(options.plugin.manifest.name, options.artifactKey, options.platform, options.scope);
|
|
189
|
-
const component = pathComponent({
|
|
190
|
-
kind: 'owned-text-file',
|
|
191
|
-
path: artifactPath,
|
|
192
|
-
allowedRoot: options.configDir,
|
|
193
|
-
identity,
|
|
194
|
-
});
|
|
195
|
-
return {
|
|
196
|
-
artifact: {
|
|
197
|
-
path: artifactPath,
|
|
198
|
-
kind: options.kind,
|
|
199
|
-
platform: options.platform,
|
|
200
|
-
artifactKey: options.artifactKey,
|
|
201
|
-
},
|
|
202
|
-
component,
|
|
203
|
-
write: async () => {
|
|
204
|
-
await fs.ensureDir(options.configDir);
|
|
205
|
-
await writeOwnedTextFile({
|
|
206
|
-
path: artifactPath,
|
|
207
|
-
allowedRoot: options.configDir,
|
|
208
|
-
identity,
|
|
209
|
-
content: options.content,
|
|
210
|
-
});
|
|
211
|
-
},
|
|
212
|
-
};
|
|
316
|
+
const CODEX_REMOVE_RECOVERY = 'Codex residue was retained. Retry cleanup or uninstall, upgrade AW, or install a compatible official Codex CLI.';
|
|
317
|
+
function pluginActionId(plugin) {
|
|
318
|
+
return plugin.pluginId ?? plugin.manifest.name;
|
|
213
319
|
}
|
|
214
320
|
function mergePermissionStates(values) {
|
|
215
321
|
return {
|
|
216
322
|
allow: [...new Set(values.flatMap((value) => value?.allow ?? []))],
|
|
217
323
|
ask: [...new Set(values.flatMap((value) => value?.ask ?? []))],
|
|
218
324
|
deny: [...new Set(values.flatMap((value) => value?.deny ?? []))],
|
|
325
|
+
...(values.some((value) => value?.excludedCommands !== undefined) ? {
|
|
326
|
+
excludedCommands: [...new Set(values.flatMap((value) => value?.excludedCommands ?? []))],
|
|
327
|
+
} : {}),
|
|
219
328
|
};
|
|
220
329
|
}
|
|
221
330
|
function subtractPermissionState(value, generated) {
|
|
@@ -228,6 +337,9 @@ function subtractPermissionState(value, generated) {
|
|
|
228
337
|
allow: (value?.allow ?? []).filter((entry) => !remove.allow.has(entry)),
|
|
229
338
|
ask: (value?.ask ?? []).filter((entry) => !remove.ask.has(entry)),
|
|
230
339
|
deny: (value?.deny ?? []).filter((entry) => !remove.deny.has(entry)),
|
|
340
|
+
...(value?.excludedCommands ? {
|
|
341
|
+
excludedCommands: value.excludedCommands.filter((entry) => !generated.excludedCommands?.includes(entry)),
|
|
342
|
+
} : {}),
|
|
231
343
|
};
|
|
232
344
|
}
|
|
233
345
|
function intersectPermissionState(value, generated) {
|
|
@@ -240,11 +352,17 @@ function intersectPermissionState(value, generated) {
|
|
|
240
352
|
allow: (value?.allow ?? []).filter((entry) => keep.allow.has(entry)),
|
|
241
353
|
ask: (value?.ask ?? []).filter((entry) => keep.ask.has(entry)),
|
|
242
354
|
deny: (value?.deny ?? []).filter((entry) => keep.deny.has(entry)),
|
|
355
|
+
...(value?.excludedCommands ? {
|
|
356
|
+
excludedCommands: value.excludedCommands.filter((entry) => generated.excludedCommands?.includes(entry)),
|
|
357
|
+
} : {}),
|
|
243
358
|
};
|
|
244
359
|
}
|
|
245
360
|
function rebuildClaudePermissions(settings, ownerKey, desired) {
|
|
246
361
|
const previousGenerated = mergePermissionStates(Object.values(settings.awGenerated?.permissions ?? {}));
|
|
247
|
-
const currentPermissions = mergePermissionStates([
|
|
362
|
+
const currentPermissions = mergePermissionStates([{
|
|
363
|
+
...settings.permissions,
|
|
364
|
+
...(settings.sandbox?.excludedCommands ? { excludedCommands: settings.sandbox.excludedCommands } : {}),
|
|
365
|
+
}]);
|
|
248
366
|
const manual = mergePermissionStates([
|
|
249
367
|
subtractPermissionState(currentPermissions, previousGenerated),
|
|
250
368
|
intersectPermissionState(intersectPermissionState(settings.awGenerated?.manualPermissions, previousGenerated), currentPermissions),
|
|
@@ -258,16 +376,22 @@ function rebuildClaudePermissions(settings, ownerKey, desired) {
|
|
|
258
376
|
if (Object.keys(settings.awGenerated.permissions).length === 0) {
|
|
259
377
|
delete settings.awGenerated.permissions;
|
|
260
378
|
}
|
|
261
|
-
if (manual.allow.length || manual.ask.length || manual.deny.length) {
|
|
379
|
+
if (manual.allow.length || manual.ask.length || manual.deny.length || manual.excludedCommands?.length) {
|
|
262
380
|
settings.awGenerated.manualPermissions = manual;
|
|
263
381
|
}
|
|
264
382
|
else {
|
|
265
383
|
delete settings.awGenerated.manualPermissions;
|
|
266
384
|
}
|
|
267
|
-
|
|
385
|
+
const combined = mergePermissionStates([
|
|
268
386
|
manual,
|
|
269
387
|
...Object.values(settings.awGenerated.permissions ?? {}),
|
|
270
388
|
]);
|
|
389
|
+
settings.permissions = {
|
|
390
|
+
...settings.permissions, allow: combined.allow, ask: combined.ask, deny: combined.deny,
|
|
391
|
+
};
|
|
392
|
+
if (combined.excludedCommands !== undefined) {
|
|
393
|
+
settings.sandbox = { ...settings.sandbox, excludedCommands: combined.excludedCommands };
|
|
394
|
+
}
|
|
271
395
|
if (settings.awGenerated.permissions === undefined
|
|
272
396
|
&& settings.awGenerated.manualPermissions === undefined
|
|
273
397
|
&& settings.awGenerated.hooks === undefined
|
|
@@ -275,86 +399,6 @@ function rebuildClaudePermissions(settings, ownerKey, desired) {
|
|
|
275
399
|
delete settings.awGenerated;
|
|
276
400
|
}
|
|
277
401
|
}
|
|
278
|
-
function createClaudePermissionsComponent(options) {
|
|
279
|
-
const ownerKey = createSharedOwnerToken(options.identity);
|
|
280
|
-
return {
|
|
281
|
-
kind: 'shared-config',
|
|
282
|
-
identity: options.identity,
|
|
283
|
-
label: `${options.settingsPath}#awGenerated.permissions.${ownerKey}`,
|
|
284
|
-
inspect: async () => {
|
|
285
|
-
const settings = await readClaudeSettings(options.settingsPath);
|
|
286
|
-
return settings.awGenerated?.permissions?.[ownerKey] ? 'present' : 'absent';
|
|
287
|
-
},
|
|
288
|
-
remove: async () => {
|
|
289
|
-
const settings = await readClaudeSettings(options.settingsPath);
|
|
290
|
-
rebuildClaudePermissions(settings, ownerKey);
|
|
291
|
-
await writeClaudeSettings(options.settingsPath, settings);
|
|
292
|
-
},
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
function createCodexInstructionComponent(options) {
|
|
296
|
-
const ownerKey = createSharedOwnerToken(options.identity);
|
|
297
|
-
return {
|
|
298
|
-
kind: 'managed-block',
|
|
299
|
-
identity: options.identity,
|
|
300
|
-
label: `${options.configPath}#developer_instructions:${ownerKey}`,
|
|
301
|
-
inspect: async () => {
|
|
302
|
-
const config = await readCodexConfigFile(options.configPath);
|
|
303
|
-
return config.snapshot.developerInstructions.managedBlocks[ownerKey]
|
|
304
|
-
? 'present'
|
|
305
|
-
: 'absent';
|
|
306
|
-
},
|
|
307
|
-
remove: async () => {
|
|
308
|
-
await applyCodexConfigTransactionFile(options.configPath, {
|
|
309
|
-
removeManagedInstructionPluginName: ownerKey,
|
|
310
|
-
});
|
|
311
|
-
},
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
function createCodexActivationComponent(options) {
|
|
315
|
-
return {
|
|
316
|
-
kind: 'shared-config',
|
|
317
|
-
identity: options.identity,
|
|
318
|
-
label: `${options.configPath}#plugins.${options.codexPluginId}.enabled`,
|
|
319
|
-
inspect: async () => {
|
|
320
|
-
const plugin = (await readCodexConfigFile(options.configPath))
|
|
321
|
-
.snapshot.plugins[options.codexPluginId];
|
|
322
|
-
return plugin?.enabled === options.desired ? 'present' : 'absent';
|
|
323
|
-
},
|
|
324
|
-
remove: async () => {
|
|
325
|
-
await applyCodexConfigTransactionFile(options.configPath, {
|
|
326
|
-
removePluginActivations: [options.codexPluginId],
|
|
327
|
-
});
|
|
328
|
-
},
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
function createCodexActivationCleanupComponent(options) {
|
|
332
|
-
return {
|
|
333
|
-
kind: 'shared-config',
|
|
334
|
-
identity: options.identity,
|
|
335
|
-
label: `${options.configPath}#plugins.${options.codexPluginId}.enabled`,
|
|
336
|
-
inspect: async () => {
|
|
337
|
-
const actual = (await readCodexConfigFile(options.configPath))
|
|
338
|
-
.snapshot.plugins[options.codexPluginId]?.enabled;
|
|
339
|
-
return options.disposition === 'remove'
|
|
340
|
-
? actual === undefined ? 'absent' : 'present'
|
|
341
|
-
: actual === true ? 'present' : 'absent';
|
|
342
|
-
},
|
|
343
|
-
remove: async () => {
|
|
344
|
-
await applyConditionalCodexConfigTransactionFile(options.configPath, (snapshot) => {
|
|
345
|
-
const actual = snapshot.plugins[options.codexPluginId]?.enabled;
|
|
346
|
-
if (options.disposition === 'remove') {
|
|
347
|
-
return actual === undefined
|
|
348
|
-
? null
|
|
349
|
-
: { removePluginActivations: [options.codexPluginId] };
|
|
350
|
-
}
|
|
351
|
-
return actual === true
|
|
352
|
-
? { upsertPluginActivations: { [options.codexPluginId]: false } }
|
|
353
|
-
: null;
|
|
354
|
-
});
|
|
355
|
-
},
|
|
356
|
-
};
|
|
357
|
-
}
|
|
358
402
|
function legacyCodexMcpOwner(actual) {
|
|
359
403
|
const envValue = actual?.value?.env;
|
|
360
404
|
return envValue
|
|
@@ -364,26 +408,6 @@ function legacyCodexMcpOwner(actual) {
|
|
|
364
408
|
? envValue[LEGACY_MCP_OWNER_ENV]
|
|
365
409
|
: null;
|
|
366
410
|
}
|
|
367
|
-
function createLegacyCodexMcpCleanupComponent(options) {
|
|
368
|
-
const ownerKey = createSharedOwnerToken(options.identity);
|
|
369
|
-
return {
|
|
370
|
-
kind: 'shared-config',
|
|
371
|
-
identity: options.identity,
|
|
372
|
-
label: `${options.configPath}#mcp_servers.${options.serverKey}`,
|
|
373
|
-
inspect: async () => {
|
|
374
|
-
const actual = (await readCodexConfigFile(options.configPath))
|
|
375
|
-
.snapshot.mcpServers[options.serverKey];
|
|
376
|
-
if (!actual)
|
|
377
|
-
return 'absent';
|
|
378
|
-
return legacyCodexMcpOwner(actual) === ownerKey ? 'present' : 'foreign';
|
|
379
|
-
},
|
|
380
|
-
remove: async () => {
|
|
381
|
-
await applyConditionalCodexConfigTransactionFile(options.configPath, (snapshot) => legacyCodexMcpOwner(snapshot.mcpServers[options.serverKey]) === ownerKey
|
|
382
|
-
? { removeMcpServers: [options.serverKey] }
|
|
383
|
-
: null);
|
|
384
|
-
},
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
411
|
async function readLegacyCodexHooks(hooksPath) {
|
|
388
412
|
if (!await fs.pathExists(hooksPath))
|
|
389
413
|
return parseCodexSharedHooksFile({ hooks: {} });
|
|
@@ -423,35 +447,6 @@ async function applyLegacyCodexHookCleanupTransactionFile(hooksPath, update) {
|
|
|
423
447
|
},
|
|
424
448
|
});
|
|
425
449
|
}
|
|
426
|
-
function createLegacyCodexHookCleanupComponent(options) {
|
|
427
|
-
const serialized = serializeTrackedHookGroupIdentity(options.identity);
|
|
428
|
-
return {
|
|
429
|
-
kind: 'shared-config',
|
|
430
|
-
identity: ownerIdentity(options.pluginName, internalArtifactKey('hook', serialized), 'codex', options.scope),
|
|
431
|
-
label: `${options.hooksPath}#${serialized}`,
|
|
432
|
-
inspect: async () => {
|
|
433
|
-
const parsed = await readLegacyCodexHooks(options.hooksPath);
|
|
434
|
-
return parsed.managedIdentities.some((entry) => serializeTrackedHookGroupIdentity(entry) === serialized)
|
|
435
|
-
? 'present'
|
|
436
|
-
: 'absent';
|
|
437
|
-
},
|
|
438
|
-
remove: async () => {
|
|
439
|
-
await applyLegacyCodexHookCleanupTransactionFile(options.hooksPath, (parsed) => {
|
|
440
|
-
let removed = false;
|
|
441
|
-
const remaining = parsed.groups.flatMap((entry) => {
|
|
442
|
-
if (!removed
|
|
443
|
-
&& entry.managedIdentity
|
|
444
|
-
&& serializeTrackedHookGroupIdentity(entry.managedIdentity) === serialized) {
|
|
445
|
-
removed = true;
|
|
446
|
-
return [];
|
|
447
|
-
}
|
|
448
|
-
return [entry.rawGroup];
|
|
449
|
-
});
|
|
450
|
-
return removed ? remaining : null;
|
|
451
|
-
});
|
|
452
|
-
},
|
|
453
|
-
};
|
|
454
|
-
}
|
|
455
450
|
async function codexRoleRegistrationOwned(options) {
|
|
456
451
|
if (!options.registration?.configFile)
|
|
457
452
|
return false;
|
|
@@ -467,1683 +462,203 @@ async function codexRoleRegistrationOwned(options) {
|
|
|
467
462
|
return false;
|
|
468
463
|
}
|
|
469
464
|
}
|
|
470
|
-
function
|
|
471
|
-
const
|
|
472
|
-
|
|
473
|
-
const registration = config.snapshot.agents[options.roleKey];
|
|
474
|
-
if (!registration)
|
|
475
|
-
return 'absent';
|
|
476
|
-
return await codexRoleRegistrationOwned({ ...options, registration })
|
|
477
|
-
? 'present'
|
|
478
|
-
: 'foreign';
|
|
479
|
-
};
|
|
480
|
-
return {
|
|
481
|
-
kind: 'shared-config',
|
|
482
|
-
identity: options.identity,
|
|
483
|
-
label: `${options.configPath}#agents.${options.roleKey}`,
|
|
484
|
-
inspect,
|
|
485
|
-
remove: async () => {
|
|
486
|
-
await applyConditionalCodexConfigTransactionFile(options.configPath, async (snapshot) => {
|
|
487
|
-
const registration = snapshot.agents[options.roleKey];
|
|
488
|
-
return await codexRoleRegistrationOwned({ ...options, registration })
|
|
489
|
-
? { removeAgentRegistrations: [options.roleKey] }
|
|
490
|
-
: null;
|
|
491
|
-
});
|
|
492
|
-
},
|
|
493
|
-
};
|
|
494
|
-
}
|
|
495
|
-
function sameOwnerIdentity(left, right) {
|
|
496
|
-
return left.owner === right.owner
|
|
497
|
-
&& left.sourceId === right.sourceId
|
|
498
|
-
&& left.sourceIdentity === right.sourceIdentity
|
|
499
|
-
&& left.pluginId === right.pluginId
|
|
500
|
-
&& left.plugin === right.plugin
|
|
501
|
-
&& left.artifactKey === right.artifactKey
|
|
502
|
-
&& left.platform === right.platform
|
|
503
|
-
&& left.scope === right.scope;
|
|
504
|
-
}
|
|
505
|
-
function sharedOwnerPluginName(value) {
|
|
506
|
-
return parseSharedOwnerToken(value)?.plugin ?? value;
|
|
507
|
-
}
|
|
508
|
-
async function scanCodexSharedComponents(options) {
|
|
509
|
-
const output = [];
|
|
510
|
-
const expectedIdentity = (artifactKey) => ({
|
|
511
|
-
...ownerIdentity(options.pluginName, artifactKey, 'codex', options.scope),
|
|
512
|
-
...(options.sourceId ? {
|
|
513
|
-
sourceId: options.sourceId,
|
|
514
|
-
sourceIdentity: options.sourceIdentity,
|
|
515
|
-
pluginId: options.pluginId,
|
|
516
|
-
} : {}),
|
|
517
|
-
});
|
|
518
|
-
const corruptedComponent = (filePath, error) => ({
|
|
519
|
-
kind: 'shared-config',
|
|
520
|
-
identity: ownerIdentity(options.pluginName, internalArtifactKey('corrupted-shared-config', filePath), 'codex', options.scope),
|
|
521
|
-
label: filePath,
|
|
522
|
-
inspect: async () => {
|
|
523
|
-
throw new Error(`包含 ${options.pluginName} 的 AW ownership 证据,但共享配置无法解析:${error instanceof Error ? error.message : String(error)}`);
|
|
524
|
-
},
|
|
525
|
-
remove: async () => undefined,
|
|
526
|
-
});
|
|
527
|
-
const containsOwnedEvidence = (raw) => raw.includes(options.pluginName) && (raw.includes('[[aw-managed:start plugin=')
|
|
528
|
-
|| raw.includes(OWNED_TEXT_HEADER_PREFIX)
|
|
529
|
-
|| raw.includes('agent-workflows'));
|
|
530
|
-
if (options.scanConfig) {
|
|
531
|
-
const config = await readCodexConfigFile(options.paths.configTomlPath).catch(async (error) => {
|
|
532
|
-
if (!options.ignoreReadErrors)
|
|
533
|
-
throw error;
|
|
534
|
-
const raw = await fs.readFile(options.paths.configTomlPath, 'utf8').catch(() => '');
|
|
535
|
-
if (containsOwnedEvidence(raw)) {
|
|
536
|
-
output.push(corruptedComponent(options.paths.configTomlPath, error));
|
|
537
|
-
}
|
|
538
|
-
return null;
|
|
539
|
-
});
|
|
540
|
-
const instructionIdentity = expectedIdentity('developer-instructions');
|
|
541
|
-
const instructionOwnerKey = createSharedOwnerToken(instructionIdentity);
|
|
542
|
-
if (config?.snapshot.developerInstructions.managedBlocks[instructionOwnerKey]) {
|
|
543
|
-
output.push(createCodexInstructionComponent({
|
|
544
|
-
identity: instructionIdentity,
|
|
545
|
-
scope: options.scope,
|
|
546
|
-
configPath: options.paths.configTomlPath,
|
|
547
|
-
}));
|
|
548
|
-
}
|
|
549
|
-
for (const [roleKey, registration] of Object.entries(config?.snapshot.agents ?? {})) {
|
|
550
|
-
if (!registration.configFile)
|
|
551
|
-
continue;
|
|
552
|
-
const rolePath = path.resolve(path.dirname(options.paths.configTomlPath), registration.configFile);
|
|
553
|
-
const raw = await fs.readFile(rolePath, 'utf8').catch(() => '');
|
|
554
|
-
const parsed = (() => {
|
|
555
|
-
try {
|
|
556
|
-
return parseOwnedTextHeader(raw);
|
|
557
|
-
}
|
|
558
|
-
catch {
|
|
559
|
-
return null;
|
|
560
|
-
}
|
|
561
|
-
})();
|
|
562
|
-
if (!parsed || !sameOwnerIdentity(parsed.identity, expectedIdentity(roleKey)))
|
|
563
|
-
continue;
|
|
564
|
-
output.push(createCodexRoleRegistrationComponent({
|
|
565
|
-
identity: expectedIdentity(internalArtifactKey('role', roleKey)),
|
|
566
|
-
fileIdentity: expectedIdentity(roleKey),
|
|
567
|
-
configPath: options.paths.configTomlPath,
|
|
568
|
-
roleKey,
|
|
569
|
-
rolePath,
|
|
570
|
-
}));
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
return output;
|
|
574
|
-
}
|
|
575
|
-
async function scanClaudeSharedComponents(options) {
|
|
576
|
-
const settings = await readClaudeSettings(options.settingsPath);
|
|
577
|
-
const identity = {
|
|
578
|
-
...ownerIdentity(options.pluginName, 'permissions', 'claude', options.scope),
|
|
579
|
-
...(options.sourceId ? {
|
|
580
|
-
sourceId: options.sourceId,
|
|
581
|
-
sourceIdentity: options.sourceIdentity,
|
|
582
|
-
pluginId: options.pluginId,
|
|
583
|
-
} : {}),
|
|
584
|
-
};
|
|
585
|
-
return settings.awGenerated?.permissions?.[createSharedOwnerToken(identity)]
|
|
586
|
-
? [createClaudePermissionsComponent({ ...options, identity })]
|
|
587
|
-
: [];
|
|
588
|
-
}
|
|
589
|
-
async function scanOwnedTextFiles(options) {
|
|
590
|
-
if (!await fs.pathExists(options.root))
|
|
591
|
-
return [];
|
|
592
|
-
const output = [];
|
|
593
|
-
const pending = [options.root];
|
|
594
|
-
while (pending.length > 0) {
|
|
595
|
-
const current = pending.pop();
|
|
596
|
-
for (const entry of await fs.readdir(current, { withFileTypes: true })) {
|
|
597
|
-
const entryPath = path.join(current, entry.name);
|
|
598
|
-
if (entry.isSymbolicLink())
|
|
599
|
-
continue;
|
|
600
|
-
if (entry.isDirectory()) {
|
|
601
|
-
pending.push(entryPath);
|
|
602
|
-
continue;
|
|
603
|
-
}
|
|
604
|
-
if (!entry.isFile())
|
|
605
|
-
continue;
|
|
606
|
-
const raw = await fs.readFile(entryPath, 'utf8').catch(() => '');
|
|
607
|
-
if (!raw.includes(OWNED_TEXT_HEADER_PREFIX))
|
|
608
|
-
continue;
|
|
609
|
-
let parsed;
|
|
610
|
-
try {
|
|
611
|
-
parsed = parseOwnedTextHeader(raw);
|
|
612
|
-
}
|
|
613
|
-
catch {
|
|
614
|
-
continue;
|
|
615
|
-
}
|
|
616
|
-
if (parsed?.identity.plugin !== options.pluginName
|
|
617
|
-
|| (options.sourceId !== undefined && parsed.identity.sourceId !== options.sourceId)
|
|
618
|
-
|| (options.sourceIdentity !== undefined
|
|
619
|
-
&& parsed.identity.sourceIdentity !== options.sourceIdentity)
|
|
620
|
-
|| parsed.identity.platform !== options.platform
|
|
621
|
-
|| parsed.identity.scope !== options.scope)
|
|
622
|
-
continue;
|
|
623
|
-
output.push(pathComponent({
|
|
624
|
-
kind: 'owned-text-file',
|
|
625
|
-
path: entryPath,
|
|
626
|
-
allowedRoot: options.root,
|
|
627
|
-
identity: parsed.identity,
|
|
628
|
-
}));
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
return output;
|
|
632
|
-
}
|
|
633
|
-
async function scanOwnedSkills(options) {
|
|
634
|
-
if (!await fs.pathExists(options.root))
|
|
635
|
-
return [];
|
|
636
|
-
const output = [];
|
|
637
|
-
const pending = [options.root];
|
|
638
|
-
while (pending.length > 0) {
|
|
639
|
-
const current = pending.pop();
|
|
640
|
-
for (const entry of await fs.readdir(current, { withFileTypes: true })) {
|
|
641
|
-
if (!entry.isDirectory() || entry.isSymbolicLink())
|
|
642
|
-
continue;
|
|
643
|
-
const skillRoot = path.join(current, entry.name);
|
|
644
|
-
const marker = await readSkillOwnerMarker({
|
|
645
|
-
skillRoot,
|
|
646
|
-
allowedRoot: current,
|
|
647
|
-
}).catch(() => null);
|
|
648
|
-
if (marker?.plugin === options.pluginName
|
|
649
|
-
&& (options.sourceId === undefined || marker.sourceId === options.sourceId)
|
|
650
|
-
&& (options.sourceIdentity === undefined || marker.sourceIdentity === options.sourceIdentity)
|
|
651
|
-
&& marker.platform === options.platform
|
|
652
|
-
&& marker.scope === options.scope) {
|
|
653
|
-
output.push(pathComponent({
|
|
654
|
-
kind: 'skill-directory',
|
|
655
|
-
path: skillRoot,
|
|
656
|
-
allowedRoot: current,
|
|
657
|
-
identity: marker,
|
|
658
|
-
}));
|
|
659
|
-
continue;
|
|
660
|
-
}
|
|
661
|
-
pending.push(skillRoot);
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
return output;
|
|
665
|
-
}
|
|
666
|
-
function componentIdentityKey(component) {
|
|
667
|
-
return [
|
|
668
|
-
component.kind,
|
|
669
|
-
component.identity.artifactKey,
|
|
670
|
-
'path' in component ? path.resolve(component.path) : 'label' in component ? component.label : component.pluginId,
|
|
671
|
-
].join('\0');
|
|
672
|
-
}
|
|
673
|
-
function dedupeComponents(components) {
|
|
674
|
-
const seen = new Set();
|
|
675
|
-
return components.filter((component) => {
|
|
676
|
-
const key = componentIdentityKey(component);
|
|
677
|
-
if (seen.has(key))
|
|
678
|
-
return false;
|
|
679
|
-
seen.add(key);
|
|
680
|
-
return true;
|
|
681
|
-
});
|
|
682
|
-
}
|
|
683
|
-
async function preflightCodexWriteSafety(options) {
|
|
684
|
-
const pluginName = options.plugin.manifest.name;
|
|
685
|
-
const userConfigPath = resolveCodexPaths(options.cwd, 'user', options.env).configTomlPath;
|
|
686
|
-
const projectConfigPath = resolveCodexPaths(options.cwd, 'project', options.env).configTomlPath;
|
|
687
|
-
const nativeSurface = analyzeCodexSurface(options.plugin.manifest).nativeKinds.length > 0;
|
|
688
|
-
const needsUserConfig = options.scope === 'user'
|
|
689
|
-
|| nativeSurface;
|
|
690
|
-
let userConfig;
|
|
691
|
-
if (needsUserConfig) {
|
|
692
|
-
try {
|
|
693
|
-
userConfig = await readCodexConfigFile(userConfigPath);
|
|
694
|
-
}
|
|
695
|
-
catch (error) {
|
|
696
|
-
throw new Error(`codexProjectUserConfigUnreadable: 无法解析用户级 Codex 配置 ${userConfigPath}:${error instanceof Error ? error.message : String(error)}`);
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
if (options.scope === 'project' && userConfig) {
|
|
700
|
-
const expectedPluginId = `${pluginName}@${options.plugin.marketplaceName ?? MARKETPLACE_NAME}`;
|
|
701
|
-
for (const [key, plugin] of Object.entries(userConfig.snapshot.plugins)) {
|
|
702
|
-
if (key !== expectedPluginId
|
|
703
|
-
&& (key === pluginName || key.startsWith(`${pluginName}@`) || plugin.name === pluginName)) {
|
|
704
|
-
throw new Error(`externalOwnershipPresent: 用户级 Codex 已存在同名外部插件 ${key}。`);
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
const roleKeys = new Set((options.plugin.manifest.artifacts?.targets ?? [])
|
|
709
|
-
.filter((target) => target.platform === 'codex'
|
|
710
|
-
&& target.scopes.includes(options.scope)
|
|
711
|
-
&& target.target === 'codex.agentRole'
|
|
712
|
-
&& target.roleKey)
|
|
713
|
-
.map((target) => target.roleKey));
|
|
714
|
-
const needsProjectConfig = options.scope === 'project' && Boolean(nativeSurface
|
|
715
|
-
|| resolvePlatformEntries(options.plugin.manifest.extensions?.instructions, 'codex').length > 0
|
|
716
|
-
|| (options.plugin.manifest.artifacts?.targets ?? []).some((target) => target.platform === 'codex'
|
|
717
|
-
&& target.scopes.includes('project')
|
|
718
|
-
&& (target.target === 'codex.agentRole'
|
|
719
|
-
|| target.target === 'codex.developerInstructionsBlock')));
|
|
720
|
-
if (needsProjectConfig) {
|
|
721
|
-
try {
|
|
722
|
-
await readCodexConfigFile(projectConfigPath);
|
|
723
|
-
}
|
|
724
|
-
catch (error) {
|
|
725
|
-
throw new Error(`projectConfigUnreadable: 无法解析项目级 Codex 配置 ${projectConfigPath}:${error instanceof Error ? error.message : String(error)}`);
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
if (roleKeys.size === 0)
|
|
465
|
+
export async function removeForceCleanupCodexRoleRegistration(options) {
|
|
466
|
+
const component = options.component;
|
|
467
|
+
if (component.kind !== 'owned-text-file' || component.identity.platform !== 'codex')
|
|
729
468
|
return;
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
let namespace;
|
|
750
|
-
try {
|
|
751
|
-
namespace = await resolveCodexRoleNamespace(configPath, {
|
|
752
|
-
strict: true,
|
|
753
|
-
awManagedTableKeys: ownedRoleKeys,
|
|
754
|
-
awManagedRoleLayerPaths: ownedRolePaths,
|
|
755
|
-
});
|
|
756
|
-
}
|
|
757
|
-
catch (error) {
|
|
758
|
-
throw new Error(`projectConfigUnreadable: 无法读取 Codex role namespace ${configPath}:${error instanceof Error ? error.message : String(error)}`);
|
|
759
|
-
}
|
|
760
|
-
for (const roleKey of roleKeys) {
|
|
761
|
-
const tableCollision = namespace.roles.find((role) => role.source === 'registration' && role.tableKey === roleKey && !role.awManaged);
|
|
762
|
-
const nameConflict = findCodexRoleNameConflict(namespace, roleKey);
|
|
763
|
-
if (tableCollision || nameConflict?.conflict) {
|
|
764
|
-
throw new Error(`roleNameConflict: Codex role "${roleKey}" 已由外部配置占用(${configPath})。`);
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
}
|
|
769
|
-
function renderCodexRole(options) {
|
|
770
|
-
const stringValue = (value) => JSON.stringify(value.trim());
|
|
771
|
-
return [
|
|
772
|
-
`name = ${stringValue(options.roleKey)}`,
|
|
773
|
-
`description = ${stringValue(options.description)}`,
|
|
774
|
-
`developer_instructions = ${stringValue(options.developerInstructions)}`,
|
|
775
|
-
...(options.model ? [`model = ${stringValue(options.model)}`] : []),
|
|
776
|
-
...(options.modelReasoningEffort
|
|
777
|
-
? [`model_reasoning_effort = ${stringValue(options.modelReasoningEffort)}`]
|
|
778
|
-
: []),
|
|
779
|
-
'',
|
|
780
|
-
].join('\n');
|
|
781
|
-
}
|
|
782
|
-
async function resolveDynamicArtifacts(options) {
|
|
783
|
-
const declarations = (options.plugin.manifest.artifacts?.targets ?? []).filter((target) => target.platform === options.platform && target.scopes.includes(options.scope));
|
|
784
|
-
if (declarations.length === 0)
|
|
785
|
-
return { artifacts: [], sourceDirs: () => [] };
|
|
786
|
-
const render = await runArtifactRenderer({
|
|
787
|
-
event: options.event,
|
|
788
|
-
plugin: options.plugin,
|
|
789
|
-
platform: options.platform,
|
|
790
|
-
scope: options.scope,
|
|
791
|
-
cwd: options.cwd,
|
|
792
|
-
commandEnv: options.env,
|
|
793
|
-
previousArtifacts: [...options.previousArtifacts],
|
|
794
|
-
scriptTimeoutMs: options.scriptTimeoutMs,
|
|
795
|
-
});
|
|
796
|
-
const config = await resolveArtifactRenderConfig({
|
|
797
|
-
sourceId: options.plugin.sourceId,
|
|
798
|
-
sourceIdentity: options.plugin.sourceIdentity,
|
|
799
|
-
pluginName: options.plugin.manifest.name,
|
|
800
|
-
manifest: options.plugin.manifest,
|
|
801
|
-
scope: options.scope,
|
|
802
|
-
cwd: options.cwd,
|
|
803
|
-
env: options.env,
|
|
804
|
-
});
|
|
805
|
-
const artifacts = validateArtifactPlan({
|
|
806
|
-
manifest: options.plugin.manifest,
|
|
807
|
-
plan: render.plan,
|
|
808
|
-
platform: options.platform,
|
|
809
|
-
scope: options.scope,
|
|
810
|
-
renderConfig: config,
|
|
811
|
-
rendererDigest: render.target.rendererDigest,
|
|
812
|
-
manifestDigest: render.target.manifestDigest,
|
|
813
|
-
}).artifacts;
|
|
814
|
-
return {
|
|
815
|
-
artifacts,
|
|
816
|
-
sourceDirs: (artifact) => render.context.artifactSources.find((entry) => entry.id === artifact.id && entry.target === artifact.target)?.sourceDirs ?? [],
|
|
817
|
-
};
|
|
818
|
-
}
|
|
819
|
-
function dynamicSkillWrite(options) {
|
|
820
|
-
const skillKey = 'skillKey' in options.artifact ? options.artifact.skillKey : '';
|
|
821
|
-
const identity = ownerIdentity(options.plugin.manifest.name, skillKey, options.platform, options.scope);
|
|
822
|
-
const component = pathComponent({
|
|
823
|
-
kind: 'skill-directory',
|
|
824
|
-
path: options.skillPath,
|
|
825
|
-
allowedRoot: options.allowedRoot,
|
|
826
|
-
identity,
|
|
827
|
-
...(options.platform === 'codex' && options.scope === 'user'
|
|
828
|
-
? {
|
|
829
|
-
unownedIsPristine: (actualPath) => skillDirectoryMatchesExpectedTree(actualPath, options.tree),
|
|
830
|
-
}
|
|
831
|
-
: {}),
|
|
469
|
+
const paths = resolveCodexPaths(options.cwd, component.identity.scope, options.env);
|
|
470
|
+
const roleKey = component.identity.artifactKey;
|
|
471
|
+
const expectedPath = path.join(paths.agentsDir, `${buildGeneratedName(component.identity.plugin, roleKey)}.toml`);
|
|
472
|
+
if (path.resolve(component.path) !== path.resolve(expectedPath))
|
|
473
|
+
return;
|
|
474
|
+
await applyConditionalCodexConfigTransactionFile(paths.configTomlPath, async (snapshot) => {
|
|
475
|
+
const registration = snapshot.agents[roleKey];
|
|
476
|
+
if (!registration?.configFile
|
|
477
|
+
|| path.resolve(path.dirname(paths.configTomlPath), registration.configFile)
|
|
478
|
+
!== path.resolve(component.path))
|
|
479
|
+
return null;
|
|
480
|
+
// Force authorizes the existing exclusive file. The matching registration is
|
|
481
|
+
// removed before that evidence disappears; missing or foreign files grant no authority.
|
|
482
|
+
const inspected = await inspectOwnedComponents({ components: [component], forceExclusive: true });
|
|
483
|
+
return inspected.components[0]?.state === 'present'
|
|
484
|
+
? { removeAgentRegistrations: [roleKey] }
|
|
485
|
+
: null;
|
|
832
486
|
});
|
|
833
|
-
return {
|
|
834
|
-
artifact: {
|
|
835
|
-
path: options.skillPath,
|
|
836
|
-
paths: Object.keys(options.tree.files).map((relativePath) => path.join(options.skillPath, relativePath.split('/').join(path.sep))),
|
|
837
|
-
kind: 'skill',
|
|
838
|
-
platform: options.platform,
|
|
839
|
-
artifactKey: skillKey,
|
|
840
|
-
id: options.artifact.id,
|
|
841
|
-
target: options.artifact.target,
|
|
842
|
-
state: options.artifact.state,
|
|
843
|
-
...(options.artifact.disabledReason
|
|
844
|
-
? { disabledReason: options.artifact.disabledReason }
|
|
845
|
-
: {}),
|
|
846
|
-
refreshKeys: [...options.artifact.refreshKeys],
|
|
847
|
-
configDigest: options.artifact.configDigest,
|
|
848
|
-
contentDigest: options.platform === 'codex'
|
|
849
|
-
? createCodexSkillStagingTreeContentDigest(options.tree)
|
|
850
|
-
: createDynamicSkillTreeContentDigest(options.tree),
|
|
851
|
-
},
|
|
852
|
-
...(options.artifact.state === 'present' ? { component } : {}),
|
|
853
|
-
write: async () => {
|
|
854
|
-
if (options.artifact.state === 'disabled') {
|
|
855
|
-
return;
|
|
856
|
-
}
|
|
857
|
-
await writeDynamicSkillTree(options.skillPath, options.tree, {
|
|
858
|
-
allowedRoot: options.allowedRoot,
|
|
859
|
-
identity,
|
|
860
|
-
allowPristineUnowned: options.platform === 'codex' && options.scope === 'user',
|
|
861
|
-
});
|
|
862
|
-
},
|
|
863
|
-
};
|
|
864
487
|
}
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
path.join(plugin.rootDir, '.codex-plugin', 'plugin.json'),
|
|
868
|
-
...(marketplaceFallbackRoot
|
|
869
|
-
? [path.join(marketplaceFallbackRoot, '.codex-plugin', 'plugin.json')]
|
|
870
|
-
: []),
|
|
871
|
-
];
|
|
872
|
-
let manifest = null;
|
|
873
|
-
for (const manifestPath of manifestPaths) {
|
|
874
|
-
manifest = await fs.readJson(manifestPath).catch(() => null);
|
|
875
|
-
if (manifest)
|
|
876
|
-
break;
|
|
877
|
-
}
|
|
878
|
-
const raw = typeof manifest?.skills === 'string' && manifest.skills.trim() !== ''
|
|
879
|
-
? manifest.skills
|
|
880
|
-
: plugin.manifest.skills ?? './codex/skills';
|
|
881
|
-
const normalized = path.posix.normalize(raw.replace(/^\.\//u, ''));
|
|
882
|
-
if (normalized === '..' || normalized.startsWith('../') || path.isAbsolute(normalized)) {
|
|
883
|
-
throw new Error(`Codex plugin skills root 越界:${raw}`);
|
|
884
|
-
}
|
|
885
|
-
return normalized;
|
|
488
|
+
function sharedOwnerPluginName(value) {
|
|
489
|
+
return parseSharedOwnerToken(value)?.plugin ?? value;
|
|
886
490
|
}
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
if (!await fs.pathExists(sourceRoot))
|
|
891
|
-
return [];
|
|
892
|
-
const dynamicKeys = new Set((options.plugin.manifest.artifacts?.targets ?? [])
|
|
893
|
-
.filter((target) => target.target === 'codex.skill' && target.skillKey)
|
|
894
|
-
.map((target) => target.skillKey));
|
|
895
|
-
const targetRoot = await canonicalizePathThroughExistingAncestor(path.join(options.marketplaceRoot ?? resolveAwHome(options.env), 'plugins', options.plugin.manifest.name, ...relativeRoot.split('/')));
|
|
896
|
-
const writes = [];
|
|
897
|
-
for (const entry of await fs.readdir(sourceRoot, { withFileTypes: true })) {
|
|
898
|
-
if (entry.isSymbolicLink()) {
|
|
899
|
-
throw new Error(`Codex skills source 不能包含符号链接:${entry.name}`);
|
|
900
|
-
}
|
|
901
|
-
if (!entry.isDirectory() || dynamicKeys.has(entry.name))
|
|
902
|
-
continue;
|
|
903
|
-
const skillSource = path.join(sourceRoot, entry.name);
|
|
904
|
-
if (!await fs.pathExists(path.join(skillSource, 'SKILL.md')))
|
|
905
|
-
continue;
|
|
906
|
-
const tree = await createCodexSkillExpectedTree({
|
|
907
|
-
artifact: {
|
|
908
|
-
target: 'codex.skill',
|
|
909
|
-
skillKey: entry.name,
|
|
910
|
-
state: 'present',
|
|
911
|
-
content: { files: {} },
|
|
912
|
-
},
|
|
913
|
-
sourceDirs: [skillSource],
|
|
914
|
-
sourceRequirementsReceiptPolicy: 'allow',
|
|
915
|
-
});
|
|
916
|
-
const skillPath = path.join(targetRoot, entry.name);
|
|
917
|
-
const canRecoverPristine = await canonicalizePathThroughExistingAncestor(skillSource)
|
|
918
|
-
!== path.resolve(skillPath);
|
|
919
|
-
const identity = ownerIdentity(options.plugin.manifest.name, entry.name, 'codex', 'user');
|
|
920
|
-
const component = pathComponent({
|
|
921
|
-
kind: 'skill-directory',
|
|
922
|
-
path: skillPath,
|
|
923
|
-
allowedRoot: targetRoot,
|
|
924
|
-
identity,
|
|
925
|
-
...(canRecoverPristine
|
|
926
|
-
? {
|
|
927
|
-
unownedIsPristine: (actualPath) => skillDirectoryMatchesExpectedTree(actualPath, tree),
|
|
928
|
-
}
|
|
929
|
-
: {}),
|
|
930
|
-
});
|
|
931
|
-
writes.push({
|
|
932
|
-
artifact: {
|
|
933
|
-
path: skillPath,
|
|
934
|
-
paths: Object.keys(tree.files).map((relativePath) => path.join(skillPath, relativePath)),
|
|
935
|
-
kind: 'skill',
|
|
936
|
-
platform: 'codex',
|
|
937
|
-
artifactKey: entry.name,
|
|
938
|
-
},
|
|
939
|
-
component,
|
|
940
|
-
write: async () => {
|
|
941
|
-
await writeDynamicSkillTree(skillPath, tree, {
|
|
942
|
-
allowedRoot: targetRoot,
|
|
943
|
-
identity,
|
|
944
|
-
allowPristineUnowned: canRecoverPristine,
|
|
945
|
-
});
|
|
946
|
-
},
|
|
947
|
-
});
|
|
491
|
+
function observedCodexNativeState(observation, operation) {
|
|
492
|
+
if (observation.state === 'observed') {
|
|
493
|
+
return observation.value === 'installed' ? 'present' : 'absent';
|
|
948
494
|
}
|
|
949
|
-
|
|
495
|
+
if (observation.state === 'unobserved')
|
|
496
|
+
return 'partial';
|
|
497
|
+
throw new Error(`codexNativeObservationFailed: ${operation} requires Codex plugin list evidence.`);
|
|
950
498
|
}
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
const
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
});
|
|
959
|
-
for (const artifact of dynamic.artifacts.filter((entry) => entry.target === 'claude.skill')) {
|
|
960
|
-
const skillKey = artifact.skillKey;
|
|
961
|
-
const tree = await createDynamicSkillExpectedTree({
|
|
962
|
-
artifact,
|
|
963
|
-
sourceDirs: dynamic.sourceDirs(artifact),
|
|
964
|
-
requireReadme: true,
|
|
965
|
-
requirementsReceipt: requirementsReceipt(options.plugin),
|
|
966
|
-
sourceRequirementsReceiptPolicy: 'allow',
|
|
967
|
-
});
|
|
968
|
-
writes.push(dynamicSkillWrite({
|
|
969
|
-
...options,
|
|
970
|
-
platform: 'claude',
|
|
971
|
-
artifact,
|
|
972
|
-
skillPath: path.join(paths.configDir, 'skills', skillKey),
|
|
973
|
-
allowedRoot: path.join(paths.configDir, 'skills'),
|
|
974
|
-
tree,
|
|
975
|
-
}));
|
|
976
|
-
}
|
|
977
|
-
for (const artifact of generateInstructionArtifacts(options.plugin.manifest.name, resolvePlatformEntries(options.plugin.manifest.extensions?.instructions, 'claude'), 'claude')) {
|
|
978
|
-
writes.push(generatedTextWrite({
|
|
979
|
-
...options,
|
|
980
|
-
platform: 'claude',
|
|
981
|
-
configDir: paths.configDir,
|
|
982
|
-
relativePath: artifact.relativePath,
|
|
983
|
-
artifactKey: artifact.artifactKey,
|
|
984
|
-
content: artifact.content,
|
|
985
|
-
kind: 'instruction',
|
|
986
|
-
}));
|
|
987
|
-
}
|
|
988
|
-
const permissions = resolvePlatformEntries(options.plugin.manifest.extensions?.permissions, 'claude');
|
|
989
|
-
if (permissions.length > 0) {
|
|
990
|
-
const component = createClaudePermissionsComponent({
|
|
991
|
-
identity: pluginOwnerIdentity(options.plugin, 'permissions', 'claude', options.scope),
|
|
992
|
-
scope: options.scope,
|
|
993
|
-
settingsPath: paths.settingsPath,
|
|
994
|
-
});
|
|
995
|
-
writes.push({
|
|
996
|
-
artifact: { path: paths.settingsPath, kind: 'permission', platform: 'claude' },
|
|
997
|
-
component,
|
|
998
|
-
write: async () => {
|
|
999
|
-
const settings = await readClaudeSettings(paths.settingsPath);
|
|
1000
|
-
rebuildClaudePermissions(settings, createSharedOwnerToken(component.identity), mergeClaudePermissions(permissions));
|
|
1001
|
-
await writeClaudeSettings(paths.settingsPath, settings);
|
|
1002
|
-
},
|
|
1003
|
-
});
|
|
1004
|
-
}
|
|
1005
|
-
return writes;
|
|
499
|
+
function requireObservedCodexNativeState(observation, operation) {
|
|
500
|
+
if (observation.state === 'observed')
|
|
501
|
+
return observation.value;
|
|
502
|
+
const code = observation.state === 'failed'
|
|
503
|
+
? 'codexNativeObservationFailed'
|
|
504
|
+
: 'codexNativeObservationUnavailable';
|
|
505
|
+
throw new Error(`${code}: ${operation} requires Codex plugin list evidence.`);
|
|
1006
506
|
}
|
|
1007
|
-
async function
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
});
|
|
1015
|
-
const dynamicInstructions = dynamic.artifacts.filter((entry) => entry.target === 'codex.developerInstructionsBlock');
|
|
1016
|
-
const dynamicRoles = dynamic.artifacts.filter((entry) => entry.target === 'codex.agentRole');
|
|
1017
|
-
const dynamicSkills = dynamic.artifacts.filter((entry) => entry.target === 'codex.skill');
|
|
1018
|
-
const repoRoot = await resolveRepoRoot(options.cwd);
|
|
1019
|
-
if (options.scope === 'user') {
|
|
1020
|
-
writes.push(...await buildBundledCodexSkillWrites({
|
|
1021
|
-
plugin: options.plugin,
|
|
1022
|
-
env: options.env,
|
|
1023
|
-
marketplaceRoot: options.marketplaceRoot,
|
|
1024
|
-
}));
|
|
1025
|
-
}
|
|
1026
|
-
const skillRoot = options.scope === 'user'
|
|
1027
|
-
? path.join(getCodexHome(options.env), 'skills')
|
|
1028
|
-
: path.join(repoRoot, '.agents', 'skills');
|
|
1029
|
-
for (const artifact of dynamicSkills) {
|
|
1030
|
-
const tree = await createCodexSkillExpectedTree({
|
|
1031
|
-
artifact,
|
|
1032
|
-
sourceDirs: dynamic.sourceDirs(artifact),
|
|
1033
|
-
requireReadme: true,
|
|
1034
|
-
requirementsReceipt: requirementsReceipt(options.plugin),
|
|
1035
|
-
sourceRequirementsReceiptPolicy: 'allow',
|
|
1036
|
-
});
|
|
1037
|
-
writes.push(dynamicSkillWrite({
|
|
1038
|
-
...options,
|
|
1039
|
-
platform: 'codex',
|
|
1040
|
-
artifact,
|
|
1041
|
-
skillPath: path.join(skillRoot, artifact.skillKey),
|
|
1042
|
-
allowedRoot: skillRoot,
|
|
1043
|
-
tree,
|
|
1044
|
-
}));
|
|
1045
|
-
}
|
|
1046
|
-
const staticInstructions = dynamicInstructions.length > 0
|
|
1047
|
-
? []
|
|
1048
|
-
: resolvePlatformEntries(options.plugin.manifest.extensions?.instructions, 'codex');
|
|
1049
|
-
const hasInstructionOutput = dynamicInstructions.length > 0 || staticInstructions.length > 0;
|
|
1050
|
-
if (hasInstructionOutput) {
|
|
1051
|
-
const component = createCodexInstructionComponent({
|
|
1052
|
-
identity: pluginOwnerIdentity(options.plugin, 'developer-instructions', 'codex', options.scope),
|
|
1053
|
-
scope: options.scope,
|
|
1054
|
-
configPath: paths.configTomlPath,
|
|
1055
|
-
});
|
|
1056
|
-
const dynamicBlock = dynamicInstructions.length > 0
|
|
1057
|
-
? composeManagedDeveloperInstructionsBlock(options.plugin.manifest.name, dynamicInstructions
|
|
1058
|
-
.filter((entry) => entry.state === 'present')
|
|
1059
|
-
.map((entry) => ({ artifactId: entry.id, value: entry.content })))
|
|
1060
|
-
: undefined;
|
|
1061
|
-
const block = dynamicBlock?.value
|
|
1062
|
-
? { ...dynamicBlock, pluginName: createSharedOwnerToken(component.identity) }
|
|
1063
|
-
: staticInstructions.length > 0
|
|
1064
|
-
? {
|
|
1065
|
-
pluginName: createSharedOwnerToken(component.identity),
|
|
1066
|
-
value: renderCodexManagedInstructionBlock(options.plugin.manifest.name, staticInstructions),
|
|
1067
|
-
}
|
|
1068
|
-
: undefined;
|
|
1069
|
-
for (const artifact of dynamicInstructions.length > 0 ? dynamicInstructions : [{
|
|
1070
|
-
id: undefined,
|
|
1071
|
-
target: undefined,
|
|
1072
|
-
state: 'present',
|
|
1073
|
-
refreshKeys: [],
|
|
1074
|
-
configDigest: undefined,
|
|
1075
|
-
disabledReason: undefined,
|
|
1076
|
-
}]) {
|
|
1077
|
-
writes.push({
|
|
1078
|
-
artifact: {
|
|
1079
|
-
path: paths.configTomlPath,
|
|
1080
|
-
kind: 'instruction',
|
|
1081
|
-
platform: 'codex',
|
|
1082
|
-
...(artifact.id ? { id: artifact.id } : {}),
|
|
1083
|
-
...(artifact.target ? { target: artifact.target } : {}),
|
|
1084
|
-
state: artifact.state,
|
|
1085
|
-
refreshKeys: [...artifact.refreshKeys],
|
|
1086
|
-
...(artifact.configDigest ? { configDigest: artifact.configDigest } : {}),
|
|
1087
|
-
...(artifact.disabledReason ? { disabledReason: artifact.disabledReason } : {}),
|
|
1088
|
-
},
|
|
1089
|
-
...(block ? { component } : {}),
|
|
1090
|
-
write: async () => {
|
|
1091
|
-
await applyCodexConfigTransactionFile(paths.configTomlPath, block
|
|
1092
|
-
? { upsertManagedInstructionBlock: block }
|
|
1093
|
-
: { removeManagedInstructionPluginName: createSharedOwnerToken(component.identity) });
|
|
1094
|
-
},
|
|
1095
|
-
});
|
|
1096
|
-
}
|
|
1097
|
-
}
|
|
1098
|
-
for (const artifact of dynamicRoles) {
|
|
1099
|
-
const roleKey = artifact.roleKey;
|
|
1100
|
-
const rolePath = path.join(paths.configDir, 'agents', `${buildGeneratedName(options.plugin.manifest.name, roleKey)}.toml`);
|
|
1101
|
-
const roleComponent = pathComponent({
|
|
1102
|
-
kind: 'owned-text-file',
|
|
1103
|
-
path: rolePath,
|
|
1104
|
-
allowedRoot: paths.configDir,
|
|
1105
|
-
identity: pluginOwnerIdentity(options.plugin, roleKey, 'codex', options.scope),
|
|
1106
|
-
});
|
|
1107
|
-
const registrationComponent = createCodexRoleRegistrationComponent({
|
|
1108
|
-
identity: pluginOwnerIdentity(options.plugin, internalArtifactKey('role', roleKey), 'codex', options.scope),
|
|
1109
|
-
fileIdentity: roleComponent.identity,
|
|
1110
|
-
configPath: paths.configTomlPath,
|
|
1111
|
-
roleKey,
|
|
1112
|
-
rolePath,
|
|
1113
|
-
});
|
|
1114
|
-
const roleFile = artifact.content?.roleFile;
|
|
1115
|
-
const description = artifact.content?.registration?.description
|
|
1116
|
-
?? roleFile?.description;
|
|
1117
|
-
const present = artifact.state === 'present';
|
|
1118
|
-
if (present && (!description || !roleFile?.developer_instructions)) {
|
|
1119
|
-
throw new Error(`Artifact "${artifact.id}" 的 codex.agentRole 缺少 description 或 developer_instructions。`);
|
|
1120
|
-
}
|
|
1121
|
-
writes.push({
|
|
1122
|
-
artifact: {
|
|
1123
|
-
path: rolePath,
|
|
1124
|
-
paths: [paths.configTomlPath, rolePath],
|
|
1125
|
-
kind: 'agent',
|
|
1126
|
-
platform: 'codex',
|
|
1127
|
-
artifactKey: roleKey,
|
|
1128
|
-
roleKey,
|
|
1129
|
-
id: artifact.id,
|
|
1130
|
-
target: artifact.target,
|
|
1131
|
-
state: artifact.state,
|
|
1132
|
-
refreshKeys: [...artifact.refreshKeys],
|
|
1133
|
-
configDigest: artifact.configDigest,
|
|
1134
|
-
...(artifact.disabledReason ? { disabledReason: artifact.disabledReason } : {}),
|
|
1135
|
-
},
|
|
1136
|
-
...(present ? { component: roleComponent } : {}),
|
|
1137
|
-
...(present ? { additionalComponents: [registrationComponent] } : {}),
|
|
1138
|
-
write: async () => {
|
|
1139
|
-
if (!present) {
|
|
1140
|
-
return;
|
|
1141
|
-
}
|
|
1142
|
-
await fs.ensureDir(paths.configDir);
|
|
1143
|
-
await writeOwnedTextFile({
|
|
1144
|
-
path: rolePath,
|
|
1145
|
-
allowedRoot: paths.configDir,
|
|
1146
|
-
identity: roleComponent.identity,
|
|
1147
|
-
content: renderCodexRole({
|
|
1148
|
-
roleKey,
|
|
1149
|
-
description: description,
|
|
1150
|
-
developerInstructions: roleFile.developer_instructions,
|
|
1151
|
-
model: roleFile.model,
|
|
1152
|
-
modelReasoningEffort: roleFile.model_reasoning_effort,
|
|
1153
|
-
}),
|
|
1154
|
-
});
|
|
1155
|
-
const registration = {
|
|
1156
|
-
description,
|
|
1157
|
-
configFile: path.relative(path.dirname(paths.configTomlPath), rolePath).split(path.sep).join('/'),
|
|
1158
|
-
};
|
|
1159
|
-
await applyConditionalCodexConfigTransactionFile(paths.configTomlPath, async (snapshot) => {
|
|
1160
|
-
const actual = snapshot.agents[roleKey];
|
|
1161
|
-
if (actual && !await codexRoleRegistrationOwned({
|
|
1162
|
-
fileIdentity: roleComponent.identity,
|
|
1163
|
-
configPath: paths.configTomlPath,
|
|
1164
|
-
roleKey,
|
|
1165
|
-
rolePath,
|
|
1166
|
-
registration: actual,
|
|
1167
|
-
})) {
|
|
1168
|
-
throw new Error(`Codex agent registration "${roleKey}" is foreign and cannot be overwritten by plugin "${options.plugin.manifest.name}".`);
|
|
1169
|
-
}
|
|
1170
|
-
return { upsertAgentRegistrations: { [roleKey]: registration } };
|
|
1171
|
-
});
|
|
1172
|
-
},
|
|
1173
|
-
});
|
|
1174
|
-
}
|
|
1175
|
-
for (const artifact of generateCodexPermissionArtifacts(options.plugin.manifest.name, resolvePlatformEntries(options.plugin.manifest.extensions?.permissions, 'codex'))) {
|
|
1176
|
-
writes.push(generatedTextWrite({
|
|
1177
|
-
...options,
|
|
1178
|
-
platform: 'codex',
|
|
1179
|
-
configDir: paths.configDir,
|
|
1180
|
-
relativePath: artifact.relativePath,
|
|
1181
|
-
artifactKey: artifact.artifactKey,
|
|
1182
|
-
content: artifact.content,
|
|
1183
|
-
kind: 'permission',
|
|
1184
|
-
}));
|
|
1185
|
-
}
|
|
1186
|
-
for (const artifact of generateAgentArtifacts(options.plugin.manifest.name, resolvePlatformEntries(options.plugin.manifest.extensions?.agents, 'codex'), 'codex')) {
|
|
1187
|
-
writes.push(generatedTextWrite({
|
|
1188
|
-
...options,
|
|
1189
|
-
platform: 'codex',
|
|
1190
|
-
configDir: paths.configDir,
|
|
1191
|
-
relativePath: artifact.relativePath,
|
|
1192
|
-
artifactKey: artifact.artifactKey,
|
|
1193
|
-
content: artifact.content,
|
|
1194
|
-
kind: 'agent',
|
|
1195
|
-
}));
|
|
1196
|
-
}
|
|
1197
|
-
const codexPluginId = `${options.plugin.manifest.name}@${options.marketplaceName ?? options.plugin.marketplaceName ?? MARKETPLACE_NAME}`;
|
|
1198
|
-
const nativeSurface = analyzeCodexSurface(options.plugin.manifest).nativeKinds.length > 0;
|
|
1199
|
-
const userActivationDesired = options.scope === 'user'
|
|
1200
|
-
|| options.userActivationDesired?.has(codexPluginId) === true;
|
|
1201
|
-
for (const activation of !nativeSurface ? [] : options.scope === 'project'
|
|
1202
|
-
? [
|
|
1203
|
-
{
|
|
1204
|
-
scope: 'user',
|
|
1205
|
-
desired: userActivationDesired,
|
|
1206
|
-
configPath: resolveCodexPaths(options.cwd, 'user', options.env).configTomlPath,
|
|
1207
|
-
},
|
|
1208
|
-
{ scope: 'project', desired: true, configPath: paths.configTomlPath },
|
|
1209
|
-
]
|
|
1210
|
-
: [{ scope: 'user', desired: true, configPath: paths.configTomlPath }]) {
|
|
1211
|
-
const component = createCodexActivationComponent({
|
|
1212
|
-
identity: pluginOwnerIdentity(options.plugin, internalArtifactKey('activation', activation.scope), 'codex', options.scope),
|
|
1213
|
-
configPath: activation.configPath,
|
|
1214
|
-
codexPluginId,
|
|
1215
|
-
desired: activation.desired,
|
|
1216
|
-
});
|
|
1217
|
-
writes.push({
|
|
1218
|
-
artifact: {
|
|
1219
|
-
path: activation.configPath,
|
|
1220
|
-
kind: 'instruction',
|
|
1221
|
-
platform: 'codex',
|
|
1222
|
-
artifactKey: internalArtifactKey('activation', activation.scope),
|
|
1223
|
-
},
|
|
1224
|
-
component,
|
|
1225
|
-
write: async () => {
|
|
1226
|
-
await applyCodexConfigTransactionFile(activation.configPath, {
|
|
1227
|
-
upsertPluginActivations: { [codexPluginId]: activation.desired },
|
|
1228
|
-
});
|
|
1229
|
-
},
|
|
1230
|
-
});
|
|
1231
|
-
}
|
|
1232
|
-
return writes;
|
|
1233
|
-
}
|
|
1234
|
-
async function buildInspectionWrites(options) {
|
|
1235
|
-
const writes = [];
|
|
1236
|
-
if (options.platform === 'claude') {
|
|
1237
|
-
const paths = resolveClaudePaths(options.cwd, options.scope, options.env);
|
|
1238
|
-
for (const artifact of generateInstructionArtifacts(options.plugin.manifest.name, resolvePlatformEntries(options.plugin.manifest.extensions?.instructions, 'claude'), 'claude')) {
|
|
1239
|
-
writes.push(generatedTextWrite({
|
|
1240
|
-
...options,
|
|
1241
|
-
configDir: paths.configDir,
|
|
1242
|
-
relativePath: artifact.relativePath,
|
|
1243
|
-
artifactKey: artifact.artifactKey,
|
|
1244
|
-
content: artifact.content,
|
|
1245
|
-
kind: 'instruction',
|
|
1246
|
-
}));
|
|
1247
|
-
}
|
|
1248
|
-
if (resolvePlatformEntries(options.plugin.manifest.extensions?.permissions, 'claude').length > 0) {
|
|
1249
|
-
writes.push({
|
|
1250
|
-
artifact: { path: paths.settingsPath, kind: 'permission', platform: 'claude' },
|
|
1251
|
-
component: createClaudePermissionsComponent({
|
|
1252
|
-
identity: pluginOwnerIdentity(options.plugin, 'permissions', 'claude', options.scope),
|
|
1253
|
-
scope: options.scope,
|
|
1254
|
-
settingsPath: paths.settingsPath,
|
|
1255
|
-
}),
|
|
1256
|
-
write: async () => undefined,
|
|
1257
|
-
});
|
|
1258
|
-
}
|
|
1259
|
-
for (const target of options.plugin.manifest.artifacts?.targets ?? []) {
|
|
1260
|
-
if (target.platform !== 'claude'
|
|
1261
|
-
|| !target.scopes.includes(options.scope)
|
|
1262
|
-
|| target.target !== 'claude.skill'
|
|
1263
|
-
|| !target.skillKey)
|
|
1264
|
-
continue;
|
|
1265
|
-
const state = target.states.includes('present') ? 'present' : 'disabled';
|
|
1266
|
-
const skillPath = path.join(paths.configDir, 'skills', target.skillKey);
|
|
1267
|
-
const component = pathComponent({
|
|
1268
|
-
kind: 'skill-directory',
|
|
1269
|
-
path: skillPath,
|
|
1270
|
-
allowedRoot: path.dirname(skillPath),
|
|
1271
|
-
identity: ownerIdentity(options.plugin.manifest.name, target.skillKey, 'claude', options.scope),
|
|
1272
|
-
});
|
|
1273
|
-
writes.push({
|
|
1274
|
-
artifact: {
|
|
1275
|
-
path: skillPath,
|
|
1276
|
-
kind: 'skill',
|
|
1277
|
-
platform: 'claude',
|
|
1278
|
-
artifactKey: target.skillKey,
|
|
1279
|
-
id: target.id,
|
|
1280
|
-
target: target.target,
|
|
1281
|
-
state,
|
|
1282
|
-
},
|
|
1283
|
-
...(state === 'present' ? { component } : {}),
|
|
1284
|
-
...(target.states.includes('present') && target.states.includes('disabled')
|
|
1285
|
-
? { optional: true }
|
|
1286
|
-
: {}),
|
|
1287
|
-
write: async () => undefined,
|
|
1288
|
-
});
|
|
1289
|
-
}
|
|
1290
|
-
return writes;
|
|
507
|
+
export async function inspectCodexPluginRegistrationLive(options) {
|
|
508
|
+
if (!options.nativeCliRunner) {
|
|
509
|
+
return {
|
|
510
|
+
observation: { state: 'unobserved' },
|
|
511
|
+
observations: { user: false, project: false },
|
|
512
|
+
activations: {},
|
|
513
|
+
};
|
|
1291
514
|
}
|
|
1292
|
-
const
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
writes.push(...await buildBundledCodexSkillWrites({
|
|
1296
|
-
plugin: options.plugin,
|
|
515
|
+
const ownedSession = options.observationSession ? undefined
|
|
516
|
+
: await createCodexNativeObservationSession({
|
|
517
|
+
exactCwd: options.cwd,
|
|
1297
518
|
env: options.env,
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
}
|
|
1301
|
-
const instructions = resolvePlatformEntries(options.plugin.manifest.extensions?.instructions, 'codex');
|
|
1302
|
-
const targets = (options.plugin.manifest.artifacts?.targets ?? []).filter((target) => target.platform === 'codex' && target.scopes.includes(options.scope));
|
|
1303
|
-
const instructionTargets = targets.filter((target) => target.target === 'codex.developerInstructionsBlock');
|
|
1304
|
-
const presentCapableInstructionTargets = instructionTargets.filter((target) => target.states.includes('present'));
|
|
1305
|
-
const instructionDesired = presentCapableInstructionTargets.length > 0;
|
|
1306
|
-
const instructionOptional = presentCapableInstructionTargets.length > 0
|
|
1307
|
-
&& presentCapableInstructionTargets.every((target) => target.states.includes('disabled'));
|
|
1308
|
-
if (instructions.length > 0 || instructionDesired) {
|
|
1309
|
-
writes.push({
|
|
1310
|
-
artifact: { path: paths.configTomlPath, kind: 'instruction', platform: 'codex' },
|
|
1311
|
-
component: createCodexInstructionComponent({
|
|
1312
|
-
identity: pluginOwnerIdentity(options.plugin, 'developer-instructions', 'codex', options.scope),
|
|
1313
|
-
scope: options.scope,
|
|
1314
|
-
configPath: paths.configTomlPath,
|
|
1315
|
-
}),
|
|
1316
|
-
...(instructions.length === 0 && instructionOptional ? { optional: true } : {}),
|
|
1317
|
-
write: async () => undefined,
|
|
519
|
+
runner: options.nativeCliRunner,
|
|
520
|
+
manager: options.manager ?? SYSTEM_CODEX_MANAGER,
|
|
1318
521
|
});
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
const state = target.states.includes('present') ? 'present' : 'disabled';
|
|
1325
|
-
if (target.target === 'codex.skill' && target.skillKey) {
|
|
1326
|
-
const skillPath = path.join(dynamicSkillRoot, target.skillKey);
|
|
1327
|
-
const component = pathComponent({
|
|
1328
|
-
kind: 'skill-directory',
|
|
1329
|
-
path: skillPath,
|
|
1330
|
-
allowedRoot: dynamicSkillRoot,
|
|
1331
|
-
identity: ownerIdentity(options.plugin.manifest.name, target.skillKey, 'codex', options.scope),
|
|
1332
|
-
});
|
|
1333
|
-
writes.push({
|
|
1334
|
-
artifact: {
|
|
1335
|
-
path: skillPath,
|
|
1336
|
-
kind: 'skill',
|
|
1337
|
-
platform: 'codex',
|
|
1338
|
-
artifactKey: target.skillKey,
|
|
1339
|
-
id: target.id,
|
|
1340
|
-
target: target.target,
|
|
1341
|
-
state,
|
|
1342
|
-
},
|
|
1343
|
-
...(state === 'present' ? { component } : {}),
|
|
1344
|
-
...(target.states.includes('present') && target.states.includes('disabled')
|
|
1345
|
-
? { optional: true }
|
|
1346
|
-
: {}),
|
|
1347
|
-
write: async () => undefined,
|
|
1348
|
-
});
|
|
1349
|
-
}
|
|
1350
|
-
if (target.target === 'codex.agentRole' && target.roleKey) {
|
|
1351
|
-
const rolePath = path.join(paths.configDir, 'agents', `${buildGeneratedName(options.plugin.manifest.name, target.roleKey)}.toml`);
|
|
1352
|
-
const roleComponent = pathComponent({
|
|
1353
|
-
kind: 'owned-text-file',
|
|
1354
|
-
path: rolePath,
|
|
1355
|
-
allowedRoot: paths.configDir,
|
|
1356
|
-
identity: pluginOwnerIdentity(options.plugin, target.roleKey, 'codex', options.scope),
|
|
1357
|
-
});
|
|
1358
|
-
const registrationComponent = createCodexRoleRegistrationComponent({
|
|
1359
|
-
identity: pluginOwnerIdentity(options.plugin, internalArtifactKey('role', target.roleKey), 'codex', options.scope),
|
|
1360
|
-
fileIdentity: pluginOwnerIdentity(options.plugin, target.roleKey, 'codex', options.scope),
|
|
1361
|
-
configPath: paths.configTomlPath,
|
|
1362
|
-
roleKey: target.roleKey,
|
|
1363
|
-
rolePath,
|
|
1364
|
-
});
|
|
1365
|
-
writes.push({
|
|
1366
|
-
artifact: {
|
|
1367
|
-
path: rolePath,
|
|
1368
|
-
kind: 'agent',
|
|
1369
|
-
platform: 'codex',
|
|
1370
|
-
artifactKey: target.roleKey,
|
|
1371
|
-
roleKey: target.roleKey,
|
|
1372
|
-
id: target.id,
|
|
1373
|
-
target: target.target,
|
|
1374
|
-
state,
|
|
1375
|
-
},
|
|
1376
|
-
...(state === 'present'
|
|
1377
|
-
? { component: roleComponent, additionalComponents: [registrationComponent] }
|
|
1378
|
-
: {}),
|
|
1379
|
-
...(target.states.includes('present') && target.states.includes('disabled')
|
|
1380
|
-
? { optional: true }
|
|
1381
|
-
: {}),
|
|
1382
|
-
write: async () => undefined,
|
|
1383
|
-
});
|
|
1384
|
-
}
|
|
1385
|
-
}
|
|
1386
|
-
for (const artifact of generateCodexPermissionArtifacts(options.plugin.manifest.name, resolvePlatformEntries(options.plugin.manifest.extensions?.permissions, 'codex'))) {
|
|
1387
|
-
writes.push(generatedTextWrite({
|
|
1388
|
-
...options,
|
|
1389
|
-
configDir: paths.configDir,
|
|
1390
|
-
relativePath: artifact.relativePath,
|
|
1391
|
-
artifactKey: artifact.artifactKey,
|
|
1392
|
-
content: artifact.content,
|
|
1393
|
-
kind: 'permission',
|
|
1394
|
-
}));
|
|
1395
|
-
}
|
|
1396
|
-
for (const artifact of generateAgentArtifacts(options.plugin.manifest.name, resolvePlatformEntries(options.plugin.manifest.extensions?.agents, 'codex'), 'codex')) {
|
|
1397
|
-
writes.push(generatedTextWrite({
|
|
1398
|
-
...options,
|
|
1399
|
-
configDir: paths.configDir,
|
|
1400
|
-
relativePath: artifact.relativePath,
|
|
1401
|
-
artifactKey: artifact.artifactKey,
|
|
1402
|
-
content: artifact.content,
|
|
1403
|
-
kind: 'agent',
|
|
1404
|
-
}));
|
|
1405
|
-
}
|
|
1406
|
-
const nativeSurface = analyzeCodexSurface(options.plugin.manifest).nativeKinds.length > 0;
|
|
1407
|
-
const codexPluginId = `${options.plugin.manifest.name}@${options.marketplaceName ?? options.plugin.marketplaceName ?? MARKETPLACE_NAME}`;
|
|
1408
|
-
const userActivationDesired = options.scope === 'user'
|
|
1409
|
-
|| options.userActivationDesired?.has(codexPluginId) === true;
|
|
1410
|
-
for (const activation of !nativeSurface ? [] : options.scope === 'project'
|
|
1411
|
-
? [
|
|
1412
|
-
{
|
|
1413
|
-
scope: 'user',
|
|
1414
|
-
desired: userActivationDesired,
|
|
1415
|
-
configPath: resolveCodexPaths(options.cwd, 'user', options.env).configTomlPath,
|
|
1416
|
-
},
|
|
1417
|
-
{ scope: 'project', desired: true, configPath: paths.configTomlPath },
|
|
1418
|
-
]
|
|
1419
|
-
: [{ scope: 'user', desired: true, configPath: paths.configTomlPath }]) {
|
|
1420
|
-
writes.push({
|
|
1421
|
-
artifact: {
|
|
1422
|
-
path: activation.configPath,
|
|
1423
|
-
kind: 'instruction',
|
|
1424
|
-
platform: 'codex',
|
|
1425
|
-
artifactKey: internalArtifactKey('activation', activation.scope),
|
|
1426
|
-
},
|
|
1427
|
-
component: createCodexActivationComponent({
|
|
1428
|
-
identity: pluginOwnerIdentity(options.plugin, internalArtifactKey('activation', activation.scope), 'codex', options.scope),
|
|
1429
|
-
configPath: activation.configPath,
|
|
1430
|
-
codexPluginId,
|
|
1431
|
-
desired: activation.desired,
|
|
1432
|
-
}),
|
|
1433
|
-
write: async () => undefined,
|
|
522
|
+
const session = options.observationSession ?? ownedSession;
|
|
523
|
+
try {
|
|
524
|
+
const inspected = await session.inspectPlugin({
|
|
525
|
+
pluginId: options.pluginId,
|
|
526
|
+
scope: options.scope ?? 'both',
|
|
1434
527
|
});
|
|
528
|
+
return {
|
|
529
|
+
observation: inspected.observation,
|
|
530
|
+
observations: inspected.observations,
|
|
531
|
+
activations: inspected.activations,
|
|
532
|
+
};
|
|
1435
533
|
}
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
:
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
534
|
+
finally {
|
|
535
|
+
await ownedSession?.dispose();
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
export async function removeCodexPluginActivation(options) {
|
|
539
|
+
await applyConditionalCodexConfigTransactionFile(options.configPath, (snapshot) => Object.hasOwn(snapshot.plugins, options.codexPluginId)
|
|
540
|
+
? { removePluginActivations: [options.codexPluginId] }
|
|
541
|
+
: null);
|
|
542
|
+
}
|
|
543
|
+
export async function removeNamespacedMarketplacePluginProjection(options) {
|
|
544
|
+
if (!await isSafeCodexMarketplaceRoot({
|
|
545
|
+
awHome: resolveAwHome(options.env),
|
|
546
|
+
sourceId: options.sourceId,
|
|
547
|
+
marketplaceRoot: options.rootDir,
|
|
548
|
+
})) {
|
|
549
|
+
throw new Error('marketplaceProjectionUnsafe: marketplace root is outside the canonical AW source path.');
|
|
550
|
+
}
|
|
551
|
+
const root = await readStrictNamespacedMarketplaceRoot({
|
|
552
|
+
rootDir: options.rootDir,
|
|
553
|
+
sourceId: options.sourceId,
|
|
554
|
+
sourceIdentity: options.sourceIdentity,
|
|
1450
555
|
});
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
if (options.platform === 'codex'
|
|
1457
|
-
&& artifact.artifactKey !== undefined
|
|
1458
|
-
&& new Set([
|
|
1459
|
-
internalArtifactKey('activation', 'user'),
|
|
1460
|
-
internalArtifactKey('activation', 'project'),
|
|
1461
|
-
]).has(artifact.artifactKey)) {
|
|
1462
|
-
continue;
|
|
1463
|
-
}
|
|
1464
|
-
if (options.command === 'cleanup'
|
|
1465
|
-
&& artifact.kind === 'hook'
|
|
1466
|
-
&& options.platform === 'codex') {
|
|
1467
|
-
for (const identity of artifact.hookGroups ?? []) {
|
|
1468
|
-
components.push(createLegacyCodexHookCleanupComponent({
|
|
1469
|
-
pluginName: options.pluginName,
|
|
1470
|
-
scope: options.scope,
|
|
1471
|
-
hooksPath: path.join(resolveCodexPaths(options.cwd, options.scope, options.env).configDir, 'hooks.json'),
|
|
1472
|
-
identity,
|
|
1473
|
-
}));
|
|
1474
|
-
}
|
|
1475
|
-
continue;
|
|
1476
|
-
}
|
|
1477
|
-
if (options.command === 'cleanup'
|
|
1478
|
-
&& artifact.kind === 'mcpServer'
|
|
1479
|
-
&& options.platform === 'codex'
|
|
1480
|
-
&& artifact.artifactKey) {
|
|
1481
|
-
components.push(createLegacyCodexMcpCleanupComponent({
|
|
1482
|
-
identity: historicalIdentity(internalArtifactKey('mcp', artifact.artifactKey)),
|
|
1483
|
-
configPath: resolveCodexPaths(options.cwd, options.scope, options.env).configTomlPath,
|
|
1484
|
-
serverKey: artifact.artifactKey,
|
|
1485
|
-
}));
|
|
1486
|
-
continue;
|
|
1487
|
-
}
|
|
1488
|
-
if (artifact.kind === 'instruction' && options.platform === 'codex' && !artifact.artifactKey) {
|
|
1489
|
-
components.push(createCodexInstructionComponent({
|
|
1490
|
-
identity: historicalIdentity('developer-instructions'),
|
|
1491
|
-
scope: options.scope,
|
|
1492
|
-
configPath: resolveCodexPaths(options.cwd, options.scope, options.env).configTomlPath,
|
|
1493
|
-
}));
|
|
1494
|
-
continue;
|
|
1495
|
-
}
|
|
1496
|
-
if (artifact.kind === 'permission' && options.platform === 'claude') {
|
|
1497
|
-
components.push(createClaudePermissionsComponent({
|
|
1498
|
-
identity: historicalIdentity('permissions'),
|
|
1499
|
-
scope: options.scope,
|
|
1500
|
-
settingsPath: resolveClaudePaths(options.cwd, options.scope, options.env).settingsPath,
|
|
1501
|
-
}));
|
|
1502
|
-
continue;
|
|
1503
|
-
}
|
|
1504
|
-
if (artifact.target === 'codex.agentRole'
|
|
1505
|
-
&& options.platform === 'codex'
|
|
1506
|
-
&& (artifact.roleKey || artifact.artifactKey)) {
|
|
1507
|
-
const roleKey = artifact.roleKey ?? artifact.artifactKey;
|
|
1508
|
-
components.push(createCodexRoleRegistrationComponent({
|
|
1509
|
-
identity: historicalIdentity(internalArtifactKey('role', roleKey)),
|
|
1510
|
-
fileIdentity: historicalIdentity(roleKey),
|
|
1511
|
-
configPath: resolveCodexPaths(options.cwd, options.scope, options.env).configTomlPath,
|
|
1512
|
-
roleKey,
|
|
1513
|
-
rolePath: artifact.path,
|
|
1514
|
-
}));
|
|
1515
|
-
}
|
|
1516
|
-
if (!artifact.artifactKey)
|
|
1517
|
-
continue;
|
|
1518
|
-
const identity = ownerIdentity(options.pluginName, artifact.artifactKey, options.platform, options.scope);
|
|
1519
|
-
components.push(pathComponent({
|
|
1520
|
-
kind: artifact.kind === 'skill' ? 'skill-directory' : 'owned-text-file',
|
|
1521
|
-
path: artifact.path,
|
|
1522
|
-
allowedRoot: artifact.kind === 'skill' ? path.dirname(artifact.path) : paths.configDir,
|
|
1523
|
-
identity,
|
|
1524
|
-
}));
|
|
1525
|
-
}
|
|
1526
|
-
return components;
|
|
1527
|
-
}
|
|
1528
|
-
function isAbsentCodexResiduePath(error) {
|
|
1529
|
-
const code = error.code;
|
|
1530
|
-
return code === 'ENOENT';
|
|
1531
|
-
}
|
|
1532
|
-
async function lstatCodexResidueIfPresent(filePath) {
|
|
1533
|
-
return fs.lstat(filePath).catch((error) => {
|
|
1534
|
-
if (isAbsentCodexResiduePath(error))
|
|
556
|
+
if (!root)
|
|
557
|
+
return;
|
|
558
|
+
const pluginRoot = await assertSafeNamespacedMarketplacePluginRoot(options.rootDir, options.pluginName);
|
|
559
|
+
const pluginStats = await fs.lstat(pluginRoot).catch((error) => {
|
|
560
|
+
if (error.code === 'ENOENT')
|
|
1535
561
|
return null;
|
|
1536
562
|
throw error;
|
|
1537
563
|
});
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
const stats = await lstatCodexResidueIfPresent(directory);
|
|
1541
|
-
if (!stats)
|
|
1542
|
-
return [];
|
|
1543
|
-
if (!stats.isDirectory() || stats.isSymbolicLink()) {
|
|
1544
|
-
throw new Error(`Codex residue root is not a canonical directory: ${directory}`);
|
|
564
|
+
if (pluginStats && (!pluginStats.isDirectory() || pluginStats.isSymbolicLink())) {
|
|
565
|
+
throw new Error('marketplaceProjectionUnsafe: plugin projection is not a regular directory.');
|
|
1545
566
|
}
|
|
1546
|
-
|
|
1547
|
-
}
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
const
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
(canonicalMarketplace ? labels : foreignLabels).push(`${configPath}#plugins.${pluginId}`);
|
|
1569
|
-
}
|
|
1570
|
-
const inspectManifest = async (manifestPath, kind, directoryVersion) => {
|
|
1571
|
-
const stats = await lstatCodexResidueIfPresent(manifestPath);
|
|
1572
|
-
if (!stats)
|
|
1573
|
-
return;
|
|
1574
|
-
if (!stats.isFile() || stats.isSymbolicLink()) {
|
|
1575
|
-
foreignLabels.push(manifestPath);
|
|
1576
|
-
return;
|
|
1577
|
-
}
|
|
1578
|
-
const manifest = await fs.readJson(manifestPath);
|
|
1579
|
-
const identity = manifest?.id ?? manifest?.name;
|
|
1580
|
-
const version = typeof manifest?.version === 'string' ? manifest.version : null;
|
|
1581
|
-
if (!canonicalMarketplace
|
|
1582
|
-
|| (identity !== options.pluginName && identity !== pluginId)
|
|
1583
|
-
|| !version
|
|
1584
|
-
|| (directoryVersion !== undefined && version !== directoryVersion)) {
|
|
1585
|
-
foreignLabels.push(manifestPath);
|
|
1586
|
-
return;
|
|
1587
|
-
}
|
|
1588
|
-
labels.push(manifestPath);
|
|
1589
|
-
versions.add(version);
|
|
1590
|
-
(kind === 'installed' ? installedVersions : cacheVersions).add(version);
|
|
1591
|
-
};
|
|
1592
|
-
for (const entry of await readdirCodexResidueIfPresent(cacheRoot)) {
|
|
1593
|
-
if (!entry.isDirectory() || entry.isSymbolicLink()) {
|
|
1594
|
-
foreignLabels.push(path.join(cacheRoot, entry.name));
|
|
1595
|
-
continue;
|
|
1596
|
-
}
|
|
1597
|
-
const versionRoot = path.join(cacheRoot, entry.name);
|
|
1598
|
-
const candidates = [
|
|
1599
|
-
path.join(versionRoot, 'plugin.json'),
|
|
1600
|
-
path.join(versionRoot, '.codex-plugin', 'plugin.json'),
|
|
1601
|
-
];
|
|
1602
|
-
const existing = [];
|
|
1603
|
-
for (const candidate of candidates) {
|
|
1604
|
-
if (await lstatCodexResidueIfPresent(candidate))
|
|
1605
|
-
existing.push(candidate);
|
|
567
|
+
const manifests = [
|
|
568
|
+
{ value: root.agentsManifest, path: path.join(options.rootDir, '.agents', 'plugins', 'marketplace.json') },
|
|
569
|
+
...(root.claudeManifest
|
|
570
|
+
? [{ value: root.claudeManifest, path: path.join(options.rootDir, '.claude-plugin', 'marketplace.json') }]
|
|
571
|
+
: []),
|
|
572
|
+
];
|
|
573
|
+
const hasEntry = manifests.some(({ value }) => Array.isArray(value.plugins)
|
|
574
|
+
&& value.plugins.some((entry) => entry !== null && typeof entry === 'object'
|
|
575
|
+
&& entry.name === options.pluginName));
|
|
576
|
+
let hasIdentityManifest = false;
|
|
577
|
+
if (pluginStats) {
|
|
578
|
+
for (const manifestName of ['.agents-plugin/plugin.json', '.codex-plugin/plugin.json']) {
|
|
579
|
+
const manifestPath = path.join(pluginRoot, manifestName);
|
|
580
|
+
const manifest = await fs.readJson(manifestPath).catch((error) => {
|
|
581
|
+
if (error.code === 'ENOENT')
|
|
582
|
+
return null;
|
|
583
|
+
throw error;
|
|
584
|
+
});
|
|
585
|
+
if (manifest && manifest.name !== options.pluginName) {
|
|
586
|
+
throw new Error('marketplaceProjectionIdentityMismatch: plugin projection has a foreign name.');
|
|
587
|
+
}
|
|
588
|
+
hasIdentityManifest ||= manifest?.name === options.pluginName;
|
|
1606
589
|
}
|
|
1607
|
-
if (
|
|
1608
|
-
|
|
1609
|
-
for (const candidate of existing)
|
|
1610
|
-
await inspectManifest(candidate, 'cache', entry.name);
|
|
1611
|
-
}
|
|
1612
|
-
const installedStats = await lstatCodexResidueIfPresent(installedRoot);
|
|
1613
|
-
if (installedStats && (!installedStats.isDirectory() || installedStats.isSymbolicLink())) {
|
|
1614
|
-
foreignLabels.push(installedRoot);
|
|
1615
|
-
}
|
|
1616
|
-
else if (installedStats) {
|
|
1617
|
-
await inspectManifest(installedManifest, 'installed');
|
|
1618
|
-
}
|
|
1619
|
-
return foreignLabels.length > 0
|
|
1620
|
-
? {
|
|
1621
|
-
state: 'foreign', labels: [...labels, ...foreignLabels], versions: [...versions],
|
|
1622
|
-
installedVersions: [...installedVersions], cacheVersions: [...cacheVersions],
|
|
1623
|
-
enabled: configEntry?.enabled === true,
|
|
590
|
+
if (!hasEntry && !hasIdentityManifest) {
|
|
591
|
+
throw new Error('marketplaceProjectionIdentityUnavailable: plugin directory has no matching marketplace entry or plugin manifest.');
|
|
1624
592
|
}
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
};
|
|
1635
|
-
}
|
|
1636
|
-
function isPathWithin(root, candidate) {
|
|
1637
|
-
const relative = path.relative(path.resolve(root), path.resolve(candidate));
|
|
1638
|
-
return relative === '' || (!relative.startsWith(`..${path.sep}`) && relative !== '..' && !path.isAbsolute(relative));
|
|
1639
|
-
}
|
|
1640
|
-
async function codexPayloadPathSafe(payloadRoot) {
|
|
1641
|
-
const rootStats = await lstatCodexResidueIfPresent(payloadRoot);
|
|
1642
|
-
if (!rootStats?.isDirectory() || rootStats.isSymbolicLink())
|
|
1643
|
-
return false;
|
|
1644
|
-
const pending = [payloadRoot];
|
|
1645
|
-
while (pending.length > 0) {
|
|
1646
|
-
const current = pending.pop();
|
|
1647
|
-
for (const entry of await fs.readdir(current, { withFileTypes: true })) {
|
|
1648
|
-
const entryPath = path.join(current, entry.name);
|
|
1649
|
-
if (entry.isSymbolicLink()) {
|
|
1650
|
-
const target = path.resolve(path.dirname(entryPath), await fs.readlink(entryPath));
|
|
1651
|
-
if (!isPathWithin(payloadRoot, target))
|
|
1652
|
-
return false;
|
|
1653
|
-
}
|
|
1654
|
-
else if (entry.isDirectory()) {
|
|
1655
|
-
pending.push(entryPath);
|
|
1656
|
-
}
|
|
1657
|
-
else if (!entry.isFile()) {
|
|
1658
|
-
return false;
|
|
593
|
+
}
|
|
594
|
+
if (pluginStats) {
|
|
595
|
+
const inspectTree = async (directory) => {
|
|
596
|
+
for (const entry of await fs.readdir(directory, { withFileTypes: true })) {
|
|
597
|
+
if (entry.isSymbolicLink() || (!entry.isDirectory() && !entry.isFile())) {
|
|
598
|
+
throw new Error('marketplaceProjectionUnsafe: plugin projection contains an unsafe node.');
|
|
599
|
+
}
|
|
600
|
+
if (entry.isDirectory())
|
|
601
|
+
await inspectTree(path.join(directory, entry.name));
|
|
1659
602
|
}
|
|
603
|
+
};
|
|
604
|
+
await inspectTree(pluginRoot);
|
|
605
|
+
await fs.remove(pluginRoot);
|
|
606
|
+
}
|
|
607
|
+
for (const manifest of manifests) {
|
|
608
|
+
if (!Array.isArray(manifest.value.plugins)) {
|
|
609
|
+
throw new Error('marketplaceProjectionInvalid: marketplace plugins are not an array.');
|
|
610
|
+
}
|
|
611
|
+
const plugins = manifest.value.plugins.filter((entry) => entry === null
|
|
612
|
+
|| typeof entry !== 'object'
|
|
613
|
+
|| entry.name !== options.pluginName);
|
|
614
|
+
if (plugins.length !== manifest.value.plugins.length) {
|
|
615
|
+
await atomicReplaceConfigFile({
|
|
616
|
+
filePath: manifest.path,
|
|
617
|
+
allowedRoot: options.rootDir,
|
|
618
|
+
content: `${JSON.stringify({ ...manifest.value, plugins }, null, 2)}\n`,
|
|
619
|
+
});
|
|
1660
620
|
}
|
|
1661
621
|
}
|
|
1662
|
-
return true;
|
|
1663
622
|
}
|
|
1664
623
|
/**
|
|
1665
|
-
* Read-only
|
|
1666
|
-
*
|
|
624
|
+
* Read-only shared-native inspection. Official Codex list evidence owns installation
|
|
625
|
+
* state. Filesystem validation is limited to the AW-owned marketplace source.
|
|
1667
626
|
*/
|
|
1668
627
|
export async function inspectCodexSharedNativeLive(options) {
|
|
1669
628
|
const marketplaceName = options.marketplaceName ?? MARKETPLACE_NAME;
|
|
1670
|
-
const marketplaceRoot = options.marketplaceRoot ?? resolveAwHome(options.env);
|
|
629
|
+
const marketplaceRoot = options.marketplaceRoot ?? path.join(resolveAwHome(options.env), 'marketplaces', options.sourceId);
|
|
630
|
+
const marketplacePathSafe = await isSafeCodexMarketplaceRoot({
|
|
631
|
+
awHome: resolveAwHome(options.env),
|
|
632
|
+
sourceId: options.sourceId,
|
|
633
|
+
marketplaceRoot,
|
|
634
|
+
});
|
|
1671
635
|
const pluginId = `${options.pluginName}@${marketplaceName}`;
|
|
1672
636
|
const config = await readCodexConfigFile(resolveCodexPaths(options.cwd, 'user', options.env).configTomlPath);
|
|
1673
|
-
const
|
|
1674
|
-
const installedManifestPath = path.join(getCodexHome(options.env), 'plugins', pluginId, 'manifest.json');
|
|
1675
|
-
const cacheRootStats = await lstatCodexResidueIfPresent(cacheRoot);
|
|
1676
|
-
let unsafeCachePath = Boolean(cacheRootStats
|
|
1677
|
-
&& (!cacheRootStats.isDirectory() || cacheRootStats.isSymbolicLink()));
|
|
1678
|
-
const candidates = [];
|
|
1679
|
-
if (cacheRootStats?.isDirectory() && !cacheRootStats.isSymbolicLink()) {
|
|
1680
|
-
for (const entry of await fs.readdir(cacheRoot, { withFileTypes: true })) {
|
|
1681
|
-
const payloadPath = path.join(cacheRoot, entry.name);
|
|
1682
|
-
if (!entry.isDirectory() || entry.isSymbolicLink()) {
|
|
1683
|
-
unsafeCachePath = true;
|
|
1684
|
-
continue;
|
|
1685
|
-
}
|
|
1686
|
-
const manifestPaths = [
|
|
1687
|
-
path.join(payloadPath, 'plugin.json'),
|
|
1688
|
-
path.join(payloadPath, '.codex-plugin', 'plugin.json'),
|
|
1689
|
-
];
|
|
1690
|
-
const existingManifestPaths = [];
|
|
1691
|
-
for (const manifestPath of manifestPaths) {
|
|
1692
|
-
const stats = await lstatCodexResidueIfPresent(manifestPath);
|
|
1693
|
-
if (stats)
|
|
1694
|
-
existingManifestPaths.push(manifestPath);
|
|
1695
|
-
}
|
|
1696
|
-
if (existingManifestPaths.length !== 1) {
|
|
1697
|
-
candidates.push({
|
|
1698
|
-
version: entry.name,
|
|
1699
|
-
manifest: existingManifestPaths.length === 0 ? { state: 'absent' } : { state: 'unreadable' },
|
|
1700
|
-
payloadPath,
|
|
1701
|
-
});
|
|
1702
|
-
continue;
|
|
1703
|
-
}
|
|
1704
|
-
const manifestPath = existingManifestPaths[0];
|
|
1705
|
-
const manifestStats = await lstatCodexResidueIfPresent(manifestPath);
|
|
1706
|
-
if (!manifestStats?.isFile() || manifestStats.isSymbolicLink()) {
|
|
1707
|
-
candidates.push({ version: entry.name, manifest: { state: 'unreadable' }, payloadPath });
|
|
1708
|
-
continue;
|
|
1709
|
-
}
|
|
1710
|
-
let manifest;
|
|
1711
|
-
try {
|
|
1712
|
-
const value = await fs.readJson(manifestPath);
|
|
1713
|
-
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
1714
|
-
throw new Error('invalid manifest');
|
|
1715
|
-
manifest = value;
|
|
1716
|
-
}
|
|
1717
|
-
catch {
|
|
1718
|
-
candidates.push({ version: entry.name, manifest: { state: 'unreadable' }, payloadPath });
|
|
1719
|
-
continue;
|
|
1720
|
-
}
|
|
1721
|
-
const pathSafe = await codexPayloadPathSafe(payloadPath);
|
|
1722
|
-
let payloadDigest = options.expectedPayloadDigest;
|
|
1723
|
-
if (pathSafe) {
|
|
1724
|
-
try {
|
|
1725
|
-
payloadDigest = await calculateCodexSharedNativePayloadDigest(payloadPath);
|
|
1726
|
-
}
|
|
1727
|
-
catch {
|
|
1728
|
-
candidates.push({ version: entry.name, manifest: { state: 'unreadable' }, payloadPath });
|
|
1729
|
-
continue;
|
|
1730
|
-
}
|
|
1731
|
-
}
|
|
1732
|
-
candidates.push({
|
|
1733
|
-
version: typeof manifest.version === 'string' ? manifest.version : entry.name,
|
|
1734
|
-
payloadPath,
|
|
1735
|
-
manifest: {
|
|
1736
|
-
state: 'present',
|
|
1737
|
-
identity: typeof manifest.id === 'string'
|
|
1738
|
-
? manifest.id
|
|
1739
|
-
: typeof manifest.name === 'string' ? manifest.name : '',
|
|
1740
|
-
version: typeof manifest.version === 'string' ? manifest.version : '',
|
|
1741
|
-
payloadDigest,
|
|
1742
|
-
payloadPath,
|
|
1743
|
-
pathSafe,
|
|
1744
|
-
},
|
|
1745
|
-
});
|
|
1746
|
-
}
|
|
1747
|
-
}
|
|
1748
|
-
let installedVersion;
|
|
1749
|
-
const installedStats = await lstatCodexResidueIfPresent(installedManifestPath);
|
|
1750
|
-
if (installedStats?.isFile() && !installedStats.isSymbolicLink()) {
|
|
1751
|
-
try {
|
|
1752
|
-
const installed = await fs.readJson(installedManifestPath);
|
|
1753
|
-
if (typeof installed.version === 'string')
|
|
1754
|
-
installedVersion = installed.version;
|
|
1755
|
-
}
|
|
1756
|
-
catch {
|
|
1757
|
-
installedVersion = undefined;
|
|
1758
|
-
}
|
|
1759
|
-
}
|
|
1760
|
-
const selected = candidates.find((candidate) => candidate.version === installedVersion)
|
|
1761
|
-
?? candidates.find((candidate) => candidate.version === options.desiredVersion)
|
|
1762
|
-
?? (candidates.length === 1 ? candidates[0] : undefined);
|
|
1763
|
-
const pluginListEntries = candidates.map((candidate) => ({
|
|
637
|
+
const pluginList = options.pluginRegistration ?? await inspectCodexPluginRegistrationLive({
|
|
1764
638
|
pluginId,
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
...(installedVersion ? { version: installedVersion } : {}),
|
|
1774
|
-
path: path.dirname(installedManifestPath),
|
|
1775
|
-
});
|
|
1776
|
-
}
|
|
1777
|
-
if (unsafeCachePath && pluginListEntries.length === 0) {
|
|
1778
|
-
pluginListEntries.push({
|
|
1779
|
-
pluginId,
|
|
1780
|
-
enabled: config.snapshot.plugins[pluginId]?.enabled === true,
|
|
1781
|
-
version: options.desiredVersion,
|
|
1782
|
-
path: cacheRoot,
|
|
1783
|
-
});
|
|
1784
|
-
}
|
|
1785
|
-
const manifest = unsafeCachePath
|
|
1786
|
-
? {
|
|
1787
|
-
state: 'present',
|
|
1788
|
-
identity: pluginId,
|
|
1789
|
-
version: options.desiredVersion,
|
|
1790
|
-
payloadDigest: options.expectedPayloadDigest,
|
|
1791
|
-
payloadPath: cacheRoot,
|
|
1792
|
-
pathSafe: false,
|
|
1793
|
-
}
|
|
1794
|
-
: selected?.manifest ?? { state: 'absent' };
|
|
639
|
+
cwd: options.cwd,
|
|
640
|
+
env: options.env,
|
|
641
|
+
nativeCliRunner: options.nativeCliRunner,
|
|
642
|
+
manager: options.manager,
|
|
643
|
+
scope: options.observationScope,
|
|
644
|
+
observationSession: options.observationSession,
|
|
645
|
+
});
|
|
646
|
+
const expectedPayloadDigest = options.expectedPayloadDigest;
|
|
1795
647
|
const sharedNative = inspectCodexSharedNative({
|
|
1796
648
|
pluginName: options.pluginName,
|
|
1797
649
|
pluginId,
|
|
1798
650
|
marketplaceName,
|
|
1799
651
|
canonicalMarketplaceRoot: marketplaceRoot,
|
|
1800
652
|
desiredVersion: options.desiredVersion,
|
|
1801
|
-
expectedPayloadDigest
|
|
653
|
+
expectedPayloadDigest,
|
|
1802
654
|
marketplaceRegistration: config.snapshot.marketplaces[marketplaceName],
|
|
1803
|
-
marketplacePathSafe
|
|
1804
|
-
|
|
1805
|
-
manifest,
|
|
1806
|
-
managedByCurrentIntent: options.managedByCurrentIntent && manifest.state === 'present',
|
|
655
|
+
marketplacePathSafe,
|
|
656
|
+
observation: pluginList.observation,
|
|
1807
657
|
});
|
|
1808
658
|
return {
|
|
1809
659
|
sharedNative,
|
|
1810
|
-
...(
|
|
1811
|
-
actualPayloadDigest: manifest.payloadDigest,
|
|
1812
|
-
payloadPath: manifest.payloadPath,
|
|
1813
|
-
} : {}),
|
|
1814
|
-
};
|
|
1815
|
-
}
|
|
1816
|
-
export async function codexNativeRemovalRequired(options) {
|
|
1817
|
-
const residue = await inspectCodexNativeResidue(options);
|
|
1818
|
-
if (residue.state === 'present')
|
|
1819
|
-
return true;
|
|
1820
|
-
if (residue.state === 'foreign')
|
|
1821
|
-
return false;
|
|
1822
|
-
const marketplaceName = options.marketplaceName ?? MARKETPLACE_NAME;
|
|
1823
|
-
const marketplaceRoot = options.marketplaceRoot ?? resolveAwHome(options.env);
|
|
1824
|
-
const config = await readCodexConfigFile(resolveCodexPaths(options.cwd, 'user', options.env).configTomlPath);
|
|
1825
|
-
const marketplace = config.snapshot.marketplaces[marketplaceName];
|
|
1826
|
-
const canonical = marketplace?.sourceType === 'local'
|
|
1827
|
-
&& !marketplace.sourcePointsToManifest
|
|
1828
|
-
&& path.normalize(marketplace.source ?? '') === path.normalize(marketplaceRoot);
|
|
1829
|
-
if (!canonical)
|
|
1830
|
-
return false;
|
|
1831
|
-
return (await discoverCodexNativeResidueNames(options)).length === 0;
|
|
1832
|
-
}
|
|
1833
|
-
export async function discoverCodexNativeResidueNames(options) {
|
|
1834
|
-
const marketplaceName = options.marketplaceName ?? MARKETPLACE_NAME;
|
|
1835
|
-
const marketplaceRoot = options.marketplaceRoot ?? resolveAwHome(options.env);
|
|
1836
|
-
const names = new Set();
|
|
1837
|
-
const config = await readCodexConfigFile(resolveCodexPaths(options.cwd, 'user', options.env).configTomlPath);
|
|
1838
|
-
const marketplace = config.snapshot.marketplaces[marketplaceName];
|
|
1839
|
-
const canonicalMarketplace = marketplace?.sourceType === 'local'
|
|
1840
|
-
&& !marketplace.sourcePointsToManifest
|
|
1841
|
-
&& path.normalize(marketplace.source ?? '') === path.normalize(marketplaceRoot);
|
|
1842
|
-
const probeFailure = (location, cause, pluginName) => {
|
|
1843
|
-
if (cause instanceof CodexNativeResidueProbeError)
|
|
1844
|
-
throw cause;
|
|
1845
|
-
throw new CodexNativeResidueProbeError(location, cause, pluginName);
|
|
1846
|
-
};
|
|
1847
|
-
for (const pluginId of canonicalMarketplace ? Object.keys(config.snapshot.plugins) : []) {
|
|
1848
|
-
const suffix = `@${marketplaceName}`;
|
|
1849
|
-
const match = pluginId.endsWith(suffix)
|
|
1850
|
-
? /^([a-z0-9]+(?:-[a-z0-9]+)*)$/u.exec(pluginId.slice(0, -suffix.length))
|
|
1851
|
-
: null;
|
|
1852
|
-
if (match)
|
|
1853
|
-
names.add(match[1]);
|
|
1854
|
-
}
|
|
1855
|
-
const cacheRoot = path.join(getCodexHome(options.env), 'plugins', 'cache', marketplaceName);
|
|
1856
|
-
const cacheEntries = await readdirCodexResidueIfPresent(cacheRoot).catch((error) => probeFailure(cacheRoot, error));
|
|
1857
|
-
for (const entry of cacheEntries) {
|
|
1858
|
-
if (entry.isFile())
|
|
1859
|
-
continue;
|
|
1860
|
-
const entryPath = path.join(cacheRoot, entry.name);
|
|
1861
|
-
const pluginName = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u.test(entry.name)
|
|
1862
|
-
? entry.name
|
|
1863
|
-
: probeFailure(entryPath, new Error('Codex cache residue has an invalid plugin identity.'));
|
|
1864
|
-
if (!entry.isDirectory() || entry.isSymbolicLink()) {
|
|
1865
|
-
probeFailure(entryPath, new Error('Codex cache residue is not a canonical plugin directory.'), pluginName);
|
|
1866
|
-
}
|
|
1867
|
-
let versionEntries;
|
|
1868
|
-
try {
|
|
1869
|
-
versionEntries = await fs.readdir(entryPath, { withFileTypes: true });
|
|
1870
|
-
}
|
|
1871
|
-
catch (error) {
|
|
1872
|
-
throw new CodexNativeResidueProbeError(entryPath, error, pluginName);
|
|
1873
|
-
}
|
|
1874
|
-
if (versionEntries.length === 0) {
|
|
1875
|
-
if (names.has(pluginName)) {
|
|
1876
|
-
probeFailure(entryPath, new Error('Codex cache residue manifest is missing.'), pluginName);
|
|
1877
|
-
}
|
|
1878
|
-
continue;
|
|
1879
|
-
}
|
|
1880
|
-
let residue;
|
|
1881
|
-
try {
|
|
1882
|
-
residue = await inspectCodexNativeResidue({ ...options, pluginName: entry.name });
|
|
1883
|
-
}
|
|
1884
|
-
catch (error) {
|
|
1885
|
-
throw new CodexNativeResidueProbeError(entryPath, error, pluginName);
|
|
1886
|
-
}
|
|
1887
|
-
if (residue.state !== 'present') {
|
|
1888
|
-
probeFailure(entryPath, new Error('Codex cache residue has foreign or incomplete manifest evidence.'), pluginName);
|
|
1889
|
-
}
|
|
1890
|
-
names.add(pluginName);
|
|
1891
|
-
}
|
|
1892
|
-
const pluginsRoot = path.join(getCodexHome(options.env), 'plugins');
|
|
1893
|
-
const pluginEntries = await readdirCodexResidueIfPresent(pluginsRoot).catch((error) => probeFailure(pluginsRoot, error));
|
|
1894
|
-
for (const entry of pluginEntries) {
|
|
1895
|
-
const suffix = `@${marketplaceName}`;
|
|
1896
|
-
const match = entry.name.endsWith(suffix)
|
|
1897
|
-
? /^([a-z0-9]+(?:-[a-z0-9]+)*)$/u.exec(entry.name.slice(0, -suffix.length))
|
|
1898
|
-
: null;
|
|
1899
|
-
if (!match)
|
|
1900
|
-
continue;
|
|
1901
|
-
const installedRoot = path.join(pluginsRoot, entry.name);
|
|
1902
|
-
if (!entry.isDirectory() || entry.isSymbolicLink()) {
|
|
1903
|
-
probeFailure(installedRoot, new Error('Codex installed residue is not a canonical plugin directory.'), match[1]);
|
|
1904
|
-
}
|
|
1905
|
-
const installedStats = await lstatCodexResidueIfPresent(installedRoot);
|
|
1906
|
-
if (!installedStats || !installedStats.isDirectory() || installedStats.isSymbolicLink()) {
|
|
1907
|
-
probeFailure(installedRoot, new Error('Codex installed residue is not a canonical plugin directory.'), match[1]);
|
|
1908
|
-
}
|
|
1909
|
-
const manifestPath = path.join(pluginsRoot, entry.name, 'manifest.json');
|
|
1910
|
-
const stats = await lstatCodexResidueIfPresent(manifestPath);
|
|
1911
|
-
if (!stats?.isFile() || stats.isSymbolicLink()) {
|
|
1912
|
-
probeFailure(manifestPath, new Error('Codex installed residue manifest is missing or nonregular.'), match[1]);
|
|
1913
|
-
}
|
|
1914
|
-
let rawManifest;
|
|
1915
|
-
try {
|
|
1916
|
-
rawManifest = await fs.readJson(manifestPath);
|
|
1917
|
-
}
|
|
1918
|
-
catch (error) {
|
|
1919
|
-
throw new CodexNativeResidueProbeError(manifestPath, error, match[1]);
|
|
1920
|
-
}
|
|
1921
|
-
if (!rawManifest || typeof rawManifest !== 'object' || Array.isArray(rawManifest)) {
|
|
1922
|
-
probeFailure(manifestPath, new Error('Codex installed residue manifest must be an object.'), match[1]);
|
|
1923
|
-
}
|
|
1924
|
-
const manifest = rawManifest;
|
|
1925
|
-
const identity = manifest.id ?? manifest.name;
|
|
1926
|
-
if (!canonicalMarketplace
|
|
1927
|
-
|| (identity !== match[1] && identity !== entry.name)
|
|
1928
|
-
|| typeof manifest.version !== 'string'
|
|
1929
|
-
|| manifest.version.trim() === '') {
|
|
1930
|
-
probeFailure(manifestPath, new Error('Codex installed residue manifest has foreign identity or version.'), match[1]);
|
|
1931
|
-
}
|
|
1932
|
-
names.add(match[1]);
|
|
1933
|
-
}
|
|
1934
|
-
return [...names];
|
|
1935
|
-
}
|
|
1936
|
-
export class CodexNativeResidueProbeError extends Error {
|
|
1937
|
-
code = 'codexNativeResidueProbeFailed';
|
|
1938
|
-
location;
|
|
1939
|
-
pluginName;
|
|
1940
|
-
constructor(location, cause, pluginName) {
|
|
1941
|
-
super(`codexNativeResidueProbeFailed: cannot classify Codex native residue at ${location}.`, {
|
|
1942
|
-
cause,
|
|
1943
|
-
});
|
|
1944
|
-
this.name = 'CodexNativeResidueProbeError';
|
|
1945
|
-
this.location = location;
|
|
1946
|
-
this.pluginName = pluginName;
|
|
1947
|
-
}
|
|
1948
|
-
}
|
|
1949
|
-
async function ensureCodexActiveSkillsManifest(options) {
|
|
1950
|
-
const relativeSkillsRoot = await resolveCodexSkillsRelativeRoot(options.plugin);
|
|
1951
|
-
const skillsRoot = path.join(options.marketplaceRoot, 'plugins', options.plugin.manifest.name, ...relativeSkillsRoot.split('/'));
|
|
1952
|
-
if (options.hasRequiredSkills && !await fs.pathExists(skillsRoot)) {
|
|
1953
|
-
throw new Error(`Codex required Skills root 不存在:${skillsRoot}`);
|
|
1954
|
-
}
|
|
1955
|
-
const manifestPath = path.join(options.marketplaceRoot, 'plugins', options.plugin.manifest.name, '.codex-plugin', 'plugin.json');
|
|
1956
|
-
const manifest = await fs.readJson(manifestPath).catch((error) => {
|
|
1957
|
-
if (error.code === 'ENOENT')
|
|
1958
|
-
return {};
|
|
1959
|
-
throw error;
|
|
1960
|
-
});
|
|
1961
|
-
const updated = {
|
|
1962
|
-
...manifest,
|
|
1963
|
-
name: options.plugin.manifest.name,
|
|
1964
|
-
version: options.plugin.manifest.version,
|
|
1965
|
-
};
|
|
1966
|
-
if (options.hasRequiredSkills)
|
|
1967
|
-
updated.skills = `./${relativeSkillsRoot}`;
|
|
1968
|
-
else
|
|
1969
|
-
delete updated.skills;
|
|
1970
|
-
await fs.outputJson(manifestPath, updated, { spaces: 2 });
|
|
1971
|
-
return options.hasRequiredSkills ? relativeSkillsRoot : null;
|
|
1972
|
-
}
|
|
1973
|
-
function createCodexMarketplaceComponent(options) {
|
|
1974
|
-
const configPath = resolveCodexPaths(options.cwd, 'user', options.env).configTomlPath;
|
|
1975
|
-
const inspectCanonicalMarketplace = async () => {
|
|
1976
|
-
const config = await readCodexConfigFile(configPath);
|
|
1977
|
-
const marketplace = config.snapshot.marketplaces[options.marketplaceName];
|
|
1978
|
-
if (!marketplace)
|
|
1979
|
-
return 'absent';
|
|
1980
|
-
if (marketplace.sourceType !== 'local'
|
|
1981
|
-
|| marketplace.sourcePointsToManifest
|
|
1982
|
-
|| path.normalize(marketplace.source ?? '') !== path.normalize(options.marketplaceRoot))
|
|
1983
|
-
return 'foreign';
|
|
1984
|
-
return 'present';
|
|
1985
|
-
};
|
|
1986
|
-
const hasRemainingPlugins = async () => {
|
|
1987
|
-
return (await discoverCodexNativeResidueNames({
|
|
1988
|
-
cwd: options.cwd,
|
|
1989
|
-
env: options.env,
|
|
1990
|
-
marketplaceName: options.marketplaceName,
|
|
1991
|
-
marketplaceRoot: options.marketplaceRoot,
|
|
1992
|
-
})).some((name) => name !== options.pluginName);
|
|
1993
|
-
};
|
|
1994
|
-
const inspect = async () => {
|
|
1995
|
-
const canonical = await inspectCanonicalMarketplace();
|
|
1996
|
-
const plugin = await inspectCodexNativeResidue({
|
|
1997
|
-
pluginName: options.pluginName,
|
|
1998
|
-
cwd: options.cwd,
|
|
1999
|
-
env: options.env,
|
|
2000
|
-
marketplaceName: options.marketplaceName,
|
|
2001
|
-
marketplaceRoot: options.marketplaceRoot,
|
|
2002
|
-
});
|
|
2003
|
-
if (plugin.state === 'foreign')
|
|
2004
|
-
return 'foreign';
|
|
2005
|
-
if (options.desired) {
|
|
2006
|
-
return canonical === 'present' && plugin.state === 'present' && plugin.enabled
|
|
2007
|
-
? 'present'
|
|
2008
|
-
: 'absent';
|
|
2009
|
-
}
|
|
2010
|
-
if (canonical !== 'present')
|
|
2011
|
-
return canonical;
|
|
2012
|
-
return await hasRemainingPlugins() ? 'absent' : 'present';
|
|
2013
|
-
};
|
|
2014
|
-
return {
|
|
2015
|
-
kind: 'shared-config',
|
|
2016
|
-
identity: ownerIdentity(options.pluginName, `marketplace-${options.marketplaceName}`, 'codex', 'user'),
|
|
2017
|
-
label: `${configPath}#marketplaces.${options.marketplaceName}`,
|
|
2018
|
-
inspect,
|
|
2019
|
-
remove: async () => {
|
|
2020
|
-
const currentResidue = await inspectCodexNativeResidue({
|
|
2021
|
-
pluginName: options.pluginName,
|
|
2022
|
-
cwd: options.cwd,
|
|
2023
|
-
env: options.env,
|
|
2024
|
-
marketplaceName: options.marketplaceName,
|
|
2025
|
-
marketplaceRoot: options.marketplaceRoot,
|
|
2026
|
-
});
|
|
2027
|
-
if (currentResidue.state === 'foreign') {
|
|
2028
|
-
throw new Error(`Codex native owner 为 foreign,拒绝移除 marketplace:${currentResidue.labels.join(',')}`);
|
|
2029
|
-
}
|
|
2030
|
-
if (await inspectCanonicalMarketplace() !== 'present'
|
|
2031
|
-
|| currentResidue.state === 'present'
|
|
2032
|
-
|| await hasRemainingPlugins())
|
|
2033
|
-
return;
|
|
2034
|
-
try {
|
|
2035
|
-
await runNativeCliChecked(buildCodexMarketplaceRemoveInvocation(requireCodexManager(options.codexManager), options.marketplaceName, options.cwd, options.env), options.runner);
|
|
2036
|
-
await runNativeCliChecked(buildCodexMarketplaceListInvocation(requireCodexManager(options.codexManager), options.cwd, options.env), options.runner);
|
|
2037
|
-
}
|
|
2038
|
-
catch {
|
|
2039
|
-
throw new Error(`codexNativeRemoveFailed: ${CODEX_REMOVE_RECOVERY}`);
|
|
2040
|
-
}
|
|
2041
|
-
},
|
|
2042
|
-
};
|
|
2043
|
-
}
|
|
2044
|
-
async function assertCodexNativeInstallState(options) {
|
|
2045
|
-
const marketplaceName = options.marketplaceName ?? MARKETPLACE_NAME;
|
|
2046
|
-
const pluginId = `${options.pluginName}@${marketplaceName}`;
|
|
2047
|
-
const configPath = resolveCodexPaths(options.cwd, 'user', options.env).configTomlPath;
|
|
2048
|
-
const config = await readCodexConfigFile(configPath);
|
|
2049
|
-
const marketplace = config.snapshot.marketplaces[marketplaceName];
|
|
2050
|
-
if (marketplace?.sourceType !== 'local'
|
|
2051
|
-
|| marketplace.sourcePointsToManifest
|
|
2052
|
-
|| path.normalize(marketplace.source ?? '') !== path.normalize(options.marketplaceRoot)) {
|
|
2053
|
-
throw new Error(`Codex marketplace aw 未指向当前 AW_HOME:${options.marketplaceRoot}`);
|
|
2054
|
-
}
|
|
2055
|
-
if (config.snapshot.plugins[pluginId]?.enabled !== true) {
|
|
2056
|
-
throw new Error(`Codex enabled config 缺少 ${pluginId}。`);
|
|
2057
|
-
}
|
|
2058
|
-
const cacheRoot = path.join(getCodexHome(options.env), 'plugins', 'cache', marketplaceName, options.pluginName, options.pluginVersion);
|
|
2059
|
-
const candidates = [
|
|
2060
|
-
path.join(cacheRoot, 'plugin.json'),
|
|
2061
|
-
path.join(cacheRoot, '.codex-plugin', 'plugin.json'),
|
|
2062
|
-
];
|
|
2063
|
-
const expectedRoot = path.join(options.marketplaceRoot, 'plugins', options.pluginName);
|
|
2064
|
-
const assertExpectedPayload = async () => {
|
|
2065
|
-
const collectFiles = async (root) => {
|
|
2066
|
-
const output = [];
|
|
2067
|
-
const pending = [''];
|
|
2068
|
-
while (pending.length > 0) {
|
|
2069
|
-
const relativeRoot = pending.pop();
|
|
2070
|
-
for (const entry of await fs.readdir(path.join(root, relativeRoot), { withFileTypes: true })) {
|
|
2071
|
-
const relativePath = path.join(relativeRoot, entry.name);
|
|
2072
|
-
if (entry.isSymbolicLink()) {
|
|
2073
|
-
throw new Error(`Codex native payload 不能包含符号链接:${path.join(root, relativePath)}`);
|
|
2074
|
-
}
|
|
2075
|
-
if (entry.isDirectory())
|
|
2076
|
-
pending.push(relativePath);
|
|
2077
|
-
else if (entry.isFile())
|
|
2078
|
-
output.push(relativePath);
|
|
2079
|
-
else
|
|
2080
|
-
throw new Error(`Codex native payload 包含不支持的节点:${path.join(root, relativePath)}`);
|
|
2081
|
-
}
|
|
2082
|
-
}
|
|
2083
|
-
return output;
|
|
2084
|
-
};
|
|
2085
|
-
const manifestPaths = new Set(['plugin.json', path.join('.codex-plugin', 'plugin.json')]);
|
|
2086
|
-
const allowedMetadata = new Set(['metadata.json', '.metadata.json']);
|
|
2087
|
-
const [expectedFiles, actualFiles] = await Promise.all([
|
|
2088
|
-
collectFiles(expectedRoot),
|
|
2089
|
-
collectFiles(cacheRoot),
|
|
2090
|
-
]);
|
|
2091
|
-
const expectedSet = new Set(expectedFiles);
|
|
2092
|
-
for (const relativePath of expectedFiles) {
|
|
2093
|
-
if (manifestPaths.has(relativePath))
|
|
2094
|
-
continue;
|
|
2095
|
-
const expectedPath = path.join(expectedRoot, relativePath);
|
|
2096
|
-
const actualPath = path.join(cacheRoot, relativePath);
|
|
2097
|
-
const actualStats = await fs.lstat(actualPath).catch(() => null);
|
|
2098
|
-
if (!actualStats?.isFile() || actualStats.isSymbolicLink()) {
|
|
2099
|
-
throw new Error(`Codex native cache 缺少 expected payload:${actualPath}`);
|
|
2100
|
-
}
|
|
2101
|
-
const [expectedContent, actualContent] = await Promise.all([
|
|
2102
|
-
fs.readFile(expectedPath),
|
|
2103
|
-
fs.readFile(actualPath),
|
|
2104
|
-
]);
|
|
2105
|
-
if (!expectedContent.equals(actualContent)) {
|
|
2106
|
-
throw new Error(`Codex native cache expected payload digest 不匹配:${actualPath}`);
|
|
2107
|
-
}
|
|
2108
|
-
}
|
|
2109
|
-
for (const relativePath of actualFiles) {
|
|
2110
|
-
if (expectedSet.has(relativePath)
|
|
2111
|
-
|| manifestPaths.has(relativePath)
|
|
2112
|
-
|| allowedMetadata.has(relativePath))
|
|
2113
|
-
continue;
|
|
2114
|
-
throw new Error(`Codex native cache 包含 unexpected loadable payload:${path.join(cacheRoot, relativePath)}`);
|
|
2115
|
-
}
|
|
660
|
+
...(expectedPayloadDigest ? { expectedPayloadDigest } : {}),
|
|
2116
661
|
};
|
|
2117
|
-
let matchedManifest = false;
|
|
2118
|
-
for (const candidate of candidates) {
|
|
2119
|
-
if (!await fs.pathExists(candidate))
|
|
2120
|
-
continue;
|
|
2121
|
-
const manifest = await fs.readJson(candidate).catch(() => null);
|
|
2122
|
-
if (!manifest) {
|
|
2123
|
-
throw new Error(`Codex native cache manifest 无法解析:${candidate}`);
|
|
2124
|
-
}
|
|
2125
|
-
const identity = manifest.id ?? manifest.name;
|
|
2126
|
-
const matches = ((identity === options.pluginName || identity === pluginId)
|
|
2127
|
-
&& manifest.version === options.pluginVersion
|
|
2128
|
-
&& (options.skillsRelativeRoot === null
|
|
2129
|
-
? typeof manifest.skills !== 'string'
|
|
2130
|
-
: typeof manifest.skills === 'string'
|
|
2131
|
-
&& path.posix.normalize(manifest.skills.replace(/^\.\//u, '')) === options.skillsRelativeRoot));
|
|
2132
|
-
if (!matches) {
|
|
2133
|
-
throw new Error(`Codex native cache manifest 不匹配:${candidate}`);
|
|
2134
|
-
}
|
|
2135
|
-
matchedManifest = true;
|
|
2136
|
-
}
|
|
2137
|
-
if (!matchedManifest) {
|
|
2138
|
-
throw new Error(`Codex native cache 缺少匹配 ${pluginId}@${options.pluginVersion} 的 manifest:${cacheRoot}`);
|
|
2139
|
-
}
|
|
2140
|
-
for (const skillKey of options.requiredSkillKeys) {
|
|
2141
|
-
const skillPath = path.join(cacheRoot, ...options.skillsRelativeRoot.split('/'), skillKey, 'SKILL.md');
|
|
2142
|
-
if (!await fs.pathExists(skillPath)) {
|
|
2143
|
-
throw new Error(`Codex native cache 缺少 required Skill:${skillPath}`);
|
|
2144
|
-
}
|
|
2145
|
-
}
|
|
2146
|
-
await assertExpectedPayload();
|
|
2147
662
|
}
|
|
2148
663
|
async function readJsonObjectIfExists(filePath, label) {
|
|
2149
664
|
let value;
|
|
@@ -2420,41 +935,202 @@ export async function assertNoClaudeUnboundNativeNameCollision(options) {
|
|
|
2420
935
|
throw new Error(`externalOwnershipPresent: Claude has an unbound installed plugin named ${options.pluginName}; native install would overwrite it.`);
|
|
2421
936
|
}
|
|
2422
937
|
}
|
|
2423
|
-
export async function
|
|
2424
|
-
const
|
|
2425
|
-
const
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
938
|
+
export async function inspectNativeMarketplaceRegistration(options) {
|
|
939
|
+
const { sourceId, platform, marketplaceName, cwd, env } = options;
|
|
940
|
+
const [awRoot, configRoot] = await Promise.all([
|
|
941
|
+
canonicalNamespaceRoot(resolveAwHome(env)),
|
|
942
|
+
canonicalNamespaceRoot(resolvePlatformConfigRoot(platform, { cwd, env })),
|
|
943
|
+
]);
|
|
944
|
+
const marketplaceRoot = path.join(getManagedPlatformRoot(awRoot, platform, `${platform}-marketplace`, configRoot), 'marketplaces', sourceId);
|
|
945
|
+
if (platform === 'codex') {
|
|
946
|
+
const config = await readCodexConfigFile(resolveCodexPaths(cwd, 'user', env).configTomlPath);
|
|
947
|
+
const marketplace = config.snapshot.marketplaces[marketplaceName];
|
|
948
|
+
if (marketplace !== undefined) {
|
|
949
|
+
return isCanonicalCodexMarketplaceRegistration(marketplace, marketplaceRoot) ? 'canonical' : 'foreign';
|
|
950
|
+
}
|
|
951
|
+
const suffix = `@${marketplaceName}`;
|
|
952
|
+
// A repair can restore activation before the marketplace has been registered again.
|
|
953
|
+
const ownedActivations = new Set(options.codexPackages
|
|
954
|
+
.filter(({ packageId, sourceLocation }) => sourceLocation === path.join(marketplaceRoot, 'plugins', packageId))
|
|
955
|
+
.map(({ registrationId }) => registrationId));
|
|
956
|
+
return Object.keys(config.snapshot.plugins).some((id) => id.length > suffix.length && id.endsWith(suffix) && !ownedActivations.has(id))
|
|
957
|
+
? 'foreign' : 'absent';
|
|
958
|
+
}
|
|
2438
959
|
const claudeState = await readClaudeNativeState({
|
|
2439
960
|
pluginName: '__marketplace_preflight__',
|
|
2440
961
|
scope: 'user',
|
|
2441
|
-
cwd
|
|
2442
|
-
env
|
|
2443
|
-
marketplaceName
|
|
2444
|
-
marketplaceRoot
|
|
962
|
+
cwd,
|
|
963
|
+
env,
|
|
964
|
+
marketplaceName,
|
|
965
|
+
marketplaceRoot,
|
|
2445
966
|
});
|
|
2446
|
-
|
|
967
|
+
return claudeState.marketplaceState === 'absent'
|
|
2447
968
|
&& claudeState.marketplaceConsumerEvidence
|
|
2448
969
|
? 'foreign'
|
|
2449
970
|
: claudeState.marketplaceState;
|
|
2450
|
-
return { codex, claude };
|
|
2451
971
|
}
|
|
2452
|
-
function
|
|
2453
|
-
|
|
2454
|
-
|
|
972
|
+
export async function applyPlannedOperationAction(action) {
|
|
973
|
+
if (action.kind !== 'updateSharedConfig' || action.mutation.kind !== 'claude-permissions'
|
|
974
|
+
|| action.locator.kind !== 'claude-permissions') {
|
|
975
|
+
throw new Error('platformContributionUnsupported: expected a Claude permissions contribution.');
|
|
976
|
+
}
|
|
977
|
+
const settings = await readClaudeSettings(action.locator.settingsPath);
|
|
978
|
+
const before = settings.permissions;
|
|
979
|
+
rebuildClaudePermissions(settings, action.locator.ownerKey, action.mutation.permissions);
|
|
980
|
+
await writeClaudeSettings(action.locator.settingsPath, settings);
|
|
981
|
+
return {
|
|
982
|
+
allow: (settings.permissions?.allow ?? []).filter((rule) => !before?.allow?.includes(rule)),
|
|
983
|
+
ask: (settings.permissions?.ask ?? []).filter((rule) => !before?.ask?.includes(rule)),
|
|
984
|
+
deny: (settings.permissions?.deny ?? []).filter((rule) => !before?.deny?.includes(rule)),
|
|
985
|
+
};
|
|
986
|
+
}
|
|
987
|
+
function createNativeDriver(options) {
|
|
988
|
+
const runner = options.context.nativeCliRunner;
|
|
989
|
+
const currentCodexManager = () => options.context.codexManager;
|
|
990
|
+
const codexNativeStates = new Map();
|
|
991
|
+
const pendingCodexNativeStates = new Map();
|
|
992
|
+
const codexMutationMarketplaces = new Set();
|
|
993
|
+
let nativeMarketplaceEligibleTargets;
|
|
994
|
+
let deferredPostchecks = [];
|
|
995
|
+
const nativeGroupKey = (target) => [
|
|
996
|
+
target.identity.sourceId ?? '',
|
|
997
|
+
target.identity.sourceIdentity ?? '',
|
|
998
|
+
target.identity.marketplaceName ?? MARKETPLACE_NAME,
|
|
999
|
+
path.normalize(path.resolve(target.identity.marketplaceRoot ?? resolveAwHome(options.context.env))),
|
|
1000
|
+
].join('\0');
|
|
1001
|
+
const observationScopeFor = (target) => codexObservationScope(options.context, target.identity.marketplaceName ?? MARKETPLACE_NAME, target.identity.scope);
|
|
1002
|
+
const checkCodexInstalledVersion = async (target, pluginId, marketplaceName) => {
|
|
1003
|
+
const scope = codexObservationScope(options.context, marketplaceName, target.identity.scope);
|
|
1004
|
+
const registration = await inspectCodexPluginRegistrationLive({
|
|
1005
|
+
pluginId,
|
|
1006
|
+
cwd: target.identity.cwd,
|
|
1007
|
+
env: options.context.env,
|
|
1008
|
+
nativeCliRunner: runner,
|
|
1009
|
+
manager: currentCodexManager(),
|
|
1010
|
+
scope,
|
|
1011
|
+
observationSession: options.context.codexObservationSession,
|
|
1012
|
+
});
|
|
1013
|
+
const state = requireObservedCodexNativeState(registration.observation, 'native install postcheck');
|
|
1014
|
+
requireCodexObservationCoverage(registration, scope, 'native install postcheck');
|
|
1015
|
+
if (state !== 'installed') {
|
|
1016
|
+
throw new Error(`codexNativeInstallIncomplete: ${pluginId} is absent from Codex plugin list.`);
|
|
1017
|
+
}
|
|
1018
|
+
const installedEntry = registration.observation.state === 'observed'
|
|
1019
|
+
&& registration.observation.value === 'installed'
|
|
1020
|
+
? registration.observation.entry
|
|
1021
|
+
: undefined;
|
|
1022
|
+
if (installedEntry?.version !== undefined
|
|
1023
|
+
&& installedEntry.version !== target.identity.pluginVersion) {
|
|
1024
|
+
throw new Error(`codexNativeInstallIncomplete: ${pluginId} version is ${installedEntry.version}; expected ${target.identity.pluginVersion}.`);
|
|
1025
|
+
}
|
|
1026
|
+
};
|
|
1027
|
+
const groupTargets = (target) => {
|
|
1028
|
+
if (!options.operationScopedNativePhases)
|
|
1029
|
+
return [target];
|
|
1030
|
+
const key = nativeGroupKey(target);
|
|
1031
|
+
return options.targets.filter((candidate) => nativeGroupKey(candidate) === key
|
|
1032
|
+
&& (nativeMarketplaceEligibleTargets?.has(candidate) ?? true));
|
|
1033
|
+
};
|
|
1034
|
+
const findTarget = (component) => {
|
|
1035
|
+
const target = options.targets.find((entry) => entry.identity.pluginName === component.identity.plugin
|
|
1036
|
+
&& entry.identity.sourceId === component.identity.sourceId
|
|
1037
|
+
&& entry.identity.platform === component.identity.platform
|
|
1038
|
+
&& entry.identity.scope === component.identity.scope);
|
|
1039
|
+
if (!target)
|
|
1040
|
+
throw new Error('Ownership executor cannot resolve its desired target.');
|
|
1041
|
+
return target;
|
|
1042
|
+
};
|
|
1043
|
+
const codexStateKey = (target, pluginId) => `${nativeGroupKey(target)}\0${pluginId}`;
|
|
1044
|
+
const runObservedCodexMutation = async (options_) => runCodexMutationWithInvalidation({
|
|
1045
|
+
...options_,
|
|
1046
|
+
...(options.operationScopedNativePhases
|
|
1047
|
+
? {}
|
|
1048
|
+
: { observationSession: options.context.codexObservationSession }),
|
|
1049
|
+
});
|
|
1050
|
+
const prepareNativeGroup = async (target) => {
|
|
1051
|
+
for (const member of groupTargets(target)) {
|
|
1052
|
+
if (member.identity.platform !== 'codex')
|
|
1053
|
+
continue;
|
|
1054
|
+
for (const component of member.ownedComponents) {
|
|
1055
|
+
if (component.kind !== 'native-plugin')
|
|
1056
|
+
continue;
|
|
1057
|
+
const registration = await inspectCodexPluginRegistrationLive({ pluginId: component.pluginId,
|
|
1058
|
+
cwd: member.identity.cwd, env: options.context.env, nativeCliRunner: runner,
|
|
1059
|
+
manager: currentCodexManager(), scope: observationScopeFor(member),
|
|
1060
|
+
observationSession: options.context.codexObservationSession });
|
|
1061
|
+
codexNativeStates.set(codexStateKey(member, component.pluginId), requireObservedCodexNativeState(registration.observation, 'native cleanup precheck') === 'installed' ? 'present' : 'absent');
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
};
|
|
1065
|
+
const inspectCodexMarketplace = async (component) => {
|
|
1066
|
+
if (component.locator.kind !== 'codex-marketplace')
|
|
1067
|
+
throw new Error('Invalid Codex marketplace locator.');
|
|
1068
|
+
const target = findTarget(component);
|
|
1069
|
+
const configPath = resolveCodexPaths(target.identity.cwd, 'user', options.context.env).configTomlPath;
|
|
1070
|
+
const config = await readCodexConfigFile(configPath);
|
|
1071
|
+
const marketplace = config.snapshot.marketplaces[component.locator.marketplaceName];
|
|
1072
|
+
const canonical = !marketplace
|
|
1073
|
+
? 'absent'
|
|
1074
|
+
: isCanonicalCodexMarketplaceRegistration(marketplace, component.locator.marketplaceRoot)
|
|
1075
|
+
? 'present'
|
|
1076
|
+
: 'foreign';
|
|
1077
|
+
if (component.locator.desired) {
|
|
1078
|
+
if (canonical !== 'present')
|
|
1079
|
+
return canonical;
|
|
1080
|
+
const pluginId = `${component.identity.plugin}@${component.locator.marketplaceName}`;
|
|
1081
|
+
return config.snapshot.plugins[pluginId]?.enabled === true ? 'present' : 'absent';
|
|
1082
|
+
}
|
|
1083
|
+
if (canonical !== 'present')
|
|
1084
|
+
return canonical;
|
|
1085
|
+
const suffix = `@${component.locator.marketplaceName}`;
|
|
1086
|
+
const currentPluginId = `${component.identity.plugin}${suffix}`;
|
|
1087
|
+
const projectConfig = await readCodexConfigFile(resolveCodexPaths(target.identity.cwd, 'project', options.context.env).configTomlPath);
|
|
1088
|
+
const configuredPluginIds = [
|
|
1089
|
+
...Object.keys(config.snapshot.plugins),
|
|
1090
|
+
...Object.keys(projectConfig.snapshot.plugins),
|
|
1091
|
+
].filter((pluginId) => pluginId.endsWith(suffix));
|
|
1092
|
+
if (configuredPluginIds.some((pluginId) => pluginId !== currentPluginId))
|
|
1093
|
+
return 'absent';
|
|
1094
|
+
const ownedSession = options.context.codexObservationSession ? undefined
|
|
1095
|
+
: await createCodexNativeObservationSession({
|
|
1096
|
+
exactCwd: target.identity.cwd,
|
|
1097
|
+
env: options.context.env,
|
|
1098
|
+
runner,
|
|
1099
|
+
manager: currentCodexManager() ?? SYSTEM_CODEX_MANAGER,
|
|
1100
|
+
});
|
|
1101
|
+
const session = options.context.codexObservationSession ?? ownedSession;
|
|
1102
|
+
try {
|
|
1103
|
+
const observationScope = observationScopeFor(target);
|
|
1104
|
+
const snapshot = await session.snapshot(component.locator.marketplaceName, observationScope);
|
|
1105
|
+
if (!snapshot.neutral || (observationScope === 'both' && !snapshot.exact))
|
|
1106
|
+
return 'absent';
|
|
1107
|
+
const officialPluginIds = new Set([
|
|
1108
|
+
...(snapshot.exact?.keys() ?? []),
|
|
1109
|
+
...snapshot.neutral.keys(),
|
|
1110
|
+
]);
|
|
1111
|
+
return [...officialPluginIds].some((pluginId) => pluginId !== currentPluginId)
|
|
1112
|
+
? 'absent'
|
|
1113
|
+
: 'present';
|
|
1114
|
+
}
|
|
1115
|
+
finally {
|
|
1116
|
+
await ownedSession?.dispose();
|
|
1117
|
+
}
|
|
1118
|
+
};
|
|
1119
|
+
const inspectClaudeMarketplace = async (component) => {
|
|
1120
|
+
if (component.locator.kind !== 'claude-marketplace')
|
|
1121
|
+
throw new Error('Invalid Claude marketplace locator.');
|
|
1122
|
+
const target = findTarget(component);
|
|
1123
|
+
const state = await readClaudeNativeState({
|
|
1124
|
+
pluginName: component.identity.plugin,
|
|
1125
|
+
scope: component.identity.scope,
|
|
1126
|
+
cwd: target.identity.cwd,
|
|
1127
|
+
env: options.context.env,
|
|
1128
|
+
marketplaceName: component.locator.marketplaceName,
|
|
1129
|
+
marketplaceRoot: component.locator.marketplaceRoot,
|
|
1130
|
+
});
|
|
2455
1131
|
if (state.pluginState === 'foreign')
|
|
2456
1132
|
return 'foreign';
|
|
2457
|
-
if (
|
|
1133
|
+
if (component.locator.desired) {
|
|
2458
1134
|
return state.marketplaceDeclaredState === 'canonical'
|
|
2459
1135
|
&& state.marketplaceMaterializedState === 'canonical'
|
|
2460
1136
|
&& state.pluginState === 'present'
|
|
@@ -2464,200 +1140,280 @@ function createClaudeMarketplaceComponent(options) {
|
|
|
2464
1140
|
}
|
|
2465
1141
|
if (state.marketplaceState !== 'canonical')
|
|
2466
1142
|
return state.marketplaceState;
|
|
2467
|
-
const projectPath =
|
|
2468
|
-
? path.normalize(await resolveRepoRoot(
|
|
1143
|
+
const projectPath = component.identity.scope === 'project'
|
|
1144
|
+
? path.normalize(await resolveRepoRoot(target.identity.cwd))
|
|
2469
1145
|
: undefined;
|
|
2470
|
-
return state.marketplaceConsumers.some((consumer) => !(consumer.name ===
|
|
2471
|
-
&& consumer.scope ===
|
|
2472
|
-
&& (
|
|
2473
|
-
|
|
2474
|
-
: 'present';
|
|
1146
|
+
return state.marketplaceConsumers.some((consumer) => !(consumer.name === component.identity.plugin
|
|
1147
|
+
&& consumer.scope === component.identity.scope
|
|
1148
|
+
&& (component.identity.scope === 'user'
|
|
1149
|
+
|| path.normalize(consumer.projectPath ?? '') === projectPath))) ? 'absent' : 'present';
|
|
2475
1150
|
};
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
1151
|
+
const ownership = {
|
|
1152
|
+
inspectShared: async (component) => {
|
|
1153
|
+
const locator = component.locator;
|
|
1154
|
+
switch (locator.kind) {
|
|
1155
|
+
case 'host-permissions':
|
|
1156
|
+
return await hasPermissionOwner(options.context.env, locator) ? 'present' : 'absent';
|
|
1157
|
+
case 'cursor-workspace-hook':
|
|
1158
|
+
return platformOwnership.inspectShared(component);
|
|
1159
|
+
case 'claude-permissions':
|
|
1160
|
+
return (await readClaudeSettings(locator.settingsPath)).awGenerated
|
|
1161
|
+
?.permissions?.[locator.ownerKey] ? 'present' : 'absent';
|
|
1162
|
+
case 'codex-instruction':
|
|
1163
|
+
return (await readCodexConfigFile(locator.configPath)).snapshot
|
|
1164
|
+
.developerInstructions.managedBlocks[locator.ownerKey] ? 'present' : 'absent';
|
|
1165
|
+
case 'codex-activation': {
|
|
1166
|
+
const actual = (await readCodexConfigFile(locator.configPath))
|
|
1167
|
+
.snapshot.plugins[locator.codexPluginId]?.enabled;
|
|
1168
|
+
if (locator.disposition === 'remove')
|
|
1169
|
+
return actual === undefined ? 'absent' : 'present';
|
|
1170
|
+
if (locator.disposition === 'disable')
|
|
1171
|
+
return actual === true ? 'present' : 'absent';
|
|
1172
|
+
return actual === locator.desired ? 'present' : 'absent';
|
|
1173
|
+
}
|
|
1174
|
+
case 'legacy-codex-mcp': {
|
|
1175
|
+
const actual = (await readCodexConfigFile(locator.configPath))
|
|
1176
|
+
.snapshot.mcpServers[locator.serverKey];
|
|
1177
|
+
if (!actual)
|
|
1178
|
+
return 'absent';
|
|
1179
|
+
return legacyCodexMcpOwner(actual) === locator.ownerKey ? 'present' : 'foreign';
|
|
1180
|
+
}
|
|
1181
|
+
case 'legacy-codex-hook':
|
|
1182
|
+
return (await readLegacyCodexHooks(locator.hooksPath)).managedIdentities.some((entry) => serializeTrackedHookGroupIdentity(entry) === locator.serializedIdentity)
|
|
1183
|
+
? 'present'
|
|
1184
|
+
: 'absent';
|
|
1185
|
+
case 'codex-role-registration': {
|
|
1186
|
+
const registration = (await readCodexConfigFile(locator.configPath))
|
|
1187
|
+
.snapshot.agents[locator.roleKey];
|
|
1188
|
+
if (!registration)
|
|
1189
|
+
return 'absent';
|
|
1190
|
+
return await codexRoleRegistrationOwned({
|
|
1191
|
+
fileIdentity: locator.fileIdentity,
|
|
1192
|
+
configPath: locator.configPath,
|
|
1193
|
+
roleKey: locator.roleKey,
|
|
1194
|
+
rolePath: locator.rolePath,
|
|
1195
|
+
registration,
|
|
1196
|
+
}) ? 'present' : 'foreign';
|
|
1197
|
+
}
|
|
1198
|
+
case 'codex-marketplace':
|
|
1199
|
+
return inspectCodexMarketplace(component);
|
|
1200
|
+
case 'claude-marketplace':
|
|
1201
|
+
return inspectClaudeMarketplace(component);
|
|
1202
|
+
case 'corrupted':
|
|
1203
|
+
throw new Error(locator.message);
|
|
2498
1204
|
}
|
|
2499
1205
|
},
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
return { rootDir, commit: async () => undefined, rollback: async () => undefined };
|
|
2508
|
-
}
|
|
2509
|
-
const awHome = path.resolve(resolveAwHome(env));
|
|
2510
|
-
const awHomeStats = await fs.lstat(awHome).catch((error) => {
|
|
2511
|
-
if (error.code === 'ENOENT')
|
|
2512
|
-
return null;
|
|
2513
|
-
throw error;
|
|
2514
|
-
});
|
|
2515
|
-
if (!awHomeStats?.isDirectory() || awHomeStats.isSymbolicLink()) {
|
|
2516
|
-
throw new Error(`marketplaceRootInvalid: AW_HOME must be a regular directory: ${awHome}`);
|
|
2517
|
-
}
|
|
2518
|
-
const canonicalAwHome = await fs.realpath(awHome);
|
|
2519
|
-
const expectedParent = path.join(canonicalAwHome, 'marketplaces');
|
|
2520
|
-
const destination = target.marketplaceRoot;
|
|
2521
|
-
const parent = path.dirname(destination);
|
|
2522
|
-
if (path.resolve(parent) !== path.join(awHome, 'marketplaces')) {
|
|
2523
|
-
throw new Error(`marketplaceRootInvalid: marketplace parent is not under canonical AW_HOME: ${parent}`);
|
|
2524
|
-
}
|
|
2525
|
-
let parentStats = await fs.lstat(parent).catch((error) => {
|
|
2526
|
-
if (error.code === 'ENOENT')
|
|
2527
|
-
return null;
|
|
2528
|
-
throw error;
|
|
2529
|
-
});
|
|
2530
|
-
if (!parentStats) {
|
|
2531
|
-
await fs.mkdir(parent);
|
|
2532
|
-
parentStats = await fs.lstat(parent);
|
|
2533
|
-
}
|
|
2534
|
-
if (!parentStats.isDirectory() || parentStats.isSymbolicLink()) {
|
|
2535
|
-
throw new Error(`marketplaceRootInvalid: marketplace parent must be a regular directory: ${parent}`);
|
|
2536
|
-
}
|
|
2537
|
-
const canonicalParent = await fs.realpath(parent);
|
|
2538
|
-
if (canonicalParent !== expectedParent) {
|
|
2539
|
-
throw new Error(`marketplaceRootInvalid: marketplace parent is outside canonical AW_HOME: ${parent}`);
|
|
2540
|
-
}
|
|
2541
|
-
const staging = await fs.mkdtemp(path.join(parent, `.${target.sourceId}-staging-`));
|
|
2542
|
-
try {
|
|
2543
|
-
for (const entry of ['.agents', '.claude-plugin', 'plugins']) {
|
|
2544
|
-
await fs.copy(path.join(catalog.rootDir, entry), path.join(staging, entry));
|
|
2545
|
-
}
|
|
2546
|
-
const marketplaceName = target.marketplaceName ?? getNamespacedMarketplaceName(target.sourceId);
|
|
2547
|
-
for (const [platform, manifestPath] of [
|
|
2548
|
-
['codex', path.join(staging, '.agents', 'plugins', 'marketplace.json')],
|
|
2549
|
-
['claude', path.join(staging, '.claude-plugin', 'marketplace.json')],
|
|
2550
|
-
]) {
|
|
2551
|
-
const manifest = await fs.readJson(manifestPath);
|
|
2552
|
-
await fs.writeJson(manifestPath, {
|
|
2553
|
-
...projectMarketplaceManifestForPlatform(manifest, platform),
|
|
2554
|
-
name: marketplaceName,
|
|
2555
|
-
}, { spaces: 2 });
|
|
2556
|
-
}
|
|
2557
|
-
await fs.writeJson(path.join(staging, 'config.json'), {
|
|
2558
|
-
schemaVersion: 2,
|
|
2559
|
-
sourceId: target.sourceId,
|
|
2560
|
-
sourceIdentity: target.sourceIdentity,
|
|
2561
|
-
marketplaceName,
|
|
2562
|
-
}, { spaces: 2 });
|
|
2563
|
-
const destinationExists = await fs.lstat(destination).then(() => true, (error) => {
|
|
2564
|
-
if (error.code === 'ENOENT' || error.code === 'ENOTDIR')
|
|
2565
|
-
return false;
|
|
2566
|
-
throw error;
|
|
2567
|
-
});
|
|
2568
|
-
if (destinationExists) {
|
|
2569
|
-
await replayNamespacedCodexSkillOverlays({
|
|
2570
|
-
sourceRoot: destination,
|
|
2571
|
-
stagingRoot: staging,
|
|
2572
|
-
sourceId: target.sourceId,
|
|
2573
|
-
sourceIdentity: target.sourceIdentity,
|
|
2574
|
-
marketplaceName,
|
|
2575
|
-
});
|
|
2576
|
-
}
|
|
2577
|
-
const backup = `${destination}.backup-${crypto.randomUUID()}`;
|
|
2578
|
-
if (destinationExists)
|
|
2579
|
-
await fs.move(destination, backup);
|
|
2580
|
-
try {
|
|
2581
|
-
await fs.move(staging, destination);
|
|
2582
|
-
}
|
|
2583
|
-
catch (error) {
|
|
2584
|
-
const backupStats = await fs.lstat(backup).catch((inspectionError) => {
|
|
2585
|
-
if (inspectionError.code === 'ENOENT')
|
|
2586
|
-
return null;
|
|
2587
|
-
throw inspectionError;
|
|
2588
|
-
});
|
|
2589
|
-
const destinationStats = await fs.lstat(destination).catch((inspectionError) => {
|
|
2590
|
-
if (inspectionError.code === 'ENOENT')
|
|
2591
|
-
return null;
|
|
2592
|
-
throw inspectionError;
|
|
2593
|
-
});
|
|
2594
|
-
if (backupStats && !destinationStats) {
|
|
2595
|
-
await fs.move(backup, destination);
|
|
2596
|
-
}
|
|
2597
|
-
throw error;
|
|
2598
|
-
}
|
|
2599
|
-
let state = 'active';
|
|
2600
|
-
return {
|
|
2601
|
-
rootDir: destination,
|
|
2602
|
-
commit: async () => {
|
|
2603
|
-
if (state !== 'active')
|
|
1206
|
+
removeShared: async (component) => {
|
|
1207
|
+
const locator = component.locator;
|
|
1208
|
+
switch (locator.kind) {
|
|
1209
|
+
case 'host-permissions':
|
|
1210
|
+
if (options.context.removeHostPermissions)
|
|
1211
|
+
return options.context.removeHostPermissions(locator);
|
|
1212
|
+
await updateHostPermissions({ env: options.context.env, cwd: locator.projectRoot ?? locator.hostConfigRoot, invocationCwd: options.context.invocationCwd }, locator);
|
|
2604
1213
|
return;
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
1214
|
+
case 'cursor-workspace-hook':
|
|
1215
|
+
return platformOwnership.removeShared(component);
|
|
1216
|
+
case 'claude-permissions': {
|
|
1217
|
+
const settings = await readClaudeSettings(locator.settingsPath);
|
|
1218
|
+
rebuildClaudePermissions(settings, locator.ownerKey);
|
|
1219
|
+
await writeClaudeSettings(locator.settingsPath, settings);
|
|
1220
|
+
return;
|
|
1221
|
+
}
|
|
1222
|
+
case 'codex-instruction':
|
|
1223
|
+
await applyCodexConfigTransactionFile(locator.configPath, {
|
|
1224
|
+
removeManagedInstructionPluginName: locator.ownerKey,
|
|
1225
|
+
});
|
|
1226
|
+
return;
|
|
1227
|
+
case 'codex-activation':
|
|
1228
|
+
await applyConditionalCodexConfigTransactionFile(locator.configPath, (snapshot) => {
|
|
1229
|
+
const actual = snapshot.plugins[locator.codexPluginId]?.enabled;
|
|
1230
|
+
if (locator.disposition === 'remove') {
|
|
1231
|
+
return actual === undefined ? null : { removePluginActivations: [locator.codexPluginId] };
|
|
1232
|
+
}
|
|
1233
|
+
if (locator.disposition === 'disable') {
|
|
1234
|
+
return actual === true
|
|
1235
|
+
? { upsertPluginActivations: { [locator.codexPluginId]: false } }
|
|
1236
|
+
: null;
|
|
1237
|
+
}
|
|
1238
|
+
return { removePluginActivations: [locator.codexPluginId] };
|
|
1239
|
+
});
|
|
1240
|
+
return;
|
|
1241
|
+
case 'legacy-codex-mcp':
|
|
1242
|
+
await applyConditionalCodexConfigTransactionFile(locator.configPath, (snapshot) => legacyCodexMcpOwner(snapshot.mcpServers[locator.serverKey]) === locator.ownerKey
|
|
1243
|
+
? { removeMcpServers: [locator.serverKey] }
|
|
1244
|
+
: null);
|
|
1245
|
+
return;
|
|
1246
|
+
case 'legacy-codex-hook':
|
|
1247
|
+
await applyLegacyCodexHookCleanupTransactionFile(locator.hooksPath, (parsed) => {
|
|
1248
|
+
let removed = false;
|
|
1249
|
+
const remaining = parsed.groups.flatMap((entry) => {
|
|
1250
|
+
if (!removed && entry.managedIdentity
|
|
1251
|
+
&& serializeTrackedHookGroupIdentity(entry.managedIdentity) === locator.serializedIdentity) {
|
|
1252
|
+
removed = true;
|
|
1253
|
+
return [];
|
|
1254
|
+
}
|
|
1255
|
+
return [entry.rawGroup];
|
|
1256
|
+
});
|
|
1257
|
+
return removed ? remaining : null;
|
|
1258
|
+
});
|
|
1259
|
+
return;
|
|
1260
|
+
case 'codex-role-registration':
|
|
1261
|
+
await applyConditionalCodexConfigTransactionFile(locator.configPath, async (snapshot) => await codexRoleRegistrationOwned({
|
|
1262
|
+
fileIdentity: locator.fileIdentity,
|
|
1263
|
+
configPath: locator.configPath,
|
|
1264
|
+
roleKey: locator.roleKey,
|
|
1265
|
+
rolePath: locator.rolePath,
|
|
1266
|
+
registration: snapshot.agents[locator.roleKey],
|
|
1267
|
+
}) ? { removeAgentRegistrations: [locator.roleKey] } : null);
|
|
1268
|
+
return;
|
|
1269
|
+
case 'codex-marketplace': {
|
|
1270
|
+
if (locator.desired)
|
|
1271
|
+
return;
|
|
1272
|
+
const target = findTarget(component);
|
|
1273
|
+
await prepareNativeGroup(target);
|
|
1274
|
+
const pluginId = `${target.identity.pluginName}@${locator.marketplaceName}`;
|
|
1275
|
+
const stateKey = codexStateKey(target, pluginId);
|
|
1276
|
+
if (codexNativeStates.get(stateKey) === 'present'
|
|
1277
|
+
&& pendingCodexNativeStates.get(stateKey) !== 'absent')
|
|
1278
|
+
return;
|
|
1279
|
+
codexMutationMarketplaces.add(locator.marketplaceName);
|
|
1280
|
+
await runObservedCodexMutation({
|
|
1281
|
+
marketplaceName: locator.marketplaceName,
|
|
1282
|
+
mutation: () => runNativeCliChecked(buildCodexMarketplaceRemoveInvocation(currentCodexManager() ?? SYSTEM_CODEX_MANAGER, locator.marketplaceName, target.identity.cwd, options.context.env), runner),
|
|
2612
1283
|
});
|
|
2613
|
-
|
|
1284
|
+
return;
|
|
2614
1285
|
}
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
1286
|
+
case 'claude-marketplace': {
|
|
1287
|
+
return;
|
|
1288
|
+
}
|
|
1289
|
+
case 'corrupted':
|
|
1290
|
+
throw new Error(locator.message);
|
|
1291
|
+
}
|
|
1292
|
+
},
|
|
1293
|
+
validateSkillDirectory: async (component) => {
|
|
1294
|
+
await validateSkillDirectory(component.path, component.identity.platform === 'codex' ? 'codex.skill' : 'claude.skill', { ownerMarkerPolicy: 'ignore', requirementsReceiptPolicy: 'allow' });
|
|
1295
|
+
},
|
|
1296
|
+
skillDirectoryMatchesPristineTree: async ({ actualPath, files }) => {
|
|
1297
|
+
const expectedFiles = new Map(files.map((entry) => [entry.relativePath, entry]));
|
|
1298
|
+
const expectedDirectories = new Set(['']);
|
|
1299
|
+
for (const relativePath of expectedFiles.keys()) {
|
|
1300
|
+
const segments = relativePath.split('/');
|
|
1301
|
+
for (let index = 1; index < segments.length; index += 1) {
|
|
1302
|
+
expectedDirectories.add(segments.slice(0, index).join('/'));
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
const seen = new Set();
|
|
1306
|
+
const pending = [{ absolutePath: actualPath, relativePath: '' }];
|
|
1307
|
+
while (pending.length > 0) {
|
|
1308
|
+
const current = pending.pop();
|
|
1309
|
+
for (const entry of await fs.readdir(current.absolutePath, { withFileTypes: true })) {
|
|
1310
|
+
const relativePath = current.relativePath ? `${current.relativePath}/${entry.name}` : entry.name;
|
|
1311
|
+
if (entry.isSymbolicLink())
|
|
1312
|
+
return false;
|
|
1313
|
+
const absolutePath = path.join(current.absolutePath, entry.name);
|
|
1314
|
+
if (entry.isDirectory()) {
|
|
1315
|
+
if (!expectedDirectories.has(relativePath))
|
|
1316
|
+
return false;
|
|
1317
|
+
pending.push({ absolutePath, relativePath });
|
|
1318
|
+
continue;
|
|
2618
1319
|
}
|
|
2619
|
-
|
|
1320
|
+
if (!entry.isFile())
|
|
1321
|
+
return false;
|
|
1322
|
+
const digest = `sha256:${crypto.createHash('sha256').update(await fs.readFile(absolutePath)).digest('hex')}`;
|
|
1323
|
+
const expected = expectedFiles.get(relativePath);
|
|
1324
|
+
if (expected?.contentDigest !== digest)
|
|
1325
|
+
return false;
|
|
1326
|
+
if (catalogFileMode(relativePath, (await fs.stat(absolutePath)).mode)
|
|
1327
|
+
!== catalogFileMode(relativePath, expected.mode ?? 0o644))
|
|
1328
|
+
return false;
|
|
1329
|
+
seen.add(relativePath);
|
|
2620
1330
|
}
|
|
2621
|
-
}
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
return;
|
|
2625
|
-
const backupStats = await fs.lstat(backup).catch((error) => {
|
|
2626
|
-
if (error.code === 'ENOENT')
|
|
2627
|
-
return null;
|
|
2628
|
-
throw error;
|
|
2629
|
-
});
|
|
2630
|
-
await fs.remove(destination);
|
|
2631
|
-
if (backupStats)
|
|
2632
|
-
await fs.move(backup, destination);
|
|
2633
|
-
state = 'rolledBack';
|
|
2634
|
-
},
|
|
2635
|
-
};
|
|
2636
|
-
}
|
|
2637
|
-
catch (error) {
|
|
2638
|
-
await fs.remove(staging);
|
|
2639
|
-
throw error;
|
|
2640
|
-
}
|
|
2641
|
-
}
|
|
2642
|
-
function createNativeDriver(options) {
|
|
2643
|
-
const runner = options.context.nativeCliRunner;
|
|
2644
|
-
const codexManager = options.context.codexManager;
|
|
2645
|
-
const mirrorTransactions = new WeakMap();
|
|
2646
|
-
const finalizeNamespacedCleanup = async (target) => {
|
|
2647
|
-
if (target.identity.platform === 'codex')
|
|
2648
|
-
return;
|
|
2649
|
-
const { sourceId, sourceIdentity, marketplaceRoot, marketplaceName } = target.identity;
|
|
2650
|
-
if (!sourceId || !sourceIdentity || !marketplaceRoot)
|
|
2651
|
-
return;
|
|
2652
|
-
await cleanupOrphanNamespacedMarketplaceRoot({
|
|
2653
|
-
sourceId,
|
|
2654
|
-
sourceIdentity,
|
|
2655
|
-
...(marketplaceName ? { marketplaceName } : {}),
|
|
2656
|
-
cwd: target.identity.cwd,
|
|
2657
|
-
env: options.context.env,
|
|
2658
|
-
});
|
|
1331
|
+
}
|
|
1332
|
+
return seen.size === expectedFiles.size;
|
|
1333
|
+
},
|
|
2659
1334
|
};
|
|
2660
1335
|
return {
|
|
1336
|
+
ownership,
|
|
1337
|
+
setNativeMarketplaceEligibleTargets: (eligibleTargets) => {
|
|
1338
|
+
nativeMarketplaceEligibleTargets = new Set(eligibleTargets);
|
|
1339
|
+
},
|
|
1340
|
+
prepareNativeMarketplaceGroup: prepareNativeGroup,
|
|
1341
|
+
postcheckCodexProvider: async (target) => {
|
|
1342
|
+
const pending = deferredPostchecks.filter((entry) => entry.target === target);
|
|
1343
|
+
deferredPostchecks = deferredPostchecks.filter((entry) => entry.target !== target);
|
|
1344
|
+
// A dependent can write as soon as this returns. Read a new Codex list
|
|
1345
|
+
// after the provider's writes, even when its install receipt was healthy.
|
|
1346
|
+
const marketplaces = new Set((target.platformDeployment?.plans ?? []).flatMap((plan) => plan.evidence.layout.marketplaceName && plan.projections.some((projection) => projection.bundle)
|
|
1347
|
+
? [plan.evidence.layout.marketplaceName] : []));
|
|
1348
|
+
if (target.requiresNative)
|
|
1349
|
+
marketplaces.add(target.identity.marketplaceName ?? MARKETPLACE_NAME);
|
|
1350
|
+
for (const name of marketplaces)
|
|
1351
|
+
options.context.codexObservationSession?.invalidate(name);
|
|
1352
|
+
if (!pending.length)
|
|
1353
|
+
await target.platformDeployment?.verify();
|
|
1354
|
+
for (const entry of pending)
|
|
1355
|
+
await entry.postcheck();
|
|
1356
|
+
for (const name of marketplaces) {
|
|
1357
|
+
await checkCodexInstalledVersion(target, `${target.identity.pluginName}@${name}`, name);
|
|
1358
|
+
}
|
|
1359
|
+
},
|
|
1360
|
+
...(options.operationScopedNativePhases ? {
|
|
1361
|
+
deferPostcheck: (target, postcheck) => {
|
|
1362
|
+
if (target.identity.platform !== 'codex')
|
|
1363
|
+
return false;
|
|
1364
|
+
deferredPostchecks.push({
|
|
1365
|
+
target,
|
|
1366
|
+
postcheck: async () => {
|
|
1367
|
+
if (target.requiresNative) {
|
|
1368
|
+
const marketplaceName = target.identity.marketplaceName ?? MARKETPLACE_NAME;
|
|
1369
|
+
await checkCodexInstalledVersion(target, `${target.identity.pluginName}@${marketplaceName}`, marketplaceName);
|
|
1370
|
+
}
|
|
1371
|
+
await postcheck();
|
|
1372
|
+
},
|
|
1373
|
+
});
|
|
1374
|
+
return true;
|
|
1375
|
+
},
|
|
1376
|
+
completePostchecks: async () => {
|
|
1377
|
+
const pending = deferredPostchecks;
|
|
1378
|
+
deferredPostchecks = [];
|
|
1379
|
+
const failures = [];
|
|
1380
|
+
for (const entry of pending) {
|
|
1381
|
+
try {
|
|
1382
|
+
await entry.postcheck();
|
|
1383
|
+
}
|
|
1384
|
+
catch (error) {
|
|
1385
|
+
failures.push({ target: entry.target, error });
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
return failures;
|
|
1389
|
+
},
|
|
1390
|
+
} : {}),
|
|
1391
|
+
captureCodexPostMutationSnapshots: async (marketplaceNames = []) => {
|
|
1392
|
+
for (const marketplaceName of marketplaceNames) {
|
|
1393
|
+
codexMutationMarketplaces.add(marketplaceName);
|
|
1394
|
+
}
|
|
1395
|
+
const changedMarketplaces = [...codexMutationMarketplaces];
|
|
1396
|
+
const marketplaces = [...new Set([...changedMarketplaces, ...deferredPostchecks.flatMap(({ target }) => (target.platformDeployment?.plans ?? []).flatMap((plan) => plan.evidence.layout.marketplaceName
|
|
1397
|
+
&& plan.projections.some((projection) => projection.bundle) ? [plan.evidence.layout.marketplaceName] : []))])].sort();
|
|
1398
|
+
if (marketplaces.length === 0)
|
|
1399
|
+
return;
|
|
1400
|
+
const session = options.context.codexObservationSession;
|
|
1401
|
+
if (!session) {
|
|
1402
|
+
throw new Error('codexNativeObservationUnavailable: grouped postcheck requires an observation session.');
|
|
1403
|
+
}
|
|
1404
|
+
codexMutationMarketplaces.clear();
|
|
1405
|
+
// Platform mutations already invalidated and observed their generation.
|
|
1406
|
+
// Only legacy writes still deferred in the dirty set need invalidation.
|
|
1407
|
+
for (const marketplaceName of changedMarketplaces)
|
|
1408
|
+
session.invalidate(marketplaceName);
|
|
1409
|
+
await Promise.all(marketplaces.map((marketplaceName) => session.snapshot(marketplaceName, options.context.codexObservationScopeByMarketplace?.get(marketplaceName)
|
|
1410
|
+
?? (options.targets.some((target) => (nativeMarketplaceEligibleTargets?.has(target) ?? true)
|
|
1411
|
+
&& target.identity.platform === 'codex'
|
|
1412
|
+
&& (target.platformDeployment ? target.platformDeployment.plans.some((plan) => plan.evidence.layout.marketplaceName === marketplaceName && plan.binding.scope.kind === 'project')
|
|
1413
|
+
: (target.identity.marketplaceName ?? MARKETPLACE_NAME) === marketplaceName && target.identity.scope === 'project'))
|
|
1414
|
+
? 'both'
|
|
1415
|
+
: 'user'))));
|
|
1416
|
+
},
|
|
2661
1417
|
preflightMaterialize: async (target) => {
|
|
2662
1418
|
if (target.identity.sourceId && options.context.expectedCatalogConfigDigest) {
|
|
2663
1419
|
const current = await readCatalogSourcesConfigSnapshot(options.context.env);
|
|
@@ -2665,47 +1421,22 @@ function createNativeDriver(options) {
|
|
|
2665
1421
|
throw new Error('catalogSourceConflict: catalog source config changed before owner publication.');
|
|
2666
1422
|
}
|
|
2667
1423
|
}
|
|
2668
|
-
if (target.identity.platform === 'claude')
|
|
1424
|
+
if (target.identity.platform === 'claude')
|
|
2669
1425
|
await assertNoClaudeUnboundNativeNameCollision({
|
|
2670
|
-
pluginName: target.identity.pluginName,
|
|
2671
|
-
cwd: target.identity.cwd,
|
|
2672
|
-
env: options.context.env,
|
|
1426
|
+
pluginName: target.identity.pluginName, cwd: target.identity.cwd, env: options.context.env
|
|
2673
1427
|
});
|
|
2674
|
-
return;
|
|
2675
|
-
}
|
|
2676
|
-
const marketplaceName = target.identity.marketplaceName ?? MARKETPLACE_NAME;
|
|
2677
|
-
const marketplaceRoot = target.identity.marketplaceRoot ?? resolveAwHome(options.context.env);
|
|
2678
|
-
const config = await readCodexConfigFile(resolveCodexPaths(target.identity.cwd, 'user', options.context.env).configTomlPath);
|
|
2679
|
-
const marketplace = config.snapshot.marketplaces[marketplaceName];
|
|
2680
|
-
const canonical = marketplace?.sourceType === 'local'
|
|
2681
|
-
&& !marketplace.sourcePointsToManifest
|
|
2682
|
-
&& path.resolve(marketplace.source ?? '') === path.resolve(marketplaceRoot);
|
|
2683
|
-
const expectedPluginId = `${target.identity.pluginName}@${marketplaceName}`;
|
|
2684
|
-
if ((marketplace !== undefined && !canonical)
|
|
2685
|
-
|| (Object.hasOwn(config.snapshot.plugins, expectedPluginId) && !canonical)) {
|
|
2686
|
-
throw new Error(`externalOwnershipPresent: Codex marketplace ${marketplaceName} has a foreign source instead of its canonical namespaced root.`);
|
|
2687
|
-
}
|
|
2688
|
-
},
|
|
2689
|
-
commitMaterialize: async (target) => {
|
|
2690
|
-
const transaction = mirrorTransactions.get(target);
|
|
2691
|
-
if (!transaction)
|
|
2692
|
-
return;
|
|
2693
|
-
await transaction.commit();
|
|
2694
|
-
mirrorTransactions.delete(target);
|
|
2695
1428
|
},
|
|
2696
|
-
|
|
2697
|
-
const
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
1429
|
+
finalizeCleanup: async (target) => {
|
|
1430
|
+
for (const action of target.operationActions ?? []) {
|
|
1431
|
+
if (action.kind !== 'retainManagedCommandPackage')
|
|
1432
|
+
continue;
|
|
1433
|
+
options.context.commandResults ??= [];
|
|
1434
|
+
if (!options.context.commandResults.some((result) => result.packageId === action.packageId))
|
|
1435
|
+
options.context.commandResults.push(retainedManagedCommandPackageResult(action));
|
|
1436
|
+
}
|
|
2702
1437
|
},
|
|
2703
|
-
finalizeCleanup: finalizeNamespacedCleanup,
|
|
2704
1438
|
probeNative: async (component) => {
|
|
2705
|
-
const target =
|
|
2706
|
-
&& entry.target.identity.sourceId === component.identity.sourceId
|
|
2707
|
-
&& entry.target.identity.platform === component.identity.platform
|
|
2708
|
-
&& entry.target.identity.scope === component.identity.scope)?.target;
|
|
1439
|
+
const target = findTarget(component);
|
|
2709
1440
|
if (!target)
|
|
2710
1441
|
throw new Error('Native ownership probe cannot resolve its desired target.');
|
|
2711
1442
|
if (target.identity.platform === 'claude') {
|
|
@@ -2720,22 +1451,24 @@ function createNativeDriver(options) {
|
|
|
2720
1451
|
return state.pluginState;
|
|
2721
1452
|
}
|
|
2722
1453
|
if (target.identity.platform === 'codex') {
|
|
2723
|
-
const
|
|
2724
|
-
|
|
1454
|
+
const pending = pendingCodexNativeStates.get(codexStateKey(target, component.pluginId));
|
|
1455
|
+
if (pending)
|
|
1456
|
+
return pending;
|
|
1457
|
+
const registration = await inspectCodexPluginRegistrationLive({
|
|
1458
|
+
pluginId: component.pluginId,
|
|
2725
1459
|
cwd: target.identity.cwd,
|
|
2726
1460
|
env: options.context.env,
|
|
2727
|
-
|
|
2728
|
-
|
|
1461
|
+
nativeCliRunner: runner,
|
|
1462
|
+
manager: currentCodexManager(),
|
|
1463
|
+
scope: observationScopeFor(target),
|
|
1464
|
+
observationSession: options.context.codexObservationSession,
|
|
2729
1465
|
});
|
|
2730
|
-
return
|
|
1466
|
+
return observedCodexNativeState(registration.observation, 'native probe');
|
|
2731
1467
|
}
|
|
2732
1468
|
return 'absent';
|
|
2733
1469
|
},
|
|
2734
1470
|
probeNativeHealth: async (component) => {
|
|
2735
|
-
const target =
|
|
2736
|
-
&& entry.target.identity.sourceId === component.identity.sourceId
|
|
2737
|
-
&& entry.target.identity.platform === component.identity.platform
|
|
2738
|
-
&& entry.target.identity.scope === component.identity.scope)?.target;
|
|
1471
|
+
const target = findTarget(component);
|
|
2739
1472
|
if (!target)
|
|
2740
1473
|
throw new Error('Native health probe cannot resolve its desired target.');
|
|
2741
1474
|
if (target.identity.platform === 'claude') {
|
|
@@ -2749,84 +1482,92 @@ function createNativeDriver(options) {
|
|
|
2749
1482
|
});
|
|
2750
1483
|
if (state.pluginState !== 'present')
|
|
2751
1484
|
return state.pluginState;
|
|
2752
|
-
|
|
1485
|
+
if (!state.pluginEnabled)
|
|
1486
|
+
return 'partial';
|
|
1487
|
+
return 'present';
|
|
2753
1488
|
}
|
|
2754
1489
|
if (target.identity.platform === 'codex') {
|
|
2755
|
-
const
|
|
2756
|
-
|
|
1490
|
+
const pluginId = `${target.identity.pluginName}@${target.identity.marketplaceName ?? MARKETPLACE_NAME}`;
|
|
1491
|
+
const registration = await inspectCodexPluginRegistrationLive({
|
|
1492
|
+
pluginId,
|
|
2757
1493
|
cwd: target.identity.cwd,
|
|
2758
1494
|
env: options.context.env,
|
|
2759
|
-
|
|
2760
|
-
|
|
1495
|
+
nativeCliRunner: runner,
|
|
1496
|
+
manager: currentCodexManager(),
|
|
1497
|
+
scope: observationScopeFor(target),
|
|
1498
|
+
observationSession: options.context.codexObservationSession,
|
|
2761
1499
|
});
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
return 'present';
|
|
1500
|
+
const nativeState = observedCodexNativeState(registration.observation, 'native health postcheck');
|
|
1501
|
+
if (nativeState !== 'present')
|
|
1502
|
+
return nativeState;
|
|
2766
1503
|
const userConfig = await readCodexConfigFile(resolveCodexPaths(target.identity.cwd, 'user', options.context.env).configTomlPath);
|
|
1504
|
+
const userEnabled = userConfig.snapshot.plugins[pluginId]?.enabled === true;
|
|
1505
|
+
if (target.identity.scope === 'user')
|
|
1506
|
+
return userEnabled ? 'present' : 'partial';
|
|
2767
1507
|
const projectConfig = await readCodexConfigFile(resolveCodexPaths(target.identity.cwd, 'project', options.context.env).configTomlPath);
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
const invocations = buildCodexProjectPluginListInvocations(codexManager, {
|
|
2772
|
-
exactCwd: target.identity.cwd,
|
|
2773
|
-
neutralCwd,
|
|
2774
|
-
env: options.context.env,
|
|
2775
|
-
});
|
|
2776
|
-
const [exactResult, neutralResult] = await Promise.all([
|
|
2777
|
-
runNativeCliChecked(invocations.exact, runner),
|
|
2778
|
-
runNativeCliChecked(invocations.neutral, runner),
|
|
2779
|
-
]);
|
|
2780
|
-
postcheckCodexProjectPluginActivation({
|
|
2781
|
-
pluginId,
|
|
2782
|
-
userEnabled: userConfig.snapshot.plugins[pluginId]?.enabled === true,
|
|
2783
|
-
projectEnabled: projectConfig.snapshot.plugins[pluginId]?.enabled === true,
|
|
2784
|
-
exactResult,
|
|
2785
|
-
neutralResult,
|
|
2786
|
-
});
|
|
2787
|
-
}
|
|
2788
|
-
finally {
|
|
2789
|
-
await fs.remove(neutralCwd);
|
|
2790
|
-
}
|
|
2791
|
-
return 'present';
|
|
1508
|
+
return userEnabled || projectConfig.snapshot.plugins[pluginId]?.enabled === true
|
|
1509
|
+
? 'present'
|
|
1510
|
+
: 'partial';
|
|
2792
1511
|
}
|
|
2793
1512
|
return 'absent';
|
|
2794
1513
|
},
|
|
2795
1514
|
removeNative: async (component) => {
|
|
2796
|
-
const target =
|
|
2797
|
-
&& entry.target.identity.sourceId === component.identity.sourceId
|
|
2798
|
-
&& entry.target.identity.platform === component.identity.platform
|
|
2799
|
-
&& entry.target.identity.scope === component.identity.scope)?.target;
|
|
1515
|
+
const target = findTarget(component);
|
|
2800
1516
|
if (!target)
|
|
2801
1517
|
throw new Error('Native ownership removal cannot resolve its desired target.');
|
|
1518
|
+
await prepareNativeGroup(target);
|
|
2802
1519
|
if (target.identity.platform === 'codex') {
|
|
2803
|
-
const
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
marketplaceRoot: target.identity.marketplaceRoot,
|
|
2809
|
-
});
|
|
2810
|
-
if (before.state === 'foreign') {
|
|
2811
|
-
throw new Error(`Codex native owner 为 foreign,拒绝调用 plugin remove:${before.labels.join(',')}`);
|
|
1520
|
+
const marketplaceName = component.pluginId.slice(component.pluginId.lastIndexOf('@') + 1);
|
|
1521
|
+
const stateKey = codexStateKey(target, component.pluginId);
|
|
1522
|
+
const before = pendingCodexNativeStates.get(stateKey) ?? codexNativeStates.get(stateKey);
|
|
1523
|
+
if (!before) {
|
|
1524
|
+
throw new Error('codexNativeObservationUnavailable: native group precheck is missing.');
|
|
2812
1525
|
}
|
|
2813
|
-
|
|
1526
|
+
const removalRequired = before === 'present';
|
|
1527
|
+
if (!removalRequired)
|
|
2814
1528
|
return;
|
|
2815
1529
|
try {
|
|
2816
|
-
|
|
1530
|
+
codexMutationMarketplaces.add(marketplaceName);
|
|
1531
|
+
await runObservedCodexMutation({
|
|
1532
|
+
marketplaceName,
|
|
1533
|
+
mutation: () => runNativeCliChecked(buildCodexPluginRemoveInvocation(requireCodexManager(currentCodexManager()), component.pluginId, target.identity.cwd, options.context.env), runner),
|
|
1534
|
+
});
|
|
2817
1535
|
}
|
|
2818
|
-
catch {
|
|
2819
|
-
|
|
1536
|
+
catch (error) {
|
|
1537
|
+
const diagnostic = readSafeOperationError(error);
|
|
1538
|
+
throw attachSafeOperationError(new Error(`codexNativeRemoveFailed: ${CODEX_REMOVE_RECOVERY}`), {
|
|
1539
|
+
code: 'codexNativeRemoveFailed',
|
|
1540
|
+
safeMessage: `Codex plugin removal did not complete. ${CODEX_REMOVE_RECOVERY}`,
|
|
1541
|
+
...(diagnostic?.exitCode === undefined ? {} : { exitCode: diagnostic.exitCode }),
|
|
1542
|
+
...(diagnostic ? {
|
|
1543
|
+
cause: { code: diagnostic.code, safeMessage: diagnostic.safeMessage },
|
|
1544
|
+
} : {}),
|
|
1545
|
+
});
|
|
2820
1546
|
}
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
1547
|
+
pendingCodexNativeStates.set(stateKey, 'absent');
|
|
1548
|
+
const postcheck = async () => {
|
|
1549
|
+
const after = await inspectCodexPluginRegistrationLive({
|
|
1550
|
+
pluginId: component.pluginId,
|
|
1551
|
+
cwd: target.identity.cwd,
|
|
1552
|
+
env: options.context.env,
|
|
1553
|
+
nativeCliRunner: runner,
|
|
1554
|
+
manager: currentCodexManager(),
|
|
1555
|
+
scope: observationScopeFor(target),
|
|
1556
|
+
observationSession: options.context.codexObservationSession,
|
|
1557
|
+
});
|
|
1558
|
+
const expected = pendingCodexNativeStates.get(stateKey) ?? 'absent';
|
|
1559
|
+
const observed = requireObservedCodexNativeState(after.observation, 'native mutation postcheck');
|
|
1560
|
+
if ((observed === 'installed' ? 'present' : 'absent') !== expected) {
|
|
1561
|
+
throw new Error(expected === 'absent'
|
|
1562
|
+
? `codexNativeRemoveIncomplete: ${CODEX_REMOVE_RECOVERY}`
|
|
1563
|
+
: `codexNativeInstallIncomplete: ${component.pluginId} is absent from Codex plugin list.`);
|
|
1564
|
+
}
|
|
1565
|
+
};
|
|
1566
|
+
if (options.operationScopedNativePhases) {
|
|
1567
|
+
deferredPostchecks.push({ target, postcheck });
|
|
1568
|
+
}
|
|
1569
|
+
else {
|
|
1570
|
+
await postcheck();
|
|
2830
1571
|
}
|
|
2831
1572
|
}
|
|
2832
1573
|
else {
|
|
@@ -2855,497 +1596,129 @@ function createNativeDriver(options) {
|
|
|
2855
1596
|
}
|
|
2856
1597
|
}
|
|
2857
1598
|
},
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
if (!plan)
|
|
2861
|
-
throw new Error('Missing rebuild integration plan.');
|
|
2862
|
-
const marketplaceName = target.identity.marketplaceName ?? MARKETPLACE_NAME;
|
|
2863
|
-
const expectedMarketplaceRoot = target.identity.marketplaceRoot ?? resolveAwHome(options.context.env);
|
|
2864
|
-
if (target.identity.platform === 'codex') {
|
|
2865
|
-
const before = await inspectCodexNativeResidue({
|
|
2866
|
-
pluginName: target.identity.pluginName,
|
|
2867
|
-
cwd: target.identity.cwd,
|
|
2868
|
-
env: options.context.env,
|
|
2869
|
-
marketplaceName,
|
|
2870
|
-
marketplaceRoot: expectedMarketplaceRoot,
|
|
2871
|
-
});
|
|
2872
|
-
if (before.state === 'foreign') {
|
|
2873
|
-
throw new Error(`codexSharedNativeForeign: ${before.labels.join(', ')}`);
|
|
2874
|
-
}
|
|
2875
|
-
if (before.state === 'present') {
|
|
2876
|
-
await runNativeCliChecked(buildCodexPluginRemoveInvocation(requireCodexManager(codexManager), `${target.identity.pluginName}@${marketplaceName}`, target.identity.cwd, options.context.env), runner);
|
|
2877
|
-
}
|
|
2878
|
-
}
|
|
2879
|
-
const writeGeneration = async () => {
|
|
2880
|
-
if (mirrorTransactions.has(target)) {
|
|
2881
|
-
throw new Error('Marketplace mirror transaction is already active for this target.');
|
|
2882
|
-
}
|
|
2883
|
-
{
|
|
2884
|
-
if (target.identity.platform === 'codex') {
|
|
2885
|
-
const config = await readCodexConfigFile(resolveCodexPaths(target.identity.cwd, 'user', options.context.env).configTomlPath);
|
|
2886
|
-
const marketplace = config.snapshot.marketplaces[marketplaceName];
|
|
2887
|
-
if (marketplace && (marketplace.sourceType !== 'local'
|
|
2888
|
-
|| marketplace.sourcePointsToManifest
|
|
2889
|
-
|| path.normalize(marketplace.source ?? '') !== path.normalize(expectedMarketplaceRoot))) {
|
|
2890
|
-
throw new Error(`externalOwnershipPresent: Codex marketplace ${marketplaceName} 已由 foreign source 占用,拒绝覆盖。`);
|
|
2891
|
-
}
|
|
2892
|
-
}
|
|
2893
|
-
else {
|
|
2894
|
-
const state = await readClaudeNativeState({
|
|
2895
|
-
pluginName: target.identity.pluginName,
|
|
2896
|
-
scope: target.identity.scope,
|
|
2897
|
-
cwd: target.identity.cwd,
|
|
2898
|
-
env: options.context.env,
|
|
2899
|
-
marketplaceName,
|
|
2900
|
-
marketplaceRoot: expectedMarketplaceRoot,
|
|
2901
|
-
});
|
|
2902
|
-
if (state.marketplaceState === 'foreign') {
|
|
2903
|
-
throw new Error(`Claude marketplace ${marketplaceName} 已由 foreign source 占用,拒绝覆盖。`);
|
|
2904
|
-
}
|
|
2905
|
-
}
|
|
2906
|
-
const mirrored = await mirrorCatalog(plan.catalog, options.context.env, target.identity);
|
|
2907
|
-
mirrorTransactions.set(target, mirrored);
|
|
2908
|
-
const marketplaceRoot = mirrored.rootDir;
|
|
2909
|
-
const pluginId = `${target.identity.pluginName}@${marketplaceName}`;
|
|
2910
|
-
if (target.identity.platform === 'codex') {
|
|
2911
|
-
const nativePluginRoot = await canonicalizePathThroughExistingAncestor(path.join(marketplaceRoot, 'plugins', target.identity.pluginName));
|
|
2912
|
-
const requiredSkillWrites = plan.writes.filter((entry) => !entry.optional
|
|
2913
|
-
&& entry.component?.kind === 'skill-directory'
|
|
2914
|
-
&& entry.artifact.kind === 'skill'
|
|
2915
|
-
&& entry.artifact.state !== 'disabled'
|
|
2916
|
-
&& target.identity.scope === 'user'
|
|
2917
|
-
&& !path.relative(nativePluginRoot, entry.component.path).startsWith('..'));
|
|
2918
|
-
for (const write of requiredSkillWrites) {
|
|
2919
|
-
await write.write();
|
|
2920
|
-
}
|
|
2921
|
-
const skillsRelativeRoot = await ensureCodexActiveSkillsManifest({
|
|
2922
|
-
plugin: target.plugin,
|
|
2923
|
-
marketplaceRoot,
|
|
2924
|
-
hasRequiredSkills: target.identity.scope === 'project'
|
|
2925
|
-
? target.plugin.manifest.skills !== undefined
|
|
2926
|
-
: requiredSkillWrites.length > 0,
|
|
2927
|
-
});
|
|
2928
|
-
const config = await readCodexConfigFile(resolveCodexPaths(target.identity.cwd, 'user', options.context.env).configTomlPath);
|
|
2929
|
-
const marketplace = config.snapshot.marketplaces[marketplaceName];
|
|
2930
|
-
if (path.normalize(marketplace?.source ?? '') !== path.normalize(marketplaceRoot)) {
|
|
2931
|
-
await runNativeCliChecked(buildCodexMarketplaceAddInvocation(requireCodexManager(codexManager), marketplaceRoot, target.identity.cwd, options.context.env), runner);
|
|
2932
|
-
}
|
|
2933
|
-
await runNativeCliChecked(buildCodexMarketplaceListInvocation(requireCodexManager(codexManager), target.identity.cwd, options.context.env), runner);
|
|
2934
|
-
await runNativeCliChecked(buildCodexPluginAddInvocation(requireCodexManager(codexManager), pluginId, target.identity.cwd, options.context.env), runner);
|
|
2935
|
-
await runNativeCliChecked(buildCodexPluginListInvocation(requireCodexManager(codexManager), target.identity.cwd, options.context.env), runner);
|
|
2936
|
-
await assertCodexNativeInstallState({
|
|
2937
|
-
pluginName: target.identity.pluginName,
|
|
2938
|
-
pluginVersion: target.identity.pluginVersion,
|
|
2939
|
-
cwd: target.identity.cwd,
|
|
2940
|
-
env: options.context.env,
|
|
2941
|
-
marketplaceRoot,
|
|
2942
|
-
marketplaceName,
|
|
2943
|
-
skillsRelativeRoot,
|
|
2944
|
-
requiredSkillKeys: requiredSkillWrites.flatMap((write) => write.artifact.artifactKey ? [write.artifact.artifactKey] : []),
|
|
2945
|
-
});
|
|
2946
|
-
}
|
|
2947
|
-
else {
|
|
2948
|
-
await runNativeCliChecked({
|
|
2949
|
-
command: 'claude',
|
|
2950
|
-
args: ['plugin', 'marketplace', 'add', marketplaceRoot, '--scope', target.identity.scope],
|
|
2951
|
-
cwd: target.identity.cwd,
|
|
2952
|
-
env: options.context.env,
|
|
2953
|
-
}, runner);
|
|
2954
|
-
await runNativeCliChecked({
|
|
2955
|
-
command: 'claude',
|
|
2956
|
-
args: ['plugin', 'install', pluginId, '--scope', target.identity.scope],
|
|
2957
|
-
cwd: target.identity.cwd,
|
|
2958
|
-
env: options.context.env,
|
|
2959
|
-
}, runner);
|
|
2960
|
-
await runNativeCliChecked({
|
|
2961
|
-
command: 'claude',
|
|
2962
|
-
args: ['plugin', 'list'],
|
|
2963
|
-
cwd: target.identity.cwd,
|
|
2964
|
-
env: options.context.env,
|
|
2965
|
-
}, runner);
|
|
2966
|
-
const after = await readClaudeNativeState({
|
|
2967
|
-
pluginName: target.identity.pluginName,
|
|
2968
|
-
scope: target.identity.scope,
|
|
2969
|
-
cwd: target.identity.cwd,
|
|
2970
|
-
env: options.context.env,
|
|
2971
|
-
marketplaceName,
|
|
2972
|
-
marketplaceRoot,
|
|
2973
|
-
});
|
|
2974
|
-
if (after.marketplaceDeclaredState !== 'canonical'
|
|
2975
|
-
|| after.marketplaceMaterializedState !== 'canonical'
|
|
2976
|
-
|| after.pluginState !== 'present'
|
|
2977
|
-
|| !after.pluginEnabled
|
|
2978
|
-
|| !after.pluginVersions.includes(target.identity.pluginVersion)) {
|
|
2979
|
-
throw new Error(`Claude native install postcheck 失败:declaredMarketplace=${after.marketplaceDeclaredState},materializedMarketplace=${after.marketplaceMaterializedState},plugin=${after.pluginState},enabled=${after.pluginEnabled},versions=${after.pluginVersions.join(',')}。`);
|
|
2980
|
-
}
|
|
2981
|
-
}
|
|
2982
|
-
}
|
|
2983
|
-
};
|
|
2984
|
-
await writeGeneration();
|
|
2985
|
-
},
|
|
1599
|
+
applyManagedCommands: (target) => publishLifecycleCommandPackages(target, options.context),
|
|
1600
|
+
writeNative: async () => { throw new Error('platformDeploymentRequired: native writes require a frozen platform deployment.'); },
|
|
2986
1601
|
writeArtifacts: async (target) => {
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
const writeAll = async () => {
|
|
2991
|
-
for (const write of plan.writes)
|
|
2992
|
-
await write.write();
|
|
2993
|
-
return plan.writes.map((write) => write.artifact);
|
|
2994
|
-
};
|
|
2995
|
-
return writeAll();
|
|
1602
|
+
if (target.artifacts.length > 0)
|
|
1603
|
+
throw new Error('platformDeploymentRequired: platform output requires a frozen platform deployment.');
|
|
1604
|
+
return [];
|
|
2996
1605
|
},
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
1606
|
+
runPreApply: async (invocation) => {
|
|
1607
|
+
if (isNativeActivationOnlyTarget(options.context, invocation.target.identity))
|
|
1608
|
+
return;
|
|
1609
|
+
const run = () => runPreApplyScript({
|
|
1610
|
+
plugin: invocation.plugin,
|
|
3001
1611
|
platform: invocation.target.identity.platform,
|
|
3002
1612
|
scope: invocation.target.identity.scope,
|
|
3003
1613
|
cwd: invocation.target.identity.cwd,
|
|
3004
1614
|
context: options.context,
|
|
3005
|
-
|
|
3006
|
-
artifacts: [...invocation.artifacts],
|
|
1615
|
+
referencePlugins: options.context.referencePlugins,
|
|
3007
1616
|
scriptTimeoutMs: options.scriptTimeoutMs,
|
|
3008
1617
|
});
|
|
1618
|
+
const cache = options.context.preApplyExecutionCache;
|
|
1619
|
+
if (!cache) {
|
|
1620
|
+
await run();
|
|
1621
|
+
return;
|
|
1622
|
+
}
|
|
1623
|
+
const { identity } = invocation.target;
|
|
1624
|
+
const sourceIdentity = invocation.plugin.sourceIdentity ?? identity.sourceIdentity;
|
|
1625
|
+
const pluginId = invocation.plugin.pluginId ?? identity.pluginId;
|
|
1626
|
+
if (!sourceIdentity || !pluginId) {
|
|
1627
|
+
await run();
|
|
1628
|
+
return;
|
|
1629
|
+
}
|
|
1630
|
+
const projectKey = identity.scope === 'project'
|
|
1631
|
+
? identity.platform === 'codex'
|
|
1632
|
+
? await resolveCodexProjectKey(identity.cwd)
|
|
1633
|
+
: identity.platform === 'claude'
|
|
1634
|
+
? await resolveClaudeProjectKey(identity.cwd)
|
|
1635
|
+
: createProjectLocationKey(await resolveRequiredCanonicalRepoRoot(identity.cwd))
|
|
1636
|
+
: '';
|
|
1637
|
+
const key = [
|
|
1638
|
+
sourceIdentity,
|
|
1639
|
+
pluginId,
|
|
1640
|
+
identity.platform,
|
|
1641
|
+
identity.scope,
|
|
1642
|
+
projectKey,
|
|
1643
|
+
].join('\0');
|
|
1644
|
+
let execution = cache.get(key);
|
|
1645
|
+
if (!execution) {
|
|
1646
|
+
execution = run();
|
|
1647
|
+
cache.set(key, execution);
|
|
1648
|
+
}
|
|
1649
|
+
await execution;
|
|
3009
1650
|
},
|
|
3010
1651
|
};
|
|
3011
1652
|
}
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
return plan ? [{ target, plan }] : [];
|
|
3017
|
-
});
|
|
1653
|
+
export function isNativeActivationOnlyTarget(context, identity) {
|
|
1654
|
+
return context.nativeActivationOnlyTargets?.some((target) => target.pluginId === identity.pluginId
|
|
1655
|
+
&& target.platform === identity.platform
|
|
1656
|
+
&& target.scope === identity.scope) === true;
|
|
3018
1657
|
}
|
|
3019
1658
|
export function createRebuildIntegration(options) {
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
const driver = createNativeDriver({
|
|
1659
|
+
options.context.scriptTimeoutMs ??= options.scriptTimeoutMs;
|
|
1660
|
+
const targets = [...(options.preparedTargets ?? [])];
|
|
1661
|
+
const driver = createNativeDriver({ targets, ...options });
|
|
1662
|
+
const renderResults = options.context.preparedArtifactRenderResults ??= new Map();
|
|
1663
|
+
const packageCache = options.context.packagePreparationCache
|
|
1664
|
+
?? commandPackageCandidates.get(renderResults) ?? new Map();
|
|
1665
|
+
commandPackageCandidates.set(renderResults, packageCache);
|
|
1666
|
+
options.context.packagePreparationCache = packageCache;
|
|
1667
|
+
const sessions = platformRebuildSessions.get(renderResults) ?? new Map();
|
|
1668
|
+
platformRebuildSessions.set(renderResults, sessions);
|
|
1669
|
+
const platformSession = options.context.platformRebuildSession
|
|
1670
|
+
?? sessions.get(options.context.batchInstallPlatform)
|
|
1671
|
+
?? new PlatformRebuildSession(options.context);
|
|
1672
|
+
sessions.set(options.context.batchInstallPlatform, platformSession);
|
|
1673
|
+
options.context.platformRebuildSession = platformSession;
|
|
1674
|
+
platformSession.updateContext(options.context);
|
|
1675
|
+
platformSession.setOwnershipExecutor(driver.ownership);
|
|
1676
|
+
const targetPlatforms = new Map();
|
|
3023
1677
|
return {
|
|
1678
|
+
resolvePlatformTargets: async (inputs) => {
|
|
1679
|
+
await platformSession.resolveAll(inputs);
|
|
1680
|
+
for (const input of inputs) {
|
|
1681
|
+
const id = input.pluginId ?? pluginActionId(input.plugin);
|
|
1682
|
+
const platforms = targetPlatforms.get(id) ?? [];
|
|
1683
|
+
if (!platforms.includes(input.platform))
|
|
1684
|
+
platforms.push(input.platform);
|
|
1685
|
+
targetPlatforms.set(id, platforms);
|
|
1686
|
+
}
|
|
1687
|
+
},
|
|
1688
|
+
sealMarketplaceGenerations: (eligible) => platformSession.sealMarketplaceGenerations(eligible),
|
|
1689
|
+
pendingOpenCodeProjectNotices: (interrupted) => platformSession.pendingOpenCodeProjectNotices(interrupted),
|
|
3024
1690
|
driver,
|
|
1691
|
+
setNativeMarketplaceEligibleTargets: driver.setNativeMarketplaceEligibleTargets,
|
|
1692
|
+
prepareNativeMarketplaceGroup: driver.prepareNativeMarketplaceGroup,
|
|
1693
|
+
postcheckCodexProvider: driver.postcheckCodexProvider,
|
|
1694
|
+
captureCodexPostMutationSnapshots: driver.captureCodexPostMutationSnapshots,
|
|
3025
1695
|
buildTarget: async (input) => {
|
|
3026
|
-
const
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
managedPaths: input.platform === 'codex'
|
|
3034
|
-
? ['.codex/config.toml']
|
|
3035
|
-
: ['.claude/settings.json'],
|
|
3036
|
-
});
|
|
3037
|
-
input = { ...input, cwd: canonicalRepoRoot };
|
|
3038
|
-
}
|
|
3039
|
-
if (materializing && input.platform === 'codex') {
|
|
3040
|
-
await preflightCodexWriteSafety({
|
|
3041
|
-
plugin: input.plugin,
|
|
3042
|
-
scope: input.scope,
|
|
3043
|
-
cwd: input.cwd,
|
|
3044
|
-
env: options.context.env,
|
|
3045
|
-
});
|
|
3046
|
-
}
|
|
3047
|
-
const event = input.command === 'upgrade' ? 'upgrade' : 'install';
|
|
3048
|
-
let historicalArtifacts = [];
|
|
3049
|
-
if (input.includeHistoricalLifecycleArtifacts) {
|
|
3050
|
-
const loadPlugin = (bundleRoot) => readPluginManifest(bundleRoot, { mode: 'bundle' });
|
|
3051
|
-
const { readLifecycleActiveSnapshot } = await import('../utils/lifecycle-active-store.js');
|
|
3052
|
-
const active = await readLifecycleActiveSnapshot({
|
|
3053
|
-
...(input.sourceId ? {
|
|
3054
|
-
sourceId: input.sourceId,
|
|
3055
|
-
sourceIdentity: input.sourceIdentity,
|
|
3056
|
-
} : {}),
|
|
3057
|
-
pluginName: input.plugin.manifest.name,
|
|
3058
|
-
platform: input.platform,
|
|
3059
|
-
scope: input.scope,
|
|
3060
|
-
cwd: input.cwd,
|
|
3061
|
-
env: options.context.env,
|
|
3062
|
-
loadPlugin,
|
|
3063
|
-
});
|
|
3064
|
-
if (input.expectedLifecycleMetadataIntegrityDigest !== undefined
|
|
3065
|
-
&& active?.metadata.metadataIntegrityDigest
|
|
3066
|
-
!== input.expectedLifecycleMetadataIntegrityDigest) {
|
|
3067
|
-
throw new Error('stateInventoryFailed: lifecycle active generation changed after verified inventory.');
|
|
3068
|
-
}
|
|
3069
|
-
historicalArtifacts = active?.artifacts ?? [];
|
|
3070
|
-
}
|
|
3071
|
-
let writes = [];
|
|
3072
|
-
let currentRemovalComponents = [];
|
|
3073
|
-
if (input.command !== 'cleanup' && input.command !== 'uninstall') {
|
|
3074
|
-
if (input.readOnlyInspectionPlan) {
|
|
3075
|
-
writes = await buildInspectionWrites({
|
|
3076
|
-
plugin: input.plugin,
|
|
3077
|
-
platform: input.platform,
|
|
3078
|
-
scope: input.scope,
|
|
3079
|
-
cwd: input.cwd,
|
|
3080
|
-
env: options.context.env,
|
|
3081
|
-
marketplaceRoot: input.marketplaceRoot,
|
|
3082
|
-
marketplaceName: input.marketplaceName,
|
|
3083
|
-
userActivationDesired: options.context.codexUserActivationDesired,
|
|
3084
|
-
});
|
|
3085
|
-
}
|
|
3086
|
-
else if (input.platform === 'codex') {
|
|
3087
|
-
writes = await buildCodexWrites({
|
|
3088
|
-
...input,
|
|
3089
|
-
env: options.context.env,
|
|
3090
|
-
event,
|
|
3091
|
-
historicalArtifacts,
|
|
3092
|
-
scriptTimeoutMs: options.scriptTimeoutMs,
|
|
3093
|
-
marketplaceName: input.marketplaceName,
|
|
3094
|
-
userActivationDesired: options.context.codexUserActivationDesired,
|
|
3095
|
-
});
|
|
1696
|
+
const removed = input.command === 'cleanup' || input.command === 'uninstall';
|
|
1697
|
+
const id = input.pluginId ?? pluginActionId(input.plugin);
|
|
1698
|
+
const platforms = options.context.commandPackagePlatforms?.get(id) ?? targetPlatforms.get(id) ?? [input.platform];
|
|
1699
|
+
let commands;
|
|
1700
|
+
if (!input.readOnlyInspectionPlan) {
|
|
1701
|
+
try {
|
|
1702
|
+
commands = await prepareLifecycleCommandPackage({ ...input, removing: removed, platforms, context: options.context });
|
|
3096
1703
|
}
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
event,
|
|
3102
|
-
historicalArtifacts,
|
|
3103
|
-
scriptTimeoutMs: options.scriptTimeoutMs,
|
|
3104
|
-
});
|
|
1704
|
+
catch (error) {
|
|
1705
|
+
if (error instanceof ManagedCommandError)
|
|
1706
|
+
throw new Error(`${error.code}: ${error.message}`, { cause: error });
|
|
1707
|
+
throw error;
|
|
3105
1708
|
}
|
|
3106
1709
|
}
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
...(write.additionalComponents ?? []),
|
|
3120
|
-
...(write.component ? [write.component] : []),
|
|
3121
|
-
]);
|
|
3122
|
-
}
|
|
3123
|
-
const desiredComponents = writes.filter((write) => !write.optional).flatMap((write) => [
|
|
3124
|
-
...(write.additionalComponents ?? []),
|
|
3125
|
-
...(write.component ? [write.component] : []),
|
|
3126
|
-
]);
|
|
3127
|
-
const optionalComponents = writes
|
|
3128
|
-
.filter((write) => write.optional)
|
|
3129
|
-
.flatMap((write) => [
|
|
3130
|
-
...(write.additionalComponents ?? []),
|
|
3131
|
-
...(write.component ? [write.component] : []),
|
|
3132
|
-
]);
|
|
3133
|
-
const optionalComponentKeys = new Set(optionalComponents.map(componentIdentityKey));
|
|
3134
|
-
const configDir = input.platform === 'codex'
|
|
3135
|
-
? resolveCodexPaths(input.cwd, input.scope, options.context.env).configDir
|
|
3136
|
-
: resolveClaudePaths(input.cwd, input.scope, options.context.env).configDir;
|
|
3137
|
-
const textRoots = input.platform === 'codex'
|
|
3138
|
-
? [path.join(configDir, 'rules'), path.join(configDir, 'agents')]
|
|
3139
|
-
: [path.join(configDir, 'rules'), path.join(configDir, 'agents')];
|
|
3140
|
-
const scannedText = (await Promise.all(textRoots.map((root) => scanOwnedTextFiles({
|
|
3141
|
-
sourceId: input.sourceId,
|
|
3142
|
-
sourceIdentity: input.sourceIdentity,
|
|
3143
|
-
root,
|
|
3144
|
-
pluginName: input.plugin.manifest.name,
|
|
3145
|
-
platform: input.platform,
|
|
3146
|
-
scope: input.scope,
|
|
3147
|
-
})))).flat();
|
|
3148
|
-
const skillRoots = input.platform === 'codex'
|
|
3149
|
-
? input.scope === 'project'
|
|
3150
|
-
? []
|
|
3151
|
-
: [
|
|
3152
|
-
path.join(getCodexHome(options.context.env), 'skills'),
|
|
3153
|
-
...(input.preserveCodexSharedNativePayload
|
|
3154
|
-
? []
|
|
3155
|
-
: [await canonicalizePathThroughExistingAncestor(path.join(input.marketplaceRoot ?? resolveAwHome(options.context.env), 'plugins', input.plugin.manifest.name))]),
|
|
3156
|
-
]
|
|
3157
|
-
: [path.join(configDir, 'skills')];
|
|
3158
|
-
const scanSkills = () => Promise.all(skillRoots.map((root) => scanOwnedSkills({
|
|
3159
|
-
sourceId: input.sourceId,
|
|
3160
|
-
sourceIdentity: input.sourceIdentity,
|
|
3161
|
-
root,
|
|
3162
|
-
pluginName: input.plugin.manifest.name,
|
|
3163
|
-
platform: input.platform,
|
|
3164
|
-
scope: input.scope,
|
|
3165
|
-
})));
|
|
3166
|
-
const scannedSkills = (await scanSkills()).flat();
|
|
3167
|
-
let historicalComponents = await buildHistoricalComponents({
|
|
3168
|
-
sourceId: input.sourceId,
|
|
3169
|
-
sourceIdentity: input.sourceIdentity,
|
|
3170
|
-
pluginId: input.pluginId,
|
|
3171
|
-
pluginName: input.plugin.manifest.name,
|
|
3172
|
-
platform: input.platform,
|
|
3173
|
-
scope: input.scope,
|
|
3174
|
-
cwd: input.cwd,
|
|
3175
|
-
env: options.context.env,
|
|
3176
|
-
artifacts: historicalArtifacts,
|
|
3177
|
-
command: input.command,
|
|
3178
|
-
});
|
|
3179
|
-
if (input.preserveCodexSharedNativePayload) {
|
|
3180
|
-
const nativePluginRoots = await Promise.all([
|
|
3181
|
-
path.join(input.marketplaceRoot ?? resolveAwHome(options.context.env), 'plugins', input.plugin.manifest.name),
|
|
3182
|
-
path.join(getCodexHome(options.context.env), 'plugins', 'cache', input.marketplaceName ?? MARKETPLACE_NAME, input.plugin.manifest.name),
|
|
3183
|
-
].map((root) => canonicalizePathThroughExistingAncestor(root)));
|
|
3184
|
-
historicalComponents = historicalComponents.filter((component) => {
|
|
3185
|
-
if (!('path' in component))
|
|
3186
|
-
return true;
|
|
3187
|
-
return nativePluginRoots.every((nativePluginRoot) => {
|
|
3188
|
-
const relative = path.relative(nativePluginRoot, path.resolve(component.path));
|
|
3189
|
-
return relative === '..'
|
|
3190
|
-
|| relative.startsWith(`..${path.sep}`)
|
|
3191
|
-
|| path.isAbsolute(relative);
|
|
3192
|
-
});
|
|
3193
|
-
});
|
|
3194
|
-
}
|
|
3195
|
-
const sharedComponents = input.platform === 'codex'
|
|
3196
|
-
? await scanCodexSharedComponents({
|
|
3197
|
-
sourceId: input.sourceId,
|
|
3198
|
-
sourceIdentity: input.sourceIdentity,
|
|
3199
|
-
pluginId: input.pluginId,
|
|
3200
|
-
pluginName: input.plugin.manifest.name,
|
|
3201
|
-
scope: input.scope,
|
|
3202
|
-
paths: resolveCodexPaths(input.cwd, input.scope, options.context.env),
|
|
3203
|
-
scanConfig: true,
|
|
3204
|
-
ignoreReadErrors: true,
|
|
3205
|
-
})
|
|
3206
|
-
: await scanClaudeSharedComponents({
|
|
3207
|
-
sourceId: input.sourceId,
|
|
3208
|
-
sourceIdentity: input.sourceIdentity,
|
|
3209
|
-
pluginId: input.pluginId,
|
|
3210
|
-
pluginName: input.plugin.manifest.name,
|
|
3211
|
-
scope: input.scope,
|
|
3212
|
-
settingsPath: resolveClaudePaths(input.cwd, input.scope, options.context.env).settingsPath,
|
|
3213
|
-
});
|
|
3214
|
-
const nativeRequired = input.platform === 'claude'
|
|
3215
|
-
|| analyzeCodexSurface(input.plugin.manifest).nativeKinds.length > 0;
|
|
3216
|
-
const nativeDesired = nativeRequired
|
|
3217
|
-
&& input.command !== 'cleanup'
|
|
3218
|
-
&& input.command !== 'uninstall';
|
|
3219
|
-
const codexNative = input.platform === 'codex' && nativeRequired
|
|
3220
|
-
? await inspectCodexNativeResidue({
|
|
3221
|
-
pluginName: input.plugin.manifest.name,
|
|
3222
|
-
cwd: input.cwd,
|
|
3223
|
-
env: options.context.env,
|
|
3224
|
-
marketplaceName: input.marketplaceName,
|
|
3225
|
-
marketplaceRoot: input.marketplaceRoot,
|
|
3226
|
-
})
|
|
3227
|
-
: undefined;
|
|
3228
|
-
const codexNativeExact = codexNative?.state === 'present'
|
|
3229
|
-
&& codexNative.versions.length > 0
|
|
3230
|
-
&& codexNative.versions.every((version) => version === input.plugin.manifest.version);
|
|
3231
|
-
const materializeNativeRequired = nativeDesired && (input.platform === 'claude'
|
|
3232
|
-
|| input.command === 'reinstall'
|
|
3233
|
-
|| !codexNativeExact);
|
|
3234
|
-
const nativeCleanupCandidate = input.platform === 'claude'
|
|
3235
|
-
&& input.includeNativeCleanupCandidate !== false;
|
|
3236
|
-
const nativePlugin = (nativeDesired || nativeCleanupCandidate)
|
|
3237
|
-
? [{
|
|
3238
|
-
kind: 'native-plugin',
|
|
3239
|
-
identity: ownerIdentity(input.plugin.manifest.name, 'native', input.platform, input.scope),
|
|
3240
|
-
pluginId: `${input.plugin.manifest.name}@${input.marketplaceName ?? MARKETPLACE_NAME}`,
|
|
3241
|
-
}]
|
|
3242
|
-
: [];
|
|
3243
|
-
const marketplaceDesired = nativeRequired
|
|
3244
|
-
&& input.command !== 'cleanup'
|
|
3245
|
-
&& input.command !== 'uninstall';
|
|
3246
|
-
const marketplace = input.platform === 'codex' && input.scope === 'user' && nativeDesired
|
|
3247
|
-
? [createCodexMarketplaceComponent({
|
|
3248
|
-
pluginName: input.plugin.manifest.name,
|
|
3249
|
-
codexManager: options.context.codexManager,
|
|
3250
|
-
cwd: input.cwd,
|
|
3251
|
-
env: options.context.env,
|
|
3252
|
-
runner: options.context.nativeCliRunner,
|
|
3253
|
-
marketplaceName: input.marketplaceName ?? MARKETPLACE_NAME,
|
|
3254
|
-
marketplaceRoot: input.marketplaceRoot ?? resolveAwHome(options.context.env),
|
|
3255
|
-
desired: marketplaceDesired,
|
|
3256
|
-
})]
|
|
3257
|
-
: input.platform === 'claude'
|
|
3258
|
-
? [createClaudeMarketplaceComponent({
|
|
3259
|
-
pluginName: input.plugin.manifest.name,
|
|
3260
|
-
scope: input.scope,
|
|
3261
|
-
cwd: input.cwd,
|
|
3262
|
-
env: options.context.env,
|
|
3263
|
-
runner: options.context.nativeCliRunner,
|
|
3264
|
-
marketplaceName: input.marketplaceName ?? MARKETPLACE_NAME,
|
|
3265
|
-
marketplaceRoot: input.marketplaceRoot ?? resolveAwHome(options.context.env),
|
|
3266
|
-
desired: marketplaceDesired,
|
|
3267
|
-
})]
|
|
3268
|
-
: [];
|
|
3269
|
-
if (nativeDesired)
|
|
3270
|
-
desiredComponents.push(...nativePlugin, ...marketplace);
|
|
3271
|
-
const activationCleanup = input.platform === 'codex'
|
|
3272
|
-
&& nativeRequired
|
|
3273
|
-
&& (input.command === 'cleanup' || input.command === 'uninstall')
|
|
3274
|
-
? (input.scope === 'project'
|
|
3275
|
-
? [
|
|
3276
|
-
createCodexActivationComponent({
|
|
3277
|
-
identity: ownerIdentity(input.plugin.manifest.name, internalArtifactKey('activation', 'project'), 'codex', input.scope),
|
|
3278
|
-
configPath: resolveCodexPaths(input.cwd, 'project', options.context.env).configTomlPath,
|
|
3279
|
-
codexPluginId: `${input.plugin.manifest.name}@${input.marketplaceName ?? MARKETPLACE_NAME}`,
|
|
3280
|
-
desired: true,
|
|
3281
|
-
}),
|
|
3282
|
-
]
|
|
3283
|
-
: [createCodexActivationComponent({
|
|
3284
|
-
identity: ownerIdentity(input.plugin.manifest.name, internalArtifactKey('activation', 'user'), 'codex', input.scope),
|
|
3285
|
-
configPath: resolveCodexPaths(input.cwd, 'user', options.context.env).configTomlPath,
|
|
3286
|
-
codexPluginId: `${input.plugin.manifest.name}@${input.marketplaceName ?? MARKETPLACE_NAME}`,
|
|
3287
|
-
desired: true,
|
|
3288
|
-
})])
|
|
3289
|
-
: [];
|
|
3290
|
-
const explicitActivationCleanup = input.platform === 'codex'
|
|
3291
|
-
? (input.codexActivationCleanup ?? []).map((activation) => createCodexActivationCleanupComponent({
|
|
3292
|
-
identity: ownerIdentity(input.plugin.manifest.name, internalArtifactKey('activation', activation.scope), 'codex', input.scope),
|
|
3293
|
-
configPath: resolveCodexPaths(input.cwd, activation.scope, options.context.env).configTomlPath,
|
|
3294
|
-
codexPluginId: activation.codexPluginId,
|
|
3295
|
-
disposition: activation.disposition,
|
|
3296
|
-
}))
|
|
3297
|
-
: [];
|
|
3298
|
-
const allComponents = dedupeComponents([
|
|
3299
|
-
...desiredComponents,
|
|
3300
|
-
...optionalComponents,
|
|
3301
|
-
...(input.platform === 'codex' ? sharedComponents : []),
|
|
3302
|
-
...scannedText,
|
|
3303
|
-
...scannedSkills,
|
|
3304
|
-
...currentRemovalComponents,
|
|
3305
|
-
...historicalComponents,
|
|
3306
|
-
...(input.platform === 'claude' ? sharedComponents : []),
|
|
3307
|
-
...nativePlugin,
|
|
3308
|
-
...marketplace,
|
|
3309
|
-
...activationCleanup,
|
|
3310
|
-
...explicitActivationCleanup,
|
|
3311
|
-
]);
|
|
3312
|
-
bindNamespacedOwnerIdentity(allComponents, input);
|
|
3313
|
-
const desiredKeys = new Set(desiredComponents.map(componentIdentityKey));
|
|
3314
|
-
const target = {
|
|
3315
|
-
plugin: input.plugin,
|
|
3316
|
-
identity: {
|
|
3317
|
-
...(input.sourceId ? {
|
|
3318
|
-
sourceId: input.sourceId,
|
|
3319
|
-
sourceIdentity: input.sourceIdentity,
|
|
3320
|
-
pluginId: input.pluginId,
|
|
3321
|
-
marketplaceName: input.marketplaceName,
|
|
3322
|
-
marketplaceRoot: input.marketplaceRoot,
|
|
3323
|
-
} : {}),
|
|
3324
|
-
pluginName: input.plugin.manifest.name,
|
|
3325
|
-
pluginVersion: input.plugin.manifest.version,
|
|
3326
|
-
platform: input.platform,
|
|
3327
|
-
scope: input.scope,
|
|
3328
|
-
cwd: input.cwd,
|
|
3329
|
-
},
|
|
3330
|
-
ownedComponents: allComponents,
|
|
3331
|
-
desiredOwnedComponents: allComponents.filter((component) => desiredKeys.has(componentIdentityKey(component))),
|
|
3332
|
-
optionalOwnedComponents: allComponents.filter((component) => optionalComponentKeys.has(componentIdentityKey(component))),
|
|
3333
|
-
requiresNative: nativeDesired,
|
|
3334
|
-
writeNativeRequired: materializeNativeRequired,
|
|
3335
|
-
artifacts: writes.map((write) => write.artifact),
|
|
3336
|
-
lifecycleSource: input.plugin,
|
|
3337
|
-
...(input.expectedLifecycleMetadataIntegrityDigest
|
|
3338
|
-
? {
|
|
3339
|
-
historicalLifecycleMetadataIntegrityDigest: input.expectedLifecycleMetadataIntegrityDigest,
|
|
3340
|
-
}
|
|
3341
|
-
: {}),
|
|
3342
|
-
};
|
|
3343
|
-
plans.set(target, {
|
|
3344
|
-
catalog: input.catalog,
|
|
3345
|
-
event,
|
|
3346
|
-
writes,
|
|
3347
|
-
});
|
|
3348
|
-
planTargets.get(plans).push(target);
|
|
1710
|
+
const target = await platformSession.buildTarget({ ...input, commandRecord: commands?.record });
|
|
1711
|
+
if (commands) {
|
|
1712
|
+
const operationActions = commands.actions;
|
|
1713
|
+
const preApply = input.plugin.manifest.scripts?.preApply;
|
|
1714
|
+
if (preApply && !removed && !isNativeActivationOnlyTarget(options.context, target.identity))
|
|
1715
|
+
operationActions.push({ kind: 'runPreApply',
|
|
1716
|
+
pluginId: input.pluginId ?? pluginActionId(input.plugin), platform: input.platform, scope: input.scope,
|
|
1717
|
+
script: preApply.path, scriptDigest: `sha256:${crypto.createHash('sha256')
|
|
1718
|
+
.update(await fs.readFile(path.resolve(input.plugin.rootDir, preApply.path.replace(/^\.\//u, '')))).digest('hex')}` });
|
|
1719
|
+
target.operationActions = operationActions;
|
|
1720
|
+
}
|
|
1721
|
+
targets.push(target);
|
|
3349
1722
|
return target;
|
|
3350
1723
|
},
|
|
3351
1724
|
};
|
|
@@ -3372,11 +1745,12 @@ export async function inspectRebuildTarget(options) {
|
|
|
3372
1745
|
cwd: options.cwd,
|
|
3373
1746
|
command: 'install',
|
|
3374
1747
|
catalog: options.catalog,
|
|
3375
|
-
includeHistoricalLifecycleArtifacts: false,
|
|
3376
1748
|
readOnlyInspectionPlan: true,
|
|
1749
|
+
readOnlyShallowInspectionPlan: options.shallow,
|
|
3377
1750
|
});
|
|
3378
1751
|
const inspection = await inspectOwnedComponents({
|
|
3379
1752
|
components: target.ownedComponents,
|
|
1753
|
+
executor: integration.driver.ownership,
|
|
3380
1754
|
nativeProbe: options.nativeProbe
|
|
3381
1755
|
?? integration.driver.probeNativeHealth
|
|
3382
1756
|
?? integration.driver.probeNative,
|
|
@@ -3385,24 +1759,22 @@ export async function inspectRebuildTarget(options) {
|
|
|
3385
1759
|
if (!target.requiresNative)
|
|
3386
1760
|
return { target, inspection };
|
|
3387
1761
|
if (target.identity.platform === 'codex') {
|
|
3388
|
-
const
|
|
3389
|
-
|
|
1762
|
+
const nativeInspection = inspection.components.find((component) => component.component.kind === 'native-plugin');
|
|
1763
|
+
if (nativeInspection?.state !== 'present')
|
|
1764
|
+
return { target, inspection };
|
|
1765
|
+
const registration = await inspectCodexPluginRegistrationLive({
|
|
1766
|
+
pluginId: `${target.identity.pluginName}@${target.identity.marketplaceName ?? MARKETPLACE_NAME}`,
|
|
3390
1767
|
cwd: target.identity.cwd,
|
|
3391
1768
|
env: options.context.env,
|
|
3392
|
-
|
|
3393
|
-
|
|
1769
|
+
nativeCliRunner: options.context.nativeCliRunner,
|
|
1770
|
+
manager: options.context.codexManager,
|
|
1771
|
+
scope: target.identity.scope,
|
|
1772
|
+
observationSession: options.context.codexObservationSession,
|
|
3394
1773
|
});
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
return installed.length === 1
|
|
3400
|
-
? { target, inspection, installedVersion: installed[0] }
|
|
3401
|
-
: { target, inspection };
|
|
3402
|
-
}
|
|
3403
|
-
const cached = [...new Set(residue.cacheVersions)];
|
|
3404
|
-
return cached.length === 1
|
|
3405
|
-
? { target, inspection, installedVersion: cached[0] }
|
|
1774
|
+
return registration.observation.state === 'observed'
|
|
1775
|
+
&& registration.observation.value === 'installed'
|
|
1776
|
+
&& registration.observation.entry.version !== undefined
|
|
1777
|
+
? { target, inspection, installedVersion: registration.observation.entry.version }
|
|
3406
1778
|
: { target, inspection };
|
|
3407
1779
|
}
|
|
3408
1780
|
const native = await readClaudeNativeState({
|
|
@@ -3538,13 +1910,46 @@ export async function discoverRebuildTargetNames(options) {
|
|
|
3538
1910
|
}
|
|
3539
1911
|
}
|
|
3540
1912
|
else {
|
|
3541
|
-
|
|
3542
|
-
|
|
1913
|
+
const marketplaceName = options.marketplaceName ?? MARKETPLACE_NAME;
|
|
1914
|
+
const marketplaceRoot = options.marketplaceRoot ?? resolveAwHome(options.env);
|
|
1915
|
+
const marketplace = config.snapshot.marketplaces[marketplaceName];
|
|
1916
|
+
const canonicalMarketplace = isCanonicalCodexMarketplaceRegistration(marketplace, marketplaceRoot);
|
|
1917
|
+
const suffix = `@${marketplaceName}`;
|
|
1918
|
+
const configuredPluginIds = Object.keys(config.snapshot.plugins)
|
|
1919
|
+
.filter((pluginId) => pluginId.endsWith(suffix));
|
|
1920
|
+
if (configuredPluginIds.length > 0 && !canonicalMarketplace) {
|
|
1921
|
+
throw new Error(`externalOwnershipPresent: Codex marketplace ${marketplaceName} has a foreign public config source.`);
|
|
1922
|
+
}
|
|
1923
|
+
for (const pluginId of canonicalMarketplace ? configuredPluginIds : []) {
|
|
1924
|
+
const name = pluginId.slice(0, -suffix.length);
|
|
1925
|
+
if (/^[a-z0-9]+(?:-[a-z0-9]+)*$/u.test(name))
|
|
1926
|
+
names.add(name);
|
|
1927
|
+
}
|
|
1928
|
+
const session = await createCodexNativeObservationSession({
|
|
1929
|
+
exactCwd: options.cwd,
|
|
3543
1930
|
env: options.env,
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
1931
|
+
runner: options.nativeCliRunner,
|
|
1932
|
+
});
|
|
1933
|
+
try {
|
|
1934
|
+
const snapshot = await session.snapshot(marketplaceName, 'user');
|
|
1935
|
+
if (!snapshot.neutral) {
|
|
1936
|
+
if (options.nativeFailureMode !== 'ignore') {
|
|
1937
|
+
throw new Error('codexNativeObservationFailed: cannot discover official Codex plugins.');
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
else {
|
|
1941
|
+
for (const pluginId of snapshot.neutral.keys()) {
|
|
1942
|
+
if (!pluginId.endsWith(suffix))
|
|
1943
|
+
continue;
|
|
1944
|
+
const name = pluginId.slice(0, -suffix.length);
|
|
1945
|
+
if (/^[a-z0-9]+(?:-[a-z0-9]+)*$/u.test(name))
|
|
1946
|
+
names.add(name);
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
finally {
|
|
1951
|
+
await session.dispose();
|
|
1952
|
+
}
|
|
3548
1953
|
}
|
|
3549
1954
|
}
|
|
3550
1955
|
else {
|