@simplexai/localmodels-linux-arm64 0.1.0-dev.103 → 0.1.0-dev.105

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 (172) hide show
  1. package/LICENSE +201 -0
  2. package/{modules/simplex_localmodels-0.1.0.dev103.dist-info/licenses/NOTICE → NOTICE} +42 -13
  3. package/README.md +10 -0
  4. package/bootstrap.identity +1 -1
  5. package/bootstrap.sha256 +159 -158
  6. package/modules/localmodels/__init__.py +1 -1
  7. package/modules/localmodels/__main__.py +204 -86
  8. package/modules/localmodels/apple_sensors.py +23 -0
  9. package/modules/localmodels/approval.py +25 -2
  10. package/modules/localmodels/catalog.json +584 -158
  11. package/modules/localmodels/catalog.py +18 -3
  12. package/modules/localmodels/catalog_recipes.py +64 -6
  13. package/modules/localmodels/cli_help.py +10 -0
  14. package/modules/localmodels/cli_parser.py +313 -230
  15. package/modules/localmodels/component.py +21 -3
  16. package/modules/localmodels/console.py +1 -1
  17. package/modules/localmodels/context_policy.py +6 -5
  18. package/modules/localmodels/custom_probe.py +4 -2
  19. package/modules/localmodels/debug_cli.py +0 -12
  20. package/modules/localmodels/debug_mode.py +0 -6
  21. package/modules/localmodels/decode_calibration.json +3 -4
  22. package/modules/localmodels/decode_calibration.py +5 -2
  23. package/modules/localmodels/deploy.py +11 -1
  24. package/modules/localmodels/deployment_lifecycle.py +1 -1
  25. package/modules/localmodels/download-mirrors.json +1 -1
  26. package/modules/localmodels/engine_adapters/base.py +11 -1
  27. package/modules/localmodels/engine_adapters/strata_poly.py +65 -3
  28. package/modules/localmodels/engine_adapters/suite_plan.py +61 -24
  29. package/modules/localmodels/engines-b11583.json +6 -26
  30. package/modules/localmodels/engines-b12588-mix-c0c3de8.json +3 -15
  31. package/modules/localmodels/engines-b12757-mix-ef2df21.json +3 -15
  32. package/modules/localmodels/engines-prism-b12178-03ec600.json +3 -15
  33. package/modules/localmodels/engines-speechcpp-v0.11.3.json +4 -20
  34. package/modules/localmodels/engines-strata-0.1.47.json +1 -5
  35. package/modules/localmodels/engines-strata-0.1.49.2.json +1 -5
  36. package/modules/localmodels/engines-strata-0.1.59.1.json +1 -5
  37. package/modules/localmodels/engines-strata-poly-0.2.20-poly.1.json +6 -30
  38. package/modules/localmodels/engines-strata-poly-0.2.20-poly.9.json +129 -0
  39. package/modules/localmodels/engines-whisper-b5454.json +6 -30
  40. package/modules/localmodels/engines.json +13 -61
  41. package/modules/localmodels/estimator.py +10 -5
  42. package/modules/localmodels/gpu_specs.py +1 -1
  43. package/modules/localmodels/host_sensors.py +25 -2
  44. package/modules/localmodels/hosts.py +38 -21
  45. package/modules/localmodels/kokoro-tts-0.6.1.txt +1 -1
  46. package/modules/localmodels/library_cli.py +34 -16
  47. package/modules/localmodels/library_custom.py +9 -1
  48. package/modules/localmodels/library_direct.py +41 -1
  49. package/modules/localmodels/library_elastic.py +135 -6
  50. package/modules/localmodels/library_jobs.py +23 -4
  51. package/modules/localmodels/library_kept.py +9 -1
  52. package/modules/localmodels/library_model.py +174 -2
  53. package/modules/localmodels/library_order.py +175 -69
  54. package/modules/localmodels/library_poly.py +150 -21
  55. package/modules/localmodels/library_presentation.py +485 -0
  56. package/modules/localmodels/library_pricing.py +15 -4
  57. package/modules/localmodels/library_serve.py +342 -70
  58. package/modules/localmodels/library_smoke.py +63 -5
  59. package/modules/localmodels/library_state.py +48 -10
  60. package/modules/localmodels/library_status.py +37 -17
  61. package/modules/localmodels/llm_rank.py +22 -11
  62. package/modules/localmodels/metal.py +1 -2
  63. package/modules/localmodels/plan_envelope.py +40 -13
  64. package/modules/localmodels/planning/budget.py +14 -12
  65. package/modules/localmodels/planning/memory_pools.py +7 -1
  66. package/modules/localmodels/privacy_acceptance.py +6 -5
  67. package/modules/localmodels/probe.py +34 -7
  68. package/modules/localmodels/py.typed +0 -0
  69. package/modules/localmodels/quant_formats.py +10 -3
  70. package/modules/localmodels/recommend_cli.py +1 -1
  71. package/modules/localmodels/records.py +19 -2
  72. package/modules/localmodels/remote_ops_launchd.py +8 -1
  73. package/modules/localmodels/remote_ops_verify.py +91 -24
  74. package/modules/localmodels/runtime_index.py +303 -0
  75. package/modules/localmodels/runtime_process.py +1 -1
  76. package/modules/localmodels/service_deployment.py +2 -4
  77. package/modules/localmodels/service_probe.py +59 -13
  78. package/modules/localmodels/setup_inspection.py +94 -73
  79. package/modules/localmodels/setup_text.py +7 -56
  80. package/modules/localmodels/sidecar_downloads.py +34 -0
  81. package/modules/localmodels/sidecar_http.py +61 -5
  82. package/modules/localmodels/sidecar_state.py +52 -2
  83. package/modules/localmodels/speech_admission.py +20 -4
  84. package/modules/localmodels/speech_catalog.py +23 -0
  85. package/modules/localmodels/speech_cli.py +30 -16
  86. package/modules/localmodels/speech_jobs.py +42 -17
  87. package/modules/localmodels/speech_serve.py +9 -2
  88. package/modules/localmodels/speech_server.py +185 -81
  89. package/modules/localmodels/speech_state.py +4 -1
  90. package/modules/localmodels/speech_workers.py +11 -0
  91. package/modules/localmodels/stack.py +1 -1
  92. package/modules/localmodels/stack_args.py +276 -145
  93. package/modules/localmodels/stack_auto.py +91 -6
  94. package/modules/localmodels/stack_aux_gpu.py +1 -1
  95. package/modules/localmodels/stack_cleanup.py +21 -18
  96. package/modules/localmodels/stack_cli.py +120 -115
  97. package/modules/localmodels/stack_compose.py +16 -5
  98. package/modules/localmodels/stack_debug.py +15 -6
  99. package/modules/localmodels/stack_decision.py +4 -4
  100. package/modules/localmodels/stack_doctor.py +2 -2
  101. package/modules/localmodels/stack_down.py +2 -0
  102. package/modules/localmodels/stack_events.py +1 -1
  103. package/modules/localmodels/stack_gpu_memory.py +1 -1
  104. package/modules/localmodels/stack_hardware.py +17 -15
  105. package/modules/localmodels/stack_mcp.py +1 -2
  106. package/modules/localmodels/stack_mlx.py +8 -1
  107. package/modules/localmodels/stack_picks.py +20 -21
  108. package/modules/localmodels/stack_plan.py +12 -11
  109. package/modules/localmodels/stack_ports.py +31 -4
  110. package/modules/localmodels/stack_review.py +28 -7
  111. package/modules/localmodels/stack_rollback.py +1 -1
  112. package/modules/localmodels/stack_run.py +1 -1
  113. package/modules/localmodels/stack_suite.py +72 -21
  114. package/modules/localmodels/stack_up.py +2 -0
  115. package/modules/localmodels/stack_view.py +180 -35
  116. package/modules/localmodels/stack_view_agent.py +1 -1
  117. package/modules/localmodels/stack_view_demo.py +2 -0
  118. package/modules/localmodels/stack_view_gpu.py +36 -2
  119. package/modules/localmodels/stack_view_schema.py +26 -3
  120. package/modules/localmodels/stack_view_serve.py +0 -2
  121. package/modules/localmodels/stack_view_slots.py +3 -1
  122. package/modules/localmodels/stack_view_telemetry.py +90 -4
  123. package/modules/localmodels/stack_view_tick.py +246 -40
  124. package/modules/localmodels/stack_view_words.py +9 -2
  125. package/modules/localmodels/stack_warm.py +2 -2
  126. package/modules/localmodels/stack_whatif.py +524 -41
  127. package/modules/localmodels/stack_whatif_html.py +900 -0
  128. package/modules/localmodels/startlux-decide-83fe6c7d.txt +2 -2
  129. package/modules/localmodels/{strata-poly-serve-0.2.20-poly.7.txt → strata-poly-serve-0.2.20-poly.9.txt} +1 -1
  130. package/modules/localmodels/strata_poly_server.py +114 -3
  131. package/modules/localmodels/suite.py +265 -6
  132. package/modules/localmodels/telemetry_math.py +458 -18
  133. package/modules/localmodels/transport.py +8 -1
  134. package/modules/localmodels/tts_admission.py +2 -17
  135. package/modules/localmodels/tts_catalog.py +29 -1
  136. package/modules/localmodels/tts_cli.py +45 -22
  137. package/modules/localmodels/tts_http.py +10 -4
  138. package/modules/localmodels/tts_jobs.py +49 -19
  139. package/modules/localmodels/tts_serve.py +9 -2
  140. package/modules/localmodels/tts_server.py +1 -1
  141. package/modules/localmodels/tts_sidecar.py +69 -28
  142. package/modules/localmodels/tts_state.py +7 -2
  143. package/modules/localmodels/vision.py +5 -3
  144. package/modules/localmodels/web/view/ASSET-SOURCES.md +4 -7
  145. package/modules/localmodels/web/view/view.css +0 -1
  146. package/modules/localmodels/web/view/view.js +2 -5
  147. package/modules/localmodels/web/whatif/app.js +730 -0
  148. package/modules/localmodels/web/whatif/page.html +1172 -0
  149. package/modules/localmodels/web/whatif/sim.js +297 -0
  150. package/modules/localmodels/win_probe.py +89 -16
  151. package/modules/localmodels/windows_job.py +179 -11
  152. package/modules/simplex_localmodels-0.1.0.dev105.dist-info/METADATA +14 -0
  153. package/modules/{simplex_localmodels-0.1.0.dev103.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/RECORD +151 -145
  154. package/modules/simplex_localmodels-0.1.0.dev105.dist-info/licenses/LICENSE +201 -0
  155. package/modules/simplex_localmodels-0.1.0.dev105.dist-info/licenses/NOTICE +126 -0
  156. package/package.json +11 -2
  157. package/tool.json +1 -1
  158. package/modules/localmodels/engines-strata-poly-0.2.20-poly.7.json +0 -94
  159. package/modules/localmodels/fixtures/stack-research-demo-plan.json +0 -1059
  160. package/modules/localmodels/stack_research.py +0 -716
  161. package/modules/localmodels/stack_research_demo.py +0 -125
  162. package/modules/localmodels/stack_research_plan.py +0 -146
  163. package/modules/localmodels/web/index.html +0 -2605
  164. package/modules/localmodels/web/sizecalc/app.js +0 -1306
  165. package/modules/localmodels/web/sizecalc/calc.js +0 -269
  166. package/modules/localmodels/web/sizecalc/page.html +0 -520
  167. package/modules/localmodels/web/view/logo-claude.svg +0 -3
  168. package/modules/localmodels/web/view/logo-codex.png +0 -0
  169. package/modules/simplex_localmodels-0.1.0.dev103.dist-info/METADATA +0 -9
  170. /package/modules/{simplex_localmodels-0.1.0.dev103.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/WHEEL +0 -0
  171. /package/modules/{simplex_localmodels-0.1.0.dev103.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/entry_points.txt +0 -0
  172. /package/modules/{simplex_localmodels-0.1.0.dev103.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -25,6 +25,7 @@ from typing import Any, TypedDict
25
25
  _PROC = Path("/proc")
26
26
  _SECTOR_BYTES = 512
27
27
  _BYTES_PER_MB = 1_000_000.0
28
+ _COLD_SAMPLE_S = 0.02
28
29
  # Whole physical block devices on Linux (excludes partitions and loop/ram/dm to avoid double counts).
29
30
  _WHOLE_DISK_RE = re.compile(r"^(?:nvme\d+n\d+|sd[a-z]+|vd[a-z]+|hd[a-z]+|xvd[a-z]+|mmcblk\d+)$")
30
31
  _OOM_MARKERS = ("out of memory", "oom-kill", "oom_kill", "cudamalloc failed", "bad_alloc")
@@ -461,7 +462,7 @@ def _collect_linux(
461
462
 
462
463
  # On a cold sample with no prior snapshot, take one tiny 20 ms delta so live CPU % is real.
463
464
  if not isinstance(prev_cpu, dict) and curr_cpu:
464
- time.sleep(0.02)
465
+ time.sleep(_COLD_SAMPLE_S)
465
466
  now_mono = time.monotonic()
466
467
  stat_text2 = _read_text(proc / "stat")
467
468
  disk_text2 = _read_text(proc / "diskstats")
@@ -471,7 +472,7 @@ def _collect_linux(
471
472
  if disk_text2 and curr_disk is not None:
472
473
  prev_disk = curr_disk
473
474
  curr_disk = parse_proc_diskstats(disk_text2)
474
- prev_at = now_mono - 0.02
475
+ prev_at = now_mono - _COLD_SAMPLE_S
475
476
 
476
477
  overall: float | None = None
477
478
  per_core: list[CoreUsage] = []
@@ -530,6 +531,15 @@ def _collect_macos(
530
531
  prev_disk = prev_state.get("disk")
531
532
  prev_at = prev_state.get("at")
532
533
 
534
+ # On a cold sample with no prior snapshot, take one tiny 20 ms delta so live CPU % is real.
535
+ if not isinstance(prev_cpu, dict) and curr_cpu:
536
+ time.sleep(_COLD_SAMPLE_S)
537
+ now_mono = time.monotonic()
538
+ curr_cpu2 = _read_macos_cpu_ticks()
539
+ if curr_cpu2:
540
+ prev_cpu = curr_cpu
541
+ curr_cpu = curr_cpu2
542
+
533
543
  overall, per_core = (
534
544
  diff_cpu_samples(prev_cpu, curr_cpu)
535
545
  if isinstance(prev_cpu, dict) and curr_cpu
@@ -577,6 +587,19 @@ def _collect_windows(
577
587
  ) -> tuple[CpuSensors, DiskSensors, MemoryPressure, dict[str, Any]]:
578
588
  curr_times = _read_windows_system_times()
579
589
  prev_times = prev_state.get("win_cpu")
590
+
591
+ # On a cold sample with no prior snapshot, take one tiny 20 ms delta so live CPU % is real.
592
+ if (
593
+ not (isinstance(prev_times, list | tuple) and len(prev_times) == 3)
594
+ and curr_times is not None
595
+ ):
596
+ time.sleep(_COLD_SAMPLE_S)
597
+ now_mono = time.monotonic()
598
+ curr_times2 = _read_windows_system_times()
599
+ if curr_times2 is not None:
600
+ prev_times = curr_times
601
+ curr_times = curr_times2
602
+
580
603
  overall: float | None = None
581
604
  if isinstance(prev_times, list | tuple) and len(prev_times) == 3 and curr_times is not None:
582
605
  overall = parse_windows_system_times(
@@ -7,9 +7,12 @@ keep the full plan and step results, never the API key; the key stays in a 0600
7
7
 
8
8
  from __future__ import annotations
9
9
 
10
+ import contextlib
10
11
  import json
11
12
  import os
12
13
  import re
14
+ import sys
15
+ import tempfile
13
16
  import threading
14
17
  import time
15
18
  from collections.abc import Callable, Iterator, Mapping
@@ -18,6 +21,7 @@ from pathlib import Path
18
21
  from typing import Any, Literal, TypedDict, TypeVar
19
22
 
20
23
  from localmodels import deployment_lifecycle as lifecycle
24
+ from localmodels import runtime_windows_acl
21
25
  from localmodels.contracts import decode
22
26
  from localmodels.probe import HostFacts
23
27
  from localmodels.records import Device, FinishedRecord, Plan
@@ -41,11 +45,28 @@ def stacks_dir() -> Path:
41
45
 
42
46
  def _write_private(path: Path, data: object) -> Path:
43
47
  path.parent.mkdir(parents=True, exist_ok=True)
44
- tmp = path.with_name(path.name + ".tmp")
45
- tmp.touch(0o600)
46
- tmp.chmod(0o600) # owner-only before any content, so no interrupt leaves a readable copy
47
- tmp.write_text(json.dumps(data, ensure_ascii=False, indent=1) + "\n", encoding="utf-8")
48
- tmp.replace(path) # atomic: a kill mid-write never leaves a truncated record
48
+ fd, tmp_name = tempfile.mkstemp(prefix=f".{path.name}.", suffix=".tmp", dir=path.parent)
49
+ tmp = Path(tmp_name)
50
+ closed = False
51
+ try:
52
+ if os.name != "nt":
53
+ os.chmod(
54
+ tmp, 0o600
55
+ ) # owner-only before any content, so no interrupt leaves a readable copy
56
+ with os.fdopen(fd, "w", encoding="utf-8") as handle:
57
+ closed = True
58
+ handle.write(json.dumps(data, ensure_ascii=False, indent=1) + "\n")
59
+ if sys.platform == "win32":
60
+ runtime_windows_acl.rename_with_retry(tmp, path, replace=True)
61
+ else:
62
+ tmp.replace(path) # atomic: a kill mid-write never leaves a truncated record
63
+ except BaseException:
64
+ if not closed:
65
+ with contextlib.suppress(OSError):
66
+ os.close(fd)
67
+ with contextlib.suppress(OSError):
68
+ tmp.unlink(missing_ok=True)
69
+ raise
49
70
  return path
50
71
 
51
72
 
@@ -540,7 +561,7 @@ def update_owned(change: Callable[[Owned], None], tools_dir: str | Path = TOOLS_
540
561
  `owned.lock` is permanent, even when the manifest becomes empty. Unlinking it after the
541
562
  flock is released splits the lock domain: a writer that already opened the old inode and
542
563
  a writer that recreates the pathname would both hold an "exclusive" lock and one archive
543
- entry would be lost (WHI-317). Nothing removes the tools directory itself."""
564
+ entry would be lost. Nothing removes the tools directory itself."""
544
565
  if os.name == "nt":
545
566
  return _update_owned_windows(change, tools_dir)
546
567
  import fcntl
@@ -591,18 +612,6 @@ def own_gateway(
591
612
  update_owned(change, tools_dir)
592
613
 
593
614
 
594
- def own_magpie(tools_dir: str | Path, record: OwnedMagpie | None) -> None:
595
- """Record or clear the private ``magpie serve`` instance launched by this tool."""
596
-
597
- def change(doc: Owned) -> None:
598
- if record is None:
599
- doc["gateway"].pop("magpie", None)
600
- else:
601
- doc["gateway"]["magpie"] = record
602
-
603
- update_owned(change, tools_dir)
604
-
605
-
606
615
  def forget_search(tools_dir: str | Path, field: Literal["search", "search_you"]) -> None:
607
616
  """Forget a Magpie search API this tool added for the web search service it used to run."""
608
617
 
@@ -661,17 +670,25 @@ def port_owned_elsewhere(port: int, deploy_dir: str, tools_dir: str | Path = TOO
661
670
  )
662
671
 
663
672
 
664
- def own_deployment(plan: Plan, tools_dir: str | Path = TOOLS_DIR, *, ok: bool = True) -> bool:
673
+ def own_deployment(
674
+ plan: Plan, tools_dir: str | Path = TOOLS_DIR, *, ok: bool = True, adopt: bool = False
675
+ ) -> bool:
665
676
  """Record a deployment on this computer (``owned_entry``). Never overwrites a live verified
666
677
  manifest entry belonging to another directory, never claims a unit owned by another live
667
678
  verified deployment, and on failure never registers a competing owner on a port another live
668
- deployment holds."""
679
+ deployment holds.
680
+
681
+ ``adopt`` (an uninstall taking a deployment its manifest does not list) only adds a missing
682
+ entry, never replacing one written meanwhile, and records a failed deploy even on a port a
683
+ live deployment holds: FAILED never blocks that owner, and the uninstall can remove it."""
669
684
  entry = owned_entry(plan)
670
685
  recorded = False
671
686
 
672
687
  def add(doc: Owned) -> None:
673
688
  nonlocal recorded
674
689
  existing = doc["deployments"].get(plan["name"])
690
+ if adopt and existing is not None:
691
+ return
675
692
  if existing is not None and not lifecycle.same_dir(
676
693
  existing["deploy_dir"], entry["deploy_dir"]
677
694
  ):
@@ -684,7 +701,7 @@ def own_deployment(plan: Plan, tools_dir: str | Path = TOOLS_DIR, *, ok: bool =
684
701
  continue
685
702
  if other["service"] == entry["service"]:
686
703
  return
687
- if not ok and other["port"] == entry["port"]:
704
+ if not ok and not adopt and other["port"] == entry["port"]:
688
705
  return
689
706
  event = lifecycle.Event.DEPLOYED if ok else lifecycle.Event.DEPLOY_FAILED
690
707
  lifecycle.advance(doc["deployments"], plan["name"], event, entry)
@@ -1,6 +1,6 @@
1
1
  # kokoro-onnx 0.6.1 (thewh1teagle/kokoro-onnx, MIT) with misaki 0.9.4's Chinese G2P (hexgrad/misaki,
2
2
  # Apache-2.0) on onnxruntime 1.23.2 for the Kokoro-82M TTS service (localmodels/tts_server.py). The
3
- # versions are those of the venv measured on lab-12021 (2026-10-16-speech-retrieval, Python 3.10.12),
3
+ # versions are those of the venv measured on a reference Linux host (Python 3.10.12),
4
4
  # without its Piper voices. Installed by localmodels/frontend.py with --require-hashes --no-deps.
5
5
  # Regenerate with
6
6
  # uv pip compile --universal --python-version 3.10 --generate-hashes --no-header --no-annotate
@@ -12,19 +12,9 @@ import argparse
12
12
  import json
13
13
  import sys
14
14
  from pathlib import Path
15
+ from typing import TYPE_CHECKING
15
16
 
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
- )
27
- from localmodels.contracts import decode
17
+ from localmodels import cli_help
28
18
  from localmodels.library_model import (
29
19
  EXIT_FAILED,
30
20
  LibraryError,
@@ -32,7 +22,9 @@ from localmodels.library_model import (
32
22
  error_doc,
33
23
  result_doc,
34
24
  )
35
- from localmodels.probe import HostFacts
25
+
26
+ if TYPE_CHECKING:
27
+ from localmodels.probe import HostFacts
36
28
 
37
29
  DESCRIPTION = (
38
30
  "Each validated chat model on its own: download it (then load it when its memory pool has "
@@ -55,7 +47,7 @@ FALLBACK = {
55
47
  def _base(p: argparse.ArgumentParser) -> None:
56
48
  p.add_argument(
57
49
  "--base-dir",
58
- default=deploy.DEFAULT_BASE_DIR,
50
+ default=cli_help.DEFAULT_BASE_DIR,
59
51
  metavar="DIR",
60
52
  help="where weights, engines and deployments live (the v1 calls' --base-dir)",
61
53
  )
@@ -70,12 +62,18 @@ def add_parser(sub: argparse._SubParsersAction[argparse.ArgumentParser]) -> None
70
62
  verbs = parser.add_subparsers(dest="library_command", required=True, metavar="COMMAND")
71
63
  status = verbs.add_parser("status", help="every model, its fit, state and pool (JSON)")
72
64
  _base(status)
73
- status.add_argument(
65
+ status_facts = status.add_mutually_exclusive_group()
66
+ status_facts.add_argument(
74
67
  "--facts",
75
68
  type=Path,
76
69
  metavar="FILE",
77
70
  help="price against saved host facts (probe JSON) instead of probing; read-only",
78
71
  )
72
+ status_facts.add_argument(
73
+ "--cached-facts",
74
+ action="store_true",
75
+ help="reuse cached $LOCALMODELS_STATE/facts/local.json when present (falls back to live probe)",
76
+ )
79
77
  status.add_argument("--json", action="store_true", help="accepted; the output is JSON")
80
78
  cli_help.document(
81
79
  status,
@@ -195,12 +193,18 @@ def add_parser(sub: argparse._SubParsersAction[argparse.ArgumentParser]) -> None
195
193
  help="read probe target (and optional token) as JSON from standard input",
196
194
  )
197
195
  _base(c_probe)
198
- c_probe.add_argument(
196
+ probe_facts = c_probe.add_mutually_exclusive_group()
197
+ probe_facts.add_argument(
199
198
  "--facts",
200
199
  type=Path,
201
200
  metavar="FILE",
202
201
  help="price variants against saved host facts (probe JSON) instead of probing; read-only",
203
202
  )
203
+ probe_facts.add_argument(
204
+ "--cached-facts",
205
+ action="store_true",
206
+ help="reuse cached $LOCALMODELS_STATE/facts/local.json when present (falls back to live probe)",
207
+ )
204
208
  c_probe.add_argument("--json", action="store_true", help="accepted; the output is JSON")
205
209
  cli_help.document(
206
210
  c_probe,
@@ -261,6 +265,10 @@ def _read_custom_stdin() -> dict[str, object]:
261
265
 
262
266
 
263
267
  def _custom(args: argparse.Namespace) -> int:
268
+ from localmodels import custom_hub, custom_probe, library_custom, library_jobs
269
+ from localmodels.contracts import decode
270
+ from localmodels.probe import HostFacts
271
+
264
272
  sub = args.custom_command
265
273
  jsonl = sub == "download"
266
274
  token: str | None = None
@@ -284,6 +292,8 @@ def _custom(args: argparse.Namespace) -> int:
284
292
  raise LibraryError(
285
293
  "INVALID_REPO_SPEC", f"invalid --facts file {args.facts}: {exc}"
286
294
  ) from None
295
+ elif getattr(args, "cached_facts", False):
296
+ facts = library_jobs.cached_or_probe()
287
297
  doc = custom_probe.probe(payload, args.base_dir, facts=facts)
288
298
  except LibraryError as exc:
289
299
  safe = LibraryError(
@@ -308,9 +318,15 @@ def _custom(args: argparse.Namespace) -> int:
308
318
 
309
319
 
310
320
  def _status(args: argparse.Namespace) -> int:
321
+ from localmodels import library_jobs, library_status
322
+ from localmodels.contracts import decode
323
+ from localmodels.probe import HostFacts
324
+
311
325
  try:
312
326
  if args.facts is not None:
313
327
  facts = decode(json.loads(args.facts.read_text(encoding="utf-8")), HostFacts)
328
+ elif getattr(args, "cached_facts", False):
329
+ facts = library_jobs.cached_or_probe()
314
330
  else:
315
331
  facts = library_jobs.probe()
316
332
  doc = library_status.build(library_status.Library.read(facts, args.base_dir))
@@ -327,6 +343,8 @@ def cli(args: argparse.Namespace) -> int:
327
343
  return _status(args)
328
344
  if verb == "custom":
329
345
  return _custom(args)
346
+ from localmodels import library_jobs, library_serve, library_smoke
347
+
330
348
  jsonl = verb in ("download", "load", "smoke-test")
331
349
  try:
332
350
  if verb == "download":
@@ -32,6 +32,7 @@ from localmodels import (
32
32
  plan_envelope,
33
33
  remote_ops,
34
34
  remote_ops_download,
35
+ runtime_index,
35
36
  )
36
37
  from localmodels.gguf import GGUFHeader
37
38
  from localmodels.library_model import (
@@ -442,7 +443,13 @@ def _build_download_plan(
442
443
  placement={"id": placement_id, "label": pool_id, "pooled": False, "gpus": placement_gpus},
443
444
  launch=launch,
444
445
  service={"argv": argv, "env": {}, "autostart": False},
445
- endpoint={"model": model_alias},
446
+ endpoint={
447
+ "model": model_alias,
448
+ "health_path": "/health",
449
+ "slots_path": None,
450
+ "metrics_path": None,
451
+ "metrics_requires_auth": False,
452
+ },
446
453
  warnings=[],
447
454
  )
448
455
 
@@ -866,3 +873,4 @@ def _commit_custom_record(
866
873
  if stale:
867
874
  library_jobs.delete_weights(stale, library_jobs.in_use(custom_model_id))
868
875
  library_jobs.prune_empty_custom_dirs(stale, base_dir)
876
+ runtime_index.refresh()
@@ -10,12 +10,13 @@ from __future__ import annotations
10
10
 
11
11
  import os
12
12
  import re
13
+ from collections.abc import Mapping
13
14
  from pathlib import Path
14
15
 
15
16
  from localmodels import catalog as cat
16
17
  from localmodels import vision
17
18
  from localmodels.library_model import PiSpec, display_name, split_id
18
- from localmodels.library_state import Registration
19
+ from localmodels.library_state import Record, Registration
19
20
  from localmodels.records import Plan
20
21
 
21
22
  PROVIDER_PREFIX = "localmodels-lib-"
@@ -92,3 +93,42 @@ def pi_spec(
92
93
  "default_effort": default_effort(levels),
93
94
  "api_key_file": api_key_file(plan),
94
95
  }
96
+
97
+
98
+ def pi_spec_for_record(
99
+ record: Record,
100
+ *,
101
+ catalog_by_id: Mapping[str, cat.CatalogEntry] | None = None,
102
+ ) -> PiSpec:
103
+ """Build ``PiSpec`` directly from a saved library ``Record`` (curated, custom, or retired)."""
104
+ reg = record.get("registration")
105
+ api_name = (reg.get("api") if reg else None) or DEFAULT_API
106
+ plan = record["plan"]
107
+ model = record["id"]
108
+ entry = catalog_by_id.get(record["catalog_id"]) if catalog_by_id else None
109
+ if entry is not None:
110
+ return pi_spec(model, entry, plan, api=api_name)
111
+ raw_name = str(plan["model"]["display_name"])
112
+ efforts: list[str] = list(cat.EFFORT_LEVELS)
113
+ if isinstance(ce := record.get("catalog_entry"), Mapping):
114
+ if isinstance(ce_name := ce.get("display_name"), str) and ce_name:
115
+ raw_name = ce_name
116
+ raw_efforts = ce.get("reasoning_efforts")
117
+ if isinstance(raw_efforts, list) and all(isinstance(v, str) for v in raw_efforts):
118
+ efforts = list(raw_efforts) or list(cat.EFFORT_LEVELS)
119
+ served = str(plan["endpoint"]["model"])
120
+ pid = provider_id(model)
121
+ context = int(str(plan["launch"].get("window") or 0)) or DEFAULT_CONTEXT
122
+ return {
123
+ "provider": pid,
124
+ "model": served,
125
+ "pi_model": f"{pid}/{served}",
126
+ "name": display_name(raw_name, split_id(model)[1]),
127
+ "api": api_name,
128
+ "base_url": str(plan["endpoint"]["base_url"]),
129
+ "context_tokens": context,
130
+ "vision": vision.reads_pictures(plan["launch"]),
131
+ "efforts": efforts,
132
+ "default_effort": default_effort(efforts),
133
+ "api_key_file": api_key_file(plan),
134
+ }
@@ -24,6 +24,7 @@ from localmodels import (
24
24
  library_pricing,
25
25
  metal,
26
26
  plan_envelope,
27
+ suite,
27
28
  vision,
28
29
  )
29
30
  from localmodels.context_policy import AgentPosture
@@ -240,15 +241,19 @@ def _floor_need_bytes(
240
241
 
241
242
  def minimum_memory_bytes(facts: HostFacts, model: Model, pool: str) -> int | None:
242
243
  """Estimated footprint at the lowest elastic posture rung (floor ctx x 1 slot, compact KV)."""
243
- if (
244
- not pool
245
- or pool == "system"
246
- or model.entry.runtime != "llama.cpp"
247
- or library_kept.retired(model.entry)
248
- ):
244
+ if not pool or pool == "system" or library_kept.retired(model.entry):
249
245
  return None
250
246
  if pool not in memory_pools.pools(facts):
251
247
  return None
248
+ if model.entry.runtime == "strata-poly":
249
+ if pool == "unified" and metal.supported(facts):
250
+ return library_poly.unified_floor_bytes(
251
+ suite.recipe(model.entry.id),
252
+ context_policy.posture_for(library_pricing.posture(), "metal"),
253
+ )
254
+ return None
255
+ if model.entry.runtime != "llama.cpp":
256
+ return None
252
257
  backend: budget.Backend = "metal" if pool == "unified" and metal.supported(facts) else "cuda"
253
258
  ladder = elastic_posture_ladder(
254
259
  library_pricing.posture(),
@@ -536,6 +541,120 @@ def load_posture(model: Model, base_dir: str) -> AgentPosture:
536
541
  return replace(posture, draft="off")
537
542
 
538
543
 
544
+ def _price_poly_unified(
545
+ facts: HostFacts,
546
+ model: Model,
547
+ base_dir: str,
548
+ port: int,
549
+ adm: budget.AdmissionBudget,
550
+ *,
551
+ allow_overcommit: bool,
552
+ force: bool,
553
+ ) -> ElasticPlan:
554
+ """Dual-tier Metal admission for a ``strata-poly`` recipe on Apple Silicon unified memory."""
555
+ mac_posture = context_policy.posture_for(library_pricing.posture(), "metal")
556
+ if problem := metal.problem(facts):
557
+ floor_need = library_poly.unified_floor_bytes(suite.recipe(model.entry.id), mac_posture)
558
+ if metal.is_critical_pressure(facts):
559
+ raise ElasticRoomError(
560
+ problem,
561
+ pool="unified",
562
+ need_bytes=floor_need,
563
+ free_bytes=0,
564
+ memory="unified memory",
565
+ wired_headroom_bytes=0,
566
+ soft_available_bytes=0,
567
+ pressure_level=adm.pressure_level,
568
+ can_force=False,
569
+ )
570
+ raise LiveMemoryUnavailable(problem)
571
+ plan, needed, wired = library_poly.build_unified_plan(
572
+ facts, model.entry.id, base_dir, port, mac_posture
573
+ )
574
+ eff = _plan_posture(plan)
575
+ working_set = metal.working_set_bytes(facts)
576
+ pool_cap = memory_pools.pool_total(facts, "unified")
577
+ tier1_limit = min(working_set, pool_cap, adm.soft_budget_bytes)
578
+ if (
579
+ needed <= tier1_limit
580
+ and wired <= adm.hard_ceiling_bytes
581
+ and needed <= adm.physical_limit_bytes
582
+ ):
583
+ return ElasticPlan(plan, 0, (), eff, eff, False, None, None, False, adm)
584
+ if (
585
+ allow_overcommit
586
+ and adm.allows_soft_overcommit
587
+ and not adm.critical_pressure
588
+ and adm.pressure_level != metal.PRESSURE_WARN
589
+ and wired <= adm.hard_ceiling_bytes
590
+ and needed <= min(working_set, pool_cap, adm.physical_limit_bytes)
591
+ ):
592
+ warning: MemoryPressureWarning = {
593
+ "level": "soft",
594
+ "pool": "unified",
595
+ "free_bytes": adm.soft_budget_bytes,
596
+ "budget_bytes": adm.hard_ceiling_bytes,
597
+ }
598
+ return ElasticPlan(
599
+ plan=plan,
600
+ rung_index=0,
601
+ ladder=(),
602
+ requested_posture=eff,
603
+ effective_posture=eff,
604
+ degraded=True,
605
+ degradation_reason="above_soft_budget",
606
+ memory_pressure_warning=warning,
607
+ forced=False,
608
+ admission=adm,
609
+ )
610
+ if force and _force_within_hard_limits(adm, needed, wired):
611
+ forced_warning: MemoryPressureWarning = {
612
+ "level": "high",
613
+ "pool": "unified",
614
+ "free_bytes": min(adm.soft_budget_bytes, adm.hard_ceiling_bytes),
615
+ "budget_bytes": adm.physical_limit_bytes,
616
+ }
617
+ return ElasticPlan(
618
+ plan=plan,
619
+ rung_index=0,
620
+ ladder=(),
621
+ requested_posture=eff,
622
+ effective_posture=eff,
623
+ degraded=True,
624
+ degradation_reason="forced_overcommit",
625
+ memory_pressure_warning=forced_warning,
626
+ forced=True,
627
+ admission=adm,
628
+ )
629
+ can_force = not force and _force_within_hard_limits(adm, needed, wired)
630
+ wired_blocked = wired > adm.hard_ceiling_bytes
631
+ phys_blocked = needed > adm.physical_limit_bytes
632
+ ws_blocked = needed > working_set
633
+ soft_blocked = not wired_blocked and not phys_blocked and not ws_blocked
634
+ report_need = wired if wired_blocked else needed
635
+ if wired_blocked:
636
+ report_free = adm.hard_ceiling_bytes
637
+ elif phys_blocked:
638
+ report_free = adm.physical_limit_bytes
639
+ elif ws_blocked:
640
+ report_free = working_set
641
+ else:
642
+ report_free = adm.soft_budget_bytes
643
+ ceiling_label = "soft budget" if soft_blocked else "hard ceiling"
644
+ raise ElasticRoomError(
645
+ f"{model.id} does not fit unified now (needs {report_need} bytes, {ceiling_label} "
646
+ f"{report_free} bytes)",
647
+ pool="unified",
648
+ need_bytes=report_need,
649
+ free_bytes=report_free,
650
+ memory="unified memory",
651
+ wired_headroom_bytes=adm.wired_headroom_bytes,
652
+ soft_available_bytes=adm.soft_budget_bytes,
653
+ pressure_level=adm.pressure_level,
654
+ can_force=can_force,
655
+ )
656
+
657
+
539
658
  def price_elastic(
540
659
  facts: HostFacts,
541
660
  model: Model,
@@ -563,6 +682,16 @@ def price_elastic(
563
682
  if adm is None:
564
683
  raise plan_envelope.PlanError(f"this computer has no pool {pool}")
565
684
  if model.entry.runtime == "strata-poly":
685
+ if pool == "unified" and metal.supported(facts):
686
+ return _price_poly_unified(
687
+ facts,
688
+ model,
689
+ base_dir,
690
+ port,
691
+ adm,
692
+ allow_overcommit=allow_overcommit,
693
+ force=force,
694
+ )
566
695
  poly_plan = library_poly.price(
567
696
  facts,
568
697
  model.entry.id,
@@ -36,6 +36,7 @@ from localmodels import (
36
36
  remote_ops_download,
37
37
  remote_ops_mirrors,
38
38
  reuse,
39
+ runtime_index,
39
40
  )
40
41
  from localmodels.deploy_steps import Action
41
42
  from localmodels.library_model import (
@@ -54,15 +55,31 @@ from localmodels.records import Plan, ReusableFile
54
55
  from localmodels.transport import Executor
55
56
 
56
57
 
57
- def probe() -> HostFacts:
58
- """This computer's facts, an inference server's file-cached weights on a Mac out of the RAM
59
- available (metal.foreign_cached_bytes; the library's own servers are not foreign)."""
60
- facts = app.probe(hosts.LOCAL_ID)
58
+ def _adjust_foreign_ram(facts: HostFacts) -> HostFacts:
61
59
  if foreign := metal.foreign_cached_bytes(facts):
62
60
  facts["ram"]["available_bytes"] = max(0, facts["ram"]["available_bytes"] - foreign)
63
61
  return facts
64
62
 
65
63
 
64
+ def probe() -> HostFacts:
65
+ """This computer's facts, an inference server's file-cached weights on a Mac out of the RAM
66
+ available (metal.foreign_cached_bytes; the library's own servers are not foreign)."""
67
+ return _adjust_foreign_ram(app.probe(hosts.LOCAL_ID))
68
+
69
+
70
+ def cached_or_probe() -> HostFacts:
71
+ """Reuse saved ``$LOCALMODELS_STATE/facts/local.json`` when present and valid; otherwise run
72
+ a live ``probe()`` (which also populates the cache). Debug simulate mode still answers via
73
+ ``probe()`` so simulated profiles are not shadowed by stale real-host facts."""
74
+ from localmodels import debug_mode
75
+
76
+ if debug_mode.simulating() is None:
77
+ cached = hosts.load_facts(hosts.LOCAL_ID)
78
+ if cached is not None:
79
+ return _adjust_foreign_ram(cached)
80
+ return probe()
81
+
82
+
66
83
  def executor() -> Executor:
67
84
  return hosts.executor(hosts.get_device(hosts.LOCAL_ID))
68
85
 
@@ -639,6 +656,7 @@ def _fetch_and_commit(
639
656
  # the record's, and no download job is left for a cancel to act on.
640
657
  library_state.save(record)
641
658
  library_state.clear_job(model.id)
659
+ runtime_index.refresh()
642
660
 
643
661
 
644
662
  def download(
@@ -714,6 +732,7 @@ def download(
714
732
  ):
715
733
  record_["note"] = {"code": NO_ROOM_TO_LOAD}
716
734
  library_state.save(record_)
735
+ runtime_index.refresh()
717
736
  return library_status.model_row(library_status.Library.read(probe(), base_dir), model.id)
718
737
 
719
738
 
@@ -60,11 +60,19 @@ def _named(entry: cat.CatalogEntry, catalog: Iterable[cat.CatalogEntry]) -> cat.
60
60
 
61
61
 
62
62
  def _runtime(record: Record) -> str:
63
- build = str(record["plan"]["engine"].get("build") or "")
63
+ plan = record["plan"]
64
+ build = str(plan["engine"].get("build") or "")
64
65
  if build.startswith("strata-poly"):
65
66
  return "strata-poly"
66
67
  if build.startswith("strata"):
67
68
  return "strata"
69
+ launch_runtime = str(plan["launch"].get("runtime") or "")
70
+ custom = record.get("custom")
71
+ custom_fmt = custom.get("format") if custom is not None else None
72
+ if launch_runtime == "mlx-lm" or build.startswith("mlx") or custom_fmt == "mlx":
73
+ return "mlx-lm"
74
+ if launch_runtime and launch_runtime != "llama.cpp":
75
+ return launch_runtime
68
76
  return "llama.cpp"
69
77
 
70
78