@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
|
@@ -13,10 +13,14 @@ from collections.abc import Callable
|
|
|
13
13
|
from pathlib import Path
|
|
14
14
|
|
|
15
15
|
from localmodels import (
|
|
16
|
-
|
|
16
|
+
approval,
|
|
17
|
+
bifrost_config,
|
|
18
|
+
contracts,
|
|
19
|
+
harness_core,
|
|
17
20
|
harness_probe,
|
|
18
21
|
hosts,
|
|
19
22
|
magpie_windows,
|
|
23
|
+
pi_profile,
|
|
20
24
|
process_identity,
|
|
21
25
|
remote_ops_service,
|
|
22
26
|
runtime_io,
|
|
@@ -34,13 +38,13 @@ SERVE_STOPPED = {
|
|
|
34
38
|
def address_port(addr: str) -> int:
|
|
35
39
|
host, separator, value = addr.rpartition(":")
|
|
36
40
|
if not separator or host not in ("127.0.0.1", "localhost", "[::1]"):
|
|
37
|
-
raise
|
|
41
|
+
raise harness_core.HarnessError("cannot confirm who owns a non-loopback Magpie gateway")
|
|
38
42
|
try:
|
|
39
43
|
port = int(value)
|
|
40
44
|
except ValueError as exc:
|
|
41
|
-
raise
|
|
45
|
+
raise harness_core.HarnessError("invalid Magpie gateway port") from exc
|
|
42
46
|
if not 1 <= port <= 65535:
|
|
43
|
-
raise
|
|
47
|
+
raise harness_core.HarnessError("invalid Magpie gateway port")
|
|
44
48
|
return port
|
|
45
49
|
|
|
46
50
|
|
|
@@ -60,11 +64,11 @@ def owned_address(addr: str, tools_dir: str, magpie: str | None) -> bool:
|
|
|
60
64
|
try:
|
|
61
65
|
if address_port(owned_magpie["addr"]) != port:
|
|
62
66
|
return False
|
|
63
|
-
except
|
|
67
|
+
except harness_core.HarnessError:
|
|
64
68
|
return False
|
|
65
69
|
state, pid = process_identity.status(receipt)
|
|
66
70
|
if state != "active" and magpie_windows.adopt_magpie_successor(
|
|
67
|
-
receipt, magpie, port=port, gateway_home=
|
|
71
|
+
receipt, magpie, port=port, gateway_home=pi_profile.gateway_home(tools_dir)
|
|
68
72
|
):
|
|
69
73
|
state, pid = process_identity.status(receipt) # restarted into an updated binary
|
|
70
74
|
if state != "active" or pid is None:
|
|
@@ -92,7 +96,7 @@ def address_listening(
|
|
|
92
96
|
return True
|
|
93
97
|
if result == errno.ECONNREFUSED:
|
|
94
98
|
return False
|
|
95
|
-
raise
|
|
99
|
+
raise harness_core.HarnessError("cannot confirm whether the IPv6 loopback gateway port is free")
|
|
96
100
|
|
|
97
101
|
|
|
98
102
|
def select_address(
|
|
@@ -108,30 +112,30 @@ def select_address(
|
|
|
108
112
|
try:
|
|
109
113
|
busy = address_listening(addr, listening)
|
|
110
114
|
except (OSError, RuntimeError) as exc:
|
|
111
|
-
raise
|
|
115
|
+
raise harness_core.HarnessError(
|
|
112
116
|
"cannot confirm whether the Magpie gateway port is free"
|
|
113
117
|
) from exc
|
|
114
118
|
if not busy or owned(addr):
|
|
115
119
|
return addr
|
|
116
120
|
if requested:
|
|
117
|
-
raise
|
|
121
|
+
raise harness_core.HarnessError(
|
|
118
122
|
f"Magpie gateway address {addr} is held by a program without proof of ownership;"
|
|
119
123
|
" that program is kept",
|
|
120
124
|
code="gateway-port-in-use",
|
|
121
125
|
)
|
|
122
|
-
raise
|
|
126
|
+
raise harness_core.HarnessError(
|
|
123
127
|
"Magpie default ports 3425..3456 are all in use", code="gateway-port-in-use"
|
|
124
128
|
)
|
|
125
129
|
|
|
126
130
|
|
|
127
|
-
def require_target(plan:
|
|
131
|
+
def require_target(plan: harness_core.ToolPlan) -> None:
|
|
128
132
|
"""Never query a listener merely because it uses our UID or answers like Magpie."""
|
|
129
|
-
|
|
133
|
+
harness_core.gateway_environment(plan)
|
|
130
134
|
action = next((t for t in plan["tools"] if t["tool"] == "gateway"), None)
|
|
131
135
|
if action is None:
|
|
132
136
|
if "environment" in plan and "gateway" not in plan:
|
|
133
137
|
return # The instance-owned gateway API supplies its already verified context.
|
|
134
|
-
raise
|
|
138
|
+
raise harness_core.HarnessError("no approved Magpie gateway address")
|
|
135
139
|
select_address(
|
|
136
140
|
action["path"],
|
|
137
141
|
plan["tools_dir"],
|
|
@@ -139,34 +143,40 @@ def require_target(plan: harness.ToolPlan) -> None:
|
|
|
139
143
|
)
|
|
140
144
|
|
|
141
145
|
|
|
146
|
+
def checked_gateway_environment(plan: harness_core.ToolPlan) -> dict[str, str]:
|
|
147
|
+
"""Prove the target before any command can send data to it."""
|
|
148
|
+
require_target(plan)
|
|
149
|
+
return harness_core.gateway_environment(plan)
|
|
150
|
+
|
|
151
|
+
|
|
142
152
|
def plan_gateway(
|
|
143
|
-
state:
|
|
153
|
+
state: harness_core.ToolState,
|
|
144
154
|
platform: str,
|
|
145
155
|
arch: str,
|
|
146
156
|
systemd_user: bool,
|
|
147
|
-
tools_dir: str =
|
|
148
|
-
lock:
|
|
149
|
-
) -> tuple[
|
|
157
|
+
tools_dir: str = harness_core.DEFAULT_TOOLS_DIR,
|
|
158
|
+
lock: harness_core.ToolLock | None = None,
|
|
159
|
+
) -> tuple[harness_core.ToolPlan, list[str]]:
|
|
150
160
|
"""The existing pinned Magpie installation without Agent clients or LLM routing."""
|
|
151
161
|
tools_dir = hosts.tools_dir(tools_dir)
|
|
152
|
-
lock = lock or
|
|
153
|
-
bin_dir =
|
|
154
|
-
actions: list[
|
|
162
|
+
lock = lock or harness_core.load_lock()
|
|
163
|
+
bin_dir = harness_core.BIN_DIR
|
|
164
|
+
actions: list[harness_core.ToolAction] = []
|
|
155
165
|
warnings: list[str] = []
|
|
156
166
|
if state["magpie"]:
|
|
157
|
-
actions.append(
|
|
167
|
+
actions.append(harness_core.reuse_tool("magpie", state["magpie"], state["magpie_version"]))
|
|
158
168
|
else:
|
|
159
|
-
build =
|
|
169
|
+
build = harness_core.tool_build(lock["magpie"]["builds"], platform, arch, "Magpie")
|
|
160
170
|
magpie = f"{bin_dir}/magpie" + (".exe" if platform == "win32" else "")
|
|
161
171
|
if state["inspection"] == "complete" and os.path.lexists(os.path.expanduser(magpie)):
|
|
162
|
-
raise
|
|
172
|
+
raise harness_core.HarnessError(f"{magpie} exists but does not run; deal with it first")
|
|
163
173
|
actions.append(
|
|
164
174
|
{
|
|
165
175
|
"tool": "magpie",
|
|
166
176
|
"action": "install",
|
|
167
177
|
"path": magpie,
|
|
168
178
|
"version": lock["magpie"]["version"],
|
|
169
|
-
"artifacts": [
|
|
179
|
+
"artifacts": [harness_core.tool_artifact(build)],
|
|
170
180
|
}
|
|
171
181
|
)
|
|
172
182
|
warnings.append(
|
|
@@ -175,7 +185,7 @@ def plan_gateway(
|
|
|
175
185
|
)
|
|
176
186
|
if state.get("gateway_other_user"):
|
|
177
187
|
# Wiring into it would send this user's requests through another user's gateway.
|
|
178
|
-
raise
|
|
188
|
+
raise harness_core.HarnessError(
|
|
179
189
|
f"Magpie gateway address {state['gateway_addr']} is held by another user's program;"
|
|
180
190
|
" wiring into it would send your requests through someone else's gateway. Ask them to"
|
|
181
191
|
" free the port, or set MAGPIE_ADDR=127.0.0.1:<free port> in the same terminal, then"
|
|
@@ -214,53 +224,47 @@ def plan_gateway(
|
|
|
214
224
|
}, warnings
|
|
215
225
|
|
|
216
226
|
|
|
217
|
-
def _standalone_target(tools_dir: str) ->
|
|
218
|
-
|
|
219
|
-
from localmodels.contracts import decode
|
|
220
|
-
|
|
221
|
-
found: dict[tuple[str, str, str], harness.ToolPlan] = {}
|
|
227
|
+
def _standalone_target(tools_dir: str) -> harness_core.ToolPlan | None:
|
|
228
|
+
found: dict[tuple[str, str, str], harness_core.ToolPlan] = {}
|
|
222
229
|
for path in (hosts.state_dir() / "magpie").glob("*.json"):
|
|
223
230
|
try:
|
|
224
231
|
saved = json.loads(path.read_text(encoding="utf-8"))
|
|
225
|
-
tools = decode(saved["tools"],
|
|
226
|
-
if digest(saved) != saved["plan_id"] or _tools_path(
|
|
227
|
-
tools_dir
|
|
228
|
-
):
|
|
232
|
+
tools = contracts.decode(saved["tools"], harness_core.ToolPlan)
|
|
233
|
+
if approval.digest(saved) != saved["plan_id"] or _tools_path(
|
|
234
|
+
tools["tools_dir"]
|
|
235
|
+
) != _tools_path(tools_dir):
|
|
229
236
|
continue
|
|
230
237
|
addr = next(t["path"] for t in tools["tools"] if t["tool"] == "gateway")
|
|
231
|
-
binary =
|
|
238
|
+
binary = harness_core.tool_path(tools, "magpie")
|
|
232
239
|
if owned_address(addr, tools_dir, binary):
|
|
233
|
-
home =
|
|
240
|
+
home = harness_core.gateway_environment(tools).get("HOME", "")
|
|
234
241
|
found[(addr, os.path.realpath(binary), home)] = tools
|
|
235
242
|
except (OSError, ValueError, RuntimeError, StopIteration, KeyError, TypeError):
|
|
236
243
|
continue
|
|
237
244
|
return next(iter(found.values())) if len(found) == 1 else None
|
|
238
245
|
|
|
239
246
|
|
|
240
|
-
def _recorded_target(view: object, plan: object, tools_dir: str) ->
|
|
247
|
+
def _recorded_target(view: object, plan: object, tools_dir: str) -> harness_core.ToolPlan | None:
|
|
241
248
|
"""The harness of one stack run record, only when the record and its saved plan still carry
|
|
242
249
|
the approval digest and name this tools directory."""
|
|
243
|
-
from localmodels.approval import digest
|
|
244
|
-
from localmodels.contracts import decode
|
|
245
|
-
|
|
246
250
|
if (
|
|
247
251
|
isinstance(view, dict)
|
|
248
252
|
and view.get("schema") == "localmodels.stack-run/v1"
|
|
249
253
|
and isinstance(plan, dict)
|
|
250
254
|
and plan.get("schema") == "localmodels.stack-plan/v1"
|
|
251
|
-
and digest(plan) == plan.get("plan_id") == view.get("plan_id")
|
|
255
|
+
and approval.digest(plan) == plan.get("plan_id") == view.get("plan_id")
|
|
252
256
|
and isinstance(plan.get("harness"), dict)
|
|
253
257
|
and isinstance(plan["harness"].get("tools_dir"), str)
|
|
254
258
|
and _tools_path(plan["harness"]["tools_dir"]) == _tools_path(tools_dir)
|
|
255
259
|
):
|
|
256
260
|
try:
|
|
257
|
-
return decode(plan["harness"],
|
|
261
|
+
return contracts.decode(plan["harness"], harness_core.HarnessPlan)
|
|
258
262
|
except ValueError:
|
|
259
263
|
return None
|
|
260
264
|
return None
|
|
261
265
|
|
|
262
266
|
|
|
263
|
-
def accepted_plan(tools_dir: str) ->
|
|
267
|
+
def accepted_plan(tools_dir: str) -> harness_core.ToolPlan | None:
|
|
264
268
|
"""Recover a recorded approved target; standalone previews also need live ownership."""
|
|
265
269
|
if any(hosts.stacks_dir().glob("*.run.json")):
|
|
266
270
|
runs = hosts.stack_runs()
|
|
@@ -268,12 +272,12 @@ def accepted_plan(tools_dir: str) -> harness.ToolPlan | None:
|
|
|
268
272
|
return _standalone_target(tools_dir)
|
|
269
273
|
|
|
270
274
|
|
|
271
|
-
def _magpie_tool(plan:
|
|
275
|
+
def _magpie_tool(plan: harness_core.ToolPlan) -> str | None:
|
|
272
276
|
path = next((t["path"] for t in plan["tools"] if t["tool"] == "magpie"), None)
|
|
273
277
|
return os.path.expanduser(path) if path else None
|
|
274
278
|
|
|
275
279
|
|
|
276
|
-
def magpie_target(tools_dir: str) ->
|
|
280
|
+
def magpie_target(tools_dir: str) -> harness_core.ToolPlan | None:
|
|
277
281
|
"""The newest approved plan that ran this tool's Magpie. ``stack apply`` records a plan
|
|
278
282
|
moving the stack to Bifrost before it undoes the Magpie wiring, so that wiring belongs to an
|
|
279
283
|
earlier run: approved Bifrost records are passed over, and any record that cannot be verified
|
|
@@ -286,14 +290,14 @@ def magpie_target(tools_dir: str) -> harness.ToolPlan | None:
|
|
|
286
290
|
return None
|
|
287
291
|
if _magpie_tool(target) is not None:
|
|
288
292
|
return target
|
|
289
|
-
if
|
|
293
|
+
if harness_core.gateway_kind(target.get("gateway")) != "bifrost": # type: ignore[arg-type]
|
|
290
294
|
return None
|
|
291
295
|
return None
|
|
292
296
|
|
|
293
297
|
|
|
294
298
|
def removal_target(
|
|
295
|
-
magpie: str | None, tools_dir: str, plan:
|
|
296
|
-
) ->
|
|
299
|
+
magpie: str | None, tools_dir: str, plan: harness_core.ToolPlan | None
|
|
300
|
+
) -> harness_core.ToolPlan | None:
|
|
297
301
|
target = plan or accepted_plan(tools_dir)
|
|
298
302
|
if (
|
|
299
303
|
target is None
|
|
@@ -305,12 +309,12 @@ def removal_target(
|
|
|
305
309
|
return None
|
|
306
310
|
try:
|
|
307
311
|
require_target(target)
|
|
308
|
-
except
|
|
312
|
+
except harness_core.HarnessError:
|
|
309
313
|
return None
|
|
310
314
|
return target
|
|
311
315
|
|
|
312
316
|
|
|
313
|
-
def owned_magpie_target(record: hosts.OwnedMagpie) ->
|
|
317
|
+
def owned_magpie_target(record: hosts.OwnedMagpie) -> harness_core.ToolPlan:
|
|
314
318
|
"""Reconstruct the approved ToolPlan for a private ``magpie serve`` recorded in owned.json."""
|
|
315
319
|
return {
|
|
316
320
|
"tools_dir": record["tools_dir"],
|
|
@@ -335,7 +339,7 @@ def owned_magpie_target(record: hosts.OwnedMagpie) -> harness.ToolPlan:
|
|
|
335
339
|
}
|
|
336
340
|
|
|
337
341
|
|
|
338
|
-
def _recorded_magpie_target(tools_dir: str) ->
|
|
342
|
+
def _recorded_magpie_target(tools_dir: str) -> harness_core.ToolPlan | None:
|
|
339
343
|
record = hosts.load_owned(tools_dir)["gateway"].get("magpie")
|
|
340
344
|
if record is None:
|
|
341
345
|
return None
|
|
@@ -349,7 +353,7 @@ def stop_gateway(
|
|
|
349
353
|
started: str,
|
|
350
354
|
tools_dir: str = hosts.TOOLS_DIR,
|
|
351
355
|
*,
|
|
352
|
-
plan:
|
|
356
|
+
plan: harness_core.ToolPlan | None = None,
|
|
353
357
|
forget: bool = True,
|
|
354
358
|
) -> Check:
|
|
355
359
|
"""Signal only a process whose private receipt still proves the approved gateway.
|
|
@@ -372,7 +376,7 @@ def stop_gateway(
|
|
|
372
376
|
):
|
|
373
377
|
return failure
|
|
374
378
|
gw_action = next((t for t in target["tools"] if t["tool"] == "gateway"), None)
|
|
375
|
-
gw_home =
|
|
379
|
+
gw_home = pi_profile.gateway_home(tools_dir)
|
|
376
380
|
pid_file = _tools_path(tools_dir) / SERVE_PID
|
|
377
381
|
try:
|
|
378
382
|
port = address_port(gw_action["path"]) if gw_action is not None else None
|
|
@@ -386,7 +390,7 @@ def stop_gateway(
|
|
|
386
390
|
if not remote_ops_service.command_matches(pid, [magpie, "serve"]):
|
|
387
391
|
return failure
|
|
388
392
|
elif state == "unknown":
|
|
389
|
-
saved = process_identity.
|
|
393
|
+
saved = process_identity.recorded(pid_file)
|
|
390
394
|
current = process_identity.inspect(saved["pid"]) if saved else None
|
|
391
395
|
if current is not None and saved is not None and current["started"] == saved["started"]:
|
|
392
396
|
return failure
|
|
@@ -406,38 +410,38 @@ def stop_gateway(
|
|
|
406
410
|
return {"check": "gateway", "ok": True, "detail": SERVE_STOPPED[outcome]}
|
|
407
411
|
|
|
408
412
|
|
|
409
|
-
def private_home(plan:
|
|
413
|
+
def private_home(plan: harness_core.ToolPlan) -> None:
|
|
410
414
|
"""Create the private client context before wiring clients, without repairing existing state."""
|
|
411
415
|
if "environment" in plan:
|
|
412
416
|
return
|
|
413
|
-
home =
|
|
417
|
+
home = pi_profile.gateway_home(plan["tools_dir"])
|
|
414
418
|
try:
|
|
415
419
|
runtime_io.private_directory(home)
|
|
416
420
|
except ValueError as exc:
|
|
417
421
|
if sys.platform == "win32":
|
|
418
|
-
raise
|
|
422
|
+
raise harness_core.HarnessError(
|
|
419
423
|
f"{home} is not a private directory for the current Windows user ({exc});"
|
|
420
424
|
" no config changed. Close Linger and stop the localmodels gateway if it is"
|
|
421
425
|
" running. If you confirm localmodels created this folder, rename it in File"
|
|
422
426
|
" Explorer to keep a backup (ask an administrator if denied), then retry"
|
|
423
427
|
" without elevation."
|
|
424
428
|
) from exc
|
|
425
|
-
raise
|
|
429
|
+
raise harness_core.HarnessError(
|
|
426
430
|
f"{home} is not a directory private to the current user ({exc}; should be 0700); no"
|
|
427
431
|
f" config changed. Once you confirm this tool created it, run chmod 700 {home} and retry"
|
|
428
432
|
) from exc
|
|
429
433
|
|
|
430
434
|
|
|
431
|
-
def gateway_profile(plan:
|
|
435
|
+
def gateway_profile(plan: harness_core.ToolPlan | None) -> Path | None:
|
|
432
436
|
if plan is None or "environment" in plan:
|
|
433
437
|
return None
|
|
434
|
-
profile =
|
|
435
|
-
environment =
|
|
438
|
+
profile = pi_profile.gateway_home(plan["tools_dir"])
|
|
439
|
+
environment = harness_core.gateway_environment(plan)
|
|
436
440
|
gateway = plan.get("gateway")
|
|
437
|
-
if isinstance(gateway, dict) and
|
|
441
|
+
if isinstance(gateway, dict) and harness_core.gateway_kind(gateway) == "bifrost":
|
|
438
442
|
if any(
|
|
439
443
|
environment.get(key) != value
|
|
440
|
-
for key, value in
|
|
444
|
+
for key, value in pi_profile.client_environment(plan["tools_dir"]).items()
|
|
441
445
|
):
|
|
442
446
|
return None
|
|
443
447
|
elif environment.get("HOME") != str(profile):
|
|
@@ -447,18 +451,16 @@ def gateway_profile(plan: harness.ToolPlan | None) -> Path | None:
|
|
|
447
451
|
return profile
|
|
448
452
|
|
|
449
453
|
|
|
450
|
-
def purge_gateway_profile(plan:
|
|
454
|
+
def purge_gateway_profile(plan: harness_core.ToolPlan | None, notes: list[str]) -> None:
|
|
451
455
|
profile = gateway_profile(plan)
|
|
452
456
|
if profile is None or not profile.exists() or plan is None:
|
|
453
457
|
return
|
|
454
458
|
gateway = plan.get("gateway")
|
|
455
|
-
if isinstance(gateway, dict) and
|
|
456
|
-
from localmodels import gateway_bifrost
|
|
457
|
-
|
|
459
|
+
if isinstance(gateway, dict) and harness_core.gateway_kind(gateway) == "bifrost":
|
|
458
460
|
record = hosts.load_owned(plan["tools_dir"])["gateway"].get("bifrost")
|
|
459
461
|
if (
|
|
460
462
|
record is not None
|
|
461
|
-
or process_identity.status(
|
|
463
|
+
or process_identity.status(bifrost_config.app_dir() / "bifrost.pid")[0] != "inactive"
|
|
462
464
|
):
|
|
463
465
|
notes.append(
|
|
464
466
|
"- private client config kept: Bifrost still registered, running"
|
|
@@ -473,7 +475,7 @@ def purge_gateway_profile(plan: harness.ToolPlan | None, notes: list[str]) -> No
|
|
|
473
475
|
if hasattr(os, "getuid") and any(
|
|
474
476
|
path.lstat().st_uid != os.getuid() for path in profile.rglob("*")
|
|
475
477
|
):
|
|
476
|
-
raise
|
|
478
|
+
raise harness_core.HarnessError(
|
|
477
479
|
"the private gateway directory holds another user's files; not cleaned"
|
|
478
480
|
)
|
|
479
481
|
shutil.rmtree(profile)
|
|
@@ -481,7 +483,7 @@ def purge_gateway_profile(plan: harness.ToolPlan | None, notes: list[str]) -> No
|
|
|
481
483
|
|
|
482
484
|
def require_inactive(tools_dir: Path) -> None:
|
|
483
485
|
if process_identity.status(tools_dir / SERVE_PID)[0] != "inactive":
|
|
484
|
-
raise
|
|
486
|
+
raise harness_core.HarnessError(
|
|
485
487
|
"private gateway process still running or of unknown owner; no second process started"
|
|
486
488
|
)
|
|
487
489
|
|
|
@@ -494,12 +496,12 @@ def record_started_child(proc: subprocess.Popen[bytes], tools_dir: Path) -> None
|
|
|
494
496
|
process_identity.kill_started(proc.pid)
|
|
495
497
|
proc.wait(timeout=10)
|
|
496
498
|
if isinstance(exc, Exception):
|
|
497
|
-
raise
|
|
499
|
+
raise harness_core.HarnessError(
|
|
498
500
|
f"gateway start receipt failed ({type(exc).__name__}); the new process was stopped"
|
|
499
501
|
) from exc
|
|
500
502
|
raise
|
|
501
503
|
|
|
502
504
|
|
|
503
|
-
def pending_owned(plan:
|
|
505
|
+
def pending_owned(plan: harness_core.ToolPlan) -> bool:
|
|
504
506
|
action = next(t for t in plan["tools"] if t["tool"] == "gateway")
|
|
505
|
-
return owned_address(action["path"], plan["tools_dir"],
|
|
507
|
+
return owned_address(action["path"], plan["tools_dir"], harness_core.tool_path(plan, "magpie"))
|