@lmmslab/harness 0.81.0 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lmmslab/harness",
3
- "version": "0.81.0",
3
+ "version": "0.81.1",
4
4
  "description": "Automatic Control for anything that acts",
5
5
  "license": "MIT",
6
6
  "homepage": "https://harness.lmms-lab.com",
@@ -2,7 +2,7 @@
2
2
 
3
3
  # The one version: the core's. A lock records it with the versions of the packages that
4
4
  # ran and the hash of the whole lock (the agent's identity, config/agent.py).
5
- __version__ = "0.81.0"
5
+ __version__ = "0.81.1"
6
6
 
7
7
  # A checkout's packages import beside the harness (paths.py).
8
8
  from . import paths as _paths # noqa: E402,F401
@@ -24,7 +24,7 @@ import tomllib
24
24
  from .. import providers
25
25
  from ..core import episodes as runs
26
26
  from ..core.remote import RemoteEnvironment
27
- from ..packages import Packages, RegistryError, activate, addons, describe
27
+ from ..packages import MissingPackage, Packages, RegistryError, activate, addons, describe
28
28
  from ..paths import ROOT, data
29
29
  from harness.runtime.task.delegation import Agents, Place
30
30
  from harness.runtime.task.environments import Place as Attaching
@@ -123,6 +123,8 @@ class TaskHost:
123
123
  with a screen carries a `note` when the model (`model_entry`, default the chosen
124
124
  one) reads no images: the user is told before they choose."""
125
125
  options = self.workspaces.environments()
126
+ have = {row["value"] for row in options}
127
+ options += [row for row in self.installable_environments() if row["value"] not in have]
126
128
  note = self.reads_no_images(model_entry)
127
129
  if note:
128
130
  options = [{**row, "note": note} if row.get("views") else row for row in options]
@@ -134,6 +136,43 @@ class TaskHost:
134
136
  "folder": self.settings.remembered("session", "last_folder") or None,
135
137
  "setting": self.settings.get()["session"]["environment"]}
136
138
 
139
+ def installable_environments(self) -> list[dict]:
140
+ """What a new installation can choose before any environment package is installed:
141
+ the environments of the registry's packages, as rows of the choice ({"value",
142
+ "label", "about", "package"}); choosing one installs its package as
143
+ packages.auto_install says. None when that is off, when the registry cannot be read
144
+ (asked again after ten minutes), or once a package gives an environment: from then
145
+ on the choice lists what is installed, and naming another one still installs it."""
146
+ if self.packages.auto_install() == "off" or self.workspaces.providers():
147
+ return []
148
+ if time.monotonic() < getattr(self, "_registry_unread_until", 0):
149
+ return []
150
+ try:
151
+ rows = self.packages.registry.search()
152
+ except (RegistryError, OSError, ValueError):
153
+ self._registry_unread_until = time.monotonic() + 600
154
+ return []
155
+ installed = {row["name"] for row in self.packages.installed()}
156
+ found = {}
157
+ for row in rows:
158
+ if row["name"] in installed:
159
+ continue
160
+ for kind in row.get("provides", {}).get("workspaces", []):
161
+ found.setdefault(kind, {"value": kind, "label": kind.replace("-", " ").capitalize(),
162
+ "about": f"{row['summary']} (installs the package {row['name']})",
163
+ "package": row["name"]})
164
+ from .workspaces import ORDER
165
+ return [found[kind] for kind in (*[k for k in ORDER if k in found], *sorted(set(found) - set(ORDER)))]
166
+
167
+ def install_environment(self, workspace: str) -> bool:
168
+ """Install the registry's package of an environment no installed package gives
169
+ (packages.auto_install); False when there is none or it is not to be installed."""
170
+ try:
171
+ self.packages.ensure("workspaces", workspace, log=lambda message: None)
172
+ except (MissingPackage, RegistryError, OSError):
173
+ return False
174
+ return workspace in self.workspaces.kinds()
175
+
137
176
  def reads_no_images(self, model_entry: str | None = None) -> str:
138
177
  """What to say beside an environment with a screen when the model reads no images
139
178
  (its entry of the model list); empty when it reads them."""
@@ -162,7 +201,11 @@ class TaskHost:
162
201
  offered = self.environments(model_entry)
163
202
  by = {row["value"]: row for row in offered["options"]}
164
203
  if workspace in (None, "auto") and folder is not None:
165
- workspace = self.workspaces.kind(None, None, binding={"folder": folder})
204
+ if any(provider.accepts({"folder": folder}) for provider in self.workspaces.providers()):
205
+ workspace = self.workspaces.kind(None, None, binding={"folder": folder})
206
+ else:
207
+ # No installed package takes a folder: a folder alone names a project.
208
+ workspace = "project"
166
209
  if workspace in (None, "auto"):
167
210
  setting = "last" if last else offered["setting"]
168
211
  if setting == "last" and offered["selected"]:
@@ -185,8 +228,13 @@ class TaskHost:
185
228
  f"one of {names}; or set session.environment to last or to one of them"})
186
229
  if by.get(workspace, {}).get("folder") and folder is None:
187
230
  folder = offered["folder"]
188
- if workspace not in by:
189
- raise ValueError(f"no installed package provides workspace {workspace!r}; there are {', '.join(by)}")
231
+ # An environment of a package that is not installed yet: installed the first time.
232
+ if (workspace not in by or by[workspace].get("package")) and self.install_environment(workspace):
233
+ offered = self.environments(model_entry)
234
+ by = {row["value"]: row for row in offered["options"]}
235
+ if workspace not in by or by[workspace].get("package"):
236
+ raise ValueError(f"no installed package provides workspace {workspace!r}; there are "
237
+ f"{', '.join(kind for kind, row in by.items() if not row.get('package'))}")
190
238
  kind = self.workspaces.kind(workspace)
191
239
  if by[workspace].get("folder") and not folder:
192
240
  raise ValueError(f"a {kind} conversation works in one folder: name it with --folder PATH (folder=PATH)")
@@ -13,6 +13,7 @@ A package is a folder with package.toml at its root:
13
13
  [provides]
14
14
  commands = { audit-run = "benches.minecraft.audit:main" }
15
15
  host = "harness_computer.host" # what it adds to the session host (harness/extensions.py)
16
+ workspaces = ["desktop", "browser"] # the --workspace values that host gives
16
17
 
17
18
  Everything else it provides is found in its folders and files (CONVENTION): skills/,
18
19
  embodiments/, benches/, services/, prompts/, configs/profiles/, configs/experiments/, agent-skills/,
@@ -65,6 +66,9 @@ PROVIDES = {
65
66
  "{ name = \"module:Class\" } (runtime/task/delegation.py)",
66
67
  "host": "what it adds to the session host and its frontends, declared only: a module of the package "
67
68
  "(harness/extensions.py)",
69
+ "workspaces": "where a conversation can work (the values of --workspace) that its host gives, declared "
70
+ "only: [\"project\"]; the registry's index carries them, so the harness finds the package "
71
+ "of an environment it lacks",
68
72
  }
69
73
 
70
74
 
@@ -176,7 +180,7 @@ def load(folder) -> Package:
176
180
  raise ValueError(f"{path}: unknown [provides] keys {sorted(unknown)}")
177
181
  found = discover(folder)
178
182
  for key, names in declared.items():
179
- if key in ("commands", "host", "agents"):
183
+ if key in ("commands", "host", "agents", "workspaces"):
180
184
  continue
181
185
  missing = sorted(set(names) - set(found[key]))
182
186
  if missing:
@@ -197,6 +201,11 @@ def load(folder) -> Package:
197
201
  if host and not (folder / host.split(".")[0]).is_dir():
198
202
  raise ValueError(f"{path}: host is a module of the package (e.g. harness_{name.replace('-', '_')}.host), "
199
203
  f"not {host!r}")
204
+ workspaces = declared.get("workspaces", [])
205
+ if not isinstance(workspaces, list) or not all(isinstance(kind, str) and NAME.match(kind) for kind in workspaces):
206
+ raise ValueError(f"{path}: workspaces is a list of names (lowercase letters, digits and hyphens)")
207
+ if workspaces and not host:
208
+ raise ValueError(f"{path}: workspaces are what the package's host gives: declare host too")
200
209
  provides = {key: tuple(found[key]) for key in found if found[key]}
201
210
  if commands:
202
211
  provides["commands"] = tuple(sorted(commands))
@@ -204,6 +213,8 @@ def load(folder) -> Package:
204
213
  provides["agents"] = tuple(sorted(agents))
205
214
  if host:
206
215
  provides["host"] = (host,)
216
+ if workspaces:
217
+ provides["workspaces"] = tuple(sorted(workspaces))
207
218
  return Package(name=name, version=version, summary=str(meta.get("summary", "")), harness=harness,
208
219
  depends=depends, platforms=platforms, homepage=str(meta.get("homepage", "")),
209
220
  license=str(meta.get("license", "")), provides=provides, commands=commands,