agora.observe.formatters

Render domain events as HTML-formatted Matrix messages.

Every formatter is a PURE function domain event -> `` :class:`FormattedMessage` (a ``content dict ready for matrix_client.send_event(room_id, "m.room.message", content)). Each produces both a plain body (clients that don’t render HTML) and an org.matrix.custom.html formatted_body (Element), escaping every interpolated value. That shared contract is the docstring for the one-line format_* renderers below; only the ones with a non-obvious contract (dual input shapes, optional artifact snapshot) carry their own.

Golden-tested: these functions are pure.

Functions

format_ack(text)

format_command_reference()

A compact, collapsed cheat sheet for the observer commands.

format_error(text)

format_help()

format_learning(learning)

format_note(sender, text)

format_phase_change(change)

format_review_summary(project_name, phase, ...)

Render a review summary.

format_task_completed(result_content)

Render a task-completion card (badge + artifacts + per-postcondition results).

format_task_started(task_content)

format_write_event(*, task_id, path, ...[, ...])

Render a compact card for a file-write event.

Classes

ArtifactSnapshot

What actually exists on disk at review time.

FormattedMessage

A Matrix message in both plain and HTML form.

class agora.observe.formatters.FormattedMessage[source]

Bases: object

A Matrix message in both plain and HTML form. msgtype defaults to m.notice so clients render these as bot output (dimmed) rather than as a human turn. to_content() produces the exact event content dict.

body: str
formatted_body: str
msgtype: str = 'm.notice'
to_content()[source]
__init__(body, formatted_body, msgtype='m.notice')
agora.observe.formatters.format_phase_change(change)[source]
agora.observe.formatters.format_task_started(task_content)[source]
agora.observe.formatters.format_task_completed(result_content)[source]

Render a task-completion card (badge + artifacts + per-postcondition results). Tolerates both postcondition-result shapes — dicts (MCP path) and (name, passed, reason) tuples (orchestrator path) — so the same formatter serves both callers; failed predicates show their reason, passed ones don’t.

agora.observe.formatters.format_learning(learning)[source]
class agora.observe.formatters.ArtifactSnapshot[source]

Bases: object

What actually exists on disk at review time.

ReviewCoordinator fills this in so the reviewer sees concrete files + recent commits + any failing gate before the vote, instead of voting on a black box.

files: list[tuple[str, int]]

[(relative_path, byte_count), ...] sorted by path.

recent_commits: list[str]

Short git log --oneline entries, most recent first.

postcondition_failures: list[tuple[str, str, str]]

[(task_id, predicate_name, reason), ...] for every failed postcondition.

reaction_counts: dict[str, dict[str, int]]

{task_id: {emoji_key: count}} aggregated across all reactions the reviewer left on that task’s cards during the run. Empty dict when no reactions were captured.

__init__(files, recent_commits, postcondition_failures, reaction_counts=<factory>)
agora.observe.formatters.format_review_summary(project_name, phase, task_results_summary, artifact=None)[source]

Render a review summary.

Accepts either dicts (MCP path) or TaskResult dataclass instances (orchestrator path); both carry success / task_id fields.

When artifact is provided, the review summary also shows the file tree, recent commits, and any failed postconditions — so the reviewer votes on concrete state rather than a name alone.

agora.observe.formatters.format_help()[source]
agora.observe.formatters.format_command_reference()[source]

A compact, collapsed cheat sheet for the observer commands.

Posted once per project at observer attach. Element users can expand the <details> block to see every verb without typing /agora help.

agora.observe.formatters.format_note(sender, text)[source]
agora.observe.formatters.format_ack(text)[source]
agora.observe.formatters.format_error(text)[source]
agora.observe.formatters.format_write_event(*, task_id, path, operation, size_bytes, hook_summary, preview=None)[source]

Render a compact card for a file-write event.

operation is e.g. "write", "edit:replace", "edit:insert_before", "edit:append", "fetch:save_as". hook_summary is a list of (tool_name, success) tuples from the auto-hook chain.

preview is an optional short (< ~2 KB) snippet of what was written; it’s rendered in a collapsed <details> block so the room stays legible on scroll but the reviewer can expand and see the actual bytes.