@simplexai/localmodels-linux-x64 0.1.0-dev.49 → 0.1.0-dev.51

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 (67) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +65 -59
  3. package/modules/localmodels/__init__.py +1 -1
  4. package/modules/localmodels/catalog.json +2395 -9
  5. package/modules/localmodels/deploy.py +29 -134
  6. package/modules/localmodels/download-mirrors.json +47 -0
  7. package/modules/localmodels/engines-strata-poly-0.2.19-poly.1.json +79 -0
  8. package/modules/localmodels/engines-strata-poly-0.2.20-poly.1.json +132 -0
  9. package/modules/localmodels/gateway.py +23 -6
  10. package/modules/localmodels/gateway_bifrost.py +6 -2
  11. package/modules/localmodels/harness.py +8 -2
  12. package/modules/localmodels/harness_gateway.py +78 -17
  13. package/modules/localmodels/harness_probe.py +43 -23
  14. package/modules/localmodels/hosts.py +52 -5
  15. package/modules/localmodels/library_floor.py +76 -0
  16. package/modules/localmodels/library_gateway.py +17 -1
  17. package/modules/localmodels/library_jobs.py +38 -6
  18. package/modules/localmodels/library_model.py +5 -0
  19. package/modules/localmodels/library_poly.py +273 -0
  20. package/modules/localmodels/library_pricing.py +24 -35
  21. package/modules/localmodels/library_serve.py +7 -0
  22. package/modules/localmodels/library_state.py +16 -0
  23. package/modules/localmodels/library_status.py +114 -29
  24. package/modules/localmodels/llm_rank.py +14 -0
  25. package/modules/localmodels/magpie_windows.py +312 -0
  26. package/modules/localmodels/plan_envelope.py +234 -3
  27. package/modules/localmodels/probe.py +1 -1
  28. package/modules/localmodels/process_identity.py +19 -9
  29. package/modules/localmodels/process_identity_darwin.py +155 -0
  30. package/modules/localmodels/remote_ops.py +11 -0
  31. package/modules/localmodels/remote_ops_download.py +30 -5
  32. package/modules/localmodels/remote_ops_service.py +11 -13
  33. package/modules/localmodels/reuse.py +13 -6
  34. package/modules/localmodels/runtime_cli.py +8 -8
  35. package/modules/localmodels/runtime_install.py +25 -1
  36. package/modules/localmodels/runtime_io.py +32 -18
  37. package/modules/localmodels/setup_inspection.py +83 -79
  38. package/modules/localmodels/setup_inspection_harness.py +147 -0
  39. package/modules/localmodels/setup_text.py +12 -0
  40. package/modules/localmodels/setup_upgrade.py +11 -1
  41. package/modules/localmodels/stack.py +3 -1
  42. package/modules/localmodels/stack_auto.py +6 -2
  43. package/modules/localmodels/stack_cli.py +39 -0
  44. package/modules/localmodels/stack_clients.py +1 -1
  45. package/modules/localmodels/stack_compose.py +12 -43
  46. package/modules/localmodels/stack_down.py +25 -16
  47. package/modules/localmodels/stack_hardware.py +12 -1
  48. package/modules/localmodels/stack_picks.py +28 -13
  49. package/modules/localmodels/stack_plan.py +55 -3
  50. package/modules/localmodels/stack_remove.py +3 -1
  51. package/modules/localmodels/stack_suite.py +80 -20
  52. package/modules/localmodels/strata-poly-serve-0.2.19-poly.1.txt +428 -0
  53. package/modules/localmodels/{strata-poly-serve-0.1.45-poly.9.txt → strata-poly-serve-0.2.20-poly.1.txt} +2 -2
  54. package/modules/localmodels/strata_poly_server.py +33 -2
  55. package/modules/localmodels/suite.py +45 -4
  56. package/modules/localmodels/tool_archive.py +4 -0
  57. package/modules/localmodels/vision.py +4 -2
  58. package/modules/localmodels/win_probe.py +24 -7
  59. package/modules/{simplex_localmodels-0.1.0.dev49.dist-info → simplex_localmodels-0.1.0.dev51.dist-info}/METADATA +1 -1
  60. package/modules/{simplex_localmodels-0.1.0.dev49.dist-info → simplex_localmodels-0.1.0.dev51.dist-info}/RECORD +62 -56
  61. package/package.json +1 -1
  62. package/tool.json +1 -1
  63. package/modules/localmodels/engines-strata-poly-0.1.45-poly.9.json +0 -75
  64. /package/modules/{simplex_localmodels-0.1.0.dev49.dist-info → simplex_localmodels-0.1.0.dev51.dist-info}/WHEEL +0 -0
  65. /package/modules/{simplex_localmodels-0.1.0.dev49.dist-info → simplex_localmodels-0.1.0.dev51.dist-info}/entry_points.txt +0 -0
  66. /package/modules/{simplex_localmodels-0.1.0.dev49.dist-info → simplex_localmodels-0.1.0.dev51.dist-info}/licenses/NOTICE +0 -0
  67. /package/modules/{simplex_localmodels-0.1.0.dev49.dist-info → simplex_localmodels-0.1.0.dev51.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -18,6 +18,7 @@ from localmodels import (
18
18
  metal,
19
19
  probe,
20
20
  service_probe,
21
+ setup_inspection_harness,
21
22
  setup_text,
22
23
  setup_upgrade,
23
24
  stack,
@@ -33,7 +34,6 @@ from localmodels.probe import HostFacts, Services
33
34
  from localmodels.runtime_cli import inspect_runtimes
34
35
  from localmodels.setup_text import Lang, text
35
36
  from localmodels.stack_plan import (
36
- RAM_FLOOR,
37
37
  StackError,
38
38
  StackOptions,
39
39
  StackPlan,
@@ -104,9 +104,10 @@ class SetupReport(TypedDict):
104
104
 
105
105
  _DRIVER_REASON_CODES = frozenset({"cuda-driver-update-required", "cuda-driver-version-unknown"})
106
106
  _VERSION_RE = re.compile(r"^\d+(?:\.\d+){0,2}$")
107
+ _capacity_facts = setup_inspection_harness.capacity_facts
107
108
 
108
109
 
109
- def _plan_reason(error: PlanError | StackError | harness.HarnessError) -> Reason:
110
+ def _plan_reason(error: PlanError | StackError) -> Reason:
110
111
  return {"code": "plan-unavailable", "message": str(error)}
111
112
 
112
113
 
@@ -141,19 +142,29 @@ def _cuda_driver_reason(error: CudaDriverError, lang: Lang) -> Reason:
141
142
  return reason
142
143
 
143
144
 
145
+ def _plans_hardware(options: StackOptions, facts: HostFacts) -> bool:
146
+ try:
147
+ stack.build(options, facts=facts)
148
+ except (PlanError, stack.StackError):
149
+ return False
150
+ except harness.HarnessError:
151
+ return True
152
+ return True
153
+
154
+
144
155
  def _fits_with_required_cuda(options: StackOptions, facts: HostFacts, required_cuda: str) -> bool:
145
156
  """Whether this computer's hardware fits a local stack once the NVIDIA driver supports
146
157
  ``required_cuda`` (live or once other programs free memory)."""
147
158
  upgraded = copy.deepcopy(facts)
148
159
  upgraded["nvidia"] = {**(upgraded.get("nvidia") or {}), "cuda_version": required_cuda}
149
- if _plans(options, upgraded):
160
+ if _plans_hardware(options, upgraded):
150
161
  return True
151
162
  roomy = _capacity_facts(upgraded)
152
- return roomy is not None and _plans(options, roomy)
163
+ return roomy is not None and _plans_hardware(options, roomy)
153
164
 
154
165
 
155
166
  def _driver_block(
156
- error: PlanError | StackError | harness.HarnessError | None,
167
+ error: PlanError | StackError | None,
157
168
  options: StackOptions,
158
169
  facts: HostFacts,
159
170
  lang: Lang,
@@ -177,7 +188,7 @@ def _capacity_availability(
177
188
  return None
178
189
  try:
179
190
  plan = stack.build(options, facts=roomy)
180
- except (PlanError, stack.StackError, harness.HarnessError) as roomy_exc:
191
+ except (PlanError, stack.StackError) as roomy_exc:
181
192
  if blocked := _driver_block(roomy_exc, options, roomy, lang):
182
193
  return blocked
183
194
  # The hardware itself is too small and the live refusal stands, unless only another
@@ -209,41 +220,29 @@ def _capacity_availability(
209
220
  }
210
221
 
211
222
 
212
- def _stack(
213
- root: Path,
214
- facts: HostFacts,
215
- offline: bool,
216
- defer_services: bool = False,
217
- share_gpu: bool = False,
218
- decision: Literal["auto", "none"] = "none",
219
- unified_memory: str | None = None,
220
- lang: Lang = "zh",
223
+ def _harness_availability(
224
+ options: StackOptions, facts: HostFacts, exc: harness.HarnessError, lang: Lang
221
225
  ) -> StackAvailability:
222
- reason: Reason | None = None
223
- plan: StackPlan | None = None
224
- if error := platform_error(facts["platform"], arch=facts.get("arch")):
225
- reason = {
226
- "code": "unsupported-platform",
227
- "message": error,
228
- }
229
- elif facts["ram"]["total_bytes"] <= 0 or facts["disk"]["free_bytes"] is None:
230
- reason = {"code": "facts-unavailable", "message": text("facts-unavailable", lang)}
231
- elif _nvidia_cards_unmeasured(facts):
232
- reason = {"code": "facts-unavailable", "message": text("nvidia-unmeasured", lang)}
233
- else:
234
- options = stack.default_options()
235
- options["base_dir"] = str(root)
236
- options["offline"] = offline
237
- options["share_gpu"] = share_gpu
238
- options["decision"] = decision
239
- if defer_services:
240
- options["defer_services"] = True
241
- if unified_memory:
242
- options["unified_memory"] = unified_memory
226
+ """Classify a gateway/tool HarnessError separately from hardware incapability."""
227
+ code, capable, message = setup_inspection_harness.classify_harness_error(
228
+ options, facts, exc, lang
229
+ )
230
+ return {
231
+ "available": False,
232
+ "reasons": [{"code": code, "message": message}],
233
+ "plan": None,
234
+ "hardwareCapable": capable,
235
+ }
236
+
237
+
238
+ def _plan_stack(
239
+ options: StackOptions, facts: HostFacts, share_gpu: bool, lang: Lang
240
+ ) -> StackAvailability:
241
+ try:
243
242
  try:
244
243
  plan = stack.build(options, facts=facts)
245
- except (PlanError, stack.StackError, harness.HarnessError) as exc:
246
- last_error: PlanError | StackError | harness.HarnessError | None = exc
244
+ except (PlanError, stack.StackError) as exc:
245
+ last_error: PlanError | StackError | None = exc
247
246
  last_options = options
248
247
  reason = _plan_reason(exc)
249
248
  # Consent decides by free VRAM whoever else uses a card (roadmap decision 60), so
@@ -256,7 +255,7 @@ def _stack(
256
255
  shared_options: StackOptions = {**options, "share_gpu": True}
257
256
  try:
258
257
  stack.build(shared_options, facts=facts)
259
- except (PlanError, stack.StackError, harness.HarnessError) as shared_exc:
258
+ except (PlanError, stack.StackError) as shared_exc:
260
259
  last_error, last_options = shared_exc, shared_options
261
260
  reason = _plan_reason(shared_exc)
262
261
  else:
@@ -270,66 +269,62 @@ def _stack(
270
269
  if reason["code"] == "plan-unavailable":
271
270
  if capacity := _capacity_availability(options, facts, lang):
272
271
  return capacity
272
+ return {"available": False, "reasons": [reason], "plan": None}
273
273
  else:
274
274
  availability: StackAvailability = {"available": True, "reasons": [], "plan": plan}
275
275
  if upgrade := setup_upgrade.upgrade_hint(options, facts, plan, lang, _capacity_facts):
276
276
  availability["upgrade"] = upgrade
277
277
  return availability
278
+ except harness.HarnessError as exc:
279
+ return _harness_availability(options, facts, exc, lang)
278
280
 
279
- return {"available": plan is not None, "reasons": [reason] if reason else [], "plan": plan}
280
-
281
-
282
- def _capacity_facts(facts: HostFacts) -> HostFacts | None:
283
- """``facts`` once the user's other programs are closed, or None when that frees nothing.
284
281
 
285
- A Mac keeps what an idle one leaves to macOS and applications (``metal.in_use``) and is at
286
- normal pressure; a Linux host keeps the planner's own floor a second time for its desktop.
287
- An NVIDIA card keeps an idle driver context, unless serving work this tool does not own
288
- runs on it: that memory needs sharing consent, and closing applications does not free it.
289
- """
290
- roomy = copy.deepcopy(facts)
291
- ram = roomy["ram"]
292
- total = ram["total_bytes"]
293
- if metal.supported(facts):
294
- room = total - metal.in_use(total)
295
- ram["pressure_level"] = 1
296
- ram.pop("pressure_kept_bytes", None)
282
+ def _stack(
283
+ root: Path,
284
+ facts: HostFacts,
285
+ offline: bool,
286
+ defer_services: bool = False,
287
+ share_gpu: bool = False,
288
+ decision: Literal["auto", "none"] = "none",
289
+ unified_memory: str | None = None,
290
+ lang: Lang = "zh",
291
+ ) -> StackAvailability:
292
+ if error := platform_error(facts["platform"], arch=facts.get("arch")):
293
+ reason: Reason = {"code": "unsupported-platform", "message": error}
294
+ elif facts["ram"]["total_bytes"] <= 0 or facts["disk"]["free_bytes"] is None:
295
+ reason = {"code": "facts-unavailable", "message": text("facts-unavailable", lang)}
296
+ elif _nvidia_cards_unmeasured(facts):
297
+ reason = {"code": "facts-unavailable", "message": text("nvidia-unmeasured", lang)}
297
298
  else:
298
- room = total - RAM_FLOOR
299
- ram["available_bytes"] = max(ram["available_bytes"], room)
300
- served = budget.gpu_conflicts(facts)
301
- for gpu in roomy.get("gpus") or []:
302
- if served.get(gpu["uuid"]):
303
- continue
304
- idle = max(0, gpu["total_bytes"] - budget.IDLE_USED_BYTES)
305
- if gpu["free_bytes"] < idle:
306
- gpu["free_bytes"], gpu["used_bytes"] = idle, gpu["total_bytes"] - idle
307
- return None if roomy == facts else roomy
299
+ options = stack.default_options()
300
+ options["base_dir"] = str(root)
301
+ options["offline"] = offline
302
+ options["share_gpu"] = share_gpu
303
+ options["decision"] = decision
304
+ if defer_services:
305
+ options["defer_services"] = True
306
+ if unified_memory:
307
+ options["unified_memory"] = unified_memory
308
+ return _plan_stack(options, facts, share_gpu, lang)
309
+ return {"available": False, "reasons": [reason], "plan": None}
308
310
 
309
311
 
310
312
  def _fits_without_other_inference(options: StackOptions, roomy: HostFacts) -> StackPlan | None:
311
313
  """A Mac's capacity plan once the inference apps this tool does not own on its GPU
312
314
  (``metal.conflicts``) are quit as well, or None when it still does not fit."""
313
- if not metal.supported(roomy) or not metal.conflicts(roomy):
315
+ alone = setup_inspection_harness.without_other_inference(roomy)
316
+ if alone is None:
314
317
  return None
315
- alone = copy.deepcopy(roomy)
316
- services = alone["services"]
317
- assert services is not None # conflicts come from service discovery
318
- services["compute_processes"] = [
319
- p
320
- for p in services.get("compute_processes") or []
321
- if p["gpu_uuid"] != metal.METAL_UUID or p["owned"] is True
322
- ]
323
318
  try:
324
319
  return stack.build(options, facts=alone)
325
- except (PlanError, stack.StackError, harness.HarnessError):
320
+ except (PlanError, stack.StackError):
326
321
  return None
327
322
 
328
323
 
329
324
  def _plans(options: StackOptions, facts: HostFacts) -> bool:
330
325
  try:
331
326
  stack.build(options, facts=facts)
332
- except (PlanError, stack.StackError, harness.HarnessError):
327
+ except (PlanError, stack.StackError):
333
328
  return False
334
329
  return True
335
330
 
@@ -418,11 +413,16 @@ def _classify(availability: StackAvailability, facts: HostFacts) -> None:
418
413
  availability.get("basis") == "capacity"
419
414
  or "gpu-sharing-required" in codes
420
415
  or bool(codes & _DRIVER_REASON_CODES)
416
+ or (
417
+ bool(codes & setup_inspection_harness.HARNESS_CODES)
418
+ and availability.get("hardwareCapable") is True
419
+ )
421
420
  ):
422
421
  availability["state"], availability["hardwareCapable"] = "blocked-now", True
423
422
  else:
424
423
  availability["state"] = "unavailable"
425
- availability["hardwareCapable"] = None if "facts-unavailable" in codes else False
424
+ if "hardwareCapable" not in availability:
425
+ availability["hardwareCapable"] = None if "facts-unavailable" in codes else False
426
426
  plan, summary = availability["plan"], availability.get("summary")
427
427
  if availability.get("basis") != "capacity" or plan is None or summary is None:
428
428
  return
@@ -537,13 +537,17 @@ INSPECT = (
537
537
  )
538
538
  INSPECT_REASONS = (
539
539
  "unsupported-platform · facts-unavailable · plan-unavailable · gpu-sharing-required\n"
540
- "cuda-driver-update-required · cuda-driver-version-unknown\n"
540
+ "cuda-driver-update-required · cuda-driver-version-unknown · gateway-port-in-use · "
541
+ "harness-unavailable\n"
541
542
  "(gpu-sharing-required: a plan fits only beside other GPU work, its owner known or not; ask, "
542
543
  "then rerun with --share-gpu, which plans by the free VRAM)\n"
543
544
  "cuda-driver-update-required / cuda-driver-version-unknown (stack.state is blocked-now, "
544
545
  "hardwareCapable is true: the GPU can run local models, but the NVIDIA driver's CUDA version "
545
546
  "is older than requiredCudaVersion or could not be read; detectedCudaVersion, "
546
547
  "requiredCudaVersion and driverVersion carry the versions)\n"
548
+ "gateway-port-in-use / harness-unavailable (stack.state is blocked-now with "
549
+ "hardwareCapable true when the hardware fits, but the gateway port is held or tool checks "
550
+ "failed; free the port or fix the tool issue and check again)\n"
547
551
  "gpu-memory-required (stack.state is blocked-now, stack.basis is capacity: other programs "
548
552
  "use the GPU memory the plan needs; close them and check again; gpuIndex, freeBytes and "
549
553
  "requiredBytes give the card and its free and needed VRAM)\n"
@@ -0,0 +1,147 @@
1
+ """Classify ``HarnessError`` in ``setup inspect`` separately from hardware incapability."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import copy
6
+
7
+ from localmodels import (
8
+ budget,
9
+ deploy,
10
+ harness,
11
+ metal,
12
+ stack,
13
+ stack_compose,
14
+ stack_gpu_memory,
15
+ stack_hardware,
16
+ stack_suite,
17
+ )
18
+ from localmodels.plan_envelope import PlanError
19
+ from localmodels.probe import HostFacts
20
+ from localmodels.setup_text import Lang, text
21
+ from localmodels.stack_plan import RAM_FLOOR, StackOptions, platform_error
22
+
23
+ HARNESS_CODES = frozenset({"gateway-port-in-use", "harness-unavailable"})
24
+ _PORT_CONFLICT_HINTS = (
25
+ "is held by",
26
+ "ports 3425..3456 are all in use",
27
+ "port still listening",
28
+ )
29
+
30
+
31
+ def capacity_facts(facts: HostFacts) -> HostFacts | None:
32
+ """``facts`` once the user's other programs are closed, or None when that frees nothing.
33
+
34
+ A Mac keeps what an idle one leaves to macOS and applications (``metal.in_use``) and is at
35
+ normal pressure; a Linux host keeps the planner's own floor a second time for its desktop.
36
+ An NVIDIA card keeps an idle driver context, unless serving work this tool does not own
37
+ runs on it: that memory needs sharing consent, and closing applications does not free it.
38
+ """
39
+ roomy = copy.deepcopy(facts)
40
+ ram = roomy["ram"]
41
+ total = ram["total_bytes"]
42
+ if metal.supported(facts):
43
+ room = total - metal.in_use(total)
44
+ ram["pressure_level"] = 1
45
+ ram.pop("pressure_kept_bytes", None)
46
+ else:
47
+ room = total - RAM_FLOOR
48
+ ram["available_bytes"] = max(ram["available_bytes"], room)
49
+ served = budget.gpu_conflicts(facts)
50
+ for gpu in roomy.get("gpus") or []:
51
+ if served.get(gpu["uuid"]):
52
+ continue
53
+ idle = max(0, gpu["total_bytes"] - budget.IDLE_USED_BYTES)
54
+ if gpu["free_bytes"] < idle:
55
+ gpu["free_bytes"], gpu["used_bytes"] = idle, gpu["total_bytes"] - idle
56
+ return None if roomy == facts else roomy
57
+
58
+
59
+ def harness_code(error: harness.HarnessError) -> str:
60
+ if error.code in HARNESS_CODES:
61
+ return error.code
62
+ lowered = str(error).lower()
63
+ if any(hint in lowered for hint in _PORT_CONFLICT_HINTS):
64
+ return "gateway-port-in-use"
65
+ return "harness-unavailable"
66
+
67
+
68
+ def fits_hardware_once(options: StackOptions, facts: HostFacts) -> bool:
69
+ """Whether ``facts`` can fit a verified local stack ignoring gateway/harness conflicts."""
70
+ try:
71
+ seen = stack_hardware.assumed(facts, options.get("unified_memory"))
72
+ if platform_error(seen["platform"], options.get("profile"), seen["arch"]):
73
+ return False
74
+ if options.get("profile") != "macos-mlx-preview" and metal.problem(seen):
75
+ return False
76
+ if metal.supported(seen) and options.get("profile") != "macos-mlx-preview":
77
+ seen = metal.reclaimed(seen)
78
+ seen, _ = metal.pressured(seen)
79
+ seen, _ = stack_gpu_memory.capped(seen, options)
80
+ resolver = deploy.catalog_pins if options.get("offline") else deploy.resolve_files
81
+ parts, chosen = stack_compose.choose_parts(
82
+ seen,
83
+ options,
84
+ resolver=resolver,
85
+ listening=lambda _port: False,
86
+ previous=lambda _name, _port: None,
87
+ existing=lambda _recipes: [],
88
+ owned_ram=lambda: 0,
89
+ )
90
+ if chosen.get("defer_services"):
91
+ parts["decision"] = {
92
+ **parts["decision"],
93
+ "plan": None,
94
+ "front": None,
95
+ "existing": None,
96
+ "options": [],
97
+ }
98
+ named = stack_suite.named_foundations(chosen)
99
+ parts["aux"] = [p for p in parts["aux"] if stack_suite.task_of(p) not in named]
100
+ stack_compose.ram_budget(parts)
101
+ except (PlanError, stack.StackError):
102
+ return False
103
+ return True
104
+
105
+
106
+ def without_other_inference(roomy: HostFacts) -> HostFacts | None:
107
+ """``roomy`` with foreign Metal inference apps stripped, or None when none are present."""
108
+ if not metal.supported(roomy) or not metal.conflicts(roomy):
109
+ return None
110
+ alone = copy.deepcopy(roomy)
111
+ services = alone["services"]
112
+ assert services is not None # conflicts come from service discovery
113
+ services["compute_processes"] = [
114
+ p
115
+ for p in services.get("compute_processes") or []
116
+ if p["gpu_uuid"] != metal.METAL_UUID or p["owned"] is True
117
+ ]
118
+ return alone
119
+
120
+
121
+ def hardware_capable_without_harness(options: StackOptions, facts: HostFacts) -> bool:
122
+ """True when the computer's hardware fits a stack once gateway/harness blockers clear."""
123
+ if fits_hardware_once(options, facts):
124
+ return True
125
+ if (
126
+ not options.get("share_gpu")
127
+ and budget.holders(facts)
128
+ and (not budget.unknown_services(facts) or not metal.supported(facts))
129
+ and fits_hardware_once({**options, "share_gpu": True}, facts)
130
+ ):
131
+ return True
132
+ if roomy := capacity_facts(facts):
133
+ if fits_hardware_once(options, roomy):
134
+ return True
135
+ if (alone := without_other_inference(roomy)) is not None:
136
+ return fits_hardware_once(options, alone)
137
+ return False
138
+
139
+
140
+ def classify_harness_error(
141
+ options: StackOptions, facts: HostFacts, exc: harness.HarnessError, lang: Lang
142
+ ) -> tuple[str, bool, str]:
143
+ """Return ``(reason_code, hardware_capable, message)`` for a gateway/tool ``HarnessError``."""
144
+ code = harness_code(exc)
145
+ capable = hardware_capable_without_harness(options, facts)
146
+ message = text(code, lang, detail=str(exc)) if capable else str(exc)
147
+ return code, capable, message
@@ -86,6 +86,18 @@ MESSAGES: dict[str, tuple[str, str]] = {
86
86
  "(requires CUDA {required} or newer). Update or reinstall the NVIDIA driver and check "
87
87
  "again.",
88
88
  ),
89
+ "gateway-port-in-use": (
90
+ "这台电脑的硬件可以运行本地模型,但网关端口当前被其他程序占用({detail})。"
91
+ "请停止占用该端口的程序,或设置其他网关地址后重新检查。",
92
+ "This computer's hardware can run local models, but the gateway port is currently in use "
93
+ "({detail}). Stop that program or set another gateway address, then check again.",
94
+ ),
95
+ "harness-unavailable": (
96
+ "这台电脑的硬件可以运行本地模型,但网关或工具环境检查未通过({detail})。"
97
+ "请先处理该问题后重新检查。",
98
+ "This computer's hardware can run local models, but gateway or tool preparation is "
99
+ "currently blocked ({detail}). Resolve this issue and check again.",
100
+ ),
89
101
  "plan-invalid": (
90
102
  "批准计划不存在、无效或摘要不一致。",
91
103
  "The approved plan is missing or invalid, or its digest does not match.",
@@ -96,10 +96,20 @@ def upgrade_hint(
96
96
  gib = budget.gib
97
97
  reasons: list[UpgradeReason] = []
98
98
  live_gpus = {g["index"]: g for g in facts.get("gpus") or []}
99
+ is_strata = str(roomy_plan["llm"]["engine"].get("build") or "").startswith("strata")
100
+ idle_cap = (
101
+ budget.DESKTOP_VRAM_BASELINE_CAP_BYTES
102
+ if facts.get("platform") == "win32" and facts.get("services") is not None
103
+ else budget.IDLE_USED_BYTES
104
+ )
99
105
  for index, vram in _vram_by_card(roomy_plan).items():
100
106
  card = live_gpus.get(index)
107
+ if card is None:
108
+ continue
101
109
  required = vram + AGENT_VRAM_RESERVE_BYTES
102
- if card is None or card["free_bytes"] >= required:
110
+ if is_strata and not options.get("share_gpu"):
111
+ required = max(required, max(0, card["total_bytes"] - idle_cap))
112
+ if card["free_bytes"] >= required:
103
113
  continue
104
114
  reasons.append(
105
115
  {
@@ -112,7 +112,9 @@ def build(
112
112
  == Path(options["base_dir"]).expanduser()
113
113
  ):
114
114
  context = accepted
115
- tools_dir = context["harness"]["tools_dir"] if context else harness.DEFAULT_TOOLS_DIR
115
+ tools_dir = hosts.tools_dir(
116
+ context["harness"]["tools_dir"] if context else harness.DEFAULT_TOOLS_DIR
117
+ )
116
118
  tools = harness.inspect(
117
119
  tools_dir=tools_dir, approved=context["harness"] if context else None, private_clients=True
118
120
  )
@@ -77,7 +77,9 @@ def strata_parts(
77
77
  added to ``passed_over`` for the llama.cpp plan's warnings."""
78
78
  bar, llama_id = llama
79
79
  skipped: list[str] = []
80
- for recipe in stack_suite.auto_strata_candidates(facts, llm_rank.strata_bar(bar, options)):
80
+ for recipe in stack_suite.auto_strata_candidates(
81
+ facts, llm_rank.strata_bar(bar, options), llama_score=bar, options=options
82
+ ):
81
83
  score = recipe["quality"]["score"]
82
84
  why = (
83
85
  f"LLM: auto picks Strata {recipe['id']} (installed SimplexAI score {score}"
@@ -154,7 +156,9 @@ def card_fits(
154
156
  share = bool(options.get("share_gpu", False) or gpu_conflicts(facts).get(gpu["uuid"]))
155
157
  bar = llm_rank.strata_bar(llama_score, probe_opts)
156
158
  fits: list[LlmFit] = []
157
- for recipe in stack_suite.auto_strata_candidates(facts, bar):
159
+ for recipe in stack_suite.auto_strata_candidates(
160
+ facts, bar, llama_score=llama_score, options=probe_opts
161
+ ):
158
162
  candidate_options: StackOptions = {
159
163
  **probe_opts,
160
164
  "gpu": index,
@@ -6,6 +6,7 @@ import argparse
6
6
  import contextlib
7
7
  import json
8
8
  import os
9
+ import re
9
10
  import sys
10
11
  from collections.abc import Callable
11
12
  from pathlib import Path
@@ -14,6 +15,7 @@ from typing import Any
14
15
  from localmodels import (
15
16
  app,
16
17
  console,
18
+ deploy,
17
19
  harness,
18
20
  hosts,
19
21
  stack_arena,
@@ -210,6 +212,41 @@ def apply_cli(
210
212
  return report(record, timing=shown.timing() if shown else None)
211
213
 
212
214
 
215
+ _PLAN_ERROR_CODES = frozenset(
216
+ {
217
+ "HUB_UNREACHABLE",
218
+ "MEMORY_INSUFFICIENT",
219
+ "DISK_INSUFFICIENT",
220
+ "GPU_CONFLICT",
221
+ }
222
+ )
223
+ _SAFE_HOST = re.compile(r"^[A-Za-z0-9](?:[A-Za-z0-9.-]*[A-Za-z0-9])?(?::[0-9]{1,5})?$")
224
+
225
+
226
+ def _plan_error_payload(exc: BaseException) -> dict[str, object]:
227
+ """Structured, path-free error document for ``stack plan --json`` failures."""
228
+ raw_code = getattr(exc, "cause_code", None)
229
+ code = (
230
+ raw_code
231
+ if isinstance(raw_code, str) and raw_code in _PLAN_ERROR_CODES
232
+ else "STACK_PLAN_FAILED"
233
+ )
234
+ payload: dict[str, object] = {
235
+ "schema": "localmodels.stack-plan-error/v1",
236
+ "event": "error",
237
+ "code": code,
238
+ }
239
+ if isinstance(exc, deploy.HubUnreachableError):
240
+ hosts_tried = [
241
+ host
242
+ for host, _ in exc.failures
243
+ if isinstance(host, str) and len(host) <= 253 and _SAFE_HOST.fullmatch(host)
244
+ ]
245
+ if hosts_tried:
246
+ payload["hosts"] = list(dict.fromkeys(hosts_tried))
247
+ return payload
248
+
249
+
213
250
  def run_cli(
214
251
  args: argparse.Namespace,
215
252
  *,
@@ -284,5 +321,7 @@ def run_cli(
284
321
  ) as exc:
285
322
  if getattr(args, "jsonl", False):
286
323
  return stack_progress.error(2, guard_details(exc))
324
+ if args.stack_command == "plan" and getattr(args, "json", False):
325
+ print(json.dumps(_plan_error_payload(exc), separators=(",", ":")))
287
326
  print(f"stack: {exc}", file=sys.stderr)
288
327
  return 2
@@ -95,7 +95,7 @@ def plan_tools(
95
95
  actions: list[harness.ToolAction] = []
96
96
  native: dict[str, dict[str, Any]] = {}
97
97
  native_arch = {"x86_64": "x64", "aarch64": "arm64"}.get(arch, arch)
98
- root = Path(tools_dir).expanduser().absolute() / "clients"
98
+ root = Path(hosts.tools_dir(tools_dir)).expanduser().absolute() / "clients"
99
99
  owned = {tool["path"]: tool for tool in hosts.load_owned(tools_dir)["tools"]}
100
100
  for client, seen in planned_clients(state).items():
101
101
  wrapper = Path(harness.BIN_DIR).expanduser() / client