@simplexai/localmodels-linux-arm64 0.1.0-dev.61 → 0.1.0-dev.63

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.
Files changed (67) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +66 -63
  3. package/modules/localmodels/__init__.py +1 -1
  4. package/modules/localmodels/bifrost_checks.py +19 -13
  5. package/modules/localmodels/bifrost_clients.py +38 -36
  6. package/modules/localmodels/bifrost_config.py +19 -6
  7. package/modules/localmodels/bifrost_log.py +3 -3
  8. package/modules/localmodels/bifrost_models.py +9 -8
  9. package/modules/localmodels/bifrost_pi.py +27 -72
  10. package/modules/localmodels/catalog.json +51 -58
  11. package/modules/localmodels/custom_hub.py +10 -1
  12. package/modules/localmodels/custom_hub_http.py +41 -107
  13. package/modules/localmodels/debug_mode.py +3 -3
  14. package/modules/localmodels/gateway.py +56 -55
  15. package/modules/localmodels/gateway_bifrost.py +70 -83
  16. package/modules/localmodels/gateway_clients.py +33 -116
  17. package/modules/localmodels/gateway_home.py +5 -5
  18. package/modules/localmodels/gateway_keys.py +8 -6
  19. package/modules/localmodels/gateway_probe.py +4 -4
  20. package/modules/localmodels/gateway_server.py +4 -4
  21. package/modules/localmodels/gateway_speed.py +2 -2
  22. package/modules/localmodels/harness.py +185 -401
  23. package/modules/localmodels/harness_core.py +409 -0
  24. package/modules/localmodels/harness_gateway.py +75 -73
  25. package/modules/localmodels/harness_probe.py +19 -216
  26. package/modules/localmodels/library_custom.py +51 -16
  27. package/modules/localmodels/library_elastic.py +1 -1
  28. package/modules/localmodels/library_gateway.py +59 -176
  29. package/modules/localmodels/library_jobs.py +4 -0
  30. package/modules/localmodels/library_model.py +23 -0
  31. package/modules/localmodels/library_pricing.py +2 -2
  32. package/modules/localmodels/library_serve.py +5 -3
  33. package/modules/localmodels/library_smoke.py +33 -21
  34. package/modules/localmodels/library_status.py +330 -2
  35. package/modules/localmodels/llm_rank.py +14 -5
  36. package/modules/localmodels/magpie_setup.py +5 -4
  37. package/modules/localmodels/magpie_windows.py +1 -1
  38. package/modules/localmodels/memcalc_load.py +9 -4
  39. package/modules/localmodels/pi_profile.py +384 -0
  40. package/modules/localmodels/process_identity.py +3 -3
  41. package/modules/localmodels/remote_ops_common.py +31 -90
  42. package/modules/localmodels/remote_ops_download.py +2 -0
  43. package/modules/localmodels/remote_ops_mirrors.py +1 -1
  44. package/modules/localmodels/remote_ops_ranges.py +4 -1
  45. package/modules/localmodels/remote_ops_redirect.py +393 -0
  46. package/modules/localmodels/runtime_cli.py +32 -46
  47. package/modules/localmodels/runtime_pi.py +1 -1
  48. package/modules/localmodels/source_byok.py +9 -16
  49. package/modules/localmodels/source_cli.py +136 -23
  50. package/modules/localmodels/speech_jobs.py +4 -0
  51. package/modules/localmodels/stack_binding.py +9 -7
  52. package/modules/localmodels/stack_clients.py +137 -21
  53. package/modules/localmodels/stack_doctor.py +6 -3
  54. package/modules/localmodels/stack_hardware.py +18 -0
  55. package/modules/localmodels/stack_lifecycle.py +3 -2
  56. package/modules/localmodels/stack_remove.py +2 -1
  57. package/modules/localmodels/stack_verify.py +2 -2
  58. package/modules/localmodels/stack_view_events.py +2 -2
  59. package/modules/localmodels/transport.py +1 -0
  60. package/modules/{simplex_localmodels-0.1.0.dev61.dist-info → simplex_localmodels-0.1.0.dev63.dist-info}/METADATA +1 -1
  61. package/modules/{simplex_localmodels-0.1.0.dev61.dist-info → simplex_localmodels-0.1.0.dev63.dist-info}/RECORD +63 -60
  62. package/package.json +1 -1
  63. package/tool.json +1 -1
  64. /package/modules/{simplex_localmodels-0.1.0.dev61.dist-info → simplex_localmodels-0.1.0.dev63.dist-info}/WHEEL +0 -0
  65. /package/modules/{simplex_localmodels-0.1.0.dev61.dist-info → simplex_localmodels-0.1.0.dev63.dist-info}/entry_points.txt +0 -0
  66. /package/modules/{simplex_localmodels-0.1.0.dev61.dist-info → simplex_localmodels-0.1.0.dev63.dist-info}/licenses/NOTICE +0 -0
  67. /package/modules/{simplex_localmodels-0.1.0.dev61.dist-info → simplex_localmodels-0.1.0.dev63.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -18,27 +18,38 @@ from pathlib import Path
18
18
  from typing import Any
19
19
 
20
20
  from localmodels import (
21
+ bifrost_clients,
21
22
  bifrost_config,
22
23
  bifrost_log,
24
+ bifrost_models,
25
+ bifrost_pi,
23
26
  gateway_home,
24
- gateway_keys,
25
- harness,
27
+ harness_cleanup,
28
+ harness_core,
26
29
  harness_gateway,
27
30
  harness_probe,
28
31
  hosts,
29
32
  http_local,
33
+ pi_profile,
30
34
  plan_envelope,
31
35
  process_identity,
32
36
  remote_ops_service,
37
+ stack_clients,
33
38
  )
34
39
  from localmodels.bifrost_config import ADMIN_USER as ADMIN_USER
40
+ from localmodels.bifrost_config import AGENT_MODEL as AGENT_MODEL
35
41
  from localmodels.bifrost_config import AGENT_RULE as AGENT_RULE
42
+ from localmodels.bifrost_config import APP_DIR as APP_DIR
36
43
  from localmodels.bifrost_config import AUX_PROVIDERS as AUX_PROVIDERS
44
+ from localmodels.bifrost_config import CALLER_KEY as CALLER_KEY
37
45
  from localmodels.bifrost_config import COMPLEX_RULE as COMPLEX_RULE
38
46
  from localmodels.bifrost_config import DECISION_TIMEOUT as DECISION_TIMEOUT
39
47
  from localmodels.bifrost_config import FAST_PROVIDER as FAST_PROVIDER
40
48
  from localmodels.bifrost_config import LOG_BATCH_INTERVAL as LOG_BATCH_INTERVAL
49
+ from localmodels.bifrost_config import PI_MODEL as PI_MODEL
50
+ from localmodels.bifrost_config import PI_PROVIDER as PI_PROVIDER
41
51
  from localmodels.bifrost_config import STORE as STORE
52
+ from localmodels.bifrost_config import app_dir as app_dir
42
53
  from localmodels.bifrost_config import differs as _config_differs
43
54
  from localmodels.bifrost_config import origin as origin
44
55
  from localmodels.bifrost_config import read_config as read_config
@@ -47,7 +58,7 @@ from localmodels.bifrost_config import render_config as render_config
47
58
  from localmodels.bifrost_config import sanitize_governance as sanitize_governance
48
59
  from localmodels.bifrost_config import write_config as write_config
49
60
  from localmodels.gateway_requests import AuxEndpoint, Check
50
- from localmodels.harness import (
61
+ from localmodels.harness_core import (
51
62
  HarnessError,
52
63
  HarnessPlan,
53
64
  ToolAction,
@@ -57,21 +68,11 @@ from localmodels.harness import (
57
68
  )
58
69
  from localmodels.runtime_io import Event
59
70
 
60
- _write_config = write_config
61
-
62
- APP_DIR = "~/.local/share/localmodels/bifrost"
63
- # The routed model, named like Magpie's routing group: Codex, pi and Claude Code all send it, and
64
- # the LLM's key lists it and the routing rules match it. No Claude-specific name: Claude Code reads
65
- # CLAUDE_CODE_MAX_CONTEXT_TOKENS only for an id that does not start with ``claude-``.
66
- AGENT_MODEL = harness.GROUP
67
- PI_PROVIDER = "localmodels"
68
- PI_MODEL = f"{PI_PROVIDER}/{AGENT_MODEL}"
69
- CALLER_KEY = gateway_keys.CALLER_KEY # clients send it; loopback inference checks no key
70
71
  HEALTH_TIMEOUT_S = 180.0
71
72
  # Windows cannot delete config.db while a running Bifrost holds it open: stop it before a change.
72
73
  STOP_BEFORE_CONFIG_CHANGE = os.name == "nt"
73
74
  LEGACY_UNIT = "localmodels-gateway" # the one name every install shared before 2026-11-10
74
- UNIT_DIR = harness.UNIT_DIR
75
+ UNIT_DIR = harness_core.UNIT_DIR
75
76
 
76
77
  Systemctl = Callable[..., "subprocess.CompletedProcess[str]"]
77
78
 
@@ -110,7 +111,7 @@ def unit_text(binary: str, app: Path, addr: str) -> str:
110
111
  )
111
112
 
112
113
 
113
- def retire_legacy_unit(name: str, app: Path, systemctl: Systemctl) -> None:
114
+ def retire_legacy_unit(name: str, app: Path, run_systemctl: Systemctl) -> None:
114
115
  """Stop, disable and delete the untagged unit when it runs this instance's directory; a unit
115
116
  of that name running any other directory belongs to another install and is kept."""
116
117
  old = unit_file(LEGACY_UNIT)
@@ -122,18 +123,18 @@ def retire_legacy_unit(name: str, app: Path, systemctl: Systemctl) -> None:
122
123
  return
123
124
  if old.stat().st_uid != os.getuid() or f" -app-dir {app} -host " not in body:
124
125
  return
125
- if systemctl("disable", "--now", f"{LEGACY_UNIT}.service").returncode != 0:
126
+ if run_systemctl("disable", "--now", f"{LEGACY_UNIT}.service").returncode != 0:
126
127
  raise HarnessError(f"systemctl --user disable --now {LEGACY_UNIT} failed")
127
128
  old.unlink()
128
- systemctl("daemon-reload")
129
+ run_systemctl("daemon-reload")
129
130
 
130
131
 
131
- def _require_owned_unit(record: hosts.OwnedBifrost, path: Path, systemctl: Systemctl) -> None:
132
+ def _require_owned_unit(record: hosts.OwnedBifrost, path: Path, run_systemctl: Systemctl) -> None:
132
133
  """Require both the private unit's exact content and systemd's loaded fragment."""
133
134
  try:
134
135
  info = path.lstat()
135
136
  expected = unit_text(record["binary"], Path(record["app_dir"]), record["addr"])
136
- fragment = systemctl("show", "-p", "FragmentPath", "--value", unit(record) + ".service")
137
+ fragment = run_systemctl("show", "-p", "FragmentPath", "--value", unit(record) + ".service")
137
138
  if (
138
139
  path.is_symlink()
139
140
  or info.st_uid != os.getuid()
@@ -147,13 +148,13 @@ def _require_owned_unit(record: hosts.OwnedBifrost, path: Path, systemctl: Syste
147
148
  raise HarnessError("cannot verify ownership of the Bifrost unit; left untouched") from None
148
149
 
149
150
 
150
- def _pause_unit(record: hosts.OwnedBifrost, path: Path, systemctl: Systemctl) -> None:
151
+ def _pause_unit(record: hosts.OwnedBifrost, path: Path, run_systemctl: Systemctl) -> None:
151
152
  """Stop the verified unit and confirm that systemd no longer has its process."""
152
- _require_owned_unit(record, path, systemctl)
153
+ _require_owned_unit(record, path, run_systemctl)
153
154
  name = unit(record) + ".service"
154
- if systemctl("stop", name).returncode:
155
+ if run_systemctl("stop", name).returncode:
155
156
  raise HarnessError("Bifrost unit could not stop")
156
- pid = systemctl("show", "-p", "MainPID", "--value", name)
157
+ pid = run_systemctl("show", "-p", "MainPID", "--value", name)
157
158
  if pid.returncode or pid.stdout.strip() != "0":
158
159
  raise HarnessError("Bifrost unit did not stop")
159
160
 
@@ -171,24 +172,24 @@ def plan_tools(
171
172
  resolved = hosts.tools_dir(tools_dir)
172
173
  cleaned = resolved.rstrip("/\\")
173
174
  tools_dir = cleaned if cleaned and not cleaned.endswith(":") else resolved
174
- lock = lock or harness.load_lock()
175
+ lock = lock or harness_core.load_lock()
175
176
  if "bifrost" not in lock:
176
177
  raise HarnessError("the tool lock has no Bifrost")
177
- build = harness.tool_build(lock["bifrost"]["builds"], platform, arch, "Bifrost")
178
+ build = harness_core.tool_build(lock["bifrost"]["builds"], platform, arch, "Bifrost")
178
179
  version = lock["bifrost"]["version"]
179
180
  # Windows starts only a file named .exe; the npm package and the CDN name it bifrost-http.
180
181
  binary = f"{tools_dir}/bifrost-{version}/bifrost-http" + (".exe" if platform == "win32" else "")
181
182
  found = os.path.expanduser(binary)
182
- if os.path.lexists(found) and harness.digest(found) != build["sha256"]:
183
+ if os.path.lexists(found) and harness_cleanup.digest(found) != build["sha256"]:
183
184
  raise HarnessError(f"{binary} is not the pinned Bifrost {version}; deal with it first")
184
185
  action: ToolAction = {
185
186
  "tool": "bifrost",
186
187
  "action": "reuse" if os.path.lexists(found) else "install",
187
188
  "path": binary,
188
189
  "version": version,
189
- "artifacts": [] if os.path.lexists(found) else [harness.tool_artifact(build)],
190
+ "artifacts": [] if os.path.lexists(found) else [harness_core.tool_artifact(build)],
190
191
  }
191
- addr = state.get("bifrost_addr") or harness.bifrost_addr()
192
+ addr = state.get("bifrost_addr") or harness_core.bifrost_addr()
192
193
  listeners = set(state.get("bifrost_listeners", []))
193
194
  ours = hosts.load_owned(tools_dir)["gateway"].get("bifrost")
194
195
  if listeners - {process_identity.current_uid()}:
@@ -208,7 +209,7 @@ def plan_tools(
208
209
  "artifacts": [],
209
210
  }
210
211
  warnings = [
211
- f"adds systemd --user service {unit_for(app_dir())}.service to keep the Bifrost gateway ({addr}) running"
212
+ f"adds systemd --user service {unit_for(bifrost_config.app_dir())}.service to keep the Bifrost gateway ({addr}) running"
212
213
  if systemd_user
213
214
  else "no systemd --user: Bifrost runs in the background; stack up restarts it after reboot"
214
215
  ]
@@ -218,7 +219,7 @@ def plan_tools(
218
219
  def plan_notes(has_decision: bool) -> list[str]:
219
220
  notes = [
220
221
  "the gateway is this tool's own Bifrost "
221
- f"{harness.load_lock().get('bifrost', {}).get('version', '')}; config and logs in"
222
+ f"{harness_core.load_lock().get('bifrost', {}).get('version', '')}; config and logs in"
222
223
  f" {APP_DIR} (0700; config has service keys, 0600); loopback skips key checks (as Magpie),"
223
224
  " the admin API uses a private password; logs keep request metadata only, never content"
224
225
  ]
@@ -241,23 +242,21 @@ def adopt(
241
242
  """Make ``harness.plan_harness``'s gateway plan this tool's Bifrost: its address, the pi
242
243
  model it sets, and pi's and the clients' current defaults as their own settings name them
243
244
  (not as a Magpie shows them)."""
244
- from localmodels import bifrost_clients, bifrost_pi, stack_clients
245
-
246
245
  gw = plan["gateway"]
247
246
  plan["warnings"] += plan_notes(has_decision)
248
247
  gw["kind"] = "bifrost"
249
- gw["addr"] = state.get("bifrost_addr") or harness.bifrost_addr()
248
+ gw["addr"] = state.get("bifrost_addr") or harness_core.bifrost_addr()
250
249
  gw["pi_model"] = PI_MODEL
251
250
  if state["inspection"] == "complete":
252
251
  gw["pi_model_before"] = bifrost_pi.pi_model(
253
- bifrost_pi.pi_profile(harness.gateway_environment(plan))
252
+ bifrost_pi.pi_profile(harness_core.gateway_environment(plan))
254
253
  )
255
254
  if context:
256
255
  gw["context"] = context
257
256
  if vision:
258
257
  gw["vision"] = True
259
258
  for name, seen in gw.get("clients", {}).items():
260
- environment = harness.gateway_environment(plan)
259
+ environment = harness_core.gateway_environment(plan)
261
260
  seen["model"] = bifrost_clients.current_model(name, environment)
262
261
  seen["files"] = stack_clients.config_files(name, environment)
263
262
 
@@ -273,11 +272,11 @@ def install_binary(
273
272
  target = Path(os.path.expanduser(action["path"]))
274
273
  artifact = action["artifacts"][0]
275
274
  if target.exists():
276
- if harness.digest(str(target)) == artifact["sha256"]:
275
+ if harness_cleanup.digest(str(target)) == artifact["sha256"]:
277
276
  log(f"Bifrost {action['version']} already at {target}, reused")
278
277
  return None
279
278
  raise HarnessError(f"{target} exists and is not the pinned version; not overwritten")
280
- archive = harness._fetch(tools_dir, artifact, log, event)
279
+ archive = harness_core.fetch_artifact(tools_dir, artifact, log, event)
281
280
  target.parent.mkdir(parents=True, exist_ok=True)
282
281
  staging = target.with_name(f".{target.name}.tmp")
283
282
  staging.unlink(missing_ok=True)
@@ -291,11 +290,6 @@ def install_binary(
291
290
  return str(target.parent)
292
291
 
293
292
 
294
- def app_dir() -> Path:
295
- override = os.environ.get("LOCALMODELS_BIFROST_DIR", "").strip()
296
- return Path(os.path.expanduser(override or APP_DIR))
297
-
298
-
299
293
  def _seal(app: Path) -> None:
300
294
  """Bifrost creates its SQLite stores and log with the umask; keep them 0600."""
301
295
  for path in (*app.glob("*.db*"), app / "bifrost.log"):
@@ -305,7 +299,7 @@ def _seal(app: Path) -> None:
305
299
 
306
300
  def admin_password(app: Path | None = None) -> str:
307
301
  """The private management password, made once and kept beside the config (0600)."""
308
- app = app or app_dir()
302
+ app = app or bifrost_config.app_dir()
309
303
  path = app / "admin-password"
310
304
  if path.is_file():
311
305
  return path.read_text(encoding="utf-8").strip()
@@ -365,7 +359,7 @@ def owned_listener(record: hosts.OwnedBifrost) -> bool:
365
359
  or path.read_text() != unit_text(record["binary"], app, addr)
366
360
  ):
367
361
  return False
368
- out = _systemctl("show", "-p", "MainPID", "--value", f"{unit(record)}.service")
362
+ out = systemctl("show", "-p", "MainPID", "--value", f"{unit(record)}.service")
369
363
  pid = int(out.stdout) if out.returncode == 0 else 0
370
364
  else:
371
365
  state, found = process_identity.status(app / "bifrost.pid")
@@ -393,7 +387,7 @@ def require_target(plan: ToolPlan) -> hosts.OwnedBifrost | None:
393
387
  record = hosts.load_owned(plan["tools_dir"])["gateway"].get("bifrost")
394
388
  # A different binary is a newly pinned Bifrost for this same instance, not another owner:
395
389
  # ownership is proven below against the recorded binary, and wire restarts on the new one.
396
- if record and (record["addr"] != addr or Path(record["app_dir"]) != app_dir()):
390
+ if record and (record["addr"] != addr or Path(record["app_dir"]) != bifrost_config.app_dir()):
397
391
  raise HarnessError("Bifrost owner differs from the approved plan; existing instance kept")
398
392
  if (harness_probe.listener_uids(addr) or harness_gateway.address_listening(addr)) and not (
399
393
  record and owned_listener(record)
@@ -408,7 +402,7 @@ def require_target(plan: ToolPlan) -> hosts.OwnedBifrost | None:
408
402
  return record
409
403
 
410
404
 
411
- def _healthy_owned(record: hosts.OwnedBifrost) -> bool:
405
+ def healthy_owned(record: hosts.OwnedBifrost) -> bool:
412
406
  return owned_listener(record) and healthy(record["addr"])
413
407
 
414
408
 
@@ -420,7 +414,7 @@ def healthy(addr: str, timeout: float = 5) -> bool:
420
414
  return False
421
415
 
422
416
 
423
- def _await(
417
+ def await_ready(
424
418
  addr: str,
425
419
  timeout: float = HEALTH_TIMEOUT_S,
426
420
  *,
@@ -431,7 +425,7 @@ def _await(
431
425
  app = Path(record["app_dir"])
432
426
  pid_file = app / "bifrost.pid"
433
427
  while time.monotonic() < deadline:
434
- if _healthy_owned(record):
428
+ if healthy_owned(record):
435
429
  return
436
430
  if (
437
431
  record["how"] != "unit"
@@ -451,18 +445,18 @@ def _await(
451
445
  raise HarnessError(f"Bifrost {addr} not ready in {int(timeout)} s; see {APP_DIR}/bifrost.log")
452
446
 
453
447
 
454
- def _systemctl(*args: str) -> subprocess.CompletedProcess[str]:
455
- return harness.run_tool(["systemctl", "--user", *args], timeout=120)
448
+ def systemctl(*args: str) -> subprocess.CompletedProcess[str]:
449
+ return harness_core.run_tool(["systemctl", "--user", *args], timeout=120)
456
450
 
457
451
 
458
452
  def _record(plan: ToolPlan, how: str) -> hosts.OwnedBifrost:
459
453
  """Register the instance before it acts, so a failure leaves a record remove can undo."""
460
- app = app_dir()
454
+ app = bifrost_config.app_dir()
461
455
  record: hosts.OwnedBifrost = {
462
456
  "app_dir": str(app),
463
457
  "addr": _addr(plan),
464
458
  "how": how,
465
- "binary": harness.tool_path(plan, "bifrost"),
459
+ "binary": harness_core.tool_path(plan, "bifrost"),
466
460
  }
467
461
  if how == "unit":
468
462
  record["unit"] = unit_for(app)
@@ -478,17 +472,17 @@ def _record(plan: ToolPlan, how: str) -> hosts.OwnedBifrost:
478
472
  return record
479
473
 
480
474
 
481
- def _start(record: hosts.OwnedBifrost, restart: bool) -> None:
475
+ def start(record: hosts.OwnedBifrost, restart: bool) -> None:
482
476
  app, addr = Path(record["app_dir"]), record["addr"]
483
477
  if record["how"] == "unit":
484
478
  name = unit(record)
485
- retire_legacy_unit(name, app, _systemctl) # it holds the port the new unit listens on
479
+ retire_legacy_unit(name, app, systemctl) # it holds the port the new unit listens on
486
480
  path = unit_file(name)
487
481
  text = unit_text(record["binary"], app, addr)
488
482
  if not path.is_file() or path.read_text(encoding="utf-8") != text:
489
483
  path.parent.mkdir(parents=True, exist_ok=True)
490
484
  path.write_text(text, encoding="utf-8")
491
- if _systemctl("daemon-reload").returncode != 0:
485
+ if systemctl("daemon-reload").returncode != 0:
492
486
  raise HarnessError("systemctl --user daemon-reload failed")
493
487
  restart = True
494
488
  # A unit an older release wrote under umask 0002 has the right text but is group
@@ -496,12 +490,12 @@ def _start(record: hosts.OwnedBifrost, restart: bool) -> None:
496
490
  if not path.is_symlink():
497
491
  path.chmod(0o644)
498
492
  verb = "restart" if restart else "start"
499
- if _systemctl("enable", f"{name}.service").returncode != 0:
493
+ if systemctl("enable", f"{name}.service").returncode != 0:
500
494
  raise HarnessError(f"systemctl --user enable {name} failed")
501
- if _systemctl(verb, f"{name}.service").returncode != 0:
495
+ if systemctl(verb, f"{name}.service").returncode != 0:
502
496
  raise HarnessError(f"systemctl --user {verb} {name} failed")
503
497
  return
504
- if not restart and _healthy_owned(record):
498
+ if not restart and healthy_owned(record):
505
499
  return
506
500
  _stop_owned_serve(record) # ours: restarted, or an earlier instance that stopped answering
507
501
  env = {**os.environ, "NO_PROXY": "127.0.0.1,localhost", "no_proxy": "127.0.0.1,localhost"}
@@ -578,7 +572,7 @@ def _stop_orphaned_serve(record: hosts.OwnedBifrost) -> None:
578
572
 
579
573
  def _stop_owned_serve(record: hosts.OwnedBifrost) -> None:
580
574
  app = Path(record["app_dir"])
581
- _stop_serve(app)
575
+ stop_serve(app)
582
576
  if not os.path.lexists(app / "bifrost.pid"):
583
577
  _stop_orphaned_serve(record)
584
578
 
@@ -596,14 +590,11 @@ def stop_serve(app: Path) -> None:
596
590
  _stop_orphaned_serve(record)
597
591
 
598
592
 
599
- _stop_serve = stop_serve
600
-
601
-
602
593
  def pause(record: hosts.OwnedBifrost) -> str:
603
594
  """Stop the proven instance, retaining its unit, configuration and ownership record."""
604
595
  running = owned_listener(record)
605
596
  if record["how"] == "unit":
606
- _pause_unit(record, unit_file(unit(record)), _systemctl)
597
+ _pause_unit(record, unit_file(unit(record)), systemctl)
607
598
  else:
608
599
  _retire(record)
609
600
  return "stopped" if running else "not-running"
@@ -614,7 +605,7 @@ def _retire(record: hosts.OwnedBifrost) -> None:
614
605
  it ours; a record naming the new binary could not, so wire would refuse the held port."""
615
606
  if record["how"] == "unit":
616
607
  name = unit(record)
617
- if _systemctl("stop", f"{name}.service").returncode != 0:
608
+ if systemctl("stop", f"{name}.service").returncode != 0:
618
609
  raise HarnessError(f"systemctl --user stop {name} failed; the earlier Bifrost kept")
619
610
  return
620
611
  _stop_owned_serve(record)
@@ -625,7 +616,7 @@ def ensure(plan: ToolPlan) -> str:
625
616
  reused, one on an earlier pinned binary is stopped first. ``wire`` writes the config and
626
617
  (re)starts it."""
627
618
  previous = require_target(plan)
628
- if previous and previous["binary"] != harness.tool_path(plan, "bifrost"):
619
+ if previous and previous["binary"] != harness_core.tool_path(plan, "bifrost"):
629
620
  _retire(previous)
630
621
  if "environment" not in plan:
631
622
  gateway_home.reclaim(plan["tools_dir"]) # an elevated run's folder (GitLab #15)
@@ -636,14 +627,14 @@ def ensure(plan: ToolPlan) -> str:
636
627
  app.chmod(0o700)
637
628
  admin_password(app)
638
629
  _seal(app)
639
- return "reused" if _healthy_owned(record) else "installed"
630
+ return "reused" if healthy_owned(record) else "installed"
640
631
 
641
632
 
642
633
  def revive(plan: HarnessPlan) -> str:
643
634
  """After a reboot: reuse an answering gateway, else start the recorded one."""
644
635
  addr = plan["gateway"]["addr"]
645
636
  record = require_target(plan)
646
- if record and _healthy_owned(record):
637
+ if record and healthy_owned(record):
647
638
  return "reused"
648
639
  if not record:
649
640
  raise HarnessError("the ownership manifest has no record of this tool's Bifrost gateway")
@@ -653,10 +644,10 @@ def revive(plan: HarnessPlan) -> str:
653
644
  if sanitized:
654
645
  if STOP_BEFORE_CONFIG_CHANGE and record["how"] != "unit":
655
646
  _stop_owned_serve(record)
656
- _write_config(app, config)
647
+ write_config(app, config)
657
648
  log_offset = bifrost_log.log_size(app)
658
- _start(record, restart=sanitized)
659
- _await(addr, record=record, log_offset=log_offset)
649
+ start(record, restart=sanitized)
650
+ await_ready(addr, record=record, log_offset=log_offset)
660
651
  _seal(app)
661
652
  return "started"
662
653
 
@@ -711,11 +702,11 @@ def wire(
711
702
  and _config_differs(app, config, sheets)
712
703
  ):
713
704
  _stop_owned_serve(record)
714
- changed = _write_config(app, config, sheets)
715
- if changed or not _healthy_owned(record):
705
+ changed = write_config(app, config, sheets)
706
+ if changed or not healthy_owned(record):
716
707
  log_offset = bifrost_log.log_size(app)
717
- _start(record, restart=changed)
718
- _await(record["addr"], record=record, log_offset=log_offset)
708
+ start(record, restart=changed)
709
+ await_ready(record["addr"], record=record, log_offset=log_offset)
719
710
  _seal(app)
720
711
  done = [f"provider {pid}" for pid in config["providers"]]
721
712
  default = gw.get("llm_fast") or gw["llm"]
@@ -730,8 +721,6 @@ def wire(
730
721
  )
731
722
  ]
732
723
  if select_pi:
733
- from localmodels import bifrost_clients, bifrost_models, bifrost_pi
734
-
735
724
  # pi and the clients get only names the running instance lists (bifrost_models).
736
725
  listed = bifrost_models.listed(record["addr"])
737
726
  done.append(bifrost_pi.point_pi(plan, listed))
@@ -750,13 +739,13 @@ def stop(tools_dir: str = hosts.TOOLS_DIR) -> Check:
750
739
  name = unit(record)
751
740
  path = unit_file(name)
752
741
  if path.is_file():
753
- out = _systemctl("disable", "--now", f"{name}.service")
742
+ out = systemctl("disable", "--now", f"{name}.service")
754
743
  if out.returncode != 0:
755
744
  return {"check": "bifrost", "ok": False, "detail": f"stopping {name} failed"}
756
745
  path.unlink()
757
- _systemctl("daemon-reload")
746
+ systemctl("daemon-reload")
758
747
  try:
759
- retire_legacy_unit(name, app, _systemctl)
748
+ retire_legacy_unit(name, app, systemctl)
760
749
  except HarnessError as exc:
761
750
  return {"check": "bifrost", "ok": False, "detail": str(exc)}
762
751
  else:
@@ -777,15 +766,13 @@ def stop(tools_dir: str = hosts.TOOLS_DIR) -> Check:
777
766
  def unwire(tools_dir: str = hosts.TOOLS_DIR, *, plan: ToolPlan | None = None) -> list[Check]:
778
767
  """Undo ``wire``: the native clients, then pi, then the instance itself. An entry leaves
779
768
  the manifest only once its removal succeeded."""
780
- from localmodels import bifrost_clients, bifrost_pi
781
-
782
769
  doc = hosts.load_owned(tools_dir)
783
770
  if not doc["gateway"].get("bifrost") and not (doc["pi"] and doc["pi"]["model"] == PI_MODEL):
784
771
  return []
785
772
  environment = (
786
- harness.gateway_environment(plan)
773
+ harness_core.gateway_environment(plan)
787
774
  if plan
788
- else {**os.environ, **harness.client_environment(tools_dir)}
775
+ else {**os.environ, **pi_profile.client_environment(tools_dir)}
789
776
  )
790
777
  results = bifrost_clients.unwire(tools_dir, environment=environment)
791
778
  if any(not check["ok"] for check in results):