@lmmslab/harness 0.81.1 → 0.83.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -35
- package/package.json +2 -2
- package/python/harness/README.md +3 -3
- package/python/harness/__init__.py +1 -1
- package/python/harness/builtin/configs/assistant.toml +0 -1
- package/python/harness/builtin/configs/default.toml +1 -1
- package/python/harness/builtin/prompts/conversation/core.md +2 -2
- package/python/harness/builtin/prompts/core/core.md +197 -45
- package/python/harness/builtin/prompts/core/pack.toml +2 -2
- package/python/harness/builtin/prompts/reflect/core.md +4 -13
- package/python/harness/builtin/prompts/reflect/pack.toml +3 -2
- package/python/harness/builtin/prompts/shared/learning-goal.md +5 -29
- package/python/harness/builtin/prompts/shared/learning.md +8 -10
- package/python/harness/builtin/prompts/shared/web.md +11 -0
- package/python/harness/builtin/skills/agents/__init__.py +24 -22
- package/python/harness/builtin/skills/entries/__init__.py +43 -28
- package/python/harness/builtin/skills/entries/skill.toml +2 -3
- package/python/harness/builtin/skills/environments/__init__.py +2 -9
- package/python/harness/builtin/skills/mcp/__init__.py +2 -3
- package/python/harness/builtin/skills/memory/__init__.py +2 -5
- package/python/harness/builtin/skills/web/__init__.py +92 -0
- package/python/harness/builtin/skills/web/skill.toml +9 -0
- package/python/harness/cli.py +85 -17
- package/python/harness/config/agent.py +36 -9
- package/python/harness/core/episodes.py +5 -4
- package/python/harness/core/lanes.py +3 -0
- package/python/harness/core/memory.py +5 -1
- package/python/harness/core/remote.py +4 -3
- package/python/harness/core/worker.py +58 -3
- package/python/harness/extensions.py +23 -2
- package/python/harness/host/__init__.py +43 -1
- package/python/harness/host/client.py +36 -6
- package/python/harness/host/http.py +19 -0
- package/python/harness/host/server.py +17 -3
- package/python/harness/host/sessions.py +3 -2
- package/python/harness/host/tasks.py +107 -26
- package/python/harness/host/workspaces.py +69 -7
- package/python/harness/model_list.py +1 -1
- package/python/harness/packages/manager.py +5 -1
- package/python/harness/providers.py +14 -5
- package/python/harness/runtime/decision/loop.py +105 -117
- package/python/harness/runtime/decision/messages.py +158 -55
- package/python/harness/runtime/decision/model.py +85 -22
- package/python/harness/runtime/decision/notices.py +66 -0
- package/python/harness/runtime/decision/prompts.py +15 -11
- package/python/harness/runtime/decision/protocol.py +12 -6
- package/python/harness/runtime/decision/thoughts.py +10 -16
- package/python/harness/runtime/events.py +28 -13
- package/python/harness/runtime/execution/attached.py +1 -1
- package/python/harness/runtime/execution/control.py +17 -35
- package/python/harness/runtime/execution/entries.py +204 -124
- package/python/harness/runtime/execution/kernel.py +471 -281
- package/python/harness/runtime/execution/managed.py +231 -0
- package/python/harness/runtime/execution/noenv.py +2 -2
- package/python/harness/runtime/execution/results.py +2 -0
- package/python/harness/runtime/execution/session.py +284 -115
- package/python/harness/runtime/learning/active.py +41 -50
- package/python/harness/runtime/learning/fixtures.py +2 -2
- package/python/harness/runtime/learning/learner.py +75 -2
- package/python/harness/runtime/learning/library.py +77 -10
- package/python/harness/runtime/learning/views.py +12 -1
- package/python/harness/runtime/reactive/__init__.py +1 -1
- package/python/harness/runtime/reactive/rules.py +29 -394
- package/python/harness/runtime/reactive/tree.py +611 -0
- package/python/harness/runtime/safety/approval.py +8 -3
- package/python/harness/runtime/safety/permissions.py +242 -0
- package/python/harness/runtime/status.py +7 -2
- package/python/harness/runtime/task/delegation.py +97 -58
- package/python/harness/runtime/task/environments.py +3 -4
- package/python/harness/runtime/task/inbound.py +64 -0
- package/python/harness/runtime/task/run.py +1231 -790
- package/python/harness/runtime/tick.py +257 -91
- package/python/harness/sdk/__init__.py +7 -4
- package/python/harness/settings.py +30 -5
- package/python/harness/terminal.py +10 -6
- package/python/harness/transcript.py +18 -6
- package/python/harness/tui/answer.py +51 -0
- package/python/harness/tui/chat.py +75 -26
- package/python/harness/tui/views.py +1 -0
- package/python/harness/builtin/prompts/shared/entries.md +0 -86
|
@@ -234,7 +234,8 @@ class TaskHost:
|
|
|
234
234
|
by = {row["value"]: row for row in offered["options"]}
|
|
235
235
|
if workspace not in by or by[workspace].get("package"):
|
|
236
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'))}"
|
|
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()))
|
|
238
239
|
kind = self.workspaces.kind(workspace)
|
|
239
240
|
if by[workspace].get("folder") and not folder:
|
|
240
241
|
raise ValueError(f"a {kind} conversation works in one folder: name it with --folder PATH (folder=PATH)")
|
|
@@ -303,7 +304,10 @@ class TaskHost:
|
|
|
303
304
|
embodiment_config["skills"] = {**embodiment_config.get("skills", {}), "enable": skills["enable"]}
|
|
304
305
|
# What waits for the user in this conversation (its lock records it; the conversation's
|
|
305
306
|
# confirmation follows it, confirmation_policy).
|
|
306
|
-
|
|
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")}}
|
|
307
311
|
# The skills the user installed: the prompt's installed section (runtime/decision/prompts.py).
|
|
308
312
|
if skills["installed"]:
|
|
309
313
|
embodiment_config["runtime"] = {**embodiment_config.get("runtime", {}), "installed_skills": skills["installed"]}
|
|
@@ -392,7 +396,7 @@ class TaskHost:
|
|
|
392
396
|
enable = [*(["checklist"] if not {"checklist", "plan"} & off else []), "entries", *installed,
|
|
393
397
|
*sorted(mine - set(installed)), *(["instructions"] if agent else [])]
|
|
394
398
|
enable += list(self.workspaces.provider(kind).extra_skills(kind))
|
|
395
|
-
enable
|
|
399
|
+
enable += ["environments", "web"]
|
|
396
400
|
if agents is None:
|
|
397
401
|
agents = values["session"]["agents"] == "on"
|
|
398
402
|
if agents and values["limits"]["agent_depth"] > 0:
|
|
@@ -472,9 +476,11 @@ class TaskHost:
|
|
|
472
476
|
|
|
473
477
|
tree = load_layered(CONVERSATION)
|
|
474
478
|
limits = values["limits"]
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
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}
|
|
478
484
|
# The workspace's own (a background browser's prompt).
|
|
479
485
|
tree = self.workspaces.tree(tree, kind)
|
|
480
486
|
# When the model thinks while the agent acts (Settings, Model).
|
|
@@ -531,8 +537,10 @@ class TaskHost:
|
|
|
531
537
|
reasoning_effort: str | None = None, profile: str | None = None, *,
|
|
532
538
|
agent: str | None = None, folder: str | None = None, isolation: str | None = None,
|
|
533
539
|
frontend: str | None = None, mcp_tools=(), execution: str | None = None,
|
|
534
|
-
budget: dict | None = None, library: dict | None = None, title: str | None = None, model_entry: str | None = None
|
|
535
|
-
|
|
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
|
|
536
544
|
now, its workspace (of kind `workspace`: "none" takes none; without one and without a
|
|
537
545
|
`folder`, session.environment decides, environment(); installed on first use) and the
|
|
538
546
|
episode on a thread of their own. `runtime`: this conversation's
|
|
@@ -560,7 +568,11 @@ class TaskHost:
|
|
|
560
568
|
if choice is None:
|
|
561
569
|
raise ValueError("the selected model is no longer enabled")
|
|
562
570
|
model = choice["model"] or None
|
|
563
|
-
if choice["provider"]
|
|
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:
|
|
564
576
|
if agent and agent != choice["provider"]:
|
|
565
577
|
raise ValueError("the selected model uses a different agent")
|
|
566
578
|
agent = choice["provider"]
|
|
@@ -573,6 +585,9 @@ class TaskHost:
|
|
|
573
585
|
raise ValueError("this adapter does not accept execution bounds")
|
|
574
586
|
if runtime or profile or confirmation or workspace not in (None, "auto"):
|
|
575
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")
|
|
576
591
|
return self.start_external(server, agent, str(text or ""), files, folder, isolation,
|
|
577
592
|
frontend, model, reasoning_effort or None, mcp_tools=mcp_tools)
|
|
578
593
|
if isolation or mcp_tools:
|
|
@@ -584,7 +599,13 @@ class TaskHost:
|
|
|
584
599
|
text = str(text or "").strip()
|
|
585
600
|
if not text:
|
|
586
601
|
raise ValueError("say what to do")
|
|
587
|
-
|
|
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:
|
|
588
609
|
provider = providers.PROVIDERS[choice["provider"]]
|
|
589
610
|
if provider.key_env:
|
|
590
611
|
self.credentials.load()
|
|
@@ -638,14 +659,14 @@ class TaskHost:
|
|
|
638
659
|
library_settings(library)
|
|
639
660
|
config.runtime = {**config.runtime, "library": dict(library)}
|
|
640
661
|
name = runs.new_name()
|
|
641
|
-
directory = self.conversations_dir / name
|
|
662
|
+
directory = Path(resume["directory"]) if resume else self.conversations_dir / name
|
|
642
663
|
if learn is not None and learn is not False:
|
|
643
664
|
if library is None:
|
|
644
665
|
config.runtime = {**config.runtime, "library": {"path": str(directory / "library"),
|
|
645
666
|
"learn": "on", "reflect": True}}
|
|
646
667
|
config = self.learning(config, learn)
|
|
647
668
|
if managed:
|
|
648
|
-
config.runtime = {**config.runtime, "library": None, "agent_skills": []
|
|
669
|
+
config.runtime = {**config.runtime, "library": None, "agent_skills": []}
|
|
649
670
|
if reasoning_effort:
|
|
650
671
|
config.main = {**config.main, "reasoning_effort": reasoning_effort}
|
|
651
672
|
elif reasoning_effort == "":
|
|
@@ -653,11 +674,14 @@ class TaskHost:
|
|
|
653
674
|
options, metadata = self.workspaces.bind(kind, directory, request)
|
|
654
675
|
conversation = TaskRun(config, 0, directory, interactive=True,
|
|
655
676
|
confirmation=confirmation_policy(confirmation), instruction=text,
|
|
656
|
-
agents=None if managed else self.sub_agents(server, kind, assistant=True),
|
|
677
|
+
agents=None if managed else self.sub_agents(server, kind, assistant=True),
|
|
678
|
+
restore=resume["kept"] if resume else None, **self._models)
|
|
657
679
|
from ..extensions import hosts
|
|
658
680
|
|
|
659
681
|
conversation.workspace_kind = kind
|
|
660
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"]
|
|
661
685
|
if not managed:
|
|
662
686
|
from harness.runtime.task.environments import Environments
|
|
663
687
|
|
|
@@ -677,15 +701,21 @@ class TaskHost:
|
|
|
677
701
|
**metadata,
|
|
678
702
|
**({"model_entry": model_entry} if model_entry else {}),
|
|
679
703
|
**({"learning": config.max_wall_seconds / 60} if active.is_active(config.runtime) else {}),
|
|
680
|
-
**({"profile": profile} if profile else {})
|
|
681
|
-
|
|
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")
|
|
682
709
|
run = directory.relative_to(server.root).as_posix()
|
|
683
710
|
self._kinds[run] = kind
|
|
684
711
|
# What the next conversation's choice highlights (and session.environment = last takes).
|
|
685
712
|
self.settings.remember("session", "last_environment", kind)
|
|
686
713
|
if metadata.get("folder"):
|
|
687
714
|
self.settings.remember("session", "last_folder", metadata["folder"])
|
|
688
|
-
if
|
|
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:
|
|
689
719
|
server.conversations[run] = conversation
|
|
690
720
|
else:
|
|
691
721
|
server.conversations.add(run, conversation, title=meta["title"], frontend=frontend)
|
|
@@ -748,6 +778,45 @@ class TaskHost:
|
|
|
748
778
|
threading.Thread(target=begin, name=f"start-{name}", daemon=True).start()
|
|
749
779
|
return run
|
|
750
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
|
+
|
|
751
820
|
def start_external(self, server, agent, text, files, folder, isolation, frontend, model, effort, *,
|
|
752
821
|
handoff=None, reconnect=None, observe=None, mcp_tools=()):
|
|
753
822
|
from ..core import atomic_write
|
|
@@ -801,10 +870,9 @@ class TaskHost:
|
|
|
801
870
|
return run
|
|
802
871
|
|
|
803
872
|
# Records after which the user is needed in the chat: the agent waits for an approval,
|
|
804
|
-
# or it stopped on an error. And the end of the agent's turn (an answer, a
|
|
805
|
-
#
|
|
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).
|
|
806
875
|
NEEDS_THE_USER = ("confirmation_request", "error", "kernel_died", "external_notice", "external_question")
|
|
807
|
-
TURN_ENDS = ("message", "finish", "budget")
|
|
808
876
|
|
|
809
877
|
def _watcher(self):
|
|
810
878
|
"""A conversation's watcher (a subscriber of its trace): brings the app's window to
|
|
@@ -820,9 +888,7 @@ class TaskHost:
|
|
|
820
888
|
turn["stay"] = True
|
|
821
889
|
elif event == "user_message":
|
|
822
890
|
turn["stay"] = False
|
|
823
|
-
needed = event in self.NEEDS_THE_USER or (
|
|
824
|
-
event == "state" and record.get("status") == "IDLE" and record.get("reason") in self.TURN_ENDS
|
|
825
|
-
and not turn["stay"])
|
|
891
|
+
needed = event in self.NEEDS_THE_USER or (event == "turn_result" and not turn["stay"])
|
|
826
892
|
if needed and self.focus_chat is not None:
|
|
827
893
|
threading.Thread(target=self.focus_chat, name="show-chat", daemon=True).start()
|
|
828
894
|
|
|
@@ -841,9 +907,10 @@ class TaskHost:
|
|
|
841
907
|
max_depth=self.settings.get()["limits"]["agent_depth"])
|
|
842
908
|
|
|
843
909
|
def _evict(self, server, runs, run) -> bool:
|
|
844
|
-
"""Make room for `run`:
|
|
845
|
-
for the user (IDLE after its turn)
|
|
846
|
-
|
|
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)."""
|
|
847
914
|
with self._reclaiming:
|
|
848
915
|
idle = []
|
|
849
916
|
for other in runs:
|
|
@@ -859,8 +926,9 @@ class TaskHost:
|
|
|
859
926
|
if not idle:
|
|
860
927
|
return False
|
|
861
928
|
_, other, conversation = min(idle, key=lambda item: item[0])
|
|
862
|
-
self._note(run, "
|
|
929
|
+
self._note(run, "parking the conversation that waited longest, for its workspace")
|
|
863
930
|
conversation.trace.emit("workspace_reclaimed", by=run)
|
|
931
|
+
conversation.parked = True
|
|
864
932
|
conversation.close()
|
|
865
933
|
return True
|
|
866
934
|
|
|
@@ -1143,6 +1211,19 @@ class TaskHandler(Handler):
|
|
|
1143
1211
|
mcp_tools=body.get("mcp_tools") or (),
|
|
1144
1212
|
model_entry=body.get("model_entry"), library=body.get("library"), budget=body.get("budget"))})
|
|
1145
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
|
+
|
|
1146
1227
|
def post_conversations_handoff(self, body):
|
|
1147
1228
|
source = self.server.conversations.resolve(body.get("run"))
|
|
1148
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, "
|
|
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
|
|
161
|
-
|
|
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(
|
|
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(
|
|
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:
|
|
@@ -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
|
-
|
|
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"{
|
|
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
|
-
|
|
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
|
|
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)
|