@simplexai/localmodels-linux-x64 0.1.0-dev.32.build.git0f60eee490864cf83e343f8db13a335676a19dd8 → 0.1.0-dev.35

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 (140) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +138 -97
  3. package/modules/localmodels/__init__.py +1 -1
  4. package/modules/localmodels/__main__.py +4 -0
  5. package/modules/localmodels/app.py +7 -2
  6. package/modules/localmodels/approval.py +4 -4
  7. package/modules/localmodels/bifrost_checks.py +121 -3
  8. package/modules/localmodels/bifrost_provider.py +53 -0
  9. package/modules/localmodels/bifrost_unit.py +32 -1
  10. package/modules/localmodels/budget.py +5 -1
  11. package/modules/localmodels/catalog.json +51 -10
  12. package/modules/localmodels/catalog.py +30 -29
  13. package/modules/localmodels/catalog_add.py +1 -0
  14. package/modules/localmodels/cli_parser.py +10 -2
  15. package/modules/localmodels/component.py +7 -1
  16. package/modules/localmodels/decode_calibration.json +6 -0
  17. package/modules/localmodels/decode_calibration.py +104 -0
  18. package/modules/localmodels/deploy.py +44 -7
  19. package/modules/localmodels/deploy_steps.py +10 -1
  20. package/modules/localmodels/engines-strata-0.1.49.2.json +31 -0
  21. package/modules/localmodels/engines.json +57 -1
  22. package/modules/localmodels/engines.py +6 -2
  23. package/modules/localmodels/estimator.py +21 -7
  24. package/modules/localmodels/frontend.py +4 -4
  25. package/modules/localmodels/gateway.py +14 -4
  26. package/modules/localmodels/gateway_app_bifrost.py +4 -3
  27. package/modules/localmodels/gateway_bifrost.py +70 -57
  28. package/modules/localmodels/gateway_probe.py +3 -4
  29. package/modules/localmodels/gguf.py +7 -0
  30. package/modules/localmodels/harness.py +24 -25
  31. package/modules/localmodels/harness_gateway.py +19 -10
  32. package/modules/localmodels/harness_probe.py +33 -6
  33. package/modules/localmodels/hosts.py +73 -9
  34. package/modules/localmodels/install.py +36 -6
  35. package/modules/localmodels/library_cli.py +179 -0
  36. package/modules/localmodels/library_convert.py +132 -0
  37. package/modules/localmodels/library_gateway.py +471 -0
  38. package/modules/localmodels/library_jobs.py +314 -0
  39. package/modules/localmodels/library_model.py +246 -0
  40. package/modules/localmodels/library_pricing.py +347 -0
  41. package/modules/localmodels/library_serve.py +348 -0
  42. package/modules/localmodels/library_state.py +373 -0
  43. package/modules/localmodels/library_status.py +349 -0
  44. package/modules/localmodels/llm_rank.py +16 -2
  45. package/modules/localmodels/memcalc.py +7 -30
  46. package/modules/localmodels/metal.py +26 -0
  47. package/modules/localmodels/plan_envelope.py +4 -1
  48. package/modules/localmodels/preparation.py +49 -0
  49. package/modules/localmodels/probe.py +8 -8
  50. package/modules/localmodels/process_identity.py +536 -9
  51. package/modules/localmodels/quant_formats.py +123 -0
  52. package/modules/localmodels/recommend_cli.py +8 -4
  53. package/modules/localmodels/records.py +1 -0
  54. package/modules/localmodels/remote_ops.py +104 -6
  55. package/modules/localmodels/remote_ops_download.py +17 -2
  56. package/modules/localmodels/remote_ops_prepare.py +406 -0
  57. package/modules/localmodels/remote_ops_remove.py +40 -7
  58. package/modules/localmodels/remote_ops_service.py +110 -8
  59. package/modules/localmodels/remote_ops_verify.py +15 -2
  60. package/modules/localmodels/runtime_auth.py +31 -1
  61. package/modules/localmodels/runtime_cli.py +3 -4
  62. package/modules/localmodels/runtime_io.py +50 -6
  63. package/modules/localmodels/service_autostart.py +45 -1
  64. package/modules/localmodels/service_control.py +13 -0
  65. package/modules/localmodels/service_deployment.py +12 -3
  66. package/modules/localmodels/service_jobs.py +33 -4
  67. package/modules/localmodels/service_probe.py +67 -13
  68. package/modules/localmodels/service_stop.py +152 -0
  69. package/modules/localmodels/service_worker.py +9 -1
  70. package/modules/localmodels/services_cli.py +50 -6
  71. package/modules/localmodels/setup_inspection.py +34 -25
  72. package/modules/localmodels/setup_text.py +118 -0
  73. package/modules/localmodels/sizecalc.py +625 -0
  74. package/modules/localmodels/sizecalc_cli.py +249 -0
  75. package/modules/localmodels/stack.py +69 -17
  76. package/modules/localmodels/stack_args.py +91 -19
  77. package/modules/localmodels/stack_auto.py +78 -0
  78. package/modules/localmodels/stack_binding.py +23 -35
  79. package/modules/localmodels/stack_card.py +195 -0
  80. package/modules/localmodels/stack_cleanup.py +379 -0
  81. package/modules/localmodels/stack_clients.py +4 -1
  82. package/modules/localmodels/stack_compose.py +150 -194
  83. package/modules/localmodels/stack_console.py +2 -0
  84. package/modules/localmodels/stack_decision.py +3 -2
  85. package/modules/localmodels/stack_down.py +189 -0
  86. package/modules/localmodels/stack_events.py +54 -0
  87. package/modules/localmodels/stack_hardware.py +22 -23
  88. package/modules/localmodels/stack_journal.py +29 -8
  89. package/modules/localmodels/stack_ledger.py +411 -0
  90. package/modules/localmodels/stack_lifecycle.py +162 -167
  91. package/modules/localmodels/stack_llm_ram.py +57 -5
  92. package/modules/localmodels/stack_memory.py +721 -0
  93. package/modules/localmodels/stack_picks.py +139 -0
  94. package/modules/localmodels/stack_plan.py +140 -22
  95. package/modules/localmodels/stack_ports.py +22 -0
  96. package/modules/localmodels/stack_preflight.py +699 -0
  97. package/modules/localmodels/stack_review.py +123 -5
  98. package/modules/localmodels/stack_rollback.py +2 -0
  99. package/modules/localmodels/stack_route.py +256 -0
  100. package/modules/localmodels/stack_run.py +11 -0
  101. package/modules/localmodels/stack_suite.py +102 -17
  102. package/modules/localmodels/stack_summary.py +65 -4
  103. package/modules/localmodels/stack_try.py +354 -0
  104. package/modules/localmodels/stack_try_client.py +194 -0
  105. package/modules/localmodels/stack_try_docs.py +139 -0
  106. package/modules/localmodels/stack_up.py +8 -1
  107. package/modules/localmodels/stack_update.py +29 -4
  108. package/modules/localmodels/stack_verify.py +3 -1
  109. package/modules/localmodels/stack_view.py +10 -11
  110. package/modules/localmodels/stack_view_apply.py +4 -2
  111. package/modules/localmodels/stack_view_events.py +2 -1
  112. package/modules/localmodels/stack_view_serve.py +3 -0
  113. package/modules/localmodels/stack_view_text.py +1 -1
  114. package/modules/localmodels/stack_view_words.py +4 -1
  115. package/modules/localmodels/stack_warm.py +574 -0
  116. package/modules/localmodels/stack_whatif.py +558 -0
  117. package/modules/localmodels/suite.py +48 -39
  118. package/modules/localmodels/tool_archive.py +40 -0
  119. package/modules/localmodels/tools.json +8 -0
  120. package/modules/localmodels/transport.py +1 -0
  121. package/modules/localmodels/vision.py +8 -1
  122. package/modules/localmodels/web/sizecalc/app.js +431 -0
  123. package/modules/localmodels/web/sizecalc/calc.js +269 -0
  124. package/modules/localmodels/web/sizecalc/page.html +362 -0
  125. package/modules/localmodels/web/view/ASSET-SOURCES.md +11 -0
  126. package/modules/localmodels/web/view/i18n.js +1 -1
  127. package/modules/localmodels/web/view/logo-claude.svg +3 -0
  128. package/modules/localmodels/web/view/logo-codex.png +0 -0
  129. package/modules/localmodels/web/view/logo-pi.svg +6 -0
  130. package/modules/localmodels/web/view/view.css +4 -0
  131. package/modules/localmodels/web/view/view.js +15 -6
  132. package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev35.dist-info}/METADATA +1 -1
  133. package/modules/simplex_localmodels-0.1.0.dev35.dist-info/RECORD +241 -0
  134. package/package.json +1 -1
  135. package/tool.json +1 -1
  136. package/modules/simplex_localmodels-0.1.0.dev32.dist-info/RECORD +0 -200
  137. /package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev35.dist-info}/WHEEL +0 -0
  138. /package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev35.dist-info}/entry_points.txt +0 -0
  139. /package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev35.dist-info}/licenses/NOTICE +0 -0
  140. /package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev35.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -0,0 +1,139 @@
1
+ """The two LLMs ``stack`` offers for one computer: the smartest that fits, and the fastest.
2
+
3
+ Both come from the per-card lists ``stack hardware`` prints (stack_hardware.llm_fits): validated
4
+ models that pass the agent gate on a card ``--llm auto`` may take, so nothing here prices or
5
+ probes again. ``smartest`` is what ``--prefer smartest`` (the default) installs. ``fastest`` is
6
+ what ``--prefer fastest`` installs: the highest decode speed that fits, whatever its score. One
7
+ pick is returned when the same model is both, or when the faster one gains less than
8
+ WORTH_FASTER. Speeds are the catalog's: measured on the same device model where a measurement
9
+ exists, an estimate otherwise (memory bandwidth over the bytes read per token, with no
10
+ speculative decoding); the basis travels with each pick and is printed. An estimate is not a
11
+ bound: with MTP on, Qwen3.8-27B decoded prose faster than its estimate on local-118 (CYC2).
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ from collections.abc import Sequence
17
+ from typing import TypedDict
18
+
19
+ from localmodels import catalog as cat
20
+ from localmodels import llm_rank
21
+
22
+ # A second choice has to be worth offering: at least this much faster than the smartest.
23
+ WORTH_FASTER = 1.2
24
+ ROLES = ("smartest", "fastest")
25
+
26
+
27
+ class Fit(TypedDict):
28
+ """A validated LLM that passes the agent gate on one card (stack_hardware.llm_fits);
29
+ stack_plan names it LlmFit."""
30
+
31
+ id: str
32
+ quant: str
33
+ quality: int
34
+ decode_tok_s: float # calibrated estimate, or a same-device measurement
35
+ decode_basis: str # a catalog.DECODE_BASES key
36
+
37
+
38
+ class Pick(Fit):
39
+ """One offered LLM. ``role`` is also the ``--prefer`` value that plans it."""
40
+
41
+ role: str
42
+ card: int
43
+ shared: bool # the card runs another program's service: the plan needs --share-gpu
44
+
45
+
46
+ class CardFits(TypedDict):
47
+ """The fields of stack_plan.Card the picks read."""
48
+
49
+ index: int
50
+ free_bytes: int
51
+ auto: bool
52
+ llm: list[Fit]
53
+
54
+
55
+ def picks(cards: Sequence[CardFits], default: str | None = None) -> list[Pick]:
56
+ """The smartest fitting LLM, then the fastest when it is another model and worth it. Each
57
+ model counts on the first card that holds it, in the order ``--llm auto`` tries cards (most
58
+ free memory first); ``default`` is the small-Mac default (llm_rank.mac_default). When every
59
+ card that holds a model runs another program's service (a shared Mac's one GPU), the picks
60
+ are what sharing it would install and say so. Empty when nothing validated fits."""
61
+ free = [c for c in cards if c["auto"] and c["llm"]]
62
+ found: dict[str, Pick] = {}
63
+ for card in sorted(free or cards, key=lambda c: (-c["free_bytes"], c["index"])):
64
+ for fit in card["llm"]:
65
+ found.setdefault(
66
+ fit["id"], {**fit, "role": "", "card": card["index"], "shared": not free}
67
+ )
68
+ if not found:
69
+ return []
70
+ ranked = [((p["quality"], p["decode_tok_s"]), p["id"], p["card"]) for p in found.values()]
71
+ smartest = found[llm_rank.choose(ranked, "smartest", default)[0]]
72
+ fastest = found[llm_rank.choose(ranked, "fastest")[0]]
73
+ offered: list[Pick] = [{**smartest, "role": "smartest"}]
74
+ if (
75
+ fastest["id"] != smartest["id"]
76
+ and fastest["decode_tok_s"] >= smartest["decode_tok_s"] * WORTH_FASTER
77
+ ):
78
+ offered.append({**fastest, "role": "fastest"})
79
+ return offered
80
+
81
+
82
+ def second(offered: list[Pick], chosen: str) -> Pick | None:
83
+ """The pick to offer beside a plan whose LLM is ``chosen``: the other one. A plan may hold
84
+ an LLM that is neither (a Strata recipe that beat the smartest llama.cpp model): then the
85
+ fastest pick is the other choice."""
86
+ if chosen in [p["id"] for p in offered]:
87
+ others = [p for p in offered if p["id"] != chosen]
88
+ return others[0] if others else None
89
+ return next((p for p in offered if p["role"] == "fastest"), None)
90
+
91
+
92
+ def label(pick: Pick) -> str:
93
+ """One pick in a line: model, score, speed and what the speed rests on."""
94
+ score = f"score {pick['quality']}" if pick["quality"] else "no SimplexAI score"
95
+ measured = pick["decode_basis"] == "measured-decode"
96
+ speed = f"{pick['decode_tok_s']:.0f} tok/s " + ("measured" if measured else "estimated")
97
+ return f"{pick['id']} {pick['quant']} · {score} · {speed}"
98
+
99
+
100
+ def lines(offered: list[Pick], command: str | None) -> list[str]:
101
+ """The ``choices`` rows of ``stack hardware``: each pick and the command that installs it;
102
+ ``command`` None on a platform that can read its hardware but not install the stack."""
103
+ if not offered:
104
+ return []
105
+ out: list[str] = []
106
+ for pick in offered:
107
+ option = "" if pick["role"] == "smartest" else f" --prefer {pick['role']}"
108
+ head = " choices " if not out else " "
109
+ how = f"; {command} install{option}" if command else ""
110
+ out.append(f"{head}{pick['role']:<9} {label(pick)}{how}")
111
+ if len(offered) == 1:
112
+ out.append(
113
+ " one choice: no other validated LLM that fits is at least "
114
+ f"{WORTH_FASTER:g}x faster"
115
+ )
116
+ if any(p["shared"] for p in offered):
117
+ out.append(
118
+ " the card runs another program's service: once sharing it is "
119
+ "confirmed, add --share-gpu (with --gpu N on an NVIDIA card)"
120
+ )
121
+ if any(p["decode_basis"] != "measured-decode" for p in offered):
122
+ bases = sorted({p["decode_basis"] for p in offered} - {"measured-decode"})
123
+ out.append(
124
+ " estimated speeds come from "
125
+ + "; ".join(cat.DECODE_BASES[b] for b in bases)
126
+ + ", without speculative decoding; stack warm measures the installed one"
127
+ )
128
+ return out
129
+
130
+
131
+ def alternative_line(offered: list[Pick], chosen: str, command: str) -> str | None:
132
+ """The plan summary's pointer to the other choice, None when the plan has no second pick."""
133
+ other = second(offered, chosen)
134
+ if other is None:
135
+ return None
136
+ return (
137
+ f" choice also fits, {other['role']}: {label(other)}; plan it with "
138
+ f"{command} stack plan --prefer {other['role']}"
139
+ )
@@ -12,12 +12,14 @@ 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, reuse, vision
15
+ from localmodels import approval, deploy, gateway, harness, hosts, preparation, reuse, vision
16
16
  from localmodels.budget import gib
17
+ from localmodels.gateway_bifrost import FAST_PROVIDER
17
18
  from localmodels.plan_envelope import PlanError, resolved_name
18
19
  from localmodels.plan_envelope import verified_in_place as verified_in_place
19
- from localmodels.probe import ServiceManager
20
+ from localmodels.probe import HostFacts, ServiceManager
20
21
  from localmodels.records import Plan, ReleaseEngine
22
+ from localmodels.stack_picks import Fit, Pick
21
23
 
22
24
  SCHEMA = "localmodels.stack-plan/v1"
23
25
  GIB = 1 << 30
@@ -36,6 +38,7 @@ METAL_RAM_FLOOR = 1 * GIB
36
38
  # 2026-11-05) closes its thinking and answers. `--reasoning-budget` overrides it, 0 removes it.
37
39
  REASONING_BUDGET = 8192
38
40
  HARNESS_RAM = 1 * GIB # the gateway (Bifrost or Magpie) plus one client session (estimate)
41
+ FRONT_ENV_BYTES = 200 << 20 # a decision front's environment: 110 MB source archive plus wheels
39
42
 
40
43
 
41
44
  def ram_floor(metal: bool) -> int:
@@ -78,14 +81,22 @@ def guard_details(exc: BaseException) -> dict[str, object]:
78
81
 
79
82
  def platform_error(platform: str, profile: str | None = None, arch: str | None = "") -> str | None:
80
83
  """Executable stack recipes, not the controller's ability to inspect a host: Linux, Apple
81
- Silicon Macs (Metal; an unknown ``arch`` is taken as one) and the explicit Apple Silicon
82
- MLX installation preview."""
84
+ Silicon Macs (Metal; an unknown ``arch`` is taken as one), 64-bit Windows (roadmap decision
85
+ 48; an unknown ``arch`` is taken as x64) and the explicit Apple Silicon MLX installation
86
+ preview."""
83
87
  if profile == "macos-mlx-preview":
84
88
  if platform == "darwin" and arch == "arm64":
85
89
  return None
86
90
  return "macos-mlx-preview supports Apple Silicon macOS only"
87
91
  if platform.startswith("linux"):
88
92
  return None
93
+ if platform == "win32" and arch in (None, "", "x64"):
94
+ return None
95
+ if platform == "win32":
96
+ return (
97
+ "on Windows the local model stack supports 64-bit x64 only; this computer's "
98
+ f"architecture is {arch}. Hardware facts can still be inspected."
99
+ )
89
100
  if platform == "darwin" and arch in (None, "", "arm64"):
90
101
  return None
91
102
  if platform == "darwin":
@@ -94,7 +105,8 @@ def platform_error(platform: str, profile: str | None = None, arch: str | None =
94
105
  f"architecture is {arch}. Hardware facts can still be inspected."
95
106
  )
96
107
  return (
97
- "the local model stack supports Linux and Apple Silicon Macs only; this platform is "
108
+ "the local model stack supports Linux, Apple Silicon Macs and 64-bit Windows only; this"
109
+ " platform is "
98
110
  f"{platform}. Hardware facts can still be inspected."
99
111
  )
100
112
 
@@ -141,10 +153,14 @@ class _OptionsSince20261022(TypedDict, total=False):
141
153
  # "K/V" and the catalog variant. Absent: the plan chooses them, as every older plan did.
142
154
  kv: str
143
155
  quant: str
156
+ route: str # opt-in fastest target for easy Bifrost turns; absent preserves older plans
157
+ llm_fast_port: int # resolved when route is enabled, bound by approval
144
158
 
145
159
 
146
160
  # The scenarios a user picks instead of weights (roadmap decision 26, docs/local-models/model-scoring.md).
147
- PREFERENCES = ("smartest", "concurrent", "fast")
161
+ # Since 2026-11-12 (decision 45): fastest, the highest decode speed that fits whatever its score,
162
+ # the second choice `stack` offers beside smartest (stack_picks).
163
+ PREFERENCES = ("smartest", "concurrent", "fast", "fastest")
148
164
 
149
165
 
150
166
  class StackOptions(_OptionsSince20261022):
@@ -173,14 +189,7 @@ class DecisionOption(TypedDict):
173
189
  commercial_use: bool
174
190
 
175
191
 
176
- class LlmFit(TypedDict):
177
- """A validated LLM that passes the agent gate on one card (stack_hardware.llm_fits)."""
178
-
179
- id: str
180
- quant: str
181
- quality: int
182
- decode_tok_s: float # estimate: bandwidth over bytes read per token, an upper bound
183
- decode_basis: str # a catalog.DECODE_BASES key
192
+ LlmFit = Fit # a validated LLM that passes the agent gate on one card
184
193
 
185
194
 
186
195
  class _CardSince20261028(TypedDict, total=False):
@@ -220,7 +229,13 @@ class _HardwareSince20261031(_HardwareSince20261029, total=False):
220
229
  service_manager: ServiceManager
221
230
 
222
231
 
223
- class Hardware(_HardwareSince20261031):
232
+ class _HardwareSince20261112(_HardwareSince20261031, total=False):
233
+ # The LLMs offered for this computer, smartest first, then the fastest when it is another
234
+ # model (stack_picks.picks). A plan's snapshot keeps them so its summary names the other.
235
+ picks: list[Pick]
236
+
237
+
238
+ class Hardware(_HardwareSince20261112):
224
239
  """What stack_hardware reads from the host; a plan keeps it as ``hardware``."""
225
240
 
226
241
  hostname: str
@@ -238,7 +253,7 @@ class Hardware(_HardwareSince20261031):
238
253
  class UpdateChange(TypedDict):
239
254
  """One component of an update plan against the accepted plan it updates."""
240
255
 
241
- role: str # llm | decision | decision_front | an auxiliary contract
256
+ role: str # llm | llm_fast | decision | decision_front | an auxiliary contract
242
257
  action: str # keep | replace | add | retire
243
258
  old: str | None # its deployment in the base plan
244
259
  new: str | None # its deployment in this plan
@@ -255,6 +270,26 @@ class Update(TypedDict):
255
270
  retire: list[str]
256
271
 
257
272
 
273
+ class PreflightFinding(TypedDict):
274
+ """One read-only check of the computer the plan will run on (stack_preflight)."""
275
+
276
+ check: str # a stable id: preflight.memory, preflight.gpu, ...
277
+ level: str # pass | warn | fail (a str, not a Literal: contracts.decode does not take them)
278
+ detail: str # what was read; never a key, a prompt, an answer or a log line
279
+ fix: str # what to do next; empty when nothing is needed
280
+
281
+
282
+ class Preflight(TypedDict):
283
+ """What ``stack plan`` read about this computer before it asked for approval. An
284
+ observation, like ``hardware``: approving a plan does not bind it, and a changed reading
285
+ never invalidates an approval."""
286
+
287
+ schema: str
288
+ live: bool # False: saved --facts were checked, not this computer now
289
+ counts: dict[str, int] # pass, warn, fail
290
+ findings: list[PreflightFinding]
291
+
292
+
258
293
  class _PlanSince20261022(TypedDict, total=False):
259
294
  decision_front: Plan | None # startlux-decide in front of the decision llama-server
260
295
  # Reserved plans for the background worker: the decision model and its front; on unified
@@ -264,6 +299,9 @@ class _PlanSince20261022(TypedDict, total=False):
264
299
  # Since 2026-10-28: the readings the plan was priced against, shown in its summary; not a
265
300
  # section approval binds.
266
301
  hardware: Hardware
302
+ # Since 2026-11-09: checks of this computer made beside the plan (stack_preflight), shown in
303
+ # its summary; an observation too, never a section approval binds.
304
+ preflight: Preflight
267
305
  update: Update # since 2026-11-03: what an update plan changes against its base
268
306
 
269
307
 
@@ -271,6 +309,7 @@ class _PlanSince20261110(_PlanSince20261022, total=False):
271
309
  # A fresh plan's earlier stack deployments of the same base directory whose roles it takes
272
310
  # over under other names; apply removes them (model files and logs stay) first.
273
311
  replaces: list[str]
312
+ llm_fast: Plan # optional second LLM, only with --route fastest
274
313
 
275
314
 
276
315
  class StackPlan(_PlanSince20261110): # plans saved before 2026-10-22 lack the optional keys
@@ -302,7 +341,13 @@ class DecisionChoice(TypedDict):
302
341
  options: list[DecisionOption]
303
342
 
304
343
 
305
- class Parts(TypedDict):
344
+ class _RouteParts(TypedDict, total=False):
345
+ llm_fast: Plan
346
+ llm_fast_running: bool
347
+ llm_fast_ram: int
348
+
349
+
350
+ class Parts(_RouteParts):
306
351
  """What one branch of ``stack plan`` picks; stack_compose.assemble prices it as one stack."""
307
352
 
308
353
  llm: Plan
@@ -345,6 +390,11 @@ class StackRecord(_RunFields):
345
390
  deployments: list[str] # names of the deployments this apply ran; stack remove's scope
346
391
 
347
392
 
393
+ def default_gateway(platform: str = sys.platform) -> str:
394
+ """Bifrost, except on Windows: no Windows Bifrost build is pinned, Magpie's is (decision 32)."""
395
+ return "magpie" if platform == "win32" else harness.DEFAULT_GATEWAY
396
+
397
+
348
398
  def default_options() -> StackOptions:
349
399
  return {
350
400
  "llm": "auto",
@@ -364,7 +414,7 @@ def default_options() -> StackOptions:
364
414
  "tts": False,
365
415
  "search": True,
366
416
  "reasoning_budget": REASONING_BUDGET,
367
- "gateway": harness.DEFAULT_GATEWAY,
417
+ "gateway": default_gateway(),
368
418
  "vision": vision.DEFAULT,
369
419
  }
370
420
 
@@ -383,6 +433,7 @@ def gateway_lines(plan: StackPlan) -> list[str]:
383
433
  bifrost = harness.gateway_kind(gw) == "bifrost"
384
434
  lines = [
385
435
  f" gateway {'Bifrost' if bifrost else 'Magpie'} {gw['addr']}: {gw['llm_provider']}"
436
+ + (f", {FAST_PROVIDER}" if gw.get("llm_fast") else "")
386
437
  + (f", {gw['decision_provider']}" if gw["decision"] else "")
387
438
  + "".join(f", {pid}" for pid in aux_providers)
388
439
  + (
@@ -407,7 +458,13 @@ def gateway_lines(plan: StackPlan) -> list[str]:
407
458
  def deployments(plan: StackPlan) -> list[Plan]:
408
459
  """Every deployment a stack plan holds: the LLM, the decision model and its front, and the
409
460
  auxiliaries. Planning, apply and stack remove all take a plan's parts from here."""
410
- parts = [plan["llm"], plan["decision"], plan.get("decision_front"), *plan.get("aux", [])]
461
+ parts = [
462
+ plan["llm"],
463
+ plan.get("llm_fast"),
464
+ plan["decision"],
465
+ plan.get("decision_front"),
466
+ *plan.get("aux", []),
467
+ ]
411
468
  return [p for p in parts if p is not None]
412
469
 
413
470
 
@@ -483,17 +540,78 @@ def reuse_copies(
483
540
  for f in part["files"]:
484
541
  copy = copies.get(f["path"].rsplit("/", 1)[-1])
485
542
  if verified_in_place(f) or f.get("reuse"):
486
- saved += f["size_bytes"]
543
+ if not f.get("generated"):
544
+ saved += f["size_bytes"]
487
545
  elif copy:
488
546
  f["reuse"] = copy
489
- saved += f["size_bytes"]
547
+ if not f.get("generated"):
548
+ saved += f["size_bytes"]
490
549
  notes.append(
491
550
  f"reusing {copy} on this computer ({gib(f['size_bytes'])}): its SHA256 is "
492
- "checked first and it is hard-linked only on a match, else downloaded"
551
+ "checked first and it is hard-linked only on a match, else "
552
+ + ("prepared from pinned inputs" if f.get("generated") else "downloaded")
493
553
  )
494
554
  return saved, notes
495
555
 
496
556
 
557
+ def engine_download_bytes(parts: list[Plan]) -> int:
558
+ """Engine archives to fetch, once per engine directory (several components share a build)."""
559
+ by_dir = {
560
+ str(p["engine"].get("dir") or id(p)): sum(a["size_bytes"] for a in p["engine"]["assets"])
561
+ for p in parts
562
+ if p["engine"].get("assets")
563
+ }
564
+ return sum(by_dir.values())
565
+
566
+
567
+ def download_budget(
568
+ facts: HostFacts,
569
+ fresh: list[Plan],
570
+ tools: harness.HarnessPlan,
571
+ front: Plan | None,
572
+ copies: Callable[[dict[str, tuple[int, str]]], dict[str, str]],
573
+ ) -> tuple[dict[str, object], list[str]]:
574
+ """Network and peak disk for fresh components, including verified reuse and preparation."""
575
+ front_env = FRONT_ENV_BYTES if any(front is p for p in fresh) else 0
576
+ # Installed venvs also occupy the installer's cache; engine and tool archives stay on disk.
577
+ venvs = sum(int(str(p["launch"].get("frontend_bytes", 0))) for p in fresh)
578
+ engine_bytes = engine_download_bytes(fresh)
579
+ saved, notes = reuse_copies(fresh, copies)
580
+ preparations = [preparation.cost(p) for p in fresh]
581
+ preparation_downloads = sum(p.download_bytes for p in preparations)
582
+ preparation_disk = sum(p.disk_bytes for p in preparations)
583
+ downloads = (
584
+ sum(p["model"]["download_bytes"] for p in fresh)
585
+ + engine_bytes
586
+ + tools["download_bytes"]
587
+ + front_env
588
+ + venvs
589
+ + preparation_downloads
590
+ - saved
591
+ )
592
+ disk_needed = (
593
+ downloads
594
+ - preparation_downloads
595
+ + preparation_disk
596
+ + engine_bytes
597
+ + tools["download_bytes"]
598
+ + 3 * front_env
599
+ + venvs
600
+ )
601
+ free = facts["disk"]["free_bytes"]
602
+ if free is not None and disk_needed > free:
603
+ raise StackError(
604
+ f"not enough disk space: the stack needs about {gib(disk_needed)}, "
605
+ f"{facts['disk']['path']} has only {gib(free)} free"
606
+ )
607
+ return {
608
+ "disk_free_bytes": free,
609
+ "disk_needed_bytes": disk_needed,
610
+ "download_bytes": downloads,
611
+ "reused_bytes": saved,
612
+ }, notes
613
+
614
+
497
615
  def engine_line(part: Plan) -> str:
498
616
  """The engine the component runs on: a pinned build with what it needs, or a host binary."""
499
617
  e = part["engine"]
@@ -86,6 +86,28 @@ def private_previous(
86
86
  return None
87
87
 
88
88
 
89
+ def failed_own_port(model_ids: Sequence[str], base_dir: str) -> int | None:
90
+ """The port of this root's newest deployment of these models when its last apply failed
91
+ and its directory is still there. Its service can still be running and holding the port; a
92
+ new plan on another port would leave it behind, so the retry replaces it in place (install
93
+ proves the running process is that deployment's before stopping it)."""
94
+ base = Path(base_dir).expanduser().resolve() / "deployments"
95
+ for record in reversed(hosts.records(hosts.LOCAL_ID)):
96
+ plan = record["plan"]
97
+ service = plan["service"]
98
+ directory = Path(service["deploy_dir"]).expanduser().resolve()
99
+ if (
100
+ plan["model"]["id"] not in model_ids
101
+ or directory.parent != base
102
+ or plan["name"] != own_name(plan["model"]["id"], service["port"], base_dir)
103
+ ):
104
+ continue
105
+ if record["ok"] or not (directory / "deployment.json").is_file():
106
+ return None
107
+ return int(service["port"])
108
+ return None
109
+
110
+
89
111
  def loopback_listening(port: int) -> bool:
90
112
  """Keep planning failures typed while sharing the lower-level listener proof."""
91
113
  try: