@lmmslab/harness 0.85.0 → 0.86.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 (94) hide show
  1. package/README.md +1 -1
  2. package/package.json +1 -1
  3. package/python/harness/__init__.py +2 -2
  4. package/python/harness/bench.py +2 -2
  5. package/python/harness/builtin/benches/README.md +1 -2
  6. package/python/harness/builtin/configs/default.toml +4 -19
  7. package/python/harness/builtin/configs/deploy/example-api.toml +1 -1
  8. package/python/harness/builtin/configs/models/deepseek-flash.toml +1 -1
  9. package/python/harness/builtin/configs/models/grok-low.toml +1 -1
  10. package/python/harness/builtin/configs/models/grok-medium.toml +3 -6
  11. package/python/harness/builtin/environment/README.md +8 -25
  12. package/python/harness/builtin/prompts/conversation/core.md +6 -5
  13. package/python/harness/builtin/prompts/core/core.md +147 -203
  14. package/python/harness/builtin/prompts/core/pack.toml +0 -1
  15. package/python/harness/builtin/prompts/reflect/core.md +8 -32
  16. package/python/harness/builtin/prompts/reflect/pack.toml +2 -4
  17. package/python/harness/builtin/prompts/shared/agent-skills.md +5 -3
  18. package/python/harness/builtin/prompts/shared/agents.md +20 -10
  19. package/python/harness/builtin/prompts/shared/checklist.md +13 -17
  20. package/python/harness/builtin/prompts/shared/environments.md +20 -15
  21. package/python/harness/builtin/prompts/shared/learning-goal.md +2 -3
  22. package/python/harness/builtin/prompts/shared/learning.md +73 -23
  23. package/python/harness/builtin/prompts/shared/mcp.md +11 -6
  24. package/python/harness/builtin/prompts/shared/reflex-method.md +243 -0
  25. package/python/harness/builtin/prompts/shared/units.md +138 -0
  26. package/python/harness/builtin/prompts/shared/web.md +5 -6
  27. package/python/harness/builtin/skills/agents/__init__.py +18 -3
  28. package/python/harness/builtin/skills/agents/skill.toml +3 -3
  29. package/python/harness/builtin/skills/checklist/__init__.py +34 -32
  30. package/python/harness/builtin/skills/checklist/skill.toml +9 -9
  31. package/python/harness/builtin/skills/environments/__init__.py +9 -5
  32. package/python/harness/builtin/skills/environments/skill.toml +1 -1
  33. package/python/harness/builtin/skills/experience/skill.toml +1 -1
  34. package/python/harness/builtin/skills/learning/__init__.py +19 -5
  35. package/python/harness/builtin/skills/mcp/skill.toml +1 -1
  36. package/python/harness/builtin/skills/memory/__init__.py +4 -1
  37. package/python/harness/builtin/skills/memory/skill.toml +0 -5
  38. package/python/harness/builtin/skills/verify/skill.toml +1 -0
  39. package/python/harness/builtin/skills/web/__init__.py +4 -1
  40. package/python/harness/builtin/third_party/sources.toml +2 -40
  41. package/python/harness/cli.py +16 -25
  42. package/python/harness/config/__init__.py +2 -2
  43. package/python/harness/config/agent.py +59 -47
  44. package/python/harness/core/__init__.py +1 -1
  45. package/python/harness/core/codec.py +4 -4
  46. package/python/harness/core/contracts.py +1 -1
  47. package/python/harness/core/media.py +1 -1
  48. package/python/harness/core/ports.py +2 -2
  49. package/python/harness/core/procs.py +1 -1
  50. package/python/harness/core/remote.py +1 -1
  51. package/python/harness/core/worker.py +19 -13
  52. package/python/harness/embodiments.py +53 -44
  53. package/python/harness/extensions.py +22 -0
  54. package/python/harness/host/__init__.py +1 -1
  55. package/python/harness/host/http.py +6 -12
  56. package/python/harness/host/sessions.py +1 -1
  57. package/python/harness/host/tasks.py +15 -11
  58. package/python/harness/host/workspaces.py +36 -8
  59. package/python/harness/packages/__init__.py +5 -5
  60. package/python/harness/packages/environments.py +30 -18
  61. package/python/harness/packages/manager.py +1 -1
  62. package/python/harness/packages/manifest.py +6 -6
  63. package/python/harness/packages/provision.py +1 -1
  64. package/python/harness/packages/sources.py +1 -1
  65. package/python/harness/paths.py +1 -1
  66. package/python/harness/runtime/decision/loop.py +95 -5
  67. package/python/harness/runtime/decision/messages.py +128 -2
  68. package/python/harness/runtime/decision/model.py +4 -5
  69. package/python/harness/runtime/decision/prompts.py +20 -32
  70. package/python/harness/runtime/events.py +7 -5
  71. package/python/harness/runtime/execution/attached.py +3 -3
  72. package/python/harness/runtime/execution/entries.py +189 -8
  73. package/python/harness/runtime/execution/kernel.py +26 -1
  74. package/python/harness/runtime/execution/results.py +2 -3
  75. package/python/harness/runtime/execution/session.py +417 -32
  76. package/python/harness/runtime/execution/skills.py +63 -16
  77. package/python/harness/runtime/learning/active.py +7 -7
  78. package/python/harness/runtime/learning/learner.py +3 -2
  79. package/python/harness/runtime/learning/library.py +9 -4
  80. package/python/harness/runtime/learning/reflect.py +10 -9
  81. package/python/harness/runtime/reactive/rules.py +4 -4
  82. package/python/harness/runtime/reactive/tree.py +506 -25
  83. package/python/harness/runtime/safety/input.py +1 -1
  84. package/python/harness/runtime/safety/isolation.py +3 -3
  85. package/python/harness/runtime/safety/shield.py +4 -50
  86. package/python/harness/runtime/task/delegation.py +5 -5
  87. package/python/harness/runtime/task/environments.py +10 -0
  88. package/python/harness/runtime/task/run.py +222 -27
  89. package/python/harness/runtime/tick.py +24 -1
  90. package/python/harness/sdk/__init__.py +2 -5
  91. package/python/harness/services/registry.py +23 -19
  92. package/python/harness/settings.py +9 -9
  93. package/python/harness/builtin/environment/constraints.txt +0 -31
  94. package/python/harness/builtin/prompts/shared/world.md +0 -1
@@ -40,15 +40,50 @@ def current_entry():
40
40
 
41
41
  class Box:
42
42
  """What one unit gathered for the model: its output (a writer the kernel gives it, whose
43
- recent(chars) is what was printed last), the pictures it showed and looked at, and the
44
- events of its executions."""
43
+ recent(chars) is what was printed last), the pictures it showed and looked at, the pages
44
+ of instructions it asked for, and the events of its executions."""
45
45
 
46
46
  def __init__(self):
47
47
  self.output = None
48
- self.attachments, self.events, self.looks = [], [], []
48
+ self.attachments, self.events, self.looks, self.pages = [], [], [], []
49
49
  self.event_counts = {}
50
50
 
51
51
 
52
+ # What a program is told when something it relies on is not so, as Claude Code refuses a
53
+ # write to a file that is not what the model read.
54
+ UNEXPECTED = 'Nothing further ran: you expected "{text}". It does not hold: {found}'
55
+ # What a program is told when it acts on the environment and has checked nothing it relies on.
56
+ UNCHECKED = ("{what} did not run: this program has not checked what it relies on. Before it acts, call "
57
+ "expect(text, check) for each thing that must be so for the action to work: the thing it acts on, "
58
+ "the way to it, what it uses; and for each thing that must be so for you to go on once the action is "
59
+ "done: what else the action changes, the state it leaves you in. What holds for every action (the "
60
+ "agent is there and able to act) is "
61
+ "not one of them. text says what you expect; check reads the environment now and returns True, or "
62
+ "what it found instead.")
63
+ FOUND_CHARS = 2000
64
+
65
+
66
+ def _found(value) -> str:
67
+ """What a check found instead of what was expected, as text of at most FOUND_CHARS."""
68
+ text = value if isinstance(value, str) else repr(value)
69
+ return text if len(text) <= FOUND_CHARS else text[:FOUND_CHARS] + f" ... [{len(text) - FOUND_CHARS} more characters]"
70
+
71
+
72
+ # After a program whose expectations all held and whose result was not there.
73
+ OWED = ("{what} did not run: the last program that acted expected only what this one expects ({lines}); all of it "
74
+ "held and its result was not there, so it relied on something that was not checked. Find what that was "
75
+ "and add an expect for it before this program acts.")
76
+
77
+
78
+ class Unchecked(Exception):
79
+ """A program acted on the environment without an expect(text, check) before it."""
80
+
81
+
82
+ class Unexpected(Exception):
83
+ """What a program expected of the environment (expect(text, check)) is not so: the
84
+ program ends here, before what it would have done next."""
85
+
86
+
52
87
  class Cancelled(BaseException):
53
88
  """Raised in an entry's code when the entry was cancelled; a BaseException so that the
54
89
  broad excepts of a program do not keep it running."""
@@ -116,6 +151,27 @@ class Entry:
116
151
  # states none), and whether it held when the unit ended (None: no condition).
117
152
  self.until = None
118
153
  self.ok = None
154
+ # Whether it said it only reads (until(None)), and what it expected of the
155
+ # environment before it acted (expect(text, check)): {"text", "held", "found"} each.
156
+ self.reads = False
157
+ self.expects = []
158
+ # How many checks of an expect run in it now: what a check does in the environment
159
+ # is reading, and is held to nothing.
160
+ self.checking = 0
161
+ # What it says of itself whenever the model is told of it (until(report=)): a function
162
+ # of the view. And what becomes of it when a reflex takes the environment from it
163
+ # (until(interrupted=)): the model is told and it goes on ("tell"), it ends there
164
+ # ("stop"), or it goes on and nothing is told ("never").
165
+ self.report = None
166
+ self.interrupted = "tell"
167
+ # The times a reflex took the environment from it and gave it back ({"by", "at",
168
+ # "until"} each), of how many the model was told one by one, and how many more there
169
+ # were (runtime/reactive/tree.py interrupted_by).
170
+ self.pauses = []
171
+ self.interruptions_told = 0
172
+ self.interruptions_untold = 0
173
+ # The units this one took the environment from while it ran (a reflex's program).
174
+ self.took = []
119
175
  # A tree started it (runtime/reactive/tree.py): its end is the tree's business and
120
176
  # is recorded without being told to the model.
121
177
  self.quiet = False
@@ -386,16 +442,141 @@ class Tree:
386
442
  except BaseException:
387
443
  return False
388
444
 
389
- def until(self, condition) -> None:
445
+ def until(self, condition, report=None, interrupted="tell") -> None:
390
446
  """The unit this code runs in is for `condition`: a function of the view that holds
391
447
  when its work is done. It is judged when the unit ends, and the end says whether it
392
- held."""
393
- if not callable(condition):
394
- raise TypeError("until(condition): a function of the view that holds when this program's work is done")
448
+ held. until(None): the unit is for nothing but reading, and its end says nothing of
449
+ done. `report`: a function of the view that returns what the model is to read
450
+ whenever it is told of this unit (while it runs, when a reflex takes the environment
451
+ from it, when it ends). `interrupted`: what becomes of the unit when a reflex takes
452
+ the environment from it: "tell" (the model is told and the unit goes on), "stop" (it
453
+ ends there and the model is told), "never" (it goes on and nothing is told)."""
454
+ if condition is not None and not callable(condition):
455
+ raise TypeError("until(condition): a function of the view that holds when this program's work is done, "
456
+ "or None for a program that only reads")
457
+ if report is not None and not callable(report):
458
+ raise TypeError("until(report=): a function of the view that returns what you want to read whenever "
459
+ "you are told of this program")
460
+ if interrupted not in ("tell", "stop", "never"):
461
+ raise ValueError(f'until(interrupted=): "tell", "stop" or "never", got {interrupted!r}')
395
462
  entry = self.current()
396
463
  if entry is self.root:
397
464
  raise RuntimeError("until() is called by a program: it says what that program is for")
398
- entry.until = condition
465
+ entry.report, entry.interrupted = report, interrupted
466
+ if condition is not None:
467
+ entry.until = condition
468
+ else:
469
+ entry.reads = True
470
+
471
+ def after(self, unit) -> dict:
472
+ """Wait until the unit `unit` (its name, or its handle) has ended, however it ended,
473
+ and return {"ended": its status, "done": whether what it was for is the case (None:
474
+ it stated no condition)}. Its failure is not raised here and stays unhandled: the
475
+ caller goes on from the state as it is. For a program that is sent while an
476
+ earlier one still runs and is to act when that one is over."""
477
+ entry = unit if getattr(unit, "tree", None) is self else self.entries.get(str(unit))
478
+ if entry is None or entry is self.root:
479
+ raise ValueError(f"after({unit!r}): no unit of that name; the message that told you a program still "
480
+ "runs gives its unit")
481
+ caller = self.current()
482
+ if caller is entry:
483
+ raise ValueError("a unit cannot wait for itself")
484
+ with self._changed:
485
+ while not entry._done.is_set():
486
+ self.check(caller)
487
+ self._changed.wait(1.0)
488
+ return {"ended": entry.status, "done": entry.ok}
489
+
490
+ def acts(self, what) -> None:
491
+ """The calling code is about to act on the environment (`what`: the call). Where
492
+ the run holds programs to it (expect_required), a unit of the model that has checked
493
+ nothing it relies on does not act: Unchecked, as Claude Code refuses a write to a
494
+ file the model has not read. Held to nothing: the root, a check of an expect, and
495
+ a reflex's program with what it starts (a reaction does not wait)."""
496
+ session = self.session
497
+ if not getattr(session, "_expect_required", False):
498
+ return
499
+ entry = self.current()
500
+ if entry is self.root:
501
+ return
502
+ chain, unit = [], entry
503
+ while unit is not None and unit is not self.root:
504
+ chain.append(unit)
505
+ unit = unit.parent
506
+ if any(unit.rule is not None or unit.checking for unit in chain):
507
+ return
508
+ uncovered = session._uncovered(what) if hasattr(session, "_uncovered") else None
509
+ if uncovered:
510
+ raise Unchecked(uncovered)
511
+ texts = [row["text"] for unit in chain for row in unit.expects]
512
+ if not texts:
513
+ raise Unchecked(UNCHECKED.format(what=what))
514
+ owed = getattr(session, "_owed_expects", None)
515
+ if owed:
516
+ if all(text in owed for text in texts):
517
+ raise Unchecked(OWED.format(what=what, lines="; ".join(f'"{text}"' for text in sorted(owed))))
518
+ session._owed_expects = None
519
+
520
+ def noted(self, text, held, found=None) -> None:
521
+ """An expectation that was checked elsewhere for the calling unit (code a skill ran
522
+ in the environment), kept with the unit's own for its end report."""
523
+ entry = self.current()
524
+ if entry is self.root:
525
+ return
526
+ row = {"text": " ".join(str(text).split()), "held": bool(held)}
527
+ if not held:
528
+ row["found"] = _found(found)
529
+ entry.expects.append(row)
530
+
531
+ def expect(self, text, check) -> bool:
532
+ """What the unit this code runs in relies on, checked now: `text` says what is
533
+ expected, `check` reads the environment and returns True, or what it found
534
+ instead. What it showed is kept for the unit's end report. When it does not hold,
535
+ a unit that acts ends here (Unexpected); one that only reads (until(None)) goes
536
+ on. Returns whether it held."""
537
+ if not isinstance(text, str) or not text.strip():
538
+ raise TypeError("expect(text, check): text is a sentence that says what you expect")
539
+ if not callable(check):
540
+ raise TypeError("expect(text, check): check is a function that reads the environment now and returns "
541
+ "True, or what it found instead")
542
+ entry = self.current()
543
+ if entry is self.root:
544
+ raise RuntimeError("expect() is called by a program: it says what that program relies on")
545
+ entry.checking += 1
546
+ try:
547
+ found = check()
548
+ except Cancelled:
549
+ raise
550
+ except Exception as error:
551
+ found = f"the check raised {type(error).__name__}: {error}"
552
+ finally:
553
+ entry.checking -= 1
554
+ held = found is True or (type(found).__name__ == "bool_" and bool(found))
555
+ row = {"text": text.strip(), "held": held}
556
+ if not held:
557
+ row["found"] = _found(found)
558
+ entry.expects.append(row)
559
+ if not held and not entry.reads:
560
+ raise Unexpected(UNEXPECTED.format(text=row["text"], found=row["found"]))
561
+ return held
562
+
563
+ def reports(self, entry, pictures=True) -> dict:
564
+ """What the unit says of itself now (its until(report=)), as a message
565
+ (runtime/reactive/tree.py message: {"says", "shows", "files"}); {} without one.
566
+ Without `pictures`, a look() in the report sees nothing and asks the environment
567
+ nothing: for what is told every second of a unit that runs."""
568
+ if entry.report is None:
569
+ return {}
570
+ try:
571
+ view = self.session._view(self.session.state, 0)
572
+ except BaseException as error:
573
+ return {"says": f"(the view could not be made: {type(error).__name__}: {error})"}
574
+ with self.session.reporting(pictures):
575
+ return reflexes.message(entry.report, view)
576
+
577
+ def says(self, entry):
578
+ """The text of what the unit says of itself now, with no picture taken; None without."""
579
+ return self.reports(entry, pictures=False).get("says")
399
580
 
400
581
  def at_priority(self, priority) -> "_Priority":
401
582
  """`with at_priority(priority):` the unit this code runs in holds the embodiment
@@ -475,6 +475,9 @@ class Kernel:
475
475
  "timeout": float(timeout)}, float(timeout) + 70.0)
476
476
 
477
477
  def load_library(self, phase, entries=(), *, timeout=120):
478
+ """The phases of taking library entries into the kernel: "prepare" stages them,
479
+ "match" says what trials the staged nodes of a tree had in the tree ({"trials",
480
+ "problems"}), "commit" publishes what is staged, "discard" drops it."""
478
481
  return self._cell({"op": "library", "phase": phase,
479
482
  "entries": [(item.revision, item.pack().decode(), hand) for item, hand in entries]}, timeout)
480
483
 
@@ -798,6 +801,19 @@ def _serve(bootstrap: str, options: dict, *, forward_workspace_requests: bool =
798
801
  # how it ended, and whether what it was for is the case (None: it stated no condition).
799
802
  result["ended"] = ended(result, getattr(entry, "timed_out", False))
800
803
  result["done"] = entry.ok
804
+ # What it says of itself at its end (until(report=)), and how often a reflex took the
805
+ # environment from it without the model being told of it by itself.
806
+ result.update(tree.reports(entry) if entry.report is not None else {})
807
+ if entry.interruptions_untold:
808
+ result["interruptions_untold"] = entry.interruptions_untold
809
+ # What it expected of the environment (expect(text, check)) and what each check showed.
810
+ if entry.expects:
811
+ result["expected"] = list(entry.expects)
812
+ # (Only of a program that ended by itself: one that was refused or failed did not
813
+ # get to show that what it checked was not enough.)
814
+ if (entry.status == "done" and entry.ok is False and entry.rule is None
815
+ and all(row["held"] for row in entry.expects)):
816
+ session._owed_expects = {row["text"] for row in entry.expects}
801
817
  if entry.cell is not None:
802
818
  with api_lock:
803
819
  # Names the session gained while the program ran (an attached environment,
@@ -834,6 +850,8 @@ def _serve(bootstrap: str, options: dict, *, forward_workspace_requests: bool =
834
850
  for key in ("attachments", "events", "looks", "event_counts"):
835
851
  if getattr(box, key):
836
852
  result[key] = getattr(box, key)
853
+ if box.pages:
854
+ result["pages"] = session._pages_given(box.pages)
837
855
  if entry.status == "done" and entry.result is not None:
838
856
  returned = entry.result if isinstance(entry.result, (dict, list, str, int, float, bool)) else repr(
839
857
  entry.result)
@@ -912,6 +930,7 @@ def _serve(bootstrap: str, options: dict, *, forward_workspace_requests: bool =
912
930
  try:
913
931
  phase = request["phase"]
914
932
  reactive = getattr(session, "reactive", None)
933
+ found = {}
915
934
  if phase == "prepare":
916
935
  staged_library = None
917
936
  items = []
@@ -921,6 +940,12 @@ def _serve(bootstrap: str, options: dict, *, forward_workspace_requests: bool =
921
940
  raise ValueError("library payload does not match its revision")
922
941
  items.append((item, hand))
923
942
  staged_library = stage_entries(items, namespace, active_library, reactive, api=api)
943
+ elif phase == "match" and staged_library is not None:
944
+ # The trials the staged nodes had in the tree (Reflexes.tried): nothing runs.
945
+ rules = staged_library[2]
946
+ trials, problems = (reactive.tried(rules) if rules is not None
947
+ else ({}, ["this run has no tree of reflexes"]))
948
+ found = {"trials": trials, "problems": problems}
924
949
  elif phase == "commit" and staged_library is not None:
925
950
  publish_entries(staged_library, namespace, active_library, reactive)
926
951
  staged_library = None
@@ -928,7 +953,7 @@ def _serve(bootstrap: str, options: dict, *, forward_workspace_requests: bool =
928
953
  staged_library = None
929
954
  else:
930
955
  raise ValueError("invalid library activation phase")
931
- reply({"status": "ok", "active": {key: row[0] for key, row in active_library.items()}})
956
+ reply({"status": "ok", "active": {key: row[0] for key, row in active_library.items()}, **found})
932
957
  except BaseException as error:
933
958
  staged_library = None
934
959
  reply({"status": "error", "error": format_error(error)})
@@ -3,8 +3,7 @@
3
3
 
4
4
  def _taken_over(result: dict) -> dict | None:
5
5
  """The worker's reason when a step was refused because the user brought a window of
6
- theirs to the front (a worker that sends the user's real input: the computer's,
7
- Minecraft's), else None."""
6
+ theirs to the front (a worker that sends the user's real input), else None."""
8
7
  for item in result.get("events") or []:
9
8
  for reason in ((item.get("event") or {}).get("detail") or {}).get("reasons") or []:
10
9
  if isinstance(reason, dict) and reason.get("took_over"):
@@ -31,7 +30,7 @@ def _cell_usage(summary: dict, result: dict) -> None:
31
30
 
32
31
  def _wrap_up(kernel, trace):
33
32
  """The benchmark's end-of-episode convention, the same for every layer: the kernel
34
- returns the arms to their start pose when the embodiment profile asks for it."""
33
+ returns the body to its start pose when the embodiment profile asks for it."""
35
34
  try:
36
35
  # (A paused run that ends is wrapped up all the same.)
37
36
  kernel.resume()