@simplexai/localmodels-darwin-x64 0.1.0-dev.63 → 0.1.0-dev.65

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 (142) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +140 -130
  3. package/modules/localmodels/__init__.py +1 -1
  4. package/modules/localmodels/__main__.py +2 -2
  5. package/modules/localmodels/app.py +15 -2
  6. package/modules/localmodels/approval.py +5 -3
  7. package/modules/localmodels/bifrost_checks.py +2 -1
  8. package/modules/localmodels/catalog.json +36 -0
  9. package/modules/localmodels/catalog.py +28 -5
  10. package/modules/localmodels/catalog_recipes.py +40 -1
  11. package/modules/localmodels/component.py +1 -1
  12. package/modules/localmodels/context_policy.py +7 -2
  13. package/modules/localmodels/custom_probe.py +5 -5
  14. package/modules/localmodels/debug_mode.py +85 -103
  15. package/modules/localmodels/deploy.py +129 -18
  16. package/modules/localmodels/deployment_lifecycle.py +167 -0
  17. package/modules/localmodels/download-mirrors.json +126 -6
  18. package/modules/localmodels/draft_spec.py +164 -0
  19. package/modules/localmodels/engine_adapters/__init__.py +4 -0
  20. package/modules/localmodels/engine_adapters/auxiliary.py +27 -0
  21. package/modules/localmodels/engine_adapters/base.py +40 -0
  22. package/modules/localmodels/engine_adapters/strata_poly.py +57 -0
  23. package/modules/localmodels/engine_adapters/suite_plan.py +394 -0
  24. package/modules/localmodels/engines-prism-b12178-03ec600.json +7 -7
  25. package/modules/localmodels/gateway.py +124 -13
  26. package/modules/localmodels/gateway_accept.py +1 -6
  27. package/modules/localmodels/gateway_cli.py +13 -24
  28. package/modules/localmodels/gateway_ops.py +185 -0
  29. package/modules/localmodels/gateway_server.py +3 -2
  30. package/modules/localmodels/harness.py +13 -16
  31. package/modules/localmodels/harness_core.py +4 -9
  32. package/modules/localmodels/harness_gateway.py +4 -3
  33. package/modules/localmodels/hosts.py +22 -34
  34. package/modules/localmodels/install.py +15 -0
  35. package/modules/localmodels/library_convert.py +5 -11
  36. package/modules/localmodels/library_custom.py +6 -6
  37. package/modules/localmodels/library_elastic.py +24 -127
  38. package/modules/localmodels/library_jobs.py +14 -5
  39. package/modules/localmodels/library_order.py +4 -3
  40. package/modules/localmodels/library_poly.py +5 -4
  41. package/modules/localmodels/library_pricing.py +80 -255
  42. package/modules/localmodels/library_serve.py +13 -14
  43. package/modules/localmodels/library_smoke.py +8 -1
  44. package/modules/localmodels/library_status.py +16 -16
  45. package/modules/localmodels/llm_rank.py +1 -1
  46. package/modules/localmodels/magpie_legacy.py +160 -0
  47. package/modules/localmodels/magpie_setup.py +6 -1
  48. package/modules/localmodels/memcalc_cli.py +2 -2
  49. package/modules/localmodels/pi_profile.py +3 -7
  50. package/modules/localmodels/plan_envelope.py +1 -1
  51. package/modules/localmodels/planning/__init__.py +3 -0
  52. package/modules/localmodels/{budget.py → planning/budget.py} +48 -30
  53. package/modules/localmodels/{stack_llm_ram.py → planning/llm_ram.py} +11 -1
  54. package/modules/localmodels/{memcalc_load.py → planning/memcalc_load.py} +1 -1
  55. package/modules/localmodels/planning/memory_pools.py +403 -0
  56. package/modules/localmodels/{sizecalc.py → planning/sizecalc.py} +1 -1
  57. package/modules/localmodels/recommend.py +1 -1
  58. package/modules/localmodels/recommend_cli.py +3 -4
  59. package/modules/localmodels/residency_host.py +1 -1
  60. package/modules/localmodels/service_control.py +4 -4
  61. package/modules/localmodels/service_deployment.py +3 -2
  62. package/modules/localmodels/service_wiring.py +17 -19
  63. package/modules/localmodels/setup_inspection.py +1 -1
  64. package/modules/localmodels/setup_inspection_harness.py +1 -1
  65. package/modules/localmodels/setup_upgrade.py +3 -12
  66. package/modules/localmodels/sizecalc_cli.py +10 -2
  67. package/modules/localmodels/speech_admission.py +1 -1
  68. package/modules/localmodels/speech_jobs.py +2 -1
  69. package/modules/localmodels/speech_model.py +2 -0
  70. package/modules/localmodels/speech_server.py +130 -9
  71. package/modules/localmodels/speech_state.py +11 -0
  72. package/modules/localmodels/speech_worker_sensevoice.py +38 -0
  73. package/modules/localmodels/speech_workers.py +5 -1
  74. package/modules/localmodels/stack.py +4 -9
  75. package/modules/localmodels/stack_arena.py +2 -2
  76. package/modules/localmodels/stack_auto.py +5 -5
  77. package/modules/localmodels/stack_aux_gpu.py +5 -3
  78. package/modules/localmodels/stack_binding.py +24 -143
  79. package/modules/localmodels/stack_capacity.py +1 -1
  80. package/modules/localmodels/stack_card.py +3 -3
  81. package/modules/localmodels/stack_cleanup.py +6 -5
  82. package/modules/localmodels/stack_client_settings.py +9 -2
  83. package/modules/localmodels/stack_compose.py +43 -6
  84. package/modules/localmodels/stack_console.py +2 -2
  85. package/modules/localmodels/stack_debug.py +1 -1
  86. package/modules/localmodels/stack_decision.py +1 -1
  87. package/modules/localmodels/stack_doctor.py +10 -7
  88. package/modules/localmodels/stack_down.py +3 -3
  89. package/modules/localmodels/stack_gpu_memory.py +1 -1
  90. package/modules/localmodels/stack_hardware.py +3 -3
  91. package/modules/localmodels/stack_hardware_text.py +1 -1
  92. package/modules/localmodels/stack_ledger.py +2 -1
  93. package/modules/localmodels/stack_lifecycle.py +7 -7
  94. package/modules/localmodels/stack_mcp.py +1 -1
  95. package/modules/localmodels/stack_memory.py +4 -4
  96. package/modules/localmodels/stack_mlx.py +1 -1
  97. package/modules/localmodels/stack_plan.py +18 -13
  98. package/modules/localmodels/stack_ports.py +2 -2
  99. package/modules/localmodels/stack_preflight.py +4 -3
  100. package/modules/localmodels/stack_remove.py +13 -6
  101. package/modules/localmodels/stack_review.py +3 -5
  102. package/modules/localmodels/stack_rollback.py +1 -1
  103. package/modules/localmodels/stack_route.py +5 -4
  104. package/modules/localmodels/stack_run.py +16 -0
  105. package/modules/localmodels/stack_suite.py +14 -6
  106. package/modules/localmodels/stack_summary.py +1 -1
  107. package/modules/localmodels/stack_try.py +10 -14
  108. package/modules/localmodels/stack_up.py +25 -39
  109. package/modules/localmodels/stack_update.py +2 -1
  110. package/modules/localmodels/stack_verify.py +4 -30
  111. package/modules/localmodels/stack_view.py +6 -4
  112. package/modules/localmodels/stack_view_apply.py +2 -2
  113. package/modules/localmodels/stack_view_llm.py +12 -7
  114. package/modules/localmodels/stack_view_text.py +2 -6
  115. package/modules/localmodels/stack_view_tick.py +2 -2
  116. package/modules/localmodels/stack_view_words.py +5 -2
  117. package/modules/localmodels/stack_warm.py +7 -4
  118. package/modules/localmodels/stack_whatif.py +1 -1
  119. package/modules/localmodels/suite.py +6 -334
  120. package/modules/localmodels/tui_views.py +28 -7
  121. package/modules/localmodels/web/index.html +595 -226
  122. package/modules/localmodels/web/sizecalc/app.js +34 -40
  123. package/modules/localmodels/web/sizecalc/calc.js +3 -3
  124. package/modules/localmodels/web/sizecalc/page.html +4 -3
  125. package/modules/localmodels/web/view/fleet.html +18 -3
  126. package/modules/localmodels/web/view/fleet.js +135 -14
  127. package/modules/localmodels/web/view/i18n.js +4 -0
  128. package/modules/localmodels/web/view/index.html +16 -0
  129. package/modules/localmodels/web/view/nav.js +49 -0
  130. package/modules/localmodels/web/view/theme.js +1 -1
  131. package/modules/localmodels/web/view/view.css +51 -15
  132. package/modules/localmodels/web/view/view.js +22 -4
  133. package/modules/{simplex_localmodels-0.1.0.dev63.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/METADATA +1 -1
  134. package/modules/{simplex_localmodels-0.1.0.dev63.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/RECORD +137 -127
  135. package/package.json +1 -1
  136. package/tool.json +1 -1
  137. package/modules/localmodels/library_vram.py +0 -123
  138. /package/modules/localmodels/{memcalc.py → planning/memcalc.py} +0 -0
  139. /package/modules/{simplex_localmodels-0.1.0.dev63.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/WHEEL +0 -0
  140. /package/modules/{simplex_localmodels-0.1.0.dev63.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/entry_points.txt +0 -0
  141. /package/modules/{simplex_localmodels-0.1.0.dev63.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/licenses/NOTICE +0 -0
  142. /package/modules/{simplex_localmodels-0.1.0.dev63.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -9,7 +9,16 @@ import sys
9
9
  from pathlib import Path
10
10
  from typing import TypedDict, cast
11
11
 
12
- from localmodels import harness, harness_core, hosts, runtime_discovery, stack, stack_run
12
+ from localmodels import (
13
+ deployment_lifecycle,
14
+ gateway_ops,
15
+ harness,
16
+ harness_core,
17
+ hosts,
18
+ runtime_discovery,
19
+ stack,
20
+ stack_run,
21
+ )
13
22
  from localmodels import stack_lifecycle as lifecycle
14
23
  from localmodels.setup_text import Lang, text
15
24
  from localmodels.stack_plan import StackPlan, deployments
@@ -44,22 +53,6 @@ def _windows() -> bool:
44
53
  return os.name == "nt"
45
54
 
46
55
 
47
- def _same_path(left: str | Path, right: str | Path) -> bool:
48
- return os.path.normcase(os.path.normpath(os.path.expanduser(str(left)))) == os.path.normcase(
49
- os.path.normpath(os.path.expanduser(str(right)))
50
- )
51
-
52
-
53
- def _same_real_path(left: str | Path, right: str | Path) -> bool:
54
- return os.path.normcase(os.path.realpath(left)) == os.path.normcase(os.path.realpath(right))
55
-
56
-
57
- def _with_path(env: dict[str, str], prefixes: list[str]) -> dict[str, str]:
58
- merged = {key: value for key, value in env.items() if key.upper() != "PATH"}
59
- merged["PATH"] = os.pathsep.join([*prefixes, os.environ.get("PATH", "")])
60
- return merged
61
-
62
-
63
56
  def _reparse_point(info: os.stat_result) -> bool:
64
57
  return bool(getattr(info, "st_file_attributes", 0) & _REPARSE_POINT)
65
58
 
@@ -175,107 +168,30 @@ def _deployments_ready(
175
168
  service = part["service"]
176
169
  if (
177
170
  not entry
178
- or entry["removed"]
171
+ or deployment_lifecycle.is_removed(entry)
179
172
  or entry["service"] != service["name"]
180
173
  or entry["kind"] != service["kind"]
181
174
  # The manifest records the expanded directory (hosts.own_deployment); a plan on
182
175
  # the default base directory names it under "~".
183
- or not _same_path(entry["deploy_dir"], service["deploy_dir"])
176
+ or not gateway_ops.same_path(entry["deploy_dir"], service["deploy_dir"])
184
177
  or entry["port"] != service["port"]
185
178
  ):
186
179
  return False
187
180
  return True
188
181
 
189
182
 
190
- def _bifrost_binding(plan: StackPlan, owned: hosts.Owned, lang: Lang = "zh") -> PiBinding | Reason:
191
- from localmodels import bifrost_pi, gateway_bifrost
192
-
193
- gateway = plan["harness"]["gateway"]
194
- record = owned["gateway"].get("bifrost")
195
- if (
196
- not record
197
- or record["addr"] != gateway["addr"]
198
- # an instance still on an earlier pinned binary is not the approved plan until apply
199
- # restarts it
200
- or not _same_path(record["binary"], harness.tool_path(plan["harness"], "bifrost"))
201
- or not owned["pi"]
202
- or owned["pi"]["model"] != gateway["pi_model"]
203
- ):
204
- return _reason("gateway-ownership", lang)
205
- try:
206
- if gateway_bifrost.require_target(plan["harness"]) != record:
207
- raise harness.HarnessError("Bifrost record changed")
208
- except harness.HarnessError:
209
- return _reason("gateway-ownership", lang, "gateway-record")
210
- executable = Path(harness.tool_path(plan["harness"], "pi"))
211
- profile = bifrost_pi.pi_profile(harness_core.gateway_environment(plan["harness"]))
212
- if not executable.is_absolute() or not profile.is_absolute():
213
- raise ValueError("Pi paths must be absolute")
214
- fingerprint = _profile_fingerprint(executable, profile)
215
- if (
216
- not gateway_bifrost.owned_listener(record)
217
- or not gateway_bifrost.healthy(gateway["addr"])
218
- or bifrost_pi.pi_model(profile) != (gateway["pi_model"])
219
- ):
220
- return _reason("gateway-unavailable", lang)
221
- env = {**harness_core.gateway_environment(plan["harness"]), "PI_CODING_AGENT_DIR": str(profile)}
222
- listed = harness_core.run_tool([str(executable), "--list-models"], timeout=30, env=env)
223
- expected = gateway["pi_model"].split("/", 1)
224
- if listed.returncode != 0 or not any(
225
- len(fields) >= 2 and fields[:2] == expected
226
- for fields in (line.split() for line in listed.stdout.splitlines())
227
- ):
228
- return _reason("pi-model-unavailable", lang)
229
- if _profile_fingerprint(executable, profile) != fingerprint:
230
- return _reason("pi-config-changed", lang)
231
- return {
232
- "executable": str(executable),
233
- "environment": {"PI_CODING_AGENT_DIR": str(profile)},
234
- "configFingerprint": fingerprint,
235
- }
236
-
237
-
238
183
  def _pi_binding(plan: StackPlan, owned: hosts.Owned, lang: Lang = "zh") -> PiBinding | Reason:
239
184
  gateway = plan["harness"]["gateway"]
240
- if harness.gateway_kind(gateway) == "bifrost":
241
- return _bifrost_binding(plan, owned, lang)
242
- if (
243
- owned["gateway"]["group"] != gateway["group"]
244
- or not owned["pi"]
245
- or owned["pi"]["model"] != gateway["pi_model"]
246
- ):
247
- return _reason("gateway-ownership", lang)
185
+ ops = gateway_ops.of(gateway)
186
+ if refusal := ops.pi_owner(plan["harness"], owned):
187
+ return _reason(refusal[0], lang, refusal[1])
248
188
  executable = Path(harness.tool_path(plan["harness"], "pi"))
249
- profile = Path(
250
- harness_core.gateway_environment(plan["harness"])["PI_CODING_AGENT_DIR"]
251
- ).expanduser()
189
+ profile = ops.pi_profile(plan["harness"])
252
190
  if not executable.is_absolute() or not profile.is_absolute():
253
191
  raise ValueError("Pi paths must be absolute")
254
192
  fingerprint = _profile_fingerprint(executable, profile)
255
- magpie = harness.tool_path(plan["harness"], "magpie")
256
- env = {
257
- **_with_path(
258
- harness.checked_gateway_environment(plan["harness"]),
259
- [str(executable.parent), str(Path(magpie).parent)],
260
- ),
261
- "MAGPIE_ADDR": gateway["addr"],
262
- "PI_CODING_AGENT_DIR": str(profile),
263
- }
264
- state = harness.inspect(
265
- env=env,
266
- tools_dir=plan["harness"]["tools_dir"],
267
- approved=plan["harness"],
268
- private_clients=True,
269
- )
270
- if (
271
- not state["gateway_up"]
272
- or state.get("gateway_other_user")
273
- or not state["pi"]
274
- or not state["magpie"]
275
- or not _same_real_path(state["magpie"], magpie)
276
- or not _same_real_path(state["pi"], executable)
277
- or state["pi_model"] != gateway["pi_model"]
278
- ):
193
+ env = ops.pi_env(plan["harness"], owned, executable, profile)
194
+ if env is None:
279
195
  return _reason("gateway-unavailable", lang)
280
196
  listed = harness_core.run_tool([str(executable), "--list-models"], timeout=30, env=env)
281
197
  expected = gateway["pi_model"].split("/", 1)
@@ -316,55 +232,20 @@ def _library_binding(
316
232
  unpoints pi when the last stack LLM leaves, so pi's selection is not checked. The gateway
317
233
  still is while anything the library did not adopt (the decision model, foundation
318
234
  services, the other LLM) routes through it."""
319
- from localmodels import bifrost_pi, gateway_bifrost, stack_verify
235
+ from localmodels import stack_verify
320
236
 
321
237
  if not _stack_installed(plan, owned):
322
238
  return _reason("deployment-unavailable", lang)
323
- gateway = plan["harness"]["gateway"]
239
+ ops = gateway_ops.of(plan["harness"]["gateway"])
324
240
  executable = Path(harness.tool_path(plan["harness"], "pi"))
325
- environment = harness_core.gateway_environment(plan["harness"])
326
- # The profile the stack's own binding reads: a Magpie plan on a shared daemon has none
327
- # (KeyError, unavailable), never the user's ~/.pi/agent.
328
- profile = (
329
- bifrost_pi.pi_profile(environment)
330
- if harness.gateway_kind(gateway) == "bifrost"
331
- else Path(environment["PI_CODING_AGENT_DIR"]).expanduser()
332
- )
241
+ profile = ops.pi_profile(plan["harness"])
333
242
  if not executable.is_absolute() or not profile.is_absolute():
334
243
  raise ValueError("Pi paths must be absolute")
335
244
  fingerprint = _profile_fingerprint(executable, profile)
336
245
  unadopted = any(component not in adopted for component, _ in stack_verify.parts(plan))
337
- pi_points_magpie = harness.gateway_kind(gateway) != "bifrost" and (
338
- bifrost_pi.pi_model(profile) or ""
339
- ).startswith("magpie/")
340
- if unadopted or pi_points_magpie:
341
- if harness.gateway_kind(gateway) == "bifrost":
342
- record = owned["gateway"].get("bifrost")
343
- if not record or record["addr"] != gateway["addr"]:
344
- return _reason("gateway-ownership", lang)
345
- if not gateway_bifrost.owned_listener(record) or not gateway_bifrost.healthy(
346
- gateway["addr"]
347
- ):
348
- return _reason("gateway-unavailable", lang)
349
- else:
350
- if unadopted and owned["gateway"]["group"] != gateway["group"]:
351
- return _reason("gateway-ownership", lang)
352
- magpie = harness.tool_path(plan["harness"], "magpie")
353
- env = {
354
- **_with_path(
355
- harness.checked_gateway_environment(plan["harness"]),
356
- [str(Path(magpie).parent)],
357
- ),
358
- "MAGPIE_ADDR": gateway["addr"],
359
- }
360
- state = harness.inspect(
361
- env=env,
362
- tools_dir=plan["harness"]["tools_dir"],
363
- approved=plan["harness"],
364
- private_clients=True,
365
- )
366
- if not state["gateway_up"] or state.get("gateway_other_user"):
367
- return _reason("gateway-unavailable", lang)
246
+ if unadopted or ops.pi_on_previous(profile):
247
+ if refusal := ops.library_refusal(plan["harness"], owned, unadopted):
248
+ return _reason(refusal, lang)
368
249
  if _profile_fingerprint(executable, profile) != fingerprint:
369
250
  return _reason("pi-config-changed", lang)
370
251
  return {
@@ -11,7 +11,6 @@ from dataclasses import replace
11
11
 
12
12
  from localmodels import catalog as cat
13
13
  from localmodels import component, context_policy, gpu_specs, llm_rank, metal
14
- from localmodels.budget import gib
15
14
  from localmodels.context_policy import AGENT, AgentPosture, cache_floor_bytes, posture_for
16
15
  from localmodels.estimator import (
17
16
  AGENT_VRAM_RESERVE_BYTES,
@@ -20,6 +19,7 @@ from localmodels.estimator import (
20
19
  PhysicsRefusal,
21
20
  )
22
21
  from localmodels.plan_envelope import PlanError
22
+ from localmodels.planning.budget import gib
23
23
  from localmodels.probe import GPU, HostFacts
24
24
  from localmodels.stack_plan import CapacityFit, Hardware, StackOptions
25
25
 
@@ -13,8 +13,8 @@ import math
13
13
  from html import escape
14
14
  from pathlib import Path
15
15
 
16
- from localmodels import cli_help, stack_up, stack_view_llm, stack_warm, suite
17
- from localmodels.budget import gib
16
+ from localmodels import cli_help, stack_run, stack_up, stack_view_llm, stack_warm, suite
17
+ from localmodels.planning.budget import gib
18
18
  from localmodels.stack_plan import StackError, StackPlan
19
19
 
20
20
 
@@ -181,7 +181,7 @@ def add_parser(actions: argparse._SubParsersAction[argparse.ArgumentParser]) ->
181
181
 
182
182
 
183
183
  def cli(args: argparse.Namespace) -> int:
184
- plan = stack_up._accepted()
184
+ plan = stack_run.accepted()
185
185
  if plan is None or stack_up.drift(plan):
186
186
  raise StackError("no unchanged accepted local stack; run stack install or stack up")
187
187
  directory = Path(plan["llm"]["service"]["deploy_dir"]).expanduser()
@@ -2,7 +2,8 @@
2
2
 
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
- lists them (so ``--purge`` can delete them later) and the manifest's empty lock file. stack_lifecycle.remove stops and removes the
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
7
  services, the gateway and the tools; ``sweep`` then deletes what only the stack used: the
7
8
  engines its deployments ran that no remaining record names (with their download archives), the
8
9
  saved stack plans with their run records, the cached host facts, and the tool's own directories
@@ -20,8 +21,8 @@ import sys
20
21
  from collections.abc import Callable, Iterable, Iterator
21
22
  from pathlib import Path
22
23
 
23
- from localmodels import deploy, hosts
24
- from localmodels.budget import gib
24
+ from localmodels import deploy, deployment_lifecycle, hosts
25
+ from localmodels.planning.budget import gib
25
26
  from localmodels.stack_plan import StackError, platform_error
26
27
 
27
28
  Out = Callable[[str], None]
@@ -204,7 +205,7 @@ def tidy(base_dirs: Iterable[Path], tools_dir: str | Path = hosts.TOOLS_DIR) ->
204
205
  then the tool's own directories (OWN_DIRS) left empty and each base directory left empty.
205
206
  A directory someone else made there stays, empty or not. The manifest's empty
206
207
  ``owned.lock`` stays: unlinking a lock file lets two writers each hold a "lock" (WHI-317,
207
- .agents/skills/owned-manifest-lock), so it is the one file an uninstall leaves."""
208
+ .agents/skills/owned-manifest-lock), and ``engines/.engine.lock`` stays for the same reason (WHI-759, ``remote_ops_mirrors.engine_lock``)."""
208
209
  root = Path(hosts.tools_dir(tools_dir)).expanduser()
209
210
  private = root.resolve() / "gateway-home"
210
211
  if not hosts.owned_path(tools_dir).exists() and private.is_dir():
@@ -292,7 +293,7 @@ def without_others_archives(doc: hosts.Owned, taken: set[str], out: Out) -> host
292
293
  theirs = {
293
294
  Path(os.path.expanduser(d["deploy_dir"])).parent.parent
294
295
  for name, d in doc["deployments"].items()
295
- if name not in taken and not d["removed"]
296
+ if name not in taken and deployment_lifecycle.holds_service(d)
296
297
  }
297
298
  kept = [a for a in doc["archives"] if any(base in Path(a).parents for base in theirs)]
298
299
  if not kept:
@@ -12,7 +12,14 @@ import argparse
12
12
  import json
13
13
  import urllib.parse
14
14
 
15
- from localmodels import bifrost_models, gateway_bifrost, harness, hosts, stack_update, vision
15
+ from localmodels import (
16
+ bifrost_models,
17
+ gateway_bifrost,
18
+ hosts,
19
+ magpie_legacy,
20
+ stack_update,
21
+ vision,
22
+ )
16
23
  from localmodels.bifrost_models import StackClients
17
24
  from localmodels.stack_plan import StackError, command
18
25
 
@@ -36,7 +43,7 @@ def settings(base: str | None = None) -> StackClients:
36
43
  f" {command()} install"
37
44
  )
38
45
  gw = plan["harness"]["gateway"]
39
- if harness.gateway_kind(gw) != "bifrost":
46
+ if magpie_legacy.of(gw).legacy:
40
47
  raise StackError(
41
48
  f"the installed stack (plan {plan['plan_id'][:12]}) runs on Magpie; stack clients"
42
49
  " describes a stack on this tool's Bifrost (plan it with --gateway bifrost)"
@@ -22,12 +22,15 @@ from pathlib import Path
22
22
  from localmodels import (
23
23
  approval,
24
24
  deploy,
25
+ deployment_lifecycle,
26
+ draft_spec,
25
27
  gateway_keys,
26
28
  harness,
27
29
  harness_probe,
28
30
  hf_repo,
29
31
  hosts,
30
32
  llm_rank,
33
+ magpie_legacy,
31
34
  metal,
32
35
  process_identity,
33
36
  remote_ops_launchd,
@@ -46,11 +49,11 @@ from localmodels import stack_aux_gpu as aux_gpu
46
49
  from localmodels import stack_decision as decide
47
50
  from localmodels import stack_gpu_memory as gpu_memory
48
51
  from localmodels import stack_hardware as hardware
49
- from localmodels import stack_llm_ram as llm_ram
50
52
  from localmodels.approval import digest
51
- from localmodels.budget import gib, host_ram
52
53
  from localmodels.context_policy import AGENT, AgentPosture, posture_for, window_k
53
54
  from localmodels.plan_envelope import PlanError, require_free_port, utc_now
55
+ from localmodels.planning import llm_ram
56
+ from localmodels.planning.budget import gib, host_ram
54
57
  from localmodels.probe import HostFacts
55
58
  from localmodels.records import PinnedFile, Plan
56
59
  from localmodels.stack_plan import (
@@ -100,7 +103,7 @@ def _native_owned(plan: Plan, port: int) -> bool:
100
103
  argv = [os.path.expanduser(a) for a in plan["service"]["argv"]]
101
104
  return any(
102
105
  process_identity.command_matches(pid, argv) for pid in pids
103
- ) and stack_lifecycle.healthy(*stack_lifecycle.liveness(plan))
106
+ ) and deployment_lifecycle.healthy(*stack_lifecycle.liveness(plan))
104
107
  service = plan["service"]
105
108
  directory = str(Path(service["deploy_dir"]).expanduser())
106
109
  try:
@@ -447,12 +450,19 @@ def _llama_parts(
447
450
  approved: StackPlan | None = None,
448
451
  *,
449
452
  min_prompt_cache: bool = False,
453
+ draft: bool = True,
450
454
  ) -> Parts:
451
455
  """A catalog llama.cpp LLM, the decision model on its card, the auxiliaries in the RAM left.
452
456
  On unified memory the foundations ``--aux`` named are priced first: the LLM, the decision
453
457
  model and the prompt cache's growth are fitted to the RAM those leave (2026-11-01 user
454
- decision: ticked foundations win over the cache beyond its floor and over a larger LLM)."""
458
+ decision: ticked foundations win over the cache beyond its floor and over a larger LLM).
459
+ An optional external drafter (DSpark) comes last: when it would leave the prompt cache below
460
+ its full size, the LLM is planned again without it (``draft=False``)."""
455
461
  posture = agent_posture(options)
462
+ if min_prompt_cache or not draft:
463
+ # WHI-898: capacity plans for blocked-now hosts price minimum required RAM, not
464
+ # optional accelerators that greedily expand into synthetic idle memory.
465
+ posture = replace(posture, draft="off")
456
466
  aux_notes: list[str] = []
457
467
  candidates = stack_suite.aux_plans(
458
468
  facts, options, listening, previous, aux_notes, approved=approved
@@ -494,7 +504,11 @@ def _llama_parts(
494
504
  base_dir=options["base_dir"],
495
505
  hf_download_endpoint=options["hf_endpoint"],
496
506
  hf_api_endpoint=options["hf_endpoint"],
497
- agent=posture if mtp else replace(posture, mtp_draft_depth=0, ubatch_pinned=True),
507
+ agent=(
508
+ posture
509
+ if mtp
510
+ else replace(posture, mtp_draft_depth=0, ubatch_pinned=True, draft="off")
511
+ ),
498
512
  quant=str(options.get("quant") or ""),
499
513
  ),
500
514
  entries=entries,
@@ -563,6 +577,17 @@ def _llama_parts(
563
577
  posture=ram_posture,
564
578
  approved_mib=approved_mib,
565
579
  )
580
+ if (
581
+ draft
582
+ and running_llm is None
583
+ and draft_spec.active(llm["launch"])
584
+ and (
585
+ _approved_without_drafter(approved, llm)
586
+ or (hardware.on_metal(llm) and llm_ram.drafter_costs_cache(llm, ram_posture))
587
+ )
588
+ ):
589
+ reads = (resolver, listening, previous, existing, owned_ram, qa_cpu_decision, approved)
590
+ return _llama_parts(facts, options, *reads, min_prompt_cache=min_prompt_cache, draft=False)
566
591
  return {
567
592
  "llm": llm,
568
593
  "llm_running": running_llm is not None,
@@ -575,6 +600,18 @@ def _llama_parts(
575
600
  }
576
601
 
577
602
 
603
+ def _approved_without_drafter(approved: StackPlan | None, llm: Plan) -> bool:
604
+ """Whether the approved plan runs this same LLM without its optional drafter: apply keeps it
605
+ off, so a little more free RAM than at plan time does not change the approved argv."""
606
+ kept = approved.get("llm") if approved else None
607
+ return (
608
+ isinstance(kept, dict)
609
+ and kept["model"]["id"] == llm["model"]["id"]
610
+ and kept["model"]["quant"] == llm["model"]["quant"]
611
+ and not draft_spec.active(kept["launch"])
612
+ )
613
+
614
+
578
615
  def ram_budget(parts: Parts) -> dict[str, int]:
579
616
  """The whole-stack RAM budget, refusing the same shortfall in plans and upgrade advice."""
580
617
  llm, choice, aux = parts["llm"], parts["decision"], parts["aux"]
@@ -695,7 +732,7 @@ def assemble(
695
732
  w.replace("so all hit one LLM at client effort", "each LLM uses client effort")
696
733
  for w in tools_plan["warnings"]
697
734
  ]
698
- if harness.gateway_kind(tools_plan["gateway"]) != "bifrost":
735
+ if magpie_legacy.of(tools_plan["gateway"]).plan_caller_key:
699
736
  tools_plan = gateway_keys.with_caller_key(tools_plan)
700
737
  warnings += tools_plan["warnings"]
701
738
 
@@ -20,7 +20,7 @@ from dataclasses import dataclass, field
20
20
  from types import TracebackType
21
21
  from typing import TextIO
22
22
 
23
- from localmodels import console, harness, stack_run
23
+ from localmodels import console, magpie_legacy, stack_run
24
24
  from localmodels.stack_events import PublicProgress
25
25
  from localmodels.stack_plan import StackPlan
26
26
 
@@ -78,7 +78,7 @@ def labels(plan: StackPlan) -> list[tuple[str, str]]:
78
78
  for part in plan.get("aux", []):
79
79
  rows.append((str(part["endpoint"].get("contract") or "aux"), part["model"]["id"]))
80
80
  gate = plan["harness"]["gateway"]
81
- kind = "Bifrost" if harness.gateway_kind(gate) == "bifrost" else "Magpie"
81
+ kind = magpie_legacy.of(gate).label
82
82
  rows += [("gateway", f"{kind} {gate['addr']}"), ("acceptance", "end-to-end acceptance")]
83
83
  return rows
84
84
 
@@ -18,10 +18,10 @@ from collections.abc import Mapping
18
18
  from dataclasses import replace
19
19
 
20
20
  from localmodels import catalog as cat
21
- from localmodels.budget import gib
22
21
  from localmodels.context_policy import AgentPosture, window_k
23
22
  from localmodels.estimator import PhysicsRefusal
24
23
  from localmodels.plan_envelope import PlanError
24
+ from localmodels.planning.budget import gib
25
25
  from localmodels.records import Plan
26
26
 
27
27
  Options = Mapping[str, object] # stack_plan.StackOptions, which sits above this module
@@ -30,9 +30,9 @@ from localmodels import (
30
30
  stack_ports,
31
31
  suite,
32
32
  )
33
- from localmodels.budget import gib
34
33
  from localmodels.context_policy import AGENT
35
34
  from localmodels.plan_envelope import PlanError, require_free_port
35
+ from localmodels.planning.budget import gib
36
36
  from localmodels.probe import GPU, HostFacts
37
37
  from localmodels.records import Plan
38
38
  from localmodels.stack_plan import Component, DecisionChoice, DecisionOption, StackPlan, own_name
@@ -25,17 +25,19 @@ from localmodels import (
25
25
  bifrost_checks,
26
26
  console,
27
27
  deploy,
28
+ deployment_lifecycle,
28
29
  gateway_probe,
29
30
  harness,
30
31
  harness_core,
31
32
  hosts,
33
+ magpie_legacy,
32
34
  stack_run,
33
35
  stack_verify,
34
36
  )
35
37
  from localmodels import stack_lifecycle as lifecycle
36
- from localmodels.budget import gib
37
38
  from localmodels.gateway import Check
38
39
  from localmodels.gateway_probe import Finding, Level, finding
40
+ from localmodels.planning.budget import gib
39
41
  from localmodels.records import Plan
40
42
  from localmodels.stack_plan import StackError, StackPlan, command, platform_error, start_here
41
43
  from localmodels.stack_ports import loopback_listening
@@ -351,7 +353,7 @@ def _targets(
351
353
  named = {part["name"] for _, part in found}
352
354
  elsewhere = []
353
355
  for name, entry in doc["deployments"].items():
354
- if entry["removed"] or name in named:
356
+ if deployment_lifecycle.is_removed(entry) or name in named:
355
357
  continue
356
358
  try:
357
359
  part = hosts.record(hosts.LOCAL_ID, name)["plan"]
@@ -490,12 +492,13 @@ def doctor(deep: bool, as_json: bool, out: Callable[[str], None] = print) -> int
490
492
  t = console.term(sys.stdout)
491
493
  out(t.paint(f"stack doctor: {about}", "bold") + f" ({scope})")
492
494
  # The section names the gateway the plan wires, or the one the manifest records.
493
- bifrost = (
494
- harness.gateway_kind(plan["harness"]["gateway"]) == "bifrost"
495
+ gateway = (
496
+ magpie_legacy.of(plan["harness"]["gateway"])
495
497
  if plan
496
- else bifrost_checks.wired(hosts.load_owned())
497
- )
498
- gateway = "Bifrost" if bifrost else "Magpie"
498
+ else magpie_legacy.BIFROST_ADAPTER
499
+ if bifrost_checks.wired(hosts.load_owned())
500
+ else magpie_legacy.MAGPIE_LEGACY
501
+ ).label
499
502
  for prefix, title in SECTIONS.items():
500
503
  section = [f for f in found if f["check"].split(".")[0] == prefix]
501
504
  if section:
@@ -17,6 +17,7 @@ from typing import Literal, TypedDict
17
17
  from localmodels import (
18
18
  console,
19
19
  deploy,
20
+ deployment_lifecycle,
20
21
  gateway,
21
22
  gateway_bifrost,
22
23
  harness,
@@ -30,7 +31,6 @@ from localmodels.stack_plan import StackError, StackPlan, platform_error
30
31
 
31
32
  SCHEMA: Literal["localmodels.stack-down/v1"] = "localmodels.stack-down/v1"
32
33
  Out = Callable[[str], None]
33
- DOWN = ("inactive", "failed", "dead") # service states with no process to stop
34
34
 
35
35
 
36
36
  class Part(TypedDict):
@@ -156,11 +156,11 @@ def _down(out: Out) -> DownReport:
156
156
  "detail": "",
157
157
  }
158
158
  state, _ = lifecycle.liveness(plan)
159
- if state not in DOWN:
159
+ if deployment_lifecycle.needs_stop(state):
160
160
  executor = hosts.executor(hosts.get_device(hosts.LOCAL_ID))
161
161
  event = deploy.service_action(executor, plan, "stop")
162
162
  state, _ = lifecycle.liveness(plan)
163
- failed = event.get("event") == "error" or state not in DOWN
163
+ failed = event.get("event") == "error" or deployment_lifecycle.needs_stop(state)
164
164
  row["action"] = "failed" if failed else "stopped"
165
165
  row["detail"] = (
166
166
  str(event.get("message") or f"service is still {state} after stop")[-300:]
@@ -6,7 +6,7 @@ from __future__ import annotations
6
6
  from typing import cast
7
7
 
8
8
  from localmodels import suite
9
- from localmodels.budget import gib
9
+ from localmodels.planning.budget import gib
10
10
  from localmodels.probe import GPU, HostFacts
11
11
  from localmodels.stack_plan import StackError, StackOptions
12
12
 
@@ -19,15 +19,15 @@ from localmodels import (
19
19
  stack_warm_store,
20
20
  suite,
21
21
  )
22
- from localmodels.budget import (
22
+ from localmodels.context_policy import AgentPosture, posture_for
23
+ from localmodels.estimator import AGENT_VRAM_RESERVE_BYTES
24
+ from localmodels.planning.budget import (
23
25
  gib,
24
26
  holders,
25
27
  host_ram,
26
28
  placements,
27
29
  sharing_cards,
28
30
  )
29
- from localmodels.context_policy import AgentPosture, posture_for
30
- from localmodels.estimator import AGENT_VRAM_RESERVE_BYTES
31
31
  from localmodels.probe import GPU, HostFacts
32
32
  from localmodels.records import Plan
33
33
  from localmodels.stack_capacity import decision_reserve as decision_reserve
@@ -4,11 +4,11 @@ from __future__ import annotations
4
4
 
5
5
  from localmodels import catalog as cat
6
6
  from localmodels import catalog_recipes, console, metal, stack_capacity, stack_hardware
7
- from localmodels.budget import gib
8
7
  from localmodels.estimator import (
9
8
  AGENT_DISPLAY_RESERVE_BYTES,
10
9
  AGENT_VRAM_SAFETY_BYTES,
11
10
  )
11
+ from localmodels.planning.budget import gib
12
12
  from localmodels.records import Plan
13
13
  from localmodels.stack_picks import label as fit_label
14
14
  from localmodels.stack_picks import lines as pick_lines
@@ -23,6 +23,7 @@ from localmodels import (
23
23
  cli_help,
24
24
  http_local,
25
25
  stack_lifecycle,
26
+ stack_run,
26
27
  stack_up,
27
28
  stack_verify,
28
29
  stack_view_gpu,
@@ -431,7 +432,7 @@ def add_parser(actions: argparse._SubParsersAction[argparse.ArgumentParser]) ->
431
432
  def cli(args: argparse.Namespace) -> int:
432
433
  if not 0.1 <= args.seconds <= 60 or not 0.1 <= args.interval <= 60:
433
434
  raise StackError("--seconds and --interval must be between 0.1 and 60")
434
- plan = stack_up._accepted()
435
+ plan = stack_run.accepted()
435
436
  if plan is None or stack_up.drift(plan):
436
437
  raise StackError("no unchanged accepted local stack; run stack install or stack up")
437
438
  report = sample(plan, args.seconds, args.interval)