@kbediako/codex-orchestrator 0.1.38 → 0.2.1
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/.agents/plugins/marketplace.json +20 -0
- package/README.md +46 -317
- package/bin/codex-orchestrator.js +161 -0
- package/codex.orchestrator.json +149 -13
- package/dist/bin/codex-orchestrator.js +797 -1154
- package/dist/orchestrator/src/cli/adapters/CommandBuilder.js +50 -0
- package/dist/orchestrator/src/cli/adapters/CommandPlanner.js +22 -4
- package/dist/orchestrator/src/cli/adapters/CommandReviewer.js +3 -3
- package/dist/orchestrator/src/cli/adapters/CommandTester.js +2 -2
- package/dist/orchestrator/src/cli/adapters/cloudFailureDiagnostics.js +295 -11
- package/dist/orchestrator/src/cli/coStatusAttachCliShell.js +402 -0
- package/dist/orchestrator/src/cli/coStatusCliShell.js +451 -0
- package/dist/orchestrator/src/cli/coStatusOperatorAutopilotCliShell.js +120 -0
- package/dist/orchestrator/src/cli/codexCliShell.js +119 -0
- package/dist/orchestrator/src/cli/codexDefaultsSetup.js +265 -36
- package/dist/orchestrator/src/cli/config/delegationConfig.js +317 -5
- package/dist/orchestrator/src/cli/config/repoConfigPolicy.js +2 -3
- package/dist/orchestrator/src/cli/config/userConfig.js +28 -13
- package/dist/orchestrator/src/cli/control/authenticatedControlRouteGate.js +69 -0
- package/dist/orchestrator/src/cli/control/authenticatedRouteComposition.js +267 -0
- package/dist/orchestrator/src/cli/control/authenticatedRouteController.js +5 -0
- package/dist/orchestrator/src/cli/control/authenticatedRouteDispatcher.js +41 -0
- package/dist/orchestrator/src/cli/control/compatibilityIssuePresenter.js +1035 -0
- package/dist/orchestrator/src/cli/control/confirmationApproveController.js +62 -0
- package/dist/orchestrator/src/cli/control/confirmationCreateController.js +69 -0
- package/dist/orchestrator/src/cli/control/confirmationIssueConsumeController.js +43 -0
- package/dist/orchestrator/src/cli/control/confirmationListController.js +22 -0
- package/dist/orchestrator/src/cli/control/confirmationValidateController.js +58 -0
- package/dist/orchestrator/src/cli/control/confirmations.js +25 -3
- package/dist/orchestrator/src/cli/control/controlActionCancelConfirmation.js +65 -0
- package/dist/orchestrator/src/cli/control/controlActionController.js +77 -0
- package/dist/orchestrator/src/cli/control/controlActionControllerSequencing.js +161 -0
- package/dist/orchestrator/src/cli/control/controlActionExecution.js +142 -0
- package/dist/orchestrator/src/cli/control/controlActionFinalization.js +43 -0
- package/dist/orchestrator/src/cli/control/controlActionOutcome.js +60 -0
- package/dist/orchestrator/src/cli/control/controlActionPreflight.js +476 -0
- package/dist/orchestrator/src/cli/control/controlAuthenticatedRouteHandoff.js +57 -0
- package/dist/orchestrator/src/cli/control/controlBootstrapAssembly.js +39 -0
- package/dist/orchestrator/src/cli/control/controlBootstrapMetadataPersistence.js +16 -0
- package/dist/orchestrator/src/cli/control/controlEventTransport.js +49 -0
- package/dist/orchestrator/src/cli/control/controlExpiryLifecycle.js +102 -0
- package/dist/orchestrator/src/cli/control/controlHostOwnership.js +480 -0
- package/dist/orchestrator/src/cli/control/controlHostSupervision.js +630 -0
- package/dist/orchestrator/src/cli/control/controlOversightFacade.js +8 -0
- package/dist/orchestrator/src/cli/control/controlOversightReadContract.js +1 -0
- package/dist/orchestrator/src/cli/control/controlOversightReadService.js +16 -0
- package/dist/orchestrator/src/cli/control/controlOversightUpdateContract.js +1 -0
- package/dist/orchestrator/src/cli/control/controlPersistenceFiles.js +6 -0
- package/dist/orchestrator/src/cli/control/controlQuestionChildResolution.js +18 -0
- package/dist/orchestrator/src/cli/control/controlRequestContext.js +42 -0
- package/dist/orchestrator/src/cli/control/controlRequestController.js +9 -0
- package/dist/orchestrator/src/cli/control/controlRequestPredispatch.js +17 -0
- package/dist/orchestrator/src/cli/control/controlRequestRouteDispatch.js +44 -0
- package/dist/orchestrator/src/cli/control/controlRuntime.js +1003 -0
- package/dist/orchestrator/src/cli/control/controlServer.js +23 -1456
- package/dist/orchestrator/src/cli/control/controlServerAuditAndErrorHelpers.js +115 -0
- package/dist/orchestrator/src/cli/control/controlServerAuthenticatedRouteBranch.js +29 -0
- package/dist/orchestrator/src/cli/control/controlServerBootstrapLifecycle.js +30 -0
- package/dist/orchestrator/src/cli/control/controlServerBootstrapStartSequence.js +21 -0
- package/dist/orchestrator/src/cli/control/controlServerOwnedRuntimeLifecycle.js +67 -0
- package/dist/orchestrator/src/cli/control/controlServerPublicLifecycle.js +756 -0
- package/dist/orchestrator/src/cli/control/controlServerPublicRouteHelpers.js +86 -0
- package/dist/orchestrator/src/cli/control/controlServerReadyInstanceLifecycle.js +25 -0
- package/dist/orchestrator/src/cli/control/controlServerReadyInstanceStartup.js +18 -0
- package/dist/orchestrator/src/cli/control/controlServerRequestBodyHelpers.js +37 -0
- package/dist/orchestrator/src/cli/control/controlServerRequestShell.js +40 -0
- package/dist/orchestrator/src/cli/control/controlServerRequestShellBinding.js +17 -0
- package/dist/orchestrator/src/cli/control/controlServerSeedLoading.js +27 -0
- package/dist/orchestrator/src/cli/control/controlServerSeededRuntimeAssembly.js +186 -0
- package/dist/orchestrator/src/cli/control/controlServerStartupInputPreparation.js +31 -0
- package/dist/orchestrator/src/cli/control/controlServerStartupSequence.js +49 -0
- package/dist/orchestrator/src/cli/control/controlState.js +233 -2
- package/dist/orchestrator/src/cli/control/controlStatusDashboard.js +1904 -0
- package/dist/orchestrator/src/cli/control/controlTelegramBridgeBootstrapLifecycle.js +22 -0
- package/dist/orchestrator/src/cli/control/controlTelegramBridgeLifecycle.js +67 -0
- package/dist/orchestrator/src/cli/control/controlTelegramBridgeOversightFacadeFactory.js +8 -0
- package/dist/orchestrator/src/cli/control/controlTelegramCommandController.js +49 -0
- package/dist/orchestrator/src/cli/control/controlTelegramDispatchRead.js +40 -0
- package/dist/orchestrator/src/cli/control/controlTelegramPollingController.js +89 -0
- package/dist/orchestrator/src/cli/control/controlTelegramProjectionNotificationController.js +29 -0
- package/dist/orchestrator/src/cli/control/controlTelegramPushState.js +63 -0
- package/dist/orchestrator/src/cli/control/controlTelegramQuestionRead.js +13 -0
- package/dist/orchestrator/src/cli/control/controlTelegramReadController.js +216 -0
- package/dist/orchestrator/src/cli/control/controlTelegramUpdateHandler.js +63 -0
- package/dist/orchestrator/src/cli/control/controlWatcher.js +73 -5
- package/dist/orchestrator/src/cli/control/delegationRegisterController.js +35 -0
- package/dist/orchestrator/src/cli/control/dynamicToolBridgePolicy.js +139 -0
- package/dist/orchestrator/src/cli/control/eventsSseController.js +12 -0
- package/dist/orchestrator/src/cli/control/linearBudgetState.js +1789 -0
- package/dist/orchestrator/src/cli/control/linearDispatchSource.js +1137 -0
- package/dist/orchestrator/src/cli/control/linearGraphqlClient.js +150 -0
- package/dist/orchestrator/src/cli/control/linearRateLimit.js +102 -0
- package/dist/orchestrator/src/cli/control/linearWebhookController.js +499 -0
- package/dist/orchestrator/src/cli/control/liveLinearAdvisoryRuntime.js +70 -0
- package/dist/orchestrator/src/cli/control/observabilityApiController.js +173 -0
- package/dist/orchestrator/src/cli/control/observabilityReadModel.js +500 -0
- package/dist/orchestrator/src/cli/control/observabilitySurface.js +284 -0
- package/dist/orchestrator/src/cli/control/observabilityUpdateNotifier.js +22 -0
- package/dist/orchestrator/src/cli/control/operatorDashboardPresenter.js +252 -0
- package/dist/orchestrator/src/cli/control/providerAgentCapacity.js +70 -0
- package/dist/orchestrator/src/cli/control/providerControlHostFreshnessGauge.js +1068 -0
- package/dist/orchestrator/src/cli/control/providerIntakeState.js +473 -0
- package/dist/orchestrator/src/cli/control/providerIssueHandoff.js +6811 -0
- package/dist/orchestrator/src/cli/control/providerIssueObservability.js +1348 -0
- package/dist/orchestrator/src/cli/control/providerIssueRetryQueue.js +84 -0
- package/dist/orchestrator/src/cli/control/providerLinearRuntimeProof.js +588 -0
- package/dist/orchestrator/src/cli/control/providerLinearScreenshotProof.js +473 -0
- package/dist/orchestrator/src/cli/control/providerLinearWorkerTruth.js +383 -0
- package/dist/orchestrator/src/cli/control/providerLinearWorkflowAudit.js +254 -0
- package/dist/orchestrator/src/cli/control/providerLinearWorkflowFacade.js +5573 -0
- package/dist/orchestrator/src/cli/control/providerLinearWorkflowStates.js +115 -0
- package/dist/orchestrator/src/cli/control/providerMergeCloseout.js +1868 -0
- package/dist/orchestrator/src/cli/control/providerOperatorAutopilot.js +1580 -0
- package/dist/orchestrator/src/cli/control/providerOperatorAutopilotLifecycle.js +154 -0
- package/dist/orchestrator/src/cli/control/providerOperatorAutopilotLocalRolloutExecution.js +1006 -0
- package/dist/orchestrator/src/cli/control/providerPollingHealth.js +435 -0
- package/dist/orchestrator/src/cli/control/providerTerminalCleanup.js +516 -0
- package/dist/orchestrator/src/cli/control/providerWorkerHosts.js +191 -0
- package/dist/orchestrator/src/cli/control/providerWorkflowConfigStore.js +515 -0
- package/dist/orchestrator/src/cli/control/questionChildResolutionAdapter.js +361 -0
- package/dist/orchestrator/src/cli/control/questionQueueController.js +181 -0
- package/dist/orchestrator/src/cli/control/questionReadRetryDeduplication.js +9 -0
- package/dist/orchestrator/src/cli/control/questionReadSequence.js +10 -0
- package/dist/orchestrator/src/cli/control/securityViolationController.js +27 -0
- package/dist/orchestrator/src/cli/control/selectedRunProjection.js +1885 -0
- package/dist/orchestrator/src/cli/control/telegramOversightApiClient.js +48 -0
- package/dist/orchestrator/src/cli/control/telegramOversightBridge.js +180 -0
- package/dist/orchestrator/src/cli/control/telegramOversightBridgeProjectionDeliveryQueue.js +25 -0
- package/dist/orchestrator/src/cli/control/telegramOversightBridgeRuntimeLifecycle.js +45 -0
- package/dist/orchestrator/src/cli/control/telegramOversightBridgeStateStore.js +77 -0
- package/dist/orchestrator/src/cli/control/telegramOversightControlActionApiClient.js +45 -0
- package/dist/orchestrator/src/cli/control/trackerDispatchPilot.js +439 -0
- package/dist/orchestrator/src/cli/control/uiDataController.js +34 -0
- package/dist/orchestrator/src/cli/control/uiSessionController.js +100 -0
- package/dist/orchestrator/src/cli/controlHostCliShell.js +860 -0
- package/dist/orchestrator/src/cli/controlHostFreshnessGaugeCliShell.js +129 -0
- package/dist/orchestrator/src/cli/controlHostSupervisionCliShell.js +2127 -0
- package/dist/orchestrator/src/cli/delegationCliShell.js +62 -0
- package/dist/orchestrator/src/cli/delegationServer.js +567 -678
- package/dist/orchestrator/src/cli/delegationServerCliShell.js +52 -0
- package/dist/orchestrator/src/cli/delegationServerQuestionFlowShell.js +228 -0
- package/dist/orchestrator/src/cli/delegationServerToolDispatchShell.js +411 -0
- package/dist/orchestrator/src/cli/delegationServerTransport.js +274 -0
- package/dist/orchestrator/src/cli/delegationSetup.js +51 -171
- package/dist/orchestrator/src/cli/devtoolsCliShell.js +34 -0
- package/dist/orchestrator/src/cli/doctor.js +678 -164
- package/dist/orchestrator/src/cli/doctorCliRequestShell.js +72 -0
- package/dist/orchestrator/src/cli/doctorCliShell.js +138 -0
- package/dist/orchestrator/src/cli/doctorUsage.js +119 -15
- package/dist/orchestrator/src/cli/exec/experience.js +16 -2
- package/dist/orchestrator/src/cli/exec/summary.js +3 -0
- package/dist/orchestrator/src/cli/execCliShell.js +51 -0
- package/dist/orchestrator/src/cli/flowCliRequestShell.js +44 -0
- package/dist/orchestrator/src/cli/flowCliShell.js +239 -0
- package/dist/orchestrator/src/cli/frontendTestCliRequestShell.js +80 -0
- package/dist/orchestrator/src/cli/frontendTestCliShell.js +41 -0
- package/dist/orchestrator/src/cli/init.js +95 -1
- package/dist/orchestrator/src/cli/initCliShell.js +50 -0
- package/dist/orchestrator/src/cli/linearCliShell.js +1200 -0
- package/dist/orchestrator/src/cli/mcpEnableCliShell.js +132 -0
- package/dist/orchestrator/src/cli/metrics/metricsAggregator.js +3 -2
- package/dist/orchestrator/src/cli/metrics/metricsRecorder.js +56 -0
- package/dist/orchestrator/src/cli/orchestrator.js +66 -1376
- package/dist/orchestrator/src/cli/planCliShell.js +19 -0
- package/dist/orchestrator/src/cli/prCliShell.js +41 -0
- package/dist/orchestrator/src/cli/providerLinearChildLanePhaseContract.js +204 -0
- package/dist/orchestrator/src/cli/providerLinearChildLaneRunner.js +1835 -0
- package/dist/orchestrator/src/cli/providerLinearChildLaneShell.js +2420 -0
- package/dist/orchestrator/src/cli/providerLinearChildStreamShell.js +385 -0
- package/dist/orchestrator/src/cli/providerLinearWorkerRunner.js +6834 -0
- package/dist/orchestrator/src/cli/resumeCliShell.js +14 -0
- package/dist/orchestrator/src/cli/reviewCliLaunchShell.js +72 -0
- package/dist/orchestrator/src/cli/rlm/alignment.js +3 -3
- package/dist/orchestrator/src/cli/rlm/context.js +94 -7
- package/dist/orchestrator/src/cli/rlm/rlmCodexRuntimeShell.js +546 -0
- package/dist/orchestrator/src/cli/rlm/symbolic.js +4 -2
- package/dist/orchestrator/src/cli/rlmCliRequestShell.js +42 -0
- package/dist/orchestrator/src/cli/rlmCompletionCliShell.js +46 -0
- package/dist/orchestrator/src/cli/rlmLaunchCliShell.js +51 -0
- package/dist/orchestrator/src/cli/rlmRunner.js +83 -523
- package/dist/orchestrator/src/cli/run/blockMemory.js +500 -0
- package/dist/orchestrator/src/cli/run/manifest.js +410 -73
- package/dist/orchestrator/src/cli/run/manifestPersister.js +45 -14
- package/dist/orchestrator/src/cli/run/runMemoryController.js +216 -0
- package/dist/orchestrator/src/cli/run/source0.js +690 -0
- package/dist/orchestrator/src/cli/run/workspacePath.js +101 -0
- package/dist/orchestrator/src/cli/runtime/mode.js +2 -1
- package/dist/orchestrator/src/cli/runtime/provider.js +39 -2
- package/dist/orchestrator/src/cli/selfCheckCliShell.js +12 -0
- package/dist/orchestrator/src/cli/services/commandRunner.js +698 -18
- package/dist/orchestrator/src/cli/services/execRuntime.js +66 -1
- package/dist/orchestrator/src/cli/services/orchestratorAutoScoutEvidenceRecorder.js +71 -0
- package/dist/orchestrator/src/cli/services/orchestratorCloudBranchResolution.js +8 -0
- package/dist/orchestrator/src/cli/services/orchestratorCloudEnvironmentResolution.js +22 -0
- package/dist/orchestrator/src/cli/services/orchestratorCloudExecutionLifecycleShell.js +39 -0
- package/dist/orchestrator/src/cli/services/orchestratorCloudPromptBuilder.js +37 -0
- package/dist/orchestrator/src/cli/services/orchestratorCloudRouteFallbackContract.js +45 -0
- package/dist/orchestrator/src/cli/services/orchestratorCloudRouteShell.js +36 -0
- package/dist/orchestrator/src/cli/services/orchestratorCloudTargetExecutor.js +277 -0
- package/dist/orchestrator/src/cli/services/orchestratorControlPlaneLifecycle.js +98 -0
- package/dist/orchestrator/src/cli/services/orchestratorControlPlaneLifecycleShell.js +54 -0
- package/dist/orchestrator/src/cli/services/orchestratorExecutionLifecycle.js +112 -0
- package/dist/orchestrator/src/cli/services/orchestratorExecutionModePolicy.js +27 -0
- package/dist/orchestrator/src/cli/services/orchestratorExecutionRouteAdapterShell.js +59 -0
- package/dist/orchestrator/src/cli/services/orchestratorExecutionRouteDecisionShell.js +57 -0
- package/dist/orchestrator/src/cli/services/orchestratorExecutionRouteState.js +21 -0
- package/dist/orchestrator/src/cli/services/orchestratorExecutionRouter.js +2 -0
- package/dist/orchestrator/src/cli/services/orchestratorLocalPipelineExecutor.js +149 -0
- package/dist/orchestrator/src/cli/services/orchestratorLocalRouteShell.js +63 -0
- package/dist/orchestrator/src/cli/services/orchestratorPlanShell.js +54 -0
- package/dist/orchestrator/src/cli/services/orchestratorPlanTargetTracker.js +16 -0
- package/dist/orchestrator/src/cli/services/orchestratorResumePreparationShell.js +84 -0
- package/dist/orchestrator/src/cli/services/orchestratorResumeTokenValidation.js +15 -0
- package/dist/orchestrator/src/cli/services/orchestratorRunLifecycleCompletion.js +31 -0
- package/dist/orchestrator/src/cli/services/orchestratorRunLifecycleExecutionRegistration.js +37 -0
- package/dist/orchestrator/src/cli/services/orchestratorRunLifecycleOrchestrationShell.js +83 -0
- package/dist/orchestrator/src/cli/services/orchestratorRunLifecycleTaskManagerShell.js +37 -0
- package/dist/orchestrator/src/cli/services/orchestratorRuntimeManifestMutation.js +20 -0
- package/dist/orchestrator/src/cli/services/orchestratorStartPreparationShell.js +56 -0
- package/dist/orchestrator/src/cli/services/orchestratorStatusShell.js +70 -0
- package/dist/orchestrator/src/cli/services/pipelineResolver.js +7 -3
- package/dist/orchestrator/src/cli/services/plannerMemory.js +119 -0
- package/dist/orchestrator/src/cli/services/runPreparation.js +7 -3
- package/dist/orchestrator/src/cli/services/runSummaryWriter.js +9 -0
- package/dist/orchestrator/src/cli/setupBootstrapShell.js +114 -0
- package/dist/orchestrator/src/cli/setupCliShell.js +51 -0
- package/dist/orchestrator/src/cli/skillsCliShell.js +56 -0
- package/dist/orchestrator/src/cli/startCliRequestShell.js +53 -0
- package/dist/orchestrator/src/cli/startCliShell.js +68 -0
- package/dist/orchestrator/src/cli/statusCliShell.js +22 -0
- package/dist/orchestrator/src/cli/utils/authProvenanceFingerprint.js +27 -0
- package/dist/orchestrator/src/cli/utils/cloudPreflight.js +285 -7
- package/dist/orchestrator/src/cli/utils/codexFeatures.js +60 -0
- package/dist/orchestrator/src/cli/utils/delegationConfigParser.js +250 -0
- package/dist/orchestrator/src/cli/utils/delegationMcpHealth.js +1382 -0
- package/dist/orchestrator/src/cli/utils/devtools.js +2 -54
- package/dist/orchestrator/src/cli/utils/mcpServerEntry.js +53 -0
- package/dist/orchestrator/src/cli/utils/packageProgramResolver.js +151 -0
- package/dist/orchestrator/src/cli/utils/providerOverrideEnv.js +71 -0
- package/dist/orchestrator/src/cli/utils/trailingJsonObject.js +59 -0
- package/dist/orchestrator/src/learning/crystalizer.js +2 -2
- package/dist/orchestrator/src/manager.js +74 -4
- package/dist/orchestrator/src/persistence/ExperienceStore.js +233 -49
- package/dist/orchestrator/src/persistence/TaskStateStore.js +6 -6
- package/dist/orchestrator/src/persistence/lockFile.js +70 -4
- package/dist/orchestrator/src/persistence/sanitizeIdentifier.js +39 -0
- package/dist/orchestrator/src/sync/createCloudSyncWorker.js +3 -2
- package/dist/orchestrator/src/utils/atomicWrite.js +17 -2
- package/dist/packages/orchestrator/src/exec/unified-exec.js +99 -6
- package/dist/packages/orchestrator/src/instructions/promptPacks.js +150 -19
- package/dist/packages/sdk-node/src/orchestrator.js +137 -13
- package/dist/packages/shared/config/designConfig.js +8 -1
- package/dist/packages/shared/streams/stdio.js +1 -1
- package/dist/scripts/design/pipeline/permit.js +15 -0
- package/dist/scripts/lib/docs-catalog.js +399 -0
- package/dist/scripts/lib/docs-helpers.js +87 -5
- package/dist/scripts/lib/pr-watch-merge.js +1088 -80
- package/dist/scripts/lib/provider-run-contract.js +26 -0
- package/dist/scripts/lib/review-command-intent-classification.js +532 -0
- package/dist/scripts/lib/review-command-probe-classification.js +385 -0
- package/dist/scripts/lib/review-execution-boundary-preflight.js +279 -0
- package/dist/scripts/lib/review-execution-runtime.js +753 -0
- package/dist/scripts/lib/review-execution-state.js +1144 -0
- package/dist/scripts/lib/review-execution-telemetry.js +215 -0
- package/dist/scripts/lib/review-inspection-target-parsing.js +78 -0
- package/dist/scripts/lib/review-launch-attempt.js +601 -0
- package/dist/scripts/lib/review-meta-surface-boundary-analysis.js +300 -0
- package/dist/scripts/lib/review-meta-surface-normalization.js +746 -0
- package/dist/scripts/lib/review-non-interactive-handoff.js +61 -0
- package/dist/scripts/lib/review-prompt-context.js +376 -0
- package/dist/scripts/lib/review-scope-advisory.js +286 -0
- package/dist/scripts/lib/review-scope-paths.js +123 -0
- package/dist/scripts/lib/review-shell-command-parser.js +389 -0
- package/dist/scripts/lib/review-shell-env-interpreter.js +340 -0
- package/dist/scripts/lib/run-manifests.js +192 -36
- package/dist/scripts/lib/spark-policy-classifier.js +593 -0
- package/dist/scripts/run-review.js +507 -1777
- package/docs/README.md +43 -20
- package/docs/book/README.md +19 -0
- package/docs/book/codex-cli-0124-adoption.md +68 -0
- package/docs/book/local-hook-impact.md +73 -0
- package/docs/book/operations.md +60 -0
- package/docs/book/public-posture.md +34 -0
- package/docs/book/setup.md +91 -0
- package/docs/book/skills.md +11 -0
- package/docs/guides/codex-version-policy.md +104 -0
- package/docs/public/downstream-setup.md +113 -0
- package/docs/public/provider-onboarding.md +173 -0
- package/package.json +23 -10
- package/plugins/codex-orchestrator/.codex-plugin/plugin.json +30 -0
- package/plugins/codex-orchestrator/.mcp.json +13 -0
- package/plugins/codex-orchestrator/launcher.mjs +361 -0
- package/schemas/manifest.json +411 -0
- package/skills/README.md +26 -0
- package/skills/collab-subagents-first/SKILL.md +1 -1
- package/skills/delegation-usage/DELEGATION_GUIDE.md +30 -12
- package/skills/delegation-usage/SKILL.md +25 -14
- package/skills/land/SKILL.md +77 -0
- package/skills/linear/SKILL.md +255 -0
- package/skills/release/SKILL.md +47 -3
- package/skills/standalone-review/SKILL.md +6 -1
- package/templates/README.md +4 -2
- package/templates/codex/.codex/agents/awaiter-high.toml +2 -2
- package/templates/codex/.codex/agents/worker-complex.toml +1 -1
- package/templates/codex/.codex/config.toml +3 -4
- package/templates/codex/.codex/providers/README.md +13 -0
- package/templates/codex/.codex/providers/control.example.json +18 -0
- package/templates/codex/.codex/providers/provider.env.example +15 -0
- package/templates/codex/AGENTS.md +15 -8
- package/templates/codex/mcp-client.json +5 -1
- package/docs/assets/setup.gif +0 -0
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import { logger } from '../logger.js';
|
|
3
|
+
export const MAX_MCP_MESSAGE_BYTES = 1024 * 1024;
|
|
4
|
+
export const MAX_MCP_HEADER_BYTES = 16 * 1024;
|
|
5
|
+
const MCP_HEADER_DELIMITER = '\r\n\r\n';
|
|
6
|
+
const MCP_HEADER_DELIMITER_BYTES = MCP_HEADER_DELIMITER.length;
|
|
7
|
+
const MCP_HEADER_DELIMITER_BUFFER = Buffer.from(MCP_HEADER_DELIMITER, 'utf8');
|
|
8
|
+
const MAX_MCP_BUFFER_BYTES = (MAX_MCP_MESSAGE_BYTES + MAX_MCP_HEADER_BYTES + MCP_HEADER_DELIMITER_BYTES) * 2;
|
|
9
|
+
export async function runJsonRpcServer(handler, options = {}) {
|
|
10
|
+
let buffer = Buffer.alloc(0);
|
|
11
|
+
let expectedLength = null;
|
|
12
|
+
let processing = Promise.resolve();
|
|
13
|
+
let halted = false;
|
|
14
|
+
let inFlightRequests = 0;
|
|
15
|
+
const input = options.stdin ?? process.stdin;
|
|
16
|
+
const output = options.stdout ?? process.stdout;
|
|
17
|
+
const idleTimeoutMs = typeof options.idleTimeoutMs === 'number' && Number.isFinite(options.idleTimeoutMs)
|
|
18
|
+
? Math.max(0, Math.floor(options.idleTimeoutMs))
|
|
19
|
+
: 0;
|
|
20
|
+
let idleTimer = null;
|
|
21
|
+
const clearIdleTimer = () => {
|
|
22
|
+
if (idleTimer) {
|
|
23
|
+
clearTimeout(idleTimer);
|
|
24
|
+
idleTimer = null;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const armIdleTimer = () => {
|
|
28
|
+
clearIdleTimer();
|
|
29
|
+
if (halted || idleTimeoutMs <= 0 || inFlightRequests > 0) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
idleTimer = setTimeout(() => {
|
|
33
|
+
if (halted || inFlightRequests > 0) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
halted = true;
|
|
37
|
+
if (typeof input.pause === 'function') {
|
|
38
|
+
input.pause();
|
|
39
|
+
}
|
|
40
|
+
if (options.onIdleTimeout) {
|
|
41
|
+
options.onIdleTimeout();
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
process.exit(0);
|
|
45
|
+
}, idleTimeoutMs);
|
|
46
|
+
idleTimer.unref?.();
|
|
47
|
+
};
|
|
48
|
+
const handleProtocolViolation = (message) => {
|
|
49
|
+
if (halted) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
halted = true;
|
|
53
|
+
clearIdleTimer();
|
|
54
|
+
logger.warn(message);
|
|
55
|
+
process.exitCode = 1;
|
|
56
|
+
buffer = Buffer.alloc(0);
|
|
57
|
+
expectedLength = null;
|
|
58
|
+
if (typeof input.pause === 'function') {
|
|
59
|
+
input.pause();
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const handleInputError = (error) => {
|
|
63
|
+
if (halted) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
halted = true;
|
|
67
|
+
clearIdleTimer();
|
|
68
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
69
|
+
logger.error(`MCP input stream error: ${detail}`);
|
|
70
|
+
process.exitCode = 1;
|
|
71
|
+
buffer = Buffer.alloc(0);
|
|
72
|
+
expectedLength = null;
|
|
73
|
+
if (typeof input.pause === 'function') {
|
|
74
|
+
input.pause();
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
input.on('data', (chunk) => {
|
|
78
|
+
if (halted) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
clearIdleTimer();
|
|
82
|
+
buffer = Buffer.concat([buffer, Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)]);
|
|
83
|
+
if (buffer.length > MAX_MCP_BUFFER_BYTES) {
|
|
84
|
+
handleProtocolViolation(`Rejecting MCP buffer larger than ${MAX_MCP_BUFFER_BYTES} bytes`);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
processing = processing
|
|
88
|
+
.then(async () => {
|
|
89
|
+
await processBuffer();
|
|
90
|
+
if (!halted) {
|
|
91
|
+
armIdleTimer();
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
.catch((error) => {
|
|
95
|
+
logger.error(`Failed to process MCP buffer: ${error?.message ?? error}`);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
input.on('end', clearIdleTimer);
|
|
99
|
+
input.on('close', clearIdleTimer);
|
|
100
|
+
input.on('error', handleInputError);
|
|
101
|
+
armIdleTimer();
|
|
102
|
+
async function processBuffer() {
|
|
103
|
+
while (buffer.length > 0) {
|
|
104
|
+
if (halted) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (expectedLength !== null) {
|
|
108
|
+
if (buffer.length < expectedLength) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const body = buffer.slice(0, expectedLength);
|
|
112
|
+
buffer = buffer.slice(expectedLength);
|
|
113
|
+
expectedLength = null;
|
|
114
|
+
await handleMessage(body.toString('utf8'), 'framed');
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const headerEnd = buffer.indexOf('\r\n\r\n');
|
|
118
|
+
if (headerEnd === -1) {
|
|
119
|
+
const newlineIndex = buffer.indexOf('\n');
|
|
120
|
+
if (newlineIndex !== -1) {
|
|
121
|
+
const lineBuffer = buffer.slice(0, newlineIndex);
|
|
122
|
+
const line = lineBuffer.toString('utf8').trim();
|
|
123
|
+
buffer = buffer.slice(newlineIndex + 1);
|
|
124
|
+
if (!line) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
const normalizedLine = line.trimStart();
|
|
128
|
+
const looksLikeHeaderLine = /^[A-Za-z0-9-]+:/.test(normalizedLine);
|
|
129
|
+
const looksLikeJson = normalizedLine.startsWith('{') || normalizedLine.startsWith('[');
|
|
130
|
+
const isContentLength = normalizedLine.toLowerCase().startsWith('content-length:');
|
|
131
|
+
let restoredHeader = false;
|
|
132
|
+
if (!looksLikeJson && looksLikeHeaderLine) {
|
|
133
|
+
buffer = Buffer.concat([Buffer.from(lineBuffer), Buffer.from('\n'), buffer]);
|
|
134
|
+
restoredHeader = true;
|
|
135
|
+
}
|
|
136
|
+
else if (!isContentLength) {
|
|
137
|
+
const lineBytes = Buffer.byteLength(line, 'utf8');
|
|
138
|
+
if (lineBytes > MAX_MCP_MESSAGE_BYTES) {
|
|
139
|
+
handleProtocolViolation(`Rejecting MCP payload (${lineBytes} bytes) larger than ${MAX_MCP_MESSAGE_BYTES}`);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
await handleMessage(line, 'jsonl');
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (!restoredHeader && isContentLength) {
|
|
146
|
+
buffer = Buffer.concat([Buffer.from(lineBuffer), Buffer.from('\n'), buffer]);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
else if (buffer.length > MAX_MCP_MESSAGE_BYTES) {
|
|
150
|
+
handleProtocolViolation(`Rejecting MCP payload (${buffer.length} bytes) larger than ${MAX_MCP_MESSAGE_BYTES}`);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (buffer.length > MAX_MCP_HEADER_BYTES) {
|
|
154
|
+
const overflow = buffer.slice(MAX_MCP_HEADER_BYTES);
|
|
155
|
+
const allowedPrefix = MCP_HEADER_DELIMITER_BUFFER.subarray(0, overflow.length);
|
|
156
|
+
if (overflow.length > MCP_HEADER_DELIMITER_BYTES || !overflow.equals(allowedPrefix)) {
|
|
157
|
+
handleProtocolViolation(`Rejecting MCP header larger than ${MAX_MCP_HEADER_BYTES} bytes`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (headerEnd > MAX_MCP_HEADER_BYTES) {
|
|
163
|
+
handleProtocolViolation(`Rejecting MCP header larger than ${MAX_MCP_HEADER_BYTES} bytes`);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const header = buffer.slice(0, headerEnd).toString('utf8');
|
|
167
|
+
const parsed = parseContentLengthHeader(header);
|
|
168
|
+
if (parsed.error) {
|
|
169
|
+
handleProtocolViolation(parsed.error);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
if (parsed.length === null) {
|
|
173
|
+
const lines = header.split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
|
|
174
|
+
if (lines.length === 0) {
|
|
175
|
+
buffer = buffer.slice(headerEnd + 4);
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
const allJsonLike = lines.every((line) => line.startsWith('{') || line.startsWith('['));
|
|
179
|
+
if (allJsonLike) {
|
|
180
|
+
buffer = buffer.slice(headerEnd + 4);
|
|
181
|
+
for (const line of lines) {
|
|
182
|
+
await handleMessage(line, 'jsonl');
|
|
183
|
+
}
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
handleProtocolViolation('Missing Content-Length header in MCP message');
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
const length = parsed.length;
|
|
190
|
+
if (!Number.isFinite(length) || length < 0) {
|
|
191
|
+
handleProtocolViolation('Invalid Content-Length for MCP payload');
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (length > MAX_MCP_MESSAGE_BYTES) {
|
|
195
|
+
handleProtocolViolation(`Rejecting MCP payload (${length} bytes) larger than ${MAX_MCP_MESSAGE_BYTES}`);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
expectedLength = length;
|
|
199
|
+
buffer = buffer.slice(headerEnd + 4);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
async function handleMessage(raw, format) {
|
|
203
|
+
clearIdleTimer();
|
|
204
|
+
inFlightRequests += 1;
|
|
205
|
+
let request;
|
|
206
|
+
try {
|
|
207
|
+
request = JSON.parse(raw);
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
logger.error(`Failed to parse MCP message: ${error?.message ?? error}`);
|
|
211
|
+
inFlightRequests -= 1;
|
|
212
|
+
armIdleTimer();
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (typeof request.method !== 'string') {
|
|
216
|
+
inFlightRequests -= 1;
|
|
217
|
+
armIdleTimer();
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
const id = request.id ?? null;
|
|
221
|
+
try {
|
|
222
|
+
const result = await handler(request);
|
|
223
|
+
if (id !== null && typeof id !== 'undefined') {
|
|
224
|
+
sendResponse({ jsonrpc: '2.0', id, result }, output, format);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
if (id !== null && typeof id !== 'undefined') {
|
|
229
|
+
sendResponse({
|
|
230
|
+
jsonrpc: '2.0',
|
|
231
|
+
id,
|
|
232
|
+
error: { code: -32603, message: error?.message ?? String(error) }
|
|
233
|
+
}, output, format);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
finally {
|
|
237
|
+
inFlightRequests = Math.max(0, inFlightRequests - 1);
|
|
238
|
+
armIdleTimer();
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
export function parseContentLengthHeader(header) {
|
|
243
|
+
const lines = header.split(/\r?\n/);
|
|
244
|
+
let contentLength = null;
|
|
245
|
+
for (const line of lines) {
|
|
246
|
+
const separator = line.indexOf(':');
|
|
247
|
+
if (separator === -1) {
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
const name = line.slice(0, separator).trim().toLowerCase();
|
|
251
|
+
if (name !== 'content-length') {
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
if (contentLength !== null) {
|
|
255
|
+
return { length: null, error: 'Multiple Content-Length headers in MCP message' };
|
|
256
|
+
}
|
|
257
|
+
const value = line.slice(separator + 1).trim();
|
|
258
|
+
if (!/^\d+$/.test(value)) {
|
|
259
|
+
return { length: null, error: 'Invalid Content-Length header in MCP message' };
|
|
260
|
+
}
|
|
261
|
+
contentLength = Number(value);
|
|
262
|
+
}
|
|
263
|
+
return { length: contentLength };
|
|
264
|
+
}
|
|
265
|
+
function sendResponse(response, output = process.stdout, format = 'framed') {
|
|
266
|
+
const payload = JSON.stringify(response);
|
|
267
|
+
if (format === 'jsonl') {
|
|
268
|
+
output.write(`${payload}\n`);
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
const buffer = Buffer.from(payload, 'utf8');
|
|
272
|
+
const header = Buffer.from(`Content-Length: ${buffer.length}\r\n\r\n`, 'utf8');
|
|
273
|
+
output.write(Buffer.concat([header, buffer]));
|
|
274
|
+
}
|
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
import { spawn
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
2
|
import process from 'node:process';
|
|
3
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
4
3
|
import { join, resolve } from 'node:path';
|
|
5
4
|
import { resolveCodexCliBin } from './utils/codexCli.js';
|
|
6
5
|
import { resolveCodexHome } from './utils/codexPaths.js';
|
|
7
6
|
import { buildCommandPreview } from './utils/commandPreview.js';
|
|
7
|
+
import { readDelegationFallbackConfig } from './utils/delegationConfigParser.js';
|
|
8
|
+
import { classifyDelegationTransport, inspectDelegationMcpConfig, readPinnedRepo, resolveDelegationServerInvocation } from './utils/delegationMcpHealth.js';
|
|
8
9
|
export async function runDelegationSetup(options = {}) {
|
|
9
10
|
const env = options.env ?? process.env;
|
|
10
11
|
const repoRoot = resolve(options.repoRoot ?? process.cwd());
|
|
11
12
|
const codexBin = resolveCodexCliBin(env);
|
|
12
13
|
const codexHome = resolveCodexHome(env);
|
|
13
14
|
const configPath = join(codexHome, 'config.toml');
|
|
15
|
+
const delegateServer = resolveDelegationServerInvocation({
|
|
16
|
+
allowMissingDist: !options.apply,
|
|
17
|
+
env,
|
|
18
|
+
execPath: process.execPath
|
|
19
|
+
});
|
|
14
20
|
const plan = {
|
|
15
21
|
codexBin,
|
|
16
22
|
codexHome,
|
|
@@ -20,13 +26,13 @@ export async function runDelegationSetup(options = {}) {
|
|
|
20
26
|
'add',
|
|
21
27
|
'delegation',
|
|
22
28
|
'--',
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
delegateServer.command,
|
|
30
|
+
...delegateServer.args,
|
|
25
31
|
'--repo',
|
|
26
32
|
repoRoot
|
|
27
33
|
])
|
|
28
34
|
};
|
|
29
|
-
const probe = inspectDelegationReadiness({
|
|
35
|
+
const probe = inspectDelegationReadiness({ configPath, repoRoot, env });
|
|
30
36
|
const readiness = { configured: probe.configured, configPath };
|
|
31
37
|
if (!options.apply) {
|
|
32
38
|
return { status: 'planned', plan, readiness };
|
|
@@ -35,7 +41,7 @@ export async function runDelegationSetup(options = {}) {
|
|
|
35
41
|
return { status: 'skipped', reason: probe.reason ?? 'Delegation MCP is already configured.', plan, readiness };
|
|
36
42
|
}
|
|
37
43
|
await applyDelegationSetup({ codexBin, repoRoot, removeExisting: probe.removeExisting, envVars: probe.envVars }, env);
|
|
38
|
-
const configuredAfter = inspectDelegationReadiness({
|
|
44
|
+
const configuredAfter = inspectDelegationReadiness({ configPath, repoRoot, env }).configured;
|
|
39
45
|
return {
|
|
40
46
|
status: 'applied',
|
|
41
47
|
reason: probe.reason,
|
|
@@ -59,7 +65,8 @@ export function formatDelegationSetupSummary(result) {
|
|
|
59
65
|
}
|
|
60
66
|
function inspectDelegationReadiness(options) {
|
|
61
67
|
const requestedRepo = resolve(options.repoRoot);
|
|
62
|
-
const
|
|
68
|
+
const snapshot = inspectDelegationMcpConfig(options.env);
|
|
69
|
+
const existing = snapshot.entry;
|
|
63
70
|
if (existing) {
|
|
64
71
|
const envVars = existing.envVars;
|
|
65
72
|
const isDelegationServer = existing.args.includes('delegate-server') || existing.args.includes('delegation-server');
|
|
@@ -71,6 +78,15 @@ function inspectDelegationReadiness(options) {
|
|
|
71
78
|
reason: 'Existing delegation MCP entry does not point to codex-orchestrator delegate-server; reconfiguring.'
|
|
72
79
|
};
|
|
73
80
|
}
|
|
81
|
+
const transport = classifyDelegationTransport(existing);
|
|
82
|
+
if (transport.status !== 'safe') {
|
|
83
|
+
return {
|
|
84
|
+
configured: false,
|
|
85
|
+
removeExisting: true,
|
|
86
|
+
envVars,
|
|
87
|
+
reason: `Existing delegation MCP entry uses ${transport.kind} transport; reconfiguring to the direct dist entrypoint.`
|
|
88
|
+
};
|
|
89
|
+
}
|
|
74
90
|
if (existing.pinnedRepo) {
|
|
75
91
|
const pinnedRepo = resolve(existing.pinnedRepo);
|
|
76
92
|
if (pinnedRepo !== requestedRepo) {
|
|
@@ -99,6 +115,7 @@ function inspectDelegationReadiness(options) {
|
|
|
99
115
|
return inspectDelegationReadinessFallback(options.configPath, requestedRepo);
|
|
100
116
|
}
|
|
101
117
|
function applyDelegationSetup(plan, env) {
|
|
118
|
+
const delegateServer = resolveDelegationServerInvocation({ env, execPath: process.execPath });
|
|
102
119
|
const envFlags = [];
|
|
103
120
|
for (const [key, value] of Object.entries(plan.envVars ?? {})) {
|
|
104
121
|
envFlags.push('--env', `${key}=${value}`);
|
|
@@ -111,8 +128,8 @@ function applyDelegationSetup(plan, env) {
|
|
|
111
128
|
'delegation',
|
|
112
129
|
...envFlags,
|
|
113
130
|
'--',
|
|
114
|
-
|
|
115
|
-
|
|
131
|
+
delegateServer.command,
|
|
132
|
+
...delegateServer.args,
|
|
116
133
|
'--repo',
|
|
117
134
|
plan.repoRoot
|
|
118
135
|
], { stdio: 'inherit', env });
|
|
@@ -142,55 +159,36 @@ function applyDelegationSetup(plan, env) {
|
|
|
142
159
|
});
|
|
143
160
|
});
|
|
144
161
|
}
|
|
145
|
-
function readDelegationMcpServer(codexBin, env) {
|
|
146
|
-
const result = spawnSync(codexBin, ['mcp', 'get', 'delegation', '--json'], {
|
|
147
|
-
encoding: 'utf8',
|
|
148
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
149
|
-
timeout: 5000,
|
|
150
|
-
env
|
|
151
|
-
});
|
|
152
|
-
if (result.error || result.status !== 0) {
|
|
153
|
-
return null;
|
|
154
|
-
}
|
|
155
|
-
const stdout = String(result.stdout ?? '').trim();
|
|
156
|
-
if (!stdout) {
|
|
157
|
-
return null;
|
|
158
|
-
}
|
|
159
|
-
try {
|
|
160
|
-
const parsed = JSON.parse(stdout);
|
|
161
|
-
const transport = parsed.transport;
|
|
162
|
-
const args = Array.isArray(transport?.args)
|
|
163
|
-
? transport.args.filter((value) => typeof value === 'string')
|
|
164
|
-
: [];
|
|
165
|
-
const envVars = {};
|
|
166
|
-
const envRecord = transport?.env;
|
|
167
|
-
if (envRecord && typeof envRecord === 'object' && !Array.isArray(envRecord)) {
|
|
168
|
-
for (const [key, value] of Object.entries(envRecord)) {
|
|
169
|
-
if (typeof value === 'string') {
|
|
170
|
-
envVars[key] = value;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
const pinnedRepo = readPinnedRepo(args);
|
|
175
|
-
return { args, pinnedRepo, envVars };
|
|
176
|
-
}
|
|
177
|
-
catch {
|
|
178
|
-
return null;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
function readPinnedRepo(args) {
|
|
182
|
-
const index = args.indexOf('--repo');
|
|
183
|
-
if (index === -1) {
|
|
184
|
-
return null;
|
|
185
|
-
}
|
|
186
|
-
const candidate = args[index + 1];
|
|
187
|
-
return typeof candidate === 'string' && candidate.trim().length > 0 ? candidate.trim() : null;
|
|
188
|
-
}
|
|
189
162
|
function inspectDelegationReadinessFallback(configPath, requestedRepo) {
|
|
190
163
|
const config = readDelegationFallbackConfig(configPath);
|
|
191
164
|
if (!config) {
|
|
192
165
|
return { configured: false, removeExisting: false, envVars: {} };
|
|
193
166
|
}
|
|
167
|
+
const isDelegationServer = config.args.includes('delegate-server') || config.args.includes('delegation-server');
|
|
168
|
+
if (!isDelegationServer) {
|
|
169
|
+
return {
|
|
170
|
+
configured: false,
|
|
171
|
+
removeExisting: true,
|
|
172
|
+
envVars: config.envVars,
|
|
173
|
+
reason: 'Existing delegation MCP entry does not point to codex-orchestrator delegate-server; reconfiguring.'
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
const transport = classifyDelegationTransport({
|
|
177
|
+
source: 'fallback',
|
|
178
|
+
command: config.command,
|
|
179
|
+
args: config.args,
|
|
180
|
+
envVars: config.envVars,
|
|
181
|
+
pinnedRepo: readPinnedRepo(config.args),
|
|
182
|
+
commandLine: buildCommandPreview(config.command ?? '<missing>', config.args)
|
|
183
|
+
});
|
|
184
|
+
if (transport.status !== 'safe') {
|
|
185
|
+
return {
|
|
186
|
+
configured: false,
|
|
187
|
+
removeExisting: true,
|
|
188
|
+
envVars: config.envVars,
|
|
189
|
+
reason: `Existing delegation MCP entry uses ${transport.kind} transport; reconfiguring to the direct dist entrypoint.`
|
|
190
|
+
};
|
|
191
|
+
}
|
|
194
192
|
const pinnedRepo = readPinnedRepo(config.args);
|
|
195
193
|
if (!pinnedRepo) {
|
|
196
194
|
return {
|
|
@@ -216,121 +214,3 @@ function inspectDelegationReadinessFallback(configPath, requestedRepo) {
|
|
|
216
214
|
reason: `Delegation MCP is already configured (pinned to ${pinnedRepo}).`
|
|
217
215
|
};
|
|
218
216
|
}
|
|
219
|
-
function readDelegationFallbackConfig(configPath) {
|
|
220
|
-
if (!existsSync(configPath)) {
|
|
221
|
-
return null;
|
|
222
|
-
}
|
|
223
|
-
try {
|
|
224
|
-
const raw = readFileSync(configPath, 'utf8');
|
|
225
|
-
if (!hasMcpServerEntry(raw, 'delegation')) {
|
|
226
|
-
return null;
|
|
227
|
-
}
|
|
228
|
-
return {
|
|
229
|
-
args: readDelegationArgsFromConfig(raw),
|
|
230
|
-
envVars: readDelegationEnvVarsFromConfig(raw)
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
catch {
|
|
234
|
-
return null;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
function readDelegationArgsFromConfig(raw) {
|
|
238
|
-
const sectionMatch = raw.match(/\[mcp_servers(?:\.delegation|\."delegation"|.'delegation')\]([\s\S]*?)(?=\n\[|$)/u);
|
|
239
|
-
if (!sectionMatch) {
|
|
240
|
-
return [];
|
|
241
|
-
}
|
|
242
|
-
const section = sectionMatch[1] ?? '';
|
|
243
|
-
const argsMatch = section.match(/^\s*args\s*=\s*\[([\s\S]*?)\]/mu);
|
|
244
|
-
if (!argsMatch) {
|
|
245
|
-
return [];
|
|
246
|
-
}
|
|
247
|
-
const argsRaw = argsMatch[1] ?? '';
|
|
248
|
-
const args = [];
|
|
249
|
-
const tokenPattern = /"((?:\\"|[^"])*)"|'((?:\\'|[^'])*)'/gu;
|
|
250
|
-
let token = tokenPattern.exec(argsRaw);
|
|
251
|
-
while (token) {
|
|
252
|
-
const quoted = token[1] ?? token[2] ?? '';
|
|
253
|
-
const decoded = quoted.replace(/\\"/gu, '"').replace(/\\'/gu, '\'');
|
|
254
|
-
args.push(decoded);
|
|
255
|
-
token = tokenPattern.exec(argsRaw);
|
|
256
|
-
}
|
|
257
|
-
return args;
|
|
258
|
-
}
|
|
259
|
-
function readDelegationEnvVarsFromConfig(raw) {
|
|
260
|
-
const envVars = {};
|
|
261
|
-
const sectionMatch = raw.match(/\[mcp_servers(?:\.delegation|\."delegation"|.'delegation')\.env\]([\s\S]*?)(?=\n\[|$)/u);
|
|
262
|
-
if (!sectionMatch) {
|
|
263
|
-
return envVars;
|
|
264
|
-
}
|
|
265
|
-
const section = sectionMatch[1] ?? '';
|
|
266
|
-
const linePattern = /^\s*([A-Za-z0-9_.-]+)\s*=\s*("(?:\\"|[^"])*"|'(?:\\'|[^'])*')\s*$/gmu;
|
|
267
|
-
let match = linePattern.exec(section);
|
|
268
|
-
while (match) {
|
|
269
|
-
const key = match[1];
|
|
270
|
-
const rawValue = match[2] ?? '';
|
|
271
|
-
if (key) {
|
|
272
|
-
const unquoted = rawValue.slice(1, -1);
|
|
273
|
-
const decoded = unquoted.replace(/\\"/gu, '"').replace(/\\'/gu, '\'');
|
|
274
|
-
envVars[key] = decoded;
|
|
275
|
-
}
|
|
276
|
-
match = linePattern.exec(section);
|
|
277
|
-
}
|
|
278
|
-
return envVars;
|
|
279
|
-
}
|
|
280
|
-
function hasMcpServerEntry(raw, serverName) {
|
|
281
|
-
const lines = raw.split('\n');
|
|
282
|
-
let currentTable = null;
|
|
283
|
-
for (const line of lines) {
|
|
284
|
-
const trimmed = stripTomlComment(line).trim();
|
|
285
|
-
if (!trimmed) {
|
|
286
|
-
continue;
|
|
287
|
-
}
|
|
288
|
-
const tableMatch = trimmed.match(/^\[(.+)\]$/u);
|
|
289
|
-
if (tableMatch) {
|
|
290
|
-
currentTable = tableMatch[1]?.trim() ?? null;
|
|
291
|
-
if (currentTable === `mcp_servers.${serverName}` ||
|
|
292
|
-
currentTable === `mcp_servers."${serverName}"` ||
|
|
293
|
-
currentTable === `mcp_servers.'${serverName}'`) {
|
|
294
|
-
return true;
|
|
295
|
-
}
|
|
296
|
-
continue;
|
|
297
|
-
}
|
|
298
|
-
if (trimmed.startsWith('mcp_servers.')) {
|
|
299
|
-
if (trimmed.startsWith(`mcp_servers."${serverName}".`)) {
|
|
300
|
-
return true;
|
|
301
|
-
}
|
|
302
|
-
if (trimmed.startsWith(`mcp_servers.'${serverName}'.`)) {
|
|
303
|
-
return true;
|
|
304
|
-
}
|
|
305
|
-
if (trimmed.startsWith(`mcp_servers.${serverName}.`)) {
|
|
306
|
-
return true;
|
|
307
|
-
}
|
|
308
|
-
if (trimmed.startsWith(`mcp_servers."${serverName}"=`)) {
|
|
309
|
-
return true;
|
|
310
|
-
}
|
|
311
|
-
if (trimmed.startsWith(`mcp_servers.'${serverName}'=`)) {
|
|
312
|
-
return true;
|
|
313
|
-
}
|
|
314
|
-
if (trimmed.startsWith(`mcp_servers.${serverName}=`)) {
|
|
315
|
-
return true;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
if (currentTable === 'mcp_servers') {
|
|
319
|
-
const entryPattern = new RegExp(`^"?${escapeRegExp(serverName)}"?\\s*=`, 'u');
|
|
320
|
-
if (entryPattern.test(trimmed)) {
|
|
321
|
-
return true;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
return false;
|
|
326
|
-
}
|
|
327
|
-
function stripTomlComment(line) {
|
|
328
|
-
const index = line.indexOf('#');
|
|
329
|
-
if (index === -1) {
|
|
330
|
-
return line;
|
|
331
|
-
}
|
|
332
|
-
return line.slice(0, index);
|
|
333
|
-
}
|
|
334
|
-
function escapeRegExp(value) {
|
|
335
|
-
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
336
|
-
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/* eslint-disable patterns/prefer-logger-over-console */
|
|
2
|
+
import { formatDevtoolsSetupSummary, runDevtoolsSetup } from './devtoolsSetup.js';
|
|
3
|
+
const DEFAULT_DEPENDENCIES = {
|
|
4
|
+
runDevtoolsSetup,
|
|
5
|
+
formatDevtoolsSetupSummary,
|
|
6
|
+
log: (line) => console.log(line)
|
|
7
|
+
};
|
|
8
|
+
export async function runDevtoolsCliShell(params, overrides = {}) {
|
|
9
|
+
const dependencies = { ...DEFAULT_DEPENDENCIES, ...overrides };
|
|
10
|
+
const positionals = [...params.positionals];
|
|
11
|
+
const subcommand = positionals.shift();
|
|
12
|
+
if (!subcommand) {
|
|
13
|
+
throw new Error('devtools requires a subcommand (setup).');
|
|
14
|
+
}
|
|
15
|
+
if (subcommand !== 'setup') {
|
|
16
|
+
throw new Error(`Unknown devtools subcommand: ${subcommand}`);
|
|
17
|
+
}
|
|
18
|
+
const format = resolveOutputFormat(params.flags);
|
|
19
|
+
const apply = Boolean(params.flags['yes']);
|
|
20
|
+
if (format === 'json' && apply) {
|
|
21
|
+
throw new Error('devtools setup does not support --format json with --yes.');
|
|
22
|
+
}
|
|
23
|
+
const result = await dependencies.runDevtoolsSetup({ apply });
|
|
24
|
+
if (format === 'json') {
|
|
25
|
+
dependencies.log(JSON.stringify(result, null, 2));
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
for (const line of dependencies.formatDevtoolsSetupSummary(result)) {
|
|
29
|
+
dependencies.log(line);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function resolveOutputFormat(flags) {
|
|
33
|
+
return flags['format'] === 'json' ? 'json' : 'text';
|
|
34
|
+
}
|