@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
@@ -12,13 +12,23 @@ from collections.abc import Callable
12
12
  from pathlib import Path
13
13
  from typing import Literal, TypedDict, cast
14
14
 
15
- from localmodels import approval, deploy, gateway, harness, hosts, preparation, reuse, vision
16
- from localmodels.budget import HARNESS_RAM as HARNESS_RAM
17
- from localmodels.budget import RAM_FLOOR as RAM_FLOOR
18
- from localmodels.budget import gib, host_ram, placements
15
+ from localmodels import (
16
+ approval,
17
+ deploy,
18
+ gateway,
19
+ harness,
20
+ hosts,
21
+ magpie_legacy,
22
+ preparation,
23
+ reuse,
24
+ vision,
25
+ )
19
26
  from localmodels.gateway_bifrost import FAST_PROVIDER
20
27
  from localmodels.plan_envelope import PlanError, resolved_name
21
28
  from localmodels.plan_envelope import verified_in_place as verified_in_place
29
+ from localmodels.planning.budget import HARNESS_RAM as HARNESS_RAM
30
+ from localmodels.planning.budget import RAM_FLOOR as RAM_FLOOR
31
+ from localmodels.planning.budget import gib, host_ram, placements
22
32
  from localmodels.probe import HostFacts, ServiceManager
23
33
  from localmodels.records import Plan, ReleaseEngine
24
34
  from localmodels.stack_picks import Fit, Pick
@@ -456,21 +466,16 @@ def gateway_lines(plan: StackPlan) -> list[str]:
456
466
  for p in plan.get("aux", [])
457
467
  if (c := p["endpoint"].get("contract", "")) in gateway.AUX_PROVIDERS
458
468
  ]
459
- bifrost = harness.gateway_kind(gw) == "bifrost"
469
+ adapter = magpie_legacy.of(gw)
460
470
  lines = [
461
- f" gateway {'Bifrost' if bifrost else 'Magpie'} {gw['addr']}: {gw['llm_provider']}"
471
+ f" gateway {adapter.label} {gw['addr']}: {gw['llm_provider']}"
462
472
  + (f", {FAST_PROVIDER}" if gw.get("llm_fast") else "")
463
473
  + (f", {gw['decision_provider']}" if gw["decision"] else "")
464
474
  + "".join(f", {pid}" for pid in aux_providers)
465
- + (
466
- f", routed model {gw['group']}"
467
- + (" (tiered by the decision model)" if gw["decision"] else "")
468
- if bifrost
469
- else f", routing group group/{gw['group']}"
470
- )
475
+ + adapter.routing(gw["group"], tiered=bool(gw["decision"]))
471
476
  + f"; pi default model {gw['pi_model_before'] or 'not set'} → {gw['pi_model']}"
472
477
  ]
473
- if not bifrost:
478
+ if adapter.legacy:
474
479
  return lines + gateway_clients.summary_lines(gw)
475
480
  return lines + [
476
481
  f" gateway {client} default model {before['model'] or 'native default'} → "
@@ -6,7 +6,7 @@ import argparse
6
6
  from collections.abc import Callable, Sequence
7
7
  from pathlib import Path
8
8
 
9
- from localmodels import component, deploy, harness_probe, hosts
9
+ from localmodels import component, deploy, deployment_lifecycle, harness_probe, hosts
10
10
  from localmodels.plan_envelope import PlanError
11
11
  from localmodels.probe import HostFacts
12
12
  from localmodels.records import Plan
@@ -152,7 +152,7 @@ def llm_port(
152
152
  if old is not None and old == plan:
153
153
  from localmodels import stack_lifecycle
154
154
 
155
- if stack_lifecycle.healthy(*stack_lifecycle.liveness(old)):
155
+ if deployment_lifecycle.healthy(*stack_lifecycle.liveness(old)):
156
156
  return port
157
157
  occupied = {s["port"] for s in facts.get("llama_servers") or []}
158
158
  services = facts.get("services")
@@ -30,10 +30,11 @@ import sys
30
30
  from pathlib import Path
31
31
  from typing import cast
32
32
 
33
- from localmodels import deploy, hosts, metal, stack_llm_ram
34
- from localmodels.budget import gib
33
+ from localmodels import deploy, hosts, metal
35
34
  from localmodels.context_policy import AGENT
36
35
  from localmodels.gateway_probe import Finding, finding
36
+ from localmodels.planning import llm_ram
37
+ from localmodels.planning.budget import gib
37
38
  from localmodels.probe import HostFacts
38
39
  from localmodels.stack_plan import Preflight, StackPlan, command, deployments, platform_error
39
40
 
@@ -579,7 +580,7 @@ def _reproducible(plan: StackPlan, facts: HostFacts) -> list[Finding]:
579
580
  f"pinned at {_gib(int(metal.assumed_total(facts) or 0))} of unified memory",
580
581
  )
581
582
  ]
582
- cache = stack_llm_ram.prompt_cache_bytes(plan["llm"])
583
+ cache = llm_ram.prompt_cache_bytes(plan["llm"])
583
584
  if cache <= 0 or cache >= (AGENT.prompt_cache_mib << 20):
584
585
  return []
585
586
  ceiling = metal.stable_ceiling(facts)
@@ -9,16 +9,18 @@ from pathlib import Path
9
9
 
10
10
  from localmodels import (
11
11
  deploy,
12
+ deployment_lifecycle,
12
13
  gateway,
13
14
  gateway_probe,
14
15
  harness,
15
16
  harness_core,
16
17
  harness_gateway,
17
18
  hosts,
19
+ magpie_legacy,
18
20
  stack_cleanup,
19
21
  )
20
- from localmodels.budget import gib
21
22
  from localmodels.contracts import decode
23
+ from localmodels.planning.budget import gib
22
24
  from localmodels.records import FinishedRecord, Plan
23
25
  from localmodels.remote_ops import RemoveParams, StrataPreparation
24
26
  from localmodels.stack_plan import StackError, command, platform_error
@@ -172,7 +174,8 @@ def remove_services(
172
174
  act: ActFn,
173
175
  ) -> list[gateway.Check]:
174
176
  """Stop and remove each service with its directory. A deployment whose model files stay
175
- remains in the manifest as removed, so a later ``--purge`` finds them."""
177
+ moves to ``Phase.REMOVED`` in the manifest, so a later ``--purge`` finds them; one with
178
+ nothing kept is purged (``deployment_lifecycle``)."""
176
179
  if not all(check["ok"] for check in unwire_checks):
177
180
  return []
178
181
  checks: list[gateway.Check] = []
@@ -204,7 +207,8 @@ def remove_tools(
204
207
  checks: list[gateway.Check] = []
205
208
  notes: list[str] = []
206
209
  started = doc["gateway"]["started"]
207
- ours = next((t for t in doc["tools"] if Path(t["path"]).name in ("magpie", "magpie.exe")), None)
210
+ names = magpie_legacy.MAGPIE_LEGACY.executables
211
+ ours = next((t for t in doc["tools"] if Path(t["path"]).name in names), None)
208
212
  drift = harness.changed(ours) if ours and os.path.lexists(ours["path"]) else None
209
213
  if started and magpie and ours and drift:
210
214
  hosts.own_gateway(hosts.TOOLS_DIR, "started", None)
@@ -250,7 +254,7 @@ def chosen(members: set[str], doc: hosts.Owned, everything: bool, out: Out) -> s
250
254
  selected = set(members)
251
255
  for name, has_record in outside(members, doc).items():
252
256
  entry = doc["deployments"].get(name)
253
- live = entry is not None and not entry["removed"]
257
+ live = deployment_lifecycle.holds_service(entry)
254
258
  here = live and os.path.isdir(os.path.expanduser(doc["deployments"][name]["deploy_dir"]))
255
259
  if everything or (entry is not None and not has_record and not here):
256
260
  if live and not here:
@@ -338,8 +342,11 @@ def run_remove(
338
342
  keep |= {
339
343
  f
340
344
  for n, d in hosts.load_owned()["deployments"].items()
341
- if not d["removed"]
342
- and (n not in entries or not hosts._same_place(d["deploy_dir"], entries[n]["deploy_dir"]))
345
+ if deployment_lifecycle.holds_service(d)
346
+ and (
347
+ n not in entries
348
+ or not deployment_lifecycle.same_dir(d["deploy_dir"], entries[n]["deploy_dir"])
349
+ )
343
350
  for f in d["files"]
344
351
  }
345
352
  found = list_files(executor, entries, plans, keep, purge, act=act)
@@ -7,14 +7,12 @@ from pathlib import Path
7
7
  from typing import TypedDict
8
8
  from urllib.parse import urlsplit, urlunsplit
9
9
 
10
- from localmodels import budget, catalog_license, harness, stack
10
+ from localmodels import catalog_license, magpie_legacy, stack
11
11
  from localmodels.contracts import decode
12
+ from localmodels.planning import budget
12
13
  from localmodels.setup_text import Lang, join, text
13
14
  from localmodels.stack_plan import StackPlan, deployments
14
15
 
15
- # The gateway the plan installs, as the approval screen names it (harness.gateway_kind).
16
- GATEWAY_NAMES = {"bifrost": "Bifrost", "magpie": "Magpie"}
17
-
18
16
 
19
17
  class SelectedGPU(TypedDict):
20
18
  index: int
@@ -196,7 +194,7 @@ def review_plan(path: Path, lang: Lang = "zh") -> StackReview:
196
194
  "downloadBytes": decode(budget["download_bytes"], int),
197
195
  "diskBytes": decode(budget["disk_needed_bytes"], int),
198
196
  "memoryBytes": decode(budget["ram_needed_bytes"], int),
199
- "components": [*components, GATEWAY_NAMES[harness.gateway_kind(gateway)], "Pi"],
197
+ "components": [*components, magpie_legacy.of(gateway).label, "Pi"],
200
198
  "warnings": list(dict.fromkeys(warnings)),
201
199
  "gpus": _gpus(plan),
202
200
  "summary": summarize(plan, lang),
@@ -26,8 +26,8 @@ from typing import TYPE_CHECKING, TypedDict
26
26
  from localmodels import app, component, hosts, stack_hardware, stack_run, stack_update
27
27
  from localmodels import stack_lifecycle as lifecycle
28
28
  from localmodels.approval import digest
29
- from localmodels.budget import gpu_conflicts, gpu_users_unknown, unknown_services
30
29
  from localmodels.contracts import decode
30
+ from localmodels.planning.budget import gpu_conflicts, gpu_users_unknown, unknown_services
31
31
  from localmodels.probe import HostFacts
32
32
  from localmodels.records import Plan
33
33
  from localmodels.stack_compose import loopback_listening
@@ -13,17 +13,18 @@ from localmodels import (
13
13
  component,
14
14
  deploy,
15
15
  hosts,
16
+ magpie_legacy,
16
17
  metal,
17
18
  stack_hardware,
18
- stack_llm_ram,
19
19
  stack_picks,
20
20
  stack_ports,
21
21
  stack_suite,
22
22
  suite,
23
23
  vision,
24
24
  )
25
- from localmodels.budget import gib, holders, placements
26
25
  from localmodels.context_policy import AgentPosture
26
+ from localmodels.planning import llm_ram
27
+ from localmodels.planning.budget import gib, holders, placements
27
28
  from localmodels.probe import HostFacts
28
29
  from localmodels.records import PinnedFile, Plan
29
30
  from localmodels.stack_plan import Hardware, Parts, StackError, StackOptions, own_name
@@ -39,7 +40,7 @@ def validate(options: StackOptions, facts: HostFacts) -> None:
39
40
  raise StackError("--route accepts fastest")
40
41
  if metal.supported(facts):
41
42
  raise StackError("--route fastest is not supported on Metal yet; use one LLM on this Mac")
42
- if options.get("gateway", "magpie") != "bifrost":
43
+ if not magpie_legacy.of_options(options).routes_fastest:
43
44
  raise StackError("--route fastest requires --gateway bifrost; Magpie is not supported")
44
45
  if options["decision"] == "none":
45
46
  raise StackError("--route fastest requires a decision model; use --decision auto or ID")
@@ -173,7 +174,7 @@ def add(
173
174
  (running is not None, 0, parts["ram_available"]),
174
175
  parts["warnings"],
175
176
  posture=posture,
176
- approved_mib=stack_llm_ram.approved_cache_mib(approved, fast),
177
+ approved_mib=llm_ram.approved_cache_mib(approved, fast),
177
178
  reserved_bytes=parts["llm_ram"],
178
179
  fixed_aux=True,
179
180
  )
@@ -16,15 +16,22 @@ from localmodels import catalog as cat
16
16
  from localmodels import cli_help, hosts, llm_rank, metal, stack_ports, suite, vision
17
17
  from localmodels import stack_decision as decide
18
18
  from localmodels import stack_gpu_memory as gpu_memory
19
- from localmodels import stack_llm_ram as llm_ram
20
- from localmodels.budget import busy_cards, gib, holders, host_ram, idle_cards, sharing_cards
21
19
  from localmodels.context_policy import AgentPosture
22
20
  from localmodels.engine_adapters import suite_plan
23
21
  from localmodels.engines import engine_lock_path
24
22
  from localmodels.plan_envelope import PlanError
23
+ from localmodels.planning import llm_ram
24
+ from localmodels.planning.budget import (
25
+ busy_cards,
26
+ gib,
27
+ holders,
28
+ host_ram,
29
+ idle_cards,
30
+ sharing_cards,
31
+ )
32
+ from localmodels.planning.llm_ram import prompt_cache_bytes, prompt_cache_fit
25
33
  from localmodels.probe import GPU, HostFacts
26
34
  from localmodels.records import Plan
27
- from localmodels.stack_llm_ram import prompt_cache_bytes, prompt_cache_fit
28
35
  from localmodels.stack_plan import (
29
36
  HARNESS_RAM,
30
37
  RAM_FLOOR,
@@ -20,8 +20,8 @@ from localmodels import (
20
20
  )
21
21
  from localmodels import stack_decision as decide
22
22
  from localmodels import stack_hardware_text as hardware_text
23
- from localmodels.budget import gib
24
23
  from localmodels.context_policy import window_k
24
+ from localmodels.planning.budget import gib
25
25
  from localmodels.records import Plan
26
26
  from localmodels.stack_plan import (
27
27
  StackPlan,
@@ -28,11 +28,11 @@ from localmodels import (
28
28
  gateway_keys,
29
29
  harness,
30
30
  hosts,
31
+ magpie_legacy,
31
32
  stack_run,
32
33
  stack_suite,
33
34
  stack_try_docs,
34
35
  stack_up,
35
- stack_verify,
36
36
  vision,
37
37
  )
38
38
  from localmodels.records import Plan
@@ -98,22 +98,17 @@ def _installed(mode: str) -> tuple[Gateway, str | None, StackPlan]:
98
98
  or parsed.fragment
99
99
  ):
100
100
  raise StackError(f"The saved gateway address is not local; run {command()} stack doctor.")
101
- if not stack_verify._gateway_up(tools):
101
+ if not gateway.answers(tools):
102
102
  raise StackError(f"The installed gateway is not running; run {command()} stack up.")
103
103
  owned = hosts.load_owned(tools["tools_dir"])
104
- kind = harness.gateway_kind(gw)
104
+ adapter = magpie_legacy.of(gw)
105
105
  if mode == "docs":
106
- wired = (
107
- bifrost_checks.wired_providers(owned)
108
- if kind == "bifrost"
109
- else set(owned["gateway"]["providers"])
110
- )
111
- if gateway.AUX_PROVIDERS["embedding"] not in wired:
106
+ if gateway.AUX_PROVIDERS["embedding"] not in gateway.wired_providers(tools, owned):
112
107
  raise StackError(
113
108
  f"Embedding is not wired to the gateway; run {command()} stack doctor."
114
109
  )
115
- model = gw["group"] if kind == "bifrost" else f"group/{gw['group']}"
116
- client = Gateway(f"http://{gw['addr']}", model, gateway_keys.CALLER_KEY, kind)
110
+ model = adapter.model(gw["group"])
111
+ client = Gateway(f"http://{gw['addr']}", model, gateway_keys.CALLER_KEY, adapter.kind)
117
112
  return client, embedding, plan
118
113
 
119
114
 
@@ -406,7 +401,7 @@ def _answered_by(
406
401
  matched = _model_attribution(stats.response_model, primary, fast, llm_provider)
407
402
  if matched is not None:
408
403
  return matched
409
- if harness.gateway_kind(gw) == "bifrost":
404
+ if magpie_legacy.of(gw).request_log:
410
405
  correlation_ids = ({stats.request_id} if stats.request_id else set()) | stats.response_ids
411
406
  logged = _log_attribution(
412
407
  gw["addr"],
@@ -448,7 +443,7 @@ def cli(args: argparse.Namespace) -> int:
448
443
  routed_chat = args.try_command == "chat" and plan.get("llm_fast") is not None
449
444
  before_logs = (
450
445
  _chat_log_signatures(gw["addr"])
451
- if routed_chat and harness.gateway_kind(gw) == "bifrost"
446
+ if routed_chat and magpie_legacy.of(gw).request_log
452
447
  else set()
453
448
  )
454
449
 
@@ -23,17 +23,19 @@ from localmodels import (
23
23
  app,
24
24
  console,
25
25
  deploy,
26
+ deployment_lifecycle,
26
27
  gateway,
27
28
  harness,
28
29
  hosts,
29
30
  library_convert,
31
+ magpie_legacy,
30
32
  stack_hardware,
31
33
  stack_run,
32
34
  stack_verify,
33
35
  )
34
36
  from localmodels import stack_lifecycle as lifecycle
35
- from localmodels.budget import gpu_conflicts, gpu_users_unknown, unknown_services
36
37
  from localmodels.contracts import decode
38
+ from localmodels.planning.budget import gpu_conflicts, gpu_users_unknown, unknown_services
37
39
  from localmodels.records import Plan
38
40
  from localmodels.stack_plan import (
39
41
  StackError,
@@ -91,7 +93,7 @@ def drift(plan: StackPlan, library: set[str] | frozenset[str] = frozenset()) ->
91
93
  if part["name"] in library:
92
94
  continue
93
95
  record, entry = records.get(part["name"]), owned.get(part["name"])
94
- if record is None or (entry is not None and entry["removed"]):
96
+ if record is None or deployment_lifecycle.is_removed(entry):
95
97
  found.append(f"{part['name']} was removed")
96
98
  elif not record["ok"] or record["plan"] != part:
97
99
  found.append(f"{part['name']} was redeployed since, or its deployment failed")
@@ -247,7 +249,7 @@ def _up(
247
249
  "not started by this tool"
248
250
  )
249
251
  seen = {p["name"]: lifecycle.liveness(p) for p in parts}
250
- stopped = [p for p in parts if seen[p["name"]][0] != "active"]
252
+ stopped = [p for p in parts if deployment_lifecycle.needs_start(seen[p["name"]][0])]
251
253
  executor = hosts.executor(hosts.get_device(hosts.LOCAL_ID))
252
254
  report: dict[str, Part] = {}
253
255
  for part in parts:
@@ -282,7 +284,7 @@ def _up(
282
284
  for part in list(waiting):
283
285
  row = report[part["name"]]
284
286
  row["state"], row["health"] = lifecycle.liveness(part)
285
- if lifecycle.healthy(row["state"], row["health"]):
287
+ if deployment_lifecycle.healthy(row["state"], row["health"]):
286
288
  waiting.remove(part)
287
289
  elif reason := _unstartable(part, row["state"]):
288
290
  row["action"], row["detail"] = "failed", reason
@@ -292,7 +294,7 @@ def _up(
292
294
  else:
293
295
  break
294
296
  ok = gate in ("reused", "started") and all(
295
- r["action"] != "failed" and lifecycle.healthy(r["state"], r["health"])
297
+ r["action"] != "failed" and deployment_lifecycle.healthy(r["state"], r["health"])
296
298
  for r in report.values()
297
299
  )
298
300
  return {
@@ -301,9 +303,7 @@ def _up(
301
303
  "ok": ok,
302
304
  "parts": list(report.values()),
303
305
  "gateway": gate,
304
- "gateway_kind": "Bifrost"
305
- if harness.gateway_kind(plan["harness"]["gateway"]) == "bifrost"
306
- else "Magpie",
306
+ "gateway_kind": magpie_legacy.of(plan["harness"]["gateway"]).label,
307
307
  "notes": notes,
308
308
  }
309
309
 
@@ -311,7 +311,8 @@ def _up(
311
311
  def print_report(report: UpReport, out: Out = print) -> int:
312
312
  t = console.term(sys.stdout)
313
313
  for row in report["parts"]:
314
- mark = t.mark("ok" if lifecycle.healthy(row["state"], row["health"]) else "fail")
314
+ healthy = deployment_lifecycle.healthy(row["state"], row["health"])
315
+ mark = t.mark("ok" if healthy else "fail")
315
316
  did = {"running": "already running", "started": "started", "failed": "failed to start"}[
316
317
  row["action"]
317
318
  ]
@@ -30,6 +30,7 @@ from typing import TYPE_CHECKING, cast
30
30
  from localmodels import (
31
31
  approval,
32
32
  deploy,
33
+ deployment_lifecycle,
33
34
  harness,
34
35
  hosts,
35
36
  metal,
@@ -478,7 +479,7 @@ def stop_replaced(parts: list[Plan]) -> list[str]:
478
479
 
479
480
 
480
481
  def healthy(part: Plan) -> bool:
481
- return lifecycle.healthy(*lifecycle.liveness(part))
482
+ return deployment_lifecycle.healthy(*lifecycle.liveness(part))
482
483
 
483
484
 
484
485
  def current(part: Plan) -> bool:
@@ -15,7 +15,7 @@ from collections.abc import Callable
15
15
  from dataclasses import dataclass
16
16
  from pathlib import Path
17
17
 
18
- from localmodels import deploy_steps, gateway, harness, harness_core, hosts
18
+ from localmodels import deploy_steps, gateway, harness, hosts, magpie_legacy
19
19
  from localmodels import stack_lifecycle as lifecycle
20
20
  from localmodels.gateway import AuxEndpoint, Check
21
21
  from localmodels.records import Plan
@@ -74,27 +74,6 @@ def _readiness(component: str, part: Plan) -> Check:
74
74
  return {"check": name, "ok": ok, "detail": (text.splitlines() or [""])[0][:160]}
75
75
 
76
76
 
77
- def _gateway_up(plan: harness.HarnessPlan) -> bool:
78
- if harness.gateway_kind(plan["gateway"]) == "bifrost":
79
- from localmodels import gateway_bifrost
80
-
81
- try:
82
- record = gateway_bifrost.require_target(plan)
83
- except harness.HarnessError:
84
- return False
85
- return bool(
86
- record
87
- and gateway_bifrost.owned_listener(record)
88
- and gateway_bifrost.healthy(plan["gateway"]["addr"])
89
- )
90
- try:
91
- env = harness.checked_gateway_environment(plan)
92
- except harness.HarnessError:
93
- return False
94
- magpie = harness.tool_path(plan, "magpie")
95
- return harness_core.run_tool([magpie, "healthcheck"], timeout=20, env=env).returncode == 0
96
-
97
-
98
77
  def _accept(
99
78
  plan: harness.HarnessPlan, decision_key: str | None, aux: list[AuxEndpoint]
100
79
  ) -> list[Check]:
@@ -106,7 +85,7 @@ class Effects:
106
85
  """The requests verify sends; a test passes its own."""
107
86
 
108
87
  readiness: Callable[[str, Plan], Check] = _readiness
109
- gateway_up: Callable[[harness.HarnessPlan], bool] = _gateway_up
88
+ gateway_up: Callable[[harness.HarnessPlan], bool] = gateway.answers
110
89
  accept: Callable[[harness.HarnessPlan, str | None, list[AuxEndpoint]], list[Check]] = _accept
111
90
 
112
91
 
@@ -161,18 +140,13 @@ def verify(plan: StackPlan, owned: hosts.Owned, do: Effects = REAL) -> list[Chec
161
140
  }
162
141
  )
163
142
  return checks
164
- bifrost = harness.gateway_kind(gw["gateway"]) == "bifrost"
165
143
  if not do.gateway_up(gw):
166
- name = "Bifrost" if bifrost else "Magpie"
144
+ name = magpie_legacy.of(gw["gateway"]).label
167
145
  detail = f"{name} gateway {gw['gateway']['addr']} did not answer; no check through it"
168
146
  checks.append({"check": "gateway", "ok": False, "detail": detail})
169
147
  return checks
170
148
  served: list[AuxEndpoint] = []
171
- wired = set(owned["gateway"]["providers"])
172
- if bifrost:
173
- from localmodels import bifrost_checks
174
-
175
- wired = bifrost_checks.wired_providers(owned)
149
+ wired = gateway.wired_providers(gw, owned)
176
150
  for part in plan.get("aux", []):
177
151
  contract = part["endpoint"].get("contract", "")
178
152
  pid = gateway.AUX_PROVIDERS.get(contract)
@@ -23,8 +23,10 @@ from typing import Any, cast
23
23
 
24
24
  from localmodels import (
25
25
  app,
26
+ deployment_lifecycle,
26
27
  host_sensors,
27
28
  hosts,
29
+ magpie_legacy,
28
30
  metal,
29
31
  stack_lifecycle,
30
32
  stack_run,
@@ -199,7 +201,7 @@ def _state(liveness: tuple[str, str] | None) -> tuple[str, str]:
199
201
  if liveness is None:
200
202
  return "planned", say("state.undeployed")
201
203
  state, health = liveness
202
- if stack_lifecycle.healthy(state, health):
204
+ if deployment_lifecycle.healthy(state, health):
203
205
  return "serving", health
204
206
  return ("failed" if state == "failed" else "stopped"), health
205
207
 
@@ -578,10 +580,10 @@ def read_live(hw: Hardware | None = None) -> Reading:
578
580
  slots: dict[str, list[Slot]] = {}
579
581
  for task, part in parts_of(plan) if plan else []:
580
582
  entry = owned["deployments"].get(part["name"])
581
- if entry is None or entry["removed"]:
583
+ if not deployment_lifecycle.holds_service(entry):
582
584
  continue # planned, or removed by stack remove: nothing of ours to ask
583
585
  liveness[part["name"]] = stack_lifecycle.liveness(part)
584
- if stack_lifecycle.healthy(*liveness[part["name"]]):
586
+ if deployment_lifecycle.healthy(*liveness[part["name"]]):
585
587
  live[task] = part # measured below: what it holds beside what the plan priced
586
588
  if found := read_metrics(part):
587
589
  counters[part["name"]] = found
@@ -589,7 +591,7 @@ def read_live(hw: Hardware | None = None) -> Reading:
589
591
  slots[part["name"]] = ctx
590
592
  magpie = (
591
593
  plan["harness"]["gateway"]["addr"]
592
- if plan and plan["options"].get("gateway", "magpie") == "magpie"
594
+ if plan and magpie_legacy.of_options(plan["options"]).usage_events
593
595
  else None
594
596
  )
595
597
  events, wf = stack_view_events.read_with_waterfall(owned, magpie) if plan else ([], [])
@@ -6,7 +6,7 @@ from __future__ import annotations
6
6
 
7
7
  from typing import TypedDict, cast
8
8
 
9
- from localmodels import stack_journal
9
+ from localmodels import magpie_legacy, stack_journal
10
10
  from localmodels.records import Plan
11
11
  from localmodels.stack_events import APPLY_ORDER as APPLY_ORDER
12
12
  from localmodels.stack_plan import StackPlan
@@ -47,7 +47,7 @@ def _apply_details(plan: StackPlan) -> dict[str, str]:
47
47
  for part in plan.get("aux", []):
48
48
  found[str(part["endpoint"].get("contract") or "aux")] = part["model"]["id"]
49
49
  gate = plan["harness"]["gateway"]
50
- kind = "Bifrost" if plan["options"].get("gateway") == "bifrost" else "Magpie"
50
+ kind = magpie_legacy.of_options(plan["options"]).label
51
51
  found["gateway"] = f"{kind} {gate['addr']}"
52
52
  found["tools"] = " · ".join(
53
53
  t["tool"] for t in plan["harness"]["tools"] if t["action"] not in ("skip", "reuse")
@@ -17,7 +17,7 @@ import time
17
17
  from collections.abc import Callable
18
18
  from typing import TextIO
19
19
 
20
- from localmodels import console
20
+ from localmodels import console, magpie_legacy
21
21
  from localmodels.stack_view import Component, Figure, Segment, StackView
22
22
  from localmodels.stack_view_events import Event
23
23
  from localmodels.stack_view_words import say
@@ -334,11 +334,7 @@ def _flow(
334
334
  ),
335
335
  ]
336
336
  who = " · ".join(c["name"] for c in view["clients"]) or say("t.clients")
337
- hub = (
338
- f"{'Bifrost' if gw and gw['kind'] == 'bifrost' else 'Magpie'} {gw['addr']}"
339
- if gw
340
- else say("t.gateway")
341
- )
337
+ hub = f"{magpie_legacy.of(gw).label} {gw['addr']}" if gw else say("t.gateway")
342
338
  lines = [
343
339
  f" {paint(say('t.flow'), bold=True)}",
344
340
  f" {who} ──▶ {paint(hub, bold=True)}"
@@ -20,7 +20,7 @@ import time
20
20
  from pathlib import Path
21
21
  from typing import Any, cast
22
22
 
23
- from localmodels import host_sensors, stack_view_gpu, telemetry_math
23
+ from localmodels import host_sensors, magpie_legacy, stack_view_gpu, telemetry_math
24
24
  from localmodels.stack_view_words import say
25
25
 
26
26
  CACHE_NAME = "stack-view-tick-cache.json"
@@ -480,7 +480,7 @@ def _cold_build(
480
480
  magpie_addr: str | None = None
481
481
  if plan is not None:
482
482
  active_bytes = stack_view_llm.active_weight_bytes(plan["llm"])
483
- if plan["options"].get("gateway", "magpie") == "magpie":
483
+ if magpie_legacy.of_options(plan["options"]).usage_events:
484
484
  magpie_addr = plan["harness"]["gateway"]["addr"]
485
485
  for task, part in stack_view.parts_of(plan):
486
486
  endpoints.append(
@@ -49,7 +49,7 @@ WORDS: dict[str, str] = {
49
49
  "part.kv": "KV cache",
50
50
  "part.state": "Recurrent state",
51
51
  "part.compute": "Compute buffer",
52
- "part.draft": "Draft (MTP)",
52
+ "part.draft": "Draft (speculation)",
53
53
  "part.process": "Process overhead",
54
54
  # the plan sandbox (stack_view_sandbox, GET /api/whatif)
55
55
  "sandbox.none": (
@@ -83,7 +83,10 @@ WORDS: dict[str, str] = {
83
83
  "A fixed state per session for the linear-attention layers; does not grow with context."
84
84
  ),
85
85
  "note.compute": "Scratch tensors of the forward pass; grow with the batch and the window.",
86
- "note.draft": "The MTP draft context: guess a few tokens ahead, then verify them at once.",
86
+ "note.draft": (
87
+ "Speculative decoding: an MTP head or a separate draft model guesses a few tokens ahead,"
88
+ " then the LLM verifies them at once."
89
+ ),
87
90
  "note.process": "The fixed cost of the CUDA context and the engine.",
88
91
  # the rest of a card or of the RAM
89
92
  "seg.foreign": "Other programs",
@@ -55,7 +55,7 @@ from localmodels import (
55
55
  stack_verify,
56
56
  stack_warm_store,
57
57
  )
58
- from localmodels.budget import gib
58
+ from localmodels.planning.budget import gib
59
59
  from localmodels.records import Plan
60
60
  from localmodels.stack_plan import StackPlan, command
61
61
 
@@ -9,8 +9,16 @@ from __future__ import annotations
9
9
  import json
10
10
  from pathlib import Path
11
11
 
12
- from localmodels import console, deploy, harness, hosts, recommend_cli, stack, stack_summary
13
- from localmodels.budget import gib
12
+ from localmodels import (
13
+ console,
14
+ deploy,
15
+ hosts,
16
+ magpie_legacy,
17
+ recommend_cli,
18
+ stack,
19
+ stack_summary,
20
+ )
21
+ from localmodels.planning.budget import gib
14
22
  from localmodels.probe import HostFacts
15
23
  from localmodels.recommend import CatalogRow, HostCatalog
16
24
  from localmodels.records import Device, FinishedRecord, Plan, ProgressEvent
@@ -182,9 +190,7 @@ def deploy_confirm_body(plan: Plan, device: str, busy: list[str]) -> list[Line]:
182
190
 
183
191
  def stack_confirm_body(path: Path, plan: stack.StackPlan) -> list[Line]:
184
192
  """Confirmation dialog body for applying a stack plan, naming its actual gateway."""
185
- gw = (
186
- "Bifrost" if harness.gateway_kind(plan["harness"].get("gateway")) == "bifrost" else "Magpie"
187
- )
193
+ gw = magpie_legacy.of(plan["harness"].get("gateway")).label
188
194
  return [
189
195
  (f"{path}", "dim"),
190
196
  (f"将按计划安装工具、部署决策模型与 LLM、接入 {gw} 并修改 pi 默认模型,", "text"),