@kbediako/codex-orchestrator 0.1.38 → 0.2.0
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 +70 -301
- package/bin/codex-orchestrator.js +161 -0
- package/codex.orchestrator.json +149 -13
- package/dist/bin/codex-orchestrator.js +795 -1154
- 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 +183 -11
- package/dist/orchestrator/src/cli/coStatusAttachCliShell.js +402 -0
- package/dist/orchestrator/src/cli/coStatusCliShell.js +429 -0
- package/dist/orchestrator/src/cli/coStatusOperatorAutopilotCliShell.js +120 -0
- package/dist/orchestrator/src/cli/codexCliShell.js +72 -0
- package/dist/orchestrator/src/cli/codexDefaultsSetup.js +49 -11
- 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 +608 -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 +992 -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 +1899 -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 +1838 -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 +542 -122
- 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 +1 -0
- 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 +1772 -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 +5738 -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 +667 -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 +83 -1
- 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/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 +365 -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/public/downstream-setup.md +106 -0
- package/docs/public/provider-onboarding.md +173 -0
- package/package.json +20 -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 +359 -0
- package/schemas/manifest.json +394 -0
- package/skills/collab-subagents-first/SKILL.md +1 -1
- package/skills/delegation-usage/DELEGATION_GUIDE.md +24 -11
- package/skills/delegation-usage/SKILL.md +19 -13
- 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 +12 -7
- package/templates/codex/mcp-client.json +5 -1
- package/docs/README.md +0 -310
- package/docs/assets/setup.gif +0 -0
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
import { slugify } from '../utils/strings.js';
|
|
2
|
+
import { isoTimestamp } from '../utils/time.js';
|
|
3
|
+
import { deriveProviderIntakeClaimFreshness } from './providerIssueObservability.js';
|
|
4
|
+
import { normalizeProviderWorkerHostName } from './providerWorkerHosts.js';
|
|
5
|
+
const PROVIDER_INTAKE_CLAIM_LIMIT = 128;
|
|
6
|
+
export function normalizeProviderIntakeState(input) {
|
|
7
|
+
const state = input ?? {
|
|
8
|
+
schema_version: 1,
|
|
9
|
+
updated_at: new Date(0).toISOString(),
|
|
10
|
+
rehydrated_at: null,
|
|
11
|
+
latest_provider_key: null,
|
|
12
|
+
latest_reason: null,
|
|
13
|
+
polling: null,
|
|
14
|
+
claims: []
|
|
15
|
+
};
|
|
16
|
+
return {
|
|
17
|
+
schema_version: 1,
|
|
18
|
+
updated_at: typeof state.updated_at === 'string' && state.updated_at.trim().length > 0
|
|
19
|
+
? state.updated_at
|
|
20
|
+
: new Date(0).toISOString(),
|
|
21
|
+
rehydrated_at: typeof state.rehydrated_at === 'string' ? state.rehydrated_at : null,
|
|
22
|
+
latest_provider_key: typeof state.latest_provider_key === 'string' ? state.latest_provider_key : null,
|
|
23
|
+
latest_reason: typeof state.latest_reason === 'string' ? state.latest_reason : null,
|
|
24
|
+
polling: isRecordLike(state.polling) ? { ...state.polling } : null,
|
|
25
|
+
claims: Array.isArray(state.claims)
|
|
26
|
+
? state.claims
|
|
27
|
+
.map(normalizeProviderIntakeClaim)
|
|
28
|
+
.filter((claim) => claim !== null)
|
|
29
|
+
.slice(-PROVIDER_INTAKE_CLAIM_LIMIT)
|
|
30
|
+
: []
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export function buildProviderIssueKey(provider, issueId) {
|
|
34
|
+
return `${provider}:${issueId}`;
|
|
35
|
+
}
|
|
36
|
+
export function buildProviderFallbackTaskId(trackedIssue) {
|
|
37
|
+
const slug = slugify(trackedIssue.id, 'issue').toLowerCase();
|
|
38
|
+
return `linear-${slug}`;
|
|
39
|
+
}
|
|
40
|
+
export function readProviderIntakeClaim(state, providerKey) {
|
|
41
|
+
return state.claims.find((claim) => claim.provider_key === providerKey) ?? null;
|
|
42
|
+
}
|
|
43
|
+
export function upsertProviderIntakeClaim(state, input) {
|
|
44
|
+
const now = input.updated_at ?? isoTimestamp();
|
|
45
|
+
const existingIndex = state.claims.findIndex((claim) => claim.provider_key === input.provider_key);
|
|
46
|
+
const existing = existingIndex >= 0 ? state.claims[existingIndex] : null;
|
|
47
|
+
const nextRunId = input.run_id ?? null;
|
|
48
|
+
const nextRunManifestPath = input.run_manifest_path ?? null;
|
|
49
|
+
const runIdentityChanged = hasProviderRunIdentityChanged(existing, {
|
|
50
|
+
task_id: input.task_id,
|
|
51
|
+
run_id: nextRunId,
|
|
52
|
+
run_manifest_path: nextRunManifestPath
|
|
53
|
+
});
|
|
54
|
+
const existingLaunchStartedAt = existing?.launch_started_at ??
|
|
55
|
+
(existing?.launch_source === 'control-host' &&
|
|
56
|
+
(existing.state === 'starting' ||
|
|
57
|
+
existing.state === 'resuming')
|
|
58
|
+
? existing.updated_at
|
|
59
|
+
: null);
|
|
60
|
+
const nextLaunchStartedAt = input.launch_started_at === undefined
|
|
61
|
+
? runIdentityChanged
|
|
62
|
+
? null
|
|
63
|
+
: existingLaunchStartedAt ??
|
|
64
|
+
(input.launch_source === 'control-host' &&
|
|
65
|
+
(input.state === 'starting' ||
|
|
66
|
+
input.state === 'resuming' ||
|
|
67
|
+
input.state === 'handoff_failed')
|
|
68
|
+
? now
|
|
69
|
+
: null)
|
|
70
|
+
: input.launch_started_at;
|
|
71
|
+
const retryStateDefaults = input.state === 'starting' || input.state === 'resuming' || input.state === 'running'
|
|
72
|
+
? {
|
|
73
|
+
retryQueued: false,
|
|
74
|
+
retryDueAt: null,
|
|
75
|
+
retryError: existing?.retry_error ?? null
|
|
76
|
+
}
|
|
77
|
+
: existing?.retry_attempt !== null && existing?.retry_attempt !== undefined
|
|
78
|
+
? input.state === 'resumable' || input.state === 'handoff_failed'
|
|
79
|
+
? {
|
|
80
|
+
retryQueued: existing?.retry_queued ?? null,
|
|
81
|
+
retryDueAt: existing?.retry_due_at ?? null,
|
|
82
|
+
retryError: existing?.retry_error ?? null
|
|
83
|
+
}
|
|
84
|
+
: {
|
|
85
|
+
retryQueued: false,
|
|
86
|
+
retryDueAt: null,
|
|
87
|
+
retryError: null
|
|
88
|
+
}
|
|
89
|
+
: {
|
|
90
|
+
retryQueued: existing?.retry_queued ?? null,
|
|
91
|
+
retryDueAt: existing?.retry_due_at ?? null,
|
|
92
|
+
retryError: existing?.retry_error ?? null
|
|
93
|
+
};
|
|
94
|
+
const next = {
|
|
95
|
+
provider: 'linear',
|
|
96
|
+
provider_key: input.provider_key,
|
|
97
|
+
issue_id: input.issue_id,
|
|
98
|
+
issue_identifier: input.issue_identifier,
|
|
99
|
+
issue_title: input.issue_title,
|
|
100
|
+
issue_state: input.issue_state ?? null,
|
|
101
|
+
issue_state_type: input.issue_state_type ?? null,
|
|
102
|
+
issue_updated_at: input.issue_updated_at ?? null,
|
|
103
|
+
issue_archived_at: input.issue_archived_at === undefined
|
|
104
|
+
? existing?.issue_archived_at ?? null
|
|
105
|
+
: input.issue_archived_at ?? null,
|
|
106
|
+
issue_trashed: input.issue_trashed === undefined
|
|
107
|
+
? existing?.issue_trashed ?? null
|
|
108
|
+
: normalizeOptionalBoolean(input.issue_trashed),
|
|
109
|
+
issue_viewer_id: input.issue_viewer_id === undefined
|
|
110
|
+
? existing?.issue_viewer_id ?? null
|
|
111
|
+
: input.issue_viewer_id ?? null,
|
|
112
|
+
issue_viewer_auth_fingerprint: input.issue_viewer_auth_fingerprint === undefined
|
|
113
|
+
? existing?.issue_viewer_auth_fingerprint ?? null
|
|
114
|
+
: input.issue_viewer_auth_fingerprint ?? null,
|
|
115
|
+
issue_assignee_id: input.issue_assignee_id ?? null,
|
|
116
|
+
issue_assignee_name: input.issue_assignee_name ?? null,
|
|
117
|
+
issue_blocked_by: input.issue_blocked_by === undefined
|
|
118
|
+
? normalizeProviderIssueBlockedBy(existing?.issue_blocked_by)
|
|
119
|
+
: normalizeProviderIssueBlockedBy(input.issue_blocked_by),
|
|
120
|
+
task_id: input.task_id,
|
|
121
|
+
mapping_source: input.mapping_source,
|
|
122
|
+
state: input.state,
|
|
123
|
+
reason: input.reason ?? null,
|
|
124
|
+
accepted_at: input.accepted_at ?? existing?.accepted_at ?? now,
|
|
125
|
+
updated_at: now,
|
|
126
|
+
last_delivery_id: input.last_delivery_id ?? null,
|
|
127
|
+
last_event: input.last_event ?? null,
|
|
128
|
+
last_action: input.last_action ?? null,
|
|
129
|
+
last_webhook_timestamp: input.last_webhook_timestamp ?? null,
|
|
130
|
+
run_id: nextRunId,
|
|
131
|
+
run_manifest_path: nextRunManifestPath,
|
|
132
|
+
worker_host: input.worker_host === undefined
|
|
133
|
+
? runIdentityChanged
|
|
134
|
+
? null
|
|
135
|
+
: existing?.worker_host ?? null
|
|
136
|
+
: normalizeProviderWorkerHostName(input.worker_host),
|
|
137
|
+
launch_source: input.launch_source === undefined
|
|
138
|
+
? runIdentityChanged
|
|
139
|
+
? null
|
|
140
|
+
: existing?.launch_source ?? null
|
|
141
|
+
: input.launch_source,
|
|
142
|
+
launch_token: input.launch_token === undefined
|
|
143
|
+
? runIdentityChanged
|
|
144
|
+
? null
|
|
145
|
+
: existing?.launch_token ?? null
|
|
146
|
+
: input.launch_token,
|
|
147
|
+
launch_started_at: nextLaunchStartedAt,
|
|
148
|
+
retry_queued: input.retry_queued === undefined
|
|
149
|
+
? retryStateDefaults.retryQueued
|
|
150
|
+
: normalizeRetryQueued(input.retry_queued),
|
|
151
|
+
retry_attempt: input.retry_attempt === undefined
|
|
152
|
+
? existing?.retry_attempt ?? null
|
|
153
|
+
: normalizeRetryAttempt(input.retry_attempt),
|
|
154
|
+
retry_due_at: input.retry_due_at === undefined
|
|
155
|
+
? retryStateDefaults.retryDueAt
|
|
156
|
+
: normalizeRetryTimestamp(input.retry_due_at),
|
|
157
|
+
retry_error: input.retry_error === undefined
|
|
158
|
+
? retryStateDefaults.retryError
|
|
159
|
+
: normalizeRetryError(input.retry_error),
|
|
160
|
+
review_promotion: input.review_promotion === undefined
|
|
161
|
+
? cloneProviderReviewHandoffPromotionRecord(existing?.review_promotion)
|
|
162
|
+
: cloneProviderReviewHandoffPromotionRecord(input.review_promotion),
|
|
163
|
+
merge_closeout: input.merge_closeout === undefined
|
|
164
|
+
? cloneProviderMergeCloseoutRecord(existing?.merge_closeout)
|
|
165
|
+
: cloneProviderMergeCloseoutRecord(input.merge_closeout)
|
|
166
|
+
};
|
|
167
|
+
if (existingIndex >= 0) {
|
|
168
|
+
state.claims.splice(existingIndex, 1, next);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
state.claims.push(next);
|
|
172
|
+
}
|
|
173
|
+
state.updated_at = now;
|
|
174
|
+
state.latest_provider_key = next.provider_key;
|
|
175
|
+
state.latest_reason = next.reason;
|
|
176
|
+
state.claims = state.claims.slice(-PROVIDER_INTAKE_CLAIM_LIMIT);
|
|
177
|
+
return next;
|
|
178
|
+
}
|
|
179
|
+
function hasProviderRunIdentityChanged(existing, next) {
|
|
180
|
+
if (!existing) {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
if (existing.task_id !== next.task_id) {
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
const existingRunId = existing.run_id ?? null;
|
|
187
|
+
const nextRunId = next.run_id ?? null;
|
|
188
|
+
if (existingRunId || nextRunId) {
|
|
189
|
+
if (!existingRunId && nextRunId) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
return existingRunId !== nextRunId;
|
|
193
|
+
}
|
|
194
|
+
return (existing.run_manifest_path ?? null) !== (next.run_manifest_path ?? null);
|
|
195
|
+
}
|
|
196
|
+
export function markProviderIntakeRehydrated(state, at = isoTimestamp()) {
|
|
197
|
+
state.rehydrated_at = at;
|
|
198
|
+
state.updated_at = at;
|
|
199
|
+
}
|
|
200
|
+
export function selectProviderIntakeClaim(state) {
|
|
201
|
+
if (!state || state.claims.length === 0) {
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
const claims = [...state.claims].sort(compareProviderClaims);
|
|
205
|
+
const activeClaims = claims.filter(isActiveProviderIntakeClaim);
|
|
206
|
+
return activeClaims[0] ?? claims[0] ?? null;
|
|
207
|
+
}
|
|
208
|
+
export function buildProviderIntakeSummary(state) {
|
|
209
|
+
const normalizedState = normalizeProviderIntakeState(state);
|
|
210
|
+
const claims = [...normalizedState.claims].sort(compareProviderClaims);
|
|
211
|
+
const activeClaims = claims.filter(isActiveProviderIntakeClaim);
|
|
212
|
+
const runningClaims = claims.filter((candidate) => candidate.state === 'running');
|
|
213
|
+
const claim = selectProviderIntakeClaim(normalizedState);
|
|
214
|
+
if (!claim) {
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
const selectedClaim = buildProviderIntakeClaimSummary({
|
|
218
|
+
claim,
|
|
219
|
+
rehydratedAt: normalizedState.rehydrated_at
|
|
220
|
+
});
|
|
221
|
+
return {
|
|
222
|
+
provider: claim.provider,
|
|
223
|
+
summary_scope: activeClaims.length > 1 ? 'selected_claim' : 'single_claim',
|
|
224
|
+
selection_strategy: activeClaims.length > 1 ? 'state_rank_updated_at' : null,
|
|
225
|
+
claim_count: claims.length,
|
|
226
|
+
active_claim_count: activeClaims.length,
|
|
227
|
+
running_claim_count: runningClaims.length,
|
|
228
|
+
active_issue_identifiers: activeClaims.map((candidate) => candidate.issue_identifier),
|
|
229
|
+
running_issue_identifiers: runningClaims.map((candidate) => candidate.issue_identifier),
|
|
230
|
+
selected_claim: selectedClaim,
|
|
231
|
+
rehydrated_at: normalizedState.rehydrated_at,
|
|
232
|
+
is_rehydrated: selectedClaim.freshness === 'rehydrated',
|
|
233
|
+
updated_at: selectedClaim.updated_at
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
function buildProviderIntakeClaimSummary(input) {
|
|
237
|
+
const freshness = deriveProviderIntakeClaimFreshness({
|
|
238
|
+
claim: input.claim,
|
|
239
|
+
rehydrated_at: input.rehydratedAt
|
|
240
|
+
});
|
|
241
|
+
return {
|
|
242
|
+
provider: input.claim.provider,
|
|
243
|
+
issue_id: input.claim.issue_id,
|
|
244
|
+
issue_identifier: input.claim.issue_identifier,
|
|
245
|
+
issue_title: input.claim.issue_title,
|
|
246
|
+
issue_state: input.claim.issue_state,
|
|
247
|
+
issue_state_type: input.claim.issue_state_type,
|
|
248
|
+
issue_updated_at: input.claim.issue_updated_at,
|
|
249
|
+
issue_archived_at: input.claim.issue_archived_at ?? null,
|
|
250
|
+
issue_trashed: input.claim.issue_trashed ?? null,
|
|
251
|
+
issue_viewer_id: input.claim.issue_viewer_id ?? null,
|
|
252
|
+
issue_assignee_id: input.claim.issue_assignee_id ?? null,
|
|
253
|
+
issue_assignee_name: input.claim.issue_assignee_name ?? null,
|
|
254
|
+
task_id: input.claim.task_id,
|
|
255
|
+
mapping_source: input.claim.mapping_source,
|
|
256
|
+
state: deriveProviderIntakeSummaryState(input.claim),
|
|
257
|
+
reason: input.claim.reason,
|
|
258
|
+
run_id: input.claim.run_id,
|
|
259
|
+
worker_host: input.claim.worker_host ?? null,
|
|
260
|
+
freshness,
|
|
261
|
+
retry: buildProviderIntakeRetrySummary(input.claim),
|
|
262
|
+
updated_at: input.claim.updated_at
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
export function hasQueuedProviderIntakeRetry(claim) {
|
|
266
|
+
return claim?.retry_queued === true;
|
|
267
|
+
}
|
|
268
|
+
function buildProviderIntakeRetrySummary(claim) {
|
|
269
|
+
if (!claim) {
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
const active = claim.retry_queued === true;
|
|
273
|
+
const attempt = claim.retry_attempt ?? null;
|
|
274
|
+
const dueAt = claim.retry_due_at ?? null;
|
|
275
|
+
const error = claim.retry_error ?? null;
|
|
276
|
+
if (!active && attempt === null && dueAt === null && error === null) {
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
return {
|
|
280
|
+
active,
|
|
281
|
+
attempt,
|
|
282
|
+
due_at: dueAt,
|
|
283
|
+
error
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
function normalizeProviderIntakeClaim(input) {
|
|
287
|
+
if (!input || input.provider !== 'linear') {
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
if (!input.provider_key ||
|
|
291
|
+
!input.issue_id ||
|
|
292
|
+
!input.issue_identifier ||
|
|
293
|
+
!input.issue_title ||
|
|
294
|
+
!input.task_id) {
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
const state = normalizeClaimState(input.state);
|
|
298
|
+
const updatedAt = typeof input.updated_at === 'string' && input.updated_at.trim().length > 0
|
|
299
|
+
? input.updated_at
|
|
300
|
+
: new Date(0).toISOString();
|
|
301
|
+
const launchSource = input.launch_source === 'control-host' ? 'control-host' : null;
|
|
302
|
+
const launchStartedAt = typeof input.launch_started_at === 'string' && input.launch_started_at.trim().length > 0
|
|
303
|
+
? input.launch_started_at
|
|
304
|
+
: launchSource === 'control-host' &&
|
|
305
|
+
(state === 'starting' || state === 'resuming')
|
|
306
|
+
? updatedAt
|
|
307
|
+
: null;
|
|
308
|
+
return {
|
|
309
|
+
provider: 'linear',
|
|
310
|
+
provider_key: input.provider_key,
|
|
311
|
+
issue_id: input.issue_id,
|
|
312
|
+
issue_identifier: input.issue_identifier,
|
|
313
|
+
issue_title: input.issue_title,
|
|
314
|
+
issue_state: typeof input.issue_state === 'string' ? input.issue_state : null,
|
|
315
|
+
issue_state_type: typeof input.issue_state_type === 'string' ? input.issue_state_type : null,
|
|
316
|
+
issue_updated_at: typeof input.issue_updated_at === 'string' ? input.issue_updated_at : null,
|
|
317
|
+
issue_archived_at: typeof input.issue_archived_at === 'string' ? input.issue_archived_at : null,
|
|
318
|
+
issue_trashed: normalizeOptionalBoolean(input.issue_trashed),
|
|
319
|
+
issue_viewer_id: typeof input.issue_viewer_id === 'string' ? input.issue_viewer_id : null,
|
|
320
|
+
issue_viewer_auth_fingerprint: typeof input.issue_viewer_auth_fingerprint === 'string'
|
|
321
|
+
? input.issue_viewer_auth_fingerprint
|
|
322
|
+
: null,
|
|
323
|
+
issue_assignee_id: typeof input.issue_assignee_id === 'string' ? input.issue_assignee_id : null,
|
|
324
|
+
issue_assignee_name: typeof input.issue_assignee_name === 'string' ? input.issue_assignee_name : null,
|
|
325
|
+
issue_blocked_by: normalizeProviderIssueBlockedBy(input.issue_blocked_by),
|
|
326
|
+
task_id: input.task_id,
|
|
327
|
+
mapping_source: 'provider_id_fallback',
|
|
328
|
+
state,
|
|
329
|
+
reason: typeof input.reason === 'string' ? input.reason : null,
|
|
330
|
+
accepted_at: typeof input.accepted_at === 'string' && input.accepted_at.trim().length > 0
|
|
331
|
+
? input.accepted_at
|
|
332
|
+
: new Date(0).toISOString(),
|
|
333
|
+
updated_at: updatedAt,
|
|
334
|
+
last_delivery_id: typeof input.last_delivery_id === 'string' ? input.last_delivery_id : null,
|
|
335
|
+
last_event: typeof input.last_event === 'string' ? input.last_event : null,
|
|
336
|
+
last_action: typeof input.last_action === 'string' ? input.last_action : null,
|
|
337
|
+
last_webhook_timestamp: typeof input.last_webhook_timestamp === 'number' &&
|
|
338
|
+
Number.isFinite(input.last_webhook_timestamp)
|
|
339
|
+
? input.last_webhook_timestamp
|
|
340
|
+
: null,
|
|
341
|
+
run_id: typeof input.run_id === 'string' ? input.run_id : null,
|
|
342
|
+
run_manifest_path: typeof input.run_manifest_path === 'string' ? input.run_manifest_path : null,
|
|
343
|
+
worker_host: normalizeProviderWorkerHostName(input.worker_host),
|
|
344
|
+
launch_source: launchSource,
|
|
345
|
+
launch_token: typeof input.launch_token === 'string' ? input.launch_token : null,
|
|
346
|
+
launch_started_at: launchStartedAt,
|
|
347
|
+
retry_queued: normalizeRetryQueued(input.retry_queued),
|
|
348
|
+
retry_attempt: normalizeRetryAttempt(input.retry_attempt),
|
|
349
|
+
retry_due_at: normalizeRetryTimestamp(input.retry_due_at),
|
|
350
|
+
retry_error: normalizeRetryError(input.retry_error),
|
|
351
|
+
review_promotion: cloneProviderReviewHandoffPromotionRecord(input.review_promotion),
|
|
352
|
+
merge_closeout: cloneProviderMergeCloseoutRecord(input.merge_closeout)
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
export function isRecordLike(value) {
|
|
356
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
357
|
+
}
|
|
358
|
+
function normalizeRetryQueued(value) {
|
|
359
|
+
return typeof value === 'boolean' ? value : null;
|
|
360
|
+
}
|
|
361
|
+
function normalizeOptionalBoolean(value) {
|
|
362
|
+
return normalizeRetryQueued(value);
|
|
363
|
+
}
|
|
364
|
+
function normalizeProviderIssueBlockedBy(value) {
|
|
365
|
+
if (!Array.isArray(value)) {
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
368
|
+
return value.map((blocker) => ({
|
|
369
|
+
id: typeof blocker?.id === 'string' ? blocker.id : null,
|
|
370
|
+
identifier: typeof blocker?.identifier === 'string' ? blocker.identifier : null,
|
|
371
|
+
state: typeof blocker?.state === 'string' ? blocker.state : null,
|
|
372
|
+
state_type: typeof blocker?.state_type === 'string' ? blocker.state_type : null
|
|
373
|
+
}));
|
|
374
|
+
}
|
|
375
|
+
function normalizeRetryAttempt(value) {
|
|
376
|
+
return typeof value === 'number' && Number.isInteger(value) && value > 0 ? value : null;
|
|
377
|
+
}
|
|
378
|
+
function normalizeRetryTimestamp(value) {
|
|
379
|
+
return typeof value === 'string' && value.trim().length > 0 ? value : null;
|
|
380
|
+
}
|
|
381
|
+
function normalizeRetryError(value) {
|
|
382
|
+
return typeof value === 'string' && value.trim().length > 0 ? value : null;
|
|
383
|
+
}
|
|
384
|
+
function cloneProviderMergeCloseoutRecord(value) {
|
|
385
|
+
return isRecordLike(value)
|
|
386
|
+
? JSON.parse(JSON.stringify(value))
|
|
387
|
+
: null;
|
|
388
|
+
}
|
|
389
|
+
function cloneProviderReviewHandoffPromotionRecord(value) {
|
|
390
|
+
return isRecordLike(value)
|
|
391
|
+
? JSON.parse(JSON.stringify(value))
|
|
392
|
+
: null;
|
|
393
|
+
}
|
|
394
|
+
function normalizeClaimState(value) {
|
|
395
|
+
switch (value) {
|
|
396
|
+
case 'ignored':
|
|
397
|
+
case 'accepted':
|
|
398
|
+
case 'starting':
|
|
399
|
+
case 'running':
|
|
400
|
+
case 'resuming':
|
|
401
|
+
case 'resumable':
|
|
402
|
+
case 'released':
|
|
403
|
+
case 'completed':
|
|
404
|
+
case 'stale':
|
|
405
|
+
case 'duplicate':
|
|
406
|
+
case 'handoff_failed':
|
|
407
|
+
return value;
|
|
408
|
+
default:
|
|
409
|
+
return 'ignored';
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
function deriveProviderIntakeSummaryState(claim) {
|
|
413
|
+
if (claim.state === 'handoff_failed' &&
|
|
414
|
+
claim.reason === 'provider_issue_handoff_owned') {
|
|
415
|
+
return 'handoff_owned';
|
|
416
|
+
}
|
|
417
|
+
return claim.state;
|
|
418
|
+
}
|
|
419
|
+
function isActiveProviderIntakeClaim(claim) {
|
|
420
|
+
if (claim.retry_queued === true) {
|
|
421
|
+
return true;
|
|
422
|
+
}
|
|
423
|
+
switch (claim.state) {
|
|
424
|
+
case 'accepted':
|
|
425
|
+
case 'starting':
|
|
426
|
+
case 'running':
|
|
427
|
+
case 'resuming':
|
|
428
|
+
case 'resumable':
|
|
429
|
+
case 'handoff_failed':
|
|
430
|
+
return true;
|
|
431
|
+
case 'released':
|
|
432
|
+
case 'completed':
|
|
433
|
+
case 'stale':
|
|
434
|
+
case 'duplicate':
|
|
435
|
+
case 'ignored':
|
|
436
|
+
default:
|
|
437
|
+
return false;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
function compareProviderClaims(left, right) {
|
|
441
|
+
const rankDelta = rankClaimState(right.state) - rankClaimState(left.state);
|
|
442
|
+
if (rankDelta !== 0) {
|
|
443
|
+
return rankDelta;
|
|
444
|
+
}
|
|
445
|
+
return Date.parse(right.updated_at) - Date.parse(left.updated_at);
|
|
446
|
+
}
|
|
447
|
+
function rankClaimState(state) {
|
|
448
|
+
switch (state) {
|
|
449
|
+
case 'running':
|
|
450
|
+
return 9;
|
|
451
|
+
case 'resuming':
|
|
452
|
+
return 8;
|
|
453
|
+
case 'starting':
|
|
454
|
+
return 7;
|
|
455
|
+
case 'resumable':
|
|
456
|
+
return 6;
|
|
457
|
+
case 'accepted':
|
|
458
|
+
return 5;
|
|
459
|
+
case 'released':
|
|
460
|
+
return 4;
|
|
461
|
+
case 'handoff_failed':
|
|
462
|
+
return 3;
|
|
463
|
+
case 'completed':
|
|
464
|
+
return 2;
|
|
465
|
+
case 'duplicate':
|
|
466
|
+
return 1;
|
|
467
|
+
case 'stale':
|
|
468
|
+
return 0;
|
|
469
|
+
case 'ignored':
|
|
470
|
+
default:
|
|
471
|
+
return -1;
|
|
472
|
+
}
|
|
473
|
+
}
|