Move harness profiles between host and Docker and stop silent draft retargeting

Native installs left Docker-era harness profiles in harnesses.json, so every
authoring launch failed trying to reach a Docker service, and a retained draft
bound to the old Docker server was silently projected onto the configured one.

- harness: add Profile.Mode and VerifyDockerLink as the single mode/verification
  helpers. `harness setup --host` configures or converts a host profile and
  clears docker_directory; reconfiguring a Docker-linked profile re-verifies the
  recorded directory still owns compose.yaml and fails naming it instead of
  saving a link that cannot launch. Setup's summary and `harness list` (via the
  new List/ListView shape) report the resulting mode and, for Docker, the
  directory, without changing the stored Config schema.
- setup-native.py: after build/install-skill it writes host (no docker_directory)
  profiles for the detected harnesses, defaulting to the detected OpenCode profile
  rather than a stale pi default, taking models from --model or the existing valid
  profile and never inventing one; it clears a stale Docker link and preserves
  unrelated keys/profiles. Detection-only: no harness install, upgrade or download.
- draft: add Draft.Resolve, the shared mismatch helper, which projects a draft
  onto the configured server and returns a dual-URL notice. CLI validate/submit
  and the TUI draft browser use it so a foreign draft is never silently
  retargeted; the TUI pre-wraps the notice to the panel width.
- Tests cover the Docker->host and host->host transitions, the missing-directory
  failure, installer write/migration (Python), and the CLI/TUI notice, using the
  real config file path in a temp dir.
- Update help text, README, docs and the packaged authoring skill reference to
  describe host as the default and the Docker-linked case.
This commit is contained in:
2026-10-15 19:53:10 +01:00
parent d00bd37833
commit 914345cb31
21 changed files with 732 additions and 141 deletions
+78 -2
View File
@@ -8,8 +8,8 @@ and ntfy from source into a per-user prefix, generates an ntfy configuration tha
mirrors compose.yaml, creates the publishing/phone accounts and writes the
manifest scripts/manage.py loads. ntfy is compiled from its pinned Go module on
every host because upstream publishes no macOS server binary. It reuses existing
host OpenCode configuration; model selection stays at runtime and is never
invented here.
host OpenCode configuration; it writes host (non-Docker) harness profiles for the
harnesses it detects and never invents a model.
"""
import argparse
import importlib.util
@@ -100,6 +100,78 @@ class Setup:
pi = shutil.which("pi")
return {"opencode": str(Path(opencode).resolve()), "pi": str(Path(pi).resolve()) if pi else ""}
# --- host harness profiles ------------------------------------------
MODEL_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_./:-"
@classmethod
def _valid_model(cls, value):
if not isinstance(value, str) or len(value) > 501 or "/" not in value:
return False
provider, model = value.split("/", 1)
if not provider or not model:
return False
return all(char in cls.MODEL_CHARS for char in value)
def harness_config_path(self):
root = Path(self.environ.get("XDG_CONFIG_HOME") or Path.home() / ".config")
return root / "pipelines" / "harnesses.json"
def _existing_harness_config(self):
path = self.harness_config_path()
if path.is_symlink() or not path.is_file():
return {}
try:
data = json.loads(path.read_text())
except (OSError, ValueError):
return {}
return data if isinstance(data, dict) else {}
def configure_harnesses(self, harness, model=""):
"""Write host (non-Docker) profiles for the harnesses detected on PATH.
The native install launches host harnesses, so a Docker-era
``docker_directory`` must be cleared rather than kept. Models come from
the explicit ``--model`` (recorded as PIPELINES_DEFAULT_MODEL) or the
existing valid profile; they are never invented. Unrelated keys and
profiles for harnesses that are not detected are preserved, matching
harness.Save. No harness is installed, upgraded or downloaded.
"""
existing = self._existing_harness_config()
profiles = existing.get("profiles")
if not isinstance(profiles, dict):
profiles = {}
merged = {name: dict(value) for name, value in profiles.items() if isinstance(value, dict)}
order = [name for name in ("opencode", "pi") if harness.get(name)]
configured = []
for name in order:
current = merged.get(name, {})
harness_model = current.get("model") if self._valid_model(current.get("model")) else ""
pipeline_model = current.get("pipeline_model") if self._valid_model(current.get("pipeline_model")) else ""
if name == "opencode" and self._valid_model(model):
harness_model = harness_model or model
pipeline_model = pipeline_model or model
if not harness_model or not pipeline_model:
continue
# Host mode: no docker_directory, executable is the detected host binary.
merged[name] = {"executable": harness[name], "model": harness_model, "pipeline_model": pipeline_model}
configured.append(name)
if not configured:
print("Host harness profiles were not written: no valid model was found for "
+ ", ".join(order) + ". Run 'pipelines harness setup opencode --host' to configure authoring.")
return None
# Prefer the primary detected harness, so a stale Docker-era default ("pi")
# never survives a native install.
default = "opencode" if "opencode" in configured else configured[0]
data = dict(existing)
data["default"] = default
data["profiles"] = merged
path = self.harness_config_path()
path.parent.mkdir(mode=0o700, parents=True, exist_ok=True)
self._write_atomic(path, (json.dumps(data, indent=2) + "\n").encode(), 0o600)
print(f"Host harness profiles written for {', '.join(configured)}; default {default} ({path}).")
return path
def resolve_prefix(self):
default = Path.home() / ".local/share/pipelines"
raw = self.prefix_argument or self.environ.get("PIPELINES_PREFIX") or default
@@ -382,6 +454,10 @@ class Setup:
resolution = self.resolve_ntfy()
self.build(prefix)
self.install_skill(prefix)
# The native install launches host harnesses, so write host profiles for
# the detected harnesses and clear any Docker-era link. Uses only the
# explicit --model or the existing valid profile/host configuration.
self.configure_harnesses(harness, args.model or "")
lan_ip = lan.detect_lan()
base_url = args.ntfy_url or f"http://{lan_ip}:{args.ntfy_port}"
config_path = self.write_ntfy_config(prefix, base_url, args.ntfy_port)