@simplexai/localmodels-darwin-arm64 0.1.0-dev.44 → 0.1.0-dev.47

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 (86) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +81 -83
  3. package/modules/localmodels/__init__.py +1 -1
  4. package/modules/localmodels/__main__.py +0 -1
  5. package/modules/localmodels/bifrost_checks.py +3 -127
  6. package/modules/localmodels/bifrost_clients.py +1 -1
  7. package/modules/localmodels/bifrost_config.py +2 -2
  8. package/modules/localmodels/bifrost_pi.py +1 -1
  9. package/modules/localmodels/budget.py +16 -1
  10. package/modules/localmodels/catalog.json +165 -50
  11. package/modules/localmodels/catalog.py +20 -5
  12. package/modules/localmodels/catalog_recipes.py +9 -1
  13. package/modules/localmodels/context_policy.py +32 -9
  14. package/modules/localmodels/deploy.py +20 -14
  15. package/modules/localmodels/engines-b12588-mix-c0c3de8.json +98 -0
  16. package/modules/localmodels/engines-strata-poly-0.1.45-poly.9.json +41 -1
  17. package/modules/localmodels/engines.py +28 -2
  18. package/modules/localmodels/estimator.py +12 -3
  19. package/modules/localmodels/gateway.py +50 -15
  20. package/modules/localmodels/gateway_accept.py +8 -5
  21. package/modules/localmodels/gateway_bifrost.py +108 -34
  22. package/modules/localmodels/gateway_cli.py +5 -2
  23. package/modules/localmodels/gateway_requests.py +9 -2
  24. package/modules/localmodels/gguf.py +6 -2
  25. package/modules/localmodels/harness.py +38 -11
  26. package/modules/localmodels/harness_gateway.py +1 -1
  27. package/modules/localmodels/harness_probe.py +60 -13
  28. package/modules/localmodels/hosts.py +7 -20
  29. package/modules/localmodels/library_gateway.py +12 -9
  30. package/modules/localmodels/library_pricing.py +7 -9
  31. package/modules/localmodels/library_state.py +6 -4
  32. package/modules/localmodels/npm_transport.py +62 -54
  33. package/modules/localmodels/probe.py +38 -11
  34. package/modules/localmodels/process_identity.py +47 -33
  35. package/modules/localmodels/process_identity_linux.py +135 -0
  36. package/modules/localmodels/process_windows.py +150 -1
  37. package/modules/localmodels/recommend.py +1 -1
  38. package/modules/localmodels/recommend_cli.py +2 -2
  39. package/modules/localmodels/remote_ops.py +14 -6
  40. package/modules/localmodels/remote_ops_download.py +1 -1
  41. package/modules/localmodels/remote_ops_verify.py +0 -33
  42. package/modules/localmodels/runtime_install.py +2 -1
  43. package/modules/localmodels/runtime_io.py +149 -34
  44. package/modules/localmodels/runtime_windows_acl.py +100 -0
  45. package/modules/localmodels/service_probe.py +26 -20
  46. package/modules/localmodels/setup_inspection.py +132 -36
  47. package/modules/localmodels/setup_text.py +14 -0
  48. package/modules/localmodels/source_byok.py +6 -3
  49. package/modules/localmodels/source_cli.py +8 -1
  50. package/modules/localmodels/stack.py +1 -5
  51. package/modules/localmodels/stack_args.py +6 -8
  52. package/modules/localmodels/stack_binding.py +61 -3
  53. package/modules/localmodels/stack_compose.py +3 -8
  54. package/modules/localmodels/stack_events.py +2 -1
  55. package/modules/localmodels/stack_lifecycle.py +7 -4
  56. package/modules/localmodels/stack_plan.py +1 -4
  57. package/modules/localmodels/stack_ports.py +0 -1
  58. package/modules/localmodels/stack_run.py +15 -30
  59. package/modules/localmodels/stack_suite.py +23 -46
  60. package/modules/localmodels/stack_summary.py +0 -1
  61. package/modules/localmodels/stack_try.py +3 -92
  62. package/modules/localmodels/stack_up.py +7 -3
  63. package/modules/localmodels/stack_update.py +5 -5
  64. package/modules/localmodels/stack_view_apply.py +1 -1
  65. package/modules/localmodels/stack_view_llm.py +1 -1
  66. package/modules/localmodels/stack_view_sandbox.py +3 -3
  67. package/modules/localmodels/stack_view_text.py +0 -1
  68. package/modules/localmodels/stack_view_words.py +0 -1
  69. package/modules/localmodels/stack_warm.py +18 -7
  70. package/modules/localmodels/strata_poly_server.py +4 -2
  71. package/modules/localmodels/suite.py +4 -7
  72. package/modules/localmodels/transport.py +7 -1
  73. package/modules/localmodels/tui_dialogs.py +0 -1
  74. package/modules/localmodels/web/view/view.css +0 -3
  75. package/modules/{simplex_localmodels-0.1.0.dev44.dist-info → simplex_localmodels-0.1.0.dev47.dist-info}/METADATA +1 -1
  76. package/modules/{simplex_localmodels-0.1.0.dev44.dist-info → simplex_localmodels-0.1.0.dev47.dist-info}/RECORD +78 -80
  77. package/package.json +1 -1
  78. package/tool.json +1 -1
  79. package/modules/localmodels/bifrost_search.py +0 -66
  80. package/modules/localmodels/gateway_search.py +0 -223
  81. package/modules/localmodels/search-ddgs-9.16.1.txt +0 -222
  82. package/modules/localmodels/search_server.py +0 -474
  83. /package/modules/{simplex_localmodels-0.1.0.dev44.dist-info → simplex_localmodels-0.1.0.dev47.dist-info}/WHEEL +0 -0
  84. /package/modules/{simplex_localmodels-0.1.0.dev44.dist-info → simplex_localmodels-0.1.0.dev47.dist-info}/entry_points.txt +0 -0
  85. /package/modules/{simplex_localmodels-0.1.0.dev44.dist-info → simplex_localmodels-0.1.0.dev47.dist-info}/licenses/NOTICE +0 -0
  86. /package/modules/{simplex_localmodels-0.1.0.dev44.dist-info → simplex_localmodels-0.1.0.dev47.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -0,0 +1,98 @@
1
+ {
2
+ "schema": "localmodels.engine-lock/v1",
3
+ "tag": "b12588-mix-c0c3de8",
4
+ "commit": "883286076efe5b85fddb31d9cc7035a6b698ba9b",
5
+ "source": "https://github.com/unslothai/llama.cpp/releases/tag/b12588-mix-c0c3de8",
6
+ "note": "Release asset digests from the GitHub release API and llama-prebuilt-sha256.json (unslothai/llama.cpp, upstream llama.cpp b12588, read 2026-11-21). Required for Inkling 2 Mini (inkling2 / inkling2_loop architecture, unsupported in b11370). Linux x64 CUDA 12 portable (CUDA 12.8, SM 70-120, Ubuntu 22.04) and Linux x64 CPU archives unpack flat with ./llama-server and import up to GLIBC_2.34 plus libgomp.so.1 (verified via ELF .gnu.version_r and dynamic NEEDED); note libggml-cuda.so links libcudart.so.12/libcublas.so.12/libcublasLt.so.12 dynamically and this release ships no separate cudart archive, so CUDA 13 portable is intentionally omitted here (cuda12-portable covers SM 70-120 across CUDA 12.8+ and 13.x drivers without requiring CUDA 13 runtime libraries). Windows x64 CUDA 12 portable and CPU zips unpack flat with llama-server.exe; macOS arm64 Metal tarball unpacks with a single top directory stripped by remote_ops.unpack.",
7
+ "builds": [
8
+ {
9
+ "platform": "linux",
10
+ "arch": "x64",
11
+ "backend": "cuda",
12
+ "min_cuda": "12.8",
13
+ "min_glibc": "2.34",
14
+ "host_libraries": {
15
+ "libgomp.so.1": "libgomp1"
16
+ },
17
+ "assets": [
18
+ {
19
+ "name": "app-b12588-mix-c0c3de8-linux-x64-cuda12-portable.tar.gz",
20
+ "url": "https://github.com/unslothai/llama.cpp/releases/download/b12588-mix-c0c3de8/app-b12588-mix-c0c3de8-linux-x64-cuda12-portable.tar.gz",
21
+ "sha256": "4c30d5e3b3d7242cf3f214977c09a0d06102c71a713c256749909dcafa9f5980",
22
+ "size_bytes": 471778328
23
+ }
24
+ ]
25
+ },
26
+ {
27
+ "platform": "linux",
28
+ "arch": "x64",
29
+ "backend": "cpu",
30
+ "min_glibc": "2.34",
31
+ "host_libraries": {
32
+ "libgomp.so.1": "libgomp1"
33
+ },
34
+ "assets": [
35
+ {
36
+ "name": "app-b12588-mix-c0c3de8-linux-x64-cpu.tar.gz",
37
+ "url": "https://github.com/unslothai/llama.cpp/releases/download/b12588-mix-c0c3de8/app-b12588-mix-c0c3de8-linux-x64-cpu.tar.gz",
38
+ "sha256": "511b22366fa879213eb7f91016d629cdfe0054537f1c3cf46346017d968e7947",
39
+ "size_bytes": 19091181,
40
+ "npm_copy": {
41
+ "package": "@simplexai/engine-app-b12588-mix-c0c3de8-linux-x64-cpu",
42
+ "version": "0.0.0-sha256-511b22366fa87921"
43
+ }
44
+ }
45
+ ]
46
+ },
47
+ {
48
+ "platform": "darwin",
49
+ "arch": "arm64",
50
+ "backend": "metal",
51
+ "assets": [
52
+ {
53
+ "name": "llama-b12588-mix-c0c3de8-bin-macos-arm64.tar.gz",
54
+ "url": "https://github.com/unslothai/llama.cpp/releases/download/b12588-mix-c0c3de8/llama-b12588-mix-c0c3de8-bin-macos-arm64.tar.gz",
55
+ "sha256": "229def18e27ed740ec4f3a6508f084b25630e08d8a87ada40b00622fc496ceb8",
56
+ "size_bytes": 13114900,
57
+ "npm_copy": {
58
+ "package": "@simplexai/engine-llama-b12588-mix-c0c3de8-bin-macos-arm64",
59
+ "version": "0.0.0-sha256-229def18e27ed740"
60
+ }
61
+ }
62
+ ]
63
+ },
64
+ {
65
+ "platform": "win32",
66
+ "arch": "x64",
67
+ "backend": "cuda",
68
+ "min_cuda": "12.8",
69
+ "binary": "llama-server.exe",
70
+ "assets": [
71
+ {
72
+ "name": "app-b12588-mix-c0c3de8-windows-x64-cuda12-portable.zip",
73
+ "url": "https://github.com/unslothai/llama.cpp/releases/download/b12588-mix-c0c3de8/app-b12588-mix-c0c3de8-windows-x64-cuda12-portable.zip",
74
+ "sha256": "3e7ebce596952a550a49e6f27560f6c26a5b6ba341bbea632fbcfeb43ae7d901",
75
+ "size_bytes": 467643864
76
+ }
77
+ ]
78
+ },
79
+ {
80
+ "platform": "win32",
81
+ "arch": "x64",
82
+ "backend": "cpu",
83
+ "binary": "llama-server.exe",
84
+ "assets": [
85
+ {
86
+ "name": "app-b12588-mix-c0c3de8-windows-x64-cpu.zip",
87
+ "url": "https://github.com/unslothai/llama.cpp/releases/download/b12588-mix-c0c3de8/app-b12588-mix-c0c3de8-windows-x64-cpu.zip",
88
+ "sha256": "d80f6d21cd9a4c0a953ff3a381391b8f6f5166ba094efa72054e87a9bba1f9ab",
89
+ "size_bytes": 21367159,
90
+ "npm_copy": {
91
+ "package": "@simplexai/engine-app-b12588-mix-c0c3de8-windows-x64-cpu",
92
+ "version": "0.0.0-sha256-d80f6d21cd9a4c0a"
93
+ }
94
+ }
95
+ ]
96
+ }
97
+ ]
98
+ }
@@ -3,7 +3,7 @@
3
3
  "tag": "strata-poly-0.1.45-poly.9",
4
4
  "commit": "v0.1.45-poly.9",
5
5
  "source": "https://github.com/simplexai-labs/PolyStrata/releases/tag/v0.1.45-poly.9",
6
- "note": "PolyStrata 0.1.45-poly.9 (MIT, commit 83a7a332), built by this project on 2026-11-11 because upstream publishes only a Windows engine. The engine archive holds the strata-poly binary, PolyStrata's Python server (serve/) and tokenizer tool (tools/) as released, their licenses and BUILD.json; the second archive holds the CUDA 13.0.3 runtime libraries the binary loads (libcublas, libcublasLt, libcudart), under NVIDIA's license. Both unpack into one directory, which the service puts on LD_LIBRARY_PATH. Built in nvidia/cuda:13.0.3-devel-ubuntu22.04 without a GPU, with upstream's Windows release flags: -DSTRATA_PORTABLE=ON (AVX2 CPU baseline) and CUDA architectures 75, 80, 86, 89 and 120 (RTX 20, 30, 40 and 50 series). Needs an NVIDIA driver for CUDA 13.0 (580 or newer), glibc 2.34 and libstdc++ 12 (Ubuntu 22.04, Debian 12 or newer). The picture reader (strata-vision) is not built. Sources: PolyStrata tag archive sha256 eeeb605b..., llama.cpp 3cf03257 archive sha256 cbe23c59... (the full digests are in BUILD.json).",
6
+ "note": "PolyStrata 0.1.45-poly.9 (MIT, commit 83a7a332), built by this project on 2026-11-11 because upstream publishes only a Windows engine. The engine archive holds the strata-poly binary, PolyStrata's Python server (serve/) and tokenizer tool (tools/) as released, their licenses and BUILD.json; the second archive holds the CUDA 13.0.3 runtime libraries the binary loads (libcublas, libcublasLt, libcudart), under NVIDIA's license. Both unpack into one directory, which the service puts on LD_LIBRARY_PATH. Built in nvidia/cuda:13.0.3-devel-ubuntu22.04 without a GPU, with upstream's Windows release flags: -DSTRATA_PORTABLE=ON (AVX2 CPU baseline) and CUDA architectures 75, 80, 86, 89 and 120 (RTX 20, 30, 40 and 50 series). Needs an NVIDIA driver for CUDA 13.0 (580 or newer), glibc 2.34 and libstdc++ 12 (Ubuntu 22.04, Debian 12 or newer). The picture reader (strata-vision) is not built. Sources: PolyStrata tag archive sha256 eeeb605b..., llama.cpp 3cf03257 archive sha256 cbe23c59... (the full digests are in BUILD.json). The Windows build is upstream's own release zip (strata-poly.exe, CUDA 13.0, the same CUDA architectures), which holds no server: the tag archive beside it supplies serve/ and tools/, and NVIDIA's cuBLAS 13.0.2.14 wheel (the version upstream's setup.py installs on Windows) supplies cublas64_13.dll under nvidia/cu13/bin/x86_64, the directory the recipes' lib_dirs put on the engine's PATH.",
7
7
  "builds": [
8
8
  {
9
9
  "platform": "linux",
@@ -30,6 +30,46 @@
30
30
  "size_bytes": 422462968
31
31
  }
32
32
  ]
33
+ },
34
+ {
35
+ "platform": "win32",
36
+ "arch": "x64",
37
+ "backend": "cuda",
38
+ "min_cuda": "13.0",
39
+ "binary": "strata-poly.exe",
40
+ "assets": [
41
+ {
42
+ "name": "strata-poly-windows-x64-66af087edd486c6d.zip",
43
+ "url": "https://github.com/simplexai-labs/PolyStrata/releases/download/v0.1.45-poly.9/strata-poly-windows-x64-66af087edd486c6d.zip",
44
+ "sha256": "68b344cc4cbaa4afedbe292d3b26ad778801de2ac9c2fbc0cff531b58e4bae92",
45
+ "size_bytes": 170179677,
46
+ "npm_copy": {
47
+ "package": "@simplexai/engine-strata-poly-windows-x64-66af087edd486c6d",
48
+ "version": "0.0.0-sha256-68b344cc4cbaa4af"
49
+ }
50
+ },
51
+ {
52
+ "name": "polystrata-0.1.45-poly.9-source.tar.gz",
53
+ "url": "https://github.com/simplexai-labs/PolyStrata/archive/refs/tags/v0.1.45-poly.9.tar.gz",
54
+ "sha256": "eeeb605b26e7e5d06bf4990b1ed14d2f0ae857d9bc304243593561cd740d5505",
55
+ "size_bytes": 25580808,
56
+ "members": [
57
+ "serve/",
58
+ "tools/",
59
+ "LICENSE"
60
+ ],
61
+ "npm_copy": {
62
+ "package": "@simplexai/engine-polystrata-0.1.45-poly.9-source",
63
+ "version": "0.0.0-sha256-eeeb605b26e7e5d0"
64
+ }
65
+ },
66
+ {
67
+ "name": "nvidia_cublas-13.0.2.14-py3-none-win_amd64.whl",
68
+ "url": "https://files.pythonhosted.org/packages/f3/91/bda39230b7a4c102bb724c21b50823efc63544490a885fea0b604911c0ab/nvidia_cublas-13.0.2.14-py3-none-win_amd64.whl",
69
+ "sha256": "5f7a90456b1392db60e28719547ba6e00696bfa81304b6887cf287f9edf2c1d7",
70
+ "size_bytes": 401887280
71
+ }
72
+ ]
33
73
  }
34
74
  ]
35
75
  }
@@ -33,6 +33,23 @@ class EngineUnavailableError(PlanError):
33
33
  """No pinned release build runs on this host; an engine already there may still."""
34
34
 
35
35
 
36
+ class CudaDriverError(PlanError):
37
+ """The host's NVIDIA driver supports too old a CUDA version, or none could be detected."""
38
+
39
+ def __init__(
40
+ self,
41
+ message: str,
42
+ *,
43
+ required_cuda: str,
44
+ detected_cuda: str = "",
45
+ driver_version: str = "",
46
+ ) -> None:
47
+ super().__init__(message)
48
+ self.required_cuda = required_cuda
49
+ self.detected_cuda = detected_cuda
50
+ self.driver_version = driver_version
51
+
52
+
36
53
  def _version(text: str | None) -> tuple[int, ...]:
37
54
  return tuple(int(x) for x in re.findall(r"\d+", text or "")[:2])
38
55
 
@@ -106,18 +123,27 @@ def select_engine_build(
106
123
  "host; this tool does not install system packages"
107
124
  )
108
125
  if not builds:
109
- detail = ""
110
126
  if backend == "cuda" and platform_builds:
111
127
  oldest = min((b["min_cuda"] for b in platform_builds), key=_cuda_tuple)
128
+ driver_version = ((facts.get("nvidia") or {}).get("driver_version") or "").strip()
112
129
  if driver == (0, 0):
113
130
  detail = f" (could not detect the driver's CUDA version; requires CUDA >= {oldest})"
131
+ detected = ""
114
132
  else:
115
133
  detail = (
116
134
  f" (the driver supports CUDA {driver_cuda}, "
117
135
  f"older than the required CUDA >= {oldest})"
118
136
  )
137
+ detected = driver_cuda
138
+ raise CudaDriverError(
139
+ f"no {lock['tag']} prebuilt engine for {platform}/{facts.get('arch')}/{backend}"
140
+ f"{detail}",
141
+ required_cuda=oldest,
142
+ detected_cuda=detected,
143
+ driver_version=driver_version,
144
+ )
119
145
  raise PlanError(
120
- f"no {lock['tag']} prebuilt engine for {platform}/{facts.get('arch')}/{backend}{detail}"
146
+ f"no {lock['tag']} prebuilt engine for {platform}/{facts.get('arch')}/{backend}"
121
147
  )
122
148
  return {"tag": lock["tag"], "commit": lock["commit"], **builds[0]}
123
149
 
@@ -65,7 +65,14 @@ _AGENT_BASE_BY_N_EMBD = (
65
65
  # unless an architecture was measured to grow faster. qwen35moe (Qwen3.6-35B-A3B, VP3 at
66
66
  # -ub 512, no MTP): the buffer rose 768.5 MiB from a 128K to a 384K window, 6.0 B each; the
67
67
  # 128K point then sits 205 MiB under this price, which keeps the estimate above both.
68
- _AGENT_WINDOW_COMPUTE_BYTES = {"qwen35moe": 6}
68
+ # inkling2 (Inkling-2-Mini looped MoE, b12588-mix-c0c3de8 CUDA vram-phase1-2.csv + Mac Metal -lv 4):
69
+ # its compute buffer has both a ubatch-scaled term (92 B/tok/ub) and a window-linear term
70
+ # (11,264 B/tok below), matching 128K/-ub 128 (3,297 MiB vs 3,276 MiB Metal / 3,211 MiB CUDA;
71
+ # UD-Q4_K_M + GPU mmproj = 21.97 GiB), 128K/-ub 256 (4,769 MiB vs 4,748 MiB CUDA / 4,714 MiB
72
+ # Metal; UD-Q4_K_M + GPU mmproj = 23.41 GiB vs 24,024 MiB CUDA peak, exceeding the 23,552 MiB
73
+ # 24 GB gate), and 200K/-ub 256 (7,058 MiB vs 7,211 MiB CUDA).
74
+ _AGENT_WINDOW_COMPUTE_BYTES = {"qwen35moe": 6, "inkling2": 92}
75
+ _AGENT_WINDOW_LINEAR_COMPUTE_BYTES = {"inkling2": 11264}
69
76
  # Launch budget = the card's live free memory minus this safety reserve: VP1's headless-card
70
77
  # driver retention plus slack for allocator variation (06 §1.1); replaces the max(2 GiB, 9%)
71
78
  # capacity margin the generic path keeps.
@@ -103,7 +110,7 @@ _KV_DTYPE_BYTES_PER_ELEM = {"f16": 2.0, "q8_0": 34 / 32, "q4_0": 18 / 32}
103
110
  # measured on b11370 with the router's unified KV (every slot sees the full window), device plus
104
111
  # host buffers, target and MTP head contexts alike (39.5 + 6.1 B; 5.9 GiB per context at 256K and
105
112
  # -ub 512, ~23 GiB at -ub 2048).
106
- _WINDOW_COMPUTE_BYTES = {"qwen4exp": 46}
113
+ _WINDOW_COMPUTE_BYTES = {"qwen4exp": 46, "inkling2": 180}
107
114
 
108
115
 
109
116
  class LayerKind(Enum):
@@ -471,6 +478,7 @@ def agent_footprint_parts(
471
478
  """``agent_footprint_bytes`` split into its FOOTPRINT_PARTS, for a view that shows where
472
479
  the card's memory goes; the parts sum to exactly that footprint."""
473
480
  per_window_token = _AGENT_WINDOW_COMPUTE_BYTES.get(profile.architecture, _F16_BYTES_PER_ELEM)
481
+ linear_per_window_token = _AGENT_WINDOW_LINEAR_COMPUTE_BYTES.get(profile.architecture, 0)
474
482
  host_side = 0 if profile.tied_embeddings else profile.embd_table_bytes
475
483
  # Without MTP the nextn block is never loaded; with it, it is, and the draft context too.
476
484
  weights_gpu = max(
@@ -481,7 +489,8 @@ def agent_footprint_parts(
481
489
  "kv": kv_pool_bytes(profile, window, kv_types),
482
490
  "state": recurrent_state_bytes(profile, slots=slots),
483
491
  "compute": int(
484
- _agent_compute_base_bytes(profile.n_embd) + window * ubatch * per_window_token
492
+ _agent_compute_base_bytes(profile.n_embd)
493
+ + window * (linear_per_window_token + ubatch * per_window_token)
485
494
  ),
486
495
  "draft": mtp_draft_bytes(profile, window, slots=slots) if mtp else 0,
487
496
  "process": AGENT_PROCESS_OVERHEAD_BYTES,
@@ -8,6 +8,7 @@ from __future__ import annotations
8
8
  import http.client
9
9
  import json
10
10
  import os
11
+ import re
11
12
  import secrets
12
13
  import shutil
13
14
  import subprocess
@@ -15,7 +16,7 @@ import time
15
16
  from collections.abc import Callable
16
17
  from http.cookies import SimpleCookie
17
18
  from pathlib import Path
18
- from typing import TypedDict
19
+ from typing import Literal, TypedDict
19
20
 
20
21
  from localmodels import (
21
22
  gateway_accept,
@@ -34,12 +35,8 @@ from localmodels import (
34
35
  from localmodels.contracts import decode
35
36
  from localmodels.gateway_requests import PI_ACCEPT_FLAGS as PI_ACCEPT_FLAGS
36
37
  from localmodels.gateway_requests import AuxEndpoint as AuxEndpoint
38
+ from localmodels.gateway_requests import Check as Check
37
39
  from localmodels.gateway_requests import post as _post
38
- from localmodels.gateway_search import SEARCH as SEARCH
39
- from localmodels.gateway_search import Check as Check
40
- from localmodels.gateway_search import search_url as search_url
41
- from localmodels.gateway_search import unwire as unwire_search
42
- from localmodels.gateway_search import wire_search
43
40
  from localmodels.harness import (
44
41
  Endpoint,
45
42
  GatewayPlan,
@@ -69,7 +66,7 @@ AUX_PROVIDERS = {
69
66
  "rerank": "localmodels-rerank",
70
67
  "stt": "localmodels-stt",
71
68
  }
72
- WIRED = (*AUX_PROVIDERS, SEARCH)
69
+ WIRED = tuple(AUX_PROVIDERS)
73
70
  FOUNDATION_PROVIDERS = {
74
71
  AUX_PROVIDERS["embedding"],
75
72
  AUX_PROVIDERS["rerank"],
@@ -410,13 +407,6 @@ def wire(
410
407
  )
411
408
  hosts.own_gateway(tools_dir, "rule", gw["intent"])
412
409
  done.append(f"rule intent → {llm_model}:{hard} (classifier {classifier})")
413
- for ep in aux:
414
- if ep["contract"] == SEARCH:
415
- try:
416
- done += wire_search(plan, search_url(ep))
417
- except HarnessError as exc: # acceptance's search check reports it as failed
418
- done.append(f"search not wired: {exc}")
419
-
420
410
  if select_pi:
421
411
  done.append(point_pi(plan, gw["pi_model_before"], f"group/{gw['group']}"))
422
412
  done += gateway_clients.wire(plan)
@@ -565,10 +555,55 @@ def _unwire_magpie(
565
555
  gone = _magpie(target, "provider", pid, timeout=20).returncode != 0
566
556
  if gone or run(f"provider rm {pid}", "provider", "rm", pid):
567
557
  hosts.own_listed(tools_dir, "providers", pid, False)
568
- results += unwire_search(target, gw.get("search"), bool(gw.get("search_you")), tools_dir)
558
+ results += _unwire_search(target, gw.get("search"), bool(gw.get("search_you")), tools_dir)
569
559
  return results + gateway_keys.remove(target, caller_keys, tools_dir)
570
560
 
571
561
 
562
+ def _search_apis(plan: ToolPlan) -> dict[str, str]:
563
+ """Magpie's search APIs as {api: URL}. ``magpie search`` lists one per line, as
564
+ ``N. SearXNG no key <url> [off]`` or ``N. You.com no key``; the api is the name's first
565
+ word in lower case (``you``)."""
566
+ out = _magpie(plan, "search", timeout=20)
567
+ if out.returncode != 0:
568
+ raise HarnessError(f"magpie search failed (exit {out.returncode})")
569
+ found: dict[str, str] = {}
570
+ for line in out.stdout.splitlines():
571
+ match = re.match(r"\s*\d+\.\s+(\S+)(.*)$", line)
572
+ if match:
573
+ url = next((w for w in match.group(2).split() if w.startswith("http")), "")
574
+ found[match.group(1).split(".")[0].lower()] = url
575
+ return found
576
+
577
+
578
+ def _unwire_search(plan: ToolPlan, url: str | None, you: bool, tools_dir: str) -> list[Check]:
579
+ """Take out the searxng and You.com search APIs the manifest says this tool added to Magpie
580
+ for the web search service the stack used to run. A searxng someone has pointed elsewhere
581
+ since is theirs now, and only the manifest forgets it."""
582
+ if not (url or you):
583
+ return []
584
+ try:
585
+ listed = _search_apis(plan)
586
+ except HarnessError as exc:
587
+ return [{"check": "search rm", "ok": False, "detail": str(exc)}]
588
+ entries: list[tuple[str, bool, Literal["search", "search_you"]]] = []
589
+ if url:
590
+ entries.append(("searxng", listed.get("searxng") == url, "search"))
591
+ if you:
592
+ entries.append(("you", "you" in listed, "search_you"))
593
+ checks: list[Check] = []
594
+ for api, ours, field in entries:
595
+ if ours:
596
+ out = _magpie(plan, "search", "rm", api, timeout=60)
597
+ detail = " ".join((out.stdout + out.stderr).split())[-200:]
598
+ checks.append(
599
+ {"check": f"search rm {api}", "ok": out.returncode == 0, "detail": detail}
600
+ )
601
+ if out.returncode != 0:
602
+ continue
603
+ hosts.forget_search(tools_dir, field)
604
+ return checks
605
+
606
+
572
607
  # ---------------------------------------------------------------------------- acceptance
573
608
 
574
609
 
@@ -14,8 +14,14 @@ from typing import Any
14
14
 
15
15
  from localmodels import gateway_clients, harness, harness_gateway
16
16
  from localmodels.contracts import decode
17
- from localmodels.gateway_requests import PI_ACCEPT_FLAGS, AuxEndpoint, aux_answer, post, text
18
- from localmodels.gateway_search import SEARCH, Check, search_checks, search_url
17
+ from localmodels.gateway_requests import (
18
+ PI_ACCEPT_FLAGS,
19
+ AuxEndpoint,
20
+ Check,
21
+ aux_answer,
22
+ post,
23
+ text,
24
+ )
19
25
  from localmodels.harness import HarnessPlan, ToolPlan
20
26
  from localmodels.remote_ops import DECISION_QUESTION, DECISION_STATE, TOUCH_EXPECT, TOUCH_PROMPT
21
27
 
@@ -158,9 +164,6 @@ def accept(
158
164
  f"Magpie routing calls to {decider}: {before} → {after}",
159
165
  )
160
166
  for ep in aux:
161
- if ep["contract"] == SEARCH:
162
- checks += search_checks(plan, search_url(ep), timeout)
163
- continue
164
167
  pid = aux_providers[ep["contract"]]
165
168
  name = f"gateway {ep['contract']} {pid}/{ep['model']}"
166
169
  before = calls_fn(plan, pid, None)
@@ -7,6 +7,7 @@ import os
7
7
  import secrets
8
8
  import shutil
9
9
  import subprocess
10
+ import sys
10
11
  import time
11
12
  import urllib.error
12
13
  import urllib.parse
@@ -17,7 +18,6 @@ from typing import Any
17
18
 
18
19
  from localmodels import (
19
20
  bifrost_datasheet,
20
- bifrost_search,
21
21
  bifrost_unit,
22
22
  gateway_home,
23
23
  gateway_keys,
@@ -43,8 +43,7 @@ from localmodels.bifrost_config import render_config as render_config
43
43
  from localmodels.bifrost_config import write_config as write_config
44
44
  from localmodels.bifrost_provider import origin as origin
45
45
  from localmodels.bifrost_unit import unit, unit_file, unit_for
46
- from localmodels.gateway_requests import AuxEndpoint
47
- from localmodels.gateway_search import Check
46
+ from localmodels.gateway_requests import AuxEndpoint, Check
48
47
  from localmodels.harness import (
49
48
  HarnessError,
50
49
  HarnessPlan,
@@ -53,6 +52,7 @@ from localmodels.harness import (
53
52
  ToolPlan,
54
53
  ToolState,
55
54
  )
55
+ from localmodels.runtime_io import Event
56
56
 
57
57
  _write_config = write_config
58
58
 
@@ -167,8 +167,14 @@ def adopt(
167
167
  seen["files"] = stack_clients.config_files(name, environment)
168
168
 
169
169
 
170
- def install_binary(tools_dir: Path, action: ToolAction, log: Callable[[str], None]) -> str | None:
171
- """Put the pinned binary at its planned path; returns its directory when this call made it."""
170
+ def install_binary(
171
+ tools_dir: Path,
172
+ action: ToolAction,
173
+ log: Callable[[str], None],
174
+ event: Event = lambda _: None,
175
+ ) -> str | None:
176
+ """Put the pinned binary at its planned path; returns its directory when this call made it.
177
+ ``event`` receives its download events."""
172
178
  target = Path(os.path.expanduser(action["path"]))
173
179
  artifact = action["artifacts"][0]
174
180
  if target.exists():
@@ -176,7 +182,7 @@ def install_binary(tools_dir: Path, action: ToolAction, log: Callable[[str], Non
176
182
  log(f"Bifrost {action['version']} already at {target}, reused")
177
183
  return None
178
184
  raise HarnessError(f"{target} exists and is not the pinned version; not overwritten")
179
- archive = harness._fetch(tools_dir, artifact, log)
185
+ archive = harness._fetch(tools_dir, artifact, log, event)
180
186
  target.parent.mkdir(parents=True, exist_ok=True)
181
187
  staging = target.with_name(f".{target.name}.tmp")
182
188
  staging.unlink(missing_ok=True)
@@ -233,6 +239,23 @@ def opener() -> urllib.request.OpenerDirector:
233
239
  return http_local.no_proxy_opener()
234
240
 
235
241
 
242
+ def _argv(record: hosts.OwnedBifrost) -> list[str]:
243
+ host, _, port = record["addr"].rpartition(":")
244
+ return [
245
+ record["binary"],
246
+ "-app-dir",
247
+ str(Path(record["app_dir"])),
248
+ "-host",
249
+ host,
250
+ "-port",
251
+ port,
252
+ "-log-style",
253
+ "json",
254
+ "-log-level",
255
+ "warn",
256
+ ]
257
+
258
+
236
259
  def owned_listener(record: hosts.OwnedBifrost) -> bool:
237
260
  """Prove this existing receipt's exact process and listener before sending requests."""
238
261
  try:
@@ -255,24 +278,10 @@ def owned_listener(record: hosts.OwnedBifrost) -> bool:
255
278
  if pid <= 1:
256
279
  return False
257
280
  before = process_identity.inspect(pid)
258
- host, _, port = addr.rpartition(":")
259
- argv = [
260
- record["binary"],
261
- "-app-dir",
262
- str(app),
263
- "-host",
264
- host,
265
- "-port",
266
- port,
267
- "-log-style",
268
- "json",
269
- "-log-level",
270
- "warn",
271
- ]
272
281
  return bool(
273
282
  before
274
283
  and before["uid"] == process_identity.current_uid()
275
- and remote_ops_service.command_matches(pid, argv)
284
+ and remote_ops_service.command_matches(pid, _argv(record))
276
285
  and remote_ops_service.listener_problem(harness_gateway.address_port(addr), [pid])
277
286
  is None
278
287
  and process_identity.inspect(pid) == before
@@ -318,9 +327,18 @@ def healthy(addr: str, timeout: float = 5) -> bool:
318
327
 
319
328
  def _await(addr: str, timeout: float = HEALTH_TIMEOUT_S, *, record: hosts.OwnedBifrost) -> None:
320
329
  deadline = time.monotonic() + timeout
330
+ pid_file = Path(record["app_dir"]) / "bifrost.pid"
321
331
  while time.monotonic() < deadline:
322
332
  if _healthy_owned(record):
323
333
  return
334
+ if (
335
+ record["how"] != "unit"
336
+ and os.path.lexists(pid_file)
337
+ and process_identity.status(pid_file)[0] == "inactive"
338
+ ):
339
+ raise HarnessError(
340
+ f"Bifrost {addr} exited before becoming ready; see {APP_DIR}/bifrost.log"
341
+ )
324
342
  time.sleep(1)
325
343
  raise HarnessError(f"Bifrost {addr} not ready in {int(timeout)} s; see {APP_DIR}/bifrost.log")
326
344
 
@@ -379,8 +397,7 @@ def _start(record: hosts.OwnedBifrost, restart: bool) -> None:
379
397
  return
380
398
  if not restart and _healthy_owned(record):
381
399
  return
382
- _stop_serve(app) # ours: restarted, or an earlier instance that stopped answering
383
- host, _, port = addr.rpartition(":")
400
+ _stop_owned_serve(record) # ours: restarted, or an earlier instance that stopped answering
384
401
  env = {**os.environ, "NO_PROXY": "127.0.0.1,localhost", "no_proxy": "127.0.0.1,localhost"}
385
402
  options: dict[str, Any] = {"cwd": app, "env": env, "stdin": subprocess.DEVNULL}
386
403
  if os.name != "nt":
@@ -389,8 +406,7 @@ def _start(record: hosts.OwnedBifrost, restart: bool) -> None:
389
406
  # Its own session; on Windows also no console, out of the starting job (a scheduled
390
407
  # task ends its job's processes), at normal priority, as every service this tool runs.
391
408
  proc = process_identity.spawn_detached(
392
- [record["binary"], "-app-dir", str(app), "-host", host, "-port", port]
393
- + ["-log-style", "json", "-log-level", "warn"],
409
+ _argv(record),
394
410
  stdout=log,
395
411
  stderr=log,
396
412
  **options,
@@ -404,12 +420,74 @@ def _start(record: hosts.OwnedBifrost, restart: bool) -> None:
404
420
  raise HarnessError(f"cannot record Bifrost process identity ({exc}); stopped it") from None
405
421
 
406
422
 
423
+ def _orphaned_serve_pid(
424
+ record: hosts.OwnedBifrost,
425
+ ) -> tuple[int, process_identity.Identity] | None:
426
+ """Find a live Bifrost whose receipt was lost (for example deleted after an earlier
427
+ ``lstart`` drift), proven to belong to ``record`` by exclusive port ownership, UID, PGID,
428
+ and exact command line including ``app_dir``."""
429
+ if record["how"] == "unit" or sys.platform == "win32":
430
+ return None
431
+ try:
432
+ port = harness_gateway.address_port(record["addr"])
433
+ owners = harness_probe.loopback_listener_pids(port)
434
+ if not owners or len(owners) != 1:
435
+ return None
436
+ pid = next(iter(owners))
437
+ before = process_identity.inspect(pid)
438
+ if (
439
+ before is None
440
+ or before["uid"] != process_identity.current_uid()
441
+ or before["pgid"] != pid
442
+ or not remote_ops_service.command_matches(pid, _argv(record))
443
+ or remote_ops_service.listener_problem(port, [pid]) is not None
444
+ or process_identity.inspect(pid) != before
445
+ ):
446
+ return None
447
+ return pid, before
448
+ except (OSError, ValueError, RuntimeError, subprocess.SubprocessError):
449
+ return None
450
+
451
+
452
+ def _stop_orphaned_serve(record: hosts.OwnedBifrost) -> None:
453
+ orphan = _orphaned_serve_pid(record)
454
+ if orphan is None:
455
+ return
456
+ pid, before = orphan
457
+ app = Path(record["app_dir"])
458
+ pid_file = app / "bifrost.pid"
459
+ try:
460
+ process_identity.save(pid_file, pid)
461
+ if process_identity.inspect(pid) != before:
462
+ for path in (pid_file, Path(f"{pid_file}.identity.json")):
463
+ path.unlink(missing_ok=True)
464
+ return
465
+ except (OSError, RuntimeError, subprocess.SubprocessError):
466
+ return
467
+ try:
468
+ process_identity.stop(pid_file)
469
+ except RuntimeError as exc:
470
+ raise HarnessError(f"Bifrost {exc}; process and config kept, rerun once resolved") from None
471
+
472
+
473
+ def _stop_owned_serve(record: hosts.OwnedBifrost) -> None:
474
+ app = Path(record["app_dir"])
475
+ _stop_serve(app)
476
+ if not os.path.lexists(app / "bifrost.pid"):
477
+ _stop_orphaned_serve(record)
478
+
479
+
407
480
  def _stop_serve(app: Path) -> None:
408
481
  """Only the process group the identity receipt proves is ours; anything else is kept."""
409
482
  try:
410
- process_identity.stop(app / "bifrost.pid")
483
+ outcome = process_identity.stop(app / "bifrost.pid")
411
484
  except RuntimeError as exc:
412
485
  raise HarnessError(f"Bifrost {exc}; process and config kept, rerun once resolved") from None
486
+ if outcome == "none":
487
+ with contextlib.suppress(OSError, ValueError):
488
+ record = hosts.load_owned()["gateway"].get("bifrost")
489
+ if record and Path(record["app_dir"]) == app:
490
+ _stop_orphaned_serve(record)
413
491
 
414
492
 
415
493
  def pause(record: hosts.OwnedBifrost) -> str:
@@ -430,7 +508,7 @@ def _retire(record: hosts.OwnedBifrost) -> None:
430
508
  if _systemctl("stop", f"{name}.service").returncode != 0:
431
509
  raise HarnessError(f"systemctl --user stop {name} failed; the earlier Bifrost kept")
432
510
  return
433
- _stop_serve(Path(record["app_dir"]))
511
+ _stop_owned_serve(record)
434
512
 
435
513
 
436
514
  def ensure(plan: ToolPlan) -> str:
@@ -476,7 +554,7 @@ def wire(
476
554
  ) -> list[str]:
477
555
  """Write the plan's config, (re)start the instance when it changed and point pi and the
478
556
  native clients at ``localmodels-agent``. A re-sync (``select_pi=False``) changes only the
479
- gateway, and keeps the providers it does not manage and the search it injects."""
557
+ gateway, and keeps the providers it does not manage."""
480
558
  gw = plan["gateway"]
481
559
  record = require_target(plan) or _record(plan, _gateway(plan)["action"])
482
560
  app = Path(record["app_dir"])
@@ -489,10 +567,9 @@ def wire(
489
567
  *AUX_PROVIDERS.values(),
490
568
  }
491
569
  managed -= {AUX_PROVIDERS["stt"]}
492
- current = (written := read_config(app)).get("providers")
570
+ current = read_config(app).get("providers")
493
571
  if isinstance(current, dict):
494
572
  keep = {k: v for k, v in current.items() if k not in managed}
495
- aux = bifrost_search.kept(aux, written)
496
573
  fast_key = None
497
574
  if gw.get("llm_fast"):
498
575
  try:
@@ -504,9 +581,6 @@ def wire(
504
581
  config = render(
505
582
  gw, llm_key, decision_key, aux, app, admin_password(app), keep, fast_key=fast_key
506
583
  )
507
- bifrost_search.inject(config, gw["llm_provider"], aux)
508
- if gw.get("llm_fast"):
509
- bifrost_search.inject(config, FAST_PROVIDER, aux)
510
584
  names = (gw["llm"]["model"], AGENT_MODEL)
511
585
  sheets = bifrost_datasheet.sheets(gw["llm_provider"], names, gw.get("context"))
512
586
  if fast := gw.get("llm_fast"):
@@ -563,7 +637,7 @@ def stop(tools_dir: str = hosts.TOOLS_DIR) -> Check:
563
637
  return {"check": "bifrost", "ok": False, "detail": str(exc)}
564
638
  else:
565
639
  try:
566
- _stop_serve(app)
640
+ _stop_owned_serve(record)
567
641
  except HarnessError as exc:
568
642
  return {"check": "bifrost", "ok": False, "detail": str(exc)}
569
643
  for name in ("config.json", *bifrost_datasheet.FILES, *STORE, "admin-password"):