@lmmslab/harness 0.83.0 → 0.85.0
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/bin/harness.js +6 -1
- package/package.json +1 -1
- package/python/harness/__init__.py +1 -1
- package/python/harness/builtin/prompts/core/core.md +68 -38
- package/python/harness/builtin/prompts/shared/learning-goal.md +1 -1
- package/python/harness/cli.py +140 -18
- package/python/harness/config/agent.py +3 -0
- package/python/harness/core/trace.py +23 -3
- package/python/harness/core/worker.py +6 -0
- package/python/harness/host/client.py +26 -21
- package/python/harness/host/http.py +11 -1
- package/python/harness/host/sessions.py +38 -3
- package/python/harness/host/tasks.py +71 -27
- package/python/harness/instructions.py +329 -0
- package/python/harness/model_list.py +25 -5
- package/python/harness/packages/environments.py +51 -12
- package/python/harness/packages/manager.py +379 -102
- package/python/harness/packages/resolve.py +52 -15
- package/python/harness/packages/sources.py +17 -5
- package/python/harness/packages/state.py +10 -0
- package/python/harness/providers.py +66 -24
- package/python/harness/runtime/decision/model.py +9 -4
- package/python/harness/runtime/events.py +1 -0
- package/python/harness/runtime/execution/entries.py +53 -7
- package/python/harness/runtime/execution/session.py +57 -10
- package/python/harness/runtime/learning/active.py +4 -4
- package/python/harness/runtime/reactive/tree.py +96 -53
- package/python/harness/runtime/task/environments.py +3 -1
- package/python/harness/runtime/task/run.py +93 -4
- package/python/harness/runtime/tick.py +34 -3
- package/python/harness/settings.py +23 -1
- package/python/harness/terminal.py +3 -0
- package/python/harness/transcript.py +12 -0
- package/python/harness/tui/__init__.py +28 -6
- package/python/harness/tui/chat.py +323 -80
- package/python/harness/tui/pty.py +16 -0
- package/python/harness/tui/renderer.py +1 -0
- package/python/harness/tui/views.py +160 -38
|
@@ -5,12 +5,13 @@ the chat (tui/chat.py, tui/views.py). Records are read as every frontend reads t
|
|
|
5
5
|
(transcript.py), commands come from the one table (terminal.COMMANDS).
|
|
6
6
|
|
|
7
7
|
prompt_toolkit (input, keys, pickers) and rich (Markdown, colour) draw it; neither is a
|
|
8
|
-
dependency of the harness. When this interpreter
|
|
8
|
+
dependency of the harness. When this interpreter lacks their declared pins, the first use
|
|
9
9
|
installs them pinned into an environment of their own (HOME/envs/tui/<hash>/,
|
|
10
|
-
environments.py) and
|
|
10
|
+
environments.py) and gives those pinned packages precedence in this process's path.
|
|
11
11
|
"""
|
|
12
12
|
|
|
13
13
|
import importlib.util
|
|
14
|
+
from importlib import metadata
|
|
14
15
|
import subprocess
|
|
15
16
|
import sys
|
|
16
17
|
|
|
@@ -27,17 +28,38 @@ def environment() -> environments.Environment:
|
|
|
27
28
|
return environments.resolve("tui", spec)
|
|
28
29
|
|
|
29
30
|
|
|
31
|
+
def _compatible() -> bool:
|
|
32
|
+
"""Check only the six declared distributions, without running pip or importing UI code."""
|
|
33
|
+
for requirement in LIBRARIES + PINS:
|
|
34
|
+
name, version = requirement.split("==", 1)
|
|
35
|
+
try:
|
|
36
|
+
if metadata.version(name) != version:
|
|
37
|
+
return False
|
|
38
|
+
except metadata.PackageNotFoundError:
|
|
39
|
+
return False
|
|
40
|
+
return all(importlib.util.find_spec(name) is not None for name in ("prompt_toolkit", "rich"))
|
|
41
|
+
|
|
42
|
+
|
|
30
43
|
def load(*, log=print) -> None:
|
|
31
|
-
"""
|
|
32
|
-
|
|
33
|
-
if all(importlib.util.find_spec(name) is not None for name in ("prompt_toolkit", "rich")):
|
|
44
|
+
"""Use the pinned TUI libraries here, preparing the managed environment if needed."""
|
|
45
|
+
if _compatible():
|
|
34
46
|
return
|
|
47
|
+
modules = ("prompt_toolkit", "rich", "wcwidth", "markdown_it", "mdurl", "pygments")
|
|
48
|
+
if any(name in sys.modules for name in modules):
|
|
49
|
+
raise RuntimeError("incompatible terminal libraries are already loaded; restart harness in a clean "
|
|
50
|
+
"Python environment, or install its terminal pins with "
|
|
51
|
+
f"{sys.executable} -m pip install " + " ".join(LIBRARIES + PINS))
|
|
35
52
|
env = environments.on_first_use(environment(), "prompt_toolkit and rich for the terminal chat", log=log)
|
|
36
53
|
packages = subprocess.run([str(env.python), "-I", "-X", "utf8", "-c",
|
|
37
54
|
"import sysconfig; print(sysconfig.get_path('purelib'))"],
|
|
38
55
|
capture_output=True, encoding="utf-8", check=True).stdout.strip()
|
|
39
|
-
|
|
56
|
+
# The managed versions must precede incompatible importable libraries in the
|
|
57
|
+
# host interpreter. Appending would leave the incompatible copies selected.
|
|
58
|
+
sys.path.insert(0, packages)
|
|
40
59
|
importlib.invalidate_caches()
|
|
60
|
+
if not _compatible():
|
|
61
|
+
raise RuntimeError(f"terminal libraries in {env.directory} do not match the declared pins; "
|
|
62
|
+
"remove that managed environment and restart harness to rebuild it")
|
|
41
63
|
|
|
42
64
|
|
|
43
65
|
def chat(conversation=None, records=None, *, host=None, start=None, log=print):
|