@simplexai/localmodels-darwin-arm64 0.1.0-dev.36 → 0.1.0-dev.38

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 (134) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +132 -110
  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_checks.py +9 -6
  7. package/modules/localmodels/bifrost_config.py +203 -0
  8. package/modules/localmodels/bifrost_datasheet.py +12 -2
  9. package/modules/localmodels/budget.py +13 -2
  10. package/modules/localmodels/catalog.json +137 -2
  11. package/modules/localmodels/catalog.py +70 -321
  12. package/modules/localmodels/catalog_add.py +2 -8
  13. package/modules/localmodels/catalog_recipes.py +352 -0
  14. package/modules/localmodels/cli_parser.py +4 -1
  15. package/modules/localmodels/console.py +5 -4
  16. package/modules/localmodels/contracts.py +13 -3
  17. package/modules/localmodels/debug_cli.py +158 -0
  18. package/modules/localmodels/debug_mode.py +727 -0
  19. package/modules/localmodels/debug_stub_server.py +192 -0
  20. package/modules/localmodels/decode_calibration.json +1 -1
  21. package/modules/localmodels/decode_calibration.py +34 -17
  22. package/modules/localmodels/gateway.py +21 -155
  23. package/modules/localmodels/gateway_accept.py +201 -0
  24. package/modules/localmodels/gateway_bifrost.py +30 -193
  25. package/modules/localmodels/gateway_cli.py +15 -6
  26. package/modules/localmodels/gateway_foundations.py +2 -4
  27. package/modules/localmodels/gateway_probe.py +0 -1
  28. package/modules/localmodels/gateway_server.py +2 -3
  29. package/modules/localmodels/gpu_specs.py +12 -0
  30. package/modules/localmodels/guard.py +2 -7
  31. package/modules/localmodels/harness.py +16 -129
  32. package/modules/localmodels/harness_cleanup.py +135 -0
  33. package/modules/localmodels/harness_gateway.py +16 -14
  34. package/modules/localmodels/harness_probe.py +12 -4
  35. package/modules/localmodels/hosts.py +25 -2
  36. package/modules/localmodels/http_local.py +59 -0
  37. package/modules/localmodels/install.py +23 -8
  38. package/modules/localmodels/library_gateway.py +20 -9
  39. package/modules/localmodels/library_jobs.py +125 -28
  40. package/modules/localmodels/library_model.py +10 -0
  41. package/modules/localmodels/library_pricing.py +29 -22
  42. package/modules/localmodels/library_serve.py +17 -1
  43. package/modules/localmodels/library_state.py +15 -2
  44. package/modules/localmodels/library_status.py +30 -0
  45. package/modules/localmodels/llm_rank.py +185 -39
  46. package/modules/localmodels/probe.py +108 -174
  47. package/modules/localmodels/process_identity.py +120 -154
  48. package/modules/localmodels/process_windows.py +86 -0
  49. package/modules/localmodels/recommend.py +6 -3
  50. package/modules/localmodels/recommend_cli.py +14 -6
  51. package/modules/localmodels/remote_ops.py +65 -0
  52. package/modules/localmodels/remote_ops_service.py +14 -2
  53. package/modules/localmodels/runtime_args.py +10 -3
  54. package/modules/localmodels/runtime_auth.py +5 -9
  55. package/modules/localmodels/runtime_cli.py +128 -129
  56. package/modules/localmodels/runtime_discovery.py +84 -0
  57. package/modules/localmodels/runtime_install.py +101 -0
  58. package/modules/localmodels/runtime_releases.py +302 -0
  59. package/modules/localmodels/search_server.py +5 -1
  60. package/modules/localmodels/service_stop.py +8 -108
  61. package/modules/localmodels/service_upgrade.py +394 -63
  62. package/modules/localmodels/services_cli.py +24 -14
  63. package/modules/localmodels/setup_inspection.py +97 -9
  64. package/modules/localmodels/setup_text.py +7 -0
  65. package/modules/localmodels/sizecalc.py +0 -1
  66. package/modules/localmodels/stack.py +45 -235
  67. package/modules/localmodels/stack_arena.py +732 -0
  68. package/modules/localmodels/stack_args.py +21 -12
  69. package/modules/localmodels/stack_auto.py +384 -3
  70. package/modules/localmodels/stack_aux_gpu.py +4 -3
  71. package/modules/localmodels/stack_capacity.py +138 -0
  72. package/modules/localmodels/stack_cleanup.py +9 -4
  73. package/modules/localmodels/stack_cli.py +288 -0
  74. package/modules/localmodels/stack_compose.py +63 -30
  75. package/modules/localmodels/stack_console.py +9 -6
  76. package/modules/localmodels/stack_hardware.py +95 -265
  77. package/modules/localmodels/stack_hardware_text.py +263 -0
  78. package/modules/localmodels/stack_journal.py +3 -9
  79. package/modules/localmodels/stack_ledger.py +48 -18
  80. package/modules/localmodels/stack_lifecycle.py +33 -312
  81. package/modules/localmodels/stack_llm_ram.py +16 -6
  82. package/modules/localmodels/stack_mcp.py +729 -0
  83. package/modules/localmodels/stack_memory.py +0 -2
  84. package/modules/localmodels/stack_picks.py +62 -15
  85. package/modules/localmodels/stack_plan.py +19 -1
  86. package/modules/localmodels/stack_preflight.py +11 -19
  87. package/modules/localmodels/stack_progress.py +9 -1
  88. package/modules/localmodels/stack_remove.py +373 -0
  89. package/modules/localmodels/stack_route.py +101 -17
  90. package/modules/localmodels/stack_run.py +29 -0
  91. package/modules/localmodels/stack_suite.py +21 -10
  92. package/modules/localmodels/stack_summary.py +14 -0
  93. package/modules/localmodels/stack_try.py +238 -24
  94. package/modules/localmodels/stack_try_client.py +53 -15
  95. package/modules/localmodels/stack_try_docs.py +2 -2
  96. package/modules/localmodels/stack_view.py +24 -171
  97. package/modules/localmodels/stack_view_access.py +114 -1
  98. package/modules/localmodels/stack_view_agent.py +3 -13
  99. package/modules/localmodels/stack_view_hub.py +9 -10
  100. package/modules/localmodels/stack_view_llm.py +1 -1
  101. package/modules/localmodels/stack_view_sandbox.py +2 -2
  102. package/modules/localmodels/stack_view_schema.py +183 -0
  103. package/modules/localmodels/stack_view_serve.py +7 -1
  104. package/modules/localmodels/stack_view_service.py +1 -2
  105. package/modules/localmodels/stack_view_text.py +13 -9
  106. package/modules/localmodels/stack_warm.py +48 -4
  107. package/modules/localmodels/stack_warm_store.py +517 -0
  108. package/modules/localmodels/tools.json +32 -18
  109. package/modules/localmodels/transport.py +38 -13
  110. package/modules/localmodels/tui.py +28 -4
  111. package/modules/localmodels/tui_dialogs.py +136 -0
  112. package/modules/localmodels/tui_modals.py +279 -0
  113. package/modules/localmodels/tui_screen.py +113 -154
  114. package/modules/localmodels/tui_views.py +134 -203
  115. package/modules/localmodels/web/index.html +510 -101
  116. package/modules/localmodels/web/sizecalc/app.js +363 -10
  117. package/modules/localmodels/web/sizecalc/page.html +27 -3
  118. package/modules/localmodels/web/view/fleet.html +11 -2
  119. package/modules/localmodels/web/view/fleet.js +191 -17
  120. package/modules/localmodels/web/view/i18n.js +3 -2
  121. package/modules/localmodels/web/view/index.html +1 -1
  122. package/modules/localmodels/web/view/nav.js +22 -3
  123. package/modules/localmodels/web/view/view.css +63 -18
  124. package/modules/localmodels/web/view/view.js +169 -32
  125. package/modules/localmodels/windows_job.py +69 -0
  126. package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/METADATA +1 -1
  127. package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/RECORD +128 -106
  128. package/package.json +1 -1
  129. package/tool.json +1 -1
  130. package/modules/localmodels/engines-strata-0.1.49.1.json +0 -31
  131. /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/WHEEL +0 -0
  132. /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/entry_points.txt +0 -0
  133. /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/licenses/NOTICE +0 -0
  134. /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -26,8 +26,10 @@ from localmodels.stack_plan import StackError, platform_error
26
26
 
27
27
  Out = Callable[[str], None]
28
28
  # State this tool writes for a stack and nothing else reads: saved plans, run records, the
29
- # apply lock and journal (stacks/), the cached probe (facts/) and the view window's profile.
30
- STACK_STATE = ("stacks", "facts", "view-app")
29
+ # apply lock and journal (stacks/), the cached probe (facts/), the view window's profile,
30
+ # measured per-device decode speeds (warm_speeds.json), and the blind Elo board (arena.json;
31
+ # its empty arena.lock stays per WHI-317).
32
+ STACK_STATE = ("stacks", "facts", "view-app", "warm_speeds.json", "arena.json")
31
33
 
32
34
 
33
35
  Engines = dict[Path, set[str]] # engine directory -> the archive names it was unpacked from
@@ -186,6 +188,9 @@ def sweep(
186
188
  for path in doomed:
187
189
  if path.is_dir() and not path.is_symlink():
188
190
  shutil.rmtree(path)
191
+ elif path.name == "arena.json":
192
+ with hosts.file_lock(path.parent / "arena.lock"):
193
+ path.unlink(missing_ok=True)
189
194
  else:
190
195
  path.unlink(missing_ok=True)
191
196
  if state:
@@ -200,8 +205,8 @@ def tidy(base_dirs: Iterable[Path], tools_dir: str | Path = hosts.TOOLS_DIR) ->
200
205
  A directory someone else made there stays, empty or not. The manifest's empty
201
206
  ``owned.lock`` stays: unlinking a lock file lets two writers each hold a "lock" (WHI-317,
202
207
  .agents/skills/owned-manifest-lock), so it is the one file an uninstall leaves."""
203
- root = Path(tools_dir).expanduser()
204
- private = root / "gateway-home"
208
+ root = Path(hosts.tools_dir(tools_dir)).expanduser()
209
+ private = root.resolve() / "gateway-home"
205
210
  if not hosts.owned_path(tools_dir).exists() and private.is_dir():
206
211
  # Windows has no uid: the directory sits in this user's profile under a private ACL.
207
212
  uid = os.getuid() if hasattr(os, "getuid") else None
@@ -0,0 +1,288 @@
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
+ failure = stack_run.component_failure(record)
204
+ return stack_progress.result(
205
+ record["ok"],
206
+ ((c["component"], c["status"]) for c in record["components"]),
207
+ profile=record.get("profile"),
208
+ cause=failure[1][0] if failure else None,
209
+ )
210
+ return report(record, timing=shown.timing() if shown else None)
211
+
212
+
213
+ def run_cli(
214
+ args: argparse.Namespace,
215
+ *,
216
+ build: Callable[..., StackPlan],
217
+ save: Callable[[StackPlan, Any], Any],
218
+ load: Callable[[Path], StackPlan],
219
+ apply: Callable[..., StackRecord],
220
+ report: Callable[..., int],
221
+ day2_fn: Callable[[argparse.Namespace], int] = day2,
222
+ ) -> int:
223
+ if args.stack_command == "capabilities":
224
+ stack_run.capabilities()
225
+ return 0
226
+ if args.stack_command == "mcp":
227
+ return stack_mcp.cli(args)
228
+ try:
229
+ if args.stack_command in (
230
+ *day2_mod.COMMANDS,
231
+ "up",
232
+ "down",
233
+ "warm",
234
+ "try",
235
+ "arena",
236
+ "ledger",
237
+ "card",
238
+ "rollback",
239
+ "view",
240
+ "clients",
241
+ "view-hub",
242
+ "view-agent",
243
+ ):
244
+ return day2_fn(args)
245
+ if args.stack_command == "decisions":
246
+ print(decide.listing())
247
+ return 0
248
+ if args.stack_command == "memory":
249
+ return stack_memory.cli(args)
250
+ if args.stack_command == "what-if":
251
+ return stack_whatif.cli(args)
252
+ facts = (
253
+ decode(json.loads(args.facts.read_text(encoding="utf-8")), HostFacts)
254
+ if getattr(args, "facts", None)
255
+ else None
256
+ )
257
+ if args.stack_command == "hardware":
258
+ return _hardware(facts, args.json, args.unified_memory)
259
+ if args.stack_command == "plan":
260
+ options: StackOptions = stack_update.requested(
261
+ options_from_args(args), args.update, getattr(args, "component_selections", ())
262
+ )
263
+ with console.status(
264
+ "Probing this computer and pricing the whole stack…"
265
+ if facts is None
266
+ else "Pricing the whole stack…"
267
+ ):
268
+ plan = build(options, facts=facts)
269
+ path = save(plan, args.out)
270
+ if args.json:
271
+ json.dump(plan, sys.stdout, ensure_ascii=False, indent=1)
272
+ sys.stdout.write("\n")
273
+ else:
274
+ print(styled(summary(plan, path)))
275
+ return 0
276
+ return apply_cli(args, load=load, apply=apply, report=report)
277
+ except (
278
+ StackError,
279
+ PlanError,
280
+ harness.HarnessError,
281
+ ServiceError,
282
+ ValueError,
283
+ KeyError,
284
+ ) as exc:
285
+ if getattr(args, "jsonl", False):
286
+ return stack_progress.error(2, guard_details(exc))
287
+ print(f"stack: {exc}", file=sys.stderr)
288
+ 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,
@@ -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,7 +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]:
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]:
299
321
  gpu = options.get("gpu")
300
322
  mac = metal.device(facts) is not None
301
323
 
@@ -315,24 +337,15 @@ def _choose_llm(facts: HostFacts, options: StackOptions, posture: AgentPosture)
315
337
  return options["llm"], placement(gpu)
316
338
  cards = hardware.cards(facts, gpu, share_gpu=options.get("share_gpu", False))
317
339
  posture = posture_for(posture, "metal") if mac else posture
318
- fitting = []
319
- fallback_ids = set()
320
- for entry in (
321
- e
322
- for e in cat.load_catalog_file()
323
- if llm_rank.automatic_here(e, facts) and e.runtime == "llama.cpp"
324
- ):
325
- variant = entry.variants[-1]
326
- for index in cards:
327
- card = hardware.llm_budget(facts, index, options, entry=entry, posture=posture)[0]
328
- if llm_rank.automatic_fit(entry, facts, card, posture, options):
329
- fitting.append((llm_rank.rank_key(entry, variant, card), entry.id, index))
330
- if llm_rank.windows_fallback(entry, facts):
331
- fallback_ids.add(entry.id)
332
- 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
+ )
333
344
  if fitting:
334
- prefer, default = str(options.get("prefer") or "smartest"), llm_rank.mac_default(facts)
335
- llm_id, index = llm_rank.choose(fitting, prefer, default, fallback_ids=fallback_ids)
345
+ if kept := stack_auto.approved_llama_choice(fitting, approved):
346
+ return kept[0], placement(kept[1])
347
+ prefer, ladder = str(options.get("prefer") or "smartest"), llm_rank.mac_ladder(facts)
348
+ llm_id, index = llm_rank.choose(fitting, prefer, ladder, fallback_ids=fallback_ids)
336
349
  return llm_id, placement(index)
337
350
  where = (
338
351
  f"GPU {gpu}"
@@ -344,15 +357,25 @@ def _choose_llm(facts: HostFacts, options: StackOptions, posture: AgentPosture)
344
357
  reserve = (
345
358
  " (with the smallest decision reserve)" if options.get("decision", "none") != "none" else ""
346
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)
347
362
  raise StackError(
348
- f"no verified LLM fits {where} in the agent posture "
349
- f"({window_k(posture.floor)} floor){reserve}{_no_fit_reason(facts, cards, mac)}; "
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}; "
350
366
  "name a catalog model with --llm (other candidates are not ranked automatically), "
351
367
  f"see each card with {command()} stack hardware"
352
368
  )
353
369
 
354
370
 
355
- def _no_fit_reason(facts: HostFacts, cards: list[int], mac: bool) -> str:
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:
356
379
  gpus = {g["index"]: g for g in facts.get("gpus") or []}
357
380
  if mac or not gpus:
358
381
  return ""
@@ -367,10 +390,13 @@ def _no_fit_reason(facts: HostFacts, cards: list[int], mac: bool) -> str:
367
390
  for p in eligible
368
391
  )
369
392
  return (
370
- f": every placeable 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 "
371
394
  "such cards; plan again once they end, or, if sharing is fine and that card has "
372
395
  "room, use --gpu N --share-gpu"
373
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)"
374
400
  best = gpus[cards[0]]
375
401
  return f": the roomiest GPU {cards[0]} has only {gib(best['free_bytes'])} free"
376
402
 
@@ -397,10 +423,10 @@ def _llm_warnings(
397
423
  and options["llm"] == "auto"
398
424
  ):
399
425
  warnings.append(f"LLM: {llm_rank.WINDOWS_FALLBACK_WARNING}")
400
- if llm_id == llm_rank.mac_default(facts) and options["llm"] == "auto":
426
+ if llm_id in getattr(llm_rank.mac_ladder(facts), "smartest", ()) and options["llm"] == "auto":
401
427
  warnings.append(
402
- "LLM: LFM3-1.7B is the user-selected small-Mac default (LFM1); "
403
- "no SimplexAI score, physical 16 GB install and full product acceptance pending"
428
+ f"LLM: {llm_id} is on the user-selected Mac small-memory ladder (decision 57, 64K x 2);"
429
+ " no SimplexAI score, physical 16 GB install and full product acceptance pending"
404
430
  )
405
431
  if options["conversation_cache"] not in ("auto", "off"):
406
432
  warnings.append(
@@ -447,7 +473,14 @@ def _llama_parts(
447
473
  )
448
474
  held = _foundation_reserve(facts, options, candidates)
449
475
  seen = metal.holds(facts, held) if held else facts
450
- 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
+ )
451
484
  llm_id, entries = hf_repo.catalog_plus(
452
485
  options["llm"],
453
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",)),