@simplexai/localmodels-win32-x64 0.1.0-dev.64 → 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 (107) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +105 -102
  3. package/modules/localmodels/__init__.py +1 -1
  4. package/modules/localmodels/__main__.py +2 -2
  5. package/modules/localmodels/approval.py +5 -3
  6. package/modules/localmodels/bifrost_checks.py +2 -1
  7. package/modules/localmodels/catalog.json +4 -2
  8. package/modules/localmodels/catalog.py +2 -1
  9. package/modules/localmodels/catalog_recipes.py +3 -0
  10. package/modules/localmodels/component.py +1 -1
  11. package/modules/localmodels/context_policy.py +1 -1
  12. package/modules/localmodels/custom_probe.py +5 -5
  13. package/modules/localmodels/deploy.py +88 -12
  14. package/modules/localmodels/deployment_lifecycle.py +167 -0
  15. package/modules/localmodels/draft_spec.py +43 -1
  16. package/modules/localmodels/gateway.py +124 -13
  17. package/modules/localmodels/gateway_accept.py +1 -6
  18. package/modules/localmodels/gateway_cli.py +13 -24
  19. package/modules/localmodels/gateway_ops.py +185 -0
  20. package/modules/localmodels/gateway_server.py +3 -2
  21. package/modules/localmodels/harness.py +13 -16
  22. package/modules/localmodels/harness_core.py +4 -9
  23. package/modules/localmodels/harness_gateway.py +4 -3
  24. package/modules/localmodels/hosts.py +22 -34
  25. package/modules/localmodels/library_convert.py +3 -3
  26. package/modules/localmodels/library_custom.py +6 -6
  27. package/modules/localmodels/library_elastic.py +23 -10
  28. package/modules/localmodels/library_jobs.py +13 -3
  29. package/modules/localmodels/library_order.py +4 -3
  30. package/modules/localmodels/library_poly.py +2 -2
  31. package/modules/localmodels/library_pricing.py +34 -318
  32. package/modules/localmodels/library_serve.py +9 -8
  33. package/modules/localmodels/library_smoke.py +8 -1
  34. package/modules/localmodels/library_status.py +16 -16
  35. package/modules/localmodels/llm_rank.py +1 -1
  36. package/modules/localmodels/magpie_legacy.py +160 -0
  37. package/modules/localmodels/magpie_setup.py +6 -1
  38. package/modules/localmodels/pi_profile.py +3 -7
  39. package/modules/localmodels/plan_envelope.py +1 -1
  40. package/modules/localmodels/{budget.py → planning/budget.py} +48 -30
  41. package/modules/localmodels/{stack_llm_ram.py → planning/llm_ram.py} +11 -1
  42. package/modules/localmodels/planning/memory_pools.py +403 -0
  43. package/modules/localmodels/recommend.py +1 -1
  44. package/modules/localmodels/recommend_cli.py +3 -4
  45. package/modules/localmodels/residency_host.py +1 -1
  46. package/modules/localmodels/service_control.py +4 -4
  47. package/modules/localmodels/service_deployment.py +1 -1
  48. package/modules/localmodels/service_wiring.py +17 -19
  49. package/modules/localmodels/setup_inspection.py +1 -1
  50. package/modules/localmodels/setup_inspection_harness.py +1 -1
  51. package/modules/localmodels/setup_upgrade.py +3 -12
  52. package/modules/localmodels/speech_admission.py +1 -1
  53. package/modules/localmodels/speech_jobs.py +2 -1
  54. package/modules/localmodels/speech_model.py +2 -0
  55. package/modules/localmodels/speech_server.py +130 -9
  56. package/modules/localmodels/speech_state.py +11 -0
  57. package/modules/localmodels/speech_worker_sensevoice.py +21 -13
  58. package/modules/localmodels/speech_workers.py +5 -1
  59. package/modules/localmodels/stack.py +2 -5
  60. package/modules/localmodels/stack_auto.py +4 -4
  61. package/modules/localmodels/stack_aux_gpu.py +1 -1
  62. package/modules/localmodels/stack_binding.py +24 -143
  63. package/modules/localmodels/stack_capacity.py +1 -1
  64. package/modules/localmodels/stack_card.py +1 -1
  65. package/modules/localmodels/stack_cleanup.py +3 -3
  66. package/modules/localmodels/stack_client_settings.py +9 -2
  67. package/modules/localmodels/stack_compose.py +35 -6
  68. package/modules/localmodels/stack_console.py +2 -2
  69. package/modules/localmodels/stack_debug.py +1 -1
  70. package/modules/localmodels/stack_decision.py +1 -1
  71. package/modules/localmodels/stack_doctor.py +10 -7
  72. package/modules/localmodels/stack_down.py +3 -3
  73. package/modules/localmodels/stack_gpu_memory.py +1 -1
  74. package/modules/localmodels/stack_hardware.py +3 -3
  75. package/modules/localmodels/stack_hardware_text.py +1 -1
  76. package/modules/localmodels/stack_lifecycle.py +7 -7
  77. package/modules/localmodels/stack_memory.py +1 -1
  78. package/modules/localmodels/stack_mlx.py +1 -1
  79. package/modules/localmodels/stack_plan.py +18 -13
  80. package/modules/localmodels/stack_ports.py +2 -2
  81. package/modules/localmodels/stack_preflight.py +4 -3
  82. package/modules/localmodels/stack_remove.py +13 -6
  83. package/modules/localmodels/stack_review.py +3 -5
  84. package/modules/localmodels/stack_rollback.py +1 -1
  85. package/modules/localmodels/stack_route.py +5 -4
  86. package/modules/localmodels/stack_suite.py +10 -3
  87. package/modules/localmodels/stack_summary.py +1 -1
  88. package/modules/localmodels/stack_try.py +8 -13
  89. package/modules/localmodels/stack_up.py +10 -9
  90. package/modules/localmodels/stack_update.py +2 -1
  91. package/modules/localmodels/stack_verify.py +4 -30
  92. package/modules/localmodels/stack_view.py +6 -4
  93. package/modules/localmodels/stack_view_apply.py +2 -2
  94. package/modules/localmodels/stack_view_text.py +2 -6
  95. package/modules/localmodels/stack_view_tick.py +2 -2
  96. package/modules/localmodels/stack_view_words.py +5 -2
  97. package/modules/localmodels/stack_warm.py +1 -1
  98. package/modules/localmodels/tui_views.py +11 -5
  99. package/modules/{simplex_localmodels-0.1.0.dev64.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/METADATA +1 -1
  100. package/modules/{simplex_localmodels-0.1.0.dev64.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/RECORD +102 -99
  101. package/package.json +1 -1
  102. package/tool.json +1 -1
  103. package/modules/localmodels/library_vram.py +0 -123
  104. /package/modules/{simplex_localmodels-0.1.0.dev64.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/WHEEL +0 -0
  105. /package/modules/{simplex_localmodels-0.1.0.dev64.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/entry_points.txt +0 -0
  106. /package/modules/{simplex_localmodels-0.1.0.dev64.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/licenses/NOTICE +0 -0
  107. /package/modules/{simplex_localmodels-0.1.0.dev64.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
 
@@ -14,7 +14,7 @@ from html import escape
14
14
  from pathlib import Path
15
15
 
16
16
  from localmodels import cli_help, stack_run, stack_up, stack_view_llm, stack_warm, suite
17
- from localmodels.budget import gib
17
+ from localmodels.planning.budget import gib
18
18
  from localmodels.stack_plan import StackError, StackPlan
19
19
 
20
20
 
@@ -21,8 +21,8 @@ import sys
21
21
  from collections.abc import Callable, Iterable, Iterator
22
22
  from pathlib import Path
23
23
 
24
- from localmodels import deploy, hosts
25
- from localmodels.budget import gib
24
+ from localmodels import deploy, deployment_lifecycle, hosts
25
+ from localmodels.planning.budget import gib
26
26
  from localmodels.stack_plan import StackError, platform_error
27
27
 
28
28
  Out = Callable[[str], None]
@@ -293,7 +293,7 @@ def without_others_archives(doc: hosts.Owned, taken: set[str], out: Out) -> host
293
293
  theirs = {
294
294
  Path(os.path.expanduser(d["deploy_dir"])).parent.parent
295
295
  for name, d in doc["deployments"].items()
296
- if name not in taken and not d["removed"]
296
+ if name not in taken and deployment_lifecycle.holds_service(d)
297
297
  }
298
298
  kept = [a for a in doc["archives"] if any(base in Path(a).parents for base in theirs)]
299
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,13 +450,16 @@ 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)
456
- if min_prompt_cache:
462
+ if min_prompt_cache or not draft:
457
463
  # WHI-898: capacity plans for blocked-now hosts price minimum required RAM, not
458
464
  # optional accelerators that greedily expand into synthetic idle memory.
459
465
  posture = replace(posture, draft="off")
@@ -571,6 +577,17 @@ def _llama_parts(
571
577
  posture=ram_posture,
572
578
  approved_mib=approved_mib,
573
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)
574
591
  return {
575
592
  "llm": llm,
576
593
  "llm_running": running_llm is not None,
@@ -583,6 +600,18 @@ def _llama_parts(
583
600
  }
584
601
 
585
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
+
586
615
  def ram_budget(parts: Parts) -> dict[str, int]:
587
616
  """The whole-stack RAM budget, refusing the same shortfall in plans and upgrade advice."""
588
617
  llm, choice, aux = parts["llm"], parts["decision"], parts["aux"]
@@ -703,7 +732,7 @@ def assemble(
703
732
  w.replace("so all hit one LLM at client effort", "each LLM uses client effort")
704
733
  for w in tools_plan["warnings"]
705
734
  ]
706
- if harness.gateway_kind(tools_plan["gateway"]) != "bifrost":
735
+ if magpie_legacy.of(tools_plan["gateway"]).plan_caller_key:
707
736
  tools_plan = gateway_keys.with_caller_key(tools_plan)
708
737
  warnings += tools_plan["warnings"]
709
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
@@ -15,6 +15,7 @@ from localmodels import (
15
15
  bifrost_checks,
16
16
  console,
17
17
  deploy,
18
+ deployment_lifecycle,
18
19
  gateway,
19
20
  gateway_bifrost,
20
21
  gateway_probe,
@@ -30,7 +31,7 @@ from localmodels import (
30
31
  stack_remove,
31
32
  stack_run,
32
33
  )
33
- from localmodels.budget import gib
34
+ from localmodels.planning.budget import gib
34
35
  from localmodels.records import FinishedRecord, Plan, ProgressEvent
35
36
  from localmodels.remote_ops import RemoveParams
36
37
  from localmodels.remote_ops_service import group_pids, listener_problem
@@ -235,10 +236,6 @@ def liveness(plan: Plan) -> tuple[str, str]:
235
236
  return state, _not_serving(plan, state, pid) or _health(plan)
236
237
 
237
238
 
238
- def healthy(state: str, health: str) -> bool:
239
- return state == "active" and health in ("ok", "ready")
240
-
241
-
242
239
  def status_rows(records: list[FinishedRecord]) -> list[Row]:
243
240
  rows: list[Row] = []
244
241
  for record in records:
@@ -304,7 +301,7 @@ def _owned_lines(doc: hosts.Owned) -> list[str]:
304
301
  lines.append(f"{client:<10}default model {receipt['model']}, remove restores the old one")
305
302
  if doc["slices"]:
306
303
  lines.append("slice " + ", ".join(doc["slices"]))
307
- kept = {n: d for n, d in doc["deployments"].items() if d["removed"]}
304
+ kept = {n: d for n, d in doc["deployments"].items() if deployment_lifecycle.is_removed(d)}
308
305
  if kept:
309
306
  files = [p for d in kept.values() for p in [d["deploy_dir"], *d["files"]]]
310
307
  lines.append(
@@ -336,7 +333,10 @@ def status(out: Out = print, as_json: bool = False) -> int:
336
333
  out(start_here())
337
334
  return 0
338
335
  for row in rows:
339
- good, up = row["ok"] and healthy(row["state"], row["health"]), row["state"] == "active"
336
+ good, up = (
337
+ row["ok"] and deployment_lifecycle.healthy(row["state"], row["health"]),
338
+ row["state"] == "active",
339
+ )
340
340
  mark = console.term(sys.stdout).mark("ok" if good else "fail" if up else "skip")
341
341
  pid = f"pid {row['pid']}" if row["pid"] else "no process"
342
342
  out(
@@ -79,7 +79,7 @@ class Posture:
79
79
  vision: str = vision.DEFAULT # one of vision.READERS
80
80
  # --cache-ram; None is the floor the stack guarantees ahead of the window (2048 MiB on a card,
81
81
  # cache_floor_bytes on a Mac). It grows the cache toward AGENT.prompt_cache_mib only from RAM
82
- # left over (stack_llm_ram), so the floor is what has to fit.
82
+ # left over (planning.llm_ram), so the floor is what has to fit.
83
83
  prompt_cache: int | None = None
84
84
 
85
85
 
@@ -12,8 +12,8 @@ from collections.abc import Callable
12
12
  from pathlib import Path
13
13
 
14
14
  from localmodels import catalog, component, deploy, frontend, hosts, llm_rank, stack_ports
15
- from localmodels.budget import host_ram
16
15
  from localmodels.plan_envelope import deployment, hub_url, plan_envelope
16
+ from localmodels.planning.budget import host_ram
17
17
  from localmodels.probe import HostFacts
18
18
  from localmodels.records import Plan, ReusableFile
19
19
  from localmodels.stack_plan import HARNESS_RAM, RAM_FLOOR, Parts, StackError, StackOptions