@bridge_gpt/mcp-server 0.2.69 → 0.2.71
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/README.md +140 -292
- package/build/agent-launchers/claude-executor-adapter.js +27 -5
- package/build/agent-registry.js +5 -5
- package/build/agents.generated.js +15 -5
- package/build/artifact-diff.js +110 -0
- package/build/bin-entrypoint.js +36 -0
- package/build/bounded-wait.js +9 -1
- package/build/bridge-permissions.js +36 -9
- package/build/claude-review-workflow-drift.js +3 -3
- package/build/codex-bridge-profile.js +1 -1
- package/build/commands.generated.js +6 -6
- package/build/conductor/bridge-api-client.js +858 -21
- package/build/conductor/bring-up-facts.js +9 -9
- package/build/conductor/command-drift-production.js +7 -2
- package/build/conductor/doctor.js +472 -18
- package/build/conductor/epic-child-continuation.js +54 -3
- package/build/conductor/epic-implementer-cli.js +136 -34
- package/build/conductor/epic-runtime.js +2 -2
- package/build/conductor/epic-state.js +1 -1
- package/build/conductor/gate-discovery.js +524 -10
- package/build/conductor/gate-settings-review.js +451 -0
- package/build/conductor/hook-runtime-qualification.js +1 -1
- package/build/conductor/install-doctor.js +4 -2
- package/build/conductor/launch-need-probes.js +342 -0
- package/build/conductor/launch-plan.js +145 -0
- package/build/conductor/local-merge.js +241 -56
- package/build/conductor/merge-credential.js +172 -0
- package/build/conductor/merge-execution-eligibility.js +1 -1
- package/build/conductor/merged-child-check.js +95 -0
- package/build/conductor/plan-trim.js +30 -0
- package/build/conductor/pr-ci-producer.js +1 -1
- package/build/conductor/precheck-timings.js +14 -0
- package/build/conductor/preview-observations.js +10 -0
- package/build/conductor/readiness-cli.js +11 -6
- package/build/conductor/readiness-prerequisites.js +41 -0
- package/build/conductor/readiness-sections.js +348 -55
- package/build/conductor/readiness.js +99 -87
- package/build/conductor/recovery-cli.js +665 -23
- package/build/conductor/recovery-operations.js +350 -8
- package/build/conductor/repair-contract.js +47 -2
- package/build/conductor/repository-workflow-remedy.js +8 -6
- package/build/conductor/stored-merge-credential.js +76 -0
- package/build/conductor/stored-merge-token-probe.js +28 -0
- package/build/conductor/temporary-plan.js +50 -0
- package/build/conductor/wait-run-cli.js +759 -0
- package/build/conductor/worker-database-doctor-inspector.js +49 -0
- package/build/conductor-bin.js +2 -2
- package/build/conductor-claude-hook-bin.js +2 -2
- package/build/conductor-claude-hook-removed-stub-bin.js +2 -5
- package/build/conductor-removed-stub-bin.js +2 -5
- package/build/credential-store.js +356 -13
- package/build/docs.generated.js +26 -13
- package/build/doctor.js +94 -32
- package/build/drive-epic-help.js +212 -0
- package/build/drive-epic.js +1989 -379
- package/build/epic-ci-workflow-drift.js +125 -0
- package/build/epic-ci-workflow-install.js +240 -0
- package/build/epic-ci-workflow-v1.js +132 -0
- package/build/epic-ci-workflow.js +318 -0
- package/build/epic-contract-context.js +326 -0
- package/build/epic-implementer-bin.js +58 -42
- package/build/epic-implementer-claude-hook-bin.js +2 -2
- package/build/escalation-reachability.js +134 -0
- package/build/executor/ci-rerun-job.js +220 -14
- package/build/executor/cleanup-report.js +99 -0
- package/build/executor/cli.js +12 -1
- package/build/executor/completion-contract.js +66 -11
- package/build/executor/completion-supervision.js +99 -0
- package/build/executor/delivery-outcome.js +179 -0
- package/build/executor/deps.js +3 -0
- package/build/executor/env.js +276 -1
- package/build/executor/failure-reason-codes.js +126 -0
- package/build/executor/gate-qualification-job.js +20 -5
- package/build/executor/heartbeat.js +38 -0
- package/build/executor/http-client.js +72 -0
- package/build/executor/integration-job.js +298 -5
- package/build/executor/job-errors.js +36 -6
- package/build/executor/job-runner.js +830 -45
- package/build/executor/likely-tests.js +42 -3
- package/build/executor/merge-job.js +145 -2
- package/build/executor/observation.js +73 -4
- package/build/executor/permissions.js +193 -97
- package/build/executor/preflight.js +19 -3
- package/build/executor/process-containment.js +46 -2
- package/build/executor/prompt-spec.js +113 -9
- package/build/executor/rebase-finalization.js +38 -3
- package/build/executor/reconcile-overlap-job.js +41 -8
- package/build/executor/required-work-ledger.js +236 -81
- package/build/executor/resume-pre-spawn.js +38 -1
- package/build/executor/runner.js +91 -3
- package/build/executor/test-clock.js +8 -0
- package/build/executor/types.js +37 -2
- package/build/executor/worker-cli-launcher.js +259 -0
- package/build/executor/worker-command.js +177 -5
- package/build/executor/worker-database-target.js +91 -0
- package/build/executor/worker-database.js +927 -0
- package/build/executor/worker-finalization.js +106 -0
- package/build/executor/worker-guard-hook.js +203 -0
- package/build/executor/worker-resources.js +58 -0
- package/build/executor/worker-verification-guidance.js +44 -2
- package/build/executor/worktree.js +303 -15
- package/build/executor-launch.js +11 -1
- package/build/generated-assets-doctor.js +9 -1
- package/build/generated-assets-health.js +13 -4
- package/build/generated-assets-legacy.js +39 -0
- package/build/generated-assets-paths.js +12 -1
- package/build/generated-assets-repair.js +4 -1
- package/build/generated-assets-test-support.js +12 -0
- package/build/github-remote.js +33 -0
- package/build/github-sign-in.js +62 -0
- package/build/index.js +1133 -546
- package/build/init.js +39 -1
- package/build/install-bridge-conductor-gate.js +270 -11
- package/build/install-bridge-conductor-setup.js +427 -0
- package/build/install-bridge-conductor.js +1545 -268
- package/build/install-bridge.js +376 -60
- package/build/mcp-install-state.js +8 -2
- package/build/merge-pull-request.js +6 -0
- package/build/merge-workflow-install.js +782 -344
- package/build/phase-result-artifacts.js +75 -20
- package/build/pipeline-orchestrator.js +247 -4
- package/build/pipelines.generated.js +35 -35
- package/build/plan-discovery.js +15 -2
- package/build/plan-execution-ledger.js +321 -17
- package/build/plan-phase-routing.js +48 -13
- package/build/plane/cli.js +105 -51
- package/build/plane/defaults.js +3 -0
- package/build/plane/plane-freshness.js +298 -0
- package/build/plane/preflight.js +19 -0
- package/build/plane/schema-compatibility.js +137 -0
- package/build/plane/shutdown-deps.js +38 -0
- package/build/plane/shutdown.js +83 -8
- package/build/plane/terminal-run-cleanup.js +303 -0
- package/build/printed-remedy-commands.js +33 -4
- package/build/readiness-check.js +6 -2
- package/build/readiness-prerequisites.generated.js +532 -0
- package/build/readme.generated.js +1 -1
- package/build/repository-toolchains.js +581 -0
- package/build/setup-epic.js +421 -34
- package/build/shared-resources.generated.js +5 -0
- package/build/start-tickets.js +28 -15
- package/build/test-command-detection.js +284 -0
- package/build/test-command-validation.js +73 -0
- package/build/testing-config-client.js +150 -0
- package/build/ticket-delivery-artifacts.js +265 -0
- package/build/ticket-delivery-enrollment.js +369 -0
- package/build/ticket-delivery.js +205 -0
- package/build/ticket-review-summary.js +14 -0
- package/build/upgrade-cli.js +13 -0
- package/build/v2-readiness-requirements.js +552 -0
- package/build/version.generated.js +3 -3
- package/build/worker-guard-hook-bin.js +2 -2
- package/build/worktree-core.js +22 -7
- package/docs/BRIDGE-DIRECTORY-README.md +48 -0
- package/docs/EPIC-IMPLEMENTER-INSTALL.md +12 -867
- package/docs/EPIC-IMPLEMENTER.md +142 -63
- package/docs/epic-implementer/getting-started.md +187 -0
- package/docs/epic-implementer/self-hosting.md +133 -0
- package/package.json +4 -4
- package/pipelines/idea-to-ticket.json +1 -1
- package/pipelines/implement-ticket.json +8 -8
- package/pipelines/review-ticket.json +2 -2
- package/design-assets/favicon/favicon-32x32.png +0 -0
- package/design-assets/just-logo-rough-draft.png +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import path from"node:path";import{fileURLToPath}from"node:url";import{spawnSync}from"node:child_process";import{readFileSync}from"node:fs";var CONDUCTOR_HOOK_EMIT_FAILED_WARNING="Warning: conductor hook emit failed.";function resolveClaudeHookEventName(payload){if(payload===null||typeof payload!="object"||Array.isArray(payload))return null;let record=payload,candidates=["hook_event_name","hookEventName","event_name","event"];for(let key of candidates){let value=record[key];if(typeof value=="string"&&value.trim().length>0)return value.trim()}return null}function mapClaudeHookEventToSemanticType(eventName){switch(eventName){case"SessionStart":return"run.started";case"SessionEnd":return"run.stopped";case"Stop":return null;case"SubagentStop":return null;case"Notification":return"agent.notification";case"PreToolUse":return"tool.intent";default:return null}}var REQUIRED_IDENTITY_ENV=["BAPI_EPIC_IMPLEMENTER_RUN_ID","BAPI_EPIC_IMPLEMENTER_WORKER_ID","BAPI_EPIC_IMPLEMENTER_TICKET_KEY","BAPI_EPIC_IMPLEMENTER_WORKTREE_PATH"];function nonEmpty(value){return typeof value=="string"&&value.trim().length>0}function buildClaudeHookConductorEvent(payload,env){let eventName=resolveClaudeHookEventName(payload),type=mapClaudeHookEventToSemanticType(eventName);if(type===null||env.BAPI_EPIC_IMPLEMENTER_ENABLED!=="1")return null;for(let key of REQUIRED_IDENTITY_ENV)if(!nonEmpty(env[key]))return null;let ticketKey=env.BAPI_EPIC_IMPLEMENTER_TICKET_KEY.trim(),worktreePath=env.BAPI_EPIC_IMPLEMENTER_WORKTREE_PATH.trim(),details={ticket_key:ticketKey,worktree_path:worktreePath};nonEmpty(env.BAPI_EPIC_IMPLEMENTER_REPO_NAME)&&(details.repo=env.BAPI_EPIC_IMPLEMENTER_REPO_NAME.trim());let raw=payload!==null&&typeof payload=="object"&&!Array.isArray(payload)?payload:{payload};return{source:"claude-code",type,subject:ticketKey,run_id:env.BAPI_EPIC_IMPLEMENTER_RUN_ID.trim(),worker_id:env.BAPI_EPIC_IMPLEMENTER_WORKER_ID.trim(),producer:"claude-code-hook",observed_via:"claude-code-hook",data:{details,raw}}}function buildConductorEmitEventArgs(event){let args=["--type",event.type,"--source",event.source];return nonEmpty(event.subject??void 0)&&args.push("--subject",event.subject),nonEmpty(event.run_id??void 0)&&args.push("--run-id",event.run_id),nonEmpty(event.worker_id??void 0)&&args.push("--worker-id",event.worker_id),nonEmpty(event.producer??void 0)&&args.push("--producer",event.producer),nonEmpty(event.observed_via??void 0)&&args.push("--observed-via",event.observed_via),args.push("--data-json-stdin","--json"),args}function resolveConductorEmitCommand(env,emitArgs){let cliFile=env.BAPI_EPIC_IMPLEMENTER_CLI_FILE;return nonEmpty(cliFile)?{command:process.execPath,args:[cliFile.trim(),"emit-event",...emitArgs]}:{command:nonEmpty(env.BAPI_EPIC_IMPLEMENTER_BIN)?env.BAPI_EPIC_IMPLEMENTER_BIN.trim():"epic-implementer",args:["emit-event",...emitArgs]}}var defaultConductorSpawn=(command,args,input)=>{let result=spawnSync(command,args,{input,encoding:"utf-8",shell:!1});return{status:result.status,error:result.error}};function emitClaudeHookEventWithConductorCli(event,deps={}){let env=deps.env??process.env,spawn=deps.spawn??defaultConductorSpawn,emitArgs=buildConductorEmitEventArgs(event),{command,args}=resolveConductorEmitCommand(env,emitArgs),stdinPayload=JSON.stringify(event.data??{});try{let result=spawn(command,args,stdinPayload);return result.error?!1:result.status===0}catch{return!1}}function runClaudeConductorHookCli(deps={}){let env=deps.env??process.env,readStdin=deps.readStdin??(()=>readStdinSync()),warn=deps.warn??(m=>process.stderr.write(`${m}
|
|
2
|
+
import{realpathSync}from"node:fs";import path from"node:path";import{fileURLToPath}from"node:url";function isBinEntrypoint(callerModuleUrl,argv1=process.argv[1]){if(argv1===void 0)return!1;let callerPath=fileURLToPath(callerModuleUrl);try{return realpathSync(argv1)===realpathSync(callerPath)}catch{return path.resolve(argv1)===callerPath}}import{spawnSync}from"node:child_process";import{readFileSync}from"node:fs";var CONDUCTOR_HOOK_EMIT_FAILED_WARNING="Warning: conductor hook emit failed.";function resolveClaudeHookEventName(payload){if(payload===null||typeof payload!="object"||Array.isArray(payload))return null;let record=payload,candidates=["hook_event_name","hookEventName","event_name","event"];for(let key of candidates){let value=record[key];if(typeof value=="string"&&value.trim().length>0)return value.trim()}return null}function mapClaudeHookEventToSemanticType(eventName){switch(eventName){case"SessionStart":return"run.started";case"SessionEnd":return"run.stopped";case"Stop":return null;case"SubagentStop":return null;case"Notification":return"agent.notification";case"PreToolUse":return"tool.intent";default:return null}}var REQUIRED_IDENTITY_ENV=["BAPI_EPIC_IMPLEMENTER_RUN_ID","BAPI_EPIC_IMPLEMENTER_WORKER_ID","BAPI_EPIC_IMPLEMENTER_TICKET_KEY","BAPI_EPIC_IMPLEMENTER_WORKTREE_PATH"];function nonEmpty(value){return typeof value=="string"&&value.trim().length>0}function buildClaudeHookConductorEvent(payload,env){let eventName=resolveClaudeHookEventName(payload),type=mapClaudeHookEventToSemanticType(eventName);if(type===null||env.BAPI_EPIC_IMPLEMENTER_ENABLED!=="1")return null;for(let key of REQUIRED_IDENTITY_ENV)if(!nonEmpty(env[key]))return null;let ticketKey=env.BAPI_EPIC_IMPLEMENTER_TICKET_KEY.trim(),worktreePath=env.BAPI_EPIC_IMPLEMENTER_WORKTREE_PATH.trim(),details={ticket_key:ticketKey,worktree_path:worktreePath};nonEmpty(env.BAPI_EPIC_IMPLEMENTER_REPO_NAME)&&(details.repo=env.BAPI_EPIC_IMPLEMENTER_REPO_NAME.trim());let raw=payload!==null&&typeof payload=="object"&&!Array.isArray(payload)?payload:{payload};return{source:"claude-code",type,subject:ticketKey,run_id:env.BAPI_EPIC_IMPLEMENTER_RUN_ID.trim(),worker_id:env.BAPI_EPIC_IMPLEMENTER_WORKER_ID.trim(),producer:"claude-code-hook",observed_via:"claude-code-hook",data:{details,raw}}}function buildConductorEmitEventArgs(event){let args=["--type",event.type,"--source",event.source];return nonEmpty(event.subject??void 0)&&args.push("--subject",event.subject),nonEmpty(event.run_id??void 0)&&args.push("--run-id",event.run_id),nonEmpty(event.worker_id??void 0)&&args.push("--worker-id",event.worker_id),nonEmpty(event.producer??void 0)&&args.push("--producer",event.producer),nonEmpty(event.observed_via??void 0)&&args.push("--observed-via",event.observed_via),args.push("--data-json-stdin","--json"),args}function resolveConductorEmitCommand(env,emitArgs){let cliFile=env.BAPI_EPIC_IMPLEMENTER_CLI_FILE;return nonEmpty(cliFile)?{command:process.execPath,args:[cliFile.trim(),"emit-event",...emitArgs]}:{command:nonEmpty(env.BAPI_EPIC_IMPLEMENTER_BIN)?env.BAPI_EPIC_IMPLEMENTER_BIN.trim():"epic-implementer",args:["emit-event",...emitArgs]}}var defaultConductorSpawn=(command,args,input)=>{let result=spawnSync(command,args,{input,encoding:"utf-8",shell:!1});return{status:result.status,error:result.error}};function emitClaudeHookEventWithConductorCli(event,deps={}){let env=deps.env??process.env,spawn=deps.spawn??defaultConductorSpawn,emitArgs=buildConductorEmitEventArgs(event),{command,args}=resolveConductorEmitCommand(env,emitArgs),stdinPayload=JSON.stringify(event.data??{});try{let result=spawn(command,args,stdinPayload);return result.error?!1:result.status===0}catch{return!1}}function runClaudeConductorHookCli(deps={}){let env=deps.env??process.env,readStdin=deps.readStdin??(()=>readStdinSync()),warn=deps.warn??(m=>process.stderr.write(`${m}
|
|
3
3
|
`)),payload;try{let raw=readStdin();payload=JSON.parse(raw)}catch{return warn(CONDUCTOR_HOOK_EMIT_FAILED_WARNING),0}let event;try{event=buildClaudeHookConductorEvent(payload,env)}catch{return warn(CONDUCTOR_HOOK_EMIT_FAILED_WARNING),0}return event===null||emitClaudeHookEventWithConductorCli(event,{env,spawn:deps.spawn})||warn(CONDUCTOR_HOOK_EMIT_FAILED_WARNING),0}function readStdinSync(){return readFileSync(0,"utf-8")}var LEGACY_EPIC_IMPLEMENTER_ENV_PREFIX="BAPI_CONDUCTOR_",EPIC_IMPLEMENTER_ENV_PREFIX="BAPI_EPIC_IMPLEMENTER_",LEGACY_EPIC_IMPLEMENTER_NODE_PATH_ENV="CONDUCTOR_NODE_PATH",EPIC_IMPLEMENTER_NODE_PATH_ENV="EPIC_IMPLEMENTER_NODE_PATH",renamed=suffix=>[`${LEGACY_EPIC_IMPLEMENTER_ENV_PREFIX}${suffix}`,{kind:"renamed",successor:`${EPIC_IMPLEMENTER_ENV_PREFIX}${suffix}`}],RENAMED_SUFFIXES=["ALLOW_LIVE_SOURCE_DISPATCH","BIN","BUSY_TIMEOUT_MS","CLI_FILE","DEAD_AFTER_MS","DECLARED_TOUCHED_FILES_JSON","DENY_PROBE_TIMEOUT_MS","DISPATCH_DRY_RUN","ENABLE_PRE_TOOL_USE","ENABLED","EPIC_KEY","EPIC_RUN_ID","ESCALATION_COOLDOWN_MS","GATE_NAME","GLOBAL_TIMEOUT_MS","HOOK_COMMAND","LIVE_SOURCE_PATH","LIVENESS_STALLED_AFTER_MS","MESSAGE_COOLDOWN_MS","PLAN_VERSION","QUIET_AFTER_MS","REPO_NAME","RETENTION_DAYS","RETENTION_MAX_ROWS","RUN_ID","STALL_ACTIVE_MS","STALL_BLOCKED_MS","STALL_CANDIDATE_DONE_MS","STALL_NOT_STARTED_MS","STALL_STALLED_MS","STALL_UNKNOWN_MS","STALL_VERIFYING_MS","SUPERVISOR_MODE","SUPERVISOR_POLL_LIMIT","TICKET_KEY","WAKE_INTERVAL_MS","WORKER_ID","WORKTREE_PATH"],LEGACY_EPIC_IMPLEMENTER_ENV_MAPPINGS=new Map([...RENAMED_SUFFIXES.map(renamed),[`${LEGACY_EPIC_IMPLEMENTER_ENV_PREFIX}ALLOW_CLAUDE_MCP_SHADOWING`,{kind:"retired"}],[LEGACY_EPIC_IMPLEMENTER_NODE_PATH_ENV,{kind:"renamed",successor:EPIC_IMPLEMENTER_NODE_PATH_ENV}],["CONDUCTOR_DEAD_MAN_ONLY",{kind:"renamed",successor:"EPIC_IMPLEMENTER_DEAD_MAN_ONLY"}],["CONDUCTOR_DEADMAN_CHANNEL_TYPE",{kind:"renamed",successor:"EPIC_IMPLEMENTER_DEADMAN_CHANNEL_TYPE"}],["CONDUCTOR_DEADMAN_DESTINATION_REF",{kind:"renamed",successor:"EPIC_IMPLEMENTER_DEADMAN_DESTINATION_REF"}]]);function isLegacyEpicImplementerEnvKey(key){return key.startsWith(LEGACY_EPIC_IMPLEMENTER_ENV_PREFIX)||key===LEGACY_EPIC_IMPLEMENTER_NODE_PATH_ENV||key==="CONDUCTOR_DEAD_MAN_ONLY"||key==="CONDUCTOR_DEADMAN_CHANNEL_TYPE"||key==="CONDUCTOR_DEADMAN_DESTINATION_REF"}function findLegacyEpicImplementerEnv(env){return Object.keys(env).filter(isLegacyEpicImplementerEnvKey).sort((a,b)=>a<b?-1:a>b?1:0).map(key=>({key,mapping:LEGACY_EPIC_IMPLEMENTER_ENV_MAPPINGS.get(key)??null}))}var LEGACY_EPIC_IMPLEMENTER_ENV_ERROR_HEADER="Error: legacy Conductor environment variables are set. They were renamed to the Epic Implementer names and are no longer read. Update or remove each one, then retry:";function describeFinding(finding){let{key,mapping}=finding;return mapping===null?` ${key}: unknown legacy setting. If it is still a current setting, rename the ${LEGACY_EPIC_IMPLEMENTER_ENV_PREFIX} prefix to ${EPIC_IMPLEMENTER_ENV_PREFIX}; otherwise remove it.`:mapping.kind==="retired"?` ${key}: retired with no replacement. Remove it.`:` ${key} -> ${mapping.successor}`}function formatLegacyEpicImplementerEnvError(findings){return[LEGACY_EPIC_IMPLEMENTER_ENV_ERROR_HEADER,...findings.map(describeFinding)].join(`
|
|
4
4
|
`)+`
|
|
5
|
-
`}function runLegacyEpicImplementerEnvPreflight(env,writeStderr){let findings=findLegacyEpicImplementerEnv(env);return findings.length===0?0:(writeStderr(formatLegacyEpicImplementerEnvError(findings)),1)}function runEpicImplementerClaudeHookBin(deps={}){let handler=deps.handler??runClaudeConductorHookCli,exit=deps.exit??process.exit.bind(process),writeStderr=deps.writeStderr??(chunk=>process.stderr.write(chunk));if(runLegacyEpicImplementerEnvPreflight(deps.env??process.env,writeStderr)!==0){exit(0);return}let exitCode=0;try{exitCode=handler()}catch{exitCode=0}exit(exitCode)}
|
|
5
|
+
`}function runLegacyEpicImplementerEnvPreflight(env,writeStderr){let findings=findLegacyEpicImplementerEnv(env);return findings.length===0?0:(writeStderr(formatLegacyEpicImplementerEnvError(findings)),1)}function runEpicImplementerClaudeHookBin(deps={}){let handler=deps.handler??runClaudeConductorHookCli,exit=deps.exit??process.exit.bind(process),writeStderr=deps.writeStderr??(chunk=>process.stderr.write(chunk));if(runLegacyEpicImplementerEnvPreflight(deps.env??process.env,writeStderr)!==0){exit(0);return}let exitCode=0;try{exitCode=handler()}catch{exitCode=0}exit(exitCode)}isBinEntrypoint(import.meta.url)&&runEpicImplementerClaudeHookBin();export{runEpicImplementerClaudeHookBin};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { normalizeReadinessDetail, normalizeReadinessRemediation, } from "./readiness-check.js";
|
|
2
|
+
/** The server diagnostic that reports whether email can actually leave the server. */
|
|
3
|
+
export const EMAIL_TRANSPORT_LIVE_DIAGNOSTIC_ID = "escalation_email.transport_live";
|
|
4
|
+
/** Both ways to reach a person, spelled once for every reachability warning. */
|
|
5
|
+
export const ESCALATION_REACHABILITY_REMEDY = "declare notify.webhook_url in the run policy, or configure live email on the server.";
|
|
6
|
+
/** Fixed copy for the known failed transport diagnostic. It never infers which failure it was. */
|
|
7
|
+
export const EMAIL_TRANSPORT_NOT_LIVE_DETAIL = "escalations go to email, and this server's email transport is not live (local no-op or unavailable), so no person is told";
|
|
8
|
+
/**
|
|
9
|
+
* Fixed copy for a failed email transport when email is not the selected channel
|
|
10
|
+
* (BAPI-1495). It reports an unused capability and never says nobody is told.
|
|
11
|
+
*/
|
|
12
|
+
export const EMAIL_TRANSPORT_UNUSED_DETAIL = "this server's email transport is not live, but escalations do not use email for this run; this is unused email capability";
|
|
13
|
+
/** Fixed copy for a failed email transport when no channel is selected. */
|
|
14
|
+
export const EMAIL_TRANSPORT_NO_CHANNEL_DETAIL = "no escalation channel is selected, and this server's email transport is not live";
|
|
15
|
+
/** Fixed copy for a failed email transport when the channel is not known. */
|
|
16
|
+
export const EMAIL_TRANSPORT_UNCERTAIN_DETAIL = "this server's email transport is not live, and the selected escalation channel is not known, so whether it matters is unconfirmed";
|
|
17
|
+
/** A known email-transport diagnostic that is applicable, declared, and failed. */
|
|
18
|
+
export function isFailedEmailTransportDiagnostic(diagnostic) {
|
|
19
|
+
return (diagnostic.id === EMAIL_TRANSPORT_LIVE_DIAGNOSTIC_ID &&
|
|
20
|
+
diagnostic.severity !== null &&
|
|
21
|
+
diagnostic.applicability === "applicable" &&
|
|
22
|
+
diagnostic.verdict === "failed");
|
|
23
|
+
}
|
|
24
|
+
/** The fixed id of the escalation-reachability row (BAPI-1490). */
|
|
25
|
+
export const ESCALATION_REACHABILITY_CHECK_ID = "escalation-reachability";
|
|
26
|
+
/**
|
|
27
|
+
* The one effective-channel resolver (BAPI-1495). Pure.
|
|
28
|
+
*
|
|
29
|
+
* The server-reported run channel wins when it is `webhook`, `email` or `none`.
|
|
30
|
+
* Otherwise the caller's resolved channel is used: `null` is an explicit "no
|
|
31
|
+
* channel", while an omitted caller channel is not known. With neither, the channel
|
|
32
|
+
* is `unknown`. Preview, attach and readiness all resolve through this function, so
|
|
33
|
+
* the same inputs always produce the same wording.
|
|
34
|
+
*
|
|
35
|
+
* Warning follow-up belongs to the invoking driver or operator and is independent of
|
|
36
|
+
* notification delivery. Every row built from this channel stays non-blocking.
|
|
37
|
+
*/
|
|
38
|
+
export function resolveEffectiveEscalationChannel(report, callerChannel) {
|
|
39
|
+
const reported = report?.escalation_channel;
|
|
40
|
+
if (reported === "webhook" || reported === "email" || reported === "none")
|
|
41
|
+
return reported;
|
|
42
|
+
if (callerChannel === undefined)
|
|
43
|
+
return "unknown";
|
|
44
|
+
return callerChannel === null ? "none" : callerChannel;
|
|
45
|
+
}
|
|
46
|
+
/** The fixed detail for a failed email transport row, by effective channel. */
|
|
47
|
+
export function emailTransportDetailForChannel(channel) {
|
|
48
|
+
switch (channel) {
|
|
49
|
+
case "email":
|
|
50
|
+
return EMAIL_TRANSPORT_NOT_LIVE_DETAIL;
|
|
51
|
+
case "webhook":
|
|
52
|
+
return EMAIL_TRANSPORT_UNUSED_DETAIL;
|
|
53
|
+
case "none":
|
|
54
|
+
return EMAIL_TRANSPORT_NO_CHANNEL_DETAIL;
|
|
55
|
+
default:
|
|
56
|
+
return EMAIL_TRANSPORT_UNCERTAIN_DETAIL;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Whether a person can be told: one conservative, non-blocking row.
|
|
61
|
+
*
|
|
62
|
+
* Pure. It reads only the report it is handed and the resolved channel; it never
|
|
63
|
+
* fetches, reads a file, or consults a collector. It reports configuration, not
|
|
64
|
+
* delivery: a `pass` says only that the selected channel has a webhook or a
|
|
65
|
+
* confirmed-live email transport, and never that an endpoint or a person received
|
|
66
|
+
* anything. Recipient and template checks stay with the admission diagnostics.
|
|
67
|
+
*
|
|
68
|
+
* - `webhook` passes whatever the email transport says, unless the webhook's last
|
|
69
|
+
* delivery failed or could not be read; those warn without naming email as the cause.
|
|
70
|
+
* - `email` passes only on exactly one applicable, confirmed-passed
|
|
71
|
+
* `escalation_email.transport_live` observation. A failed, missing, deferred,
|
|
72
|
+
* unreadable or conflicting observation warns, and the known failed one uses the
|
|
73
|
+
* fixed non-live copy. This function never guesses between local no-op and
|
|
74
|
+
* unavailable.
|
|
75
|
+
* - no channel warns whatever the transport says; an unknown channel warns with an
|
|
76
|
+
* uncertainty line.
|
|
77
|
+
*
|
|
78
|
+
* Every row is non-blocking and carries fixed prose only: no destination, address,
|
|
79
|
+
* token or configuration value can reach it.
|
|
80
|
+
*/
|
|
81
|
+
export function buildEscalationReachabilityCheck(report, callerChannel) {
|
|
82
|
+
const channel = resolveEffectiveEscalationChannel(report, callerChannel);
|
|
83
|
+
const label = "Escalation reachability";
|
|
84
|
+
const warn = (detail) => ({
|
|
85
|
+
id: ESCALATION_REACHABILITY_CHECK_ID,
|
|
86
|
+
source: "server",
|
|
87
|
+
label,
|
|
88
|
+
status: "warn",
|
|
89
|
+
blocking: false,
|
|
90
|
+
detail: normalizeReadinessDetail(detail),
|
|
91
|
+
remediation: normalizeReadinessRemediation(ESCALATION_REACHABILITY_REMEDY),
|
|
92
|
+
});
|
|
93
|
+
const pass = () => ({
|
|
94
|
+
id: ESCALATION_REACHABILITY_CHECK_ID,
|
|
95
|
+
source: "server",
|
|
96
|
+
label,
|
|
97
|
+
status: "pass",
|
|
98
|
+
blocking: false,
|
|
99
|
+
detail: normalizeReadinessDetail("the selected channel has a webhook or confirmed-live email transport"),
|
|
100
|
+
});
|
|
101
|
+
if (channel === "webhook") {
|
|
102
|
+
if (report?.webhook_last_delivery === "failed") {
|
|
103
|
+
return warn("the selected webhook's last delivery failed");
|
|
104
|
+
}
|
|
105
|
+
if (report?.webhook_last_delivery === "unknown") {
|
|
106
|
+
return warn("the selected webhook's last delivery could not be read");
|
|
107
|
+
}
|
|
108
|
+
return pass();
|
|
109
|
+
}
|
|
110
|
+
if (channel === "none") {
|
|
111
|
+
return warn("no escalation channel: no webhook is declared and email is not the selected channel, so no person is told");
|
|
112
|
+
}
|
|
113
|
+
if (channel === "unknown") {
|
|
114
|
+
return warn("the selected escalation channel is not known, so whether a person would be told is unconfirmed");
|
|
115
|
+
}
|
|
116
|
+
const diagnostics = report === null || report.unavailableSources?.includes("server") === true
|
|
117
|
+
? null
|
|
118
|
+
: report.diagnostics ?? null;
|
|
119
|
+
const uncertain = "a reachable escalation channel is not confirmed: no webhook is declared, and live email transport is not confirmed";
|
|
120
|
+
if (diagnostics === null)
|
|
121
|
+
return warn(uncertain);
|
|
122
|
+
const observed = diagnostics.filter((entry) => entry.id === EMAIL_TRANSPORT_LIVE_DIAGNOSTIC_ID);
|
|
123
|
+
if (observed.length !== 1)
|
|
124
|
+
return warn(uncertain);
|
|
125
|
+
const [observation] = observed;
|
|
126
|
+
if (isFailedEmailTransportDiagnostic(observation))
|
|
127
|
+
return warn(EMAIL_TRANSPORT_NOT_LIVE_DETAIL);
|
|
128
|
+
if (observation.severity === "advisory" &&
|
|
129
|
+
observation.applicability === "applicable" &&
|
|
130
|
+
observation.verdict === "passed") {
|
|
131
|
+
return pass();
|
|
132
|
+
}
|
|
133
|
+
return warn(uncertain);
|
|
134
|
+
}
|
|
@@ -31,6 +31,16 @@
|
|
|
31
31
|
* is actuated by the executor machine's own `gh`, so no token, credential
|
|
32
32
|
* bundle, or environment credential is injected, added to argv, or returned.
|
|
33
33
|
*
|
|
34
|
+
* BAPI-1523 adds a second, check-run variant. When a no-push repair is held for an
|
|
35
|
+
* external CI provider, the server asks the executor to send ONE
|
|
36
|
+
* `POST repos/<owner>/<repo>/check-runs/<id>/rerequest` through the same ambient
|
|
37
|
+
* `gh`. It has no polling, no worktree, and no transition authority. It reports
|
|
38
|
+
* only `rerequested`, or `not_rerequestable` with a closed `forbidden` /
|
|
39
|
+
* `not_found` reason for a reliably identified HTTP 403 / 404. Anything else —
|
|
40
|
+
* 422, a timeout, a network, authentication, rate-limit, or server failure — is a
|
|
41
|
+
* closed job failure the server records as `rerequest_not_performed`. An absent
|
|
42
|
+
* `variant` is the workflow-run form above, so existing payloads stay valid.
|
|
43
|
+
*
|
|
34
44
|
* Diagnostics go to `console.error` only. MCP stdout is a protocol channel and
|
|
35
45
|
* writing child output to it corrupts the session.
|
|
36
46
|
*/
|
|
@@ -45,6 +55,10 @@ export const CI_RERUN_POLL_DEADLINE_MS = 3 * 60 * 1000;
|
|
|
45
55
|
export const CI_RERUN_POLL_INTERVAL_MS = 10 * 1000;
|
|
46
56
|
/** Per-`gh`-invocation timeout. */
|
|
47
57
|
export const CI_RERUN_GH_TIMEOUT_MS = 60 * 1000;
|
|
58
|
+
/** Bounds aligned with the Python result boundary (`CI_RERUN_LANE_MAX_CHARS`). */
|
|
59
|
+
export const CI_RERUN_LANE_MAX_CHARS = 200;
|
|
60
|
+
const CI_RERUN_APP_SLUG_MAX_CHARS = 100;
|
|
61
|
+
const GITHUB_ACTIONS_APP_SLUG = "github-actions";
|
|
48
62
|
const OWNER_REPO_RE = /^[A-Za-z0-9._-]+\/[A-Za-z0-9._-]+$/;
|
|
49
63
|
const CLAUDE_REVIEW_WORKFLOW_BASENAME = CLAUDE_REVIEW_WORKFLOW_RELPATH.split("/").pop() ?? "claude-review.yml";
|
|
50
64
|
/**
|
|
@@ -66,6 +80,44 @@ export function identifiesClaudeReviewWorkflow(identity) {
|
|
|
66
80
|
normalized.includes("claude-review") ||
|
|
67
81
|
normalized.includes("claude review"));
|
|
68
82
|
}
|
|
83
|
+
function hasControlCharacter(value) {
|
|
84
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
85
|
+
const code = value.charCodeAt(i);
|
|
86
|
+
if (code < 32 || code === 127)
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
function isPositiveSafeInteger(value) {
|
|
92
|
+
return (typeof value === "number" &&
|
|
93
|
+
Number.isSafeInteger(value) &&
|
|
94
|
+
value > 0);
|
|
95
|
+
}
|
|
96
|
+
/** A bounded, printable lane: non-empty, within the Python bound, no control characters. */
|
|
97
|
+
function validLane(value) {
|
|
98
|
+
if (typeof value !== "string")
|
|
99
|
+
return null;
|
|
100
|
+
const trimmed = value.trim();
|
|
101
|
+
if (!trimmed || trimmed.length > CI_RERUN_LANE_MAX_CHARS)
|
|
102
|
+
return null;
|
|
103
|
+
if (hasControlCharacter(trimmed))
|
|
104
|
+
return null;
|
|
105
|
+
return trimmed;
|
|
106
|
+
}
|
|
107
|
+
/** A normalized `owner/repo`; `.` and `..` components are never accepted. */
|
|
108
|
+
function validRepoFullName(value) {
|
|
109
|
+
if (typeof value !== "string")
|
|
110
|
+
return null;
|
|
111
|
+
const trimmed = value.trim();
|
|
112
|
+
if (!OWNER_REPO_RE.test(trimmed))
|
|
113
|
+
return null;
|
|
114
|
+
const parts = trimmed.split("/");
|
|
115
|
+
if (parts.length !== 2)
|
|
116
|
+
return null;
|
|
117
|
+
if (parts.some((part) => part === "." || part === ".."))
|
|
118
|
+
return null;
|
|
119
|
+
return trimmed.toLowerCase();
|
|
120
|
+
}
|
|
69
121
|
/**
|
|
70
122
|
* Validate a raw server payload into typed fields, SYNCHRONOUSLY and before any
|
|
71
123
|
* subprocess is invoked.
|
|
@@ -73,6 +125,10 @@ export function identifiesClaudeReviewWorkflow(identity) {
|
|
|
73
125
|
* Fails closed on every unusable shape. A job that cannot prove what it is about
|
|
74
126
|
* to re-run must not run `gh` and then discover the problem — that is how a
|
|
75
127
|
* malformed payload becomes a re-run of the wrong workflow.
|
|
128
|
+
*
|
|
129
|
+
* BAPI-1523 — the payload is a union selected by `variant`. An absent
|
|
130
|
+
* discriminator is the workflow-run form; an unknown one, or a payload carrying
|
|
131
|
+
* the other variant's actuator field, is refused.
|
|
76
132
|
*/
|
|
77
133
|
export function parseCiRerunPayload(payload) {
|
|
78
134
|
const refuse = (reason) => ({ ok: false, failure: { errorKind: CI_RERUN_REFUSED, reason } });
|
|
@@ -80,38 +136,92 @@ export function parseCiRerunPayload(payload) {
|
|
|
80
136
|
return refuse("payload_not_an_object");
|
|
81
137
|
}
|
|
82
138
|
const raw = payload;
|
|
83
|
-
const
|
|
84
|
-
if (
|
|
85
|
-
|
|
139
|
+
const variantRaw = raw.variant;
|
|
140
|
+
if (variantRaw !== undefined &&
|
|
141
|
+
variantRaw !== null &&
|
|
142
|
+
variantRaw !== "workflow_run" &&
|
|
143
|
+
variantRaw !== "check_run") {
|
|
144
|
+
return refuse("variant_unknown");
|
|
86
145
|
}
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
146
|
+
const variant = variantRaw === "check_run" ? "check_run" : "workflow_run";
|
|
147
|
+
// Cross-variant actuator fields are contradictory, never ignored.
|
|
148
|
+
if (variant === "check_run" && raw.workflow_run_id !== undefined) {
|
|
149
|
+
return refuse("variant_contradictory");
|
|
150
|
+
}
|
|
151
|
+
if (variant === "workflow_run" && raw.check_run_id !== undefined) {
|
|
152
|
+
return refuse("variant_contradictory");
|
|
153
|
+
}
|
|
154
|
+
const repoFullName = validRepoFullName(raw.repo_full_name);
|
|
155
|
+
if (repoFullName === null) {
|
|
156
|
+
return refuse("repo_full_name_invalid");
|
|
92
157
|
}
|
|
93
|
-
const lane = raw.required_check_lane;
|
|
94
|
-
if (
|
|
95
|
-
return refuse("
|
|
158
|
+
const lane = validLane(raw.required_check_lane);
|
|
159
|
+
if (lane === null) {
|
|
160
|
+
return refuse(typeof raw.required_check_lane === "string" && raw.required_check_lane.trim()
|
|
161
|
+
? "required_check_lane_invalid"
|
|
162
|
+
: "required_check_lane_missing");
|
|
96
163
|
}
|
|
97
164
|
const attempt = raw.conductor_infra_attempt;
|
|
98
|
-
if (
|
|
165
|
+
if (!isPositiveSafeInteger(attempt)) {
|
|
99
166
|
return refuse("conductor_infra_attempt_invalid");
|
|
100
167
|
}
|
|
101
168
|
const identityRaw = raw.workflow_identity;
|
|
102
169
|
const workflowIdentity = typeof identityRaw === "string" && identityRaw.trim() ? identityRaw.trim() : null;
|
|
170
|
+
if (workflowIdentity !== null && hasControlCharacter(workflowIdentity)) {
|
|
171
|
+
return refuse("workflow_identity_invalid");
|
|
172
|
+
}
|
|
103
173
|
// The review-workflow refusal, evaluated on the SERVER-SUPPLIED identity and
|
|
104
174
|
// on the lane name, before any subprocess exists.
|
|
105
175
|
if (identifiesClaudeReviewWorkflow(workflowIdentity) ||
|
|
106
176
|
identifiesClaudeReviewWorkflow(lane)) {
|
|
107
177
|
return refuse("claude_review_workflow_refused");
|
|
108
178
|
}
|
|
179
|
+
// An `action_required` identity or conclusion is never actuated.
|
|
180
|
+
if (raw.conclusion === "action_required" || raw.observed_conclusion === "action_required") {
|
|
181
|
+
return refuse("action_required_refused");
|
|
182
|
+
}
|
|
183
|
+
if (variant === "check_run") {
|
|
184
|
+
const checkRunId = raw.check_run_id;
|
|
185
|
+
if (!isPositiveSafeInteger(checkRunId)) {
|
|
186
|
+
return refuse("check_run_id_invalid");
|
|
187
|
+
}
|
|
188
|
+
const appSlugRaw = raw.app_slug;
|
|
189
|
+
if (typeof appSlugRaw !== "string" ||
|
|
190
|
+
!appSlugRaw.trim() ||
|
|
191
|
+
appSlugRaw.trim().length > CI_RERUN_APP_SLUG_MAX_CHARS ||
|
|
192
|
+
hasControlCharacter(appSlugRaw)) {
|
|
193
|
+
return refuse("app_slug_invalid");
|
|
194
|
+
}
|
|
195
|
+
const appSlug = appSlugRaw.trim().toLowerCase();
|
|
196
|
+
if (appSlug === GITHUB_ACTIONS_APP_SLUG) {
|
|
197
|
+
return refuse("github_actions_refused");
|
|
198
|
+
}
|
|
199
|
+
if (identifiesClaudeReviewWorkflow(appSlug)) {
|
|
200
|
+
return refuse("claude_review_workflow_refused");
|
|
201
|
+
}
|
|
202
|
+
return {
|
|
203
|
+
ok: true,
|
|
204
|
+
fields: {
|
|
205
|
+
variant: "check_run",
|
|
206
|
+
repoFullName,
|
|
207
|
+
checkRunId,
|
|
208
|
+
requiredCheckLane: lane,
|
|
209
|
+
conductorInfraAttempt: attempt,
|
|
210
|
+
appSlug,
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
const workflowRunId = raw.workflow_run_id;
|
|
215
|
+
if (!isPositiveSafeInteger(workflowRunId)) {
|
|
216
|
+
return refuse("workflow_run_id_invalid");
|
|
217
|
+
}
|
|
109
218
|
return {
|
|
110
219
|
ok: true,
|
|
111
220
|
fields: {
|
|
112
|
-
|
|
221
|
+
variant: "workflow_run",
|
|
222
|
+
repoFullName,
|
|
113
223
|
workflowRunId,
|
|
114
|
-
requiredCheckLane: lane
|
|
224
|
+
requiredCheckLane: lane,
|
|
115
225
|
conductorInfraAttempt: attempt,
|
|
116
226
|
workflowIdentity,
|
|
117
227
|
},
|
|
@@ -156,6 +266,9 @@ export async function runCiRerunJob(payload, deps) {
|
|
|
156
266
|
console.error(`[ci_rerun] payload refused: ${parsed.failure.reason}`);
|
|
157
267
|
return parsed;
|
|
158
268
|
}
|
|
269
|
+
if (parsed.fields.variant === "check_run") {
|
|
270
|
+
return runCheckRunRerequest(parsed.fields, deps);
|
|
271
|
+
}
|
|
159
272
|
const fields = parsed.fields;
|
|
160
273
|
const gh = deps.gh;
|
|
161
274
|
const now = deps.now ?? (() => Date.now());
|
|
@@ -263,6 +376,99 @@ export async function runCiRerunJob(payload, deps) {
|
|
|
263
376
|
`conclusion=${observedConclusion ?? "pending"}`);
|
|
264
377
|
return { ok: true, result };
|
|
265
378
|
}
|
|
379
|
+
/**
|
|
380
|
+
* The explicit HTTP status in `gh api` failure output, or `null`.
|
|
381
|
+
*
|
|
382
|
+
* Reads only the CLI's own status marker — `(HTTP 403)` or `HTTP 403:` — never
|
|
383
|
+
* generic prose or an exit code, so a permission failure is never inferred from
|
|
384
|
+
* wording. The status is the only thing taken from the text; the text itself is
|
|
385
|
+
* never returned or logged.
|
|
386
|
+
*/
|
|
387
|
+
export function extractGhHttpStatus(stderr) {
|
|
388
|
+
const match = /\(HTTP (\d{3})\)|\bHTTP (\d{3}):/.exec(stderr);
|
|
389
|
+
if (match === null)
|
|
390
|
+
return null;
|
|
391
|
+
const status = Number(match[1] ?? match[2]);
|
|
392
|
+
return Number.isInteger(status) ? status : null;
|
|
393
|
+
}
|
|
394
|
+
/** GitHub also answers 403 for rate limiting; that is not a permission fact. */
|
|
395
|
+
function looksRateLimited(stderr) {
|
|
396
|
+
return /rate limit|abuse|retry-after/i.test(stderr);
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Send ONE check-run re-request and report only the actuator fact (BAPI-1523).
|
|
400
|
+
*
|
|
401
|
+
* `gh api -X POST repos/<owner>/<repo>/check-runs/<id>/rerequest`, an argument
|
|
402
|
+
* array with no shell, no credential argument, no custom header, and no injected
|
|
403
|
+
* environment: the executor machine's ambient `gh` login is the only authority.
|
|
404
|
+
* It returns straight after the request — no polling, no worker, no worktree.
|
|
405
|
+
*/
|
|
406
|
+
async function runCheckRunRerequest(fields, deps) {
|
|
407
|
+
let response;
|
|
408
|
+
try {
|
|
409
|
+
response = await deps.gh([
|
|
410
|
+
"api",
|
|
411
|
+
"-X",
|
|
412
|
+
"POST",
|
|
413
|
+
`repos/${fields.repoFullName}/check-runs/${fields.checkRunId}/rerequest`,
|
|
414
|
+
], { timeoutMs: CI_RERUN_GH_TIMEOUT_MS });
|
|
415
|
+
}
|
|
416
|
+
catch {
|
|
417
|
+
// Contained: no exception text is returned or logged.
|
|
418
|
+
console.error("[ci_rerun] check-run rerequest invocation threw");
|
|
419
|
+
return {
|
|
420
|
+
ok: false,
|
|
421
|
+
failure: { errorKind: CI_RERUN_FAILED, reason: "rerequest_invocation_failed" },
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
if (response.exitCode === 0 && !response.timedOut) {
|
|
425
|
+
console.error(`[ci_rerun] check_run=${fields.checkRunId} rerequested`);
|
|
426
|
+
return {
|
|
427
|
+
ok: true,
|
|
428
|
+
result: {
|
|
429
|
+
check_run_id: fields.checkRunId,
|
|
430
|
+
lane: fields.requiredCheckLane,
|
|
431
|
+
outcome: "rerequested",
|
|
432
|
+
},
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
if (!response.timedOut) {
|
|
436
|
+
const status = extractGhHttpStatus(response.stderr);
|
|
437
|
+
if (status === 403 && !looksRateLimited(response.stderr)) {
|
|
438
|
+
console.error(`[ci_rerun] check_run=${fields.checkRunId} not rerequestable (403)`);
|
|
439
|
+
return {
|
|
440
|
+
ok: true,
|
|
441
|
+
result: {
|
|
442
|
+
check_run_id: fields.checkRunId,
|
|
443
|
+
lane: fields.requiredCheckLane,
|
|
444
|
+
outcome: "not_rerequestable",
|
|
445
|
+
reason: "forbidden",
|
|
446
|
+
},
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
if (status === 404) {
|
|
450
|
+
console.error(`[ci_rerun] check_run=${fields.checkRunId} not rerequestable (404)`);
|
|
451
|
+
return {
|
|
452
|
+
ok: true,
|
|
453
|
+
result: {
|
|
454
|
+
check_run_id: fields.checkRunId,
|
|
455
|
+
lane: fields.requiredCheckLane,
|
|
456
|
+
outcome: "not_rerequestable",
|
|
457
|
+
reason: "not_found",
|
|
458
|
+
},
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
console.error(`[ci_rerun] check_run=${fields.checkRunId} rerequest not performed ` +
|
|
463
|
+
`(exit=${response.exitCode ?? "null"}${response.timedOut ? ", timed out" : ""})`);
|
|
464
|
+
return {
|
|
465
|
+
ok: false,
|
|
466
|
+
failure: {
|
|
467
|
+
errorKind: CI_RERUN_FAILED,
|
|
468
|
+
reason: response.timedOut ? "rerequest_timed_out" : "rerequest_not_performed",
|
|
469
|
+
},
|
|
470
|
+
};
|
|
471
|
+
}
|
|
266
472
|
/** Production dependency bundle: the existing bounded `execFile`-based runner. */
|
|
267
473
|
export function createProductionCiRerunDeps() {
|
|
268
474
|
return { gh: createProductionEpicIntegrationGhRunner() };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/** How long a woken executor keeps retrying a retained report (6 minutes). */
|
|
2
|
+
export const CLEANUP_REPORT_WAKE_RETRY_WINDOW_MS = 6 * 60 * 1000;
|
|
3
|
+
/** The record-removal decision for one delivery result. */
|
|
4
|
+
export function cleanupReportPermitsRecordRemoval(result) {
|
|
5
|
+
return result.kind === "accepted" || result.kind === "not_applicable";
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Deliver one report. Never throws; a client without `reportCleanup`, or one that
|
|
9
|
+
* throws, is a retained `client_unsupported` / `network_error` outcome.
|
|
10
|
+
*/
|
|
11
|
+
export async function submitCleanupReport(input) {
|
|
12
|
+
const report = input.httpClient.reportCleanup;
|
|
13
|
+
if (typeof report !== "function") {
|
|
14
|
+
return { kind: "retained", reason: "client_unsupported", retryable: false };
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
const result = await report.call(input.httpClient, {
|
|
18
|
+
jobId: input.jobId,
|
|
19
|
+
repoName: input.repoName,
|
|
20
|
+
ownershipToken: input.ownershipToken,
|
|
21
|
+
path: input.path,
|
|
22
|
+
});
|
|
23
|
+
return normalizeCleanupReportResult(result);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return { kind: "retained", reason: "network_error", retryable: true };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const RETAINED_REASONS = new Set([
|
|
30
|
+
"job_running",
|
|
31
|
+
"retry_later",
|
|
32
|
+
"network_error",
|
|
33
|
+
"unsupported",
|
|
34
|
+
"unauthorized",
|
|
35
|
+
"rate_limited",
|
|
36
|
+
"server_error",
|
|
37
|
+
"malformed_response",
|
|
38
|
+
"client_unsupported",
|
|
39
|
+
]);
|
|
40
|
+
/** A malformed client result is a retained, non-retryable outcome, never a removal. */
|
|
41
|
+
function normalizeCleanupReportResult(result) {
|
|
42
|
+
if (typeof result === "object" && result !== null) {
|
|
43
|
+
const kind = result.kind;
|
|
44
|
+
if (kind === "accepted")
|
|
45
|
+
return { kind: "accepted" };
|
|
46
|
+
if (kind === "not_applicable")
|
|
47
|
+
return { kind: "not_applicable" };
|
|
48
|
+
if (kind === "retained") {
|
|
49
|
+
const reason = result.reason;
|
|
50
|
+
const retryable = result.retryable;
|
|
51
|
+
if (typeof reason === "string" && RETAINED_REASONS.has(reason)) {
|
|
52
|
+
return { kind: "retained", reason: reason, retryable: retryable === true };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return { kind: "retained", reason: "malformed_response", retryable: false };
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Retry a retained wake report in the background at the heartbeat cadence, for at
|
|
60
|
+
* most {@link CLEANUP_REPORT_WAKE_RETRY_WINDOW_MS}. Resolves when it finishes; it
|
|
61
|
+
* never rejects. Stops early (keeping the record) for an authorization failure or
|
|
62
|
+
* an unsupported server, on shutdown, and on exhaustion, where it emits the closed
|
|
63
|
+
* `cleanup_report_retry_exhausted` diagnostic and leaves later delivery to the
|
|
64
|
+
* startup recovery path.
|
|
65
|
+
*/
|
|
66
|
+
export async function retryWakeCleanupReport(input) {
|
|
67
|
+
const { deps } = input;
|
|
68
|
+
const startedAt = deps.now();
|
|
69
|
+
let result = input.firstResult;
|
|
70
|
+
try {
|
|
71
|
+
for (;;) {
|
|
72
|
+
if (cleanupReportPermitsRecordRemoval(result)) {
|
|
73
|
+
await input.onTerminal();
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (result.kind !== "retained" || !result.retryable)
|
|
77
|
+
return;
|
|
78
|
+
if (input.shouldStop())
|
|
79
|
+
return;
|
|
80
|
+
if (deps.now() - startedAt + input.intervalMs > CLEANUP_REPORT_WAKE_RETRY_WINDOW_MS) {
|
|
81
|
+
deps.diagnostic({ event: "cleanup_report_retry_exhausted", jobId: input.jobId });
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
await deps.sleep(input.intervalMs);
|
|
85
|
+
if (input.shouldStop())
|
|
86
|
+
return;
|
|
87
|
+
result = await submitCleanupReport({
|
|
88
|
+
httpClient: input.httpClient,
|
|
89
|
+
jobId: input.jobId,
|
|
90
|
+
repoName: input.repoName,
|
|
91
|
+
ownershipToken: input.ownershipToken,
|
|
92
|
+
path: "wake",
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
// Contained: a retry failure keeps the record for the startup path.
|
|
98
|
+
}
|
|
99
|
+
}
|
package/build/executor/cli.js
CHANGED
|
@@ -14,6 +14,7 @@ import { resolveStartTicketsRepoName } from "../start-tickets-repo.js";
|
|
|
14
14
|
import { DEFAULT_EXECUTOR_AGENT_ID } from "./agent-identity.js";
|
|
15
15
|
import { executorEpicRunIdRefusal, isValidExecutorEpicRunId, validateExecutorClaimScope, } from "./claim-scope.js";
|
|
16
16
|
import { createDefaultExecutorDeps } from "./deps.js";
|
|
17
|
+
import { createProductionWorkerResources } from "./worker-resources.js";
|
|
17
18
|
import { scrubExecutorProcessGithubCredentials } from "./env.js";
|
|
18
19
|
import { resolveBaseUrl, resolveExecutorApiAccess, EXECUTOR_BASE_URL_REQUIRED_MESSAGE, } from "./credentials.js";
|
|
19
20
|
import { createExecutorHttpClient } from "./http-client.js";
|
|
@@ -320,7 +321,17 @@ export async function runExecutorCli(argv, overrides = {}) {
|
|
|
320
321
|
if (argv[0] === "watch") {
|
|
321
322
|
return runExecutorWatchCli(argv.slice(1));
|
|
322
323
|
}
|
|
323
|
-
|
|
324
|
+
// BAPI-1479: the disposable job database and own-build launcher attach only to
|
|
325
|
+
// the real executor process — never to `createDefaultExecutorDeps()`, which
|
|
326
|
+
// tests spread, nor to injected deps. See `worker-resources.ts`.
|
|
327
|
+
const deps = overrides.deps ?? {
|
|
328
|
+
...createDefaultExecutorDeps(),
|
|
329
|
+
workerResources: createProductionWorkerResources({
|
|
330
|
+
env: process.env,
|
|
331
|
+
cwd: process.cwd(),
|
|
332
|
+
platform: process.platform,
|
|
333
|
+
}),
|
|
334
|
+
};
|
|
324
335
|
const context = overrides.context ?? {
|
|
325
336
|
hostname: os.hostname(),
|
|
326
337
|
pid: process.pid,
|