| 231 | (self.logs_dir / "setup_version.return_code.txt").write_text(str(version_result.return_code)) |
| 232 | |
| 233 | async def run(self, instruction: str, environment: BaseEnvironment, context: AgentContext) -> None: |
| 234 | self.logs_dir.mkdir(parents=True, exist_ok=True) |
| 235 | benchmark_instruction = f"{_benchmark_instruction_preamble()}{_load_task_hint()}{instruction}" |
| 236 | local_instruction = self.logs_dir / "instruction.txt" |
| 237 | local_instruction.write_text(benchmark_instruction) |
| 238 | await environment.upload_file(local_instruction, f"{IN_CONTAINER_INPUT}/instruction.txt") |
| 239 | |
| 240 | env = { |
| 241 | "HOME": IN_CONTAINER_HOME, |
| 242 | "JCODE_HOME": IN_CONTAINER_HOME, |
| 243 | "JCODE_RUNTIME_DIR": IN_CONTAINER_RUNTIME, |
| 244 | "JCODE_NO_TELEMETRY": "1", |
| 245 | "JCODE_PROVIDER": self._provider_arg, |
| 246 | "JCODE_MODEL": self._jcode_model, |
| 247 | "JCODE_OPENAI_REASONING_EFFORT": os.environ.get("JCODE_OPENAI_REASONING_EFFORT", "high"), |
| 248 | "JCODE_OPENAI_SERVICE_TIER": os.environ.get("JCODE_OPENAI_SERVICE_TIER", "priority"), |
| 249 | "SSL_CERT_FILE": IN_CONTAINER_CA_BUNDLE, |
| 250 | "OPENSSL_CERT_FILE": IN_CONTAINER_CA_BUNDLE, |
| 251 | "LD_LIBRARY_PATH": IN_CONTAINER_LIB_DIR, |
| 252 | } |
| 253 | |
| 254 | result = await environment.exec( |
| 255 | command=( |
| 256 | 'set -e; ' |
| 257 | 'workdir="${JCODE_TASK_WORKDIR:-}"; ' |
| 258 | 'if [ -z "$workdir" ]; then ' |
| 259 | ' if [ -d /app ]; then workdir=/app; else workdir="$(pwd)"; fi; ' |
| 260 | 'fi; ' |
| 261 | f'instruction="$(cat {IN_CONTAINER_INPUT}/instruction.txt)"; ' |
| 262 | f'{IN_CONTAINER_BINARY} --quiet --no-update --no-selfdev ' |
| 263 | '--provider "$JCODE_PROVIDER" --model "$JCODE_MODEL" ' |
| 264 | '-C "$workdir" run --ndjson "$instruction" ' |
| 265 | f'> {IN_CONTAINER_OUTPUT}/events.ndjson 2> {IN_CONTAINER_OUTPUT}/stderr.txt' |
| 266 | ), |
| 267 | env=env |
| 268 | ) |
| 269 | |
| 270 | (self.logs_dir / "exec_stdout.txt").write_text(result.stdout or "") |
| 271 | (self.logs_dir / "exec_stderr.txt").write_text(result.stderr or "") |
| 272 | (self.logs_dir / "exec_return_code.txt").write_text(str(result.return_code)) |
| 273 | |
| 274 | try: |
| 275 | await environment.download_dir(IN_CONTAINER_OUTPUT, self.logs_dir / "jcode-output") |
| 276 | except Exception as e: # noqa: BLE001 |
| 277 | (self.logs_dir / "download_error.txt").write_text(str(e)) |
| 278 | |
| 279 | metadata: dict[str, Any] = { |
| 280 | "return_code": result.return_code, |
| 281 | "provider": self._provider_arg, |
| 282 | "model": self._jcode_model, |
| 283 | "jcode_binary": str(JCODE_BINARY), |
| 284 | } |
| 285 | |
| 286 | output_dir = self.logs_dir / "jcode-output" |
| 287 | payload = _load_final_payload(output_dir) |
| 288 | if payload is not None: |
| 289 | usage = payload.get("usage") or {} |
| 290 | context.n_input_tokens = usage.get("input_tokens") |