@lmmslab/harness 0.81.0 → 0.82.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.
Files changed (79) hide show
  1. package/README.md +24 -35
  2. package/package.json +2 -2
  3. package/python/harness/README.md +3 -3
  4. package/python/harness/__init__.py +1 -1
  5. package/python/harness/builtin/configs/assistant.toml +0 -1
  6. package/python/harness/builtin/configs/default.toml +1 -1
  7. package/python/harness/builtin/prompts/conversation/core.md +2 -2
  8. package/python/harness/builtin/prompts/core/core.md +177 -41
  9. package/python/harness/builtin/prompts/core/pack.toml +2 -2
  10. package/python/harness/builtin/prompts/reflect/core.md +1 -1
  11. package/python/harness/builtin/prompts/shared/learning-goal.md +5 -29
  12. package/python/harness/builtin/prompts/shared/learning.md +8 -10
  13. package/python/harness/builtin/prompts/shared/web.md +11 -0
  14. package/python/harness/builtin/skills/agents/__init__.py +24 -22
  15. package/python/harness/builtin/skills/entries/__init__.py +43 -28
  16. package/python/harness/builtin/skills/entries/skill.toml +2 -3
  17. package/python/harness/builtin/skills/environments/__init__.py +2 -9
  18. package/python/harness/builtin/skills/mcp/__init__.py +2 -3
  19. package/python/harness/builtin/skills/memory/__init__.py +2 -5
  20. package/python/harness/builtin/skills/web/__init__.py +92 -0
  21. package/python/harness/builtin/skills/web/skill.toml +9 -0
  22. package/python/harness/cli.py +84 -16
  23. package/python/harness/config/agent.py +33 -9
  24. package/python/harness/core/episodes.py +5 -4
  25. package/python/harness/core/lanes.py +3 -0
  26. package/python/harness/core/memory.py +5 -1
  27. package/python/harness/core/remote.py +4 -3
  28. package/python/harness/core/worker.py +58 -3
  29. package/python/harness/extensions.py +23 -2
  30. package/python/harness/host/__init__.py +43 -1
  31. package/python/harness/host/client.py +36 -6
  32. package/python/harness/host/http.py +19 -0
  33. package/python/harness/host/server.py +17 -3
  34. package/python/harness/host/sessions.py +3 -2
  35. package/python/harness/host/tasks.py +158 -29
  36. package/python/harness/host/workspaces.py +69 -7
  37. package/python/harness/model_list.py +1 -1
  38. package/python/harness/packages/manager.py +5 -1
  39. package/python/harness/packages/manifest.py +12 -1
  40. package/python/harness/providers.py +14 -5
  41. package/python/harness/runtime/decision/loop.py +100 -121
  42. package/python/harness/runtime/decision/messages.py +156 -48
  43. package/python/harness/runtime/decision/model.py +79 -21
  44. package/python/harness/runtime/decision/prompts.py +15 -11
  45. package/python/harness/runtime/decision/protocol.py +12 -6
  46. package/python/harness/runtime/decision/thoughts.py +10 -16
  47. package/python/harness/runtime/events.py +28 -13
  48. package/python/harness/runtime/execution/attached.py +1 -1
  49. package/python/harness/runtime/execution/control.py +17 -35
  50. package/python/harness/runtime/execution/entries.py +204 -124
  51. package/python/harness/runtime/execution/kernel.py +471 -281
  52. package/python/harness/runtime/execution/managed.py +231 -0
  53. package/python/harness/runtime/execution/noenv.py +2 -2
  54. package/python/harness/runtime/execution/results.py +2 -0
  55. package/python/harness/runtime/execution/session.py +276 -115
  56. package/python/harness/runtime/learning/active.py +36 -48
  57. package/python/harness/runtime/learning/fixtures.py +2 -2
  58. package/python/harness/runtime/learning/learner.py +75 -2
  59. package/python/harness/runtime/learning/library.py +77 -10
  60. package/python/harness/runtime/learning/views.py +12 -1
  61. package/python/harness/runtime/reactive/__init__.py +1 -1
  62. package/python/harness/runtime/reactive/rules.py +29 -394
  63. package/python/harness/runtime/reactive/tree.py +611 -0
  64. package/python/harness/runtime/safety/approval.py +8 -3
  65. package/python/harness/runtime/safety/permissions.py +242 -0
  66. package/python/harness/runtime/status.py +7 -2
  67. package/python/harness/runtime/task/delegation.py +97 -58
  68. package/python/harness/runtime/task/environments.py +3 -4
  69. package/python/harness/runtime/task/inbound.py +64 -0
  70. package/python/harness/runtime/task/run.py +1092 -726
  71. package/python/harness/runtime/tick.py +257 -91
  72. package/python/harness/sdk/__init__.py +7 -4
  73. package/python/harness/settings.py +27 -3
  74. package/python/harness/terminal.py +10 -6
  75. package/python/harness/transcript.py +18 -6
  76. package/python/harness/tui/answer.py +51 -0
  77. package/python/harness/tui/chat.py +75 -26
  78. package/python/harness/tui/views.py +1 -0
  79. package/python/harness/builtin/prompts/shared/entries.md +0 -86
@@ -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,14 @@ 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'))}"
238
+ + "".join(f"; {problem}" for problem in self.workspaces.problems.values()))
190
239
  kind = self.workspaces.kind(workspace)
191
240
  if by[workspace].get("folder") and not folder:
192
241
  raise ValueError(f"a {kind} conversation works in one folder: name it with --folder PATH (folder=PATH)")
@@ -255,7 +304,10 @@ class TaskHost:
255
304
  embodiment_config["skills"] = {**embodiment_config.get("skills", {}), "enable": skills["enable"]}
256
305
  # What waits for the user in this conversation (its lock records it; the conversation's
257
306
  # confirmation follows it, confirmation_policy).
258
- embodiment_config["runtime"] = {**embodiment_config.get("runtime", {}), "approvals": {"ask": values["approvals"]["ask"]}}
307
+ # A conversation a user starts is not isolated: its programs run on the machine as the
308
+ # user, under the user's approvals (runtime/safety/permissions.py).
309
+ embodiment_config["runtime"] = {**embodiment_config.get("runtime", {}), "isolation": False,
310
+ "approvals": {key: values["approvals"][key] for key in ("ask", "programs", "rules")}}
259
311
  # The skills the user installed: the prompt's installed section (runtime/decision/prompts.py).
260
312
  if skills["installed"]:
261
313
  embodiment_config["runtime"] = {**embodiment_config.get("runtime", {}), "installed_skills": skills["installed"]}
@@ -344,7 +396,7 @@ class TaskHost:
344
396
  enable = [*(["checklist"] if not {"checklist", "plan"} & off else []), "entries", *installed,
345
397
  *sorted(mine - set(installed)), *(["instructions"] if agent else [])]
346
398
  enable += list(self.workspaces.provider(kind).extra_skills(kind))
347
- enable.append("environments")
399
+ enable += ["environments", "web"]
348
400
  if agents is None:
349
401
  agents = values["session"]["agents"] == "on"
350
402
  if agents and values["limits"]["agent_depth"] > 0:
@@ -424,9 +476,11 @@ class TaskHost:
424
476
 
425
477
  tree = load_layered(CONVERSATION)
426
478
  limits = values["limits"]
427
- tree["budget"] = {**tree.get("budget", {}), "max_model_calls": int(limits["max_steps"]),
428
- "max_wall_seconds": int(limits["max_minutes"]) * 60,
429
- "max_cost_usd": float(limits["max_cost_usd"])}
479
+ # No cost limit: only OpenRouter reports a cost, so one would stop conversations
480
+ # on that provider alone. Calls and minutes bound every conversation.
481
+ budget = {key: value for key, value in tree.get("budget", {}).items() if key != "max_cost_usd"}
482
+ tree["budget"] = {**budget, "max_model_calls": int(limits["max_steps"]),
483
+ "max_wall_seconds": int(limits["max_minutes"]) * 60}
430
484
  # The workspace's own (a background browser's prompt).
431
485
  tree = self.workspaces.tree(tree, kind)
432
486
  # When the model thinks while the agent acts (Settings, Model).
@@ -483,8 +537,10 @@ class TaskHost:
483
537
  reasoning_effort: str | None = None, profile: str | None = None, *,
484
538
  agent: str | None = None, folder: str | None = None, isolation: str | None = None,
485
539
  frontend: str | None = None, mcp_tools=(), execution: str | None = None,
486
- budget: dict | None = None, library: dict | None = None, title: str | None = None, model_entry: str | None = None) -> str:
487
- """Start a conversation with the user's first message: its directory and record
540
+ budget: dict | None = None, library: dict | None = None, title: str | None = None, model_entry: str | None = None,
541
+ resume: dict | None = None) -> str:
542
+ """Start a conversation with the user's first message (`resume`: go on with an ended
543
+ one instead, see resume()): its directory and record
488
544
  now, its workspace (of kind `workspace`: "none" takes none; without one and without a
489
545
  `folder`, session.environment decides, environment(); installed on first use) and the
490
546
  episode on a thread of their own. `runtime`: this conversation's
@@ -512,7 +568,11 @@ class TaskHost:
512
568
  if choice is None:
513
569
  raise ValueError("the selected model is no longer enabled")
514
570
  model = choice["model"] or None
515
- if choice["provider"] not in providers.PROVIDERS:
571
+ if providers.is_agent(choice["provider"]) and agent in (None, "harness"):
572
+ # An ACP agent's entry is a model like any other: the Harness agent decides with
573
+ # it. The agent's own session in a folder is asked for by name (agent).
574
+ agent = None
575
+ elif choice["provider"] not in providers.PROVIDERS:
516
576
  if agent and agent != choice["provider"]:
517
577
  raise ValueError("the selected model uses a different agent")
518
578
  agent = choice["provider"]
@@ -525,6 +585,9 @@ class TaskHost:
525
585
  raise ValueError("this adapter does not accept execution bounds")
526
586
  if runtime or profile or confirmation or workspace not in (None, "auto"):
527
587
  raise ValueError("native workspace, isolation and approval settings apply only to the Harness agent")
588
+ if library is not None:
589
+ raise ValueError("a learning library applies only to the Harness agent: choose the agent as the "
590
+ "model (--model) instead of --agent")
528
591
  return self.start_external(server, agent, str(text or ""), files, folder, isolation,
529
592
  frontend, model, reasoning_effort or None, mcp_tools=mcp_tools)
530
593
  if isolation or mcp_tools:
@@ -536,7 +599,13 @@ class TaskHost:
536
599
  text = str(text or "").strip()
537
600
  if not text:
538
601
  raise ValueError("say what to do")
539
- if choice:
602
+ # What resume() starts the conversation with again (meta.json keeps it).
603
+ given = {"model": model, "confirmation": confirmation, "runtime": runtime, "reasoning_effort": reasoning_effort,
604
+ "profile": profile, "execution": execution, "budget": budget, "library": library,
605
+ "model_entry": model_entry}
606
+ if choice and providers.is_agent(choice["provider"]):
607
+ pass # it signs in for itself
608
+ elif choice:
540
609
  provider = providers.PROVIDERS[choice["provider"]]
541
610
  if provider.key_env:
542
611
  self.credentials.load()
@@ -590,14 +659,14 @@ class TaskHost:
590
659
  library_settings(library)
591
660
  config.runtime = {**config.runtime, "library": dict(library)}
592
661
  name = runs.new_name()
593
- directory = self.conversations_dir / name
662
+ directory = Path(resume["directory"]) if resume else self.conversations_dir / name
594
663
  if learn is not None and learn is not False:
595
664
  if library is None:
596
665
  config.runtime = {**config.runtime, "library": {"path": str(directory / "library"),
597
666
  "learn": "on", "reflect": True}}
598
667
  config = self.learning(config, learn)
599
668
  if managed:
600
- config.runtime = {**config.runtime, "library": None, "agent_skills": [], "think_while_acting": False}
669
+ config.runtime = {**config.runtime, "library": None, "agent_skills": []}
601
670
  if reasoning_effort:
602
671
  config.main = {**config.main, "reasoning_effort": reasoning_effort}
603
672
  elif reasoning_effort == "":
@@ -605,11 +674,14 @@ class TaskHost:
605
674
  options, metadata = self.workspaces.bind(kind, directory, request)
606
675
  conversation = TaskRun(config, 0, directory, interactive=True,
607
676
  confirmation=confirmation_policy(confirmation), instruction=text,
608
- agents=None if managed else self.sub_agents(server, kind, assistant=True), **self._models)
677
+ agents=None if managed else self.sub_agents(server, kind, assistant=True),
678
+ restore=resume["kept"] if resume else None, **self._models)
609
679
  from ..extensions import hosts
610
680
 
611
681
  conversation.workspace_kind = kind
612
682
  conversation.workspace_options = options
683
+ # How learned code is admitted is this computer's user's to say (learner.admission).
684
+ conversation.library_admission = self.settings.get()["learning"]["admission"]
613
685
  if not managed:
614
686
  from harness.runtime.task.environments import Environments
615
687
 
@@ -629,15 +701,21 @@ class TaskHost:
629
701
  **metadata,
630
702
  **({"model_entry": model_entry} if model_entry else {}),
631
703
  **({"learning": config.max_wall_seconds / 60} if active.is_active(config.runtime) else {}),
632
- **({"profile": profile} if profile else {})}
633
- (directory / "meta.json").write_text(json.dumps(meta, ensure_ascii=False), encoding="utf-8")
704
+ **({"profile": profile} if profile else {}),
705
+ "start": {**{key: value for key, value in given.items() if value is not None},
706
+ "workspace": kind, **({"folder": str(folder)} if folder is not None else {})}}
707
+ if resume is None:
708
+ (directory / "meta.json").write_text(json.dumps(meta, ensure_ascii=False), encoding="utf-8")
634
709
  run = directory.relative_to(server.root).as_posix()
635
710
  self._kinds[run] = kind
636
711
  # What the next conversation's choice highlights (and session.environment = last takes).
637
712
  self.settings.remember("session", "last_environment", kind)
638
713
  if metadata.get("folder"):
639
714
  self.settings.remember("session", "last_folder", metadata["folder"])
640
- if frontend is None:
715
+ if resume is not None:
716
+ # The same session, by its id: its record takes the place of the ended one.
717
+ server.conversations.reconnect(resume, conversation)
718
+ elif frontend is None:
641
719
  server.conversations[run] = conversation
642
720
  else:
643
721
  server.conversations.add(run, conversation, title=meta["title"], frontend=frontend)
@@ -700,6 +778,45 @@ class TaskHost:
700
778
  threading.Thread(target=begin, name=f"start-{name}", daemon=True).start()
701
779
  return run
702
780
 
781
+ def resume(self, server, identifier=None) -> str:
782
+ """Continue a session of the Harness agent in its own id: `identifier` (a session id,
783
+ the start of one, or a run; None: the most recent session). One that still runs is
784
+ given as it is. One that ended (its host stopped, it was closed, its workspace was
785
+ taken for another) starts again from what it kept (runtime/task/run.py saved()): the
786
+ same directory and trace, the model, workspace and options it began with, and a
787
+ new kernel; what died with the old process is a note to the model. Its run."""
788
+ from harness.runtime.task.run import saved
789
+ from .sessions import history
790
+
791
+ active = server.conversations.sessions()
792
+ index = server.conversations.index
793
+ rows = [row for row in active + (history(index, skip={row["id"] for row in active}) if index else [])
794
+ if row.get("kind", "harness") == "harness" and row.get("directory")]
795
+ if identifier is None:
796
+ found = sorted(rows, key=lambda row: row["created"] or 0)[-1:]
797
+ else:
798
+ name = str(identifier)
799
+ found = ([row for row in rows if name in (row["id"], row["run"])]
800
+ or [row for row in rows if len(name) >= 3 and row["id"].startswith(name)])
801
+ if len(found) != 1:
802
+ raise ValueError("no session to continue" if identifier is None else
803
+ f"no session {identifier} to continue (harness sessions ls --all lists them)")
804
+ row = found[0]
805
+ if row["live"]:
806
+ return row["run"]
807
+ directory = Path(row["directory"])
808
+ kept = saved(directory)
809
+ if kept is None:
810
+ raise ValueError(f"session {row['id']} kept no conversation to continue")
811
+ try:
812
+ meta = json.loads((directory / "meta.json").read_text(encoding="utf-8"))
813
+ except (OSError, ValueError):
814
+ meta = {}
815
+ # (A session from before meta.json kept how it was started: what it does say.)
816
+ given = meta.get("start") or {key: meta[key] for key in ("workspace", "folder", "profile", "model_entry",
817
+ "reasoning_effort") if meta.get(key)}
818
+ return self.start(server, meta.get("text") or row["title"], **given, resume={**row, "kept": kept})
819
+
703
820
  def start_external(self, server, agent, text, files, folder, isolation, frontend, model, effort, *,
704
821
  handoff=None, reconnect=None, observe=None, mcp_tools=()):
705
822
  from ..core import atomic_write
@@ -753,10 +870,9 @@ class TaskHost:
753
870
  return run
754
871
 
755
872
  # Records after which the user is needed in the chat: the agent waits for an approval,
756
- # or it stopped on an error. And the end of the agent's turn (an answer, a question, its
757
- # task done, the budget used up), unless the agent kept the screen (stay_on_screen).
873
+ # or it stopped on an error. And the end of the agent's turn (its result: an answer, a
874
+ # limit, an error), unless the agent kept the screen (stay_on_screen).
758
875
  NEEDS_THE_USER = ("confirmation_request", "error", "kernel_died", "external_notice", "external_question")
759
- TURN_ENDS = ("message", "finish", "budget")
760
876
 
761
877
  def _watcher(self):
762
878
  """A conversation's watcher (a subscriber of its trace): brings the app's window to
@@ -772,9 +888,7 @@ class TaskHost:
772
888
  turn["stay"] = True
773
889
  elif event == "user_message":
774
890
  turn["stay"] = False
775
- needed = event in self.NEEDS_THE_USER or (
776
- event == "state" and record.get("status") == "IDLE" and record.get("reason") in self.TURN_ENDS
777
- and not turn["stay"])
891
+ needed = event in self.NEEDS_THE_USER or (event == "turn_result" and not turn["stay"])
778
892
  if needed and self.focus_chat is not None:
779
893
  threading.Thread(target=self.focus_chat, name="show-chat", daemon=True).start()
780
894
 
@@ -793,9 +907,10 @@ class TaskHost:
793
907
  max_depth=self.settings.get()["limits"]["agent_depth"])
794
908
 
795
909
  def _evict(self, server, runs, run) -> bool:
796
- """Make room for `run`: end the conversation among `runs` that has waited longest
797
- for the user (IDLE after its turn); its workspace comes back when its episode ends.
798
- Whether one was ended (none is while all of them work)."""
910
+ """Make room for `run`: park the conversation among `runs` that has waited longest
911
+ for the user (IDLE after its turn). It ends in this process, which gives its
912
+ workspace back, and goes on in its own id with its next message (resume()).
913
+ Whether one was parked (none is while all of them work)."""
799
914
  with self._reclaiming:
800
915
  idle = []
801
916
  for other in runs:
@@ -811,8 +926,9 @@ class TaskHost:
811
926
  if not idle:
812
927
  return False
813
928
  _, other, conversation = min(idle, key=lambda item: item[0])
814
- self._note(run, "ending the conversation that waited longest, for its workspace")
929
+ self._note(run, "parking the conversation that waited longest, for its workspace")
815
930
  conversation.trace.emit("workspace_reclaimed", by=run)
931
+ conversation.parked = True
816
932
  conversation.close()
817
933
  return True
818
934
 
@@ -1095,6 +1211,19 @@ class TaskHandler(Handler):
1095
1211
  mcp_tools=body.get("mcp_tools") or (),
1096
1212
  model_entry=body.get("model_entry"), library=body.get("library"), budget=body.get("budget"))})
1097
1213
 
1214
+ def post_conversations_message(self, body):
1215
+ """A message to a conversation the host parked for its workspace continues it first."""
1216
+ run = self.server.conversations.resolve(body.get("run"))
1217
+ conversation = self.server.conversations.get(run) if run else None
1218
+ if getattr(conversation, "parked", False) and conversation.status in ("FINISHED", "ERROR"):
1219
+ self.server.app.resume(self.server, run)
1220
+ super().post_conversations_message(body)
1221
+
1222
+ def post_sessions_resume(self, body):
1223
+ run = self.server.app.resume(self.server, body.get("id") or None)
1224
+ found = self.server.conversations.session_of(run)
1225
+ self._json({"run": run, "id": found[0] if found else None})
1226
+
1098
1227
  def post_conversations_handoff(self, body):
1099
1228
  source = self.server.conversations.resolve(body.get("run"))
1100
1229
  if source is None:
@@ -1,5 +1,6 @@
1
1
  """Discover package workspace providers and route ownership; no environment implementation."""
2
2
  from pathlib import Path
3
+ import sys
3
4
  from .workers import Cancelled
4
5
 
5
6
 
@@ -78,6 +79,49 @@ class WorkspaceProvider:
78
79
  # The order environments are offered in (kinds of other packages follow).
79
80
  ORDER = ("none", "project", "browser", "apps", "desktop", "display")
80
81
 
82
+ # What every provider implements itself; WorkspaceProvider gives the rest.
83
+ REQUIRED = ("kinds", "kind", "bench", "tree", "acquire")
84
+ CONTRACT = REQUIRED + tuple(name for name, value in vars(WorkspaceProvider).items()
85
+ if callable(value) and not name.startswith("_"))
86
+
87
+
88
+ def incompatible(factory) -> str:
89
+ """Why a package's Workspaces cannot serve this harness, '' when it can: a class that
90
+ subclasses WorkspaceProvider and implements REQUIRED, or has every method of CONTRACT
91
+ (a provider written before WorkspaceProvider lacks describe, accepts, bind...)."""
92
+ if not isinstance(factory, type):
93
+ return "its Workspaces is not a class"
94
+ wanted = REQUIRED if issubclass(factory, WorkspaceProvider) else CONTRACT
95
+ missing = [name for name in dict.fromkeys(wanted) if not callable(getattr(factory, name, None))]
96
+ if not missing:
97
+ return ""
98
+ return (f"its workspace provider lacks {', '.join(missing[:3])}{', …' if len(missing) > 3 else ''} "
99
+ "(made for another harness version)")
100
+
101
+
102
+ def skipped(package, problem: str) -> str:
103
+ """The line that says a package's workspaces were left out, and how to get them."""
104
+ version = getattr(package, "version", "")
105
+ # All of them: a package that depends on it may be as old (browser on computer).
106
+ fix = ": harness install --update" if "harness version" in problem else ""
107
+ return f"{package.name} {version}".strip() + f" was skipped: {problem}{fix}"
108
+
109
+
110
+ def package_problems() -> dict:
111
+ """{package: why its workspaces are left out} for the packages this process uses, without
112
+ starting any provider: a host module that does not import (extensions.host_problems) or
113
+ a Workspaces that does not fit (incompatible). harness doctor reports them."""
114
+ from ..extensions import host_problems, hosts
115
+
116
+ loaded = hosts() # first: it finds the host modules that do not import
117
+ found = dict(host_problems())
118
+ for package, module in loaded:
119
+ factory = getattr(module, "Workspaces", None)
120
+ problem = incompatible(factory) if factory is not None else ""
121
+ if problem:
122
+ found[package.name] = skipped(package, problem)
123
+ return found
124
+
81
125
 
82
126
  class NoWorkspace(WorkspaceProvider):
83
127
  """The core's own kind, `none`: a conversation with the model and the connected tools
@@ -109,8 +153,7 @@ class NoWorkspace(WorkspaceProvider):
109
153
  agent = tree["overrides"]["agent"]
110
154
  agent["prompt"][self.KIND] = str(ROOT / "prompts" / "conversation")
111
155
  agent[self.KIND] = {"roles": ["main"], "runtime": {
112
- "contract": "native", "verifier": False, "max_history_turns": 10,
113
- "think_while_acting": "off", "bootstrap": DEFAULT_BOOTSTRAP}}
156
+ "contract": "native", "verifier": False, "bootstrap": DEFAULT_BOOTSTRAP}}
114
157
  return tree
115
158
 
116
159
  def builtin_skills(self, kind):
@@ -152,15 +195,34 @@ class Workspaces:
152
195
  self.directory, self.settings = Path(directory), settings
153
196
  self._providers = {}
154
197
  self._none = NoWorkspace()
198
+ # {package: why its workspaces are left out}: one package that does not fit this
199
+ # harness (or fails to start) costs its own environments, not every conversation.
200
+ self.problems = {}
155
201
 
156
202
  def providers(self):
157
- from ..extensions import hosts
203
+ from ..extensions import host_problems, hosts
158
204
  for package, module in hosts():
159
205
  factory = getattr(module, "Workspaces", None)
160
- if factory is not None and package.name not in self._providers:
161
- self._providers[package.name] = factory(self.directory, self.settings)
206
+ if factory is None or package.name in self._providers or package.name in self.problems:
207
+ continue
208
+ problem = incompatible(factory)
209
+ if not problem:
210
+ try:
211
+ self._providers[package.name] = factory(self.directory, self.settings)
212
+ continue
213
+ except Exception as error: # the package's own code: its environments only are lost
214
+ problem = f"its workspace provider did not start ({type(error).__name__}: {error})"
215
+ self.problems[package.name] = skipped(package, problem)
216
+ print(f"harness: {self.problems[package.name]}", file=sys.stderr, flush=True)
217
+ for name, problem in host_problems().items():
218
+ self.problems.setdefault(name, problem)
162
219
  return tuple(self._providers.values())
163
220
 
221
+ def missing(self, kind) -> str:
222
+ """The error for a kind no provider gives, with the packages that were left out."""
223
+ text = f"no installed package provides workspace {kind!r}"
224
+ return text + "".join(f"; {problem}" for problem in self.problems.values())
225
+
164
226
  def catalog(self):
165
227
  found = {}
166
228
  for provider in (*self.providers(), self._none):
@@ -177,7 +239,7 @@ class Workspaces:
177
239
  catalog = self.catalog()
178
240
  if requested not in (None, "auto"):
179
241
  if requested not in catalog:
180
- raise ValueError(f"no installed package provides workspace {requested!r}")
242
+ raise ValueError(self.missing(requested))
181
243
  return catalog[requested].kind(requested, text)
182
244
  matches = [p for p in self.providers() if p.accepts(binding or {})]
183
245
  if not matches and not binding and len(self.providers()) == 1:
@@ -198,7 +260,7 @@ class Workspaces:
198
260
  kind = self.kind() if kind is None else kind
199
261
  catalog = self.catalog()
200
262
  if kind not in catalog:
201
- raise ValueError(f"no installed package provides workspace {kind!r}")
263
+ raise ValueError(self.missing(kind))
202
264
  return catalog[kind]
203
265
 
204
266
  def require_choices(self, kind, runtime=None):
@@ -106,7 +106,7 @@ def models(directory, change=None):
106
106
  def select(directory, identifier=None, *, native=False):
107
107
  """Resolve a model for a new run. An ambiguous name must be qualified with the provider or entry ID."""
108
108
  rows = [row for row in models(directory) if row["enabled"]
109
- and (not native or row["provider"] in providers.PROVIDERS)]
109
+ and (not native or row["provider"] in providers.PROVIDERS or providers.is_agent(row["provider"]))]
110
110
  if identifier is None:
111
111
  chosen = providers.load(directory)
112
112
  return next((row for row in rows if all(row[key] == chosen[key] for key in chosen)), rows[0] if rows else None)
@@ -60,6 +60,7 @@ class Packages:
60
60
  self.cwd = cwd
61
61
  self._registry = registry
62
62
  self.problems: dict[str, str] = {}
63
+ self.on_change = None
63
64
 
64
65
  # -- configuration -----------------------------------------------------------------
65
66
 
@@ -543,8 +544,11 @@ class Packages:
543
544
  # -- the running process -----------------------------------------------------------
544
545
 
545
546
  def changed(self) -> None:
546
- """Make this process see the packages as they are now."""
547
+ """Make this process see the packages as they are now (then on_change, when set:
548
+ the session host's account of what it loaded)."""
547
549
  activate(self)
550
+ if self.on_change is not None:
551
+ self.on_change()
548
552
 
549
553
 
550
554
  def activate(packages: Packages | None = None) -> Packages:
@@ -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,
@@ -52,6 +52,11 @@ PROVIDERS = {provider.id: provider for provider in (
52
52
  note="vLLM, SGLang, LM Studio, a gateway: give the base URL"),
53
53
  )}
54
54
  DEFAULT = {"provider": "openrouter", "model": "deepseek/deepseek-v4.1-flash", "base_url": None}
55
+
56
+
57
+ def is_agent(provider) -> bool:
58
+ """Whether a model entry's provider is an ACP agent that answers as the model (acp:<id>)."""
59
+ return isinstance(provider, str) and provider.startswith("acp:")
55
60
  # Every key variable a provider uses (the app loads them from its credentials).
56
61
  KEY_NAMES = sorted({provider.key_env for provider in PROVIDERS.values() if provider.key_env})
57
62
 
@@ -171,7 +176,7 @@ def model_file(settings: dict, directory: Path, advanced: dict | None = None) ->
171
176
  every role the agent uses (main, vlm, verifier), as the default model file does.
172
177
  `advanced` (the app's model settings): reasoning_effort, max_output_tokens, and
173
178
  checker, another model of the provider for the verifier."""
174
- provider = PROVIDERS[settings["provider"]]
179
+ name = settings["provider"]
175
180
  advanced = advanced or {}
176
181
  role = model_role(settings, advanced)
177
182
  # The role that answers about images inside programs: the vision model when the main
@@ -183,20 +188,24 @@ def model_file(settings: dict, directory: Path, advanced: dict | None = None) ->
183
188
 
184
189
  from .core import atomic_write, sha256
185
190
 
186
- slug = re.sub(r"[^A-Za-z0-9.-]+", "-", f"{provider.id}-{settings['model']}")[:100]
191
+ slug = re.sub(r"[^A-Za-z0-9.-]+", "-", f"{name}-{settings['model']}")[:100]
187
192
  slug += "-" + sha256(roles)[:16]
188
193
  path = directory / "models" / (slug + ".toml")
189
- atomic_write(path, dumps({"description": f"{provider.name}: {settings['model']} (the app's model)", **roles}))
194
+ label = name if is_agent(name) else PROVIDERS[name].name
195
+ atomic_write(path, dumps({"description": f"{label}: {settings['model']} (the app's model)", **roles}))
190
196
  return path
191
197
 
192
198
 
193
199
  def model_role(settings: dict, advanced: dict | None = None) -> dict:
194
200
  """The model role (runtime/decision/model.py MODEL_KEYS) of the user's choice with the
195
201
  advanced settings; `images` false when the model list says it reads none."""
196
- provider = PROVIDERS[settings["provider"]]
197
202
  advanced = advanced or {}
198
203
  role = {"model": settings["model"]}
199
- if provider.backend == "openrouter":
204
+ provider = None if is_agent(settings["provider"]) else PROVIDERS[settings["provider"]]
205
+ if provider is None:
206
+ # An ACP agent answers as the model (the external-agents package's backend).
207
+ role.update(backend="acp", agent=settings["provider"])
208
+ elif provider.backend == "openrouter":
200
209
  # Streamed, as configs/models' OpenRouter files are: chunks keep coming while the
201
210
  # model thinks, so a dropped connection shows within the read timeout.
202
211
  role.update(backend="openrouter", stream=True)