From e6d4cdb6f4024bff9b65037790c571d18ba69c95 Mon Sep 17 00:00:00 2001 From: Marco Craveiro Date: Sat, 5 Dec 2026 02:06:05 +0000 Subject: [PATCH 1/3] [web] List the open blame reports by sprint, and open them A page of documents carries its state and the sprint its path sits in, and a request may name a Status field whose value comes back as owner, validated so no other input reaches the expression. compass.web gains a Blames screen: reports grouped by sprint, newest first, open before addressed, filtered, each opening in the document view by its :ID:. Verified against a throwaway database seeded with three of ORE Studio's blame reports in Chromium; the story closes with it. Co-Authored-By: Claude Code --- doc/agile/versions/v0/sprint_01/sprint.org | 2 +- .../surface_the_open_blame_reports/story.org | 8 +- .../task_serve_the_open_blame_reports.org | 69 ++++++-- .../compass/compass_web_features.org | 13 +- .../messages/document_queries_protocol.hpp | 8 + .../compass.http.document_queries.org | 37 ++++ projects/compass.http/src/query/reads.cpp | 68 ++++++-- .../src/routes/document_queries_routes.cpp | 2 + .../compass.http/tests/query_reads_tests.cpp | 17 +- .../packages/pages/src/BlamesScreen.tsx | 163 ++++++++++++++++++ .../packages/pages/src/DocumentScreen.tsx | 3 + .../packages/pages/src/blames.test.tsx | 100 +++++++++++ .../compass.web/packages/pages/src/client.ts | 7 + .../compass.web/packages/pages/src/i18n/en.ts | 12 ++ .../compass.web/packages/pages/src/i18n/fr.ts | 12 ++ .../compass.web/packages/pages/src/i18n/pt.ts | 12 ++ .../packages/pages/src/screens.tsx | 12 +- 17 files changed, 506 insertions(+), 39 deletions(-) create mode 100644 projects/compass.web/packages/pages/src/BlamesScreen.tsx create mode 100644 projects/compass.web/packages/pages/src/blames.test.tsx diff --git a/doc/agile/versions/v0/sprint_01/sprint.org b/doc/agile/versions/v0/sprint_01/sprint.org index 1d87a687..905c43bb 100644 --- a/doc/agile/versions/v0/sprint_01/sprint.org +++ b/doc/agile/versions/v0/sprint_01/sprint.org @@ -73,7 +73,7 @@ Know what we build and what we must beat: the repository shape, and measured bas | [[id:41FD3A9B-6D52-44A2-9676-6EC5FD28F8A9][Trace a break to its cause]] | DONE | 2026-11-21 | 2026-11-21 | Every commit and pull request states its story, task and environment, and compass traces a finding on main to the commit, pull request and environment that likely caused it. | | [[id:67224021-6300-4FEE-BA62-518F2FEB22AB][Move the skill levels to the project]] | BACKLOG | | | The level of each skill becomes the project's data in a check document, compass stamps it and reports the slices, and ORE Studio's apply_skill_levels.py goes. | | [[id:F9ED1184-6A62-4B08-A2F7-D109E2C28605][Gate the knowledge titles]] | DONE | 2026-11-22 | 2026-11-22 | A check codec holds every knowledge page's title to a noun phrase and its file name to the title in snake case, from words a project's check document lists. | -| [[id:1874A6CC-3640-4A89-B07F-C9A5F6AAD5F2][Surface the open blame reports]] | STARTED | 2026-11-29 | | Show every environment the blame reports still open on main, its own first, when it lists them, after it merges or rebases main and when it runs a gate, from the report types a project names in its configuration. | +| [[id:1874A6CC-3640-4A89-B07F-C9A5F6AAD5F2][Surface the open blame reports]] | DONE | 2026-11-29 | 2026-12-05 | Show every environment the blame reports still open on main, its own first, when it lists them, after it merges or rebases main and when it runs a gate, from the report types a project names in its configuration. | | [[id:D8019709-7EF9-43E0-AC64-85DB34A078BE][Build the compass web front end]] | STARTED | 2026-11-29 | | Give developers and testers one web front end over compass's document service, compass.web in TypeScript on ores.web's stack over compass's C++ HTTP endpoints: search, documents, the sprint board with its stories and tasks, test runs with screenshots, a WebGL link graph and a local compass agent on llama.cpp, built in increments the product owner validates in a browser and ready to sit inside ores.web. | | [[id:0D43BBF9-C7E9-4A41-BFF2-CC15D6F0AEDA][Give codegen the model contract]] | DONE | 2026-12-03 | 2026-12-04 | Refuse, with a message naming the fix, a model that omits a section or property its templates need, so a new model cannot generate C++ that does not compile. | | [[id:4BD0292F-FA8C-4EB8-B31D-DAEDFE3BDA34][Share documents across projects and environments]] | BACKLOG | | | Decide where the truth of each kind of document lives once compass serves more than one project and each project more than one environment: what every environment shares, what stays in one environment until it merges (codegen models), how projects reference each other's documents, and what each view shows by default. | diff --git a/doc/agile/versions/v0/sprint_01/surface_the_open_blame_reports/story.org b/doc/agile/versions/v0/sprint_01/surface_the_open_blame_reports/story.org index 91ce66ac..7bf6d8a4 100644 --- a/doc/agile/versions/v0/sprint_01/surface_the_open_blame_reports/story.org +++ b/doc/agile/versions/v0/sprint_01/surface_the_open_blame_reports/story.org @@ -39,11 +39,11 @@ would have caught the breaks before they reached main. | Field | Value | |---------------+----------------------------------------| -| State | STARTED | +| State | DONE | | Parent sprint | [[id:850C1BC8-FE02-4EE0-A5D6-6085DC34CE27][Sprint 1]] | -| Now | =compass blames=, =check= and the git hooks show the open reports, the current environment's first and marked; the folder is analysed and three checks are proposed. The service query and the environment naming remain. | +| Now | Nothing. | | Waiting on | Nothing. | -| Next | Serve the open reports over HTTP and MCP. | +| Next | Nothing. | | Last touched | 2026-12-05 | * Acceptance @@ -68,7 +68,7 @@ would have caught the breaks before they reached main. |------+-------+-------+-----+-------------| | [[id:686B61EC-0AD8-4AEB-ADA7-1F9EAB504AC6][List the open blame reports]] | DONE | 2026-11-29 | 2026-12-04 | A compass blames command that lists the open reports of the types a project names, the current environment's first and marked, and the same short summary from check and the git hooks. | | [[id:62A4D200-9C15-4D37-A47C-CB593BD51D64][Analyse the blame reports during the sprint]] | DONE | | 2026-12-04 | Read the blame folder at points during the sprint, class the breaks it records, and find the proactive checks that would have caught them before they reached main. | -| [[id:BFCA17AF-5BDD-4B4B-8B07-5325F191C472][Serve the open blame reports]] | BACKLOG | | | Answer the open reports over the document service, as an HTTP read route and an MCP tool generated from the route models, so agents that read compass through it see them too. | +| [[id:BFCA17AF-5BDD-4B4B-8B07-5325F191C472][Serve the open blame reports]] | DONE | 2026-12-05 | 2026-12-05 | Answer the open reports over the document service, as an HTTP read route and an MCP tool generated from the route models, so agents that read compass through it see them too. | | [[id:8DFD6766-E279-4496-AAE6-A9CD7AC6457A][Unify environment names]] | DONE | 2026-12-05 | 2026-12-05 | Give an environment one name everywhere compass and its projects state one, by a migration that renames corpus.environment.name and the environment columns of activity in one transaction, not by naming it differently on the next sync. | * Decisions diff --git a/doc/agile/versions/v0/sprint_01/surface_the_open_blame_reports/task_serve_the_open_blame_reports.org b/doc/agile/versions/v0/sprint_01/surface_the_open_blame_reports/task_serve_the_open_blame_reports.org index 9a3b2f02..7d811850 100644 --- a/doc/agile/versions/v0/sprint_01/surface_the_open_blame_reports/task_serve_the_open_blame_reports.org +++ b/doc/agile/versions/v0/sprint_01/surface_the_open_blame_reports/task_serve_the_open_blame_reports.org @@ -7,8 +7,8 @@ #+level: s1 #+filetags: :blame:serve:surface_the_open_blame_reports:sprint_01:v0: #+owner: marco -#+branch: -#+pr: +#+branch: feature/serve-the-open-blame-reports +#+pr: 280 #+blocked_on: #+blocked_since: #+created: 2026-11-29 @@ -36,22 +36,39 @@ kinds first. | Field | Value | |--------------+----------------------------------------| -| State | BACKLOG | +| State | DONE | | Parent story | [[id:1874A6CC-3640-4A89-B07F-C9A5F6AAD5F2][Surface the open blame reports]] | -| Now | Not yet started. | +| Now | Done: the reports are a query, and a Blames screen groups them by sprint and opens each one. | | Waiting on | Nothing. | -| Next | Begin implementation. | -| Last touched | 2026-11-29 | +| Next | Nothing. | +| Last touched | 2026-12-05 | * Acceptance -- +- A page of an environment's documents carries its =State= and the sprint its + path sits in, so a report list can show both without a second read. +- A list request may name a =* Status= field and each summary carries its + value as =owner=; a name a regular expression would read specially is + refused and answers empty. +- compass.web has a Blames screen: the reports of a type grouped by sprint, + newest first, the open ones first within a group, filtered by open or + addressed, each opening in the document view by its =:ID:=. +- On a real folder, a report opens with its whole page rendered, its + =* Response= included. * Plan -(Implementation strategy. Written when work starts; key decisions -are distilled into the parent story's =* Decisions= at close, but the -plan itself stays — it is the historical record of what we did.) +1. The database already keeps each page's =State=, and a sprint is the + nearest =sprint_= in its path. Add both, and an optional =owner_field=, + to =document_summary=; the owner is read from the document's source by a + regular expression whose field name is validated to letters, digits, + spaces, =_= and =-=, so no other input reaches the expression. +2. A Blames screen lists the documents of a type, groups them by sprint and + filters by the lifecycle state: a page is closed when its state is =DONE= + or =ABANDONED=, open otherwise. Each row links to the document view by + =:ID:=. +3. Verify on a real folder: three ORE Studio blame reports synced into a + throwaway database, the screen driven in Chromium, a report opened. * Measurements @@ -65,10 +82,29 @@ task and name that file in the Command column. | What | Value | Command | Commit | |------+-------+---------+--------| -| | | | | +| =compass.http.tests= | 9836 assertions in 390 cases | =compass.http.tests= | this branch | +| =@compass/pages= vitest | 255 tests in 12 files | =npx vitest run= | this branch | +| Real folder, open filter | 1 of 3 reports | Chromium against the throwaway database | this branch | +| A report opened | whole page rendered, =* Response= included | Chromium, click through from the list | this branch | * Notes +- *The owner is read from the source at query time.* The database keeps a + page's state but not the field a project's reports use for an owner, and + the field's name is project data. The request names it, the server + validates the name, and the expression reads it from the stored source. + This costs a scan of each listed document's source; filling a column at + sync through the project's =* Open reports= table would replace it, and is + the follow-up when the list grows. +- *Closed means done or abandoned.* The database's state is the page's TODO + state, so the screen treats =DONE= and =ABANDONED= as closed and every + other state as open. A project whose open states differ needs the open + states from its =* Open reports= table instead; the =blames= command + already reads them. +- *The list is capped at 100*, the route's maximum; a page shows the first + hundred and says so through its count. Paging the screen is the follow-up + if a project keeps more than that. + * Test Scenarios Manual QA scenarios (scaffolded via =compass add test_scenario=) @@ -93,3 +129,14 @@ via its "Verifies task" field. | | | | | | * Result + +A page of documents now carries its state, its sprint and, when the request +names a =* Status= field, its owner. compass.web gained a Blames screen that +groups reports by sprint with open first, filters by open or addressed, and +opens any report in the document view by its =:ID:=; the screen is the +seventh in the menu, beside Documents. + +Verified on a throwaway database seeded with three of ORE Studio's blame +reports: the open filter showed the one started report with its owner, All +showed the three, and clicking one opened its page with the owner's +=* Response= rendered. diff --git a/doc/knowledge/compass/compass_web_features.org b/doc/knowledge/compass/compass_web_features.org index a489807f..09471813 100644 --- a/doc/knowledge/compass/compass_web_features.org +++ b/doc/knowledge/compass/compass_web_features.org @@ -41,6 +41,17 @@ marked unresolved rather than followed. The view also lists the document's images, the documents it links to, and the documents that link to it, each backlink with the heading path the link sits under. Documents are read-only. +** Blames + +The Blames screen lists the reports a project keeps open, the breaks main +reported and the environment that owns each. It groups them by sprint, the +newest first, the open ones before the addressed within a group, and filters +by open or addressed. Each row names the report, its environment, the sprint +and whether a response was written; opening one shows the whole page, the +owner's response included. The screen reads the document service, so a +project states the type and the owner field in its configuration and compass +names none of them. + ** The sprint The Sprint screen draws the environment's present or an earlier sprint as a @@ -101,7 +112,7 @@ first, so what the model no longer sees is counted rather than hidden. Every address names an environment, and the picker lists every environment the service holds, with the time of its last sync and its document count. All -six screens read only that environment. The server filters every read by the +every screen reads only that environment. The server filters every read by the caller's environment, subject and view: run alone, compass has no sign-in and local callers use the team view; behind ORE Studio's gateway, the caller's session supplies the subject and view, and a knowledge view sees only what diff --git a/projects/compass.http/include/compass.http/messages/document_queries_protocol.hpp b/projects/compass.http/include/compass.http/messages/document_queries_protocol.hpp index 4cf9f34b..1798b39e 100644 --- a/projects/compass.http/include/compass.http/messages/document_queries_protocol.hpp +++ b/projects/compass.http/include/compass.http/messages/document_queries_protocol.hpp @@ -331,6 +331,9 @@ struct document_summary { std::vector tags; std::string updated; std::string excerpt; + std::string state; + std::string sprint; + std::string owner; friend bool operator==(const document_summary&, const document_summary&) = default; }; @@ -349,6 +352,9 @@ struct document_summary { ::compass::db::codec::field{"tags", &document_summary::tags, true}, ::compass::db::codec::field{"updated", &document_summary::updated}, ::compass::db::codec::field{"excerpt", &document_summary::excerpt}, + ::compass::db::codec::field{"state", &document_summary::state}, + ::compass::db::codec::field{"sprint", &document_summary::sprint}, + ::compass::db::codec::field{"owner", &document_summary::owner}, }; } @@ -357,6 +363,7 @@ struct list_documents_request { document_filter filter; std::uint32_t limit = 50; std::uint32_t offset = 0; + std::optional owner_field; friend bool operator==(const list_documents_request&, const list_documents_request&) = default; }; @@ -371,6 +378,7 @@ struct list_documents_request { ::compass::db::codec::field{"filter", &list_documents_request::filter, true}, ::compass::db::codec::field{"limit", &list_documents_request::limit, true}, ::compass::db::codec::field{"offset", &list_documents_request::offset, true}, + ::compass::db::codec::field{"owner_field", &list_documents_request::owner_field}, }; } diff --git a/projects/compass.http/modeling/compass.http.document_queries.org b/projects/compass.http/modeling/compass.http.document_queries.org index 7240b7ed..16d22982 100644 --- a/projects/compass.http/modeling/compass.http.document_queries.org +++ b/projects/compass.http/modeling/compass.http.document_queries.org @@ -492,6 +492,31 @@ The document's =#+updated:=. The first lines of the document's body, clipped for a list. Empty when the document has no body text. +*** state +:PROPERTIES: +:cpp_type: std::string +:END: + +The document's =State= row, as the database derives it: =open= or +=addressed=. Empty when the page states none. + +*** sprint +:PROPERTIES: +:cpp_type: std::string +:END: + +The sprint the document's path sits in, the nearest =sprint_= segment. +Empty when the path has none. + +*** owner +:PROPERTIES: +:cpp_type: std::string +:END: + +The value the requested =owner_field= holds in the document's =* Status= +table, bare of its code marks. Empty when the request names no field or the +document states none. + ** list_documents_request :PROPERTIES: :tool: list_documents @@ -543,6 +568,18 @@ The most documents to answer, at most 100; a larger limit is refused as How many documents to skip, for the next page. +*** owner_field +:PROPERTIES: +:cpp_type: std::optional +:http_in: query +:END: + +A =* Status= field whose value each summary carries as =owner=, such as the +field that names the environment a report belongs to. A name of letters, +digits, spaces, =_= and =-=; any other is refused. Reading it scans each +document's source at query time; a column filled at sync would replace it. + + ** list_documents_response *** documents diff --git a/projects/compass.http/src/query/reads.cpp b/projects/compass.http/src/query/reads.cpp index c8e3b8ef..ecffa23a 100644 --- a/projects/compass.http/src/query/reads.cpp +++ b/projects/compass.http/src/query/reads.cpp @@ -45,13 +45,40 @@ using db::io::result; using db::query::statement; /// The columns of a document_summary of a document d at a placement p. -constexpr std::string_view summary_columns = - "coalesce(d.org_id, ''), coalesce(d.title, ''), coalesce(d.type, ''), " - "coalesce(d.description, ''), p.path, array_to_string(d.tags, E'\\x1f'), " - "coalesce(d.updated, ''), " - "coalesce(left(btrim(regexp_replace((SELECT s.text FROM corpus.section s " - "WHERE s.hash = d.hash AND s.text <> '' ORDER BY s.ord LIMIT 1), " - "'\\[\\[[^]]*\\]\\[([^]]*)\\]\\]', '\\1', 'g')), 320), '')"; +/** + * @brief Whether @p field can be read as a Status field: letters, digits, + * spaces, underscores and dashes. Nothing that a regular expression reads + * specially, because the field names the expression. + */ +bool safe_field(std::string_view field) { + if (field.empty() || !(std::isalpha(static_cast(field[0])))) + return false; + return std::ranges::all_of(field, [](char c) { + const auto u = static_cast(c); + return std::isalnum(u) || c == ' ' || c == '_' || c == '-'; + }); +} + +/// The columns of a document_summary of a document d at a placement p, with +/// the value @p owner_field holds in the document's Status table at the end. +std::string summary_columns(std::string_view owner_field) { + std::string out = + "coalesce(d.org_id, ''), coalesce(d.title, ''), coalesce(d.type, ''), " + "coalesce(d.description, ''), p.path, array_to_string(d.tags, E'\\x1f'), " + "coalesce(d.updated, ''), " + "coalesce(left(btrim(regexp_replace((SELECT s.text FROM corpus.section s " + "WHERE s.hash = d.hash AND s.text <> '' ORDER BY s.ord LIMIT 1), " + "'\\[\\[[^]]*\\]\\[([^]]*)\\]\\]', '\\1', 'g')), 320), ''), " + "coalesce(d.state, ''), " + "coalesce(substring(p.path from '(sprint_[0-9]+)'), ''), "; + if (safe_field(owner_field)) + out += "coalesce(trim(both ' `' from substring(d.source from " + "'\\| *" + std::string(owner_field) + + " *\\| *([^|\\n]*)')), '')"; + else + out += "''"; + return out; +} std::vector split_units(std::string_view joined) { std::vector out; @@ -77,6 +104,9 @@ messages::document_summary summary_at(const result& r, std::size_t row, std::siz s.tags = split_units(r.value(row, first + 5)); s.updated = r.value(row, first + 6); s.excerpt = r.value(row, first + 7); + s.state = r.value(row, first + 8); + s.sprint = r.value(row, first + 9); + s.owner = r.value(row, first + 10); return s; } @@ -434,7 +464,7 @@ messages::list_documents_response list_documents(db::io::connection& c, const messages::list_documents_request& r) { const auto e = db::query::find_environment(c, r.environment); statement s; - s.sql = "WITH listed AS (\nSELECT " + std::string(summary_columns) + + s.sql = "WITH listed AS (\nSELECT " + summary_columns(r.owner_field.value_or("")) + "\nFROM corpus.placement p JOIN corpus.document d ON d.hash = p.hash\n"; db::query::where_documents(s, e.id, v, to_db(r.filter)); s.sql += ")\nSELECT (SELECT count(*) FROM listed), listed.* FROM listed\n" @@ -462,7 +492,7 @@ std::optional read_document(db::io::connection& c, const messages::get_document_request& r) { const auto e = db::query::find_environment(c, r.environment); statement s; - s.sql = "SELECT " + std::string(summary_columns) + ", d.source, encode(d.hash, 'hex')\n" + s.sql = "SELECT " + summary_columns({}) + ", d.source, encode(d.hash, 'hex')\n" "FROM corpus.placement p JOIN corpus.document d ON d.hash = p.hash\n"; db::query::where_documents(s, e.id, v, {}); s.sql += " AND d.org_id = " + s.bind(r.id) + "\nORDER BY p.path LIMIT 1"; @@ -471,8 +501,8 @@ std::optional read_document(db::io::connection& c, return std::nullopt; document_source out; out.summary = summary_at(found, 0, 0); - out.source = found.value(0, 8); - out.hash = found.value(0, 9); + out.source = found.value(0, 11); + out.hash = found.value(0, 12); out.synced_at = e.synced_at; out.environment_id = e.id; @@ -601,7 +631,7 @@ std::optional backlinks(db::io::connection& c, return std::nullopt; statement s; - s.sql = "SELECT " + std::string(summary_columns) + ", coalesce(h.anchor, ''),\n" + s.sql = "SELECT " + summary_columns({}) + ", coalesce(h.anchor, ''),\n" " CASE WHEN l.text <> '' THEN l.text ELSE l.path END,\n" " encode(l.hash, 'hex'), l.ord, coalesce(l.heading_ord, -1), l.path\n" "FROM corpus.link l\n" @@ -615,7 +645,7 @@ std::optional backlinks(db::io::connection& c, statement holders; std::unordered_set hashes; for (std::size_t row = 0; row < rows.rows(); ++row) - hashes.emplace(rows.value(row, 10)); + hashes.emplace(rows.value(row, 13)); std::string in; for (const auto& hash : hashes) in += (in.empty() ? "decode(" : ", decode(") + holders.bind(hash) + ", 'hex')"; @@ -643,22 +673,22 @@ std::optional backlinks(db::io::connection& c, for (std::size_t row = 0; row < rows.rows(); ++row) { messages::backlink b; b.document = summary_at(rows, row, 0); - b.anchor = rows.value(row, 8); - b.text = rows.value(row, 9); - const std::string hash(rows.value(row, 10)); + b.anchor = rows.value(row, 11); + b.text = rows.value(row, 12); + const std::string hash(rows.value(row, 13)); if (hash != parsed) { parsed = hash; source = sources[hash]; tables = {}; compass::ingest::org::parse(source, tables); } - const auto heading = to_number(rows.value(row, 12)); + const auto heading = to_number(rows.value(row, 15)); if (heading >= 0) b.headings = heading_path(outlines[hash], static_cast(heading)); const auto t = ot::view(tables); - const auto ord = to_number(rows.value(row, 11)); + const auto ord = to_number(rows.value(row, 14)); if (ord < t.links.size() && - t.links.paths[ot::link_id{ord}].of(source) == rows.value(row, 13)) + t.links.paths[ot::link_id{ord}].of(source) == rows.value(row, 16)) b.excerpt = excerpt_of(source, t, link_range(t, ot::link_id{ord})); out.backlinks.push_back(std::move(b)); } diff --git a/projects/compass.http/src/routes/document_queries_routes.cpp b/projects/compass.http/src/routes/document_queries_routes.cpp index c562bacd..9deb0f27 100644 --- a/projects/compass.http/src/routes/document_queries_routes.cpp +++ b/projects/compass.http/src/routes/document_queries_routes.cpp @@ -150,6 +150,7 @@ compass::http::messages::list_documents_request bind_list_documents(const domain b.query("property", r.filter.properties, false); b.query("limit", r.limit, false); b.query("offset", r.offset, false); + b.query("owner_field", r.owner_field, false); b.finish(); return r; } @@ -172,6 +173,7 @@ void add_list_documents(net::router& r, list_documents_handler h) { .query_array("property", "string", false, "Only documents whose top-level property holds the value, each written NAME:value and split at the first colon.") .query_param("limit", "integer", "", false, "The most documents to answer, at most 100; a larger limit is refused as invalid.") .query_param("offset", "integer", "", false, "How many documents to skip, for the next page.") + .query_param("owner_field", "string", "", false, "A * Status field whose value each summary carries as owner, such as the field that names the environment a report belongs to. A name of letters, digits, spaces, _ and -; any other is refused. Reading it scans each document's source at query time; a column filled at sync would replace it.") .input() .response() .tool_call([h](const domain::caller& c, std::string_view arguments) { diff --git a/projects/compass.http/tests/query_reads_tests.cpp b/projects/compass.http/tests/query_reads_tests.cpp index 602ed48b..3f6eb49d 100644 --- a/projects/compass.http/tests/query_reads_tests.cpp +++ b/projects/compass.http/tests/query_reads_tests.cpp @@ -125,7 +125,7 @@ const corpus& seeded() { "#+filetags: :howto:\n")); add(page("SPRINT-1", "sprint", "Sprint 1", "user", "This page documents a sprint.\n\n* Status\n\n| Field | Value |\n" - "|-------+-------|\n| State | STARTED |", + "|-------+-------|\n| State | STARTED |\n| Owner | brave_hopper |", "#+created: 2026-11-01\n")); std::vector placed; for (std::size_t i = 0; i < documents.size(); ++i) @@ -494,6 +494,21 @@ TEST_CASE("documents lists the pages the view sees, filtered and paged", "[serve CHECK_THAT(past.body, ContainsSubstring("\"documents\":[]")); } +TEST_CASE("documents carries a Status field's value only when the request names " + "it, and only for a name it can read", "[serve][query]") { + const auto& data = seeded(); + reads r(data); + const auto owner = r.get("/v1/main/documents?type=sprint&owner_field=Owner"); + CHECK_THAT(owner.body, ContainsSubstring("\"owner\":\"brave_hopper\"")); + CHECK_THAT(owner.body, ContainsSubstring("\"state\":\"STARTED\"")); + + const auto none = r.get("/v1/main/documents?type=sprint"); + CHECK_THAT(none.body, ContainsSubstring("\"owner\":\"\"")); + + const auto unsafe = r.get("/v1/main/documents?type=sprint&owner_field=Owner%29"); + CHECK_THAT(unsafe.body, ContainsSubstring("\"owner\":\"\"")); +} + TEST_CASE("document answers a page's org source, never HTML, and only in a view that " "sees it", "[serve][query]") { const auto& data = seeded(); diff --git a/projects/compass.web/packages/pages/src/BlamesScreen.tsx b/projects/compass.web/packages/pages/src/BlamesScreen.tsx new file mode 100644 index 00000000..15df49f5 --- /dev/null +++ b/projects/compass.web/packages/pages/src/BlamesScreen.tsx @@ -0,0 +1,163 @@ +/** -*- mode: typescript-ts-mode; tab-width: 4; indent-tabs-mode: nil -*- + * + * Copyright (C) 2026 Marco Craveiro + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 3 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +import { keepPreviousData, useQuery } from '@tanstack/react-query'; +import type { ReactNode } from 'react'; +import { Link, useSearchParams } from 'react-router'; +import { retryable } from './client.js'; +import { useCompass } from './context.js'; +import { useTranslation } from './i18n/Provider.js'; + +/** The reports a project keeps open, by the type its pages carry. */ +export const BLAME_TYPE = 'blame_report'; +const OWNER_FIELD = 'Owner'; +/** A page is closed when its State is one a lifecycle ends in. */ +const CLOSED = new Set(['DONE', 'ABANDONED']); +const closed = (state: string): boolean => CLOSED.has(state.toUpperCase()); +const LIMIT = 100; + +/** + * The reports of one type, grouped by the sprint their path sits in, the + * open ones first, each opening in the document view by its :ID:. + */ +export function BlamesScreen({ environment }: { readonly environment: string }): ReactNode { + const { t, plural } = useTranslation(); + const { inputs, client } = useCompass(); + const [params] = useSearchParams(); + const type = params.get('type') ?? BLAME_TYPE; + const state = params.get('state') ?? 'open'; + const reports = useQuery({ + queryKey: ['compass', inputs.httpBase, 'documents', environment, { type, owner: OWNER_FIELD, state, limit: LIMIT }], + queryFn: ({ signal }) => + client.documents( + { environment, type, owner_field: OWNER_FIELD, limit: LIMIT, offset: 0 }, + signal, + ), + placeholderData: keepPreviousData, + retry: retryable, + }); + const all = reports.data?.documents ?? []; + const visible = + state === 'all' + ? all + : state === 'addressed' + ? all.filter((d) => closed(d.state)) + : all.filter((d) => !closed(d.state)); + const groups = new Map(); + for (const d of visible) { + const key = d.sprint === '' ? '' : d.sprint; + const list = groups.get(key) ?? []; + list.push(d); + groups.set(key, list); + } + const ordered = [...groups.entries()].sort((a, b) => b[0].localeCompare(a[0], 'en', { numeric: true })); + const shown = (next: string) => { + const out = new URLSearchParams(); + out.set('type', type); + out.set('state', next); + return { search: `?${out.toString()}` }; + }; + + return ( +
+
+ {(['open', 'addressed', 'all'] as const).map((key) => ( + + {t(`blames.filter.${key}`)} + + ))} + + {plural('blames.count', visible.length)} + +
+ {reports.isPending ? ( +

{t('blames.loading')}

+ ) : reports.isError ? ( +

{t('blames.failed', { reason: reports.error.message })}

+ ) : visible.length === 0 ? ( +

+ {t('blames.empty')} +

+ ) : ( +
+ {ordered.map(([sprint, rows]) => ( +
+

+ {sprint === '' ? t('blames.noSprint') : sprint.replace(/_/g, ' ')} + {rows.length} +

+
    + {rows.map((d) => ( +
  • +
    + + {d.state === '' ? '—' : d.state} + + {d.org_id === '' ? ( + {d.title} + ) : ( + + {d.title} + + )} +
    +
    + {d.path} + {d.owner === '' ? null : ( + owner {d.owner} + )} +
    + {d.excerpt === '' ? null : ( +

    {d.excerpt}

    + )} +
  • + ))} +
+
+ ))} +
+ )} +
+ ); +} diff --git a/projects/compass.web/packages/pages/src/DocumentScreen.tsx b/projects/compass.web/packages/pages/src/DocumentScreen.tsx index 578be282..daab0014 100644 --- a/projects/compass.web/packages/pages/src/DocumentScreen.tsx +++ b/projects/compass.web/packages/pages/src/DocumentScreen.tsx @@ -716,6 +716,9 @@ export function OrgFragment({ tags: [], updated: '', excerpt: '', + state: '', + sprint: '', + owner: '', }, body: org, anchors: [], diff --git a/projects/compass.web/packages/pages/src/blames.test.tsx b/projects/compass.web/packages/pages/src/blames.test.tsx new file mode 100644 index 00000000..48748acd --- /dev/null +++ b/projects/compass.web/packages/pages/src/blames.test.tsx @@ -0,0 +1,100 @@ +/** -*- mode: typescript-ts-mode; tab-width: 4; indent-tabs-mode: nil -*- + * + * Copyright (C) 2026 Marco Craveiro + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 3 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; +import { renderToStaticMarkup } from 'react-dom/server'; +import { createMemoryRouter, RouterProvider } from 'react-router'; +import { describe, expect, it } from 'vitest'; +import type { CompassInputs } from './context.js'; +import { CompassPagesProvider } from './context.js'; +import type { Environment } from './environments.js'; +import { environmentsKey } from './environments.js'; +import { compassRoutes } from './pages.js'; + +const inputs: CompassInputs = { + httpBase: '/', + linkTo: (place) => + 'document' in place ? `/${place.environment}/docs/${place.document}` : `/${place.environment}/${place.screen ?? ''}`, + onDenied: () => undefined, +}; + +const environments: Environment[] = [ + { name: 'compass', kind: 'worktree', synced_at: '2026-12-05T09:00:00Z', documents: 3 }, +]; + +const report = (id: string, title: string, state: string, sprint: string, path: string) => ({ + org_id: id, + title, + type: 'blame_report', + description: '', + path, + tags: [], + updated: '2026-12-05', + excerpt: 'The suite asserts the old route.', + state, + sprint, + owner: id === 'B1' ? 'eager_maxwell' : 'solid_dirac', +}); + +const documents = { + documents: [report('B1', 'Blame: the first', 'open', 'sprint_31', 'doc/sprint_31/blame/a.org'), + report('B2', 'Blame: the second', 'addressed', 'sprint_31', 'doc/sprint_31/blame/b.org'), + report('B0', 'Blame: the earlier', 'open', 'sprint_30', 'doc/sprint_30/blame/c.org')], + total: 3, + synced_at: '2026-12-05T09:00:00Z', +}; + +function draw(address: string, state: string): string { + const queries = new QueryClient(); + queries.setQueryData(environmentsKey(inputs.httpBase), environments); + queries.setQueryData( + ['compass', '/', 'documents', 'compass', { type: 'blame_report', owner: 'Owner', state, limit: 100 }], + documents, + ); + const router = createMemoryRouter(compassRoutes(), { initialEntries: [address] }); + return renderToStaticMarkup( + + + + + , + ); +} + +describe('the blames screen', () => { + it('groups the reports by sprint, newest sprint first, each opening by its :ID:', () => { + const html = draw('/compass/blames?state=all', 'all'); + expect(html).toContain('sprint 31'); + expect(html).toContain('sprint 30'); + expect(html.indexOf('sprint 31')).toBeLessThan(html.indexOf('sprint 30')); + expect(html).toMatch(/href="\/compass\/docs\/B1"[^>]*>Blame: the first<\/a>/); + expect(html).toContain('3 reports'); + expect(html).toContain('owner eager_maxwell'); + }); + + it('shows only the open reports until the filter says otherwise', () => { + const html = draw('/compass/blames', 'open'); + expect(html).toContain('Blame: the first'); + expect(html).toContain('Blame: the earlier'); + expect(html).not.toContain('Blame: the second'); + expect(html).toContain('2 reports'); + expect(html).toMatch(/href="\/compass\/blames\?type=blame_report&state=all"[^>]*>All<\/a>/); + }); +}); diff --git a/projects/compass.web/packages/pages/src/client.ts b/projects/compass.web/packages/pages/src/client.ts index ec8b75c2..75162ee3 100644 --- a/projects/compass.web/packages/pages/src/client.ts +++ b/projects/compass.web/packages/pages/src/client.ts @@ -94,6 +94,9 @@ export const documentSummarySchema = z.object({ tags: z.array(z.string()), updated: z.string(), excerpt: z.string(), + state: z.string(), + sprint: z.string(), + owner: z.string(), }); /** The document a link opens, as compass.http resolved it under the caller's view. */ @@ -828,6 +831,7 @@ export interface CompassClient { query: { readonly environment: string; readonly type?: string; + readonly owner_field?: string; readonly limit: number; readonly offset: number; }, @@ -1151,6 +1155,9 @@ export function createClient( if (query.type !== undefined) { params.set('type', query.type); } + if (query.owner_field !== undefined) { + params.set('owner_field', query.owner_field); + } params.set('limit', String(query.limit)); params.set('offset', String(query.offset)); return read( diff --git a/projects/compass.web/packages/pages/src/i18n/en.ts b/projects/compass.web/packages/pages/src/i18n/en.ts index 8010b899..9d8f7d62 100644 --- a/projects/compass.web/packages/pages/src/i18n/en.ts +++ b/projects/compass.web/packages/pages/src/i18n/en.ts @@ -113,6 +113,14 @@ export const en: Catalogue = { count: { one: '{count} document, by path', other: '{count} documents, by path' }, pages: 'Pages of documents', }, + blames: { + loading: 'Reading the reports…', + failed: 'compass.http did not answer the reports: {reason}', + count: { one: '{count} report', other: '{count} reports' }, + filter: { all: 'All', open: 'Open', addressed: 'Addressed' }, + empty: 'No report matches this filter.', + noSprint: 'No sprint', + }, document: { loading: 'Reading the document…', failed: 'compass.http did not answer the document: {reason}', @@ -543,6 +551,10 @@ export const en: Catalogue = { title: 'Documents', task: 'Read a document in the browser', what: 'the document view: its metadata, its org rendered in the browser, its links, anchors, images and backlinks', + }, blames: { + title: 'Blames', + task: 'Serve the open blame reports', + what: 'the reports a project keeps open, by sprint, the open ones first, each opening in the document view', }, sprint: { title: 'Sprint', diff --git a/projects/compass.web/packages/pages/src/i18n/fr.ts b/projects/compass.web/packages/pages/src/i18n/fr.ts index 04ccb575..50cf061d 100644 --- a/projects/compass.web/packages/pages/src/i18n/fr.ts +++ b/projects/compass.web/packages/pages/src/i18n/fr.ts @@ -111,6 +111,14 @@ const fr: Catalogue = { count: { one: '{count} document, par chemin', other: '{count} documents, par chemin' }, pages: 'Pages de documents', }, + blames: { + loading: 'Lecture des rapports…', + failed: 'compass.http n\'a pas répondu aux rapports : {reason}', + count: { one: '{count} rapport', other: '{count} rapports' }, + filter: { all: 'Tous', open: 'Ouverts', addressed: 'Traités' }, + empty: 'Aucun rapport ne correspond à ce filtre.', + noSprint: 'Sans sprint', + }, document: { loading: 'Lecture du document…', failed: "compass.http n'a pas répondu avec le document : {reason}", @@ -557,6 +565,10 @@ const fr: Catalogue = { title: 'Documents', task: 'Read a document in the browser', what: 'la vue du document : ses métadonnées, son org rendu dans le navigateur, ses liens, ancres, images et rétroliens', + }, blames: { + title: 'Blâmes', + task: 'Serve the open blame reports', + what: 'les rapports qu\'un projet garde ouverts, par sprint, les ouverts d\'abord, chacun s\'ouvrant dans la vue document', }, sprint: { title: 'Sprint', diff --git a/projects/compass.web/packages/pages/src/i18n/pt.ts b/projects/compass.web/packages/pages/src/i18n/pt.ts index e35a5f55..b4688d2c 100644 --- a/projects/compass.web/packages/pages/src/i18n/pt.ts +++ b/projects/compass.web/packages/pages/src/i18n/pt.ts @@ -111,6 +111,14 @@ const pt: Catalogue = { count: { one: '{count} documento, por caminho', other: '{count} documentos, por caminho' }, pages: 'Páginas de documentos', }, + blames: { + loading: 'A ler os relatórios…', + failed: 'compass.http não respondeu aos relatórios: {reason}', + count: { one: '{count} relatório', other: '{count} relatórios' }, + filter: { all: 'Todos', open: 'Abertos', addressed: 'Tratados' }, + empty: 'Nenhum relatório corresponde a este filtro.', + noSprint: 'Sem sprint', + }, document: { loading: 'A ler o documento…', failed: 'O compass.http não respondeu com o documento: {reason}', @@ -552,6 +560,10 @@ const pt: Catalogue = { title: 'Documentos', task: 'Read a document in the browser', what: 'a vista do documento: os seus metadados, o seu org desenhado no browser, as suas ligações, âncoras, imagens e ligações de entrada', + }, blames: { + title: 'Acusações', + task: 'Serve the open blame reports', + what: 'os relatórios que um projeto mantém abertos, por sprint, os abertos primeiro, cada um a abrir na vista do documento', }, sprint: { title: 'Sprint', diff --git a/projects/compass.web/packages/pages/src/screens.tsx b/projects/compass.web/packages/pages/src/screens.tsx index 4fd1af9c..c25703bf 100644 --- a/projects/compass.web/packages/pages/src/screens.tsx +++ b/projects/compass.web/packages/pages/src/screens.tsx @@ -20,6 +20,7 @@ import type { ComponentType, ReactNode } from 'react'; import { AgentScreen } from './AgentPanel.js'; +import { BlamesScreen } from './BlamesScreen.js'; import { DocumentsScreen } from './DocumentsScreen.js'; import { GraphScreen } from './GraphScreen.js'; import { SearchScreen } from './SearchScreen.js'; @@ -27,12 +28,12 @@ import { SprintScreen } from './SprintScreen.js'; import { TestingScreen } from './TestingScreen.js'; /** - * The six screens of compass.web, in the menu's order, as the shell prototype + * The screens of compass.web, in the menu's order, as the shell prototype * signed off. The menu, the routes and the screens' titles all read this * table; a screen's catalogue entries are `screens..title`, `.task` (the * task that builds it) and `.what` (what that task builds). */ -export const SCREEN_KEYS = ['search', 'documents', 'sprint', 'testing', 'graph', 'agent'] as const; +export const SCREEN_KEYS = ['search', 'documents', 'blames', 'sprint', 'testing', 'graph', 'agent'] as const; export type ScreenKey = (typeof SCREEN_KEYS)[number]; @@ -53,6 +54,7 @@ export const SCREEN_PAGES: Readonly< > = { search: SearchScreen, documents: DocumentsScreen, + blames: BlamesScreen, sprint: SprintScreen, testing: TestingScreen, graph: GraphScreen, @@ -76,6 +78,12 @@ const ICON_PATHS: Readonly> = { ), + blames: ( + <> + + + + ), sprint: ( <> From f508193fd46f70247f6343affcc02c13ac0e909b Mon Sep 17 00:00:00 2001 From: Marco Craveiro Date: Sat, 5 Dec 2026 02:21:52 +0000 Subject: [PATCH 2/3] [web] Shape the blames screen like the prototype Count tiles first, then the three views: by sprint with the state filter, outstanding grouped by owner oldest first, and an analysis of owner load, the open-addressed split and the days reports were filed. Each row carries the owner and the age, and the list request now also returns the created date. Co-Authored-By: Claude Code --- .../task_serve_the_open_blame_reports.org | 19 +- .../messages/document_queries_protocol.hpp | 2 + .../compass.http.document_queries.org | 8 + projects/compass.http/src/query/reads.cpp | 20 +- .../packages/pages/src/BlamesScreen.tsx | 334 +++++++++++++----- .../packages/pages/src/DocumentScreen.tsx | 1 + .../packages/pages/src/blames.test.tsx | 33 +- .../compass.web/packages/pages/src/client.ts | 1 + .../compass.web/packages/pages/src/i18n/en.ts | 7 + .../compass.web/packages/pages/src/i18n/fr.ts | 7 + .../compass.web/packages/pages/src/i18n/pt.ts | 7 + 11 files changed, 327 insertions(+), 112 deletions(-) diff --git a/doc/agile/versions/v0/sprint_01/surface_the_open_blame_reports/task_serve_the_open_blame_reports.org b/doc/agile/versions/v0/sprint_01/surface_the_open_blame_reports/task_serve_the_open_blame_reports.org index 7d811850..64e9038f 100644 --- a/doc/agile/versions/v0/sprint_01/surface_the_open_blame_reports/task_serve_the_open_blame_reports.org +++ b/doc/agile/versions/v0/sprint_01/surface_the_open_blame_reports/task_serve_the_open_blame_reports.org @@ -50,9 +50,12 @@ kinds first. - A list request may name a =* Status= field and each summary carries its value as =owner=; a name a regular expression would read specially is refused and answers empty. -- compass.web has a Blames screen: the reports of a type grouped by sprint, - newest first, the open ones first within a group, filtered by open or - addressed, each opening in the document view by its =:ID:=. +- compass.web has a Blames screen shaped like the prototype the product owner + signed off: count tiles first; three views; *By sprint* groups the reports + with a filter by state; *Outstanding* groups the open ones by owner, oldest + first; *Analysis* counts each owner's load, the open and addressed split, + and the days reports were filed on. Every row opens in the document view + by its =:ID:=. - On a real folder, a report opens with its whole page rendered, its =* Response= included. @@ -130,11 +133,11 @@ via its "Verifies task" field. * Result -A page of documents now carries its state, its sprint and, when the request -names a =* Status= field, its owner. compass.web gained a Blames screen that -groups reports by sprint with open first, filters by open or addressed, and -opens any report in the document view by its =:ID:=; the screen is the -seventh in the menu, beside Documents. +A page of documents now carries its state, its sprint, its created date and, +when the request names a =* Status= field, its owner. compass.web gained the +Blames screen from the prototype: count tiles, the By sprint, Outstanding and +Analysis views, and every row opening in the document view by its =:ID:=. +It is the seventh screen in the menu, beside Documents. Verified on a throwaway database seeded with three of ORE Studio's blame reports: the open filter showed the one started report with its owner, All diff --git a/projects/compass.http/include/compass.http/messages/document_queries_protocol.hpp b/projects/compass.http/include/compass.http/messages/document_queries_protocol.hpp index 1798b39e..0661423f 100644 --- a/projects/compass.http/include/compass.http/messages/document_queries_protocol.hpp +++ b/projects/compass.http/include/compass.http/messages/document_queries_protocol.hpp @@ -334,6 +334,7 @@ struct document_summary { std::string state; std::string sprint; std::string owner; + std::string created; friend bool operator==(const document_summary&, const document_summary&) = default; }; @@ -355,6 +356,7 @@ struct document_summary { ::compass::db::codec::field{"state", &document_summary::state}, ::compass::db::codec::field{"sprint", &document_summary::sprint}, ::compass::db::codec::field{"owner", &document_summary::owner}, + ::compass::db::codec::field{"created", &document_summary::created}, }; } diff --git a/projects/compass.http/modeling/compass.http.document_queries.org b/projects/compass.http/modeling/compass.http.document_queries.org index 16d22982..aec0cb2a 100644 --- a/projects/compass.http/modeling/compass.http.document_queries.org +++ b/projects/compass.http/modeling/compass.http.document_queries.org @@ -517,6 +517,14 @@ The value the requested =owner_field= holds in the document's =* Status= table, bare of its code marks. Empty when the request names no field or the document states none. +*** created +:PROPERTIES: +:cpp_type: std::string +:END: + +The document's =#+created:=, which a list shows as the page's age. Empty +when the page states none. + ** list_documents_request :PROPERTIES: :tool: list_documents diff --git a/projects/compass.http/src/query/reads.cpp b/projects/compass.http/src/query/reads.cpp index ecffa23a..2fd5cbc8 100644 --- a/projects/compass.http/src/query/reads.cpp +++ b/projects/compass.http/src/query/reads.cpp @@ -77,6 +77,7 @@ std::string summary_columns(std::string_view owner_field) { " *\\| *([^|\\n]*)')), '')"; else out += "''"; + out += ", coalesce(d.created, '')"; return out; } @@ -107,6 +108,7 @@ messages::document_summary summary_at(const result& r, std::size_t row, std::siz s.state = r.value(row, first + 8); s.sprint = r.value(row, first + 9); s.owner = r.value(row, first + 10); + s.created = r.value(row, first + 11); return s; } @@ -501,8 +503,8 @@ std::optional read_document(db::io::connection& c, return std::nullopt; document_source out; out.summary = summary_at(found, 0, 0); - out.source = found.value(0, 11); - out.hash = found.value(0, 12); + out.source = found.value(0, 12); + out.hash = found.value(0, 13); out.synced_at = e.synced_at; out.environment_id = e.id; @@ -645,7 +647,7 @@ std::optional backlinks(db::io::connection& c, statement holders; std::unordered_set hashes; for (std::size_t row = 0; row < rows.rows(); ++row) - hashes.emplace(rows.value(row, 13)); + hashes.emplace(rows.value(row, 14)); std::string in; for (const auto& hash : hashes) in += (in.empty() ? "decode(" : ", decode(") + holders.bind(hash) + ", 'hex')"; @@ -673,22 +675,22 @@ std::optional backlinks(db::io::connection& c, for (std::size_t row = 0; row < rows.rows(); ++row) { messages::backlink b; b.document = summary_at(rows, row, 0); - b.anchor = rows.value(row, 11); - b.text = rows.value(row, 12); - const std::string hash(rows.value(row, 13)); + b.anchor = rows.value(row, 12); + b.text = rows.value(row, 13); + const std::string hash(rows.value(row, 14)); if (hash != parsed) { parsed = hash; source = sources[hash]; tables = {}; compass::ingest::org::parse(source, tables); } - const auto heading = to_number(rows.value(row, 15)); + const auto heading = to_number(rows.value(row, 16)); if (heading >= 0) b.headings = heading_path(outlines[hash], static_cast(heading)); const auto t = ot::view(tables); - const auto ord = to_number(rows.value(row, 14)); + const auto ord = to_number(rows.value(row, 15)); if (ord < t.links.size() && - t.links.paths[ot::link_id{ord}].of(source) == rows.value(row, 16)) + t.links.paths[ot::link_id{ord}].of(source) == rows.value(row, 17)) b.excerpt = excerpt_of(source, t, link_range(t, ot::link_id{ord})); out.backlinks.push_back(std::move(b)); } diff --git a/projects/compass.web/packages/pages/src/BlamesScreen.tsx b/projects/compass.web/packages/pages/src/BlamesScreen.tsx index 15df49f5..7b54635c 100644 --- a/projects/compass.web/packages/pages/src/BlamesScreen.tsx +++ b/projects/compass.web/packages/pages/src/BlamesScreen.tsx @@ -21,6 +21,7 @@ import { keepPreviousData, useQuery } from '@tanstack/react-query'; import type { ReactNode } from 'react'; import { Link, useSearchParams } from 'react-router'; +import type { DocumentSummary } from './client.js'; import { retryable } from './client.js'; import { useCompass } from './context.js'; import { useTranslation } from './i18n/Provider.js'; @@ -28,14 +29,63 @@ import { useTranslation } from './i18n/Provider.js'; /** The reports a project keeps open, by the type its pages carry. */ export const BLAME_TYPE = 'blame_report'; const OWNER_FIELD = 'Owner'; +const LIMIT = 100; /** A page is closed when its State is one a lifecycle ends in. */ const CLOSED = new Set(['DONE', 'ABANDONED']); const closed = (state: string): boolean => CLOSED.has(state.toUpperCase()); -const LIMIT = 100; +const VIEWS = ['sprint', 'outstanding', 'analysis'] as const; +type View = (typeof VIEWS)[number]; + +function ageOf(d: DocumentSummary): number | null { + const at = Date.parse(d.created); + if (Number.isNaN(at)) return null; + return Math.max(0, Math.floor((Date.now() - at) / 86_400_000)); +} + +function Tiles({ reports }: { readonly reports: readonly DocumentSummary[] }): ReactNode { + const { t } = useTranslation(); + const open = reports.filter((d) => !closed(d.state)).length; + const tiles = [ + { key: 'total', value: reports.length }, + { key: 'open', value: open }, + { key: 'addressed', value: reports.length - open }, + { key: 'unowned', value: reports.filter((d) => d.owner === '').length }, + ]; + return ( +
+ {tiles.map((tile) => ( +
+
+ {tile.value} +
+
{t(`blames.tiles.${tile.key}`)}
+
+ ))} +
+ ); +} + +function Bars({ entries }: { readonly entries: readonly (readonly [string, number])[] }): ReactNode { + const top = Math.max(...entries.map(([, n]) => n), 1); + return ( +
    + {entries.map(([label, n]) => ( +
  • + {label} + + + + {n} +
  • + ))} +
+ ); +} /** - * The reports of one type, grouped by the sprint their path sits in, the - * open ones first, each opening in the document view by its :ID:. + * The reports a project keeps open: their state, owner and sprint, the open + * ones first, each opening in the document view by its :ID:. The address + * names the view, the type and the state filter. */ export function BlamesScreen({ environment }: { readonly environment: string }): ReactNode { const { t, plural } = useTranslation(); @@ -43,6 +93,8 @@ export function BlamesScreen({ environment }: { readonly environment: string }): const [params] = useSearchParams(); const type = params.get('type') ?? BLAME_TYPE; const state = params.get('state') ?? 'open'; + const wanted = params.get('view') ?? 'sprint'; + const view: View = (VIEWS as readonly string[]).includes(wanted) ? (wanted as View) : 'sprint'; const reports = useQuery({ queryKey: ['compass', inputs.httpBase, 'documents', environment, { type, owner: OWNER_FIELD, state, limit: LIMIT }], queryFn: ({ signal }) => @@ -54,110 +106,210 @@ export function BlamesScreen({ environment }: { readonly environment: string }): retry: retryable, }); const all = reports.data?.documents ?? []; - const visible = - state === 'all' - ? all - : state === 'addressed' - ? all.filter((d) => closed(d.state)) - : all.filter((d) => !closed(d.state)); - const groups = new Map(); - for (const d of visible) { - const key = d.sprint === '' ? '' : d.sprint; - const list = groups.get(key) ?? []; - list.push(d); - groups.set(key, list); - } - const ordered = [...groups.entries()].sort((a, b) => b[0].localeCompare(a[0], 'en', { numeric: true })); - const shown = (next: string) => { + const open = all.filter((d) => !closed(d.state)); + const visible = state === 'all' ? all : state === 'addressed' ? all.filter((d) => closed(d.state)) : open; + const href = (next: { readonly state?: string; readonly view?: string }) => { const out = new URLSearchParams(); out.set('type', type); - out.set('state', next); + out.set('state', next.state ?? state); + out.set('view', next.view ?? view); return { search: `?${out.toString()}` }; }; + if (reports.isPending) { + return

{t('blames.loading')}

; + } + if (reports.isError) { + return

{t('blames.failed', { reason: reports.error.message })}

; + } + + const sprints = new Map(); + for (const d of visible) { + const list = sprints.get(d.sprint) ?? []; + list.push(d); + sprints.set(d.sprint, list); + } + const ordered = [...sprints.entries()].sort((a, b) => b[0].localeCompare(a[0], 'en', { numeric: true })); + const owners = new Map(); + for (const d of [...open].sort((a, b) => (ageOf(b) ?? 0) - (ageOf(a) ?? 0))) { + const owner = d.owner === '' ? t('blames.noOwner') : d.owner; + const list = owners.get(owner) ?? []; + list.push(d); + owners.set(owner, list); + } + const ownerLoad = [...all.reduce((m, d) => { + const key = d.owner === '' ? t('blames.noOwner') : d.owner; + m.set(key, (m.get(key) ?? 0) + 1); + return m; + }, new Map())].sort((a, b) => b[1] - a[1]); + const filed = [...all.reduce((m, d) => { + const day = d.created === '' ? '?' : d.created; + m.set(day, (m.get(day) ?? 0) + 1); + return m; + }, new Map())].sort((a, b) => a[0].localeCompare(b[0])); + return ( -
-
- {(['open', 'addressed', 'all'] as const).map((key) => ( +
+ +
- {reports.isPending ? ( -

{t('blames.loading')}

- ) : reports.isError ? ( -

{t('blames.failed', { reason: reports.error.message })}

- ) : visible.length === 0 ? ( -

- {t('blames.empty')} -

+ + + {view === 'sprint' ? ( +
+
+ {(['open', 'addressed', 'all'] as const).map((key) => ( + + {t(`blames.filter.${key}`)} + + ))} + + {plural('blames.count', visible.length)} + +
+ {visible.length === 0 ? ( +

+ {t('blames.empty')} +

+ ) : ( +
+ {ordered.map(([sprint, rows]) => ( +
+

+ {sprint === '' ? t('blames.noSprint') : sprint.replace(/_/g, ' ')} + {rows.length} +

+
    + {rows.map((d) => ( + + ))} +
+
+ ))} +
+ )} +
+ ) : view === 'outstanding' ? ( + open.length === 0 ? ( +

+ {t('blames.outstanding.empty')} +

+ ) : ( +
+ {[...owners.entries()].map(([owner, rows]) => ( +
+

+ {owner} + {rows.length} +

+
    + {rows.map((d) => ( + + ))} +
+
+ ))} +
+ ) ) : ( -
- {ordered.map(([sprint, rows]) => ( -
-

- {sprint === '' ? t('blames.noSprint') : sprint.replace(/_/g, ' ')} - {rows.length} -

-
    - {rows.map((d) => ( -
  • -
    - - {d.state === '' ? '—' : d.state} - - {d.org_id === '' ? ( - {d.title} - ) : ( - - {d.title} - - )} -
    -
    - {d.path} - {d.owner === '' ? null : ( - owner {d.owner} - )} -
    - {d.excerpt === '' ? null : ( -

    {d.excerpt}

    - )} -
  • - ))} -
-
- ))} +
+
+

+ {t('blames.analysis.owners')} +

+ +
+
+

+ {t('blames.analysis.states')} +

+ +
+
+

+ {t('blames.analysis.filed')} +

+ +
)}
); } + +function ReportRow({ + environment, + report: d, +}: { + readonly environment: string; + readonly report: DocumentSummary; +}): ReactNode { + const { t } = useTranslation(); + const { inputs } = useCompass(); + const age = ageOf(d); + return ( +
  • +
    + + {d.state === '' ? '—' : d.state} + + {d.org_id === '' ? ( + {d.title} + ) : ( + + {d.title} + + )} + {d.owner === '' ? null : ( + + {t('blames.owner', { owner: d.owner })} + + )} + {age === null ? null : {t('blames.age', { days: age })}} +
    +
    {d.path}
    + {d.excerpt === '' ? null : ( +

    {d.excerpt}

    + )} +
  • + ); +} diff --git a/projects/compass.web/packages/pages/src/DocumentScreen.tsx b/projects/compass.web/packages/pages/src/DocumentScreen.tsx index daab0014..50246c21 100644 --- a/projects/compass.web/packages/pages/src/DocumentScreen.tsx +++ b/projects/compass.web/packages/pages/src/DocumentScreen.tsx @@ -719,6 +719,7 @@ export function OrgFragment({ state: '', sprint: '', owner: '', + created: '', }, body: org, anchors: [], diff --git a/projects/compass.web/packages/pages/src/blames.test.tsx b/projects/compass.web/packages/pages/src/blames.test.tsx index 48748acd..1577a027 100644 --- a/projects/compass.web/packages/pages/src/blames.test.tsx +++ b/projects/compass.web/packages/pages/src/blames.test.tsx @@ -51,12 +51,13 @@ const report = (id: string, title: string, state: string, sprint: string, path: state, sprint, owner: id === 'B1' ? 'eager_maxwell' : 'solid_dirac', + created: '2026-11-29', }); const documents = { - documents: [report('B1', 'Blame: the first', 'open', 'sprint_31', 'doc/sprint_31/blame/a.org'), - report('B2', 'Blame: the second', 'addressed', 'sprint_31', 'doc/sprint_31/blame/b.org'), - report('B0', 'Blame: the earlier', 'open', 'sprint_30', 'doc/sprint_30/blame/c.org')], + documents: [report('B1', 'Blame: the first', 'STARTED', 'sprint_31', 'doc/sprint_31/blame/a.org'), + report('B2', 'Blame: the second', 'DONE', 'sprint_31', 'doc/sprint_31/blame/b.org'), + report('B0', 'Blame: the earlier', 'STARTED', 'sprint_30', 'doc/sprint_30/blame/c.org')], total: 3, synced_at: '2026-12-05T09:00:00Z', }; @@ -79,6 +80,16 @@ function draw(address: string, state: string): string { } describe('the blames screen', () => { + it('puts the counts first, then the three views', () => { + const html = draw('/compass/blames?state=all', 'all'); + expect(html).toContain('data-testid="blames-tile-total"'); + expect(html).toMatch(/data-testid="blames-tile-total"[^>]*>\s*3\s*]*>\s*2\s*]*>\s*1\s* { const html = draw('/compass/blames?state=all', 'all'); expect(html).toContain('sprint 31'); @@ -95,6 +106,20 @@ describe('the blames screen', () => { expect(html).toContain('Blame: the earlier'); expect(html).not.toContain('Blame: the second'); expect(html).toContain('2 reports'); - expect(html).toMatch(/href="\/compass\/blames\?type=blame_report&state=all"[^>]*>All<\/a>/); + expect(html).toContain('state=all&view=sprint'); + }); + + it('groups the outstanding by the owner that owes the answer', () => { + const html = draw('/compass/blames?state=open&view=outstanding', 'open'); + expect(html).toContain('eager_maxwell'); + expect(html).toContain('Blame: the first'); + expect(html).not.toContain('Blame: the second'); + }); + + it('counts the loads and the states in the analysis view', () => { + const html = draw('/compass/blames?state=all&view=analysis', 'all'); + expect(html).toContain('data-testid="blames-analysis"'); + expect(html).toContain('Who owes what'); + expect(html).toContain('Filed by day'); }); }); diff --git a/projects/compass.web/packages/pages/src/client.ts b/projects/compass.web/packages/pages/src/client.ts index 75162ee3..2b533ddb 100644 --- a/projects/compass.web/packages/pages/src/client.ts +++ b/projects/compass.web/packages/pages/src/client.ts @@ -97,6 +97,7 @@ export const documentSummarySchema = z.object({ state: z.string(), sprint: z.string(), owner: z.string(), + created: z.string(), }); /** The document a link opens, as compass.http resolved it under the caller's view. */ diff --git a/projects/compass.web/packages/pages/src/i18n/en.ts b/projects/compass.web/packages/pages/src/i18n/en.ts index 9d8f7d62..4b1879d3 100644 --- a/projects/compass.web/packages/pages/src/i18n/en.ts +++ b/projects/compass.web/packages/pages/src/i18n/en.ts @@ -120,6 +120,13 @@ export const en: Catalogue = { filter: { all: 'All', open: 'Open', addressed: 'Addressed' }, empty: 'No report matches this filter.', noSprint: 'No sprint', + views: { label: 'Views', sprint: 'By sprint', outstanding: 'Outstanding', analysis: 'Analysis' }, + tiles: { total: 'reports', open: 'still open', addressed: 'addressed', unowned: 'with no owner named' }, + outstanding: { empty: 'Nothing outstanding.' }, + analysis: { owners: 'Who owes what', states: 'Open and addressed', filed: 'Filed by day' }, + owner: 'owner {owner}', + age: '{days}d old', + noOwner: 'no owner', }, document: { loading: 'Reading the document…', diff --git a/projects/compass.web/packages/pages/src/i18n/fr.ts b/projects/compass.web/packages/pages/src/i18n/fr.ts index 50cf061d..61c824c6 100644 --- a/projects/compass.web/packages/pages/src/i18n/fr.ts +++ b/projects/compass.web/packages/pages/src/i18n/fr.ts @@ -118,6 +118,13 @@ const fr: Catalogue = { filter: { all: 'Tous', open: 'Ouverts', addressed: 'Traités' }, empty: 'Aucun rapport ne correspond à ce filtre.', noSprint: 'Sans sprint', + views: { label: 'Vues', sprint: 'Par sprint', outstanding: 'En cours', analysis: 'Analyse' }, + tiles: { total: 'rapports', open: 'encore ouverts', addressed: 'traités', unowned: 'sans propriétaire' }, + outstanding: { empty: 'Rien en cours.' }, + analysis: { owners: 'Qui doit quoi', states: 'Ouverts et traités', filed: 'Déposés par jour' }, + owner: 'propriétaire {owner}', + age: '{days} j', + noOwner: 'sans propriétaire', }, document: { loading: 'Lecture du document…', diff --git a/projects/compass.web/packages/pages/src/i18n/pt.ts b/projects/compass.web/packages/pages/src/i18n/pt.ts index b4688d2c..6119d4ba 100644 --- a/projects/compass.web/packages/pages/src/i18n/pt.ts +++ b/projects/compass.web/packages/pages/src/i18n/pt.ts @@ -118,6 +118,13 @@ const pt: Catalogue = { filter: { all: 'Todos', open: 'Abertos', addressed: 'Tratados' }, empty: 'Nenhum relatório corresponde a este filtro.', noSprint: 'Sem sprint', + views: { label: 'Vistas', sprint: 'Por sprint', outstanding: 'Em curso', analysis: 'Análise' }, + tiles: { total: 'relatórios', open: 'ainda abertos', addressed: 'tratados', unowned: 'sem dono' }, + outstanding: { empty: 'Nada em curso.' }, + analysis: { owners: 'Quem deve o quê', states: 'Abertos e tratados', filed: 'Registados por dia' }, + owner: 'dono {owner}', + age: '{days} d', + noOwner: 'sem dono', }, document: { loading: 'A ler o documento…', From f8af7df60b8c3edc7323444056d3b0ce4af8ecc3 Mon Sep 17 00:00:00 2001 From: Marco Craveiro Date: Sat, 5 Dec 2026 02:36:26 +0000 Subject: [PATCH 3/3] [web] Carry the found-by and the response badge in the blames list The list request may name a second Status field and a heading, so each report shows who found the break and whether a Response was written, as the prototype did. Both names are validated before they reach the expression, and the heading's section must hold text. Co-Authored-By: Claude Code --- .../task_serve_the_open_blame_reports.org | 12 +++-- .../messages/document_queries_protocol.hpp | 8 +++ .../compass.http.document_queries.org | 37 ++++++++++++++ projects/compass.http/src/query/reads.cpp | 49 +++++++++++++------ .../src/routes/document_queries_routes.cpp | 4 ++ .../compass.http/tests/query_reads_tests.cpp | 14 +++++- .../packages/pages/src/BlamesScreen.tsx | 25 +++++++++- .../packages/pages/src/DocumentScreen.tsx | 2 + .../packages/pages/src/blames.test.tsx | 6 ++- .../compass.web/packages/pages/src/client.ts | 10 ++++ .../compass.web/packages/pages/src/i18n/en.ts | 4 +- .../compass.web/packages/pages/src/i18n/fr.ts | 4 +- .../compass.web/packages/pages/src/i18n/pt.ts | 4 +- 13 files changed, 152 insertions(+), 27 deletions(-) diff --git a/doc/agile/versions/v0/sprint_01/surface_the_open_blame_reports/task_serve_the_open_blame_reports.org b/doc/agile/versions/v0/sprint_01/surface_the_open_blame_reports/task_serve_the_open_blame_reports.org index 64e9038f..bab5bed8 100644 --- a/doc/agile/versions/v0/sprint_01/surface_the_open_blame_reports/task_serve_the_open_blame_reports.org +++ b/doc/agile/versions/v0/sprint_01/surface_the_open_blame_reports/task_serve_the_open_blame_reports.org @@ -47,9 +47,10 @@ kinds first. - A page of an environment's documents carries its =State= and the sprint its path sits in, so a report list can show both without a second read. -- A list request may name a =* Status= field and each summary carries its - value as =owner=; a name a regular expression would read specially is - refused and answers empty. +- A list request may name up to two =* Status= fields and a heading; each + summary carries the fields' values as =owner= and =found_by= and whether + the heading's section holds text as =answered=. Names a regular + expression would read specially are refused and answer empty. - compass.web has a Blames screen shaped like the prototype the product owner signed off: count tiles first; three views; *By sprint* groups the reports with a filter by state; *Outstanding* groups the open ones by owner, oldest @@ -133,8 +134,9 @@ via its "Verifies task" field. * Result -A page of documents now carries its state, its sprint, its created date and, -when the request names a =* Status= field, its owner. compass.web gained the +A page of documents now carries its state, its sprint, its created date, +the requested Status fields' values as =owner= and =found_by=, and whether +the requested heading's section holds text as =answered=. compass.web gained the Blames screen from the prototype: count tiles, the By sprint, Outstanding and Analysis views, and every row opening in the document view by its =:ID:=. It is the seventh screen in the menu, beside Documents. diff --git a/projects/compass.http/include/compass.http/messages/document_queries_protocol.hpp b/projects/compass.http/include/compass.http/messages/document_queries_protocol.hpp index 0661423f..67c42d3e 100644 --- a/projects/compass.http/include/compass.http/messages/document_queries_protocol.hpp +++ b/projects/compass.http/include/compass.http/messages/document_queries_protocol.hpp @@ -335,6 +335,8 @@ struct document_summary { std::string sprint; std::string owner; std::string created; + std::string found_by; + bool answered{}; friend bool operator==(const document_summary&, const document_summary&) = default; }; @@ -357,6 +359,8 @@ struct document_summary { ::compass::db::codec::field{"sprint", &document_summary::sprint}, ::compass::db::codec::field{"owner", &document_summary::owner}, ::compass::db::codec::field{"created", &document_summary::created}, + ::compass::db::codec::field{"found_by", &document_summary::found_by}, + ::compass::db::codec::field{"answered", &document_summary::answered}, }; } @@ -366,6 +370,8 @@ struct list_documents_request { std::uint32_t limit = 50; std::uint32_t offset = 0; std::optional owner_field; + std::optional found_by_field; + std::optional answered_heading; friend bool operator==(const list_documents_request&, const list_documents_request&) = default; }; @@ -381,6 +387,8 @@ struct list_documents_request { ::compass::db::codec::field{"limit", &list_documents_request::limit, true}, ::compass::db::codec::field{"offset", &list_documents_request::offset, true}, ::compass::db::codec::field{"owner_field", &list_documents_request::owner_field}, + ::compass::db::codec::field{"found_by_field", &list_documents_request::found_by_field}, + ::compass::db::codec::field{"answered_heading", &list_documents_request::answered_heading}, }; } diff --git a/projects/compass.http/modeling/compass.http.document_queries.org b/projects/compass.http/modeling/compass.http.document_queries.org index aec0cb2a..d3263c73 100644 --- a/projects/compass.http/modeling/compass.http.document_queries.org +++ b/projects/compass.http/modeling/compass.http.document_queries.org @@ -525,6 +525,24 @@ document states none. The document's =#+created:=, which a list shows as the page's age. Empty when the page states none. +*** found_by +:PROPERTIES: +:cpp_type: std::string +:END: + +The value the requested =found_by_field= holds in the document's =* Status= +table, bare of its code marks. Empty when the request names no field or the +document states none. + +*** answered +:PROPERTIES: +:cpp_type: bool +:END: + +Whether the document has a section under the requested =answered_heading= +with text in it, as a report's =* Response= is. False when the request names +no heading or the section is absent or empty. + ** list_documents_request :PROPERTIES: :tool: list_documents @@ -587,6 +605,25 @@ field that names the environment a report belongs to. A name of letters, digits, spaces, =_= and =-=; any other is refused. Reading it scans each document's source at query time; a column filled at sync would replace it. +*** found_by_field +:PROPERTIES: +:cpp_type: std::optional +:http_in: query +:END: + +A =* Status= field whose value each summary carries as =found_by=, such as +the field that names the environment that found the break. Validated and +read as =owner_field= is. + +*** answered_heading +:PROPERTIES: +:cpp_type: std::optional +:http_in: query +:END: + +A heading whose section, when it holds text, makes =answered= true, such as +a report's =Response=. Validated and read as =owner_field= is. + ** list_documents_response diff --git a/projects/compass.http/src/query/reads.cpp b/projects/compass.http/src/query/reads.cpp index 2fd5cbc8..4bc5b919 100644 --- a/projects/compass.http/src/query/reads.cpp +++ b/projects/compass.http/src/query/reads.cpp @@ -60,8 +60,10 @@ bool safe_field(std::string_view field) { } /// The columns of a document_summary of a document d at a placement p, with -/// the value @p owner_field holds in the document's Status table at the end. -std::string summary_columns(std::string_view owner_field) { +/// the values the requested Status fields hold and whether the requested +/// heading answers, at the end. +std::string summary_columns(std::string_view owner_field, + std::string_view found_by_field, std::string_view answered_heading) { std::string out = "coalesce(d.org_id, ''), coalesce(d.title, ''), coalesce(d.type, ''), " "coalesce(d.description, ''), p.path, array_to_string(d.tags, E'\\x1f'), " @@ -77,7 +79,21 @@ std::string summary_columns(std::string_view owner_field) { " *\\| *([^|\\n]*)')), '')"; else out += "''"; - out += ", coalesce(d.created, '')"; + out += ", coalesce(d.created, ''), "; + if (safe_field(found_by_field)) + out += "coalesce(trim(both ' `' from substring(d.source from " + "'\\| *" + std::string(found_by_field) + + " *\\| *([^|\\n]*)')), '')"; + else + out += "''"; + out += ", "; + if (safe_field(answered_heading)) + out += "EXISTS (SELECT 1 FROM corpus.heading h JOIN corpus.section s " + "ON s.hash = h.hash AND s.heading_ord = h.ord AND s.text <> '' " + "WHERE h.hash = d.hash AND lower(h.title) = lower('" + + std::string(answered_heading) + "'))"; + else + out += "false"; return out; } @@ -109,6 +125,8 @@ messages::document_summary summary_at(const result& r, std::size_t row, std::siz s.sprint = r.value(row, first + 9); s.owner = r.value(row, first + 10); s.created = r.value(row, first + 11); + s.found_by = r.value(row, first + 12); + s.answered = r.value(row, first + 13) == "t"; return s; } @@ -466,7 +484,8 @@ messages::list_documents_response list_documents(db::io::connection& c, const messages::list_documents_request& r) { const auto e = db::query::find_environment(c, r.environment); statement s; - s.sql = "WITH listed AS (\nSELECT " + summary_columns(r.owner_field.value_or("")) + + s.sql = "WITH listed AS (\nSELECT " + summary_columns(r.owner_field.value_or(""), + r.found_by_field.value_or(""), r.answered_heading.value_or("")) + "\nFROM corpus.placement p JOIN corpus.document d ON d.hash = p.hash\n"; db::query::where_documents(s, e.id, v, to_db(r.filter)); s.sql += ")\nSELECT (SELECT count(*) FROM listed), listed.* FROM listed\n" @@ -494,7 +513,7 @@ std::optional read_document(db::io::connection& c, const messages::get_document_request& r) { const auto e = db::query::find_environment(c, r.environment); statement s; - s.sql = "SELECT " + summary_columns({}) + ", d.source, encode(d.hash, 'hex')\n" + s.sql = "SELECT " + summary_columns({}, {}, {}) + ", d.source, encode(d.hash, 'hex')\n" "FROM corpus.placement p JOIN corpus.document d ON d.hash = p.hash\n"; db::query::where_documents(s, e.id, v, {}); s.sql += " AND d.org_id = " + s.bind(r.id) + "\nORDER BY p.path LIMIT 1"; @@ -503,8 +522,8 @@ std::optional read_document(db::io::connection& c, return std::nullopt; document_source out; out.summary = summary_at(found, 0, 0); - out.source = found.value(0, 12); - out.hash = found.value(0, 13); + out.source = found.value(0, 14); + out.hash = found.value(0, 15); out.synced_at = e.synced_at; out.environment_id = e.id; @@ -633,7 +652,7 @@ std::optional backlinks(db::io::connection& c, return std::nullopt; statement s; - s.sql = "SELECT " + summary_columns({}) + ", coalesce(h.anchor, ''),\n" + s.sql = "SELECT " + summary_columns({}, {}, {}) + ", coalesce(h.anchor, ''),\n" " CASE WHEN l.text <> '' THEN l.text ELSE l.path END,\n" " encode(l.hash, 'hex'), l.ord, coalesce(l.heading_ord, -1), l.path\n" "FROM corpus.link l\n" @@ -647,7 +666,7 @@ std::optional backlinks(db::io::connection& c, statement holders; std::unordered_set hashes; for (std::size_t row = 0; row < rows.rows(); ++row) - hashes.emplace(rows.value(row, 14)); + hashes.emplace(rows.value(row, 16)); std::string in; for (const auto& hash : hashes) in += (in.empty() ? "decode(" : ", decode(") + holders.bind(hash) + ", 'hex')"; @@ -675,22 +694,22 @@ std::optional backlinks(db::io::connection& c, for (std::size_t row = 0; row < rows.rows(); ++row) { messages::backlink b; b.document = summary_at(rows, row, 0); - b.anchor = rows.value(row, 12); - b.text = rows.value(row, 13); - const std::string hash(rows.value(row, 14)); + b.anchor = rows.value(row, 14); + b.text = rows.value(row, 15); + const std::string hash(rows.value(row, 16)); if (hash != parsed) { parsed = hash; source = sources[hash]; tables = {}; compass::ingest::org::parse(source, tables); } - const auto heading = to_number(rows.value(row, 16)); + const auto heading = to_number(rows.value(row, 18)); if (heading >= 0) b.headings = heading_path(outlines[hash], static_cast(heading)); const auto t = ot::view(tables); - const auto ord = to_number(rows.value(row, 15)); + const auto ord = to_number(rows.value(row, 17)); if (ord < t.links.size() && - t.links.paths[ot::link_id{ord}].of(source) == rows.value(row, 17)) + t.links.paths[ot::link_id{ord}].of(source) == rows.value(row, 19)) b.excerpt = excerpt_of(source, t, link_range(t, ot::link_id{ord})); out.backlinks.push_back(std::move(b)); } diff --git a/projects/compass.http/src/routes/document_queries_routes.cpp b/projects/compass.http/src/routes/document_queries_routes.cpp index 9deb0f27..865edb96 100644 --- a/projects/compass.http/src/routes/document_queries_routes.cpp +++ b/projects/compass.http/src/routes/document_queries_routes.cpp @@ -151,6 +151,8 @@ compass::http::messages::list_documents_request bind_list_documents(const domain b.query("limit", r.limit, false); b.query("offset", r.offset, false); b.query("owner_field", r.owner_field, false); + b.query("found_by_field", r.found_by_field, false); + b.query("answered_heading", r.answered_heading, false); b.finish(); return r; } @@ -174,6 +176,8 @@ void add_list_documents(net::router& r, list_documents_handler h) { .query_param("limit", "integer", "", false, "The most documents to answer, at most 100; a larger limit is refused as invalid.") .query_param("offset", "integer", "", false, "How many documents to skip, for the next page.") .query_param("owner_field", "string", "", false, "A * Status field whose value each summary carries as owner, such as the field that names the environment a report belongs to. A name of letters, digits, spaces, _ and -; any other is refused. Reading it scans each document's source at query time; a column filled at sync would replace it.") + .query_param("found_by_field", "string", "", false, "A * Status field whose value each summary carries as found_by, such as the field that names the environment that found the break. Validated and read as owner_field is.") + .query_param("answered_heading", "string", "", false, "A heading whose section, when it holds text, makes answered true, such as a report's Response. Validated and read as owner_field is.") .input() .response() .tool_call([h](const domain::caller& c, std::string_view arguments) { diff --git a/projects/compass.http/tests/query_reads_tests.cpp b/projects/compass.http/tests/query_reads_tests.cpp index 3f6eb49d..4661e691 100644 --- a/projects/compass.http/tests/query_reads_tests.cpp +++ b/projects/compass.http/tests/query_reads_tests.cpp @@ -125,7 +125,7 @@ const corpus& seeded() { "#+filetags: :howto:\n")); add(page("SPRINT-1", "sprint", "Sprint 1", "user", "This page documents a sprint.\n\n* Status\n\n| Field | Value |\n" - "|-------+-------|\n| State | STARTED |\n| Owner | brave_hopper |", + "|-------+-------|\n| State | STARTED |\n| Owner | brave_hopper |\n| Found by | solid_dirac |", "#+created: 2026-11-01\n")); std::vector placed; for (std::size_t i = 0; i < documents.size(); ++i) @@ -507,6 +507,18 @@ TEST_CASE("documents carries a Status field's value only when the request names const auto unsafe = r.get("/v1/main/documents?type=sprint&owner_field=Owner%29"); CHECK_THAT(unsafe.body, ContainsSubstring("\"owner\":\"\"")); + + const auto found = r.get( + "/v1/main/documents?type=sprint&found_by_field=Found%20by"); + CHECK_THAT(found.body, ContainsSubstring("\"found_by\":\"solid_dirac\"")); + + const auto answered = r.get( + "/v1/main/documents?type=sprint&answered_heading=Status"); + CHECK_THAT(answered.body, ContainsSubstring("\"answered\":true")); + + const auto silent = r.get( + "/v1/main/documents?type=sprint&answered_heading=Nowhere"); + CHECK_THAT(silent.body, ContainsSubstring("\"answered\":false")); } TEST_CASE("document answers a page's org source, never HTML, and only in a view that " diff --git a/projects/compass.web/packages/pages/src/BlamesScreen.tsx b/projects/compass.web/packages/pages/src/BlamesScreen.tsx index 7b54635c..c232aa76 100644 --- a/projects/compass.web/packages/pages/src/BlamesScreen.tsx +++ b/projects/compass.web/packages/pages/src/BlamesScreen.tsx @@ -29,6 +29,8 @@ import { useTranslation } from './i18n/Provider.js'; /** The reports a project keeps open, by the type its pages carry. */ export const BLAME_TYPE = 'blame_report'; const OWNER_FIELD = 'Owner'; +const FOUND_BY_FIELD = 'Found by'; +const ANSWERED_HEADING = 'Response'; const LIMIT = 100; /** A page is closed when its State is one a lifecycle ends in. */ const CLOSED = new Set(['DONE', 'ABANDONED']); @@ -96,10 +98,18 @@ export function BlamesScreen({ environment }: { readonly environment: string }): const wanted = params.get('view') ?? 'sprint'; const view: View = (VIEWS as readonly string[]).includes(wanted) ? (wanted as View) : 'sprint'; const reports = useQuery({ - queryKey: ['compass', inputs.httpBase, 'documents', environment, { type, owner: OWNER_FIELD, state, limit: LIMIT }], + queryKey: ['compass', inputs.httpBase, 'documents', environment, { type, state, limit: LIMIT }], queryFn: ({ signal }) => client.documents( - { environment, type, owner_field: OWNER_FIELD, limit: LIMIT, offset: 0 }, + { + environment, + type, + owner_field: OWNER_FIELD, + found_by_field: FOUND_BY_FIELD, + answered_heading: ANSWERED_HEADING, + limit: LIMIT, + offset: 0, + }, signal, ), placeholderData: keepPreviousData, @@ -304,7 +314,18 @@ function ReportRow({ {t('blames.owner', { owner: d.owner })} )} + {d.found_by === '' ? null : ( + + {t('blames.foundBy', { name: d.found_by })} + + )} {age === null ? null : {t('blames.age', { days: age })}} + + {d.answered ? t('blames.answered') : t('blames.awaiting')} +
    {d.path}
    {d.excerpt === '' ? null : ( diff --git a/projects/compass.web/packages/pages/src/DocumentScreen.tsx b/projects/compass.web/packages/pages/src/DocumentScreen.tsx index 50246c21..ca2c5992 100644 --- a/projects/compass.web/packages/pages/src/DocumentScreen.tsx +++ b/projects/compass.web/packages/pages/src/DocumentScreen.tsx @@ -720,6 +720,8 @@ export function OrgFragment({ sprint: '', owner: '', created: '', + found_by: '', + answered: false, }, body: org, anchors: [], diff --git a/projects/compass.web/packages/pages/src/blames.test.tsx b/projects/compass.web/packages/pages/src/blames.test.tsx index 1577a027..5cb1514f 100644 --- a/projects/compass.web/packages/pages/src/blames.test.tsx +++ b/projects/compass.web/packages/pages/src/blames.test.tsx @@ -52,6 +52,8 @@ const report = (id: string, title: string, state: string, sprint: string, path: sprint, owner: id === 'B1' ? 'eager_maxwell' : 'solid_dirac', created: '2026-11-29', + found_by: id === 'B2' ? 'bright_faraday' : 'brave_hopper', + answered: id !== 'B0', }); const documents = { @@ -66,7 +68,7 @@ function draw(address: string, state: string): string { const queries = new QueryClient(); queries.setQueryData(environmentsKey(inputs.httpBase), environments); queries.setQueryData( - ['compass', '/', 'documents', 'compass', { type: 'blame_report', owner: 'Owner', state, limit: 100 }], + ['compass', '/', 'documents', 'compass', { type: 'blame_report', state, limit: 100 }], documents, ); const router = createMemoryRouter(compassRoutes(), { initialEntries: [address] }); @@ -98,6 +100,8 @@ describe('the blames screen', () => { expect(html).toMatch(/href="\/compass\/docs\/B1"[^>]*>Blame: the first<\/a>/); expect(html).toContain('3 reports'); expect(html).toContain('owner eager_maxwell'); + expect(html).toContain('found by brave_hopper'); + expect(html).toContain('no response'); }); it('shows only the open reports until the filter says otherwise', () => { diff --git a/projects/compass.web/packages/pages/src/client.ts b/projects/compass.web/packages/pages/src/client.ts index 2b533ddb..df1eaf98 100644 --- a/projects/compass.web/packages/pages/src/client.ts +++ b/projects/compass.web/packages/pages/src/client.ts @@ -98,6 +98,8 @@ export const documentSummarySchema = z.object({ sprint: z.string(), owner: z.string(), created: z.string(), + found_by: z.string(), + answered: z.boolean(), }); /** The document a link opens, as compass.http resolved it under the caller's view. */ @@ -833,6 +835,8 @@ export interface CompassClient { readonly environment: string; readonly type?: string; readonly owner_field?: string; + readonly found_by_field?: string; + readonly answered_heading?: string; readonly limit: number; readonly offset: number; }, @@ -1159,6 +1163,12 @@ export function createClient( if (query.owner_field !== undefined) { params.set('owner_field', query.owner_field); } + if (query.found_by_field !== undefined) { + params.set('found_by_field', query.found_by_field); + } + if (query.answered_heading !== undefined) { + params.set('answered_heading', query.answered_heading); + } params.set('limit', String(query.limit)); params.set('offset', String(query.offset)); return read( diff --git a/projects/compass.web/packages/pages/src/i18n/en.ts b/projects/compass.web/packages/pages/src/i18n/en.ts index 4b1879d3..25def01b 100644 --- a/projects/compass.web/packages/pages/src/i18n/en.ts +++ b/projects/compass.web/packages/pages/src/i18n/en.ts @@ -126,7 +126,9 @@ export const en: Catalogue = { analysis: { owners: 'Who owes what', states: 'Open and addressed', filed: 'Filed by day' }, owner: 'owner {owner}', age: '{days}d old', - noOwner: 'no owner', + noOwner: 'no owner', foundBy: 'found by {name}', + answered: 'answered', + awaiting: 'no response', }, document: { loading: 'Reading the document…', diff --git a/projects/compass.web/packages/pages/src/i18n/fr.ts b/projects/compass.web/packages/pages/src/i18n/fr.ts index 61c824c6..bf39d3c0 100644 --- a/projects/compass.web/packages/pages/src/i18n/fr.ts +++ b/projects/compass.web/packages/pages/src/i18n/fr.ts @@ -124,7 +124,9 @@ const fr: Catalogue = { analysis: { owners: 'Qui doit quoi', states: 'Ouverts et traités', filed: 'Déposés par jour' }, owner: 'propriétaire {owner}', age: '{days} j', - noOwner: 'sans propriétaire', + noOwner: 'sans propriétaire', foundBy: 'trouvé par {name}', + answered: 'répondu', + awaiting: 'sans réponse', }, document: { loading: 'Lecture du document…', diff --git a/projects/compass.web/packages/pages/src/i18n/pt.ts b/projects/compass.web/packages/pages/src/i18n/pt.ts index 6119d4ba..29eeda13 100644 --- a/projects/compass.web/packages/pages/src/i18n/pt.ts +++ b/projects/compass.web/packages/pages/src/i18n/pt.ts @@ -124,7 +124,9 @@ const pt: Catalogue = { analysis: { owners: 'Quem deve o quê', states: 'Abertos e tratados', filed: 'Registados por dia' }, owner: 'dono {owner}', age: '{days} d', - noOwner: 'sem dono', + noOwner: 'sem dono', foundBy: 'encontrado por {name}', + answered: 'respondido', + awaiting: 'sem resposta', }, document: { loading: 'A ler o documento…',