Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/added-18722-governor-pr-models-list-prs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Governor **PRs by model** can list one model's pull requests: a **▸ PRs** button on each model row opens that model's PRs in the window (outcome, review rounds, fix attempts, first pass, author agent and backend, each linking to GitHub), loaded on demand from the new optional `model=` parameter on `GET /api/governor/pr-models`. The parameter accepts any raw spelling of the model, returns up to 200 PRs most reworked first with `prs_truncated` past that, and leaves the response unchanged when omitted (#18722).
72 changes: 72 additions & 0 deletions dashboard/test/governor-pr-models-ui.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,78 @@ test('Governor PRs by model shows unmeasured run columns as a dash and discloses
}
});

// Extracts `function name(` / `async function name(` from index.html by brace matching.
function extractFunction(name) {
const re = new RegExp(`(?:async )?function ${name}\\(`);
const m = re.exec(indexHtml);
assert.ok(m, `index.html does not define ${name}()`);
const open = indexHtml.indexOf('{', m.index + m[0].length);
let depth = 0;
for (let i = open; i < indexHtml.length; i++) {
if (indexHtml[i] === '{') depth++;
else if (indexHtml[i] === '}' && --depth === 0) return indexHtml.slice(m.index, i + 1);
}
assert.fail(`unbalanced braces in ${name}()`);
}

test('Opening a model row requests model=… and lists its PRs with GitHub links (#18722)', async () => {
const vm = require('node:vm');
const fetchURLs = [];
const sandbox = {
fetchURLs,
renders: 0,
escapeHtml: s => String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;'),
fetch: async url => {
fetchURLs.push(url);
return {
ok: true,
json: async () => ({
prs: [
{ repo: 'org/a', number: 2, title: 'reworked <b>', url: 'https://github.com/org/a/pull/2', outcome: 'merged', review_rounds: 2, fix_attempts: 1, agent: 'fixer', backend: 'pi' },
{ repo: 'org/b', number: 4, url: 'https://github.com/org/b/pull/4', outcome: 'closed_unmerged', review_rounds: 1, fix_attempts: 2, first_pass: false },
],
prs_truncated: true,
}),
};
},
};
sandbox.window = sandbox;
vm.createContext(sandbox);
const src = [
"let govPRModelsWindow = '30d';",
"let govPRModelPRsOpen = '';",
'const govPRModelPRsCache = {};',
'const govPRModelPRsLoading = {};',
'function renderGovernorFromLastStatus() { renders++; }',
...['normalizeGovernorPRModelsWindowName', 'governorPRModelPRsKey', 'loadGovernorPRModelPRs', 'toggleGovernorPRModelPRs', 'governorPRModelPRsToggleHtml', 'governorPRModelPRListHtml'].map(extractFunction),
'this.api = { toggleGovernorPRModelPRs, governorPRModelPRsToggleHtml, governorPRModelPRListHtml, state: () => govPRModelPRsOpen };',
].join('\n');
vm.runInContext(src, sandbox);
const api = sandbox.api;

assert.match(api.governorPRModelPRsToggleHtml('claude-opus-5.5'), /data-action="toggleGovernorPRModelPRs" data-arg0="claude-opus-5\.5"/);
assert.match(api.governorPRModelPRsToggleHtml('claude-opus-5.5'), /aria-expanded="false"/);
assert.equal(api.governorPRModelPRListHtml('claude-opus-5.5'), '', 'a closed row renders no list');

await api.toggleGovernorPRModelPRs('claude-opus-5.5');
assert.deepEqual(fetchURLs, ['/api/governor/pr-models?window=30d&model=claude-opus-5.5']);
assert.equal(api.state(), 'claude-opus-5.5');
assert.match(api.governorPRModelPRsToggleHtml('claude-opus-5.5'), /aria-expanded="true"/);
const html = api.governorPRModelPRListHtml('claude-opus-5.5');
assert.match(html, /<a href="https:\/\/github\.com\/org\/a\/pull\/2" target="_blank" rel="noopener">org\/a#2<\/a>/);
assert.match(html, /<a href="https:\/\/github\.com\/org\/b\/pull\/4" target="_blank" rel="noopener">org\/b#4<\/a>/);
assert.match(html, /reworked &lt;b&gt;/, 'titles are escaped');
assert.match(html, /closed-unmerged/);
assert.match(html, /Showing the first 2 PRs/, 'a truncated list says so');
assert.equal(api.governorPRModelPRListHtml('gpt-6.1-sol'), '', 'other rows stay closed');

// Reopening the same model in the same window uses the cache.
await api.toggleGovernorPRModelPRs('claude-opus-5.5');
assert.equal(api.state(), '');
await api.toggleGovernorPRModelPRs('claude-opus-5.5');
assert.equal(fetchURLs.length, 1, 'cached per window and model');
});

test('Governor PRs by model tooltip lists per-backend rework and the effort split (#18715)', () => {
for (const expected of [
'const sliceRework = s =>',
Expand Down
2 changes: 1 addition & 1 deletion src/docs/api-reference/agents-and-controls.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Part of the [Dashboard REST API reference](../api-reference.md); see that page f
| `POST` | `/api/unpin/{agent}/{dimension}` | Owner only | Unpin | `pkg/dashboard/api.go:135` |
| `POST` | `/api/restart/{agent}` | Owner only | Restart | `pkg/dashboard/api.go:139` |
| `GET` | `/api/model-advisor` | Dashboard auth/session | Model Advisor | `pkg/dashboard/api.go:156` |
| `GET` | `/api/governor/pr-models` | Dashboard auth/session | Agent-authored PR distribution by normalized attribution model/backend for `window=7d`, `30d`, or `all`, including per-model rework stats, Wilson 95% `*_ci` intervals on the rates (omitted when the denominator is 0), a `coverage` block (closed-PR lookback and run-log partiality, as on `/api/contribute/effective-models`), `earliest_pr_created_at`, and the top 10 most-reworked PRs | `pkg/dashboard/api.go:157` |
| `GET` | `/api/governor/pr-models` | Dashboard auth/session | Agent-authored PR distribution by normalized attribution model/backend for `window=7d`, `30d`, or `all`, including per-model rework stats, Wilson 95% `*_ci` intervals on the rates (omitted when the denominator is 0), a `coverage` block (closed-PR lookback and run-log partiality, as on `/api/contribute/effective-models`), `earliest_pr_created_at`, and the top 10 most-reworked PRs. Optional `model=<id>` (matched after `modelfamily.Canonical`, so raw spellings such as `anthropic/claude-opus-5-5` work) adds `prs[]`: every PR in the window in that model's bucket, with the `most_reworked` fields plus `outcome` (`merged` / `closed_unmerged` / `open`), `agent`, `created_at`, `merged_at` and `first_pass`, sorted by review rounds + fix attempts then newest, capped at 200 with `prs_truncated: true` past that. An unknown model returns `prs: []`; without `model` the response is unchanged | `pkg/dashboard/api.go:157` |
| `GET` | `/api/reviewer/accuracy` | Dashboard auth/session | Reviewer verdict calibration for the configured window: false-approve/false-block rates and confidence buckets per perspective and reviewer model | `pkg/dashboard/api.go:220` |
| `GET` | `/api/review/queue` | Dashboard auth/session | PR review queue: every open PR (agent and contributor, actionable and held) ranked by triage class, confidence band, CI state and age, with per-PR `reasons`; unreviewed items carry `pending_since` and `redispatch_count` from the review dispatch state; each entry carries `stage` `{stage, entered_at, last_activity_at, quiet_for, stalled, waiting_on_hive, past_dwell, history[]}` from the stage-label store (`stalled`/`past_dwell` follow `governor.labels.stage.dwell` and `stalled.require_quiet`; `history[]` is `{from, to, at, reason, regressed}`, newest last, capped at 8) and the top-level `hive_held` counts PRs past their stage dwell while waiting on the hive (`waiting_on_hive` and `past_dwell` both true); paged with `limit` (1-200, default 50) and `offset` | `pkg/dashboard/api.go:502` |
| `POST` | `/api/review/queue/{owner}/{repo}/{number}/superseded/close` | Owner only | Close a superseded PR now (grace window or not): posts the close comment, adds `hive/superseded`, closes it | `pkg/dashboard/api.go:505` |
Expand Down
7 changes: 6 additions & 1 deletion src/docs/dashboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,12 @@ The dashboard **Governor** card summarizes queue depth, operating mode, budget
posture, and cadence controls for the hive. Its collapsible **PRs by model** nested
sub-section reads `GET /api/governor/pr-models` with the selected `7d`, `30d`,
or `all` window. The nested header keeps the window/sort toggles visible and its
collapsed summary shows the current top-ranked model plus model count.
collapsed summary shows the current top-ranked model plus model count. Each
model row has a **▸ PRs** button that opens that model's pull requests in the
selected window (outcome, review rounds, fix attempts, first pass, author agent
and backend, each linked to GitHub). The list is fetched on demand with
`GET /api/governor/pr-models?window=…&model=<model>` and cached per window and
model.

The Governor **actionable issues** and **actionable PRs** tiles use the shared
server-side actionable partition described in [Repository card legend, issue
Expand Down
4 changes: 4 additions & 0 deletions src/pkg/dashboard/api_governor_pr_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ func (s *Server) handleGovernorPRModels(w http.ResponseWriter, r *http.Request)
effective := aggregateEffectiveModelsFromPRAggregation(resp, aggregateEffectiveRunStats(runs, effectiveModelsFilterAll), effectiveModelsFilterAll, minMergedPRs)
applyGovernorPRModelEffectiveness(&resp, effective, minMergedPRs)
w.Header().Set("Content-Type", "application/json")
if model, ok := governorPRModelsQueryModel(r); ok {
_ = json.NewEncoder(w).Encode(withGovernorPRModelPRs(resp, actionable.PRs.Attributed, model, now))
return
}
_ = json.NewEncoder(w).Encode(resp)
}

Expand Down
138 changes: 138 additions & 0 deletions src/pkg/dashboard/api_governor_pr_models_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package dashboard

import (
"net/http"
"sort"
"strings"
"time"

ghpkg "github.com/hivecommons/hive/pkg/github"
"github.com/hivecommons/hive/pkg/modelfamily"
)

// governorPRModelPRsCap bounds the per-model PR list returned by
// /api/governor/pr-models?model=…; past it PRsTruncated is set.
const governorPRModelPRsCap = 200

// governorPRModelsWithPRsResponse is the /api/governor/pr-models response
// when a model filter is given: the usual body plus that model's PRs. PRs is
// a pointer so an unknown model encodes as "prs": [] rather than dropping the
// field; without a filter this type is never used, so the default response is
// unchanged.
type governorPRModelsWithPRsResponse struct {
governorPRModelsResponse
PRs *[]governorPRModelPRItem `json:"prs,omitempty"`
PRsTruncated bool `json:"prs_truncated,omitempty"`
}

// governorPRModelPRItem is one PR in a model's list: the most_reworked fields
// plus its outcome, author agent, timestamps and first-pass flag. No PR body,
// the same privacy as most_reworked.
type governorPRModelPRItem struct {
governorPRMostReworkedItem
Outcome string `json:"outcome"`
Agent string `json:"agent,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
MergedAt string `json:"merged_at,omitempty"`
FirstPass bool `json:"first_pass"`
}

// governorPRModelsQueryModel returns the canonical model named by the
// request's model= parameter, and false when the parameter is absent or blank.
func governorPRModelsQueryModel(r *http.Request) (string, bool) {
raw := strings.TrimSpace(r.URL.Query().Get("model"))
if raw == "" {
return "", false
}
return modelfamily.Canonical(raw), true
}

// governorPRModelPRList lists every attributed PR in the window whose bucket
// (modelfamily.Canonical of its model) is model, using the same window and
// attribution filters as aggregateGovernorPRModels so the list length matches
// the bucket's prs count. Sorted by review rounds + fix attempts descending,
// then created_at descending; capped at governorPRModelPRsCap.
func governorPRModelPRList(prs []ghpkg.PullRequest, window, model string, now time.Time) ([]governorPRModelPRItem, bool) {
window = normalizeGovernorPRModelsWindow(window)
cutoff := time.Time{}
switch window {
case governorPRModelsWindow7d:
cutoff = now.AddDate(0, 0, -governorPRModelsDays7)
case governorPRModelsWindow30d:
cutoff = now.AddDate(0, 0, -governorPRModelsDays30)
}
type listed struct {
item governorPRModelPRItem
created time.Time
}
var rows []listed
for _, pr := range prs {
if !pr.HiveAttributed {
continue
}
if !cutoff.IsZero() && pr.CreatedAt.Before(cutoff) {
continue
}
if modelfamily.Canonical(pr.HiveModel) != model {
continue
}
agent := ghpkg.NormalizeAttributionValue(pr.HiveAgent)
if agent == "unknown" {
agent = ""
}
item := governorPRModelPRItem{
governorPRMostReworkedItem: governorPRMostReworkedItem{
Repo: pr.Repo,
Number: pr.Number,
Title: pr.Title,
Model: model,
Backend: ghpkg.NormalizeAttributionValue(pr.HiveBackend),
URL: pr.URL,
ReviewRounds: pr.Rework.ReviewRounds,
FixAttempts: pr.Rework.FixAttempts,
FollowUpCommits: pr.Rework.FollowUpCommits,
FixerModels: append([]string(nil), pr.Rework.FixerModels...),
HumanChangeRequests: pr.Rework.HumanChangeRequests,
},
Outcome: governorPRModelOutcome(pr),
Agent: agent,
FirstPass: pr.Rework.FirstPass,
}
if !pr.CreatedAt.IsZero() {
item.CreatedAt = pr.CreatedAt.UTC().Format(time.RFC3339)
}
if !pr.MergedAt.IsZero() {
item.MergedAt = pr.MergedAt.UTC().Format(time.RFC3339)
}
rows = append(rows, listed{item: item, created: pr.CreatedAt})
}
sort.SliceStable(rows, func(i, j int) bool {
a := rows[i].item.ReviewRounds + rows[i].item.FixAttempts
b := rows[j].item.ReviewRounds + rows[j].item.FixAttempts
if a != b {
return a > b
}
if !rows[i].created.Equal(rows[j].created) {
return rows[i].created.After(rows[j].created)
}
if rows[i].item.Repo != rows[j].item.Repo {
return rows[i].item.Repo < rows[j].item.Repo
}
return rows[i].item.Number > rows[j].item.Number
})
truncated := len(rows) > governorPRModelPRsCap
if truncated {
rows = rows[:governorPRModelPRsCap]
}
out := make([]governorPRModelPRItem, 0, len(rows))
for _, row := range rows {
out = append(out, row.item)
}
return out, truncated
}

// withGovernorPRModelPRs wraps resp with model's PR list for the same window.
func withGovernorPRModelPRs(resp governorPRModelsResponse, prs []ghpkg.PullRequest, model string, now time.Time) governorPRModelsWithPRsResponse {
list, truncated := governorPRModelPRList(prs, resp.Window, model, now)
return governorPRModelsWithPRsResponse{governorPRModelsResponse: resp, PRs: &list, PRsTruncated: truncated}
}
Loading
Loading