Repository navigation
Description
Problem or use case
A table.v1 outcome value (#823, #824) is JSON. A metric card can draw it. But many places that show a factory's results cannot draw a card: an agent conversation, a Slack message, a pull request comment and an email digest. They all show Markdown.
Today each of those would have to write its own conversion from {"rows": [...]} and the key's columns to a Markdown table. They would disagree on headers, links, empty cells and escaping. An agent writes each cell, so a wrong conversion can also let one cell break the table or inject Markdown.
Desired behavior
One documented, deterministic conversion from a table.v1 value to a GitHub Flavored Markdown table. The service owns it, so every client gets the same output.
The mapping:
- The header of a column is its
title, or itsnamewhen there is notitle. - The text of a cell is
fwhen the cell has one, andvotherwise. A null cell is empty. - A cell with an
hrefbecomes[text](href). Onlyhttps://URLs and/paths exist, because feat: add table.v1 shape for JSON outcome keys #824 refuses all others. - Cell text is plain text. The conversion escapes
|, backslash, backticks,[,],<,>,*and_, and turns a line break into a space. A cell cannot add columns or markup. - A number or integer column is right-aligned. All other columns are left-aligned.
- When
total_rowsis more than the number of rows, one line follows the table:Showing <rows> of <total_rows> rows. - An empty table renders the header and no rows, plus the same "Showing" line if
total_rowssays there are more.
Example. Input (columns: pr titled "PR", status, and lines as an integer):
{"rows": [[{"v": "#818", "href": "https://github.com/OpenHands/automation/pull/818"}, "open", 412],
[{"v": "#817", "f": "#817 (merged)"}, "merged", null]],
"total_rows": 140}Output:
| PR | status | lines |
| :-- | :-- | --: |
| [#818](https://github.com/OpenHands/automation/pull/818) | open | 412 |
| #817 (merged) | merged | |
Showing 2 of 140 rows.Acceptance criteria
- A function turns a
table.v1value and its columns into Markdown, with the mapping above. - Tests cover escaping of each special character, a link cell,
foverv, null cells, alignment, an empty table,total_rowslarger than the rows, and a cell with a line break. - A test renders a table with the most columns and rows that feat: add table.v1 shape for JSON outcome keys #824 allows, and checks that every row has the same number of cells.
- The same input always gives the same text.
-
uv run pre-commit run --all-filespasses.
Additional context
- Why the caps in feat: add table.v1 shape for JSON outcome keys #824 are small: a table has at most 8 columns and 20 rows, so its Markdown stays readable in a chat message or a comment. GitHub Flavored Markdown tables have no merged cells, no multi-line cells and no nesting, which is why
table.v1is flat. See the GFM tables extension. - Open question: where does the conversion run? A server route could return it, for example a
format=markdownoption on the read route. A shared helper could be called by the code that posts to Slack or to a pull request. Or only the client could do it. The first option gives one output for every client, but it adds an API surface. This issue does not decide. The first change can be the function alone. - Not part of this issue: how a card draws the table (the display layer), and the
lastaggregation that reads the latest table. - Depends on feat: add table.v1 shape for JSON outcome keys #824.
This issue was drafted by an AI agent on behalf of the user.
OpenHands AI triage
The following comments and acceptance criteria were added by the OpenHands AI agent.
Triage
The issue states the problem, the full mapping, a worked example and its own non-goals. It also answers its open question: it records that the first change is the conversion function alone, with no decision yet on where clients call it. Verified against the repository and the dependency: table.v1 is defined by #823 and implemented by open PR #824 (branch outcome-key-shapes), which fixes the caps at 8 columns and 20 rows, restricts an href to https:// URLs and / paths, and stores cells as plain values or {v, f, href} objects that round-trip unchanged. No Markdown rendering exists in the service today, and the read route returns JSON only, so the scope below is the function plus tests and nothing else.
Scope: one deterministic, documented conversion from a table.v1 value and its key's columns to a GitHub Flavored Markdown table, with the mapping exactly as the issue specifies, plus the tests listed in the issue's criteria.
Non-goals, per the issue: no format=markdown route or other API surface, no change to the read routes' JSON responses, no wiring into Slack, pull request or digest posting, no metric-card display layer, and no last aggregation. The function ships alone; callers are chosen later.
Acceptance Criteria
- A function renders a
table.v1value and its key'scolumnsas a GitHub Flavored Markdown table per the mapping in the issue: header istitleelsename; cell text isfelsevelse empty for null; anhrefcell renders as[text](href);|, backslash, backtick,[,],<,>,*and_are escaped and a line break becomes a space;numberandintegercolumns are right-aligned, others left-aligned. - A table with 1 column and 0 rows renders the header row and delimiter only; when
total_rowsis present and greater than the row count (including 0 rows), the output ends with exactlyShowing <rows> of <total_rows> rows.; whentotal_rowsis absent or equals the row count, no Showing line appears. - Rendering the issue's example value (columns
pr/status/linesinteger) reproduces the example's Markdown output exactly, character for character. - For a cell that is a non-string scalar (for example a boolean or number), the rendered text is the stored JSON scalar form (
true/false/digits), since the same text must serve every client. - Tests cover: each of the nine special characters escaped; a line break in a cell; a link cell;
fpreferred overv; null cells; alignment fornumber,integerand other types; an empty table;total_rowslarger than the row count. - A test renders a table at the feat: add table.v1 shape for JSON outcome keys #824 caps (8 columns, 20 rows) and checks that every row, including the header, has the same number of cells, so an escaped cell cannot change the column count.
- Rendering the same input twice yields identical text.
- The function is importable and callable without an HTTP request, and no route, response schema or client wiring changes; the read route's JSON output is unchanged.
-
uv run python -m pytestpasses for the new tests, anduv run pre-commit run --all-filespasses.
Activity