@lmmslab/harness 0.0.0-stage → 0.81.1
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/LICENSE +21 -0
- package/README.md +124 -2
- package/bin/harness.js +71 -0
- package/package.json +34 -4
- package/python/harness/README.md +72 -0
- package/python/harness/__init__.py +8 -0
- package/python/harness/__main__.py +3 -0
- package/python/harness/bench.py +124 -0
- package/python/harness/builtin/benches/README.md +5 -0
- package/python/harness/builtin/benches/none/bench.toml +6 -0
- package/python/harness/builtin/configs/README.md +26 -0
- package/python/harness/builtin/configs/assistant.toml +11 -0
- package/python/harness/builtin/configs/default.toml +33 -0
- package/python/harness/builtin/configs/deploy/example-api.toml +10 -0
- package/python/harness/builtin/configs/models/deepseek-api.toml +21 -0
- package/python/harness/builtin/configs/models/deepseek-flash.toml +12 -0
- package/python/harness/builtin/configs/models/grok-low.toml +8 -0
- package/python/harness/builtin/configs/models/grok-medium.toml +43 -0
- package/python/harness/builtin/configs/models/opus-5.5.toml +11 -0
- package/python/harness/builtin/environment/README.md +53 -0
- package/python/harness/builtin/environment/constraints.txt +31 -0
- package/python/harness/builtin/model-settings.js +143 -0
- package/python/harness/builtin/prompts/conversation/core.md +5 -0
- package/python/harness/builtin/prompts/conversation/pack.toml +12 -0
- package/python/harness/builtin/prompts/core/core.md +88 -0
- package/python/harness/builtin/prompts/core/pack.toml +9 -0
- package/python/harness/builtin/prompts/reflect/core.md +45 -0
- package/python/harness/builtin/prompts/reflect/pack.toml +7 -0
- package/python/harness/builtin/prompts/shared/agent-skills.md +5 -0
- package/python/harness/builtin/prompts/shared/agents.md +14 -0
- package/python/harness/builtin/prompts/shared/checklist.md +21 -0
- package/python/harness/builtin/prompts/shared/entries.md +86 -0
- package/python/harness/builtin/prompts/shared/environments.md +21 -0
- package/python/harness/builtin/prompts/shared/learning-goal.md +31 -0
- package/python/harness/builtin/prompts/shared/learning.md +27 -0
- package/python/harness/builtin/prompts/shared/mcp.md +9 -0
- package/python/harness/builtin/prompts/shared/world.md +1 -0
- package/python/harness/builtin/skills/README.md +10 -0
- package/python/harness/builtin/skills/agents/__init__.py +88 -0
- package/python/harness/builtin/skills/agents/skill.toml +11 -0
- package/python/harness/builtin/skills/checklist/__init__.py +32 -0
- package/python/harness/builtin/skills/checklist/skill.toml +9 -0
- package/python/harness/builtin/skills/conversation/__init__.py +23 -0
- package/python/harness/builtin/skills/conversation/skill.toml +8 -0
- package/python/harness/builtin/skills/entries/__init__.py +62 -0
- package/python/harness/builtin/skills/entries/skill.toml +8 -0
- package/python/harness/builtin/skills/environments/__init__.py +69 -0
- package/python/harness/builtin/skills/environments/skill.toml +9 -0
- package/python/harness/builtin/skills/experience/__init__.py +27 -0
- package/python/harness/builtin/skills/experience/skill.toml +9 -0
- package/python/harness/builtin/skills/instructions/__init__.py +29 -0
- package/python/harness/builtin/skills/instructions/skill.toml +9 -0
- package/python/harness/builtin/skills/learning/__init__.py +189 -0
- package/python/harness/builtin/skills/learning/skill.toml +7 -0
- package/python/harness/builtin/skills/mcp/__init__.py +54 -0
- package/python/harness/builtin/skills/mcp/skill.toml +10 -0
- package/python/harness/builtin/skills/memory/__init__.py +130 -0
- package/python/harness/builtin/skills/memory/skill.toml +13 -0
- package/python/harness/builtin/skills/verify/__init__.py +31 -0
- package/python/harness/builtin/skills/verify/skill.toml +7 -0
- package/python/harness/builtin/third_party/sources.toml +40 -0
- package/python/harness/cli.py +1182 -0
- package/python/harness/config/__init__.py +224 -0
- package/python/harness/config/agent.py +777 -0
- package/python/harness/core/__init__.py +52 -0
- package/python/harness/core/artifacts.py +46 -0
- package/python/harness/core/codec.py +160 -0
- package/python/harness/core/contracts.py +75 -0
- package/python/harness/core/episodes.py +150 -0
- package/python/harness/core/format.py +51 -0
- package/python/harness/core/http.py +124 -0
- package/python/harness/core/lanes.py +324 -0
- package/python/harness/core/linux_sandbox.py +55 -0
- package/python/harness/core/media.py +96 -0
- package/python/harness/core/memory.py +147 -0
- package/python/harness/core/ports.py +63 -0
- package/python/harness/core/procs.py +227 -0
- package/python/harness/core/remote.py +102 -0
- package/python/harness/core/spans.py +166 -0
- package/python/harness/core/trace.py +139 -0
- package/python/harness/core/wait.py +12 -0
- package/python/harness/core/worker.py +388 -0
- package/python/harness/core/worker_pipe.py +119 -0
- package/python/harness/embodiments.py +217 -0
- package/python/harness/extensions.py +112 -0
- package/python/harness/host/__init__.py +397 -0
- package/python/harness/host/client.py +201 -0
- package/python/harness/host/http.py +720 -0
- package/python/harness/host/listing.py +68 -0
- package/python/harness/host/server.py +189 -0
- package/python/harness/host/sessions.py +406 -0
- package/python/harness/host/tasks.py +1356 -0
- package/python/harness/host/workers.py +257 -0
- package/python/harness/host/workspaces.py +256 -0
- package/python/harness/model_list.py +117 -0
- package/python/harness/packages/__init__.py +73 -0
- package/python/harness/packages/addons.py +121 -0
- package/python/harness/packages/archive.py +122 -0
- package/python/harness/packages/describe.py +46 -0
- package/python/harness/packages/environments.py +448 -0
- package/python/harness/packages/fetch.py +57 -0
- package/python/harness/packages/manager.py +587 -0
- package/python/harness/packages/manifest.py +232 -0
- package/python/harness/packages/migrate.py +68 -0
- package/python/harness/packages/provision.py +38 -0
- package/python/harness/packages/registry.py +275 -0
- package/python/harness/packages/resolve.py +89 -0
- package/python/harness/packages/sources.py +141 -0
- package/python/harness/packages/state.py +213 -0
- package/python/harness/packages/versions.py +112 -0
- package/python/harness/paths.py +218 -0
- package/python/harness/providers.py +303 -0
- package/python/harness/runtime/__init__.py +8 -0
- package/python/harness/runtime/decision/__init__.py +1 -0
- package/python/harness/runtime/decision/loop.py +198 -0
- package/python/harness/runtime/decision/messages.py +271 -0
- package/python/harness/runtime/decision/model.py +424 -0
- package/python/harness/runtime/decision/prompts.py +248 -0
- package/python/harness/runtime/decision/protocol.py +169 -0
- package/python/harness/runtime/decision/thoughts.py +199 -0
- package/python/harness/runtime/events.py +213 -0
- package/python/harness/runtime/execution/__init__.py +1 -0
- package/python/harness/runtime/execution/attached.py +96 -0
- package/python/harness/runtime/execution/control.py +211 -0
- package/python/harness/runtime/execution/entries.py +665 -0
- package/python/harness/runtime/execution/kernel.py +811 -0
- package/python/harness/runtime/execution/noenv.py +84 -0
- package/python/harness/runtime/execution/results.py +40 -0
- package/python/harness/runtime/execution/session.py +871 -0
- package/python/harness/runtime/execution/skills.py +436 -0
- package/python/harness/runtime/learning/__init__.py +1 -0
- package/python/harness/runtime/learning/active.py +314 -0
- package/python/harness/runtime/learning/experience.py +48 -0
- package/python/harness/runtime/learning/fixtures.py +167 -0
- package/python/harness/runtime/learning/learner.py +651 -0
- package/python/harness/runtime/learning/library.py +504 -0
- package/python/harness/runtime/learning/reflect.py +151 -0
- package/python/harness/runtime/learning/usage.py +30 -0
- package/python/harness/runtime/learning/views.py +89 -0
- package/python/harness/runtime/reactive/__init__.py +1 -0
- package/python/harness/runtime/reactive/rules.py +549 -0
- package/python/harness/runtime/safety/__init__.py +1 -0
- package/python/harness/runtime/safety/approval.py +131 -0
- package/python/harness/runtime/safety/input.py +62 -0
- package/python/harness/runtime/safety/isolation.py +419 -0
- package/python/harness/runtime/safety/shield.py +129 -0
- package/python/harness/runtime/status.py +23 -0
- package/python/harness/runtime/task/__init__.py +7 -0
- package/python/harness/runtime/task/context.py +431 -0
- package/python/harness/runtime/task/delegation.py +468 -0
- package/python/harness/runtime/task/environments.py +268 -0
- package/python/harness/runtime/task/run.py +2878 -0
- package/python/harness/runtime/tick.py +909 -0
- package/python/harness/sdk/__init__.py +281 -0
- package/python/harness/services/__init__.py +6 -0
- package/python/harness/services/broker.py +35 -0
- package/python/harness/services/connectors.py +88 -0
- package/python/harness/services/mcp.py +298 -0
- package/python/harness/services/mcp_stdio.py +131 -0
- package/python/harness/services/placement.py +82 -0
- package/python/harness/services/registry.py +156 -0
- package/python/harness/settings.py +536 -0
- package/python/harness/terminal.py +79 -0
- package/python/harness/transcript.py +297 -0
- package/python/harness/tui/__init__.py +68 -0
- package/python/harness/tui/chat.py +1181 -0
- package/python/harness/tui/pty.py +81 -0
- package/python/harness/tui/renderer.py +45 -0
- package/python/harness/tui/timeline_rows.py +58 -0
- package/python/harness/tui/views.py +434 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"""Configuration: TOML files that include others, with paths relative to the file
|
|
2
|
+
that names them, and `--set key.path=value` overrides.
|
|
3
|
+
|
|
4
|
+
Layers, later ones winning (configs/README.md):
|
|
5
|
+
|
|
6
|
+
code defaults the values the code uses when a file names none
|
|
7
|
+
default.toml the agent: prompt, skills, services, runtime, budget, and
|
|
8
|
+
its default model (other agent files may include it)
|
|
9
|
+
models/<name>.toml model roles: main, vlm, pointer, verifier (an API model or a
|
|
10
|
+
service), plus the runtime settings a model needs
|
|
11
|
+
experiments/<name>.toml the agent with a model on a benchmark: tasks, seeds,
|
|
12
|
+
layouts, budgets, worker options, overrides
|
|
13
|
+
--model, --set the command line
|
|
14
|
+
|
|
15
|
+
and configs/deploy/<machine>.toml says where services run (the local-models package). Keys
|
|
16
|
+
live in environment variables, never in these files.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
import copy
|
|
20
|
+
import json
|
|
21
|
+
import os
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
import re
|
|
24
|
+
import tomllib
|
|
25
|
+
|
|
26
|
+
from ..embodiments import KINDS
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def read_toml(path: Path) -> dict:
|
|
30
|
+
"""One TOML file as a tree, without following its includes."""
|
|
31
|
+
with Path(path).open("rb") as handle:
|
|
32
|
+
return tomllib.load(handle)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def deep_merge(base: dict, override: dict) -> dict:
|
|
36
|
+
"""`override` on top of `base`: tables merge key by key, anything else replaces."""
|
|
37
|
+
merged = copy.deepcopy(base)
|
|
38
|
+
for key, value in override.items():
|
|
39
|
+
if isinstance(value, dict) and isinstance(merged.get(key), dict):
|
|
40
|
+
merged[key] = deep_merge(merged[key], value)
|
|
41
|
+
else:
|
|
42
|
+
merged[key] = copy.deepcopy(value)
|
|
43
|
+
return merged
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# Keys whose values are paths, as dotted paths into a file's tree. They are made
|
|
47
|
+
# absolute against the directory of the file that sets them, before files merge.
|
|
48
|
+
PATH_KEYS = ("prompt", "runtime.task_descriptions", "runtime.library.path", "agent",
|
|
49
|
+
"overrides.agent.prompt", "overrides.agent.runtime.task_descriptions",
|
|
50
|
+
"overrides.agent.runtime.library.path",
|
|
51
|
+
# The agent's table of each embodiment kind but the robot's ([desktop]).
|
|
52
|
+
*(f"{prefix}{kind}.runtime.{key}" for prefix in ("", "overrides.agent.") for kind in KINDS
|
|
53
|
+
if kind != "robot" for key in ("task_descriptions", "library.path")))
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _absolutize(tree: dict, base: Path) -> dict:
|
|
57
|
+
tree = copy.deepcopy(tree)
|
|
58
|
+
for dotted in PATH_KEYS:
|
|
59
|
+
*parents, last = dotted.split(".")
|
|
60
|
+
node = tree
|
|
61
|
+
for part in parents:
|
|
62
|
+
node = node.get(part) if isinstance(node, dict) else None
|
|
63
|
+
if node is None:
|
|
64
|
+
break
|
|
65
|
+
if not isinstance(node, dict) or last not in node:
|
|
66
|
+
continue
|
|
67
|
+
node[last] = _absolute(node[last], base)
|
|
68
|
+
return tree
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _absolute(value, base: Path):
|
|
72
|
+
"""A path value made absolute: a string, a list of them, or a table of either (a
|
|
73
|
+
prompt by embodiment kind). A path under the harness's home ($HARNESS_HOME/...) stays
|
|
74
|
+
as it is (runtime/learning/learner.py library_path)."""
|
|
75
|
+
from ..paths import locate
|
|
76
|
+
|
|
77
|
+
if isinstance(value, str):
|
|
78
|
+
return value if value.startswith(("$HARNESS_HOME/", "${HARNESS_HOME}/")) else \
|
|
79
|
+
str(locate((base / value).resolve()).resolve())
|
|
80
|
+
if isinstance(value, list):
|
|
81
|
+
return [str(locate((base / item).resolve()).resolve()) if isinstance(item, str) else item for item in value]
|
|
82
|
+
if isinstance(value, dict):
|
|
83
|
+
return {key: _absolute(item, base) for key, item in value.items()}
|
|
84
|
+
return value
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def load_layered(path, _seen=()) -> dict:
|
|
88
|
+
"""A TOML file with its `include = [...]` files merged under it (in order; the
|
|
89
|
+
file's own keys win), path keys made absolute."""
|
|
90
|
+
from ..paths import locate
|
|
91
|
+
|
|
92
|
+
# A path under the repository that moved into a package is found there (paths.locate).
|
|
93
|
+
path = locate(Path(path)).resolve()
|
|
94
|
+
if path in _seen:
|
|
95
|
+
raise ValueError(f"Include cycle through {path}")
|
|
96
|
+
data = read_toml(path)
|
|
97
|
+
includes = data.pop("include", [])
|
|
98
|
+
includes = [includes] if isinstance(includes, str) else list(includes)
|
|
99
|
+
merged = {}
|
|
100
|
+
for include in includes:
|
|
101
|
+
from ..paths import locate
|
|
102
|
+
|
|
103
|
+
merged = deep_merge(merged, load_layered(locate(path.parent / include), (*_seen, path)))
|
|
104
|
+
return deep_merge(merged, _absolutize(data, path.parent))
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def parse_set(text: str) -> tuple[list[str], object]:
|
|
108
|
+
"""`a.b.c=value` as (["a", "b", "c"], value); the value is read as TOML (a number,
|
|
109
|
+
true, "text", [1, 2], {k = 1}) and as a plain string when it is not valid TOML."""
|
|
110
|
+
if "=" not in text:
|
|
111
|
+
raise ValueError(f"--set needs key.path=value, got {text!r}")
|
|
112
|
+
key, raw = text.split("=", 1)
|
|
113
|
+
try:
|
|
114
|
+
value = tomllib.loads(f"value = {raw}")["value"]
|
|
115
|
+
except tomllib.TOMLDecodeError:
|
|
116
|
+
value = raw
|
|
117
|
+
return [part for part in key.strip().split(".") if part], value
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def apply_sets(tree: dict, sets) -> dict:
|
|
121
|
+
"""A copy of `tree` with `--set` items written into it, in order. An item is a
|
|
122
|
+
`key.path=value` string or a parsed (keys, value) pair; missing tables on the path
|
|
123
|
+
are created, and a path through a value that is not a table is an error."""
|
|
124
|
+
tree = copy.deepcopy(tree)
|
|
125
|
+
for item in sets or ():
|
|
126
|
+
keys, value = parse_set(item) if isinstance(item, str) else item
|
|
127
|
+
node = tree
|
|
128
|
+
for key in keys[:-1]:
|
|
129
|
+
node = node.setdefault(key, {})
|
|
130
|
+
if not isinstance(node, dict):
|
|
131
|
+
raise ValueError(f"--set {'.'.join(keys)}: {key} is not a table")
|
|
132
|
+
node[keys[-1]] = value
|
|
133
|
+
return tree
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
BASE_URL_ENV = "OPENROUTER_BASE_URL"
|
|
137
|
+
RELAY_URL_ENV = "OPENROUTER_RELAY_URL"
|
|
138
|
+
RELAY_TOKEN_ENV = "OPENROUTER_RELAY_TOKEN"
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def route_openrouter(tree, environ=os.environ):
|
|
142
|
+
"""Point every OpenRouter model in a harness at another base URL, when asked.
|
|
143
|
+
|
|
144
|
+
Applies to each model config with `backend = "openrouter"` and no `base_url` (so
|
|
145
|
+
the openrouter.ai default) or an openrouter.ai `base_url`:
|
|
146
|
+
|
|
147
|
+
- OPENROUTER_BASE_URL (e.g. https://my-proxy.example/api/v1) replaces the URL;
|
|
148
|
+
the key is still read from the model's `api_key_env` (OPENROUTER_API_KEY).
|
|
149
|
+
- OPENROUTER_RELAY_URL replaces the URL with scripts/openrouter_relay.py and
|
|
150
|
+
reads the key from OPENROUTER_RELAY_TOKEN.
|
|
151
|
+
|
|
152
|
+
Setting both is an error. Models elsewhere (self-hosted servers, other providers)
|
|
153
|
+
are left alone. The rewritten configs go into the run snapshot, so a run records
|
|
154
|
+
the URL it called.
|
|
155
|
+
"""
|
|
156
|
+
base = environ.get(BASE_URL_ENV, "").strip()
|
|
157
|
+
relay = environ.get(RELAY_URL_ENV, "").strip()
|
|
158
|
+
if base and relay:
|
|
159
|
+
raise ValueError(f"Set {BASE_URL_ENV} or {RELAY_URL_ENV}, not both")
|
|
160
|
+
if not (base or relay):
|
|
161
|
+
return tree
|
|
162
|
+
if isinstance(tree, list):
|
|
163
|
+
return [route_openrouter(item, environ) for item in tree]
|
|
164
|
+
if not isinstance(tree, dict):
|
|
165
|
+
return tree
|
|
166
|
+
tree = {key: route_openrouter(value, environ) for key, value in tree.items()}
|
|
167
|
+
base_url = tree.get("base_url")
|
|
168
|
+
direct = isinstance(base_url, str) and "openrouter.ai" in base_url
|
|
169
|
+
if tree.get("backend") == "openrouter" and (base_url is None or direct):
|
|
170
|
+
tree["base_url"] = relay or base
|
|
171
|
+
if relay:
|
|
172
|
+
tree["api_key_env"] = RELAY_TOKEN_ENV
|
|
173
|
+
return tree
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def dumps(data: dict, comment: str = "") -> str:
|
|
177
|
+
"""A tree as a TOML file: values, then tables, lists of tables as [[...]]; None is
|
|
178
|
+
left out (TOML has no null). The one TOML writer: the user's configuration, package
|
|
179
|
+
lists and locks, model and option files."""
|
|
180
|
+
lines = [f"# {comment}"] if comment else []
|
|
181
|
+
_table(lines, [], data)
|
|
182
|
+
return "\n".join(lines).strip("\n") + "\n"
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def toml_key(name) -> str:
|
|
186
|
+
"""A key as TOML: bare when it can be, quoted otherwise."""
|
|
187
|
+
name = str(name)
|
|
188
|
+
return name if re.fullmatch(r"[A-Za-z0-9_-]+", name) else toml_value(name)
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def toml_value(value) -> str:
|
|
192
|
+
"""A value as TOML (inline tables and arrays, None left out of them)."""
|
|
193
|
+
if value is None:
|
|
194
|
+
raise TypeError("TOML has no null")
|
|
195
|
+
if isinstance(value, bool):
|
|
196
|
+
return "true" if value else "false"
|
|
197
|
+
if isinstance(value, (int, float)):
|
|
198
|
+
return repr(value)
|
|
199
|
+
if isinstance(value, (list, tuple)):
|
|
200
|
+
return "[" + ", ".join(toml_value(item) for item in value if item is not None) + "]"
|
|
201
|
+
if isinstance(value, dict):
|
|
202
|
+
return "{ " + ", ".join(f"{toml_key(key)} = {toml_value(item)}" for key, item in value.items()
|
|
203
|
+
if item is not None) + " }"
|
|
204
|
+
# JSON's escapes are TOML's; DEL is a control character TOML wants escaped too.
|
|
205
|
+
return json.dumps(str(value), ensure_ascii=False).replace("\x7f", "\\u007f")
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def _is_tables(item) -> bool:
|
|
209
|
+
return isinstance(item, list) and bool(item) and all(isinstance(part, dict) for part in item)
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def _table(lines, where, table) -> None:
|
|
213
|
+
values = {k: v for k, v in table.items() if v is not None and not isinstance(v, dict) and not _is_tables(v)}
|
|
214
|
+
tables = {k: v for k, v in table.items() if isinstance(v, dict)}
|
|
215
|
+
arrays = {k: v for k, v in table.items() if _is_tables(v)}
|
|
216
|
+
if where and (values or not (tables or arrays)):
|
|
217
|
+
lines += ["", f"[{'.'.join(toml_key(part) for part in where)}]"]
|
|
218
|
+
lines += [f"{toml_key(k)} = {toml_value(v)}" for k, v in values.items()]
|
|
219
|
+
for k, v in tables.items():
|
|
220
|
+
_table(lines, [*where, k], v)
|
|
221
|
+
for k, items in arrays.items():
|
|
222
|
+
for item in items:
|
|
223
|
+
lines += ["", f"[[{'.'.join(toml_key(part) for part in [*where, k])}]]"]
|
|
224
|
+
lines += [f"{toml_key(name)} = {toml_value(value)}" for name, value in item.items() if value is not None]
|