@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
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
"""Shared harness contracts, lock loading, tool subprocesses, gateway env and artifact fetching.
|
|
2
|
+
|
|
3
|
+
Layer-3 leaf below ``bifrost_*``, ``gateway_*``, ``harness*``, ``runtime_*``, and
|
|
4
|
+
``stack_clients`` so every L4 module depends strictly downward with zero import cycles.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import contextlib
|
|
10
|
+
import json
|
|
11
|
+
import os
|
|
12
|
+
import re
|
|
13
|
+
import subprocess
|
|
14
|
+
import tempfile
|
|
15
|
+
from collections.abc import Callable
|
|
16
|
+
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
from typing import Any, Literal, TypedDict, cast
|
|
19
|
+
|
|
20
|
+
from localmodels import harness_cleanup, hosts, pi_profile, region
|
|
21
|
+
from localmodels.contracts import decode
|
|
22
|
+
from localmodels.npm_transport import Artifact as Artifact
|
|
23
|
+
from localmodels.npm_transport import ToolBuild as ToolBuild
|
|
24
|
+
from localmodels.remote_ops import Archive, fetch
|
|
25
|
+
from localmodels.remote_ops_download import npm_copies
|
|
26
|
+
from localmodels.runtime_io import Event, fetch_bifrost
|
|
27
|
+
from localmodels.stack_events import CombinedEvents, ToolEvents
|
|
28
|
+
|
|
29
|
+
TOOL_LOCK = Path(__file__).with_name("tools.json")
|
|
30
|
+
DEFAULT_TOOLS_DIR = hosts.TOOLS_DIR
|
|
31
|
+
BIN_DIR = "~/.local/bin"
|
|
32
|
+
UNIT_DIR = "~/.config/systemd/user"
|
|
33
|
+
GATEWAY_ADDR = "127.0.0.1:3425" # Magpie's default; MAGPIE_ADDR overrides it
|
|
34
|
+
BIFROST_ADDR = "127.0.0.1:18480" # this tool's Bifrost; LOCALMODELS_BIFROST_ADDR overrides it
|
|
35
|
+
GATEWAYS = ("bifrost", "magpie")
|
|
36
|
+
DEFAULT_GATEWAY = "bifrost"
|
|
37
|
+
LLM_PROVIDER = "localmodels-llm"
|
|
38
|
+
DECISION_PROVIDER = "localmodels-jev"
|
|
39
|
+
GROUP = "localmodels-agent"
|
|
40
|
+
# The rule Magpie asks the decision model about at the start of every new turn.
|
|
41
|
+
HARD_INTENT = "a hard multi-step coding, debugging or design task"
|
|
42
|
+
OWNED_WRAPPER = "# localmodels: pi wrapper"
|
|
43
|
+
# Fixed, published value the user chose (2026-10-31); Magpie refuses sk-magpie- prefixes.
|
|
44
|
+
CALLER_KEY = "sk-local-123456"
|
|
45
|
+
PI_DOWNLOADS = 8 # pi's tree is ~120 small tarballs; one at a time takes minutes
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class HarnessError(RuntimeError):
|
|
49
|
+
"""A tool could not be planned, installed or wired; the message says why."""
|
|
50
|
+
|
|
51
|
+
def __init__(self, message: str, *, code: str | None = None) -> None:
|
|
52
|
+
super().__init__(message)
|
|
53
|
+
self.code = code
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class ClientConfig(TypedDict):
|
|
57
|
+
model: str | None
|
|
58
|
+
files: dict[str, str | None]
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class ClientState(ClientConfig):
|
|
62
|
+
path: str | None
|
|
63
|
+
version: str | None
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class NodeLock(TypedDict):
|
|
67
|
+
version: str
|
|
68
|
+
min_version: str
|
|
69
|
+
builds: list[ToolBuild]
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class NpmArtifact(TypedDict):
|
|
73
|
+
package: str
|
|
74
|
+
version: str
|
|
75
|
+
license: str
|
|
76
|
+
name: str
|
|
77
|
+
url: str
|
|
78
|
+
sha256: str
|
|
79
|
+
size_bytes: int
|
|
80
|
+
integrity: str
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class _PiModuleOptional(NpmArtifact, total=False):
|
|
84
|
+
install_script: str # "skipped": npm would run one; scripts/pin_pi.py says why it is not
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class PiModule(_PiModuleOptional):
|
|
88
|
+
path: (
|
|
89
|
+
str # its place under the package root, npm's lockfile key: node_modules/a[/node_modules/b]
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class PiLock(NpmArtifact):
|
|
94
|
+
"""pi and its whole production dependency tree, written by scripts/pin_pi.py."""
|
|
95
|
+
|
|
96
|
+
entry: str
|
|
97
|
+
modules: list[PiModule]
|
|
98
|
+
longest_path: int # characters of the deepest file below the package root
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
class MagpieLock(TypedDict):
|
|
102
|
+
version: str
|
|
103
|
+
builds: list[ToolBuild]
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
class BifrostLock(TypedDict):
|
|
107
|
+
version: str
|
|
108
|
+
source: str
|
|
109
|
+
license: str
|
|
110
|
+
note: str
|
|
111
|
+
builds: list[ToolBuild]
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
class _ToolLockSince20261102(TypedDict, total=False):
|
|
115
|
+
bifrost: BifrostLock
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
class ToolLock(_ToolLockSince20261102):
|
|
119
|
+
schema: str
|
|
120
|
+
node: NodeLock
|
|
121
|
+
pi: PiLock
|
|
122
|
+
magpie: MagpieLock
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
class _ToolStateSince20261026(TypedDict, total=False):
|
|
126
|
+
gateway_other_user: bool # another user's program listens at gateway_addr
|
|
127
|
+
clients: dict[str, ClientState]
|
|
128
|
+
tools_dir: str
|
|
129
|
+
bifrost_addr: str # where this tool's Bifrost listens (since 2026-11-02)
|
|
130
|
+
bifrost_listeners: list[int] # uids of the programs listening at bifrost_addr
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
class ToolState(_ToolStateSince20261026):
|
|
134
|
+
"""What this computer has now; read-only."""
|
|
135
|
+
|
|
136
|
+
inspection: Literal["complete", "unknown"]
|
|
137
|
+
node: str | None
|
|
138
|
+
node_version: str | None
|
|
139
|
+
pi: str | None
|
|
140
|
+
pi_version: str | None
|
|
141
|
+
magpie: str | None
|
|
142
|
+
magpie_version: str | None
|
|
143
|
+
gateway_addr: str
|
|
144
|
+
gateway_up: bool
|
|
145
|
+
pi_model: str | None
|
|
146
|
+
bin_on_path: bool
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
class ToolAction(TypedDict):
|
|
150
|
+
tool: str # node | pi | magpie | bifrost | gateway
|
|
151
|
+
action: str # reuse | install | skip | daemon | serve | unit (Bifrost's systemd --user unit)
|
|
152
|
+
path: str
|
|
153
|
+
version: str | None
|
|
154
|
+
artifacts: list[Artifact]
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
class Endpoint(TypedDict):
|
|
158
|
+
url: str
|
|
159
|
+
model: str
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
class _GatewayOptional(TypedDict, total=False):
|
|
163
|
+
efforts: list[str] # reasoning_effort levels the template accepts, low to high; none: all
|
|
164
|
+
caller_key: str # name of the gateway key gateway_keys.CALLER_KEY goes by; older plans add none
|
|
165
|
+
clients: dict[str, ClientConfig]
|
|
166
|
+
# Since 2026-11-02: which gateway carries the stack. Absent: Magpie, as every plan before.
|
|
167
|
+
kind: str # one of GATEWAYS
|
|
168
|
+
llm_fast: Endpoint # optional fastest provider, only on a two-LLM Bifrost plan
|
|
169
|
+
llm_fast_key_file: str # private deployment credential, never its content
|
|
170
|
+
llm_key_file: str # direct readiness credential path, only present on two-LLM plans
|
|
171
|
+
context: int # the LLM's context window per request, for the clients' model entries
|
|
172
|
+
vision: bool # True when the served LLM reads images (vision.reads_pictures), for clients
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
class GatewayPlan(_GatewayOptional):
|
|
176
|
+
addr: str
|
|
177
|
+
group: str
|
|
178
|
+
llm_provider: str
|
|
179
|
+
decision_provider: str
|
|
180
|
+
llm: Endpoint
|
|
181
|
+
decision: Endpoint | None
|
|
182
|
+
intent: str
|
|
183
|
+
pi_model_before: str | None
|
|
184
|
+
pi_model: str
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
class _NativeTools(TypedDict, total=False):
|
|
188
|
+
native: dict[str, dict[str, Any]]
|
|
189
|
+
environment: dict[str, str]
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
class ToolPlan(_NativeTools):
|
|
193
|
+
"""Node.js, pi, the gateway program and the gateway: what installing the tools needs,
|
|
194
|
+
without models."""
|
|
195
|
+
|
|
196
|
+
tools_dir: str
|
|
197
|
+
tools: list[ToolAction]
|
|
198
|
+
download_bytes: int
|
|
199
|
+
warnings: list[str]
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
class HarnessPlan(ToolPlan):
|
|
203
|
+
gateway: GatewayPlan
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def load_lock() -> ToolLock:
|
|
207
|
+
return decode(json.loads(TOOL_LOCK.read_text(encoding="utf-8")), ToolLock)
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def version_tuple(text: str | None) -> tuple[int, ...]:
|
|
211
|
+
return tuple(int(x) for x in re.findall(r"\d+", text or "")[:3]) or (0,)
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def run_tool(
|
|
215
|
+
argv: list[str],
|
|
216
|
+
*,
|
|
217
|
+
timeout: float = 60,
|
|
218
|
+
cwd: str | None = None,
|
|
219
|
+
env: dict[str, str] | None = None,
|
|
220
|
+
stdin_text: str | None = None,
|
|
221
|
+
) -> subprocess.CompletedProcess[str]:
|
|
222
|
+
try:
|
|
223
|
+
return subprocess.run(
|
|
224
|
+
argv,
|
|
225
|
+
capture_output=True,
|
|
226
|
+
text=True,
|
|
227
|
+
encoding="utf-8",
|
|
228
|
+
errors="replace",
|
|
229
|
+
timeout=timeout,
|
|
230
|
+
check=False,
|
|
231
|
+
input=stdin_text,
|
|
232
|
+
stdin=subprocess.DEVNULL if stdin_text is None else None,
|
|
233
|
+
cwd=cwd,
|
|
234
|
+
env=env,
|
|
235
|
+
)
|
|
236
|
+
except (OSError, subprocess.TimeoutExpired) as exc:
|
|
237
|
+
return subprocess.CompletedProcess(argv, 127, "", f"{type(exc).__name__}")
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
def gateway_addr(env: dict[str, str] | None = None) -> str:
|
|
241
|
+
return (env if env is not None else os.environ).get("MAGPIE_ADDR") or GATEWAY_ADDR
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def bifrost_addr(env: dict[str, str] | None = None) -> str:
|
|
245
|
+
return (env if env is not None else os.environ).get("LOCALMODELS_BIFROST_ADDR") or BIFROST_ADDR
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def gateway_kind(gw: GatewayPlan | dict[str, Any] | None) -> str:
|
|
249
|
+
"""The gateway a stack plan's ``harness.gateway`` names; a plan without one used Magpie."""
|
|
250
|
+
return str((gw or {}).get("kind") or "magpie")
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def search_path(env: dict[str, str]) -> str:
|
|
254
|
+
"""PATH plus ~/.local/bin, where installers put commands and non-login shells miss it."""
|
|
255
|
+
home = env.get("HOME") or os.path.expanduser("~")
|
|
256
|
+
return os.pathsep.join([env.get("PATH", ""), os.path.join(home, BIN_DIR.removeprefix("~/"))])
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
def tool_build(builds: list[ToolBuild], platform: str, arch: str, tool: str) -> ToolBuild:
|
|
260
|
+
names = {platform, "windows"} if platform == "win32" else {platform} # the lock: windows
|
|
261
|
+
match = next((b for b in builds if b["platform"] in names and b["arch"] == arch), None)
|
|
262
|
+
if match is None:
|
|
263
|
+
raise HarnessError(f"{tool} has no pinned version for {platform}/{arch}")
|
|
264
|
+
return match
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
def tool_artifact(item: ToolBuild | NpmArtifact | PiModule) -> Artifact:
|
|
268
|
+
artifact: Artifact = {
|
|
269
|
+
"name": item["name"],
|
|
270
|
+
"url": item["url"],
|
|
271
|
+
"sha256": item["sha256"],
|
|
272
|
+
"size_bytes": item["size_bytes"],
|
|
273
|
+
}
|
|
274
|
+
if "npm" in item:
|
|
275
|
+
artifact["npm"] = cast(ToolBuild, item)["npm"]
|
|
276
|
+
if "npm_copy" in item:
|
|
277
|
+
artifact["npm_copy"] = cast(ToolBuild, item)["npm_copy"]
|
|
278
|
+
if "path" in item:
|
|
279
|
+
artifact["path"] = cast(PiModule, item)["path"]
|
|
280
|
+
return artifact
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def reuse_tool(
|
|
284
|
+
tool: str, path: str | None, version: str | None, *, needed: bool = True
|
|
285
|
+
) -> ToolAction:
|
|
286
|
+
return {
|
|
287
|
+
"tool": tool,
|
|
288
|
+
"action": "reuse" if needed else "skip",
|
|
289
|
+
"path": path or "",
|
|
290
|
+
"version": version,
|
|
291
|
+
"artifacts": [],
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def tool_path(plan: ToolPlan, tool: str) -> str:
|
|
296
|
+
return os.path.expanduser(next(t["path"] for t in plan["tools"] if t["tool"] == tool))
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def gateway_environment(plan: ToolPlan, *, base: dict[str, str] | None = None) -> dict[str, str]:
|
|
300
|
+
"""Derive an execution environment without writing inherited credentials into a plan."""
|
|
301
|
+
env = dict(
|
|
302
|
+
plan["environment"] if "environment" in plan else os.environ if base is None else base
|
|
303
|
+
)
|
|
304
|
+
action = next((t for t in plan["tools"] if t["tool"] == "gateway"), None)
|
|
305
|
+
if action is None:
|
|
306
|
+
return env
|
|
307
|
+
gateway = plan.get("gateway")
|
|
308
|
+
if isinstance(gateway, dict) and gateway.get("addr") != action["path"]:
|
|
309
|
+
raise HarnessError("the gateway address in the approved plan does not match")
|
|
310
|
+
if isinstance(gateway, dict) and gateway_kind(gateway) == "bifrost":
|
|
311
|
+
if "environment" not in plan:
|
|
312
|
+
env.update(pi_profile.client_environment(plan["tools_dir"]))
|
|
313
|
+
return env
|
|
314
|
+
env["MAGPIE_ADDR"] = action["path"]
|
|
315
|
+
home = Path(env.get("HOME", str(Path.home())))
|
|
316
|
+
if "environment" not in plan and action["action"] != "daemon":
|
|
317
|
+
private = pi_profile.gateway_home(plan["tools_dir"])
|
|
318
|
+
env.update(
|
|
319
|
+
HOME=str(private),
|
|
320
|
+
USERPROFILE=str(private),
|
|
321
|
+
XDG_CONFIG_HOME=str(private / ".config"),
|
|
322
|
+
MAGPIE_CONFIG_DIR=str(private / ".config/magpie"),
|
|
323
|
+
XDG_DATA_HOME=str(private / ".local/share"),
|
|
324
|
+
XDG_CACHE_HOME=str(private / ".cache"),
|
|
325
|
+
APPDATA=str(private / "AppData/Roaming"),
|
|
326
|
+
LOCALAPPDATA=str(private / "AppData/Local"),
|
|
327
|
+
)
|
|
328
|
+
env.setdefault("PI_CODING_AGENT_DIR", str(home / ".pi/agent"))
|
|
329
|
+
env.setdefault("CODEX_HOME", str(home / ".codex"))
|
|
330
|
+
env.setdefault("CLAUDE_CONFIG_DIR", str(home / ".claude"))
|
|
331
|
+
if "gateway" in plan:
|
|
332
|
+
env.update(pi_profile.client_environment(plan["tools_dir"]))
|
|
333
|
+
return env
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
def archive_files(tools_dir: Path, artifact: Artifact) -> list[str]:
|
|
337
|
+
"""The files ``fetch_artifact`` may leave in ``.archives`` for ``artifact``: the archive,
|
|
338
|
+
fetch's verification marker and, for an npm build, its lock and the tarball with its partial
|
|
339
|
+
download (gone after a successful fetch). The owned manifest lists them for ``--purge``."""
|
|
340
|
+
path = str(tools_dir / ".archives" / artifact["name"])
|
|
341
|
+
suffixes = ("", ".sha256", *((".lock", ".tgz", ".tgz.part") if "npm" in artifact else ()))
|
|
342
|
+
return [path + suffix for suffix in suffixes]
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
def own_downloads(tools_dir: Path, artifacts: list[Artifact]) -> None:
|
|
346
|
+
"""List ``artifacts``' archive files in the owned manifest before fetching them, so
|
|
347
|
+
``--purge`` also finds the partial download of an install that failed or was killed."""
|
|
348
|
+
files = {f for a in artifacts for f in archive_files(tools_dir, a)}
|
|
349
|
+
hosts.update_owned(
|
|
350
|
+
lambda doc: doc.__setitem__("archives", sorted(set(doc["archives"]) | files)), tools_dir
|
|
351
|
+
)
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
def download_artifact(path: Path, artifact: Artifact) -> None:
|
|
355
|
+
fetch(
|
|
356
|
+
artifact["url"],
|
|
357
|
+
str(path),
|
|
358
|
+
artifact["sha256"],
|
|
359
|
+
artifact["size_bytes"],
|
|
360
|
+
artifact["name"],
|
|
361
|
+
npm_copies(cast(Archive, artifact)),
|
|
362
|
+
region.current_region(),
|
|
363
|
+
)
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
def fetch_artifact(
|
|
367
|
+
tools_dir: Path,
|
|
368
|
+
artifact: Artifact,
|
|
369
|
+
log: Callable[[str], None],
|
|
370
|
+
event: Event = lambda _: None,
|
|
371
|
+
) -> Path:
|
|
372
|
+
path = tools_dir / ".archives" / artifact["name"]
|
|
373
|
+
if "npm" in artifact:
|
|
374
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
375
|
+
# stack apply and source apply may fetch it at once: one writes the tarball, the other
|
|
376
|
+
# waits and then reuses the binary it published.
|
|
377
|
+
with hosts.file_lock(path.with_name(path.name + ".lock")):
|
|
378
|
+
if not path.is_file() or harness_cleanup.digest(str(path)) != artifact["sha256"]:
|
|
379
|
+
with tempfile.TemporaryDirectory(dir=path.parent) as temporary:
|
|
380
|
+
staged = Path(temporary) / "bifrost-http"
|
|
381
|
+
fetch_bifrost(artifact, staged, path.with_name(path.name + ".tgz"), event)
|
|
382
|
+
staged.replace(path)
|
|
383
|
+
return path
|
|
384
|
+
with contextlib.redirect_stdout(ToolEvents(log)):
|
|
385
|
+
download_artifact(path, artifact)
|
|
386
|
+
return path
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
def fetch_many(
|
|
390
|
+
tools_dir: Path, artifacts: list[Artifact], log: Callable[[str], None]
|
|
391
|
+
) -> list[Path]:
|
|
392
|
+
"""Download ``artifacts`` eight at a time, reported as one download of their total bytes;
|
|
393
|
+
the first failure cancels the ones still queued. A tarball two of them share downloads
|
|
394
|
+
once."""
|
|
395
|
+
unique = {a["name"]: a for a in artifacts}
|
|
396
|
+
events = CombinedEvents(log, {name: a["size_bytes"] for name, a in unique.items()})
|
|
397
|
+
pool = ThreadPoolExecutor(PI_DOWNLOADS)
|
|
398
|
+
try:
|
|
399
|
+
with contextlib.redirect_stdout(events):
|
|
400
|
+
futures = {
|
|
401
|
+
pool.submit(download_artifact, tools_dir / ".archives" / name, a): name
|
|
402
|
+
for name, a in unique.items()
|
|
403
|
+
}
|
|
404
|
+
for future in as_completed(futures):
|
|
405
|
+
future.result()
|
|
406
|
+
events.finished(futures[future])
|
|
407
|
+
finally:
|
|
408
|
+
pool.shutdown(wait=True, cancel_futures=True)
|
|
409
|
+
return [tools_dir / ".archives" / a["name"] for a in artifacts]
|