## Summary Adds `experimental/`, a first version of worker RSI: a Curator that shapes a Raven worker's harness from the task, the materials handed to it and feedback, the way a new employee is trained. The worker is a harness-of-harnesses. A root Raven harness faces the user and calls child harnesses, each a full Raven agent hosted over ACP, through the nodes of its playbooks. Every harness has the same four strategy facets (memory, planning, capability, action). The Curator reads the actual harnesses and generates code and config on those facets at both levels: the root candidate sets the playbooks and writes per-node requirements, each child is curated against the requirements of its nodes, and the set is checked on copies and activated together. Layout: - `curator/`: staged generation (understand, select, design, implement, repair), two-level composition, harness contracts, and `raven_adapter/`, the only layer that touches a worker's Raven runtime - `analyst/`: turns an evaluator's words and execution records into observable behavior requirements - `iteration/`: the generic loop (onboarding curation, then trial, review and curation each round) and a CLI for a human evaluator - `simulation/`: a simulated travel agency that runs the loop, plus one showcase case (`simulation/cases/s0925c/`: case notes, the exported transcript split by phase, and the round 1 and round 3 decks) - `docs/design.md` (structure, curation flow, composition sequence, the Raven connection) and `docs/rsi-iteration.md` (the loop and the Analyst) Key decisions: - No change under `raven/`, and `raven/` does not import `experimental/`. Generated artifacts land on Raven's existing extension points. The few Raven internals the adapter reads are listed in `docs/design.md` section 5.4. - The Curator explores a read-only source snapshot; the caller names the evaluation side to withhold from it, so the generic layers name no scenario. - The single-layer owner analysis is kept only to reproduce the showcase case and is marked for removal; the two-layer Analyst is the default. - The two decks are `.pptx` files of about 230 KB each. They pass `check-large-files`; flagging them in case they count as report assets under AGENTS.md section 7, in which case they can move out of git behind a link. - One follow-up for Raven 0.2.2: playbooks in prompt and rounds modes ship no fixed nodes, so node requirements are read from dag playbooks only. ## Type - [ ] Fix - [x] Feature - [ ] Docs - [ ] CI / tooling - [ ] Refactor - [ ] Other ## Verification On the branch rebased onto the latest `main`: - `uv run pytest tests/test_harness_curator_*.py tests/test_analyst_*.py tests/test_iteration_*.py tests/test_simulation_*.py -q`: 368 passed - `uv run pytest -m integration tests/integration/test_harness_curator_*.py --deselect tests/integration/test_harness_curator_real_llm.py -q` (offline, stub providers): 57 passed - `uv run pytest -q` (whole suite, with the host proxy variables unset and `PYTHONTZPATH` set): 26692 passed, 2 failed. One was an order-dependent test of this PR and is fixed here; the other, `tests/test_subagent_node_runtime.py::test_what_cannot_be_read_names_nothing`, fails only because the machine runs as root and is unrelated. - `uv run ruff check` and `uv run ruff format --check` on the touched files: clean - `scripts/check_large_files.py origin/main..HEAD`, `scripts/check_source_language.py origin/main..HEAD`, `scripts/check_commit_messages.py origin/main..HEAD` and `npx commitlint --from origin/main --to HEAD`: all exit 0 - [x] Relevant tests pass locally - [x] Relevant lint / type checks pass locally - [x] User-facing docs or screenshots are updated when needed ## Risk No user-visible change for Raven: `experimental/` is not imported by `raven/` and is not packaged in the wheel (`packages = ["raven"]`). `CONTEXT.md` gains one glossary entry. The Curator's exploration offers a shell only under an OS sandbox executor. Rollback is a revert of the squash commit; nothing else depends on `experimental/`. - [x] Security impact considered - [x] Backward compatibility considered - [x] Rollback path is clear for risky changes ## Related Issues N/A --------- Co-authored-by: Yuqi Yang <yiqiyang524@gmail.com> Co-authored-by: Claude (claude-opus-5-5) <noreply@anthropic.com>
117 lines
4.5 KiB
Python
117 lines
4.5 KiB
Python
"""How a person reads a delivered file: a web page as its visible text, a deck slide by slide.
|
|
|
|
A traveller reads what the file says; the owner, reviewing against the agency's design norms, also reads
|
|
how each slide is laid out and styled, and looks at every page as rendered.
|
|
"""
|
|
|
|
import re
|
|
from html.parser import HTMLParser
|
|
from pathlib import Path
|
|
|
|
from pptx import Presentation
|
|
from pptx.enum.dml import MSO_FILL
|
|
from pptx.enum.shapes import MSO_SHAPE_TYPE
|
|
|
|
from .render import cached
|
|
|
|
_HIDDEN = ("script", "style", "template")
|
|
_TEXT = (".md", ".txt", ".json", ".csv", ".yaml", ".yml")
|
|
_MOTION = re.compile(r"<p:(transition|timing)\b")
|
|
PAGE_WIDTH = 960
|
|
|
|
|
|
class _Visible(HTMLParser):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.parts, self._hidden = [], 0
|
|
|
|
def handle_starttag(self, tag, attrs):
|
|
if tag in _HIDDEN:
|
|
self._hidden += 1
|
|
|
|
def handle_endtag(self, tag):
|
|
if tag in _HIDDEN and self._hidden:
|
|
self._hidden -= 1
|
|
|
|
def handle_data(self, data):
|
|
if not self._hidden and data.strip():
|
|
self.parts.append(data.strip())
|
|
|
|
|
|
def visible_text(path: Path) -> str:
|
|
parser = _Visible()
|
|
parser.feed(Path(path).read_text(errors="replace"))
|
|
return "\n".join(parser.parts)
|
|
|
|
|
|
def _shapes(shapes):
|
|
for shape in shapes:
|
|
if shape.shape_type == MSO_SHAPE_TYPE.GROUP:
|
|
yield from _shapes(shape.shapes)
|
|
else:
|
|
yield shape
|
|
|
|
|
|
def _colour(font) -> str | None:
|
|
try:
|
|
return f"#{font.color.rgb}" if font.color and font.color.type is not None else None
|
|
except (AttributeError, TypeError):
|
|
return None
|
|
|
|
|
|
def deck_slides(path: Path, *, style: bool = False) -> str:
|
|
"""Each slide's text in reading order; with `style`, also its layout, fonts, colours, pictures and motion."""
|
|
deck = Presentation(str(path))
|
|
area = deck.slide_width * deck.slide_height
|
|
lines = [f"{len(deck.slides)} slides, aspect {deck.slide_width / deck.slide_height:.2f}"]
|
|
for number, slide in enumerate(deck.slides, 1):
|
|
lines.append(f"--- slide {number}" + (f" · layout {slide.slide_layout.name}" if style else ""))
|
|
fonts, pictures = set(), []
|
|
for shape in _shapes(slide.shapes):
|
|
if shape.has_text_frame:
|
|
for paragraph in shape.text_frame.paragraphs:
|
|
words = "".join(run.text for run in paragraph.runs).strip()
|
|
if words:
|
|
lines.append(words)
|
|
for run in paragraph.runs:
|
|
size = run.font.size.pt if run.font.size else None
|
|
fonts.add((run.font.name, size, _colour(run.font)))
|
|
if getattr(shape, "has_table", False) and shape.has_table:
|
|
for row in shape.table.rows:
|
|
lines.append(" | ".join(cell.text.strip() for cell in row.cells))
|
|
if shape.shape_type == MSO_SHAPE_TYPE.PICTURE and shape.width and shape.height:
|
|
pictures.append(round(100 * shape.width * shape.height / area))
|
|
if style:
|
|
fill = slide.background.fill
|
|
try:
|
|
background = f"#{fill.fore_color.rgb}" if fill.type == MSO_FILL.SOLID else "template default"
|
|
except (AttributeError, TypeError):
|
|
background = "template default"
|
|
used = sorted(
|
|
f"{name or 'inherited'} {size or '?'}pt {colour or 'inherited'}" for name, size, colour in fonts
|
|
)
|
|
lines.append(f"[style] background {background}; fonts: {', '.join(used) or 'inherited'}")
|
|
if pictures:
|
|
lines.append(f"[style] pictures covering {', '.join(f'{p}%' for p in pictures)} of the slide")
|
|
if _MOTION.search(slide.part.blob.decode("utf-8", errors="replace")):
|
|
lines.append("[style] has a transition or animation")
|
|
return "\n".join(lines)
|
|
|
|
|
|
def read_delivered(path: Path, *, style: bool = False) -> str:
|
|
path = Path(path)
|
|
suffix = path.suffix.lower()
|
|
if suffix in (".html", ".htm"):
|
|
return visible_text(path)
|
|
if suffix == ".pptx":
|
|
return deck_slides(path, style=style)
|
|
if suffix in _TEXT:
|
|
return path.read_text(errors="replace")
|
|
return f"(a {suffix or 'binary'} file of {path.stat().st_size} bytes, not readable as text)"
|
|
|
|
|
|
def page_images(path: Path) -> list[Path]:
|
|
"""How each page of a delivered deck looks, rendered once beside it as `<file>.thumbs/` (the record keeps them)."""
|
|
file = Path(path)
|
|
return cached(file, file.with_name(f"{file.name}.thumbs"), PAGE_WIDTH)
|