#!/usr/bin/env python3 """Docker backend of `pipelines harness setup opencode|pi`. Reconfigures one harness in the Docker installation without reinstalling or restarting services or deleting login. Run `pipelines harness setup ` instead of calling this directly. """ import importlib.util from pathlib import Path import subprocess import sys def module(name, file): spec = importlib.util.spec_from_file_location(name, Path(__file__).with_name(file)) result = importlib.util.module_from_spec(spec) spec.loader.exec_module(result) return result setup_docker = module("setup_docker", "setup-docker.py") def main(): root = Path(__file__).resolve().parents[1] if len(sys.argv) < 2 or sys.argv[1] not in ("opencode", "pi"): sys.exit("Usage: pipelines harness setup opencode|pi [--login] [--model P/M] [--pipeline-model P/M] [--default]") name = sys.argv[1] settings = root / ".env" docker = settings.is_file() and "PIPELINES_HOST_REPOSITORY=" in settings.read_text() if not docker: sys.exit("Docker installation is not configured. Run ./install first; harness setup does not fall back to a host runtime.") installer = setup_docker.Setup(root) installer.reconfigure_harness(name, sys.argv[2:]) installer.link_host(name) if __name__ == "__main__": try: main() except KeyboardInterrupt: sys.exit(130) except (ValueError, KeyError, OSError, subprocess.CalledProcessError) as error: sys.exit(f"Harness setup incomplete; existing credentials retained: {error}")