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/fixed-agent-issue-title-prefix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Every issue the hive files now starts with its `[<agent>]` tag, with no producer left out: one `issueshape.AgentIssueTitle` function is the choke point for every issue-creation path β€” `CreateIssue`, the review-backlog, dedupe, hotspot (`[ci-maintainer]`, matching its `agent/ci-maintainer` label), self-report, upstream-watch, advisory and recommendations filers, and the proxy's `gh issue create` β€” puts the tag first (ahead of any emoji), never doubles it, and a guard test fails any new raw create that skips it. The Activity Monitor draws the tag as a chip ahead of the title instead of repeating it. Existing issue titles are left as they are; dedupe ignores the tag so they still match their tagged successors.
106 changes: 80 additions & 26 deletions src/crux/issueshape/issueshape.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,48 +99,102 @@ func UnchosenOptionList(text string) (string, bool) {
return m, m != ""
}

// agentTitlePrefixRE matches the leading `[<agent>]` tag every hive-filed
// issue title carries (`[scanner] …`, `[reviewer] …`, `[selfreport] …`). A
// filer-chosen tag with spaces (`[ACMM L0] …`) counts too, so it is kept
// rather than stacked under a second tag.
var agentTitlePrefixRE = regexp.MustCompile(`^\s*\[([^\]\n]+)\]\s*`)
// Every issue the hive files starts with the filing agent in brackets:
// `[scanner] …`, `[reviewer] …`, `[selfreport] …` (the owner's rule: "agents
// that need to open issues need to use [agent name]"). A filer tag is the
// lowercased agent (lane) name as the dashboard shows it, so it has the slug
// shape filerTagRE describes; a bracketed tag of any other shape
// (`[ACMM L0]`, `[Tests]`) is part of the subject, not a filer.
var (
// leadingTagRE matches a title's leading `[tag]`, optionally preceded by
// a short run of symbols (an emoji convention such as `πŸ› [reviewer] …`)
// captured in group 1 so the tag can be moved in front of it.
leadingTagRE = regexp.MustCompile(`^\s*((?:[^\p{L}\p{N}\[\]\s]+\s*)?)\[([^\]\n]+)\]\s*`)
filerTagRE = regexp.MustCompile(`^[a-z0-9][a-z0-9_.-]*$`)
)

// TitleFor returns title carrying a leading `[<agent>]` tag, the convention
// every issue the hive files follows so a reader can tell which agent or
// subsystem filed it. The tag is the lowercased agent (lane) name as the
// dashboard shows it. It is idempotent: a title that already starts with a
// bracketed tag β€” the same agent, or a tag the filer chose itself such as
// `[Tests]` or `[DCO]` β€” is returned unchanged, so a title is never
// double-prefixed. An empty agent leaves the title as it is.
func TitleFor(agent, title string) string {
// AgentIssueTitle returns title carrying a leading `[<agent>]` tag. It is the
// one function every hive issue-creation path runs a title through, and it
// is idempotent:
// - a title already tagged with this agent (any case, or after a leading
// emoji) is normalised to `[agent] …` with the rest unchanged;
// - a title another hive filer already tagged (`[selfreport] …` relayed by
// the governor) is kept as it is, so a title is never double-tagged;
// - a filer-chosen bracket that is not a filer name (`[ACMM L0] …`) is part
// of the subject and gets the `[agent]` tag in front of it;
// - the tag always comes first, before any emoji the title opens with.
//
// An empty agent leaves the title as it is.
func AgentIssueTitle(agent, title string) string {
title = strings.TrimSpace(title)
agent = strings.ToLower(strings.TrimSpace(agent))
if agent == "" || title == "" || HasAgentPrefix(title) {
if agent == "" || title == "" {
return title
}
return "[" + agent + "] " + title
m := leadingTagRE.FindStringSubmatch(title)
if m == nil {
return "[" + agent + "] " + title
}
lead, tag, rest := strings.TrimSpace(m[1]), strings.TrimSpace(m[2]), title[len(m[0]):]
switch {
case strings.EqualFold(tag, agent):
return joinTitle("["+agent+"]", lead, rest)
case !IsFilerTag(tag):
return "[" + agent + "] " + title
case lead == "":
return title
default:
return joinTitle("["+tag+"]", lead, rest)
}
}

func joinTitle(parts ...string) string {
out := parts[:0]
for _, p := range parts {
if p != "" {
out = append(out, p)
}
}
return strings.Join(out, " ")
}

// IsFilerTag reports whether tag (the text inside a title's leading
// brackets) has the shape of a hive filer name: a lowercase slug.
func IsFilerTag(tag string) bool {
return filerTagRE.MatchString(strings.TrimSpace(tag))
}

// HasAgentPrefix reports whether title starts with a bracketed `[tag]`.
// HasAgentPrefix reports whether title starts with a filer tag (`[scanner] …`).
func HasAgentPrefix(title string) bool {
return agentTitlePrefixRE.MatchString(title)
return AgentPrefix(title) != ""
}

// AgentPrefix returns the tag inside a title's leading `[tag]`, lowercased,
// or "" when the title carries none.
// AgentPrefix returns the filer tag a title leads with (`[scanner] …` β†’
// "scanner"), or "" when the title carries none. A leading bracket that is
// not filer-shaped (`[ACMM L0] …`) is not a filer tag.
func AgentPrefix(title string) string {
m := agentTitlePrefixRE.FindStringSubmatch(title)
if m == nil {
m := leadingTagRE.FindStringSubmatch(title)
if m == nil || strings.TrimSpace(m[1]) != "" {
return ""
}
return strings.ToLower(m[1])
tag := strings.TrimSpace(m[2])
if !IsFilerTag(tag) {
return ""
}
return tag
}

// StripAgentPrefix returns title without its leading `[tag]`, trimmed. It is
// the key dedupe compares on so an issue filed before titles carried the
// filing agent still matches its prefixed re-filing.
// StripAgentPrefix returns title without its leading filer tag, trimmed. It
// is the key dedupe compares on so an issue filed before titles carried the
// filing agent still matches its prefixed re-filing. A non-filer bracket
// (`[ACMM L0] …`) is part of the subject and stays.
func StripAgentPrefix(title string) string {
return strings.TrimSpace(agentTitlePrefixRE.ReplaceAllString(strings.TrimSpace(title), ""))
title = strings.TrimSpace(title)
if AgentPrefix(title) == "" {
return title
}
m := leadingTagRE.FindStringSubmatch(title)
return strings.TrimSpace(title[len(m[0]):])
}

// SameTitle reports whether two issue titles are the same title once the
Expand Down
45 changes: 32 additions & 13 deletions src/crux/issueshape/issueshape_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,26 +103,36 @@ func TestUnchosenOptionList(t *testing.T) {
}
}

// Every issue the hive files names its filer in the title; TitleFor is the
// one helper that adds the tag, and it never adds a second one.
func TestTitleForTagsOnceAndKeepsExistingTag(t *testing.T) {
// Every issue the hive files names its filer in the title; AgentIssueTitle
// is the one helper that adds the tag, it puts the tag first, and it never
// adds a second one.
func TestAgentIssueTitleTagsOnceAndTagFirst(t *testing.T) {
cases := []struct{ agent, title, want string }{
{"reviewer", "Review backlog (security): token logged", "[reviewer] Review backlog (security): token logged"},
{"Reviewer", " Review backlog (style): x ", "[reviewer] Review backlog (style): x"},
{"reviewer", "[reviewer] Review backlog (security): token logged", "[reviewer] Review backlog (security): token logged"},
{"tester", "[Tests] v5 test failure on 4536f90", "[Tests] v5 test failure on 4536f90"},
{"dashboard", "[ACMM L0] Add CI/CD pipeline", "[ACMM L0] Add CI/CD pipeline"},
{"reviewer", "[Reviewer]Review backlog (security): x", "[reviewer] Review backlog (security): x"},
{"dedupe", "triage: duplicate and overlapping open issues/PRs to consolidate", "[dedupe] triage: duplicate and overlapping open issues/PRs to consolidate"},
{"ci-maintainer", "refactor: src/a.go is a merge hotspot β€” split into 4 units", "[ci-maintainer] refactor: src/a.go is a merge hotspot β€” split into 4 units"},
{"selfreport", "[selfreport] unclassified_error_repeated: x", "[selfreport] unclassified_error_repeated: x"},
{"governor", "refactor: src/a.go is a merge hotspot β€” split into 4 units", "[governor] refactor: src/a.go is a merge hotspot β€” split into 4 units"},
// Another hive filer already tagged it: never a second tag.
{"governor", "[selfreport] relayed by the hub", "[selfreport] relayed by the hub"},
// The tag comes first, before an emoji the title opens with.
{"governor", "🐝 Hive Advisory Report", "[governor] 🐝 Hive Advisory Report"},
{"reviewer", "πŸ› [reviewer] decision lost on refresh", "[reviewer] πŸ› decision lost on refresh"},
{"governor", "🐝 [selfreport] relayed", "[selfreport] 🐝 relayed"},
// A filer-chosen bracket that is not a filer name is the subject.
{"dashboard", "[ACMM L0] Add CI/CD pipeline", "[dashboard] [ACMM L0] Add CI/CD pipeline"},
{"tester", "[Tests] v5 test failure on 4536f90", "[tester] [Tests] v5 test failure on 4536f90"},
{"", "untagged stays untagged", "untagged stays untagged"},
{"scanner", "", ""},
}
for _, tc := range cases {
if got := TitleFor(tc.agent, tc.title); got != tc.want {
t.Errorf("TitleFor(%q, %q) = %q, want %q", tc.agent, tc.title, got, tc.want)
if got := AgentIssueTitle(tc.agent, tc.title); got != tc.want {
t.Errorf("AgentIssueTitle(%q, %q) = %q, want %q", tc.agent, tc.title, got, tc.want)
}
if again := TitleFor(tc.agent, TitleFor(tc.agent, tc.title)); again != tc.want {
t.Errorf("TitleFor is not idempotent for (%q, %q): %q", tc.agent, tc.title, again)
if again := AgentIssueTitle(tc.agent, AgentIssueTitle(tc.agent, tc.title)); again != tc.want {
t.Errorf("AgentIssueTitle is not idempotent for (%q, %q): %q", tc.agent, tc.title, again)
}
}
}
Expand All @@ -136,15 +146,24 @@ func TestStripAgentPrefixAndSameTitle(t *testing.T) {
if got := StripAgentPrefix(" no tag here "); got != "no tag here" {
t.Fatalf("StripAgentPrefix(untagged) = %q", got)
}
if got := AgentPrefix("[Scanner] split x.go"); got != "scanner" {
if got := StripAgentPrefix("[ACMM L0] Add CI/CD pipeline"); got != "[ACMM L0] Add CI/CD pipeline" {
t.Fatalf("StripAgentPrefix must keep a non-filer bracket: %q", got)
}
if got := AgentPrefix("[scanner] split x.go"); got != "scanner" {
t.Fatalf("AgentPrefix = %q", got)
}
if AgentPrefix("plain") != "" || HasAgentPrefix("plain") {
t.Fatal("untagged title reported a tag")
if AgentPrefix("plain") != "" || HasAgentPrefix("plain") || AgentPrefix("[Tests] failure") != "" || AgentPrefix("πŸ› [reviewer] x") != "" {
t.Fatal("a title without a leading filer tag reported one")
}
if !SameTitle("Review backlog (security): x", "[reviewer] Review backlog (security): x") {
t.Fatal("legacy untagged title must match its tagged successor")
}
if !SameTitle("[ACMM L0] Add CI/CD pipeline", "[dashboard] [ACMM L0] Add CI/CD pipeline") {
t.Fatal("legacy ACMM gap title must match its tagged successor")
}
if !SameTitle("🐝 Hive Advisory Report", "[governor] 🐝 Hive Advisory Report") {
t.Fatal("legacy advisory title must match its tagged successor")
}
if SameTitle("[reviewer] Review backlog (security): x", "[reviewer] Review backlog (security): y") {
t.Fatal("different subjects must not match")
}
Expand Down
2 changes: 1 addition & 1 deletion src/crux/proxy/github_proxy_violations.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func injectOriginLabel(method, path string, body []byte, agentName string) ([]by
if raw, present := payload["title"]; present {
var title string
if err := json.Unmarshal(raw, &title); err == nil && title != "" {
if tagged := issueshape.TitleFor(lane, title); tagged != title {
if tagged := issueshape.AgentIssueTitle(lane, title); tagged != title {
encoded, err := json.Marshal(tagged)
if err != nil {
return body, false
Expand Down
4 changes: 3 additions & 1 deletion src/crux/proxy/origin_label_inject_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ func TestInjectOriginLabelAddsLaneOnceAndKeepsAgentChoice(t *testing.T) {
}{
{name: "no labels field", method: http.MethodPost, path: path, body: `{"title":"t","body":"b"}`, agent: "scanner", wantOK: true, wantLabels: []string{"agent/scanner"}, wantTitle: "[scanner] t"},
{name: "already tagged title kept, replica suffix stripped", method: http.MethodPost, path: path, body: `{"title":"[scanner] t","body":"b","labels":["agent/scanner"]}`, agent: "scanner-2", wantOK: false},
{name: "foreign tag not double-prefixed", method: http.MethodPost, path: path, body: `{"title":"[Tests] t","body":"b"}`, agent: "tester", wantOK: true, wantLabels: []string{"agent/tester"}, wantTitle: "[Tests] t"},
{name: "another filer's tag not double-prefixed", method: http.MethodPost, path: path, body: `{"title":"[selfreport] t","body":"b"}`, agent: "tester", wantOK: true, wantLabels: []string{"agent/tester"}, wantTitle: "[selfreport] t"},
{name: "subject bracket is not a filer tag", method: http.MethodPost, path: path, body: `{"title":"[Tests] t","body":"b"}`, agent: "tester", wantOK: true, wantLabels: []string{"agent/tester"}, wantTitle: "[tester] [Tests] t"},
{name: "tag moves ahead of a leading emoji", method: http.MethodPost, path: path, body: `{"title":"πŸ› [scanner] t","body":"b"}`, agent: "scanner", wantOK: true, wantLabels: []string{"agent/scanner"}, wantTitle: "[scanner] πŸ› t"},
{name: "bare lane label dropped, replica suffix stripped", method: http.MethodPost, path: path, body: `{"title":"t","body":"b","labels":["agent/scanner","scanner","kind/bug"]}`, agent: "scanner-2", wantOK: true, wantLabels: []string{"agent/scanner", "kind/bug"}},
{name: "agent-supplied origin kept while bare filing lane drops", method: http.MethodPost, path: path, body: `{"title":"t","body":"b","labels":["origin/dashboard","agent/scanner","scanner"]}`, agent: "scanner", wantOK: true, wantLabels: []string{"origin/dashboard", "agent/scanner"}},
{name: "agent-supplied matching origin drops redundant origin and bare label", method: http.MethodPost, path: path, body: `{"title":"t","body":"b","labels":["origin/scanner","agent/scanner","scanner","kind/bug"]}`, agent: "scanner", wantOK: true, wantLabels: []string{"agent/scanner", "kind/bug"}},
Expand Down
2 changes: 1 addition & 1 deletion src/docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Read it like a weekly digest, not a to-do list. You don't have to act on everyth

## How to read hive-filed issues

Every issue a hive agent opens has the agent's name in the title β€” for example `[scanner] Possible nil pointer dereference in handler.go:142` or `[quality] Missing test coverage for payment flow`.
Every issue a hive agent opens has the agent's name in the title β€” for example `[scanner] Possible nil pointer dereference in handler.go:142` or `[quality] Missing test coverage for payment flow`. The same holds for issues the hive files on its own behalf: `[reviewer] Review backlog (security): …`, `[dedupe] triage: …`, `[ci-maintainer] refactor: … is a merge hotspot`, `[selfreport] …`, `[governor] 🐝 Hive Advisory Report`. The tag always comes first, before any emoji, and the Activity Monitor draws it as a chip ahead of the title.

When you see a new issue in your project, check the title prefix β€” it tells you which agent filed it and what kind of finding it is:

Expand Down
2 changes: 1 addition & 1 deletion src/docs/operator-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,7 @@ The hive already predicts PR file overlap for the merge train. The advisor reuse
- A file is a **hotspot** when, over the rolling window, at least `hotspot_min_prs` distinct PRs touched it and at least `hotspot_min_overlaps` pairs of them were open at the same time. Score = concurrent pairs Γ— a size weight (1 / 1.25 / 1.5 / 2 at 800 / 1500 / 4000 lines) + 2 Γ— attributed conflicts. Hunk-level "same region" weighting is not available from the train's records and is skipped.
- **Don't splinter.** A split is only recommended for code when the file has at least `hotspot_min_lines` lines **and** two or more top-level symbol groups (Go: funcs and types via `go/ast`, methods grouped under their receiver; JS/TS/Python: top-level declarations; Markdown: `##` headings). The proposal targets at most 4 files of at least 150 lines, no behaviour change, exported API unchanged, tests move with the code.
- **By kind.** Docs (`*.md`, `*.rst`, `*.txt`) are reported but only recommended for a by-section split above 1500 lines (the `docs/api-reference/<area>.md` pattern). Generated files (`// Code generated … DO NOT EDIT`, `*.pb.go`, the dashboard SPA under `pkg/dashboard/static/` β†’ `static-src/`) point at their source β€” unless that source tree is already split into more than 4 files, in which case they are report-only (regeneration makes the output touch every source change). Lock and data files are report-only.
- **One issue per file.** Title `refactor: <path> is a merge hotspot β€” split into <N> units`, labels `agent/ci-maintainer` + `kind/cleanup`, origin `governor`, body marker `<!-- hive:hotspot file=<path> -->`, evidence table, the top-level units, a concrete split proposal and the don't-splinter rule. While that issue is open no second one is filed; after it closes the file waits `hotspot_refile_days` before it can be filed again. **Capped.** At most `hotspot_max_open` modularize issues are open per repo at once (an issue that already has a PR still counts) and at most `hotspot_max_per_pass` are filed per advisor pass; the highest-ranked uncapped hotspot is filed when a slot frees, and the advisor logs one INFO line per pass when the cap holds it back. Issues go through the writeback gate as `issue_file` (a paused repo or `writeback.per_repo[<repo>].mode: off` stops them) and are skipped when the GitHub budget governor is skipping optional sweeps.
- **One issue per file.** Title `[ci-maintainer] refactor: <path> is a merge hotspot β€” split into <N> units` (the tag names the same agent as the label, as every hive-filed issue title does), labels `agent/ci-maintainer` + `kind/cleanup`, origin `governor`, body marker `<!-- hive:hotspot file=<path> -->`, evidence table, the top-level units, a concrete split proposal and the don't-splinter rule. While that issue is open no second one is filed; after it closes the file waits `hotspot_refile_days` before it can be filed again. **Capped.** At most `hotspot_max_open` modularize issues are open per repo at once (an issue that already has a PR still counts) and at most `hotspot_max_per_pass` are filed per advisor pass; the highest-ranked uncapped hotspot is filed when a slot frees, and the advisor logs one INFO line per pass when the cap holds it back. Issues go through the writeback gate as `issue_file` (a paused repo or `writeback.per_repo[<repo>].mode: off` stops them) and are skipped when the GitHub budget governor is skipping optional sweeps.
- **Where to look.** `GET /api/hotspots` (or `hivectl governor hotspots [--repo owner/name]`) lists every hotspot with its recommendation and issue; `/api/status` carries `hotspots: {count, actionable, filed}`. State lives in `/data/hotspots.json`; the analysis runs at most hourly in the eval cycle, the intake on every merge-train sweep. A PR the train has not seen for two hours has its interval closed at its last sighting.

| Key | Default | Meaning |
Expand Down
Loading
Loading