@simplexai/localmodels-darwin-x64 0.1.0-dev.62 → 0.1.0-dev.64
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.
- package/bootstrap.identity +1 -1
- package/bootstrap.sha256 +112 -103
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/app.py +15 -2
- package/modules/localmodels/bifrost_checks.py +19 -13
- package/modules/localmodels/bifrost_clients.py +38 -36
- package/modules/localmodels/bifrost_config.py +19 -6
- package/modules/localmodels/bifrost_log.py +3 -3
- package/modules/localmodels/bifrost_models.py +9 -8
- package/modules/localmodels/bifrost_pi.py +27 -72
- package/modules/localmodels/catalog.json +85 -58
- package/modules/localmodels/catalog.py +26 -4
- package/modules/localmodels/catalog_recipes.py +37 -1
- package/modules/localmodels/context_policy.py +6 -1
- package/modules/localmodels/custom_hub.py +10 -1
- package/modules/localmodels/custom_hub_http.py +14 -3
- package/modules/localmodels/debug_mode.py +85 -103
- package/modules/localmodels/deploy.py +41 -6
- package/modules/localmodels/download-mirrors.json +126 -6
- package/modules/localmodels/draft_spec.py +122 -0
- package/modules/localmodels/engine_adapters/__init__.py +4 -0
- package/modules/localmodels/engine_adapters/auxiliary.py +27 -0
- package/modules/localmodels/engine_adapters/base.py +40 -0
- package/modules/localmodels/engine_adapters/strata_poly.py +57 -0
- package/modules/localmodels/engine_adapters/suite_plan.py +394 -0
- package/modules/localmodels/engines-prism-b12178-03ec600.json +7 -7
- package/modules/localmodels/gateway.py +56 -55
- package/modules/localmodels/gateway_bifrost.py +70 -83
- package/modules/localmodels/gateway_clients.py +33 -116
- package/modules/localmodels/gateway_home.py +5 -5
- package/modules/localmodels/gateway_keys.py +8 -6
- package/modules/localmodels/gateway_probe.py +4 -4
- package/modules/localmodels/gateway_server.py +4 -4
- package/modules/localmodels/gateway_speed.py +2 -2
- package/modules/localmodels/harness.py +185 -401
- package/modules/localmodels/harness_core.py +409 -0
- package/modules/localmodels/harness_gateway.py +75 -73
- package/modules/localmodels/harness_probe.py +19 -216
- package/modules/localmodels/install.py +15 -0
- package/modules/localmodels/library_convert.py +2 -8
- package/modules/localmodels/library_custom.py +51 -16
- package/modules/localmodels/library_elastic.py +3 -119
- package/modules/localmodels/library_gateway.py +59 -176
- package/modules/localmodels/library_jobs.py +1 -2
- package/modules/localmodels/library_model.py +23 -0
- package/modules/localmodels/library_poly.py +3 -2
- package/modules/localmodels/library_pricing.py +124 -15
- package/modules/localmodels/library_serve.py +9 -9
- package/modules/localmodels/library_smoke.py +33 -21
- package/modules/localmodels/library_status.py +330 -2
- package/modules/localmodels/llm_rank.py +14 -5
- package/modules/localmodels/magpie_setup.py +5 -4
- package/modules/localmodels/magpie_windows.py +1 -1
- package/modules/localmodels/memcalc_cli.py +2 -2
- package/modules/localmodels/pi_profile.py +384 -0
- package/modules/localmodels/planning/__init__.py +3 -0
- package/modules/localmodels/{memcalc_load.py → planning/memcalc_load.py} +1 -1
- package/modules/localmodels/{sizecalc.py → planning/sizecalc.py} +1 -1
- package/modules/localmodels/process_identity.py +3 -3
- package/modules/localmodels/runtime_cli.py +32 -46
- package/modules/localmodels/runtime_pi.py +1 -1
- package/modules/localmodels/service_deployment.py +2 -1
- package/modules/localmodels/sizecalc_cli.py +10 -2
- package/modules/localmodels/source_byok.py +9 -16
- package/modules/localmodels/speech_worker_sensevoice.py +30 -0
- package/modules/localmodels/stack.py +2 -4
- package/modules/localmodels/stack_arena.py +2 -2
- package/modules/localmodels/stack_auto.py +1 -1
- package/modules/localmodels/stack_aux_gpu.py +4 -2
- package/modules/localmodels/stack_binding.py +9 -7
- package/modules/localmodels/stack_card.py +2 -2
- package/modules/localmodels/stack_cleanup.py +3 -2
- package/modules/localmodels/stack_clients.py +137 -21
- package/modules/localmodels/stack_compose.py +9 -1
- package/modules/localmodels/stack_doctor.py +6 -3
- package/modules/localmodels/stack_hardware.py +18 -0
- package/modules/localmodels/stack_ledger.py +2 -1
- package/modules/localmodels/stack_lifecycle.py +3 -2
- package/modules/localmodels/stack_mcp.py +1 -1
- package/modules/localmodels/stack_memory.py +3 -3
- package/modules/localmodels/stack_remove.py +2 -1
- package/modules/localmodels/stack_run.py +16 -0
- package/modules/localmodels/stack_suite.py +4 -3
- package/modules/localmodels/stack_try.py +2 -1
- package/modules/localmodels/stack_up.py +15 -30
- package/modules/localmodels/stack_verify.py +2 -2
- package/modules/localmodels/stack_view_events.py +2 -2
- package/modules/localmodels/stack_view_llm.py +12 -7
- package/modules/localmodels/stack_warm.py +6 -3
- package/modules/localmodels/stack_whatif.py +1 -1
- package/modules/localmodels/suite.py +6 -334
- package/modules/localmodels/tui_views.py +17 -2
- package/modules/localmodels/web/index.html +595 -226
- package/modules/localmodels/web/sizecalc/app.js +34 -40
- package/modules/localmodels/web/sizecalc/calc.js +3 -3
- package/modules/localmodels/web/sizecalc/page.html +4 -3
- package/modules/localmodels/web/view/fleet.html +18 -3
- package/modules/localmodels/web/view/fleet.js +135 -14
- package/modules/localmodels/web/view/i18n.js +4 -0
- package/modules/localmodels/web/view/index.html +16 -0
- package/modules/localmodels/web/view/nav.js +49 -0
- package/modules/localmodels/web/view/theme.js +1 -1
- package/modules/localmodels/web/view/view.css +51 -15
- package/modules/localmodels/web/view/view.js +22 -4
- package/modules/{simplex_localmodels-0.1.0.dev62.dist-info → simplex_localmodels-0.1.0.dev64.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev62.dist-info → simplex_localmodels-0.1.0.dev64.dist-info}/RECORD +109 -100
- package/package.json +1 -1
- package/tool.json +1 -1
- /package/modules/localmodels/{memcalc.py → planning/memcalc.py} +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev62.dist-info → simplex_localmodels-0.1.0.dev64.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev62.dist-info → simplex_localmodels-0.1.0.dev64.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev62.dist-info → simplex_localmodels-0.1.0.dev64.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev62.dist-info → simplex_localmodels-0.1.0.dev64.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -19,6 +19,7 @@ from localmodels import (
|
|
|
19
19
|
harness,
|
|
20
20
|
hosts,
|
|
21
21
|
library_gateway,
|
|
22
|
+
pi_profile,
|
|
22
23
|
runtime_io,
|
|
23
24
|
)
|
|
24
25
|
from localmodels.probe import HostFacts
|
|
@@ -443,22 +444,14 @@ def _write_claude_profile(root: Path, addr: str, context: int) -> str:
|
|
|
443
444
|
|
|
444
445
|
|
|
445
446
|
def _write_pi_profile(root: Path, addr: str, facts: bifrost_models.LlmFacts) -> str:
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
}
|
|
455
|
-
settings_doc = {
|
|
456
|
-
"defaultProvider": gateway_bifrost.PI_PROVIDER,
|
|
457
|
-
"defaultModel": BYOK_MODEL,
|
|
458
|
-
}
|
|
459
|
-
runtime_io.write_private_json(pi_dir / "models.json", models_doc)
|
|
460
|
-
runtime_io.write_private_json(pi_dir / "settings.json", settings_doc)
|
|
461
|
-
return str(pi_dir)
|
|
447
|
+
store = pi_profile.PiProfileStore(root / ".pi" / "agent")
|
|
448
|
+
return str(
|
|
449
|
+
store.write_isolated_profile(
|
|
450
|
+
gateway_bifrost.PI_PROVIDER,
|
|
451
|
+
bifrost_models.pi_provider(facts, BYOK_MODEL, f"http://{addr}"),
|
|
452
|
+
BYOK_MODEL,
|
|
453
|
+
)
|
|
454
|
+
)
|
|
462
455
|
|
|
463
456
|
|
|
464
457
|
def write_byok_profiles(addr: str, creds: ByokCredentials) -> dict[str, str]:
|
|
@@ -11,7 +11,9 @@ from __future__ import annotations
|
|
|
11
11
|
|
|
12
12
|
import argparse
|
|
13
13
|
import array
|
|
14
|
+
import ctypes
|
|
14
15
|
import importlib
|
|
16
|
+
import importlib.util
|
|
15
17
|
import io
|
|
16
18
|
import json
|
|
17
19
|
import os
|
|
@@ -100,10 +102,38 @@ class Recognizer(Protocol):
|
|
|
100
102
|
) -> dict[str, object]: ...
|
|
101
103
|
|
|
102
104
|
|
|
105
|
+
def _preload_windows_onnxruntime() -> None:
|
|
106
|
+
"""Preload sherpa-onnx's bundled onnxruntime.dll on Windows.
|
|
107
|
+
|
|
108
|
+
Electron hosts enable PreferSystem32Images, which otherwise resolves System32's
|
|
109
|
+
older inbox onnxruntime.dll ahead of sherpa_onnx/lib/onnxruntime.dll. Loading the
|
|
110
|
+
bundled DLL by full path pins the process module table before importing sherpa_onnx.
|
|
111
|
+
"""
|
|
112
|
+
if sys.platform != "win32" or "sherpa_onnx" in sys.modules:
|
|
113
|
+
return
|
|
114
|
+
spec = importlib.util.find_spec("sherpa_onnx")
|
|
115
|
+
if spec is None:
|
|
116
|
+
return
|
|
117
|
+
search_roots: list[Path] = []
|
|
118
|
+
if spec.submodule_search_locations:
|
|
119
|
+
search_roots.extend(Path(location) for location in spec.submodule_search_locations)
|
|
120
|
+
elif spec.origin:
|
|
121
|
+
search_roots.append(Path(spec.origin).resolve().parent)
|
|
122
|
+
win_dll = getattr(ctypes, "WinDLL", None)
|
|
123
|
+
if win_dll is None:
|
|
124
|
+
return
|
|
125
|
+
for root in search_roots:
|
|
126
|
+
ort_dll = root / "lib" / "onnxruntime.dll"
|
|
127
|
+
if ort_dll.is_file():
|
|
128
|
+
win_dll(str(ort_dll))
|
|
129
|
+
return
|
|
130
|
+
|
|
131
|
+
|
|
103
132
|
class SenseVoiceRecognizer:
|
|
104
133
|
"""Thread-safe sherpa-onnx OfflineRecognizer wrapper for SenseVoice Small INT8."""
|
|
105
134
|
|
|
106
135
|
def __init__(self, model: Path, tokens: Path, *, threads: int = 4) -> None:
|
|
136
|
+
_preload_windows_onnxruntime()
|
|
107
137
|
sherpa_onnx = importlib.import_module("sherpa_onnx")
|
|
108
138
|
self._recognizer: Any = sherpa_onnx.OfflineRecognizer.from_sense_voice(
|
|
109
139
|
model=str(model),
|
|
@@ -21,11 +21,11 @@ from localmodels import (
|
|
|
21
21
|
gateway,
|
|
22
22
|
harness,
|
|
23
23
|
hosts,
|
|
24
|
+
library_convert,
|
|
24
25
|
stack_events,
|
|
25
26
|
stack_journal,
|
|
26
27
|
stack_preflight,
|
|
27
28
|
stack_run,
|
|
28
|
-
stack_up,
|
|
29
29
|
stack_update,
|
|
30
30
|
)
|
|
31
31
|
from localmodels import stack_decision as decide
|
|
@@ -94,7 +94,7 @@ def build(
|
|
|
94
94
|
resolver = deploy.catalog_pins if options.get("offline") else deploy.resolve_files
|
|
95
95
|
context = approved
|
|
96
96
|
if context is None:
|
|
97
|
-
accepted =
|
|
97
|
+
accepted = stack_run.accepted()
|
|
98
98
|
if (
|
|
99
99
|
accepted
|
|
100
100
|
and Path(accepted["options"]["base_dir"]).expanduser()
|
|
@@ -343,8 +343,6 @@ def _deploy_aux(task: str, part: Plan, key: str, log: Log, do: Effects) -> Compo
|
|
|
343
343
|
|
|
344
344
|
def _sync_library(plan: StackPlan, attempt_id: str | None) -> None:
|
|
345
345
|
"""Keep an already-used model library in step with a newly accepted stack apply."""
|
|
346
|
-
from localmodels import library_convert
|
|
347
|
-
|
|
348
346
|
if library_convert.initialized():
|
|
349
347
|
library_convert.sync_stack(plan, attempt_id=attempt_id, if_initialized=True)
|
|
350
348
|
|
|
@@ -29,7 +29,7 @@ from dataclasses import dataclass, field
|
|
|
29
29
|
from pathlib import Path
|
|
30
30
|
from typing import Literal, TypedDict
|
|
31
31
|
|
|
32
|
-
from localmodels import cli_help, console, hosts, http_local, stack_up, stack_verify
|
|
32
|
+
from localmodels import cli_help, console, hosts, http_local, stack_run, stack_up, stack_verify
|
|
33
33
|
from localmodels.plan_envelope import utc_now
|
|
34
34
|
from localmodels.records import Plan
|
|
35
35
|
from localmodels.stack_plan import StackError, command
|
|
@@ -343,7 +343,7 @@ def _resolve_targets(args: argparse.Namespace) -> tuple[ArenaTarget, ArenaTarget
|
|
|
343
343
|
):
|
|
344
344
|
return _explicit_targets(args)
|
|
345
345
|
by_name = {r["plan"]["name"]: r["plan"] for r in hosts.records(hosts.LOCAL_ID) if r.get("ok")}
|
|
346
|
-
plan =
|
|
346
|
+
plan = stack_run.accepted()
|
|
347
347
|
if plan is not None and plan.get("llm_fast") is not None:
|
|
348
348
|
if stack_up.drift(plan):
|
|
349
349
|
raise StackError(
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
The caller supplies the resident llama.cpp score and id. The validated recipe order, tie band,
|
|
4
4
|
RAM fit and generated-pack refusals are the same policy formerly in stack_compose; local reads
|
|
5
|
-
are supplied through the planner's readers and
|
|
5
|
+
are supplied through the planner's readers and suite_plan.build_plan. No state is saved or applied.
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
8
|
from __future__ import annotations
|
|
@@ -15,6 +15,7 @@ from dataclasses import replace
|
|
|
15
15
|
from localmodels import component, hosts, metal, suite
|
|
16
16
|
from localmodels import stack_decision as decide
|
|
17
17
|
from localmodels.budget import gib
|
|
18
|
+
from localmodels.engine_adapters import suite_plan
|
|
18
19
|
from localmodels.plan_envelope import PlanError
|
|
19
20
|
from localmodels.probe import GPU, HostFacts
|
|
20
21
|
from localmodels.records import Plan
|
|
@@ -61,11 +62,12 @@ def _metal_keep_aux(
|
|
|
61
62
|
aux: list[Plan],
|
|
62
63
|
price_llm: decide.PriceLLM,
|
|
63
64
|
) -> Plan:
|
|
64
|
-
"""Step optional Metal ubatch/MTP back
|
|
65
|
+
"""Step optional Metal ubatch/MTP/draft back when unified-memory auxiliaries need the RAM."""
|
|
65
66
|
launch = llm["launch"]
|
|
66
67
|
if not aux or (
|
|
67
68
|
int(str(launch.get("ubatch") or 512)) <= 512
|
|
68
69
|
and int(str(launch.get("mtp_draft_depth") or 0)) <= 0
|
|
70
|
+
and int(str(launch.get("draft_n_max") or 0)) <= 0
|
|
69
71
|
):
|
|
70
72
|
return llm
|
|
71
73
|
needed = (
|
|
@@ -132,7 +134,7 @@ def place(
|
|
|
132
134
|
out.append(part)
|
|
133
135
|
continue
|
|
134
136
|
try:
|
|
135
|
-
gpu_part =
|
|
137
|
+
gpu_part = suite_plan.build_plan(
|
|
136
138
|
hosts.LOCAL_ID,
|
|
137
139
|
facts,
|
|
138
140
|
recipe,
|
|
@@ -9,7 +9,7 @@ import sys
|
|
|
9
9
|
from pathlib import Path
|
|
10
10
|
from typing import TypedDict, cast
|
|
11
11
|
|
|
12
|
-
from localmodels import harness, hosts, runtime_discovery, stack, stack_run
|
|
12
|
+
from localmodels import harness, harness_core, hosts, runtime_discovery, stack, stack_run
|
|
13
13
|
from localmodels import stack_lifecycle as lifecycle
|
|
14
14
|
from localmodels.setup_text import Lang, text
|
|
15
15
|
from localmodels.stack_plan import StackPlan, deployments
|
|
@@ -208,7 +208,7 @@ def _bifrost_binding(plan: StackPlan, owned: hosts.Owned, lang: Lang = "zh") ->
|
|
|
208
208
|
except harness.HarnessError:
|
|
209
209
|
return _reason("gateway-ownership", lang, "gateway-record")
|
|
210
210
|
executable = Path(harness.tool_path(plan["harness"], "pi"))
|
|
211
|
-
profile = bifrost_pi.pi_profile(
|
|
211
|
+
profile = bifrost_pi.pi_profile(harness_core.gateway_environment(plan["harness"]))
|
|
212
212
|
if not executable.is_absolute() or not profile.is_absolute():
|
|
213
213
|
raise ValueError("Pi paths must be absolute")
|
|
214
214
|
fingerprint = _profile_fingerprint(executable, profile)
|
|
@@ -218,8 +218,8 @@ def _bifrost_binding(plan: StackPlan, owned: hosts.Owned, lang: Lang = "zh") ->
|
|
|
218
218
|
or bifrost_pi.pi_model(profile) != (gateway["pi_model"])
|
|
219
219
|
):
|
|
220
220
|
return _reason("gateway-unavailable", lang)
|
|
221
|
-
env = {**
|
|
222
|
-
listed =
|
|
221
|
+
env = {**harness_core.gateway_environment(plan["harness"]), "PI_CODING_AGENT_DIR": str(profile)}
|
|
222
|
+
listed = harness_core.run_tool([str(executable), "--list-models"], timeout=30, env=env)
|
|
223
223
|
expected = gateway["pi_model"].split("/", 1)
|
|
224
224
|
if listed.returncode != 0 or not any(
|
|
225
225
|
len(fields) >= 2 and fields[:2] == expected
|
|
@@ -246,7 +246,9 @@ def _pi_binding(plan: StackPlan, owned: hosts.Owned, lang: Lang = "zh") -> PiBin
|
|
|
246
246
|
):
|
|
247
247
|
return _reason("gateway-ownership", lang)
|
|
248
248
|
executable = Path(harness.tool_path(plan["harness"], "pi"))
|
|
249
|
-
profile = Path(
|
|
249
|
+
profile = Path(
|
|
250
|
+
harness_core.gateway_environment(plan["harness"])["PI_CODING_AGENT_DIR"]
|
|
251
|
+
).expanduser()
|
|
250
252
|
if not executable.is_absolute() or not profile.is_absolute():
|
|
251
253
|
raise ValueError("Pi paths must be absolute")
|
|
252
254
|
fingerprint = _profile_fingerprint(executable, profile)
|
|
@@ -275,7 +277,7 @@ def _pi_binding(plan: StackPlan, owned: hosts.Owned, lang: Lang = "zh") -> PiBin
|
|
|
275
277
|
or state["pi_model"] != gateway["pi_model"]
|
|
276
278
|
):
|
|
277
279
|
return _reason("gateway-unavailable", lang)
|
|
278
|
-
listed =
|
|
280
|
+
listed = harness_core.run_tool([str(executable), "--list-models"], timeout=30, env=env)
|
|
279
281
|
expected = gateway["pi_model"].split("/", 1)
|
|
280
282
|
if listed.returncode != 0 or not any(
|
|
281
283
|
len(fields) >= 2 and fields[:2] == expected
|
|
@@ -320,7 +322,7 @@ def _library_binding(
|
|
|
320
322
|
return _reason("deployment-unavailable", lang)
|
|
321
323
|
gateway = plan["harness"]["gateway"]
|
|
322
324
|
executable = Path(harness.tool_path(plan["harness"], "pi"))
|
|
323
|
-
environment =
|
|
325
|
+
environment = harness_core.gateway_environment(plan["harness"])
|
|
324
326
|
# The profile the stack's own binding reads: a Magpie plan on a shared daemon has none
|
|
325
327
|
# (KeyError, unavailable), never the user's ~/.pi/agent.
|
|
326
328
|
profile = (
|
|
@@ -13,7 +13,7 @@ import math
|
|
|
13
13
|
from html import escape
|
|
14
14
|
from pathlib import Path
|
|
15
15
|
|
|
16
|
-
from localmodels import cli_help, stack_up, stack_view_llm, stack_warm, suite
|
|
16
|
+
from localmodels import cli_help, stack_run, stack_up, stack_view_llm, stack_warm, suite
|
|
17
17
|
from localmodels.budget import gib
|
|
18
18
|
from localmodels.stack_plan import StackError, StackPlan
|
|
19
19
|
|
|
@@ -181,7 +181,7 @@ def add_parser(actions: argparse._SubParsersAction[argparse.ArgumentParser]) ->
|
|
|
181
181
|
|
|
182
182
|
|
|
183
183
|
def cli(args: argparse.Namespace) -> int:
|
|
184
|
-
plan =
|
|
184
|
+
plan = stack_run.accepted()
|
|
185
185
|
if plan is None or stack_up.drift(plan):
|
|
186
186
|
raise StackError("no unchanged accepted local stack; run stack install or stack up")
|
|
187
187
|
directory = Path(plan["llm"]["service"]["deploy_dir"]).expanduser()
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
An uninstall leaves nothing behind but what was downloaded and verified (the model files and
|
|
4
4
|
the tool and engine archives, so the next install needs no download), the owned manifest that
|
|
5
|
-
lists them (so ``--purge`` can delete them later) and the
|
|
5
|
+
lists them (so ``--purge`` can delete them later) and the permanent empty lock files
|
|
6
|
+
(``tools/owned.lock``, WHI-317, and ``engines/.engine.lock``, WHI-759). stack_lifecycle.remove stops and removes the
|
|
6
7
|
services, the gateway and the tools; ``sweep`` then deletes what only the stack used: the
|
|
7
8
|
engines its deployments ran that no remaining record names (with their download archives), the
|
|
8
9
|
saved stack plans with their run records, the cached host facts, and the tool's own directories
|
|
@@ -204,7 +205,7 @@ def tidy(base_dirs: Iterable[Path], tools_dir: str | Path = hosts.TOOLS_DIR) ->
|
|
|
204
205
|
then the tool's own directories (OWN_DIRS) left empty and each base directory left empty.
|
|
205
206
|
A directory someone else made there stays, empty or not. The manifest's empty
|
|
206
207
|
``owned.lock`` stays: unlinking a lock file lets two writers each hold a "lock" (WHI-317,
|
|
207
|
-
.agents/skills/owned-manifest-lock),
|
|
208
|
+
.agents/skills/owned-manifest-lock), and ``engines/.engine.lock`` stays for the same reason (WHI-759, ``remote_ops_mirrors.engine_lock``)."""
|
|
208
209
|
root = Path(hosts.tools_dir(tools_dir)).expanduser()
|
|
209
210
|
private = root.resolve() / "gateway-home"
|
|
210
211
|
if not hosts.owned_path(tools_dir).exists() and private.is_dir():
|
|
@@ -7,12 +7,13 @@ import re
|
|
|
7
7
|
import shlex
|
|
8
8
|
import shutil
|
|
9
9
|
import sys
|
|
10
|
+
import tempfile
|
|
10
11
|
from collections.abc import Callable
|
|
11
12
|
from pathlib import Path
|
|
12
13
|
from typing import Any
|
|
13
14
|
|
|
14
|
-
from localmodels import
|
|
15
|
-
from localmodels.
|
|
15
|
+
from localmodels import harness_cleanup, harness_core, hosts, pi_profile, runtime_cli
|
|
16
|
+
from localmodels.harness_core import ClientState
|
|
16
17
|
|
|
17
18
|
CLIENTS = ("codex", "claude")
|
|
18
19
|
WRAPPER = "# localmodels: native client wrapper"
|
|
@@ -29,9 +30,9 @@ def config_files(client: str, env: dict[str, str] | None = None) -> dict[str, st
|
|
|
29
30
|
"""Fingerprint native settings, never their contents or credential values."""
|
|
30
31
|
environment = dict(os.environ if env is None else env)
|
|
31
32
|
home = Path(environment.get("HOME", os.path.expanduser("~")))
|
|
32
|
-
directory = Path(environment.get(
|
|
33
|
+
directory = Path(environment.get(pi_profile.PROFILE_KEYS[client], str(home / f".{client}")))
|
|
33
34
|
if not directory.is_absolute() or directory.is_symlink():
|
|
34
|
-
raise
|
|
35
|
+
raise harness_core.HarnessError(f"{client} config directory is not safe")
|
|
35
36
|
names = ("config.toml", "auth.json") if client == "codex" else ("settings.json",)
|
|
36
37
|
found: dict[str, str | None] = {}
|
|
37
38
|
for name in names:
|
|
@@ -42,8 +43,10 @@ def config_files(client: str, env: dict[str, str] | None = None) -> dict[str, st
|
|
|
42
43
|
not path.is_file() or (hasattr(os, "getuid") and path.stat().st_uid != os.getuid())
|
|
43
44
|
)
|
|
44
45
|
):
|
|
45
|
-
raise
|
|
46
|
-
|
|
46
|
+
raise harness_core.HarnessError(
|
|
47
|
+
f"{client} config is not a regular file of the current user"
|
|
48
|
+
)
|
|
49
|
+
found[str(path)] = harness_cleanup.digest(str(path))
|
|
47
50
|
return found
|
|
48
51
|
|
|
49
52
|
|
|
@@ -59,14 +62,16 @@ def observe(search: str, env: dict[str, str], magpie: str | None) -> dict[str, C
|
|
|
59
62
|
for client in CLIENTS:
|
|
60
63
|
executable = shutil.which(client, path=search)
|
|
61
64
|
output = (
|
|
62
|
-
|
|
65
|
+
harness_core.run_tool([executable, "--version"], timeout=10, env=env)
|
|
66
|
+
if executable
|
|
67
|
+
else None
|
|
63
68
|
)
|
|
64
69
|
version = re.search(r"\d+\.\d+\.\d+(?:[\w.+-]*)", output.stdout) if output else None
|
|
65
70
|
model = None
|
|
66
71
|
if magpie:
|
|
67
|
-
out =
|
|
72
|
+
out = harness_core.run_tool([magpie, client], timeout=20, env=env)
|
|
68
73
|
if out.returncode:
|
|
69
|
-
raise
|
|
74
|
+
raise harness_core.HarnessError(f"cannot check Magpie's {client} default model")
|
|
70
75
|
model = shown_model(client, out.stdout)
|
|
71
76
|
found[client] = {
|
|
72
77
|
"path": executable if output and output.returncode == 0 and version else None,
|
|
@@ -77,7 +82,7 @@ def observe(search: str, env: dict[str, str], magpie: str | None) -> dict[str, C
|
|
|
77
82
|
return found
|
|
78
83
|
|
|
79
84
|
|
|
80
|
-
def planned_clients(state:
|
|
85
|
+
def planned_clients(state: harness_core.ToolState) -> dict[str, ClientState]:
|
|
81
86
|
clients = state.get("clients", {})
|
|
82
87
|
return {
|
|
83
88
|
client: (
|
|
@@ -90,15 +95,15 @@ def planned_clients(state: harness.ToolState) -> dict[str, ClientState]:
|
|
|
90
95
|
|
|
91
96
|
|
|
92
97
|
def plan_tools(
|
|
93
|
-
state:
|
|
94
|
-
) -> tuple[list[
|
|
95
|
-
actions: list[
|
|
98
|
+
state: harness_core.ToolState, platform: str, arch: str, tools_dir: str
|
|
99
|
+
) -> tuple[list[harness_core.ToolAction], dict[str, dict[str, Any]]]:
|
|
100
|
+
actions: list[harness_core.ToolAction] = []
|
|
96
101
|
native: dict[str, dict[str, Any]] = {}
|
|
97
102
|
native_arch = {"x86_64": "x64", "aarch64": "arm64"}.get(arch, arch)
|
|
98
103
|
root = Path(hosts.tools_dir(tools_dir)).expanduser().absolute() / "clients"
|
|
99
104
|
owned = {tool["path"]: tool for tool in hosts.load_owned(tools_dir)["tools"]}
|
|
100
105
|
for client, seen in planned_clients(state).items():
|
|
101
|
-
wrapper = Path(
|
|
106
|
+
wrapper = Path(harness_core.BIN_DIR).expanduser() / client
|
|
102
107
|
plan = runtime_cli.native_plan(
|
|
103
108
|
client,
|
|
104
109
|
root,
|
|
@@ -109,8 +114,10 @@ def plan_tools(
|
|
|
109
114
|
reuse = plan["action"] == "reuse"
|
|
110
115
|
if not reuse and os.path.lexists(wrapper):
|
|
111
116
|
previous = owned.get(str(wrapper))
|
|
112
|
-
if previous is None or previous["sha256"] !=
|
|
113
|
-
raise
|
|
117
|
+
if previous is None or previous["sha256"] != harness_cleanup.digest(str(wrapper)):
|
|
118
|
+
raise harness_core.HarnessError(
|
|
119
|
+
f"{wrapper} exists and does not run; not overwritten"
|
|
120
|
+
)
|
|
114
121
|
native[client] = plan
|
|
115
122
|
actions.append(
|
|
116
123
|
{
|
|
@@ -124,16 +131,16 @@ def plan_tools(
|
|
|
124
131
|
return actions, native
|
|
125
132
|
|
|
126
133
|
|
|
127
|
-
def install_tools(plan:
|
|
134
|
+
def install_tools(plan: harness_core.ToolPlan, log: Callable[[str], None]) -> list[str]:
|
|
128
135
|
made: list[str] = []
|
|
129
136
|
|
|
130
137
|
def own(path: Path) -> None:
|
|
131
|
-
item: hosts.OwnedTool = {"path": str(path), "sha256":
|
|
138
|
+
item: hosts.OwnedTool = {"path": str(path), "sha256": harness_cleanup.digest(str(path))}
|
|
132
139
|
|
|
133
140
|
def add(doc: hosts.Owned) -> None:
|
|
134
141
|
previous = next((tool for tool in doc["tools"] if tool["path"] == str(path)), None)
|
|
135
142
|
if previous and previous != item:
|
|
136
|
-
raise
|
|
143
|
+
raise harness_core.HarnessError(
|
|
137
144
|
f"{path} install content changed; file and original ownership record kept"
|
|
138
145
|
)
|
|
139
146
|
doc["tools"] = [t for t in doc["tools"] if t["path"] != str(path)] + [item]
|
|
@@ -158,8 +165,8 @@ def install_tools(plan: harness.ToolPlan, log: Callable[[str], None]) -> list[st
|
|
|
158
165
|
),
|
|
159
166
|
None,
|
|
160
167
|
)
|
|
161
|
-
if not receipt or receipt["sha256"] !=
|
|
162
|
-
raise
|
|
168
|
+
if not receipt or receipt["sha256"] != harness_cleanup.digest(str(wrapper)):
|
|
169
|
+
raise harness_core.HarnessError(
|
|
163
170
|
f"{wrapper} exists and is not the original install; not overwritten"
|
|
164
171
|
)
|
|
165
172
|
wrapper.parent.mkdir(parents=True, exist_ok=True)
|
|
@@ -171,3 +178,112 @@ def install_tools(plan: harness.ToolPlan, log: Callable[[str], None]) -> list[st
|
|
|
171
178
|
own(wrapper)
|
|
172
179
|
log(f"{client} {actions[client]['version']} {native['action']} done")
|
|
173
180
|
return made
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def accept_clients(
|
|
184
|
+
executables: dict[str, str],
|
|
185
|
+
prompt: str,
|
|
186
|
+
expected: str,
|
|
187
|
+
timeout: float,
|
|
188
|
+
calls: Callable[[], int | None],
|
|
189
|
+
after: Callable[[int | None], int | None],
|
|
190
|
+
via: str = "Magpie",
|
|
191
|
+
*,
|
|
192
|
+
environment: dict[str, str],
|
|
193
|
+
) -> list[dict[str, object]]:
|
|
194
|
+
"""One real non-interactive prompt per client on its configured default; each passes only
|
|
195
|
+
with the expected answer and a new successful call in the gateway's log (``calls``)."""
|
|
196
|
+
results: list[dict[str, object]] = []
|
|
197
|
+
commands = {
|
|
198
|
+
"codex": [
|
|
199
|
+
"exec",
|
|
200
|
+
"--skip-git-repo-check",
|
|
201
|
+
"--ephemeral",
|
|
202
|
+
"--sandbox",
|
|
203
|
+
"read-only",
|
|
204
|
+
"-c",
|
|
205
|
+
'approval_policy="never"',
|
|
206
|
+
"-c",
|
|
207
|
+
"features.shell_tool=false",
|
|
208
|
+
],
|
|
209
|
+
"claude": [
|
|
210
|
+
"-p",
|
|
211
|
+
"--tools",
|
|
212
|
+
"",
|
|
213
|
+
"--strict-mcp-config",
|
|
214
|
+
"--mcp-config",
|
|
215
|
+
'{"mcpServers":{}}',
|
|
216
|
+
"--no-session-persistence",
|
|
217
|
+
"--max-turns",
|
|
218
|
+
"1",
|
|
219
|
+
"--disable-slash-commands",
|
|
220
|
+
"--setting-sources",
|
|
221
|
+
"user",
|
|
222
|
+
"--settings",
|
|
223
|
+
'{"disableAllHooks":true}',
|
|
224
|
+
],
|
|
225
|
+
}
|
|
226
|
+
env = environment.copy()
|
|
227
|
+
env["CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC"] = "1"
|
|
228
|
+
for name in ("NO_PROXY", "no_proxy"):
|
|
229
|
+
env[name] = ",".join(filter(None, (env.get(name), "127.0.0.1,localhost")))
|
|
230
|
+
for client, executable in executables.items():
|
|
231
|
+
before = calls()
|
|
232
|
+
with tempfile.TemporaryDirectory(prefix=f"localmodels-{client}-") as cwd:
|
|
233
|
+
result = harness_core.run_tool(
|
|
234
|
+
[executable, *commands[client], prompt],
|
|
235
|
+
cwd=cwd,
|
|
236
|
+
env=env,
|
|
237
|
+
timeout=timeout,
|
|
238
|
+
)
|
|
239
|
+
count = after(before)
|
|
240
|
+
ok = (
|
|
241
|
+
result.returncode == 0
|
|
242
|
+
and expected.lower() in result.stdout.lower()
|
|
243
|
+
and before is not None
|
|
244
|
+
and count is not None
|
|
245
|
+
and count > before
|
|
246
|
+
)
|
|
247
|
+
results.append(
|
|
248
|
+
{
|
|
249
|
+
"check": f"{client} via {via}",
|
|
250
|
+
"ok": ok,
|
|
251
|
+
"detail": f"exit={result.returncode}; {via} provider calls {before} → {count}",
|
|
252
|
+
}
|
|
253
|
+
)
|
|
254
|
+
return results
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def restore_failed_check(client: str) -> dict[str, object]:
|
|
258
|
+
return {
|
|
259
|
+
"check": client,
|
|
260
|
+
"ok": False,
|
|
261
|
+
"detail": "client config cannot be restored safely; services and ownership records kept",
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def accept_plan_clients(
|
|
266
|
+
plan: harness_core.HarnessPlan,
|
|
267
|
+
prompt: str,
|
|
268
|
+
expected: str,
|
|
269
|
+
timeout: float,
|
|
270
|
+
calls: Callable[[], int | None],
|
|
271
|
+
after: Callable[[int | None], int | None],
|
|
272
|
+
*,
|
|
273
|
+
via: str,
|
|
274
|
+
environment: dict[str, str],
|
|
275
|
+
) -> list[dict[str, object]]:
|
|
276
|
+
executables = {
|
|
277
|
+
client: harness_core.tool_path(plan, client)
|
|
278
|
+
for client in plan["gateway"].get("clients", {})
|
|
279
|
+
}
|
|
280
|
+
return accept_clients(
|
|
281
|
+
executables,
|
|
282
|
+
prompt,
|
|
283
|
+
expected,
|
|
284
|
+
timeout,
|
|
285
|
+
calls,
|
|
286
|
+
after,
|
|
287
|
+
via=via,
|
|
288
|
+
environment=environment,
|
|
289
|
+
)
|
|
@@ -453,6 +453,10 @@ def _llama_parts(
|
|
|
453
453
|
model and the prompt cache's growth are fitted to the RAM those leave (2026-11-01 user
|
|
454
454
|
decision: ticked foundations win over the cache beyond its floor and over a larger LLM)."""
|
|
455
455
|
posture = agent_posture(options)
|
|
456
|
+
if min_prompt_cache:
|
|
457
|
+
# WHI-898: capacity plans for blocked-now hosts price minimum required RAM, not
|
|
458
|
+
# optional accelerators that greedily expand into synthetic idle memory.
|
|
459
|
+
posture = replace(posture, draft="off")
|
|
456
460
|
aux_notes: list[str] = []
|
|
457
461
|
candidates = stack_suite.aux_plans(
|
|
458
462
|
facts, options, listening, previous, aux_notes, approved=approved
|
|
@@ -494,7 +498,11 @@ def _llama_parts(
|
|
|
494
498
|
base_dir=options["base_dir"],
|
|
495
499
|
hf_download_endpoint=options["hf_endpoint"],
|
|
496
500
|
hf_api_endpoint=options["hf_endpoint"],
|
|
497
|
-
agent=
|
|
501
|
+
agent=(
|
|
502
|
+
posture
|
|
503
|
+
if mtp
|
|
504
|
+
else replace(posture, mtp_draft_depth=0, ubatch_pinned=True, draft="off")
|
|
505
|
+
),
|
|
498
506
|
quant=str(options.get("quant") or ""),
|
|
499
507
|
),
|
|
500
508
|
entries=entries,
|
|
@@ -27,6 +27,7 @@ from localmodels import (
|
|
|
27
27
|
deploy,
|
|
28
28
|
gateway_probe,
|
|
29
29
|
harness,
|
|
30
|
+
harness_core,
|
|
30
31
|
hosts,
|
|
31
32
|
stack_run,
|
|
32
33
|
stack_verify,
|
|
@@ -117,7 +118,7 @@ def _cause(part: Plan) -> str | None:
|
|
|
117
118
|
"""Why a stopped service stopped: systemd's own result first, then its log's last 16 KiB."""
|
|
118
119
|
svc = part["service"]
|
|
119
120
|
if svc["kind"] == "systemd-user":
|
|
120
|
-
out =
|
|
121
|
+
out = harness_core.run_tool(
|
|
121
122
|
["systemctl", "--user", "show", "-p", "Result", "--value", f"{svc['name']}.service"],
|
|
122
123
|
timeout=10,
|
|
123
124
|
)
|
|
@@ -203,7 +204,7 @@ def _gpu(pids: set[int]) -> Finding | None:
|
|
|
203
204
|
if not pids or not nvsmi:
|
|
204
205
|
return None
|
|
205
206
|
query = "--query-compute-apps=pid,gpu_uuid,used_memory"
|
|
206
|
-
out =
|
|
207
|
+
out = harness_core.run_tool([nvsmi, query, "--format=csv,noheader,nounits"], timeout=20)
|
|
207
208
|
if out.returncode != 0:
|
|
208
209
|
return finding(
|
|
209
210
|
"host.gpu", "warn", "nvidia-smi query failed; GPU usage not checked", "nvidia-smi"
|
|
@@ -368,7 +369,9 @@ def _owned_only(name: str, entry: hosts.OwnedDeployment) -> Finding:
|
|
|
368
369
|
if entry["kind"] != "systemd-user" or not sys.platform.startswith("linux"):
|
|
369
370
|
return finding(check, "warn", f"{name}: {where}; cannot check", "")
|
|
370
371
|
unit = f"{entry['service']}.service"
|
|
371
|
-
state =
|
|
372
|
+
state = harness_core.run_tool(
|
|
373
|
+
["systemctl", "--user", "is-active", unit], timeout=10
|
|
374
|
+
).stdout.strip()
|
|
372
375
|
if state == "active":
|
|
373
376
|
return finding(
|
|
374
377
|
check,
|
|
@@ -343,6 +343,24 @@ def llm_fits(
|
|
|
343
343
|
found.append(((fit["quality"], tie), fit))
|
|
344
344
|
found = [row for row in found if not row[1].get("candidate_fallback")] or found
|
|
345
345
|
default_id = llm_rank.listed_default(facts, [(f["id"], f["quality"]) for _, f in found])
|
|
346
|
+
if default_id is None and found:
|
|
347
|
+
strata_ids = set(strata_vram)
|
|
348
|
+
fallback_ids = {f["id"] for _, f in found if f.get("candidate_fallback")}
|
|
349
|
+
slow_ids = {
|
|
350
|
+
f["id"]
|
|
351
|
+
for _, f in found
|
|
352
|
+
if f["id"] not in strata_ids
|
|
353
|
+
and f["decode_tok_s"] is not None
|
|
354
|
+
and f["decode_tok_s"] < cat.USABLE_FLOOR_TOK_S
|
|
355
|
+
}
|
|
356
|
+
prefer = str(options.get("prefer") or "smartest")
|
|
357
|
+
default_id = llm_rank.choose(
|
|
358
|
+
[(key, fit["id"], index) for key, fit in found],
|
|
359
|
+
prefer,
|
|
360
|
+
llm_rank.mac_ladder(facts),
|
|
361
|
+
fallback_ids=fallback_ids,
|
|
362
|
+
slow_ids=slow_ids,
|
|
363
|
+
)[0]
|
|
346
364
|
return [
|
|
347
365
|
fit
|
|
348
366
|
for _, fit in sorted(found, key=lambda t: (t[1]["id"] == default_id, t[0]), reverse=True)
|
|
@@ -23,6 +23,7 @@ from localmodels import (
|
|
|
23
23
|
cli_help,
|
|
24
24
|
http_local,
|
|
25
25
|
stack_lifecycle,
|
|
26
|
+
stack_run,
|
|
26
27
|
stack_up,
|
|
27
28
|
stack_verify,
|
|
28
29
|
stack_view_gpu,
|
|
@@ -431,7 +432,7 @@ def add_parser(actions: argparse._SubParsersAction[argparse.ArgumentParser]) ->
|
|
|
431
432
|
def cli(args: argparse.Namespace) -> int:
|
|
432
433
|
if not 0.1 <= args.seconds <= 60 or not 0.1 <= args.interval <= 60:
|
|
433
434
|
raise StackError("--seconds and --interval must be between 0.1 and 60")
|
|
434
|
-
plan =
|
|
435
|
+
plan = stack_run.accepted()
|
|
435
436
|
if plan is None or stack_up.drift(plan):
|
|
436
437
|
raise StackError("no unchanged accepted local stack; run stack install or stack up")
|
|
437
438
|
report = sample(plan, args.seconds, args.interval)
|
|
@@ -20,6 +20,7 @@ from localmodels import (
|
|
|
20
20
|
gateway_probe,
|
|
21
21
|
gateway_speed,
|
|
22
22
|
harness,
|
|
23
|
+
harness_core,
|
|
23
24
|
hosts,
|
|
24
25
|
http_local,
|
|
25
26
|
process_identity,
|
|
@@ -65,7 +66,7 @@ class Row(TypedDict):
|
|
|
65
66
|
|
|
66
67
|
|
|
67
68
|
def _run(argv: list[str]) -> str:
|
|
68
|
-
out =
|
|
69
|
+
out = harness_core.run_tool(argv, timeout=10)
|
|
69
70
|
return out.stdout.strip() if out.returncode == 0 else ""
|
|
70
71
|
|
|
71
72
|
|
|
@@ -98,7 +99,7 @@ def _service(plan: Plan) -> tuple[str, int | None]:
|
|
|
98
99
|
if _systemd_unit_elsewhere(plan):
|
|
99
100
|
return "inactive", None
|
|
100
101
|
unit = f"{svc['name']}.service"
|
|
101
|
-
state =
|
|
102
|
+
state = harness_core.run_tool(["systemctl", "--user", "is-active", unit], timeout=10)
|
|
102
103
|
pid = _run(["systemctl", "--user", "show", "-p", "MainPID", "--value", unit])
|
|
103
104
|
return state.stdout.strip() or "unknown", int(pid) if pid.isdigit() and pid != "0" else None
|
|
104
105
|
try:
|
|
@@ -31,8 +31,8 @@ from localmodels import (
|
|
|
31
31
|
)
|
|
32
32
|
from localmodels.context_policy import AGENT
|
|
33
33
|
from localmodels.contracts import decode
|
|
34
|
-
from localmodels.memcalc import KV_TYPES, MemcalcError, parse_tokens
|
|
35
34
|
from localmodels.plan_envelope import PlanError
|
|
35
|
+
from localmodels.planning.memcalc import KV_TYPES, MemcalcError, parse_tokens
|
|
36
36
|
from localmodels.probe import HostFacts
|
|
37
37
|
from localmodels.stack_compose import agent_posture, choose_parts, ram_budget
|
|
38
38
|
from localmodels.stack_plan import PREFERENCES, StackError, default_options
|