@simplexai/localmodels-win32-x64 0.1.0-dev.58 → 0.1.0-dev.60

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 (113) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +105 -98
  3. package/modules/localmodels/__init__.py +1 -1
  4. package/modules/localmodels/__main__.py +104 -43
  5. package/modules/localmodels/app.py +1 -1
  6. package/modules/localmodels/apple_sensors.py +431 -0
  7. package/modules/localmodels/bifrost_admin.py +83 -8
  8. package/modules/localmodels/bifrost_checks.py +2 -2
  9. package/modules/localmodels/bifrost_config.py +235 -13
  10. package/modules/localmodels/bifrost_log.py +166 -0
  11. package/modules/localmodels/bifrost_models.py +1 -1
  12. package/modules/localmodels/budget.py +1 -1
  13. package/modules/localmodels/catalog.json +192 -77
  14. package/modules/localmodels/catalog.py +20 -3
  15. package/modules/localmodels/catalog_add.py +42 -11
  16. package/modules/localmodels/custom_hub.py +983 -0
  17. package/modules/localmodels/custom_hub_http.py +579 -0
  18. package/modules/localmodels/custom_probe.py +451 -0
  19. package/modules/localmodels/deploy.py +27 -5
  20. package/modules/localmodels/deploy_steps.py +5 -0
  21. package/modules/localmodels/download-mirrors.json +8 -0
  22. package/modules/localmodels/engines-prism-b12178-03ec600.json +131 -0
  23. package/modules/localmodels/engines-strata-poly-0.2.20-poly.6.json +94 -0
  24. package/modules/localmodels/engines.py +38 -8
  25. package/modules/localmodels/estimator.py +60 -7
  26. package/modules/localmodels/frontend.py +26 -21
  27. package/modules/localmodels/gateway.py +48 -3
  28. package/modules/localmodels/gateway_app_bifrost.py +4 -4
  29. package/modules/localmodels/gateway_bifrost.py +128 -21
  30. package/modules/localmodels/gguf.py +6 -0
  31. package/modules/localmodels/host_sensors.py +704 -0
  32. package/modules/localmodels/hosts.py +99 -12
  33. package/modules/localmodels/library_cli.py +181 -3
  34. package/modules/localmodels/library_convert.py +34 -0
  35. package/modules/localmodels/library_custom.py +831 -0
  36. package/modules/localmodels/library_elastic.py +182 -127
  37. package/modules/localmodels/library_gateway.py +193 -40
  38. package/modules/localmodels/library_jobs.py +92 -18
  39. package/modules/localmodels/library_kept.py +50 -6
  40. package/modules/localmodels/library_model.py +254 -2
  41. package/modules/localmodels/library_pricing.py +97 -8
  42. package/modules/localmodels/library_serve.py +196 -66
  43. package/modules/localmodels/library_smoke.py +315 -0
  44. package/modules/localmodels/library_state.py +81 -2
  45. package/modules/localmodels/library_status.py +144 -8
  46. package/modules/localmodels/metal.py +1 -1
  47. package/modules/localmodels/metal_probe.py +4 -4
  48. package/modules/localmodels/nvml_ctypes.py +431 -0
  49. package/modules/localmodels/plan_envelope.py +18 -7
  50. package/modules/localmodels/process_identity_linux.py +39 -0
  51. package/modules/localmodels/records.py +1 -0
  52. package/modules/localmodels/remote_ops.py +57 -8
  53. package/modules/localmodels/remote_ops_download.py +205 -53
  54. package/modules/localmodels/remote_ops_mirrors.py +43 -2
  55. package/modules/localmodels/remote_ops_ranges.py +2 -5
  56. package/modules/localmodels/remote_ops_service.py +95 -37
  57. package/modules/localmodels/remote_ops_verify.py +22 -5
  58. package/modules/localmodels/runtime-lock.json +19 -19
  59. package/modules/localmodels/runtime_auth.py +4 -1
  60. package/modules/localmodels/service_control.py +32 -1
  61. package/modules/localmodels/service_wiring.py +237 -12
  62. package/modules/localmodels/service_worker.py +6 -2
  63. package/modules/localmodels/services_cli.py +35 -27
  64. package/modules/localmodels/setup_inspection.py +47 -70
  65. package/modules/localmodels/setup_inspection_harness.py +159 -15
  66. package/modules/localmodels/setup_text.py +14 -0
  67. package/modules/localmodels/setup_upgrade.py +1 -1
  68. package/modules/localmodels/source_byok.py +9 -7
  69. package/modules/localmodels/source_byok_probe.py +6 -1
  70. package/modules/localmodels/stack.py +9 -1
  71. package/modules/localmodels/stack_binding.py +3 -35
  72. package/modules/localmodels/stack_cleanup.py +4 -0
  73. package/modules/localmodels/stack_compose.py +18 -2
  74. package/modules/localmodels/stack_lifecycle.py +26 -3
  75. package/modules/localmodels/stack_memory.py +1 -0
  76. package/modules/localmodels/stack_plan.py +6 -2
  77. package/modules/localmodels/stack_ports.py +2 -0
  78. package/modules/localmodels/stack_remove.py +10 -1
  79. package/modules/localmodels/stack_up.py +33 -7
  80. package/modules/localmodels/stack_update.py +3 -1
  81. package/modules/localmodels/stack_view.py +77 -53
  82. package/modules/localmodels/stack_view_demo.py +36 -5
  83. package/modules/localmodels/stack_view_events.py +147 -12
  84. package/modules/localmodels/stack_view_gpu.py +97 -17
  85. package/modules/localmodels/stack_view_llm.py +15 -0
  86. package/modules/localmodels/stack_view_measure.py +4 -1
  87. package/modules/localmodels/stack_view_schema.py +54 -8
  88. package/modules/localmodels/stack_view_serve.py +40 -3
  89. package/modules/localmodels/stack_view_slots.py +89 -10
  90. package/modules/localmodels/stack_view_telemetry.py +163 -0
  91. package/modules/localmodels/stack_view_text.py +5 -2
  92. package/modules/localmodels/stack_view_tick.py +658 -0
  93. package/modules/localmodels/stack_view_words.py +4 -0
  94. package/modules/localmodels/{strata-poly-serve-0.2.19-poly.1.txt → strata-poly-serve-0.2.20-poly.6.txt} +1 -1
  95. package/modules/localmodels/suite.py +45 -27
  96. package/modules/localmodels/telemetry_math.py +538 -0
  97. package/modules/localmodels/transport.py +13 -2
  98. package/modules/localmodels/web/view/view.js +1 -1
  99. package/modules/{simplex_localmodels-0.1.0.dev58.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/METADATA +1 -1
  100. package/modules/{simplex_localmodels-0.1.0.dev58.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/RECORD +102 -95
  101. package/package.json +1 -1
  102. package/tool.json +1 -1
  103. package/modules/localmodels/bifrost_datasheet.py +0 -53
  104. package/modules/localmodels/bifrost_provider.py +0 -88
  105. package/modules/localmodels/bifrost_unit.py +0 -99
  106. package/modules/localmodels/engines-strata-poly-0.2.19-poly.1.json +0 -79
  107. package/modules/localmodels/gateway_switch.py +0 -51
  108. package/modules/localmodels/library_floor.py +0 -78
  109. package/modules/localmodels/service_stop.py +0 -52
  110. /package/modules/{simplex_localmodels-0.1.0.dev58.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/WHEEL +0 -0
  111. /package/modules/{simplex_localmodels-0.1.0.dev58.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/entry_points.txt +0 -0
  112. /package/modules/{simplex_localmodels-0.1.0.dev58.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/licenses/NOTICE +0 -0
  113. /package/modules/{simplex_localmodels-0.1.0.dev58.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -249,14 +249,33 @@ def load_facts(dev_id: str) -> HostFacts | None:
249
249
  return _read(state_dir() / "facts" / f"{dev_id}.json", None, lambda v: decode(v, HostFacts))
250
250
 
251
251
 
252
+ def _same_place(a: str, b: str) -> bool:
253
+ def norm(path: str) -> str:
254
+ return os.path.normcase(os.path.realpath(os.path.expanduser(path)))
255
+
256
+ return norm(a) == norm(b)
257
+
258
+
259
+ def _record_touched_service(record: FinishedRecord) -> bool:
260
+ """True when a deployment succeeded or got far enough that it may have installed or started
261
+ service files on this computer. A deploy that failed before ``install`` succeeded (for
262
+ example, refused on a port or unit conflict) created no owned service."""
263
+ if record["ok"]:
264
+ return True
265
+ steps = record.get("steps") or []
266
+ if not steps:
267
+ return True
268
+ return any(step["step"] in ("install", "start", "verify") and step["ok"] for step in steps)
269
+
270
+
252
271
  def save_record(dev_id: str, record: FinishedRecord) -> Path:
253
- """Keep the record; a deployment on this computer also enters the owned manifest, so
254
- ``stack remove`` can find every unit, directory and model file it created."""
272
+ """Keep the record; a deployment on this computer also enters the owned manifest when it
273
+ succeeded or installed service files, without overwriting another live deployment."""
255
274
  plan = record["plan"]
256
275
  path = state_dir() / "deployments" / dev_id / f"{plan['name']}.json"
257
276
  _write(path, record)
258
- if dev_id == LOCAL_ID:
259
- own_deployment(plan)
277
+ if dev_id == LOCAL_ID and _record_touched_service(record):
278
+ own_deployment(plan, ok=record["ok"])
260
279
  return path
261
280
 
262
281
 
@@ -272,8 +291,20 @@ def records(dev_id: str) -> list[FinishedRecord]:
272
291
 
273
292
 
274
293
  def deployment_dirs(dev_id: str) -> dict[str, str]:
275
- """Each recorded deployment's name and directory: which names are already in use, and where."""
276
- return {r["plan"]["name"]: r["plan"]["service"]["deploy_dir"] for r in records(dev_id)}
294
+ """Each recorded deployment's name and directory: which names are already in use, and where.
295
+ On this computer the shared owned manifest is included too so independent controllers with
296
+ separate state directories do not collide on one deployment name."""
297
+ taken = {r["plan"]["name"]: r["plan"]["service"]["deploy_dir"] for r in records(dev_id)}
298
+ if dev_id == LOCAL_ID and owned_path().is_file():
299
+ try:
300
+ for name, entry in load_owned()["deployments"].items():
301
+ if entry["removed"] or entry.get("failed"):
302
+ continue
303
+ if name not in taken or not _same_place(taken[name], entry["deploy_dir"]):
304
+ taken[name] = entry["deploy_dir"]
305
+ except (OSError, ValueError):
306
+ pass
307
+ return taken
277
308
 
278
309
 
279
310
  def record(dev_id: str, name: str) -> FinishedRecord:
@@ -287,22 +318,33 @@ def record(dev_id: str, name: str) -> FinishedRecord:
287
318
  return hit
288
319
 
289
320
 
290
- def delete_record(dev_id: str, name: str, *, purged: bool = False) -> None:
321
+ def delete_record(
322
+ dev_id: str, name: str, *, purged: bool = False, deploy_dir: str | None = None
323
+ ) -> None:
291
324
  """Forget a removed deployment. On this computer the owned manifest keeps it as removed, its
292
- files and log left for a purge, or drops it when ``purged``: whichever front end removed it."""
325
+ files and log left for a purge, or drops it when ``purged`` — only when the manifest entry
326
+ belongs to this deployment's directory, never another controller's."""
293
327
  path = state_dir() / "deployments" / dev_id / f"{name}.json"
328
+ recorded_dir = deploy_dir
329
+ if recorded_dir is None and path.is_file():
330
+ existing = _read(path, None, lambda v: decode(v, FinishedRecord))
331
+ if existing is not None:
332
+ recorded_dir = existing["plan"]["service"]["deploy_dir"]
294
333
  if path.exists():
295
334
  path.unlink()
296
335
  if dev_id != LOCAL_ID:
297
336
  return
298
337
 
299
338
  def change(doc: Owned) -> None:
300
- if name not in doc["deployments"]:
339
+ entry = doc["deployments"].get(name)
340
+ if entry is None:
341
+ return
342
+ if recorded_dir is not None and not _same_place(entry["deploy_dir"], recorded_dir):
301
343
  return
302
344
  if purged:
303
345
  del doc["deployments"][name]
304
346
  else:
305
- doc["deployments"][name]["removed"] = True
347
+ entry["removed"] = True
306
348
 
307
349
  if owned_path().is_file():
308
350
  update_owned(change)
@@ -316,6 +358,9 @@ OWNED_SCHEMA = "localmodels.owned/v1"
316
358
 
317
359
  class _OwnedPreparation(TypedDict, total=False):
318
360
  preparation_dir: str
361
+ failed: (
362
+ bool # True when recorded from a failed/interrupted deploy; never blocks a verified owner
363
+ )
319
364
 
320
365
 
321
366
  class OwnedDeployment(_OwnedPreparation):
@@ -609,13 +654,55 @@ def owned_entry(plan: Plan) -> OwnedDeployment:
609
654
  return entry
610
655
 
611
656
 
612
- def own_deployment(plan: Plan, tools_dir: str | Path = TOOLS_DIR) -> None:
613
- """Record a deployment on this computer (``owned_entry``)."""
657
+ def port_owned_elsewhere(port: int, deploy_dir: str, tools_dir: str | Path = TOOLS_DIR) -> bool:
658
+ """True when the shared owned manifest records another live verified deployment on ``port``."""
659
+ if not owned_path(tools_dir).is_file():
660
+ return False
661
+ try:
662
+ entries = load_owned(tools_dir)["deployments"].values()
663
+ except (OSError, ValueError):
664
+ return False
665
+ return any(
666
+ not entry["removed"]
667
+ and not entry.get("failed")
668
+ and entry["port"] == port
669
+ and not _same_place(entry["deploy_dir"], deploy_dir)
670
+ for entry in entries
671
+ )
672
+
673
+
674
+ def own_deployment(plan: Plan, tools_dir: str | Path = TOOLS_DIR, *, ok: bool = True) -> bool:
675
+ """Record a deployment on this computer (``owned_entry``). Never overwrites a live verified
676
+ manifest entry belonging to another directory, never claims a unit owned by another live
677
+ verified deployment, and on failure never registers a competing owner on a port another live
678
+ deployment holds."""
614
679
  entry = owned_entry(plan)
680
+ if not ok:
681
+ entry["failed"] = True
682
+ recorded = False
615
683
 
616
684
  def add(doc: Owned) -> None:
685
+ nonlocal recorded
686
+ existing = doc["deployments"].get(plan["name"])
687
+ if existing is not None and not _same_place(existing["deploy_dir"], entry["deploy_dir"]):
688
+ existing_live = not existing["removed"] and not existing.get("failed")
689
+ if existing_live or not ok:
690
+ return
691
+ for other in doc["deployments"].values():
692
+ if (
693
+ other["removed"]
694
+ or other.get("failed")
695
+ or _same_place(other["deploy_dir"], entry["deploy_dir"])
696
+ ):
697
+ continue
698
+ if other["service"] == entry["service"]:
699
+ return
700
+ if not ok and other["port"] == entry["port"]:
701
+ return
617
702
  doc["deployments"][plan["name"]] = entry
618
703
  if entry["slice"]:
619
704
  doc["slices"] = sorted({*doc["slices"], entry["slice"]})
705
+ recorded = True
620
706
 
621
707
  update_owned(add, tools_dir)
708
+ return recorded
@@ -13,7 +13,17 @@ import json
13
13
  import sys
14
14
  from pathlib import Path
15
15
 
16
- from localmodels import cli_help, deploy, library_jobs, library_serve, library_status
16
+ from localmodels import (
17
+ cli_help,
18
+ custom_hub,
19
+ custom_probe,
20
+ deploy,
21
+ library_custom,
22
+ library_jobs,
23
+ library_serve,
24
+ library_smoke,
25
+ library_status,
26
+ )
17
27
  from localmodels.contracts import decode
18
28
  from localmodels.library_model import (
19
29
  EXIT_FAILED,
@@ -35,6 +45,7 @@ DESCRIPTION = (
35
45
  FALLBACK = {
36
46
  "download": "DOWNLOAD_FAILED",
37
47
  "load": "ENGINE_START_FAILED",
48
+ "smoke-test": "ENGINE_START_FAILED",
38
49
  "unload": "ENGINE_START_FAILED",
39
50
  "remove": "INVALID_STATE",
40
51
  "cancel": "INVALID_STATE",
@@ -103,6 +114,13 @@ def add_parser(sub: argparse._SubParsersAction[argparse.ArgumentParser]) -> None
103
114
  action="store_true",
104
115
  help="load at the compact floor posture even when live memory is below headroom guards (still refuses critical OS memory pressure)",
105
116
  )
117
+ load.add_argument(
118
+ "--ctx",
119
+ type=int,
120
+ default=None,
121
+ metavar="TOKENS",
122
+ help="override the served context window (e.g. 2048 or 4096 for verified custom models)",
123
+ )
106
124
  load.add_argument("--jsonl", action="store_true", help="accepted; output is JSONL")
107
125
  cli_help.document(
108
126
  load,
@@ -110,6 +128,26 @@ def add_parser(sub: argparse._SubParsersAction[argparse.ArgumentParser]) -> None
110
128
  "register it with the gateway and pi.",
111
129
  examples=[("%(prog)s qwen3.8-27b:UD-Q4_K_M --unload qwen3.8-27b-iq3s:UD-IQ3_S", "")],
112
130
  )
131
+ smoke = verbs.add_parser(
132
+ "smoke-test",
133
+ help="verify a downloaded model with an ephemeral loopback server without activating it",
134
+ )
135
+ _model(smoke)
136
+ smoke.add_argument(
137
+ "--ctx",
138
+ type=int,
139
+ default=4096,
140
+ metavar="TOKENS",
141
+ help="context size for the conservative smoke-test (default 4096; retry at 2048 on OOM)",
142
+ )
143
+ _base(smoke)
144
+ smoke.add_argument("--jsonl", action="store_true", help="accepted; output is JSONL")
145
+ cli_help.document(
146
+ smoke,
147
+ "Start an isolated ephemeral loopback llama-server, run a minimal completion check, "
148
+ "record verification status, and stop the server so active models and routing stay untouched.",
149
+ examples=[("%(prog)s custom.hf.owner--repo:Q4_K_M --ctx 4096 --jsonl", "")],
150
+ )
113
151
  for verb, text, note in (
114
152
  ("unload", "stop a model's server; its weights stay", "unregister and stop the server"),
115
153
  ("remove", "delete a model's weights (unloads it first)", "keeps files others use"),
@@ -124,6 +162,80 @@ def add_parser(sub: argparse._SubParsersAction[argparse.ArgumentParser]) -> None
124
162
  f"{text[0].upper()}{text[1:]}: {note}. Prints one result or error object.",
125
163
  examples=[("%(prog)s qwen3.8-27b-iq3s:UD-IQ3_S --json", "")],
126
164
  )
165
+ custom = verbs.add_parser(
166
+ "custom", help="search and probe community Hugging Face / ModelScope repositories (JSON)"
167
+ )
168
+ custom_verbs = custom.add_subparsers(dest="custom_command", required=True, metavar="COMMAND")
169
+ c_search = custom_verbs.add_parser(
170
+ "search", help="search Hugging Face and ModelScope for GGUF repositories"
171
+ )
172
+ c_search.add_argument(
173
+ "--config-stdin",
174
+ action="store_true",
175
+ required=True,
176
+ help="read search parameters (and optional token) as JSON from standard input",
177
+ )
178
+ _base(c_search)
179
+ c_search.add_argument("--json", action="store_true", help="accepted; the output is JSON")
180
+ cli_help.document(
181
+ c_search,
182
+ "Search Hugging Face and/or ModelScope for community GGUF models without mutating state. "
183
+ "Reads JSON parameters (hub, query, format, limit, optional token) from stdin and prints "
184
+ "one localmodels.library-custom-search/v1 document.",
185
+ examples=[("%(prog)s --config-stdin --json", "")],
186
+ )
187
+ c_probe = custom_verbs.add_parser(
188
+ "probe", help="inspect a Hugging Face or ModelScope repository without downloading weights"
189
+ )
190
+ c_probe.add_argument(
191
+ "--config-stdin",
192
+ action="store_true",
193
+ required=True,
194
+ help="read probe target (and optional token) as JSON from standard input",
195
+ )
196
+ _base(c_probe)
197
+ c_probe.add_argument(
198
+ "--facts",
199
+ type=Path,
200
+ metavar="FILE",
201
+ help="price variants against saved host facts (probe JSON) instead of probing; read-only",
202
+ )
203
+ c_probe.add_argument("--json", action="store_true", help="accepted; the output is JSON")
204
+ cli_help.document(
205
+ c_probe,
206
+ "Inspect a Hugging Face or ModelScope URL or owner/repo shorthand without downloading "
207
+ "weights. Lists GGUF variants, runs a bounded Range header read for memory pricing, and "
208
+ "prints one localmodels.library-custom-probe/v1 document.",
209
+ examples=[("%(prog)s --config-stdin --base-dir /srv/models --json", "")],
210
+ )
211
+ c_download = custom_verbs.add_parser(
212
+ "download",
213
+ help="download a community Hugging Face or ModelScope GGUF model into isolated storage",
214
+ )
215
+ c_download.add_argument(
216
+ "--config-stdin",
217
+ action="store_true",
218
+ required=True,
219
+ help="read custom download spec (and optional token) as JSON from standard input",
220
+ )
221
+ _base(c_download)
222
+ c_download.add_argument("--jsonl", action="store_true", help="accepted; output is JSONL")
223
+ cli_help.document(
224
+ c_download,
225
+ "Download a community GGUF variant into isolated custom storage and leave it idle "
226
+ "(Standby-First) with verification.status='untested'. Emits localmodels.library-event/v1 "
227
+ "JSONL progress and terminal result or error.",
228
+ examples=[("%(prog)s --config-stdin --base-dir /srv/models --jsonl", "")],
229
+ )
230
+ cli_help.document(
231
+ custom,
232
+ "Search, probe, and download community Hugging Face and ModelScope model repositories.",
233
+ examples=[
234
+ ("%(prog)s search --config-stdin --json", ""),
235
+ ("%(prog)s probe --config-stdin --base-dir /srv/models --json", ""),
236
+ ("%(prog)s download --config-stdin --base-dir /srv/models --jsonl", ""),
237
+ ],
238
+ )
127
239
  cli_help.document(
128
240
  parser,
129
241
  DESCRIPTION,
@@ -134,6 +246,66 @@ def add_parser(sub: argparse._SubParsersAction[argparse.ArgumentParser]) -> None
134
246
  )
135
247
 
136
248
 
249
+ def _read_custom_stdin() -> dict[str, object]:
250
+ raw = sys.stdin.read()
251
+ if not raw.strip():
252
+ return {}
253
+ try:
254
+ parsed = json.loads(raw)
255
+ except ValueError as exc:
256
+ raise LibraryError("INVALID_REPO_SPEC", f"invalid JSON on standard input: {exc}") from None
257
+ if not isinstance(parsed, dict):
258
+ raise LibraryError("INVALID_REPO_SPEC", "standard input must be a JSON object")
259
+ return parsed
260
+
261
+
262
+ def _custom(args: argparse.Namespace) -> int:
263
+ sub = args.custom_command
264
+ jsonl = sub == "download"
265
+ token: str | None = None
266
+ try:
267
+ payload = _read_custom_stdin()
268
+ raw_token = payload.get("token")
269
+ if isinstance(raw_token, str):
270
+ token = raw_token
271
+ if sub == "search":
272
+ doc: object = custom_probe.search(payload, args.base_dir)
273
+ elif sub == "download":
274
+ row = library_custom.download_custom(payload, args.base_dir)
275
+ emit_final(result_doc(row), jsonl=True)
276
+ return 0
277
+ else:
278
+ facts: HostFacts | None = None
279
+ if args.facts is not None:
280
+ try:
281
+ facts = decode(json.loads(args.facts.read_text(encoding="utf-8")), HostFacts)
282
+ except (OSError, ValueError, TypeError) as exc:
283
+ raise LibraryError(
284
+ "INVALID_REPO_SPEC", f"invalid --facts file {args.facts}: {exc}"
285
+ ) from None
286
+ doc = custom_probe.probe(payload, args.base_dir, facts=facts)
287
+ except LibraryError as exc:
288
+ safe = LibraryError(
289
+ exc.code,
290
+ custom_hub.redact_secrets(exc.detail, extra_token=token),
291
+ failed=exc.failed,
292
+ **exc.fields,
293
+ )
294
+ emit_final(error_doc(safe), jsonl=jsonl)
295
+ return safe.exit_code
296
+ except KeyboardInterrupt:
297
+ error = LibraryError("CANCELLED", f"custom {sub} was interrupted")
298
+ emit_final(error_doc(error), jsonl=jsonl)
299
+ return error.exit_code
300
+ except Exception as exc: # noqa: BLE001 - every failure ends in one contract error line
301
+ safe_detail = custom_hub.redact_secrets(str(exc), extra_token=token)
302
+ code = "DOWNLOAD_FAILED" if sub == "download" else "HUB_UNREACHABLE"
303
+ emit_final(error_doc(LibraryError(code, safe_detail)), jsonl=jsonl)
304
+ return EXIT_FAILED
305
+ print(json.dumps(doc, ensure_ascii=False, indent=1))
306
+ return 0
307
+
308
+
137
309
  def _status(args: argparse.Namespace) -> int:
138
310
  from localmodels import library_convert
139
311
 
@@ -155,7 +327,9 @@ def cli(args: argparse.Namespace) -> int:
155
327
  verb = args.library_command
156
328
  if verb == "status":
157
329
  return _status(args)
158
- jsonl = verb in ("download", "load")
330
+ if verb == "custom":
331
+ return _custom(args)
332
+ jsonl = verb in ("download", "load", "smoke-test")
159
333
  try:
160
334
  if verb == "download":
161
335
  row = library_jobs.download(
@@ -165,7 +339,11 @@ def cli(args: argparse.Namespace) -> int:
165
339
  load=lambda m, b, u: library_serve.load(m, b, u),
166
340
  )
167
341
  elif verb == "load":
168
- row = library_serve.load(args.model, args.base_dir, args.unload, force=args.force)
342
+ row = library_serve.load(
343
+ args.model, args.base_dir, args.unload, force=args.force, ctx=args.ctx
344
+ )
345
+ elif verb == "smoke-test":
346
+ row = library_smoke.smoke_test(args.model, args.base_dir, ctx=args.ctx)
169
347
  elif verb == "unload":
170
348
  row = library_serve.unload(args.model, args.base_dir)
171
349
  elif verb == "remove":
@@ -142,6 +142,38 @@ def _planned_stack_llms(plan: StackPlan | None) -> dict[str, str]:
142
142
  return found
143
143
 
144
144
 
145
+ def adopted_components(plan: StackPlan) -> set[str]:
146
+ """The plan's LLM components the library adopted: from then on the
147
+ library loads, unloads, wires and may remove them, so their deployments, gateway route and
148
+ pi selection are no longer the stack's to check. The conversion marker names them, and
149
+ stays when ``library remove`` deletes the model's record; a converted record (an earlier
150
+ one may lack ``stack_provider``: the main LLM's) names them too. Read only; it never
151
+ converts."""
152
+ from localmodels import stack_verify
153
+
154
+ try:
155
+ marker = json.loads((library_state.root() / MARKER).read_text("utf-8"))
156
+ except (OSError, ValueError):
157
+ return set()
158
+ if not isinstance(marker, dict) or marker.get("plan_id") != plan["plan_id"]:
159
+ return set()
160
+ ids = set(marker.get("adopted") or [])
161
+ providers = {
162
+ r.get("stack_provider") or harness.LLM_PROVIDER
163
+ for r in library_state.records()
164
+ if r.get("converted")
165
+ }
166
+ return {
167
+ component
168
+ for component, part in stack_verify.parts(plan)
169
+ if component in STACK_LLMS
170
+ and (
171
+ library_id(part["model"]["id"], part["model"]["quant"]) in ids
172
+ or STACK_LLMS[component] in providers
173
+ )
174
+ }
175
+
176
+
145
177
  def _active_stack_llms(plan: StackPlan | None) -> dict[str, tuple[str, Plan]]:
146
178
  """Accepted stack LLM deployments still present and ok on disk: ``library_id -> (provider, plan)``."""
147
179
  if plan is None:
@@ -299,6 +331,8 @@ def _adopt_record(model: str, provider: str, deployed: Plan, base_dir: str | Non
299
331
  record["quant"] = spec["quant"]
300
332
  record["pool"] = pool
301
333
  record["plan"] = deployed
334
+ record.pop("baseline_plan", None)
335
+ record.pop("load_posture", None)
302
336
  record["pi_model"] = gateway_bifrost.PI_MODEL
303
337
  record["state"] = "loaded"
304
338
  record["converted"] = True