@simplexai/localmodels-linux-x64 0.1.0-dev.35 → 0.1.0-dev.37

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 (126) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +124 -102
  3. package/kit.py +1 -0
  4. package/modules/localmodels/__init__.py +1 -1
  5. package/modules/localmodels/__main__.py +9 -3
  6. package/modules/localmodels/bifrost_config.py +188 -0
  7. package/modules/localmodels/budget.py +15 -2
  8. package/modules/localmodels/catalog.json +235 -2
  9. package/modules/localmodels/catalog.py +51 -320
  10. package/modules/localmodels/catalog_add.py +2 -8
  11. package/modules/localmodels/catalog_recipes.py +321 -0
  12. package/modules/localmodels/cli_parser.py +4 -1
  13. package/modules/localmodels/console.py +5 -4
  14. package/modules/localmodels/contracts.py +13 -3
  15. package/modules/localmodels/debug_cli.py +158 -0
  16. package/modules/localmodels/debug_mode.py +727 -0
  17. package/modules/localmodels/debug_stub_server.py +192 -0
  18. package/modules/localmodels/decode_calibration.json +1 -1
  19. package/modules/localmodels/decode_calibration.py +34 -17
  20. package/modules/localmodels/engines-strata-0.1.59.1.json +31 -0
  21. package/modules/localmodels/gateway.py +21 -155
  22. package/modules/localmodels/gateway_accept.py +201 -0
  23. package/modules/localmodels/gateway_bifrost.py +19 -184
  24. package/modules/localmodels/gateway_cli.py +11 -4
  25. package/modules/localmodels/gateway_foundations.py +2 -4
  26. package/modules/localmodels/gateway_probe.py +0 -1
  27. package/modules/localmodels/gateway_server.py +2 -3
  28. package/modules/localmodels/gpu_specs.py +12 -0
  29. package/modules/localmodels/guard.py +2 -7
  30. package/modules/localmodels/harness.py +16 -129
  31. package/modules/localmodels/harness_cleanup.py +135 -0
  32. package/modules/localmodels/harness_gateway.py +16 -14
  33. package/modules/localmodels/harness_probe.py +12 -4
  34. package/modules/localmodels/hosts.py +25 -2
  35. package/modules/localmodels/http_local.py +59 -0
  36. package/modules/localmodels/install.py +23 -8
  37. package/modules/localmodels/library_gateway.py +9 -9
  38. package/modules/localmodels/library_jobs.py +76 -27
  39. package/modules/localmodels/library_serve.py +12 -1
  40. package/modules/localmodels/library_state.py +6 -1
  41. package/modules/localmodels/llm_rank.py +155 -7
  42. package/modules/localmodels/metal_probe.py +11 -7
  43. package/modules/localmodels/probe.py +108 -174
  44. package/modules/localmodels/process_identity.py +109 -154
  45. package/modules/localmodels/process_windows.py +86 -0
  46. package/modules/localmodels/recommend.py +32 -3
  47. package/modules/localmodels/recommend_cli.py +14 -6
  48. package/modules/localmodels/remote_ops.py +65 -0
  49. package/modules/localmodels/remote_ops_download.py +2 -2
  50. package/modules/localmodels/remote_ops_prepare.py +19 -0
  51. package/modules/localmodels/remote_ops_service.py +14 -2
  52. package/modules/localmodels/runtime_args.py +10 -3
  53. package/modules/localmodels/runtime_auth.py +5 -9
  54. package/modules/localmodels/runtime_cli.py +128 -129
  55. package/modules/localmodels/runtime_discovery.py +84 -0
  56. package/modules/localmodels/runtime_install.py +101 -0
  57. package/modules/localmodels/runtime_releases.py +302 -0
  58. package/modules/localmodels/service_stop.py +8 -108
  59. package/modules/localmodels/service_upgrade.py +394 -63
  60. package/modules/localmodels/services_cli.py +24 -14
  61. package/modules/localmodels/setup_inspection.py +97 -9
  62. package/modules/localmodels/setup_text.py +7 -0
  63. package/modules/localmodels/sizecalc.py +0 -1
  64. package/modules/localmodels/stack.py +14 -221
  65. package/modules/localmodels/stack_arena.py +732 -0
  66. package/modules/localmodels/stack_args.py +15 -9
  67. package/modules/localmodels/stack_auto.py +384 -3
  68. package/modules/localmodels/stack_aux_gpu.py +4 -3
  69. package/modules/localmodels/stack_capacity.py +138 -0
  70. package/modules/localmodels/stack_cleanup.py +9 -4
  71. package/modules/localmodels/stack_cli.py +286 -0
  72. package/modules/localmodels/stack_compose.py +76 -32
  73. package/modules/localmodels/stack_console.py +9 -6
  74. package/modules/localmodels/stack_hardware.py +96 -270
  75. package/modules/localmodels/stack_hardware_text.py +263 -0
  76. package/modules/localmodels/stack_journal.py +3 -9
  77. package/modules/localmodels/stack_ledger.py +48 -18
  78. package/modules/localmodels/stack_lifecycle.py +33 -312
  79. package/modules/localmodels/stack_mcp.py +729 -0
  80. package/modules/localmodels/stack_memory.py +0 -2
  81. package/modules/localmodels/stack_picks.py +73 -18
  82. package/modules/localmodels/stack_plan.py +23 -5
  83. package/modules/localmodels/stack_preflight.py +11 -19
  84. package/modules/localmodels/stack_remove.py +373 -0
  85. package/modules/localmodels/stack_route.py +101 -17
  86. package/modules/localmodels/stack_suite.py +16 -10
  87. package/modules/localmodels/stack_summary.py +14 -0
  88. package/modules/localmodels/stack_try.py +238 -24
  89. package/modules/localmodels/stack_try_client.py +53 -15
  90. package/modules/localmodels/stack_try_docs.py +2 -2
  91. package/modules/localmodels/stack_view.py +24 -171
  92. package/modules/localmodels/stack_view_access.py +114 -1
  93. package/modules/localmodels/stack_view_agent.py +3 -13
  94. package/modules/localmodels/stack_view_hub.py +9 -10
  95. package/modules/localmodels/stack_view_llm.py +1 -1
  96. package/modules/localmodels/stack_view_sandbox.py +2 -2
  97. package/modules/localmodels/stack_view_schema.py +183 -0
  98. package/modules/localmodels/stack_view_serve.py +7 -1
  99. package/modules/localmodels/stack_view_service.py +1 -2
  100. package/modules/localmodels/stack_view_text.py +13 -9
  101. package/modules/localmodels/stack_warm.py +3 -0
  102. package/modules/localmodels/stack_warm_store.py +517 -0
  103. package/modules/localmodels/tui.py +28 -4
  104. package/modules/localmodels/tui_dialogs.py +136 -0
  105. package/modules/localmodels/tui_modals.py +279 -0
  106. package/modules/localmodels/tui_screen.py +113 -154
  107. package/modules/localmodels/tui_views.py +134 -203
  108. package/modules/localmodels/web/index.html +510 -101
  109. package/modules/localmodels/web/sizecalc/app.js +363 -10
  110. package/modules/localmodels/web/sizecalc/page.html +27 -3
  111. package/modules/localmodels/web/view/fleet.html +11 -2
  112. package/modules/localmodels/web/view/fleet.js +191 -17
  113. package/modules/localmodels/web/view/i18n.js +3 -2
  114. package/modules/localmodels/web/view/index.html +1 -1
  115. package/modules/localmodels/web/view/nav.js +22 -3
  116. package/modules/localmodels/web/view/view.css +63 -18
  117. package/modules/localmodels/web/view/view.js +169 -32
  118. package/modules/{simplex_localmodels-0.1.0.dev35.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/METADATA +1 -1
  119. package/modules/{simplex_localmodels-0.1.0.dev35.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/RECORD +120 -98
  120. package/package.json +1 -1
  121. package/tool.json +1 -1
  122. package/modules/localmodels/engines-strata-0.1.49.1.json +0 -31
  123. /package/modules/{simplex_localmodels-0.1.0.dev35.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/WHEEL +0 -0
  124. /package/modules/{simplex_localmodels-0.1.0.dev35.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/entry_points.txt +0 -0
  125. /package/modules/{simplex_localmodels-0.1.0.dev35.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/licenses/NOTICE +0 -0
  126. /package/modules/{simplex_localmodels-0.1.0.dev35.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -0,0 +1,286 @@
1
+ """Command-line subcommand handlers for ``localmodels stack``."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import contextlib
7
+ import json
8
+ import os
9
+ import sys
10
+ from collections.abc import Callable
11
+ from pathlib import Path
12
+ from typing import Any
13
+
14
+ from localmodels import (
15
+ app,
16
+ console,
17
+ harness,
18
+ hosts,
19
+ stack_arena,
20
+ stack_card,
21
+ stack_client_settings,
22
+ stack_down,
23
+ stack_events,
24
+ stack_ledger,
25
+ stack_mcp,
26
+ stack_memory,
27
+ stack_progress,
28
+ stack_rollback,
29
+ stack_run,
30
+ stack_try,
31
+ stack_up,
32
+ stack_update,
33
+ stack_view_agent,
34
+ stack_view_hub_cli,
35
+ stack_warm,
36
+ stack_whatif,
37
+ )
38
+ from localmodels import stack_decision as decide
39
+ from localmodels import stack_doctor as day2_mod
40
+ from localmodels import stack_hardware as hardware
41
+ from localmodels import stack_view_serve as board
42
+ from localmodels.approval import digest
43
+ from localmodels.contracts import decode
44
+ from localmodels.plan_envelope import PlanError
45
+ from localmodels.probe import HostFacts
46
+ from localmodels.stack_args import options_from_args
47
+ from localmodels.stack_compose import agent_posture
48
+ from localmodels.stack_console import Board
49
+ from localmodels.stack_plan import (
50
+ StackError,
51
+ StackGuardError,
52
+ StackOptions,
53
+ StackPlan,
54
+ StackRecord,
55
+ command,
56
+ default_options,
57
+ guard_details,
58
+ )
59
+ from localmodels.stack_progress import JsonlObserver
60
+ from localmodels.stack_summary import styled, summary
61
+ from localmodels.stack_view_service import ServiceError
62
+
63
+
64
+ def _hardware(facts: HostFacts | None, as_json: bool, unified_memory: str | None = None) -> int:
65
+ """``stack hardware``: the readings and per-card fits, priced as ``stack plan`` would."""
66
+ options = default_options()
67
+ if facts is None:
68
+ with console.status("Probing this computer's hardware…"):
69
+ facts = app.probe(hosts.LOCAL_ID)
70
+ read = hardware.assumed(facts, unified_memory)
71
+ seen = hardware.view(read, options, agent_posture(options))
72
+ if as_json:
73
+ json.dump(seen, sys.stdout, ensure_ascii=False, indent=1)
74
+ sys.stdout.write("\n")
75
+ else:
76
+ print("\n".join(hardware.lines(seen, command())))
77
+ return 0
78
+
79
+
80
+ # Day-2 commands that wait on services get a spinner; remove and rollback may prompt or
81
+ # print a plan, and view draws its own screen, so they do not.
82
+ _WAITS = {
83
+ "status": "Reading each deployment's state and health check…",
84
+ "verify": "Sending acceptance requests to the running stack…",
85
+ "doctor": "Checking services, ports, gateway and tools…",
86
+ "up": "Starting services that are not running and waiting for health checks…",
87
+ "down": "Stopping the gateway and the stack's services…",
88
+ }
89
+
90
+
91
+ def day2(args: argparse.Namespace) -> int:
92
+ handlers = {
93
+ "up": stack_up.cli,
94
+ "down": stack_down.cli,
95
+ "warm": stack_warm.cli,
96
+ "try": stack_try.cli,
97
+ "arena": stack_arena.cli,
98
+ "ledger": stack_ledger.cli,
99
+ "card": stack_card.cli,
100
+ "rollback": stack_rollback.cli,
101
+ "view": board.cli,
102
+ "clients": stack_client_settings.cli,
103
+ "view-hub": stack_view_hub_cli.cli,
104
+ "view-agent": stack_view_agent.cli,
105
+ }
106
+ run = handlers.get(args.stack_command, day2_mod.cli)
107
+ if getattr(args, "json", False) or args.stack_command not in _WAITS:
108
+ return run(args)
109
+ with console.status(_WAITS[args.stack_command]):
110
+ return run(args)
111
+
112
+
113
+ def _mistyped_code(exc: BaseException, plan: StackPlan | None) -> bool:
114
+ """The approval failed while the plan file is intact: the code given was wrong, so the plan's
115
+ own apply line can be shown (an edited plan has no valid code to show)."""
116
+ return (
117
+ isinstance(exc, StackGuardError)
118
+ and exc.cause_code == "STACK_APPROVAL_MISMATCH"
119
+ and plan is not None
120
+ and digest(plan) == plan["plan_id"]
121
+ )
122
+
123
+
124
+ def apply_cli(
125
+ args: argparse.Namespace,
126
+ *,
127
+ load: Callable[[Path], StackPlan],
128
+ apply: Callable[..., StackRecord],
129
+ report: Callable[..., int],
130
+ ) -> int:
131
+ machine = args.json
132
+ jsonl = getattr(args, "jsonl", False)
133
+ attempt_ids: list[str] = []
134
+ plan_id: str | None = None
135
+ loaded: StackPlan | None = None
136
+
137
+ def machine_error(exc: BaseException) -> int:
138
+ interrupted = isinstance(exc, KeyboardInterrupt)
139
+ return stack_run.machine_result(
140
+ None,
141
+ "interrupted" if interrupted else "failed" if attempt_ids else "rejected",
142
+ "130" if interrupted else "1" if attempt_ids else "2",
143
+ plan_id=plan_id,
144
+ attempt_id=attempt_ids[-1] if attempt_ids else None,
145
+ cause=stack_run.cause_of(exc, started=bool(attempt_ids)),
146
+ )
147
+
148
+ def emit_progress(event: stack_events.ProgressEvent) -> None:
149
+ print(json.dumps(event, separators=(",", ":")), file=sys.stderr, flush=True)
150
+
151
+ progress = (
152
+ emit_progress
153
+ if machine or (not jsonl and os.environ.get("LOCALMODELS_PROGRESS_JSON") == "1")
154
+ else None
155
+ )
156
+ log: Callable[[str], None] = JsonlObserver(sys.stdout) if jsonl else lambda _m: None
157
+ shown: Board | None = None
158
+ stack_run.cancel_on_sigterm()
159
+ try:
160
+ plan = loaded = load(args.plan)
161
+ plan_id = stack_run.safe_digest(plan["plan_id"])
162
+ if not (jsonl or machine):
163
+ log = shown = Board.for_plan(plan)
164
+ with shown or contextlib.nullcontext():
165
+ record = apply(
166
+ plan,
167
+ args.approve,
168
+ log=log,
169
+ on_progress=progress,
170
+ on_attempt=attempt_ids.append if machine else None,
171
+ )
172
+ except KeyboardInterrupt as exc:
173
+ if jsonl:
174
+ return stack_progress.error(130, guard_details(exc))
175
+ if machine:
176
+ return machine_error(exc)
177
+ print("stack: interrupted", file=sys.stderr)
178
+ return 130
179
+ except Exception as exc:
180
+ if jsonl:
181
+ return stack_progress.error(2, guard_details(exc))
182
+ if machine:
183
+ return machine_error(exc)
184
+ if isinstance(exc, StackError | PlanError | harness.HarnessError | ValueError | KeyError):
185
+ print(f"stack: {exc}", file=sys.stderr)
186
+ if _mistyped_code(exc, loaded):
187
+ assert loaded is not None
188
+ print(
189
+ f" this plan's apply line: {command()} stack apply {args.plan} "
190
+ f"--approve {loaded['plan_id']}",
191
+ file=sys.stderr,
192
+ )
193
+ return 2
194
+ raise
195
+ if args.stack_command == "apply" and args.json:
196
+ return stack_run.machine_result(
197
+ record,
198
+ "completed" if record["ok"] else "failed",
199
+ "0" if record["ok"] else "1",
200
+ plan=plan,
201
+ )
202
+ if jsonl:
203
+ return stack_progress.result(
204
+ record["ok"],
205
+ ((c["component"], c["status"]) for c in record["components"]),
206
+ profile=record.get("profile"),
207
+ )
208
+ return report(record, timing=shown.timing() if shown else None)
209
+
210
+
211
+ def run_cli(
212
+ args: argparse.Namespace,
213
+ *,
214
+ build: Callable[..., StackPlan],
215
+ save: Callable[[StackPlan, Any], Any],
216
+ load: Callable[[Path], StackPlan],
217
+ apply: Callable[..., StackRecord],
218
+ report: Callable[..., int],
219
+ day2_fn: Callable[[argparse.Namespace], int] = day2,
220
+ ) -> int:
221
+ if args.stack_command == "capabilities":
222
+ stack_run.capabilities()
223
+ return 0
224
+ if args.stack_command == "mcp":
225
+ return stack_mcp.cli(args)
226
+ try:
227
+ if args.stack_command in (
228
+ *day2_mod.COMMANDS,
229
+ "up",
230
+ "down",
231
+ "warm",
232
+ "try",
233
+ "arena",
234
+ "ledger",
235
+ "card",
236
+ "rollback",
237
+ "view",
238
+ "clients",
239
+ "view-hub",
240
+ "view-agent",
241
+ ):
242
+ return day2_fn(args)
243
+ if args.stack_command == "decisions":
244
+ print(decide.listing())
245
+ return 0
246
+ if args.stack_command == "memory":
247
+ return stack_memory.cli(args)
248
+ if args.stack_command == "what-if":
249
+ return stack_whatif.cli(args)
250
+ facts = (
251
+ decode(json.loads(args.facts.read_text(encoding="utf-8")), HostFacts)
252
+ if getattr(args, "facts", None)
253
+ else None
254
+ )
255
+ if args.stack_command == "hardware":
256
+ return _hardware(facts, args.json, args.unified_memory)
257
+ if args.stack_command == "plan":
258
+ options: StackOptions = stack_update.requested(
259
+ options_from_args(args), args.update, getattr(args, "component_selections", ())
260
+ )
261
+ with console.status(
262
+ "Probing this computer and pricing the whole stack…"
263
+ if facts is None
264
+ else "Pricing the whole stack…"
265
+ ):
266
+ plan = build(options, facts=facts)
267
+ path = save(plan, args.out)
268
+ if args.json:
269
+ json.dump(plan, sys.stdout, ensure_ascii=False, indent=1)
270
+ sys.stdout.write("\n")
271
+ else:
272
+ print(styled(summary(plan, path)))
273
+ return 0
274
+ return apply_cli(args, load=load, apply=apply, report=report)
275
+ except (
276
+ StackError,
277
+ PlanError,
278
+ harness.HarnessError,
279
+ ServiceError,
280
+ ValueError,
281
+ KeyError,
282
+ ) as exc:
283
+ if getattr(args, "jsonl", False):
284
+ return stack_progress.error(2, guard_details(exc))
285
+ print(f"stack: {exc}", file=sys.stderr)
286
+ return 2
@@ -33,6 +33,7 @@ from localmodels import (
33
33
  remote_ops_launchd,
34
34
  reuse,
35
35
  stack_auto,
36
+ stack_capacity,
36
37
  stack_debug,
37
38
  stack_mlx,
38
39
  stack_ports,
@@ -47,7 +48,7 @@ from localmodels import stack_gpu_memory as gpu_memory
47
48
  from localmodels import stack_hardware as hardware
48
49
  from localmodels import stack_llm_ram as llm_ram
49
50
  from localmodels.approval import digest
50
- from localmodels.budget import gib, host_ram
51
+ from localmodels.budget import gib, host_ram, placements
51
52
  from localmodels.context_policy import AGENT, AgentPosture, posture_for, window_k
52
53
  from localmodels.plan_envelope import PlanError, require_free_port, utc_now
53
54
  from localmodels.probe import HostFacts
@@ -243,11 +244,17 @@ def choose_parts(
243
244
  approved=approved,
244
245
  )
245
246
  passed_over: list[str] = []
246
- if parts is None and strata is None and stack_suite.auto_strata_wanted(facts, options):
247
+ llama_reads: stack_auto.LlamaReads = (listening, previous, existing, qa_cpu_decision)
248
+ if (
249
+ parts is None
250
+ and strata is None
251
+ and not stack_auto.approved_keeps_llama(facts, approved)
252
+ and stack_suite.auto_strata_wanted(facts, options)
253
+ ):
247
254
  parts = stack_auto.strata_parts(
248
255
  facts,
249
256
  options,
250
- _llama_quality(facts, options),
257
+ _llama_quality(facts, options, owned_ram, llama_reads),
251
258
  listening,
252
259
  previous,
253
260
  owned_ram,
@@ -261,11 +268,18 @@ def choose_parts(
261
268
  return parts, options
262
269
 
263
270
 
264
- def _llama_quality(facts: HostFacts, options: StackOptions) -> tuple[int, str]:
271
+ def _llama_quality(
272
+ facts: HostFacts,
273
+ options: StackOptions,
274
+ reclaimed_ram: int | Callable[[], int] = 0,
275
+ reads: stack_auto.LlamaReads = stack_auto.DEFAULT_READS,
276
+ ) -> tuple[int, str]:
265
277
  """The installed SimplexAI score and id of what ``--llm auto`` would pick on llama.cpp,
266
278
  (-1, "") when nothing fits: the bar a Strata recipe must clear to be picked instead."""
267
279
  try:
268
- llm_id, _ = _choose_llm(facts, options, agent_posture(options))
280
+ llm_id, _ = _choose_llm(
281
+ facts, options, agent_posture(options), reclaimed_ram=reclaimed_ram, reads=reads
282
+ )
269
283
  except StackError:
270
284
  return -1, ""
271
285
  entry = next(e for e in cat.load_catalog_file() if e.id == llm_id)
@@ -295,11 +309,15 @@ def agent_posture(options: StackOptions) -> AgentPosture:
295
309
  return stack_debug.posture(posture, options) # --kv
296
310
 
297
311
 
298
- def _choose_llm(facts: HostFacts, options: StackOptions, posture: AgentPosture) -> tuple[str, str]:
299
- """(catalog id, placement id): explicit selection, then the small-Mac default if it fits.
300
- Other auto candidates must be validated and pass the agent capacity gate; quality then
301
- speed ranks them. Each takes the first fitting card from stack_hardware's free-memory
302
- order. Explicit --llm and --gpu keep the same capacity and conflict checks."""
312
+ def _choose_llm(
313
+ facts: HostFacts,
314
+ options: StackOptions,
315
+ posture: AgentPosture,
316
+ *,
317
+ reclaimed_ram: int | Callable[[], int] = 0,
318
+ reads: stack_auto.LlamaReads = stack_auto.DEFAULT_READS,
319
+ approved: StackPlan | None = None,
320
+ ) -> tuple[str, str]:
303
321
  gpu = options.get("gpu")
304
322
  mac = metal.device(facts) is not None
305
323
 
@@ -319,21 +337,15 @@ def _choose_llm(facts: HostFacts, options: StackOptions, posture: AgentPosture)
319
337
  return options["llm"], placement(gpu)
320
338
  cards = hardware.cards(facts, gpu, share_gpu=options.get("share_gpu", False))
321
339
  posture = posture_for(posture, "metal") if mac else posture
322
- fitting = []
323
- for entry in (
324
- e
325
- for e in cat.load_catalog_file()
326
- if llm_rank.automatic_here(e, facts) and e.runtime == "llama.cpp"
327
- ):
328
- variant = entry.variants[-1]
329
- for index in cards:
330
- card = hardware.llm_budget(facts, index, options, entry=entry, posture=posture)[0]
331
- if llm_rank.agent_ready(entry, variant, card, posture):
332
- fitting.append((llm_rank.rank_key(entry, variant, card), entry.id, index))
333
- break
340
+
341
+ fitting, fallback_ids, vram_fit = stack_auto.auto_llama_fits(
342
+ facts, cards, options, posture, reads=reads, reclaimed_ram=reclaimed_ram
343
+ )
334
344
  if fitting:
345
+ if kept := stack_auto.approved_llama_choice(fitting, approved):
346
+ return kept[0], placement(kept[1])
335
347
  prefer, default = str(options.get("prefer") or "smartest"), llm_rank.mac_default(facts)
336
- llm_id, index = llm_rank.choose(fitting, prefer, default)
348
+ llm_id, index = llm_rank.choose(fitting, prefer, default, fallback_ids=fallback_ids)
337
349
  return llm_id, placement(index)
338
350
  where = (
339
351
  f"GPU {gpu}"
@@ -345,27 +357,46 @@ def _choose_llm(facts: HostFacts, options: StackOptions, posture: AgentPosture)
345
357
  reserve = (
346
358
  " (with the smallest decision reserve)" if options.get("decision", "none") != "none" else ""
347
359
  )
360
+ avail = (reclaimed_ram() if callable(reclaimed_ram) else reclaimed_ram) if vram_fit else 0
361
+ reason = _no_fit_reason(facts, cards, mac, vram_fit=vram_fit, reclaimed_ram=avail)
348
362
  raise StackError(
349
- f"no verified LLM fits {where} in the agent posture "
350
- f"({window_k(posture.floor)} floor){reserve}{_no_fit_reason(facts, cards, mac)}; "
351
- "name a catalog model with --llm (candidates are not ranked automatically), "
363
+ stack_capacity.no_default_reason(facts, options, posture)
364
+ + f"no verified LLM fits {where} in the agent posture "
365
+ f"({window_k(posture.floor)} floor){reserve}{reason}; "
366
+ "name a catalog model with --llm (other candidates are not ranked automatically), "
352
367
  f"see each card with {command()} stack hardware"
353
368
  )
354
369
 
355
370
 
356
- def _no_fit_reason(facts: HostFacts, cards: list[int], mac: bool) -> str:
357
- """Why nothing fit, in the user's terms: every card busy with someone else's service, or how
358
- much the roomiest candidate card has free."""
371
+ def _no_fit_reason(
372
+ facts: HostFacts,
373
+ cards: list[int],
374
+ mac: bool,
375
+ *,
376
+ vram_fit: bool = False,
377
+ reclaimed_ram: int = 0,
378
+ ) -> str:
359
379
  gpus = {g["index"]: g for g in facts.get("gpus") or []}
360
380
  if mac or not gpus:
361
381
  return ""
362
382
  if not cards:
363
- free = ", ".join(f"GPU {i} {gib(g['free_bytes'])} free" for i, g in sorted(gpus.items()))
383
+ eligible = [p for p in placements(facts) if not p.pooled and len(p.gpu_indices) == 1]
384
+ if not eligible:
385
+ return ": no supported single-card GPU placement"
386
+ if not all(p.conflicts for p in eligible):
387
+ return ": no GPU meets automatic selection requirements; check GPU service discovery"
388
+ free = ", ".join(
389
+ f"GPU {p.gpu_indices[0]} {gib(gpus[p.gpu_indices[0]]['free_bytes'])} free"
390
+ for p in eligible
391
+ )
364
392
  return (
365
- f": every card runs services this tool does not own ({free}), and --llm auto skips "
393
+ f": every placeable card has other GPU work ({free}), and --llm auto skips "
366
394
  "such cards; plan again once they end, or, if sharing is fine and that card has "
367
395
  "room, use --gpu N --share-gpu"
368
396
  )
397
+ if vram_fit:
398
+ avail = gib(host_ram(facts, reclaimed_bytes=reclaimed_ram)[1])
399
+ return f": not enough available RAM ({avail} available)"
369
400
  best = gpus[cards[0]]
370
401
  return f": the roomiest GPU {cards[0]} has only {gib(best['free_bytes'])} free"
371
402
 
@@ -386,6 +417,12 @@ def _llm_warnings(
386
417
  """What a catalog llama.cpp LLM's plan says about itself: its own warnings, an ignored
387
418
  --conversation-cache, and a running one kept as is or a new one's GPU conflicts and speed."""
388
419
  warnings = [f"LLM: {w}" for w in llm["warnings"]]
420
+ if (
421
+ llm_id == llm_rank.WINDOWS_FALLBACK_ID
422
+ and facts["platform"] == "win32"
423
+ and options["llm"] == "auto"
424
+ ):
425
+ warnings.append(f"LLM: {llm_rank.WINDOWS_FALLBACK_WARNING}")
389
426
  if llm_id == llm_rank.mac_default(facts) and options["llm"] == "auto":
390
427
  warnings.append(
391
428
  "LLM: LFM3-1.7B is the user-selected small-Mac default (LFM1); "
@@ -436,7 +473,14 @@ def _llama_parts(
436
473
  )
437
474
  held = _foundation_reserve(facts, options, candidates)
438
475
  seen = metal.holds(facts, held) if held else facts
439
- llm_id, placement_id = _choose_llm(seen, options, posture)
476
+ llm_id, placement_id = _choose_llm(
477
+ seen,
478
+ options,
479
+ posture,
480
+ reclaimed_ram=owned_ram,
481
+ reads=(listening, previous, existing, qa_cpu_decision),
482
+ approved=approved,
483
+ )
440
484
  llm_id, entries = hf_repo.catalog_plus(
441
485
  options["llm"],
442
486
  llm_id,
@@ -180,8 +180,8 @@ class Board:
180
180
  now = time.monotonic()
181
181
  if moved or row.done is None:
182
182
  row.rate, row.mark, row.quarter = 0.0, (now, done), -1
183
- elif now - row.mark[0] >= 0.5:
184
- sample = (done - row.mark[1]) / (now - row.mark[0])
183
+ elif (dt := now - row.mark[0]) >= 0.25 and done > row.mark[1]:
184
+ sample = (done - row.mark[1]) / dt
185
185
  row.rate = sample if row.rate == 0 else 0.7 * row.rate + 0.3 * sample
186
186
  row.mark = (now, done)
187
187
  row.done, row.total = done, total
@@ -189,9 +189,12 @@ class Board:
189
189
  quarter = done * 4 // total
190
190
  if quarter > max(row.quarter, 0): # 25, 50, 75 and 100%; never a 0% line
191
191
  row.quarter = quarter
192
+ tail = f" ({console.size(done)}/{console.size(total)})"
193
+ if row.rate > 0 and done < total:
194
+ eta = (total - done) / row.rate
195
+ tail += f", {console.size(row.rate)}/s, ETA {console.duration(eta)}"
192
196
  self.live.print(
193
- f"[{row.key}:{step}] {PHASES.get(phase, phase)} {done * 100 // total}%"
194
- f" ({console.size(done)}/{console.size(total)})"
197
+ f"[{row.key}:{step}] {PHASES.get(phase, phase)} {done * 100 // total}%{tail}"
195
198
  )
196
199
  self.live.refresh()
197
200
 
@@ -315,9 +318,9 @@ class Board:
315
318
  return shown + ([(f" {row.note}", ("dim",))] if row.note else [])
316
319
  pct = row.done * 100 // row.total
317
320
  counts = f" {pct:>3}% {console.size(row.done)}/{console.size(row.total)}"
318
- if row.rate > 0:
321
+ if row.rate > 0 and row.done < row.total:
319
322
  eta = (row.total - row.done) / row.rate
320
- counts += f" {console.size(row.rate)}/s {console.duration(eta)}"
323
+ counts += f" {console.size(row.rate)}/s ETA {console.duration(eta)}"
321
324
  bar = max(8, min(30, room - console.cells(what) - console.cells(counts) - 2))
322
325
  return [
323
326
  (what + " ", ("cyan",)),