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ACtD,qCAAqC;IACrC,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,kCAAkC,GAAG,qBAAqB,CAiE9G","sourcesContent":["/**\n * Remote Execution — remote resume builder (2.14.0 → 3.0.0 bridge).\n *\n * Builds a `RemoteMissionExecutor` for a resolved durable child session, mirroring\n * `buildChildResumeExecutor` but with a remote transport instead of local spawn.\n * With the synchronised modern runtime, the remote child uses the durable\n * `--child-mission` / `--session-id` path: the SAME child session file is\n * materialised onto the target and the child continues the SAME logical mission\n * (continue-not-replay), never an unrelated subordinate session.\n */\n\nimport { readFileSync } from \"node:fs\";\nimport type { BuildAssignedExecutor } from \"../assignment/assignment-control-service.js\";\nimport { type BuiltChildResume, buildChildResumePrompt } from \"../durable-child-session/child-session-restore.js\";\nimport type { DurableMissionRecord } from \"../mission-domain/durable-store.js\";\nimport type { ProcessMissionVerifier } from \"../mission-domain/process-mission-executor.js\";\nimport type { SessionManager } from \"../session-manager.js\";\nimport { RemoteMissionExecutor, type RemoteMissionExecutorOptions } from \"./remote-mission-executor.js\";\nimport type { RemoteExecutionTarget } from \"./remote-target-types.js\";\nimport type { RemoteChildLaunch, RemoteCommandRunner, RemoteExecutionTransport } from \"./remote-transport.js\";\n\n/**\n * Legacy projection prompt (kept for the explicitly-flagged temporary mode only;\n * never used by ordinary orchestration once a synchronised runtime is present).\n */\nexport function buildRemoteTaskPrompt(record: DurableMissionRecord): string {\n\tconst criteria = record.request.acceptanceCriteria\n\t\t.map((criterion) => `- ${criterion.id}: ${criterion.description}`)\n\t\t.join(\"\\n\");\n\treturn [\n\t\t\"<remote-execution-task>\",\n\t\t`You are executing durable mission ${record.missionId} on a remote execution target.`,\n\t\t\"Complete the objective using the available tools, operating on the files in the current working directory.\",\n\t\t\"Before finishing, satisfy the acceptance criteria by running the stated verification yourself.\",\n\t\t\"</remote-execution-task>\",\n\t\t\"\",\n\t\t`Objective: ${record.request.objective}`,\n\t\t\"\",\n\t\t\"Acceptance criteria:\",\n\t\tcriteria.length > 0 ? criteria : \"(none)\",\n\t].join(\"\\n\");\n}\n\nexport interface BuildRemoteChildResumeOptions {\n\trecord: DurableMissionRecord;\n\tchildSessionId: string;\n\ttarget: RemoteExecutionTarget;\n\ttransport: RemoteExecutionTransport & RemoteCommandRunner;\n\t/** Resolved session manager (enables the modern durable child-session path). */\n\tsessionManager?: SessionManager;\n\t/** Override the materialised child session file content (else read from the session manager). */\n\tsessionFileContent?: string;\n\t/** Concrete remote child launch (remote jensen CLI command). */\n\tbuildRemoteLaunch: (input: {\n\t\trequest: DurableMissionRecord[\"request\"];\n\t\tresumePrompt: string;\n\t\tchildSessionId: string;\n\t\tworkspaceDir: string;\n\t\tagentDir: string;\n\t\tsessionDir: string;\n\t}) => RemoteChildLaunch;\n\t/** Materialised remote models.json content (ephemeral protected config). */\n\tmodelsJson: string;\n\t/** Absolute remote temp root for execution-scoped workspaces. */\n\tremoteTempRoot: string;\n\t/** Remote-relative files to hash before/after (location proof). */\n\tevidenceFiles?: string[];\n\t/** Initial workspace files to materialise on the target (remote-relative). */\n\tworkspaceFiles?: (request: DurableMissionRecord[\"request\"]) => { path: string; content: string }[];\n\texecutorId?: string;\n\tverifier?: ProcessMissionVerifier;\n\t/** Shared-inference admission wiring (reverse tunnel + token issuer). */\n\tadmission?: RemoteMissionExecutorOptions[\"admission\"];\n\t/** Remote execution timeout (ms). */\n\ttimeoutMs?: number;\n}\n\n/**\n * Build the continue-not-replay remote executor from a resolved session. When a\n * `sessionManager` is supplied, the remote child resumes the SAME durable\n * child session via `--child-mission` / `--session-id`.\n */\nexport function buildRemoteChildResumeExecutor(options: BuildRemoteChildResumeOptions): BuiltChildResume {\n\tconst { record, childSessionId } = options;\n\tconst resumePrompt = options.sessionManager\n\t\t? buildChildResumePrompt(record, options.sessionManager)\n\t\t: buildRemoteTaskPrompt(record);\n\n\tlet sessionFileContent = options.sessionFileContent;\n\tif (sessionFileContent === undefined && options.sessionManager) {\n\t\tconst sessionFile = options.sessionManager.getSessionFile();\n\t\tif (sessionFile) sessionFileContent = readFileSync(sessionFile, \"utf8\");\n\t}\n\n\tconst executor = new RemoteMissionExecutor({\n\t\texecutorId: options.executorId ?? \"remote-child-resume\",\n\t\ttarget: options.target,\n\t\ttransport: options.transport,\n\t\tbuildRemoteLaunch: ({ request, workspaceDir, agentDir, sessionDir }) =>\n\t\t\toptions.buildRemoteLaunch({ request, resumePrompt, childSessionId, workspaceDir, agentDir, sessionDir }),\n\t\tworkspaceFiles: options.workspaceFiles,\n\t\tmodelsJson: options.modelsJson,\n\t\tchildSessionId,\n\t\tsessionFileContent,\n\t\tremoteTempRoot: options.remoteTempRoot,\n\t\tevidenceFiles: options.evidenceFiles,\n\t\tverifier: options.verifier,\n\t\tadmission: options.admission,\n\t\ttimeoutMs: options.timeoutMs,\n\t});\n\n\treturn { childSessionId, resumePrompt, executor };\n}\n\n// =============================================================================\n// Worker-facing remote executor builder\n// =============================================================================\n\nexport interface BuildRemoteAssignedExecutorOptions {\n\texecutorId: string;\n\ttarget: RemoteExecutionTarget;\n\ttransport: RemoteExecutionTransport & RemoteCommandRunner;\n\t/** Absolute path to the synchronised remote Jensen CLI JS entry. */\n\tremoteCliEntry: string;\n\t/** Materialised remote models.json content (ephemeral protected config). */\n\tmodelsJson: string;\n\t/** Absolute remote temp root for execution-scoped workspaces. */\n\tremoteTempRoot: string;\n\t/** Remote-relative files to hash before/after (location proof). */\n\tevidenceFiles?: string[];\n\t/** Initial workspace files to materialise on the target (remote-relative). */\n\tworkspaceFiles?: (request: DurableMissionRecord[\"request\"]) => { path: string; content: string }[];\n\tverifier?: ProcessMissionVerifier;\n\t/** Shared-inference admission wiring (reverse tunnel + token issuer). */\n\tadmission?: RemoteMissionExecutorOptions[\"admission\"];\n\t/** Remote execution timeout (ms). */\n\ttimeoutMs?: number;\n}\n\n/**\n * Build the worker's remote executor factory for a remote-bound executor. The\n * returned `BuildAssignedExecutor` produces a `RemoteMissionExecutor` that runs\n * the synchronised current Jensen CLI on the target with the materialised agent\n * dir and the durable child-session path.\n */\nexport function buildRemoteAssignedExecutor(options: BuildRemoteAssignedExecutorOptions): BuildAssignedExecutor {\n\treturn ({ record, sessionManager, childSessionId, assignmentId }) => {\n\t\treturn buildRemoteChildResumeExecutor({\n\t\t\trecord,\n\t\t\tchildSessionId,\n\t\t\tsessionManager,\n\t\t\ttarget: options.target,\n\t\t\ttransport: options.transport,\n\t\t\tmodelsJson: options.modelsJson,\n\t\t\tremoteTempRoot: options.remoteTempRoot,\n\t\t\tevidenceFiles: options.evidenceFiles,\n\t\t\tworkspaceFiles: options.workspaceFiles,\n\t\t\texecutorId: options.executorId,\n\t\t\tverifier: options.verifier,\n\t\t\tadmission: options.admission,\n\t\t\ttimeoutMs: options.timeoutMs,\n\t\t\tbuildRemoteLaunch: ({\n\t\t\t\trequest,\n\t\t\t\tresumePrompt,\n\t\t\t\tchildSessionId: sessionId,\n\t\t\t\tsessionDir,\n\t\t\t\tagentDir,\n\t\t\t}): RemoteChildLaunch => {\n\t\t\t\tconst args: string[] = [\n\t\t\t\t\toptions.remoteCliEntry,\n\t\t\t\t\t\"--mode\",\n\t\t\t\t\t\"json\",\n\t\t\t\t\t\"-p\",\n\t\t\t\t\t\"--child-mission\",\n\t\t\t\t\trecord.missionId,\n\t\t\t\t\t\"--session-id\",\n\t\t\t\t\tsessionId,\n\t\t\t\t\t\"--session-dir\",\n\t\t\t\t\tsessionDir,\n\t\t\t\t];\n\t\t\t\tif (request.modelPolicy) {\n\t\t\t\t\targs.push(\"--provider\", request.modelPolicy.provider, \"--model\", request.modelPolicy.model);\n\t\t\t\t}\n\t\t\t\tif (request.capabilities && request.capabilities.length > 0) {\n\t\t\t\t\targs.push(\"--tools\", request.capabilities.join(\",\"));\n\t\t\t\t}\n\t\t\t\targs.push(resumePrompt);\n\t\t\t\treturn {\n\t\t\t\t\tcommand: \"node\",\n\t\t\t\t\targs,\n\t\t\t\t\tcwd: \"\", // overridden by the executor to the execution workspace\n\t\t\t\t\tenv: {\n\t\t\t\t\t\tJENSEN_CODING_AGENT_DIR: agentDir,\n\t\t\t\t\t\tJENSEN_CODE_CODING_AGENT_DIR: agentDir,\n\t\t\t\t\t\tPI_CODING_AGENT_DIR: agentDir,\n\t\t\t\t\t\tJENSEN_MISSION_ID: request.missionId,\n\t\t\t\t\t\tJENSEN_ASSIGNMENT_ID: assignmentId,\n\t\t\t\t\t\tJENSEN_SESSION_ID: sessionId,\n\t\t\t\t\t\t...(request.orchestration?.priority !== undefined\n\t\t\t\t\t\t\t? { JENSEN_INFERENCE_PRIORITY: String(request.orchestration.priority) }\n\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t...(request.orchestration?.dependencyCriticality !== undefined\n\t\t\t\t\t\t\t? { JENSEN_INFERENCE_UNBLOCKS: String(request.orchestration.dependencyCriticality) }\n\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t...(request.orchestration?.verification ? { JENSEN_INFERENCE_VERIFICATION: \"1\" } : {}),\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t},\n\t\t});\n\t};\n}\n"]}