@simplexai/localmodels-darwin-x64 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
@@ -35,7 +35,7 @@ from localmodels.estimator import HardwareBudget
35
35
  from localmodels.plan_envelope import PlanError
36
36
  from localmodels.planning import llm_ram
37
37
  from localmodels.planning.budget import HARNESS_RAM, RAM_FLOOR, gpu_conflicts, host_ram
38
- from localmodels.probe import HostFacts
38
+ from localmodels.probe import GPU, HostFacts
39
39
  from localmodels.records import PinnedFile, Plan
40
40
  from localmodels.stack_plan import (
41
41
  DecisionChoice,
@@ -61,6 +61,49 @@ DEFAULT_READS: LlamaReads = (
61
61
  )
62
62
 
63
63
 
64
+ def _part_gpu(facts: HostFacts, parts: Parts) -> GPU | None:
65
+ raw_gpu = parts["budget"].get("gpu")
66
+ if not isinstance(raw_gpu, dict):
67
+ return None
68
+ idx = raw_gpu.get("index")
69
+ return next((g for g in facts.get("gpus") or [] if g["index"] == idx), None)
70
+
71
+
72
+ def _poly_concurrent_ok(recipe: suite.SuiteRecipe, gpu: GPU | None, parts: Parts) -> bool:
73
+ if recipe.get("runtime") != "strata-poly" or not suite.poly_gpu_resident(recipe, gpu):
74
+ return False
75
+ return int(str(parts["llm"]["launch"].get("slots") or 1)) >= 2
76
+
77
+
78
+ def _llama_decode_tok_s(
79
+ facts: HostFacts, options: StackOptions, llama_id: str, gpu_index: int
80
+ ) -> float | None:
81
+ if not llama_id:
82
+ return None
83
+ entry = cat.find_entry(llama_id)
84
+ if entry is None:
85
+ return None
86
+ variant = entry.variants[-1]
87
+ measured = stack_warm_store.lookup(facts, gpu_index, entry.id, variant.quant)
88
+ if measured is not None:
89
+ return round(measured, 1)
90
+ card_budget = stack_capacity.llm_budget(facts, gpu_index, options, entry=entry)[0]
91
+ return round(cat.decode_estimate(entry, variant, card_budget).tok_s, 1)
92
+
93
+
94
+ def _poly_decode_for_gpu(
95
+ facts: HostFacts, recipe: suite.SuiteRecipe, gpu: GPU | None, quant: str
96
+ ) -> tuple[float | None, str]:
97
+ if gpu is not None:
98
+ measured = stack_warm_store.lookup(facts, gpu["index"], recipe["id"], quant)
99
+ if measured is not None:
100
+ return round(measured, 1), "measured-decode"
101
+ est = suite.poly_decode_estimate(recipe, gpu)
102
+ if est is not None:
103
+ return round(est.tok_s, 1), est.basis
104
+ return None, "unavailable"
105
+
106
+
64
107
  def strata_parts(
65
108
  facts: HostFacts,
66
109
  options: StackOptions,
@@ -74,7 +117,7 @@ def strata_parts(
74
117
  ) -> Parts | None:
75
118
  """The best validated Strata recipe whose installed SimplexAI score beats the llama.cpp
76
119
  pick by at least llm_rank.TIE_BAND and that fits this host, priced as if ``--llm`` named
77
- it (roadmap decisions 26 and 33: Strata keeps the experts in RAM, so a 24 GB card with 64 GB runs
120
+ it (Strata keeps the experts in RAM, so a 24 GB card with 64 GB runs
78
121
  Flash-Next). None leaves the choice to llama.cpp; why each better recipe was passed over is
79
122
  added to ``passed_over`` for the llama.cpp plan's warnings.
80
123
 
@@ -85,6 +128,7 @@ def strata_parts(
85
128
  refused). A recipe that no longer fits falls through to the ranking, and apply refuses the
86
129
  changed plan."""
87
130
  bar, llama_id = llama
131
+ prefer = str(options.get("prefer") or "smartest")
88
132
  skipped: list[str] = []
89
133
  ranked = stack_suite.auto_strata_candidates(
90
134
  facts, llm_rank.strata_bar(bar, options), llama_score=bar, options=options
@@ -92,12 +136,14 @@ def strata_parts(
92
136
  kept = approved_strata_recipe(facts, approved)
93
137
  if kept is not None:
94
138
  ranked = [kept, *(r for r in ranked if r["id"] != kept["id"])]
139
+ fastest_best: tuple[float, Parts, StackOptions] | None = None
95
140
  for recipe in ranked:
96
141
  score = recipe.get("quality", {}).get("score")
142
+ keeping = kept is not None and recipe["id"] == kept["id"]
97
143
  why = (
98
144
  (
99
145
  f"LLM: auto keeps the approved Strata {recipe['id']}"
100
- if kept is not None and recipe["id"] == kept["id"]
146
+ if keeping
101
147
  else f"LLM: auto picks Strata {recipe['id']}"
102
148
  )
103
149
  + f" (installed SimplexAI score {score}"
@@ -106,7 +152,7 @@ def strata_parts(
106
152
  if llama_id
107
153
  else ", no llama.cpp model fits"
108
154
  )
109
- + f", --prefer {options.get('prefer') or 'smartest'})"
155
+ + f", --prefer {prefer})"
110
156
  )
111
157
  try:
112
158
  candidate_options = options.copy()
@@ -120,6 +166,35 @@ def strata_parts(
120
166
  owned_ram=owned_ram,
121
167
  approved=approved,
122
168
  )
169
+ gpu = _part_gpu(facts, parts)
170
+ if (
171
+ not keeping
172
+ and prefer == "concurrent"
173
+ and not _poly_concurrent_ok(recipe, gpu, parts)
174
+ ):
175
+ raise StackError(
176
+ f"{recipe['id']} is offloaded or single-slot on this GPU; "
177
+ "skipped for --prefer concurrent"
178
+ )
179
+ poly_speed: float | None = None
180
+ if not keeping and prefer == "fastest" and llama_id and bar >= 0:
181
+ if not _poly_concurrent_ok(recipe, gpu, parts):
182
+ raise StackError(
183
+ f"{recipe['id']} is offloaded or single-slot on this GPU; "
184
+ "skipped for --prefer fastest"
185
+ )
186
+ poly_speed, _ = _poly_decode_for_gpu(
187
+ facts, recipe, gpu, str(parts["llm"]["model"]["quant"])
188
+ )
189
+ llama_speed = (
190
+ _llama_decode_tok_s(facts, options, llama_id, gpu["index"])
191
+ if gpu is not None
192
+ else None
193
+ )
194
+ if poly_speed is None or (llama_speed is not None and poly_speed <= llama_speed):
195
+ raise StackError(
196
+ f"{recipe['id']} estimated decode speed does not beat llama.cpp {llama_id}"
197
+ )
123
198
  missing = [
124
199
  f for f in parts["llm"]["files"] if f.get("generated") and not preparation.ready(f)
125
200
  ]
@@ -139,8 +214,15 @@ def strata_parts(
139
214
  f"(installed SimplexAI score {score}): {exc}"
140
215
  )
141
216
  continue
217
+ if not keeping and prefer == "fastest" and llama_id and bar >= 0 and poly_speed is not None:
218
+ if fastest_best is None or poly_speed > fastest_best[0]:
219
+ fastest_best = (poly_speed, parts, candidate_options)
220
+ continue
142
221
  options.update(candidate_options)
143
222
  return parts
223
+ if fastest_best is not None:
224
+ options.update(fastest_best[2])
225
+ return fastest_best[1]
144
226
  passed_over.extend(skipped)
145
227
  return None
146
228
 
@@ -197,6 +279,8 @@ def card_fits(
197
279
  previous=lambda *_: None,
198
280
  owned_ram=lambda: 0,
199
281
  )
282
+ if prefer == "concurrent" and not _poly_concurrent_ok(recipe, gpu, parts):
283
+ continue
200
284
  if (
201
285
  share
202
286
  and int(str(parts["budget"].get("vram_needed_bytes") or 0)) > gpu["free_bytes"]
@@ -222,13 +306,14 @@ def card_fits(
222
306
  )
223
307
  except (StackError, PlanError):
224
308
  continue
309
+ est = suite.poly_decode_estimate(recipe, gpu)
225
310
  fits.append(
226
311
  {
227
312
  "id": recipe["id"],
228
313
  "quant": str(parts["llm"]["model"]["quant"]),
229
314
  "quality": recipe["quality"]["score"],
230
- "decode_tok_s": None,
231
- "decode_basis": "unavailable",
315
+ "decode_tok_s": round(est.tok_s, 1) if est is not None else None,
316
+ "decode_basis": est.basis if est is not None else "unavailable",
232
317
  }
233
318
  )
234
319
  return fits
@@ -1,4 +1,4 @@
1
- """Which stack auxiliaries run on the LLM's GPU (roadmap decision 21: embedding and reranker on
1
+ """Which stack auxiliaries run on the LLM's GPU (embedding and reranker on
2
2
  the GPU when they fit, else the CPU).
3
3
 
4
4
  The decision model is placed first (2026-10-30 product decision: decision index before GPU
@@ -3,7 +3,7 @@
3
3
  An uninstall leaves nothing behind but what was downloaded and verified (the model files and
4
4
  the tool and engine archives, so the next install needs no download), the owned manifest that
5
5
  lists them (so ``--purge`` can delete them later) and the permanent empty lock files
6
- (``tools/owned.lock``, WHI-317, and ``engines/.engine.lock``, WHI-759). stack_lifecycle.remove stops and removes the
6
+ (``tools/owned.lock`` and ``engines/.engine.lock``). stack_lifecycle.remove stops and removes the
7
7
  services, the gateway and the tools; ``sweep`` then deletes what only the stack used: the
8
8
  engines its deployments ran that no remaining record names (with their download archives), the
9
9
  saved stack plans with their run records, the cached host facts, and the tool's own directories
@@ -29,7 +29,7 @@ Out = Callable[[str], None]
29
29
  # State this tool writes for a stack and nothing else reads: saved plans, run records, the
30
30
  # apply lock and journal (stacks/), the cached probe (facts/), the view window's profile,
31
31
  # measured per-device decode speeds (warm_speeds.json), and the blind Elo board (arena.json;
32
- # its empty arena.lock stays per WHI-317).
32
+ # its empty arena.lock stays).
33
33
  STACK_STATE = ("stacks", "facts", "view-app", "warm_speeds.json", "arena.json")
34
34
 
35
35
 
@@ -204,8 +204,7 @@ def tidy(base_dirs: Iterable[Path], tools_dir: str | Path = hosts.TOOLS_DIR) ->
204
204
  this tool keeps in the tools directory goes too (another user's files stay where they are),
205
205
  then the tool's own directories (OWN_DIRS) left empty and each base directory left empty.
206
206
  A directory someone else made there stays, empty or not. The manifest's empty
207
- ``owned.lock`` stays: unlinking a lock file lets two writers each hold a "lock" (WHI-317,
208
- .agents/skills/owned-manifest-lock), and ``engines/.engine.lock`` stays for the same reason (WHI-759, ``remote_ops_mirrors.engine_lock``)."""
207
+ ``owned.lock`` stays: unlinking a lock file lets two writers each hold a "lock", and ``engines/.engine.lock`` stays for the same reason (``remote_ops_mirrors.engine_lock``)."""
209
208
  root = Path(hosts.tools_dir(tools_dir)).expanduser()
210
209
  private = root.resolve() / "gateway-home"
211
210
  if not hosts.owned_path(tools_dir).exists() and private.is_dir():
@@ -244,13 +243,6 @@ def finish(
244
243
  return 0
245
244
 
246
245
 
247
- def _same_place(a: str, b: str) -> bool:
248
- def norm(p: str) -> str:
249
- return os.path.normcase(os.path.normpath(os.path.expanduser(p)))
250
-
251
- return norm(a) == norm(b)
252
-
253
-
254
246
  def adopted(members: set[str], dry_run: bool, out: Out) -> hosts.Owned:
255
247
  """The manifest as an uninstall reads it. Each of the stack's deployments is taken from its
256
248
  own record in this state directory: one the manifest does not list yet is added, and one
@@ -259,15 +251,26 @@ def adopted(members: set[str], dry_run: bool, out: Out) -> hosts.Owned:
259
251
  run), and the manifest keeps one entry per name: on home-win a stale entry named a
260
252
  temporary directory, so the uninstall "removed" that and dropped the record of the search
261
253
  server that was running (2026-11-12). The other directory is left alone. ``dry_run`` keeps
262
- the correction in memory."""
254
+ the correction in memory.
255
+
256
+ An adopted entry's phase is its record's (``deployment_lifecycle.advance``): a failed or
257
+ interrupted deploy is adopted FAILED, not LIVE, so an uninstall that stops halfway never
258
+ leaves a failed deployment holding its port, unit and name against a live one."""
263
259
  doc = hosts.load_owned()
264
260
  for record in hosts.records(hosts.LOCAL_ID):
265
261
  plan = record["plan"]
266
262
  name, entry = plan["name"], doc["deployments"].get(plan["name"])
267
263
  if name not in members:
268
264
  continue
269
- if entry is not None and _same_place(entry["deploy_dir"], plan["service"]["deploy_dir"]):
265
+ if entry is not None and deployment_lifecycle.same_dir(
266
+ entry["deploy_dir"], plan["service"]["deploy_dir"]
267
+ ):
270
268
  continue
269
+ event = (
270
+ deployment_lifecycle.Event.DEPLOYED
271
+ if record["ok"]
272
+ else deployment_lifecycle.Event.DEPLOY_FAILED
273
+ )
271
274
  if entry is not None:
272
275
  out(
273
276
  f"- {name}: the manifest named another directory ({entry['deploy_dir']}); this "
@@ -275,13 +278,13 @@ def adopted(members: set[str], dry_run: bool, out: Out) -> hosts.Owned:
275
278
  )
276
279
  # Keep the other directory's manifest entry untouched on disk; remove acts on this
277
280
  # installation's own record in memory only.
278
- doc["deployments"][name] = hosts.owned_entry(plan)
281
+ deployment_lifecycle.advance(doc["deployments"], name, event, hosts.owned_entry(plan))
279
282
  continue
280
283
  if dry_run:
281
- doc["deployments"][name] = hosts.owned_entry(plan)
282
- else:
283
- hosts.own_deployment(plan)
284
- doc = hosts.load_owned()
284
+ deployment_lifecycle.advance(doc["deployments"], name, event, hosts.owned_entry(plan))
285
+ continue
286
+ hosts.own_deployment(plan, ok=record["ok"], adopt=True)
287
+ doc = hosts.load_owned()
285
288
  return doc
286
289
 
287
290
 
@@ -10,61 +10,24 @@ import re
10
10
  import sys
11
11
  from collections.abc import Callable
12
12
  from pathlib import Path
13
- from typing import Any
14
-
15
- from localmodels import (
16
- app,
17
- console,
18
- deploy,
19
- hosts,
20
- stack,
21
- stack_arena,
22
- stack_card,
23
- stack_down,
24
- stack_events,
25
- stack_hardware_text,
26
- stack_ledger,
27
- stack_mcp,
28
- stack_memory,
29
- stack_progress,
30
- stack_rollback,
31
- stack_run,
32
- stack_try,
33
- stack_up,
34
- stack_update,
35
- stack_view_agent,
36
- stack_view_hub_cli,
37
- stack_warm,
38
- stack_whatif,
39
- )
40
- from localmodels import stack_decision as decide
41
- from localmodels import stack_doctor as day2_mod
42
- from localmodels import stack_hardware as hardware
43
- from localmodels import stack_view_serve as board
44
- from localmodels.approval import digest
45
- from localmodels.contracts import decode
46
- from localmodels.plan_envelope import PlanError
47
- from localmodels.probe import HostFacts
48
- from localmodels.stack_args import options_from_args
49
- from localmodels.stack_compose import agent_posture
50
- from localmodels.stack_console import Board
51
- from localmodels.stack_plan import (
52
- StackError,
53
- StackGuardError,
54
- StackOptions,
55
- StackPlan,
56
- StackRecord,
57
- command,
58
- default_options,
59
- guard_details,
60
- )
61
- from localmodels.stack_progress import JsonlObserver
62
- from localmodels.stack_summary import styled, summary
63
- from localmodels.stack_view_service import ServiceError
13
+ from typing import TYPE_CHECKING, Any
14
+
15
+ from localmodels import cli_help, console, stack_args
16
+
17
+ if TYPE_CHECKING:
18
+ from localmodels import stack_events
19
+ from localmodels.probe import HostFacts
20
+ from localmodels.stack_console import Board
21
+ from localmodels.stack_plan import StackOptions, StackPlan, StackRecord
64
22
 
65
23
 
66
24
  def _hardware(facts: HostFacts | None, as_json: bool, unified_memory: str | None = None) -> int:
67
25
  """``stack hardware``: the readings and per-card fits, priced as ``stack plan`` would."""
26
+ from localmodels import app, hosts, stack_hardware_text
27
+ from localmodels import stack_hardware as hardware
28
+ from localmodels.stack_compose import agent_posture
29
+ from localmodels.stack_plan import default_options
30
+
68
31
  options = default_options()
69
32
  if facts is None:
70
33
  with console.status("Probing this computer's hardware…"):
@@ -75,7 +38,7 @@ def _hardware(facts: HostFacts | None, as_json: bool, unified_memory: str | None
75
38
  json.dump(seen, sys.stdout, ensure_ascii=False, indent=1)
76
39
  sys.stdout.write("\n")
77
40
  else:
78
- print("\n".join(stack_hardware_text.lines(seen, command())))
41
+ print("\n".join(stack_hardware_text.lines(seen, cli_help.command())))
79
42
  return 0
80
43
 
81
44
 
@@ -84,27 +47,15 @@ def _hardware(facts: HostFacts | None, as_json: bool, unified_memory: str | None
84
47
  _WAITS = {
85
48
  "status": "Reading each deployment's state and health check…",
86
49
  "verify": "Sending acceptance requests to the running stack…",
87
- "doctor": "Checking services, ports, gateway and tools…",
50
+ "doctor": "Checking services, ports, GPU memory and disk…",
88
51
  "up": "Starting services that are not running and waiting for health checks…",
89
- "down": "Stopping the gateway and the stack's services…",
52
+ "down": "Stopping the stack's services…",
90
53
  }
54
+ _DAY2_ALL = stack_args.DOCTOR_COMMANDS | frozenset(stack_args.DAY2_LOADERS)
91
55
 
92
56
 
93
57
  def day2(args: argparse.Namespace) -> int:
94
- handlers = {
95
- "up": stack_up.cli,
96
- "down": stack_down.cli,
97
- "warm": stack_warm.cli,
98
- "try": stack_try.cli,
99
- "arena": stack_arena.cli,
100
- "ledger": stack_ledger.cli,
101
- "card": stack_card.cli,
102
- "rollback": stack_rollback.cli,
103
- "view": board.cli,
104
- "view-hub": stack_view_hub_cli.cli,
105
- "view-agent": stack_view_agent.cli,
106
- }
107
- run = handlers.get(args.stack_command, day2_mod.cli)
58
+ run: Callable[[argparse.Namespace], int] = stack_args.day2_module(args.stack_command).cli
108
59
  if getattr(args, "json", False) or args.stack_command not in _WAITS:
109
60
  return run(args)
110
61
  with console.status(_WAITS[args.stack_command]):
@@ -114,6 +65,9 @@ def day2(args: argparse.Namespace) -> int:
114
65
  def _mistyped_code(exc: BaseException, plan: StackPlan | None) -> bool:
115
66
  """The approval failed while the plan file is intact: the code given was wrong, so the plan's
116
67
  own apply line can be shown (an edited plan has no valid code to show)."""
68
+ from localmodels.approval import digest
69
+ from localmodels.stack_plan import StackGuardError
70
+
117
71
  return (
118
72
  isinstance(exc, StackGuardError)
119
73
  and exc.cause_code == "STACK_APPROVAL_MISMATCH"
@@ -129,6 +83,12 @@ def apply_cli(
129
83
  apply: Callable[..., StackRecord],
130
84
  report: Callable[..., int],
131
85
  ) -> int:
86
+ from localmodels import stack_progress, stack_run
87
+ from localmodels.plan_envelope import PlanError
88
+ from localmodels.stack_console import Board
89
+ from localmodels.stack_plan import StackError, guard_details
90
+ from localmodels.stack_progress import JsonlObserver
91
+
132
92
  machine = args.json
133
93
  jsonl = getattr(args, "jsonl", False)
134
94
  attempt_ids: list[str] = []
@@ -188,7 +148,7 @@ def apply_cli(
188
148
  if _mistyped_code(exc, loaded):
189
149
  assert loaded is not None
190
150
  print(
191
- f" this plan's apply line: {command()} stack apply {args.plan} "
151
+ f" this plan's apply line: {cli_help.command()} stack apply {args.plan} "
192
152
  f"--approve {loaded['plan_id']}",
193
153
  file=sys.stderr,
194
154
  )
@@ -220,6 +180,7 @@ _PLAN_ERROR_CODES = frozenset(
220
180
  "DISK_INSUFFICIENT",
221
181
  "GPU_CONFLICT",
222
182
  "PORT_PROBE_FAILED",
183
+ "PORTS_IN_USE",
223
184
  }
224
185
  )
225
186
  _SAFE_HOST = re.compile(r"^[A-Za-z0-9](?:[A-Za-z0-9.-]*[A-Za-z0-9])?(?::[0-9]{1,5})?$")
@@ -238,7 +199,9 @@ def _plan_error_payload(exc: BaseException) -> dict[str, object]:
238
199
  "event": "error",
239
200
  "code": code,
240
201
  }
241
- if isinstance(exc, deploy.HubUnreachableError):
202
+ from localmodels.plan_envelope import HubUnreachableError
203
+
204
+ if isinstance(exc, HubUnreachableError):
242
205
  hosts_tried = [
243
206
  host
244
207
  for host, _ in exc.failures
@@ -249,52 +212,77 @@ def _plan_error_payload(exc: BaseException) -> dict[str, object]:
249
212
  return payload
250
213
 
251
214
 
252
- def run_cli(
215
+ def _handled_error_types() -> tuple[type[BaseException], ...]:
216
+ types: list[type[BaseException]] = [ValueError, KeyError]
217
+ for mod_name, attr in (
218
+ ("localmodels.stack_plan", "StackError"),
219
+ ("localmodels.plan_envelope", "PlanError"),
220
+ ("localmodels.stack_view_service", "ServiceError"),
221
+ ):
222
+ mod = sys.modules.get(mod_name)
223
+ if mod is not None and isinstance(cls := getattr(mod, attr, None), type):
224
+ types.append(cls)
225
+ return tuple(types)
226
+
227
+
228
+ def _what_if(args: argparse.Namespace) -> int:
229
+ if getattr(args, "html", None):
230
+ from localmodels import stack_whatif_html
231
+
232
+ return stack_whatif_html.cli_html(args)
233
+ from localmodels import stack_whatif
234
+
235
+ return stack_whatif.cli(args)
236
+
237
+
238
+ def _dispatch_stack(
253
239
  args: argparse.Namespace,
254
240
  *,
255
- build: Callable[..., StackPlan],
256
- save: Callable[[StackPlan, Any], Any],
257
- load: Callable[[Path], StackPlan],
258
- apply: Callable[..., StackRecord],
259
- report: Callable[..., int],
241
+ build: Callable[..., StackPlan] | None = None,
242
+ save: Callable[[StackPlan, Any], Any] | None = None,
243
+ load: Callable[[Path], StackPlan] | None = None,
244
+ apply: Callable[..., StackRecord] | None = None,
245
+ report: Callable[..., int] | None = None,
260
246
  day2_fn: Callable[[argparse.Namespace], int] = day2,
261
247
  ) -> int:
262
248
  if args.stack_command == "capabilities":
249
+ from localmodels import stack_run
250
+
263
251
  stack_run.capabilities()
264
252
  return 0
265
253
  if args.stack_command == "mcp":
254
+ from localmodels import stack_mcp
255
+
266
256
  return stack_mcp.cli(args)
267
257
  try:
268
- if args.stack_command in (
269
- *day2_mod.COMMANDS,
270
- "up",
271
- "down",
272
- "warm",
273
- "try",
274
- "arena",
275
- "ledger",
276
- "card",
277
- "rollback",
278
- "view",
279
- "view-hub",
280
- "view-agent",
281
- ):
258
+ if args.stack_command in _DAY2_ALL:
282
259
  return day2_fn(args)
283
260
  if args.stack_command == "decisions":
261
+ from localmodels import stack_decision as decide
262
+
284
263
  print(decide.listing())
285
264
  return 0
286
265
  if args.stack_command == "memory":
266
+ from localmodels import stack_memory
267
+
287
268
  return stack_memory.cli(args)
288
269
  if args.stack_command == "what-if":
289
- return stack_whatif.cli(args)
290
- facts = (
291
- decode(json.loads(args.facts.read_text(encoding="utf-8")), HostFacts)
292
- if getattr(args, "facts", None)
293
- else None
294
- )
270
+ return _what_if(args)
271
+ facts: HostFacts | None = None
272
+ if getattr(args, "facts", None):
273
+ from localmodels.contracts import decode
274
+ from localmodels.probe import HostFacts as _HostFacts
275
+
276
+ facts = decode(json.loads(args.facts.read_text(encoding="utf-8")), _HostFacts)
295
277
  if args.stack_command == "hardware":
296
278
  return _hardware(facts, args.json, args.unified_memory)
279
+ from localmodels import stack
280
+
297
281
  if args.stack_command == "plan":
282
+ from localmodels import stack_update
283
+ from localmodels.stack_args import options_from_args
284
+ from localmodels.stack_summary import styled, summary
285
+
298
286
  options: StackOptions = stack_update.requested(
299
287
  options_from_args(args), args.update, getattr(args, "component_selections", ())
300
288
  )
@@ -303,23 +291,27 @@ def run_cli(
303
291
  if facts is None
304
292
  else "Pricing the whole stack…"
305
293
  ):
306
- plan = build(options, facts=facts)
307
- path = save(plan, args.out)
294
+ plan = (build or stack.build)(options, facts=facts)
295
+ path = (save or stack.save)(plan, args.out)
308
296
  if args.json:
309
297
  json.dump(plan, sys.stdout, ensure_ascii=False, indent=1)
310
298
  sys.stdout.write("\n")
311
299
  else:
312
300
  print(styled(summary(plan, path)))
313
301
  return 0
314
- return apply_cli(args, load=load, apply=apply, report=report)
315
- except (
316
- StackError,
317
- PlanError,
318
- ServiceError,
319
- ValueError,
320
- KeyError,
321
- ) as exc:
302
+ return apply_cli(
303
+ args,
304
+ load=load or stack.load,
305
+ apply=apply or stack.apply,
306
+ report=report or stack.report,
307
+ )
308
+ except Exception as exc:
309
+ if not isinstance(exc, _handled_error_types()):
310
+ raise
322
311
  if getattr(args, "jsonl", False):
312
+ from localmodels import stack_progress
313
+ from localmodels.stack_plan import guard_details
314
+
323
315
  return stack_progress.error(2, guard_details(exc))
324
316
  if args.stack_command == "plan" and getattr(args, "json", False):
325
317
  print(json.dumps(_plan_error_payload(exc), separators=(",", ":")))
@@ -327,14 +319,27 @@ def run_cli(
327
319
  return 2
328
320
 
329
321
 
330
- def cli(args: argparse.Namespace) -> int:
331
- """Entry point for ``localmodels stack`` subcommands."""
332
- return run_cli(
322
+ def run_cli(
323
+ args: argparse.Namespace,
324
+ *,
325
+ build: Callable[..., StackPlan],
326
+ save: Callable[[StackPlan, Any], Any],
327
+ load: Callable[[Path], StackPlan],
328
+ apply: Callable[..., StackRecord],
329
+ report: Callable[..., int],
330
+ day2_fn: Callable[[argparse.Namespace], int] = day2,
331
+ ) -> int:
332
+ return _dispatch_stack(
333
333
  args,
334
- build=stack.build,
335
- save=stack.save,
336
- load=stack.load,
337
- apply=stack.apply,
338
- report=stack.report,
339
- day2_fn=day2,
334
+ build=build,
335
+ save=save,
336
+ load=load,
337
+ apply=apply,
338
+ report=report,
339
+ day2_fn=day2_fn,
340
340
  )
341
+
342
+
343
+ def cli(args: argparse.Namespace) -> int:
344
+ """Entry point for ``localmodels stack`` subcommands."""
345
+ return _dispatch_stack(args, day2_fn=day2)
@@ -47,7 +47,7 @@ from localmodels import stack_gpu_memory as gpu_memory
47
47
  from localmodels import stack_hardware as hardware
48
48
  from localmodels.approval import digest
49
49
  from localmodels.context_policy import AGENT, AgentPosture, posture_for, window_k
50
- from localmodels.plan_envelope import PlanError, require_free_port, utc_now
50
+ from localmodels.plan_envelope import PlanError, ports_assumed_free, require_free_port, utc_now
51
51
  from localmodels.planning import llm_ram
52
52
  from localmodels.planning.budget import gib, host_ram
53
53
  from localmodels.probe import HostFacts
@@ -117,6 +117,10 @@ def _native_owned(plan: Plan, port: int) -> bool:
117
117
  return False
118
118
 
119
119
 
120
+ def _no_listener(_port: int) -> bool:
121
+ return False
122
+
123
+
120
124
  def compose(
121
125
  facts: HostFacts,
122
126
  options: StackOptions,
@@ -137,9 +141,12 @@ def compose(
137
141
  ) -> StackPlan:
138
142
  """The whole-stack plan from facts read now. Pure apart from the Hub lookups in resolver and
139
143
  the local lookups each keyword stands for (tests replace them); who holds a GPU comes from
140
- the facts' service discovery alone, so saved facts price the host they describe."""
144
+ the facts' service discovery alone, so saved facts price the host they describe. Under
145
+ plan_envelope.assume_ports_free no port is in use."""
141
146
  options = options.copy()
142
147
  owned_ram = cache(owned_ram)
148
+ if ports_assumed_free():
149
+ listening = _no_listener
143
150
  stack_route.validate(options, facts)
144
151
  if error := platform_error(facts["platform"], options.get("profile"), facts["arch"]):
145
152
  raise StackError(error)
@@ -234,7 +241,11 @@ def choose_parts(
234
241
  f"--context sets a llama.cpp LLM's window; the Strata recipe {strata['id']} fixes "
235
242
  "its own. Leave out --context, or name a llama.cpp LLM with --llm"
236
243
  )
237
- stack_debug.check(options, strata is not None)
244
+ stack_debug.check(
245
+ options,
246
+ strata is not None,
247
+ strata_quant=strata["version"] if strata is not None else None,
248
+ )
238
249
  parts: Parts | None = None
239
250
  if options.get("profile") == "macos-mlx-preview":
240
251
  parts = stack_mlx.parts(facts, options, listening=listening, previous=previous)
@@ -299,7 +310,7 @@ def _llama_quality(
299
310
 
300
311
  def agent_posture(options: StackOptions) -> AgentPosture:
301
312
  """The stack's agent posture with the operator's slot count. One slot is allowed since
302
- roadmap decision 26 (the smartest model does not have to serve two requests at once);
313
+ default policy (the smartest model does not have to serve two requests at once);
303
314
  ``--prefer concurrent`` keeps decision 13's two. Images are on unless the plan says
304
315
  otherwise (decision 31); a plan saved before ``--vision`` existed stays text-only. The
305
316
  thinking cap and ``--context``'s window ceiling come from the plan (decision 37)."""
@@ -459,7 +470,7 @@ def _llama_parts(
459
470
  its full size, the LLM is planned again without it (``draft=False``)."""
460
471
  posture = agent_posture(options)
461
472
  if min_prompt_cache or not draft:
462
- # WHI-898: capacity plans for blocked-now hosts price minimum required RAM, not
473
+ # Capacity plans for blocked-now hosts price minimum required RAM, not
463
474
  # optional accelerators that greedily expand into synthetic idle memory.
464
475
  posture = replace(posture, draft="off")
465
476
  aux_notes: list[str] = []