@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,436 @@
|
|
|
1
|
+
"""Skills: the API a model's programs call.
|
|
2
|
+
|
|
3
|
+
A skill is a package `skills/<name>/` in the source checkout with
|
|
4
|
+
|
|
5
|
+
skill.toml name, summary, layer, the names it exports, what it needs
|
|
6
|
+
__init__.py a mixin class with the methods (and optional exports(session) and
|
|
7
|
+
turn_report(session): what the skill adds to the model's next turn
|
|
8
|
+
after every program)
|
|
9
|
+
|
|
10
|
+
A skill runs on the embodiment kinds its `embodiments` names (default robot). The
|
|
11
|
+
kernel's session class is the embodiment's session (runtime/execution/session.py) plus the mixin of
|
|
12
|
+
every skill for that embodiment, so skills can call each other's methods. Which skills a
|
|
13
|
+
program sees is decided per run: the system names them (or the interface layers do), and
|
|
14
|
+
a skill whose services are missing, or that does not run on the run's embodiment, is
|
|
15
|
+
dropped, from the kernel namespace and from the prompt alike (runtime/decision/prompts.py), so the
|
|
16
|
+
model never reads about an API it cannot call.
|
|
17
|
+
|
|
18
|
+
The packages' skills (each package's skills/, paths.roots: those of a source checkout and
|
|
19
|
+
those a user installed) load beside these; one that does not check, or clashes with one
|
|
20
|
+
of these, is left out (USER_PROBLEMS says why) and never changes the built-in skills.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
from dataclasses import dataclass, field, replace
|
|
24
|
+
import importlib
|
|
25
|
+
import sys
|
|
26
|
+
from pathlib import Path
|
|
27
|
+
import tomllib
|
|
28
|
+
|
|
29
|
+
from harness.embodiments import KINDS
|
|
30
|
+
from harness.paths import ROOT, roots
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
SKILLS_ROOT = ROOT / "skills"
|
|
34
|
+
# Why a package's skill was left out: {folder: reason}.
|
|
35
|
+
USER_PROBLEMS: dict[str, str] = {}
|
|
36
|
+
# Layers of the interface ladder (R0-R4); every other skill belongs to "base".
|
|
37
|
+
LAYERS = ("learned", "reactive", "handlers")
|
|
38
|
+
# Which layers an agent has when its configuration does not say: learned off, reactive
|
|
39
|
+
# and handlers on.
|
|
40
|
+
LAYER_DEFAULTS = {"learned": False, "reactive": True, "handlers": True}
|
|
41
|
+
# Service kinds a skill can need (services/<name>/service.toml `kind`).
|
|
42
|
+
SERVICE_KINDS = ("segmenter", "vision", "pointer", "vlm", "verifier", "policy", "world_model", "mcp")
|
|
43
|
+
# What a game's agent knows of it (game.knowledge): "learned" (a game's default), only what
|
|
44
|
+
# the agent learned itself (runtime/learning/learner.py), no skill written for the game by hand
|
|
45
|
+
# loaded; "handwritten", those skills (a reference baseline's) may load.
|
|
46
|
+
KNOWLEDGE = ("learned", "handwritten")
|
|
47
|
+
# The keys of skills/<name>/skill.toml.
|
|
48
|
+
SKILL_KEYS = {
|
|
49
|
+
"name": "the skill's name, the same as its directory",
|
|
50
|
+
"summary": "one line: what the skill gives programs",
|
|
51
|
+
"layer": "base, or the interface layer that turns it on: learned, reactive or handlers",
|
|
52
|
+
"mixin": "the class with its methods, as \"module:Class\" (e.g. \"skills.motion:Motion\")",
|
|
53
|
+
"exports": "the names programs see: the mixin's methods, or names its exports(session) returns",
|
|
54
|
+
"interface": "per-embodiment overrides for summary, mixin and exports",
|
|
55
|
+
"required": "never dropped: the session cannot run without it (core)",
|
|
56
|
+
"needs": "service kinds that must all be available",
|
|
57
|
+
"needs_any": "service kinds of which at least one must be available",
|
|
58
|
+
"requires": "skills whose API this one's results or documentation refer to; dropped with them",
|
|
59
|
+
"conflicts": "skills it cannot be enabled with: they export some of the same names",
|
|
60
|
+
"optional": "not among the skills of its layer: only a configuration that enables it by name has it",
|
|
61
|
+
"order": "position in the session's method resolution and in the prompt (lower first)",
|
|
62
|
+
"embodiments": f"the embodiment kinds it runs on, among {', '.join(KINDS)} or [\"*\"] for all installed kinds (default [\"robot\"])",
|
|
63
|
+
"requirements": "a skill a user installs: pip requirements, installed into its own .deps folder",
|
|
64
|
+
"knowledge": "\"handwritten\": a game's knowledge written by hand, left out (not even imported) when the "
|
|
65
|
+
"agent learns the game itself (game.knowledge = \"learned\")",
|
|
66
|
+
"probe": "a table: the skill is its body's probe, which a run that learns its environment turns on "
|
|
67
|
+
"(runtime/learning/active.py); it exports probe and probe_summary, and its keys say that run's lines for this "
|
|
68
|
+
"body: try (what probe() measures), skills (the basic skills to write) and drills (how a drill's "
|
|
69
|
+
"result is checked)",
|
|
70
|
+
}
|
|
71
|
+
# The names a body's probe exports, and the keys of its [probe] table (all but try optional).
|
|
72
|
+
PROBE_EXPORTS = ("probe", "probe_summary")
|
|
73
|
+
PROBE_KEYS = ("try", "skills", "drills")
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@dataclass(frozen=True)
|
|
77
|
+
class Skill:
|
|
78
|
+
"""A skill as its skill.toml declares it (SKILL_KEYS); `path` is its directory."""
|
|
79
|
+
|
|
80
|
+
name: str
|
|
81
|
+
summary: str
|
|
82
|
+
layer: str
|
|
83
|
+
mixin: str
|
|
84
|
+
exports: tuple[str, ...]
|
|
85
|
+
# Never dropped: the session cannot run without it.
|
|
86
|
+
required: bool = False
|
|
87
|
+
# Every service kind here must be available, and at least one of needs_any.
|
|
88
|
+
needs: tuple[str, ...] = ()
|
|
89
|
+
needs_any: tuple[str, ...] = ()
|
|
90
|
+
# Skills whose API this one's documentation and results refer to.
|
|
91
|
+
requires: tuple[str, ...] = ()
|
|
92
|
+
# Skills that export some of the same names; never enabled together.
|
|
93
|
+
conflicts: tuple[str, ...] = ()
|
|
94
|
+
# Only when a configuration names it (its layer alone does not bring it).
|
|
95
|
+
optional: bool = False
|
|
96
|
+
order: int = 100
|
|
97
|
+
# The embodiment kinds it runs on (embodiments.KINDS).
|
|
98
|
+
embodiments: tuple[str, ...] = ("robot",)
|
|
99
|
+
# "handwritten": a game's knowledge written by hand (KNOWLEDGE); "" otherwise.
|
|
100
|
+
knowledge: str = ""
|
|
101
|
+
# The body's probe: its [probe] table as (key, text) pairs; empty for any other skill.
|
|
102
|
+
probe: tuple[tuple[str, str], ...] = ()
|
|
103
|
+
path: Path = field(default=None, compare=False)
|
|
104
|
+
interface: dict = field(default_factory=dict, compare=False, hash=False)
|
|
105
|
+
|
|
106
|
+
def for_embodiment(self, embodiment: str | None) -> "Skill":
|
|
107
|
+
given = self.interface.get(embodiment)
|
|
108
|
+
return replace(self, **given) if given else self
|
|
109
|
+
|
|
110
|
+
@property
|
|
111
|
+
def public(self) -> tuple[str, ...]:
|
|
112
|
+
"""The exports without a leading underscore: the API programs are told about (the
|
|
113
|
+
conversation's hook `__wrap_up__` is left out)."""
|
|
114
|
+
return tuple(name for name in self.exports if not name.startswith("_"))
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def _skill(path: Path) -> Skill:
|
|
118
|
+
with path.open("rb") as handle:
|
|
119
|
+
data = tomllib.load(handle)
|
|
120
|
+
unknown = set(data) - set(SKILL_KEYS)
|
|
121
|
+
if unknown:
|
|
122
|
+
raise ValueError(f"{path}: unknown keys {sorted(unknown)}")
|
|
123
|
+
if data.get("name") != path.parent.name:
|
|
124
|
+
raise ValueError(f"{path}: name must be the directory name {path.parent.name!r}")
|
|
125
|
+
layer = data.get("layer", "base")
|
|
126
|
+
if layer not in ("base", *LAYERS):
|
|
127
|
+
raise ValueError(f"{path}: layer must be base or one of {LAYERS}")
|
|
128
|
+
for key in ("needs", "needs_any"):
|
|
129
|
+
bad = set(data.get(key, ())) - set(SERVICE_KINDS)
|
|
130
|
+
if bad:
|
|
131
|
+
raise ValueError(f"{path}: {key} names unknown service kinds {sorted(bad)}")
|
|
132
|
+
embodiments = tuple(data.get("embodiments", ("robot",)))
|
|
133
|
+
universal = embodiments == ("*",)
|
|
134
|
+
if universal:
|
|
135
|
+
embodiments = tuple(KINDS)
|
|
136
|
+
# Kinds by name: a kind a package registers may not be installed here (a built-in skill
|
|
137
|
+
# for games without the game package), and the skill is then for the kinds there are.
|
|
138
|
+
if not embodiments or not all(isinstance(kind, str) and kind.isidentifier() for kind in embodiments):
|
|
139
|
+
raise ValueError(f"{path}: embodiments names embodiment kinds (such as {', '.join(sorted(KINDS))})")
|
|
140
|
+
if data.get("knowledge", "") not in ("", "handwritten"):
|
|
141
|
+
raise ValueError(f"{path}: knowledge is \"handwritten\" or absent")
|
|
142
|
+
interface = data.get("interface", {})
|
|
143
|
+
if not isinstance(interface, dict):
|
|
144
|
+
raise ValueError(f"{path}: interface must be a table")
|
|
145
|
+
for kind, variant in interface.items():
|
|
146
|
+
if (not kind.isidentifier() or (not universal and kind not in embodiments) or not isinstance(variant, dict)
|
|
147
|
+
or set(variant) != {"summary", "mixin", "exports"}
|
|
148
|
+
or not all(isinstance(variant[key], str) for key in ("summary", "mixin"))
|
|
149
|
+
or not isinstance(variant["exports"], list)
|
|
150
|
+
or any(name not in data["exports"] for name in variant["exports"])):
|
|
151
|
+
raise ValueError(f"{path}: an interface must name an embodiment and declare summary, mixin and "
|
|
152
|
+
"a subset of exports")
|
|
153
|
+
variant["exports"] = tuple(variant["exports"])
|
|
154
|
+
probe = data.get("probe")
|
|
155
|
+
if probe is not None:
|
|
156
|
+
if (not isinstance(probe, dict) or "try" not in probe or set(probe) - set(PROBE_KEYS)
|
|
157
|
+
or not all(isinstance(text, str) and text.strip() for text in probe.values())):
|
|
158
|
+
raise ValueError(f"{path}: probe is a table of texts: try, and optionally skills and drills")
|
|
159
|
+
missing = set(PROBE_EXPORTS) - set(data["exports"])
|
|
160
|
+
if missing:
|
|
161
|
+
raise ValueError(f"{path}: a body's probe exports {list(PROBE_EXPORTS)}; {sorted(missing)} missing")
|
|
162
|
+
return Skill(name=data["name"], summary=data.get("summary", ""), layer=layer, mixin=data["mixin"],
|
|
163
|
+
exports=tuple(data["exports"]), required=bool(data.get("required", False)),
|
|
164
|
+
needs=tuple(data.get("needs", ())), needs_any=tuple(data.get("needs_any", ())),
|
|
165
|
+
requires=tuple(data.get("requires", ())), conflicts=tuple(data.get("conflicts", ())),
|
|
166
|
+
optional=bool(data.get("optional", False)), order=int(data.get("order", 100)),
|
|
167
|
+
embodiments=embodiments, knowledge=data.get("knowledge", ""),
|
|
168
|
+
probe=tuple((key, probe[key].strip()) for key in PROBE_KEYS if key in probe) if probe else (),
|
|
169
|
+
path=path.parent, interface=interface)
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
_CACHE: dict[tuple, dict[str, Skill]] = {}
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def load_skills(root: Path = SKILLS_ROOT, user: bool = True) -> dict[str, Skill]:
|
|
176
|
+
"""Every skill under `root`, in prompt order; for the built-in skills, also the
|
|
177
|
+
packages' (each one's skills/ folder, paths.roots), unless `user` is false."""
|
|
178
|
+
root = Path(root).resolve()
|
|
179
|
+
folders = (base / "skills" for base in roots()[1:]) if user and root == SKILLS_ROOT.resolve() else ()
|
|
180
|
+
extra = tuple(folder.resolve() for folder in folders if folder.is_dir())
|
|
181
|
+
key = (root, extra, tuple(KINDS))
|
|
182
|
+
if key not in _CACHE:
|
|
183
|
+
built_in = _load_root(root)
|
|
184
|
+
_CACHE[key] = _with_user_skills(built_in, extra) if extra else built_in
|
|
185
|
+
return _CACHE[key]
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def _with_user_skills(built_in: dict, folders) -> dict:
|
|
189
|
+
"""The built-in skills and the packages' that check:
|
|
190
|
+
a valid skill.toml, a name and exports of its own (beside the skills it may be enabled
|
|
191
|
+
with), and the skills it requires or conflicts with among them all; one that does not
|
|
192
|
+
is left out with the reason in USER_PROBLEMS, and so are the skills that require it."""
|
|
193
|
+
candidates = {}
|
|
194
|
+
for folder in folders:
|
|
195
|
+
for path in sorted(Path(folder).glob("*/skill.toml")):
|
|
196
|
+
try:
|
|
197
|
+
skill = _skill(path)
|
|
198
|
+
if skill.name in built_in or skill.name in candidates:
|
|
199
|
+
raise ValueError(f"a skill named {skill.name} is there already")
|
|
200
|
+
except (ValueError, KeyError, OSError, tomllib.TOMLDecodeError) as error:
|
|
201
|
+
USER_PROBLEMS[str(path.parent)] = str(error)
|
|
202
|
+
continue
|
|
203
|
+
candidates[skill.name] = skill
|
|
204
|
+
changed = True
|
|
205
|
+
while changed:
|
|
206
|
+
changed = False
|
|
207
|
+
for skill in list(candidates.values()):
|
|
208
|
+
others = {**built_in, **{name: other for name, other in candidates.items() if name != skill.name}}
|
|
209
|
+
clash = sorted({name for other in others.values() for name in _shared_exports(skill, other)})
|
|
210
|
+
missing = (set(skill.requires) | set(skill.conflicts)) - set(others) - {skill.name}
|
|
211
|
+
problem = f"exports {clash}, which other skills export" if clash else f"names unknown skills {sorted(missing)}" if missing else None
|
|
212
|
+
if problem:
|
|
213
|
+
USER_PROBLEMS[str(skill.path)] = problem
|
|
214
|
+
del candidates[skill.name]
|
|
215
|
+
changed = True
|
|
216
|
+
for skill in candidates.values():
|
|
217
|
+
USER_PROBLEMS.pop(str(skill.path), None)
|
|
218
|
+
skills = {**built_in, **candidates}
|
|
219
|
+
return {skill.name: skill for skill in sorted(skills.values(), key=lambda s: (s.order, s.name))}
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def _shared_exports(a: Skill, b: Skill) -> set[str]:
|
|
223
|
+
if b.name in a.conflicts or a.name in b.conflicts:
|
|
224
|
+
return set()
|
|
225
|
+
return {name for kind in set(a.embodiments) & set(b.embodiments)
|
|
226
|
+
for name in set(a.for_embodiment(kind).exports) & set(b.for_embodiment(kind).exports)}
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def _load_root(root: Path) -> dict[str, Skill]:
|
|
230
|
+
"""The skills under one root, checked strictly (names, exports, references)."""
|
|
231
|
+
by_name = {path.parent.name: _skill(path) for path in sorted(root.glob("*/skill.toml"))}
|
|
232
|
+
if not by_name:
|
|
233
|
+
raise ValueError(f"No skills under {root}")
|
|
234
|
+
|
|
235
|
+
owners = {}
|
|
236
|
+
for skill in by_name.values():
|
|
237
|
+
for name in skill.exports:
|
|
238
|
+
owners.setdefault(name, []).append(skill)
|
|
239
|
+
duplicates = sorted(name for name, of in owners.items()
|
|
240
|
+
if any(name in _shared_exports(a, b)
|
|
241
|
+
for i, a in enumerate(of) for b in of[i + 1:]))
|
|
242
|
+
if duplicates:
|
|
243
|
+
raise ValueError(f"Names exported by more than one skill that may be enabled together: {duplicates}")
|
|
244
|
+
for skill in by_name.values():
|
|
245
|
+
# Optional built-ins may declare conflicts with skills supplied by packages.
|
|
246
|
+
references = skill.requires if skill.optional and root == SKILLS_ROOT.resolve() else (*skill.requires, *skill.conflicts)
|
|
247
|
+
missing = set(references) - by_name.keys()
|
|
248
|
+
if missing:
|
|
249
|
+
raise ValueError(f"Skill {skill.name} names unknown skills {sorted(missing)}")
|
|
250
|
+
return dict(sorted(by_name.items(), key=lambda pair: (pair[1].order, pair[0])))
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def skills_for_layers(layers: dict | None, root: Path = SKILLS_ROOT, *, embodiment: str = "robot") -> list[str]:
|
|
254
|
+
"""The skills of the interface layers given as switches ({"learned": bool, ...} over
|
|
255
|
+
LAYER_DEFAULTS) for an embodiment kind, without the optional ones."""
|
|
256
|
+
layers = {**LAYER_DEFAULTS, **(layers or {})}
|
|
257
|
+
unknown = set(layers) - set(LAYERS)
|
|
258
|
+
if unknown:
|
|
259
|
+
raise ValueError(f"Unknown runtime layers: {sorted(unknown)}")
|
|
260
|
+
return [name for name, skill in load_skills(root).items()
|
|
261
|
+
if embodiment in skill.embodiments and not skill.optional
|
|
262
|
+
and (skill.layer == "base" or layers[skill.layer])]
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def probes(root: Path = SKILLS_ROOT) -> list[str]:
|
|
266
|
+
"""The skills that probe a body (a [probe] table), one an embodiment kind or more."""
|
|
267
|
+
return [name for name, skill in load_skills(root).items() if skill.probe]
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
def available_services(options: dict) -> set[str]:
|
|
271
|
+
"""Service kinds a kernel's options provide: the segmenter, vision, pointer, VLM and
|
|
272
|
+
verifier configs, and at least one policy, world model or MCP server."""
|
|
273
|
+
kinds = {kind for kind in ("segmenter", "vision", "pointer", "vlm", "verifier") if options.get(kind)}
|
|
274
|
+
if options.get("policies"):
|
|
275
|
+
kinds.add("policy")
|
|
276
|
+
if options.get("world_models"):
|
|
277
|
+
kinds.add("world_model")
|
|
278
|
+
if options.get("mcp"):
|
|
279
|
+
kinds.add("mcp")
|
|
280
|
+
return kinds
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
@dataclass
|
|
284
|
+
class Resolution:
|
|
285
|
+
"""The outcome of `resolve`: the enabled skills in prompt order, and each dropped
|
|
286
|
+
skill with the reason."""
|
|
287
|
+
|
|
288
|
+
enabled: list[str]
|
|
289
|
+
dropped: dict[str, str]
|
|
290
|
+
|
|
291
|
+
def to_dict(self) -> dict:
|
|
292
|
+
"""The resolution as a plain dict."""
|
|
293
|
+
return {"enabled": list(self.enabled), "dropped": dict(self.dropped)}
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def resolve(requested, services: set[str], *, strict: bool = False, root: Path = SKILLS_ROOT,
|
|
297
|
+
embodiment: str = "robot") -> Resolution:
|
|
298
|
+
"""The requested skills that can run on this embodiment kind with these services. A
|
|
299
|
+
skill is dropped when it does not run on the embodiment, a service it needs is missing
|
|
300
|
+
or a skill it requires is not enabled (repeated until nothing changes); the
|
|
301
|
+
embodiment's required skills are always enabled. strict: dropping is an error
|
|
302
|
+
(evaluation runs must not run a smaller system than the one they name)."""
|
|
303
|
+
if embodiment not in KINDS:
|
|
304
|
+
raise ValueError(f"Unknown embodiment kind {embodiment!r}; kinds are {sorted(KINDS)}")
|
|
305
|
+
known = load_skills(root)
|
|
306
|
+
requested = list(dict.fromkeys(requested))
|
|
307
|
+
unknown = [name for name in requested if name not in known]
|
|
308
|
+
if unknown:
|
|
309
|
+
raise ValueError(f"Unknown skills {unknown}; known: {sorted(known)}")
|
|
310
|
+
dropped = {name: f"does not run on the {embodiment} embodiment" for name in requested
|
|
311
|
+
if embodiment not in known[name].embodiments}
|
|
312
|
+
wanted = ({name for name in requested if name not in dropped}
|
|
313
|
+
| {name for name, skill in known.items() if skill.required and embodiment in skill.embodiments})
|
|
314
|
+
clashes = sorted({tuple(sorted((name, other))) for name in wanted for other in known[name].conflicts
|
|
315
|
+
if other in wanted})
|
|
316
|
+
if clashes:
|
|
317
|
+
raise ValueError("Skills that cannot be enabled together (they export the same names): "
|
|
318
|
+
+ "; ".join(f"{a} and {b}" for a, b in clashes))
|
|
319
|
+
changed = True
|
|
320
|
+
while changed:
|
|
321
|
+
changed = False
|
|
322
|
+
for name in [n for n in known if n in wanted]:
|
|
323
|
+
skill = known[name]
|
|
324
|
+
reason = None
|
|
325
|
+
missing = [kind for kind in skill.needs if kind not in services]
|
|
326
|
+
if missing:
|
|
327
|
+
reason = f"no {' or '.join(missing)} service"
|
|
328
|
+
elif skill.needs_any and not set(skill.needs_any) & services:
|
|
329
|
+
reason = f"needs one of the services {', '.join(skill.needs_any)}"
|
|
330
|
+
else:
|
|
331
|
+
off = [other for other in skill.requires if other not in wanted]
|
|
332
|
+
if off:
|
|
333
|
+
reason = f"requires the skills {', '.join(off)}"
|
|
334
|
+
if reason is not None:
|
|
335
|
+
if skill.required:
|
|
336
|
+
raise ValueError(f"Required skill {name} cannot run: {reason}")
|
|
337
|
+
wanted.discard(name)
|
|
338
|
+
dropped[name] = reason
|
|
339
|
+
changed = True
|
|
340
|
+
if strict and dropped:
|
|
341
|
+
raise ValueError("Skills the system names cannot run here: "
|
|
342
|
+
+ "; ".join(f"{name} ({reason})" for name, reason in dropped.items()))
|
|
343
|
+
return Resolution([name for name in known if name in wanted], dropped)
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
def _import(spec: str):
|
|
347
|
+
module, _, attribute = spec.partition(":")
|
|
348
|
+
value = importlib.import_module(module)
|
|
349
|
+
return getattr(value, attribute) if attribute else value
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
# Skills whose module this interpreter cannot import (a kernel in an environment without
|
|
353
|
+
# their dependencies): {name: why}. They are left out of the session, never fatal.
|
|
354
|
+
UNAVAILABLE: dict[str, str] = {}
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
def _mixin(skill: Skill):
|
|
358
|
+
try:
|
|
359
|
+
return _import(skill.mixin)
|
|
360
|
+
except ImportError as error:
|
|
361
|
+
UNAVAILABLE[skill.name] = f"{type(error).__name__}: {error}"
|
|
362
|
+
print(f"skill {skill.name} left out: it cannot be imported here ({UNAVAILABLE[skill.name]})",
|
|
363
|
+
file=sys.stderr, flush=True)
|
|
364
|
+
return None
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
def _unavailable(skill: str, export: str, why: str):
|
|
368
|
+
def call(*args, **kwargs):
|
|
369
|
+
raise RuntimeError(f"{export}() of skill {skill} cannot run in this kernel: {why}")
|
|
370
|
+
|
|
371
|
+
call.__name__ = export
|
|
372
|
+
return call
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
def mixins(root: Path = SKILLS_ROOT, *, embodiment: str = "robot", knowledge: str = "handwritten") -> list[type]:
|
|
376
|
+
"""The mixin class of every skill for an embodiment kind, imported, in the skills'
|
|
377
|
+
order (the session's method resolution order); with knowledge "learned", none of the
|
|
378
|
+
handwritten ones (their modules are not imported). A skill whose module cannot be
|
|
379
|
+
imported in this interpreter is left out (UNAVAILABLE says why)."""
|
|
380
|
+
if knowledge not in KNOWLEDGE:
|
|
381
|
+
raise ValueError(f"knowledge is one of {list(KNOWLEDGE)}, not {knowledge!r}")
|
|
382
|
+
found = [_mixin(skill.for_embodiment(embodiment)) for skill in load_skills(root).values() if embodiment in skill.embodiments
|
|
383
|
+
and not (knowledge == "learned" and skill.knowledge == "handwritten")]
|
|
384
|
+
return [mixin for mixin in found if mixin is not None]
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
def handwritten(root: Path = SKILLS_ROOT) -> list[str]:
|
|
388
|
+
"""The skills that are a game's knowledge written by hand."""
|
|
389
|
+
return [name for name, skill in load_skills(root).items() if skill.knowledge == "handwritten"]
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
def namespace(session, names, root: Path = SKILLS_ROOT) -> dict:
|
|
393
|
+
"""The kernel namespace of a session with the skills `names` enabled: each skill's
|
|
394
|
+
exports(session) when its module defines one, else the session attributes it
|
|
395
|
+
exports."""
|
|
396
|
+
known = load_skills(root)
|
|
397
|
+
result = {}
|
|
398
|
+
for name in names:
|
|
399
|
+
skill = known[name].for_embodiment(getattr(session, "embodiment", None))
|
|
400
|
+
if name in UNAVAILABLE:
|
|
401
|
+
# Enabled, but not importable here: each call says why instead of a NameError.
|
|
402
|
+
result.update({export: _unavailable(name, export, UNAVAILABLE[name]) for export in skill.exports})
|
|
403
|
+
continue
|
|
404
|
+
module = _import(skill.mixin.partition(":")[0])
|
|
405
|
+
values = module.exports(session) if hasattr(module, "exports") else {
|
|
406
|
+
export: getattr(session, export) for export in skill.exports}
|
|
407
|
+
if set(values) != set(skill.exports):
|
|
408
|
+
raise ValueError(f"Skill {name}: exports() returned {sorted(values)}, skill.toml lists "
|
|
409
|
+
f"{sorted(skill.exports)}")
|
|
410
|
+
result.update(values)
|
|
411
|
+
return result
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
def reporters(names, root: Path = SKILLS_ROOT) -> list:
|
|
415
|
+
"""The turn reports of the skills `names`, in skill order: each skill module's
|
|
416
|
+
turn_report(session) -> {"text", "images"} or None, which the session calls after
|
|
417
|
+
every program (EpisodeCore.drain)."""
|
|
418
|
+
known = load_skills(root)
|
|
419
|
+
found = []
|
|
420
|
+
for name in names:
|
|
421
|
+
if name in UNAVAILABLE:
|
|
422
|
+
continue
|
|
423
|
+
module = _import(known[name].mixin.partition(":")[0])
|
|
424
|
+
if hasattr(module, "turn_report"):
|
|
425
|
+
found.append(module.turn_report)
|
|
426
|
+
return found
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
def exported_names(root: Path = SKILLS_ROOT) -> dict[str, tuple[str, ...]]:
|
|
430
|
+
"""Every exported name and the skills that export it (more than one only for
|
|
431
|
+
skills that conflict)."""
|
|
432
|
+
names = {}
|
|
433
|
+
for skill in load_skills(root).values():
|
|
434
|
+
for export in skill.exports:
|
|
435
|
+
names[export] = (*names.get(export, ()), skill.name)
|
|
436
|
+
return names
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Explicit task libraries, verification and activation."""
|