hubkit-cli 0.2.1__tar.gz → 0.2.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/CHANGELOG.md +11 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/PKG-INFO +1 -1
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/docs/architecture.md +1 -1
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/docs/configuration.md +1 -1
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/pyproject.toml +1 -1
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/scripts/hubcore/routed.py +335 -89
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/tests/run_reverts.py +3 -0
- hubkit_cli-0.2.3/tests/test_review_chain.py +84 -0
- hubkit_cli-0.2.1/tests/test_review_chain.py +0 -44
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/.gitignore +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/CLAUDE.md +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/CONTRIBUTING.md +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/LICENSE +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/README.md +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/SECURITY.md +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/SKILL.md +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/config.example.toml +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/docs/commands.md +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/docs/troubleshooting.md +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/intents.example.toml +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/references/design-sources.md +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/references/research.md +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/scripts/hubcore/__init__.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/scripts/hubcore/cli.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/scripts/hubcore/compat.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/scripts/hubcore/config.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/scripts/hubcore/gate.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/scripts/hubcore/hooks.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/scripts/hubcore/inbound.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/scripts/hubcore/install.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/scripts/hubcore/learnings.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/scripts/hubcore/ledger.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/scripts/hubcore/lessons.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/scripts/hubcore/orders.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/scripts/hubcore/redact.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/scripts/hubcore/slow.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/scripts/hubcore/status.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/scripts/hubcore/store.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/scripts/hubcore/trust.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/scripts/hubcore/watcher.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/scripts/hubkit +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/scripts/learn.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/skills/hub-mep/SKILL.md +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/skills/hubkit-setup/SKILL.md +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/tests/conftest.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/tests/test_blockers.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/tests/test_compat.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/tests/test_guards2.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/tests/test_hubkit.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/tests/test_inbound.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/tests/test_install.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/tests/test_learning_rules.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/tests/test_ledger.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/tests/test_lessons.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/tests/test_own_work.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/tests/test_peer_reports.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/tests/test_slow.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/tests/test_state_rules.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/tests/test_tool_guards.py +0 -0
- {hubkit_cli-0.2.1 → hubkit_cli-0.2.3}/tests/test_watcher.py +0 -0
|
@@ -4,6 +4,17 @@ All notable changes to this project are recorded here. The format follows [Keep
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [0.2.3] - 2026-11-06
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
- A job whose title leads with a change verb ("Fix #7 review findings") is not a review item, unless one of its sentences naming the PR leads with a review.
|
|
11
|
+
- The review hard limit (`routed.review_overdue_min`) is raised to the item's own stated `Estimate:` when that is longer.
|
|
12
|
+
|
|
13
|
+
## [0.2.2] - 2026-11-06
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
- A fix job whose change verb and PR number are in different sentences ("Fix the gaps. ... PR #7") is still recognised as a fix job, so its owner pushing to the PR is not counted as a stalled or moved head.
|
|
17
|
+
|
|
7
18
|
## [0.2.1] - 2026-11-06
|
|
8
19
|
|
|
9
20
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: hubkit-cli
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.3
|
|
4
4
|
Summary: Session supervisor for Claude Code: hooks-based multi-agent orchestration with order clocks, routed-work tracking, a watchdog and a stop gate, standard library only.
|
|
5
5
|
Project-URL: Repository, https://github.com/ankitkpandey1/hubkit
|
|
6
6
|
Project-URL: Documentation, https://github.com/ankitkpandey1/hubkit/tree/main/docs
|
|
@@ -67,7 +67,7 @@ A routed item is one outcome per (owner, PR number), or per owner when no PR is
|
|
|
67
67
|
|
|
68
68
|
- **Tracked:** a message naming a PR (URL, `PR 12`, bare `#123` resolved against `routed.repo`) or at least `min_chars` characters, and background `Agent` launches whose brief asks for a result (`Done-when`, `Output`, a PR). **Not tracked:** acknowledgements, short messages without a PR, `skip_owners`, foreground agents, standing watchers (`skip_briefs`), and a reply to a peer who wrote to the hub within `reply_window_min`.
|
|
69
69
|
- **Asks and chases.** Only a new brief is a new ask. Any later non-acknowledgement message to the same owner is a chase: it is counted, never resets the ask's clock, and clears a moved-head or old-head-verdict flag.
|
|
70
|
-
- **Reviews.** A message naming a PR and a `review_words` word ("review #N", "needs a review", "can I get a review on #N") makes a review item, unless it opens with a change verb (fix, address, resolve, apply, ...) and the review word names an existing review ("fix the findings in his review of #N"), on a short clock (`review_stall_min`, hard `OVERDUE` at `review_overdue_min`). It closes itself, PR by PR, when GitHub shows a review by someone other than the author at the PR's current head (on a PR written by `user.github_login`, a COMMENT review with a body counts too, because the reviewer peer posts as that account; an empty-body COMMENT is an inline-thread reply and does not). A review on an older head never closes it. One PR per clock: a message naming several PRs is a queue; "after X's queue" phrasing delays the clock by `queued_wait_min`.
|
|
70
|
+
- **Reviews.** A message naming a PR and a `review_words` word ("review #N", "needs a review", "can I get a review on #N") makes a review item, unless it opens with a change verb (fix, address, resolve, apply, ...) and the review word names an existing review ("fix the findings in his review of #N"), on a short clock (`review_stall_min`, hard `OVERDUE` at `review_overdue_min`, or at the brief's own `Estimate:` when that is longer). A job whose title leads with a change verb is not a review item unless a sentence naming the PR leads with a review. It closes itself, PR by PR, when GitHub shows a review by someone other than the author at the PR's current head (on a PR written by `user.github_login`, a COMMENT review with a body counts too, because the reviewer peer posts as that account; an empty-body COMMENT is an inline-thread reply and does not). A review on an older head never closes it. One PR per clock: a message naming several PRs is a queue; "after X's queue" phrasing delays the clock by `queued_wait_min`.
|
|
71
71
|
- **Heard-from.** A peer message or task notification in the hub transcript, a review on the PR, or a background agent whose transcript or output file is still growing (`routed.activity_globs`) updates the last-heard time.
|
|
72
72
|
- **Ladder.** Silence past `stall_min` climbs: step 1 a one-line state ask, step 2 a re-brief to another owner (not while the owner reported within the limit), step 3 tell the user. Every item shows one `NEXT:` action.
|
|
73
73
|
|
|
@@ -102,7 +102,7 @@ Estimates and the slowness check (hub-internal, see architecture).
|
|
|
102
102
|
| `stall_min` | `15` | Silence from the owner this long is STALLED; the ladder steps at multiples of it. |
|
|
103
103
|
| `review_words` | `["review"]` | A message naming a PR and one of these is a review item. |
|
|
104
104
|
| `review_stall_min` | `5` | Reviews: chase after this. |
|
|
105
|
-
| `review_overdue_min` | `10` | Reviews: hard OVERDUE this long after routing, whatever the owner said. |
|
|
105
|
+
| `review_overdue_min` | `10` | Reviews: hard OVERDUE this long after routing, whatever the owner said. A review brief with its own `Estimate: Nm` line (not a defaulted one) gets the larger of this and N. |
|
|
106
106
|
| `skip_owners` | `["inbox"]` | Owners that are never tracked. |
|
|
107
107
|
| `max_agents` | `4` | More distinct agents than this holding live routed work makes the routed hook warn. |
|
|
108
108
|
| `min_chars` | `200` | A message without a PR is work only from this length. |
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "hubkit-cli"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.3"
|
|
8
8
|
description = "Session supervisor for Claude Code: hooks-based multi-agent orchestration with order clocks, routed-work tracking, a watchdog and a stop gate, standard library only."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.14"
|
|
@@ -49,16 +49,23 @@ def opts(cfg: dict) -> dict:
|
|
|
49
49
|
PUSH = re.compile(
|
|
50
50
|
r"(?i)\b(fix(?:es|ed)?|address|rebase|implement|resolve|amend|patch|push|rework|refactor)\b"
|
|
51
51
|
)
|
|
52
|
-
EXAMPLE = re.compile(
|
|
52
|
+
EXAMPLE = re.compile(
|
|
53
|
+
r"(?i)\b(examples?|e\.g\.|for instance|such as|sample|placeholder|hypothetical)\b"
|
|
54
|
+
)
|
|
53
55
|
QUOTED = re.compile(r"```.*?```|`[^`\n]*`|\"[^\"\n]*\"|\u201c[^\u201d\n]*\u201d", re.S)
|
|
54
|
-
NOUN_BEFORE = re.compile(
|
|
55
|
-
|
|
56
|
+
NOUN_BEFORE = re.compile(
|
|
57
|
+
r"(?i)\b(the|his|her|their|its|a|an|my|our|your|that|this|in|from|with)\s+$"
|
|
58
|
+
)
|
|
59
|
+
NOUN_AFTER = re.compile(
|
|
60
|
+
r"(?i)^s?\s+(comments?|findings?|feedback|notes?|threads?|rounds?)\b"
|
|
61
|
+
)
|
|
56
62
|
|
|
57
63
|
|
|
58
64
|
def strip_examples(text: str) -> str:
|
|
59
65
|
"""The text without what only illustrates: code fences, backtick and quoted spans, and the part of a sentence from
|
|
60
66
|
"example", "e.g." or "such as" on (the line after a header that ends in a colon goes too). What comes before the marker
|
|
61
|
-
stays: "Review #7, e.g. the loader part" still asks for #7. A PR number inside an example is not an ask.
|
|
67
|
+
stays: "Review #7, e.g. the loader part" still asks for #7. A PR number inside an example is not an ask.
|
|
68
|
+
"""
|
|
62
69
|
text = QUOTED.sub(" ", text)
|
|
63
70
|
kept: list[str] = []
|
|
64
71
|
skip_next = False
|
|
@@ -78,6 +85,11 @@ LEADS_CHANGE = re.compile(
|
|
|
78
85
|
)
|
|
79
86
|
|
|
80
87
|
|
|
88
|
+
REVIEW_LEAD = re.compile(
|
|
89
|
+
r"(?i)^\W*(?:(?:please|then|and|also)\s+)*(?:full\s+|gated\s+|re-?)*review\b"
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
|
|
81
93
|
def _kinds(cfg: dict, sentence: str) -> set[str]:
|
|
82
94
|
"""What the owner may be asked to do in one sentence. A review word beside a PR is a review ask by default
|
|
83
95
|
("review #7", "needs a review", "can I get a review on #7"). The one exception: the sentence opens with a change
|
|
@@ -86,11 +98,20 @@ def _kinds(cfg: dict, sentence: str) -> set[str]:
|
|
|
86
98
|
PR, not to review it. "push" marks a change verb anywhere."""
|
|
87
99
|
low = sentence.lower()
|
|
88
100
|
out = {"push"} if PUSH.search(low) else set()
|
|
89
|
-
hits = [
|
|
90
|
-
|
|
101
|
+
hits = [
|
|
102
|
+
m
|
|
103
|
+
for w in (x.lower() for x in opts(cfg)["review_words"])
|
|
104
|
+
for m in re.finditer(re.escape(w), low)
|
|
105
|
+
]
|
|
106
|
+
existing = all(
|
|
107
|
+
NOUN_BEFORE.search(low[: m.start()]) or NOUN_AFTER.match(low[m.end() :])
|
|
108
|
+
for m in hits
|
|
109
|
+
)
|
|
91
110
|
words = [x.lower() for x in opts(cfg)["review_words"]]
|
|
92
111
|
later = [c.strip() for c in re.split(r",|\bthen\b|\band\b", low)[1:]]
|
|
93
|
-
asks_later = any(
|
|
112
|
+
asks_later = any(
|
|
113
|
+
any(w in c for w in words) and not LEADS_CHANGE.match(c) for c in later
|
|
114
|
+
)
|
|
94
115
|
if hits and not (LEADS_CHANGE.match(low) and existing and not asks_later):
|
|
95
116
|
out.add("review")
|
|
96
117
|
return out
|
|
@@ -98,7 +119,9 @@ def _kinds(cfg: dict, sentence: str) -> set[str]:
|
|
|
98
119
|
|
|
99
120
|
def _asks(cfg: dict, text: str, summary: str = "") -> set[str]:
|
|
100
121
|
"""The kinds of ask (see _kinds) in the sentences that name a PR, plus the summary when the text names one."""
|
|
101
|
-
sentences = [
|
|
122
|
+
sentences = [
|
|
123
|
+
x for x in re.split(r"(?<=[.!?])\s+|\n", text) if x.strip() and PR_REF.search(x)
|
|
124
|
+
]
|
|
102
125
|
if summary.strip() and PR_REF.search(text + " " + summary):
|
|
103
126
|
sentences.append(summary)
|
|
104
127
|
return set().union(*(_kinds(cfg, x) for x in sentences)) if sentences else set()
|
|
@@ -108,29 +131,52 @@ def is_review(cfg: dict, text: str, summary: str = "") -> bool:
|
|
|
108
131
|
"""A review ask: the owner is asked to review a PR, i.e. a sentence naming a PR leads with a review word (or the
|
|
109
132
|
summary does). A review word elsewhere (a handover, a status) or as a noun after another action ("fix the
|
|
110
133
|
findings in his review of #7") does not make it one."""
|
|
111
|
-
|
|
134
|
+
body = strip_examples(text)
|
|
135
|
+
if "review" not in _asks(cfg, body, summary):
|
|
136
|
+
return False
|
|
137
|
+
# a job titled as a change ("Fix #7 review findings") asks for changes, not a verdict, unless a sentence leads with a review
|
|
138
|
+
leads_review = any(
|
|
139
|
+
REVIEW_LEAD.match(x)
|
|
140
|
+
for x in re.split(r"(?<=[.!?])\s+|\n", body)
|
|
141
|
+
if PR_REF.search(x)
|
|
142
|
+
)
|
|
143
|
+
return not (LEADS_CHANGE.match(summary.strip().lower()) and not leads_review)
|
|
112
144
|
|
|
113
145
|
|
|
114
146
|
def pushes_to_pr(cfg: dict, text: str, summary: str = "") -> bool:
|
|
115
147
|
"""The owner is asked to change the PR (fix, rebase, address findings): its own pushes move the head."""
|
|
116
|
-
|
|
148
|
+
body = strip_examples(text)
|
|
149
|
+
if "push" in _asks(cfg, body, summary):
|
|
150
|
+
return True
|
|
151
|
+
# a fix job whose change verb sits in another sentence than the PR number ("Fix the gaps. ... PR #7"): still a fix job
|
|
152
|
+
return (
|
|
153
|
+
bool(PR_REF.search(text + " " + summary))
|
|
154
|
+
and bool(PUSH.search(body + " " + summary))
|
|
155
|
+
and not is_review(cfg, text, summary)
|
|
156
|
+
)
|
|
117
157
|
|
|
118
158
|
|
|
119
159
|
def owner_is_author(cfg: dict, owner: str, author: str) -> bool:
|
|
120
160
|
"""Is the owner the PR's author? A peer or agent has no GitHub login, so this uses the data on hand: an
|
|
121
161
|
explicit `routed.owner_logins` map (owner name -> login), else the owner's name equals the login or contains
|
|
122
|
-
it (a login of 4+ characters). An agent id never matches, so it is treated as a non-author.
|
|
162
|
+
it (a login of 4+ characters). An agent id never matches, so it is treated as a non-author.
|
|
163
|
+
"""
|
|
123
164
|
login = author.lower()
|
|
124
165
|
if not login:
|
|
125
166
|
return False
|
|
126
167
|
mapped = opts(cfg)["owner_logins"].get(owner)
|
|
127
|
-
return (
|
|
168
|
+
return (
|
|
169
|
+
(mapped or "").lower() == login
|
|
170
|
+
or owner.lower() == login
|
|
171
|
+
or (len(login) >= 4 and login in owner.lower())
|
|
172
|
+
)
|
|
128
173
|
|
|
129
174
|
|
|
130
175
|
def is_chase(cfg: dict, text: str) -> bool:
|
|
131
176
|
"""A short status question about a PR: an event on the existing item, not a new ask. A message with a brief marker
|
|
132
177
|
(Done-when, Output) or a sentence that opens with an action on a PR (Review #N ...) is an ask whatever else it
|
|
133
|
-
says; a status question that merely mentions a review ("state of the review on #N") is not.
|
|
178
|
+
says; a status question that merely mentions a review ("state of the review on #N") is not.
|
|
179
|
+
"""
|
|
134
180
|
sentences = [x.strip() for x in re.split(r"(?<=[.!?])\s+|\n", text)]
|
|
135
181
|
if DELIVERABLE.search(text) or any(DIRECTIVE.match(x) for x in sentences):
|
|
136
182
|
return False
|
|
@@ -152,14 +198,17 @@ DELIVERABLE = re.compile(r"(?i)done[- ]when|\boutput\b|\bdeliverable")
|
|
|
152
198
|
|
|
153
199
|
def is_deliverable_brief(cfg: dict, description: str, prompt: str) -> bool:
|
|
154
200
|
"""A background agent is routed work only when its brief asks for a result (a PR, an Output, a Done-when) and is
|
|
155
|
-
not a standing watcher (`routed.skip_briefs`); a long-running agent with nothing to deliver cannot stall.
|
|
201
|
+
not a standing watcher (`routed.skip_briefs`); a long-running agent with nothing to deliver cannot stall.
|
|
202
|
+
"""
|
|
156
203
|
low = f"{description} {prompt}".lower()
|
|
157
204
|
if any(w.lower() in low for w in opts(cfg)["skip_briefs"]):
|
|
158
205
|
return False
|
|
159
206
|
return bool(DELIVERABLE.search(prompt) or PR_REF.search(prompt))
|
|
160
207
|
|
|
161
208
|
|
|
162
|
-
def _is_reply(
|
|
209
|
+
def _is_reply(
|
|
210
|
+
cfg: dict, owner: str, text: str, asked: list[str], now: float | None
|
|
211
|
+
) -> bool:
|
|
163
212
|
"""The hub answering a peer who wrote to it recently, with no PR to work on and no brief, is not an ask."""
|
|
164
213
|
if asked or DELIVERABLE.search(text):
|
|
165
214
|
return False
|
|
@@ -199,7 +248,9 @@ def is_work(cfg: dict, owner: str, text: str, asked: list[str] | None = None) ->
|
|
|
199
248
|
o = opts(cfg)
|
|
200
249
|
if any(s.lower() in owner.lower() for s in o["skip_owners"]):
|
|
201
250
|
return False
|
|
202
|
-
if ACK.match(text) and not (
|
|
251
|
+
if ACK.match(text) and not (
|
|
252
|
+
DELIVERABLE.search(text) or DIRECTIVE.search(text) or REQUEST.search(text)
|
|
253
|
+
):
|
|
203
254
|
return False # "Ack #399 hold": a bare acknowledgement that names a PR is not an ask; any request cue makes it one
|
|
204
255
|
if asked if asked is not None else PR_REF.search(text):
|
|
205
256
|
return True
|
|
@@ -215,8 +266,14 @@ SHORT_ASK = re.compile(
|
|
|
215
266
|
|
|
216
267
|
def is_short_ask(text: str) -> bool:
|
|
217
268
|
"""A short message that asks the peer to do or answer something: a request verb opening a sentence, or a question.
|
|
218
|
-
Not an acknowledgement, not a status question (that is a chase), and long enough to carry a request.
|
|
219
|
-
|
|
269
|
+
Not an acknowledgement, not a status question (that is a chase), and long enough to carry a request.
|
|
270
|
+
"""
|
|
271
|
+
return (
|
|
272
|
+
len(text.strip()) >= 15
|
|
273
|
+
and not ACK.match(text)
|
|
274
|
+
and not CHASE.search(text)
|
|
275
|
+
and bool(SHORT_ASK.search(text))
|
|
276
|
+
)
|
|
220
277
|
|
|
221
278
|
|
|
222
279
|
REQUEST = re.compile(
|
|
@@ -228,7 +285,9 @@ DIRECTIVE = re.compile(
|
|
|
228
285
|
)
|
|
229
286
|
|
|
230
287
|
|
|
231
|
-
def asked_refs(
|
|
288
|
+
def asked_refs(
|
|
289
|
+
cfg: dict, text: str, summary: str = "", cap: int | None = MAX_QUEUE
|
|
290
|
+
) -> list[str]:
|
|
232
291
|
"""The PRs the owner is asked to work on. A short message asks about every PR it names. In a long one only
|
|
233
292
|
the summary and sentences that direct an action at a PR count: a PR named in passing (a bug
|
|
234
293
|
list, a status) is not an ask."""
|
|
@@ -247,7 +306,11 @@ def pr_num(ref: str) -> str:
|
|
|
247
306
|
def pr_key(ref: str) -> str:
|
|
248
307
|
"""Repo and number of a PR ref: `owner/repo#N` for a URL, `#N` for a bare number (repo not known)."""
|
|
249
308
|
parts = ref.rstrip("/").split("/")
|
|
250
|
-
return
|
|
309
|
+
return (
|
|
310
|
+
f"{parts[3]}/{parts[4]}#{parts[6]}".lower()
|
|
311
|
+
if ref.startswith("http") and len(parts) >= 7
|
|
312
|
+
else "#" + pr_num(ref)
|
|
313
|
+
)
|
|
251
314
|
|
|
252
315
|
|
|
253
316
|
def same_pr(a: str, b: str) -> bool:
|
|
@@ -287,7 +350,11 @@ def _repo_refs(cfg: dict, text: str) -> tuple[list[str], str]:
|
|
|
287
350
|
|
|
288
351
|
text = REPO_REF.sub(repl(), text)
|
|
289
352
|
for alias, repo in dict(opts(cfg).get("repo_aliases", {})).items():
|
|
290
|
-
text = re.sub(
|
|
353
|
+
text = re.sub(
|
|
354
|
+
rf"(?i)(?<![\w/.-]){re.escape(alias)}(?:\s*#|\s+pr\s*#?\s*|\s+)(\d{{2,6}})\b",
|
|
355
|
+
repl(repo),
|
|
356
|
+
text,
|
|
357
|
+
)
|
|
291
358
|
return list(dict.fromkeys(out)), text
|
|
292
359
|
|
|
293
360
|
|
|
@@ -335,9 +402,17 @@ def pr_info(cfg: dict, url: str, timeout: float) -> dict | None:
|
|
|
335
402
|
return None
|
|
336
403
|
try:
|
|
337
404
|
r = subprocess.run(
|
|
338
|
-
[
|
|
405
|
+
[
|
|
406
|
+
exe,
|
|
407
|
+
"pr",
|
|
408
|
+
"view",
|
|
409
|
+
url,
|
|
410
|
+
"--json",
|
|
411
|
+
"headRefOid,reviews,author,commits,state,statusCheckRollup",
|
|
412
|
+
],
|
|
339
413
|
capture_output=True,
|
|
340
|
-
encoding="utf-8",
|
|
414
|
+
encoding="utf-8",
|
|
415
|
+
errors="replace",
|
|
341
416
|
timeout=timeout,
|
|
342
417
|
check=False,
|
|
343
418
|
)
|
|
@@ -366,7 +441,14 @@ def pr_info(cfg: dict, url: str, timeout: float) -> dict | None:
|
|
|
366
441
|
return None
|
|
367
442
|
|
|
368
443
|
|
|
369
|
-
FAILED_CHECK = {
|
|
444
|
+
FAILED_CHECK = {
|
|
445
|
+
"FAILURE",
|
|
446
|
+
"TIMED_OUT",
|
|
447
|
+
"CANCELLED",
|
|
448
|
+
"STARTUP_FAILURE",
|
|
449
|
+
"ACTION_REQUIRED",
|
|
450
|
+
"ERROR",
|
|
451
|
+
}
|
|
370
452
|
OK_CHECK = {"SUCCESS", "NEUTRAL", "SKIPPED"}
|
|
371
453
|
|
|
372
454
|
|
|
@@ -374,7 +456,11 @@ def ci_state(rollup: object) -> str:
|
|
|
374
456
|
"""CI at the PR's head from gh's statusCheckRollup: 'failing', 'pending', 'green', or 'none' (no checks reported)."""
|
|
375
457
|
if not isinstance(rollup, list) or not rollup:
|
|
376
458
|
return "none"
|
|
377
|
-
seen = {
|
|
459
|
+
seen = {
|
|
460
|
+
str(c.get("conclusion") or c.get("state") or "").upper() or "PENDING"
|
|
461
|
+
for c in rollup
|
|
462
|
+
if isinstance(c, dict)
|
|
463
|
+
}
|
|
378
464
|
if seen & FAILED_CHECK:
|
|
379
465
|
return "failing"
|
|
380
466
|
return "green" if seen <= OK_CHECK else "pending"
|
|
@@ -445,12 +531,15 @@ def _same_job(i: dict, owner: str, prs: list[str], summary: str) -> bool:
|
|
|
445
531
|
return False
|
|
446
532
|
if prs:
|
|
447
533
|
return overlaps([*i["prs"], *i.get("queue", [])], prs)
|
|
448
|
-
return not i[
|
|
534
|
+
return not i[
|
|
535
|
+
"prs"
|
|
536
|
+
] # no PR named: a follow-up to the same owner is the same outcome
|
|
449
537
|
|
|
450
538
|
|
|
451
539
|
def _chase(cfg: dict, item: dict, text: str, heads: dict[str, str], now: float) -> None:
|
|
452
540
|
"""A follow-up to the owner about work already on the item: counted, never a new clock. It answers a moved head
|
|
453
|
-
or an old-head verdict (the hub acted), so those flags clear and the new head becomes the baseline.
|
|
541
|
+
or an old-head verdict (the hub acted), so those flags clear and the new head becomes the baseline.
|
|
542
|
+
"""
|
|
454
543
|
_event(item, "chase", text, now)
|
|
455
544
|
item["chases"] = int(item.get("chases", 0)) + 1
|
|
456
545
|
item["addressed"] = [*item.get("addressed", []), now]
|
|
@@ -462,7 +551,9 @@ def _chase(cfg: dict, item: dict, text: str, heads: dict[str, str], now: float)
|
|
|
462
551
|
item["heads"] = {**item["heads"], **heads}
|
|
463
552
|
|
|
464
553
|
|
|
465
|
-
def chase_owner(
|
|
554
|
+
def chase_owner(
|
|
555
|
+
cfg: dict, owner: str, text: str, now: float | None = None
|
|
556
|
+
) -> dict | None:
|
|
466
557
|
"""A message to an owner who has open items, naming no PR and carrying no new brief, is a follow-up on all of
|
|
467
558
|
them. Returns the first item, or None when the owner has none."""
|
|
468
559
|
now = now or time.time()
|
|
@@ -508,7 +599,9 @@ def record(
|
|
|
508
599
|
if hit is not None and (chase or follow_up):
|
|
509
600
|
_chase(cfg, hit, summary, heads, now)
|
|
510
601
|
if not hit.get("queue"):
|
|
511
|
-
hit["prs"] = _merge_prs(
|
|
602
|
+
hit["prs"] = _merge_prs(
|
|
603
|
+
hit["prs"], prs
|
|
604
|
+
) # a full URL replaces a bare #N
|
|
512
605
|
work_save(sd, all_)
|
|
513
606
|
return hit
|
|
514
607
|
is_new = hit is None
|
|
@@ -528,14 +621,37 @@ def record(
|
|
|
528
621
|
all_.append(hit)
|
|
529
622
|
moved: list[dict] = []
|
|
530
623
|
if is_new:
|
|
531
|
-
hit["behind"] = [
|
|
532
|
-
|
|
533
|
-
|
|
624
|
+
hit["behind"] = [
|
|
625
|
+
i["id"]
|
|
626
|
+
for i in all_
|
|
627
|
+
if i is not hit and i.get("kind") == "routed" and i["owner"] == owner
|
|
628
|
+
]
|
|
629
|
+
for (
|
|
630
|
+
other
|
|
631
|
+
) in (
|
|
632
|
+
all_
|
|
633
|
+
): # a brief on the same PRs to another owner is a re-brief: it addresses the old item
|
|
634
|
+
if (
|
|
635
|
+
other is not hit
|
|
636
|
+
and other.get("kind") == "routed"
|
|
637
|
+
and other["owner"] != owner
|
|
638
|
+
and overlaps(named, [*other["prs"], *other.get("queue", [])])
|
|
639
|
+
):
|
|
534
640
|
other["addressed"] = [*other.get("addressed", []), now]
|
|
535
|
-
if
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
other["
|
|
641
|
+
if (
|
|
642
|
+
brief
|
|
643
|
+
): # a real re-brief moves the PRs: the old owner no longer holds them
|
|
644
|
+
other["prs"] = [
|
|
645
|
+
u for u in other["prs"] if not overlaps([u], named)
|
|
646
|
+
]
|
|
647
|
+
other["queue"] = [
|
|
648
|
+
u
|
|
649
|
+
for u in other.get("queue", [])
|
|
650
|
+
if not overlaps([u], named)
|
|
651
|
+
]
|
|
652
|
+
other["heads"] = {
|
|
653
|
+
u: h for u, h in other["heads"].items() if u in other["prs"]
|
|
654
|
+
}
|
|
539
655
|
if not other["prs"]:
|
|
540
656
|
_archive(cfg, other, f"re-briefed to {owner}", now)
|
|
541
657
|
moved.append(other)
|
|
@@ -557,7 +673,9 @@ def record(
|
|
|
557
673
|
chased_level=None,
|
|
558
674
|
)
|
|
559
675
|
_set_estimate(cfg, hit, estimate, now)
|
|
560
|
-
hit.setdefault(
|
|
676
|
+
hit.setdefault(
|
|
677
|
+
"heads0", dict(heads)
|
|
678
|
+
) # the head when first asked: a later head is the owner's artifact
|
|
561
679
|
hit["heads"] = {
|
|
562
680
|
**hit["heads"],
|
|
563
681
|
**heads,
|
|
@@ -578,8 +696,21 @@ def _set_estimate(cfg: dict, item: dict, given: int | None, now: float) -> None:
|
|
|
578
696
|
from . import slow
|
|
579
697
|
|
|
580
698
|
mins, basis = (float(given), "brief") if given else slow.item_default(cfg, item)
|
|
581
|
-
item["estimates"] = [
|
|
582
|
-
|
|
699
|
+
item["estimates"] = [
|
|
700
|
+
*item.get("estimates", []),
|
|
701
|
+
{
|
|
702
|
+
"t": now,
|
|
703
|
+
"min": mins,
|
|
704
|
+
"source": "brief" if given else "default",
|
|
705
|
+
"basis": basis,
|
|
706
|
+
},
|
|
707
|
+
]
|
|
708
|
+
item.update(
|
|
709
|
+
estimate_min=mins,
|
|
710
|
+
estimate_defaulted=not given,
|
|
711
|
+
estimate_basis=basis,
|
|
712
|
+
addressed=[],
|
|
713
|
+
)
|
|
583
714
|
|
|
584
715
|
|
|
585
716
|
def from_tool(
|
|
@@ -599,7 +730,9 @@ def from_tool(
|
|
|
599
730
|
if _is_follow_up(cfg, owner, text):
|
|
600
731
|
return chase_owner(cfg, owner, str(ti.get("summary") or text), now)
|
|
601
732
|
asked = asked_refs(cfg, text, str(ti.get("summary") or ""))
|
|
602
|
-
if _is_reply(cfg, owner, text, asked, now) or not is_work(
|
|
733
|
+
if _is_reply(cfg, owner, text, asked, now) or not is_work(
|
|
734
|
+
cfg, owner, text, asked
|
|
735
|
+
):
|
|
603
736
|
return None
|
|
604
737
|
summary = str(ti.get("summary") or text.splitlines()[0])[:120]
|
|
605
738
|
chase = is_chase(cfg, text)
|
|
@@ -620,7 +753,9 @@ def from_tool(
|
|
|
620
753
|
else:
|
|
621
754
|
return None
|
|
622
755
|
every = asked_refs(cfg, text, summary)
|
|
623
|
-
queue =
|
|
756
|
+
queue = (
|
|
757
|
+
every if len(every) > 1 else []
|
|
758
|
+
) # one PR per clock: several PRs are a queue, the first is current
|
|
624
759
|
prs = every[:1] if queue else every
|
|
625
760
|
heads: dict[str, str] = {}
|
|
626
761
|
authored = False
|
|
@@ -672,11 +807,12 @@ def limit(cfg: dict, item: dict) -> float:
|
|
|
672
807
|
def overdue(cfg: dict, item: dict, now: float) -> int | None:
|
|
673
808
|
"""Minutes since the ask when a review passes its hard limit (hearing from the owner does not stop it)."""
|
|
674
809
|
age = int((now - started_at(cfg, item)) / 60)
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
810
|
+
hard = float(opts(cfg)["review_overdue_min"])
|
|
811
|
+
if item.get("estimate_min") is not None and not item.get("estimate_defaulted"):
|
|
812
|
+
hard = max(
|
|
813
|
+
hard, float(item["estimate_min"])
|
|
814
|
+
) # the job's own stated estimate sets its limit
|
|
815
|
+
return age if item.get("review") and age > hard else None
|
|
680
816
|
|
|
681
817
|
|
|
682
818
|
def level(cfg: dict, item: dict, now: float) -> int | None:
|
|
@@ -732,8 +868,10 @@ def next_action(cfg: dict, item: dict, now: float) -> str:
|
|
|
732
868
|
lvl = eff_level(cfg, item, now)
|
|
733
869
|
if item.get("reported") and not item.get("review"):
|
|
734
870
|
prs = " ".join(_pr_no(u) for u in item["prs"])
|
|
735
|
-
return (
|
|
736
|
-
|
|
871
|
+
return (
|
|
872
|
+
f"{o} reported it done {int((now - item['reported']) / 60)} min ago; that is a claim. Check the artifact"
|
|
873
|
+
f"{' (' + prs + ')' if prs else ''}, then: hubkit work done {item['id']} --note \"<what you checked>\""
|
|
874
|
+
)
|
|
737
875
|
if lvl is not None:
|
|
738
876
|
if item.get("chased_level") is not None and item["chased_level"] >= lvl:
|
|
739
877
|
nxt = base(cfg, item) + limit(cfg, item) * 60 * (lvl + 2)
|
|
@@ -813,7 +951,9 @@ def alerts(cfg: dict, now: float) -> list[dict]:
|
|
|
813
951
|
}
|
|
814
952
|
)
|
|
815
953
|
lvl = eff_level(cfg, i, now)
|
|
816
|
-
if lvl is not None and needs_action(
|
|
954
|
+
if lvl is not None and needs_action(
|
|
955
|
+
cfg, i, now
|
|
956
|
+
): # a chased item waits: no alert, no wake-up
|
|
817
957
|
out.append(
|
|
818
958
|
{
|
|
819
959
|
"key": f"{i['id']}:routed_stalled:L{lvl}",
|
|
@@ -836,8 +976,10 @@ def block_lines(cfg: dict, work: list[dict], now: float) -> list[str]:
|
|
|
836
976
|
pr = ", ".join(
|
|
837
977
|
f"{_pr_no(u)}@{i['heads'].get(u, '?')[:7]}" for u in i.get("prs", [])
|
|
838
978
|
)
|
|
839
|
-
flags = (
|
|
840
|
-
"
|
|
979
|
+
flags = (
|
|
980
|
+
(f" +{len(i['queue']) - 1} queued" if i.get("queue") else "")
|
|
981
|
+
+ (" REVIEW" if i.get("review") else "")
|
|
982
|
+
+ (" PR unknown" if i.get("pr_unknown") else "")
|
|
841
983
|
)
|
|
842
984
|
out.append(
|
|
843
985
|
f" {i['id']} -> {i['owner']}: {i['title'][:50]}{' [' + pr + ']' if pr else ''}{flags}; "
|
|
@@ -868,15 +1010,28 @@ def heard(cfg: dict, events: list[tuple[float, str, str]]) -> int:
|
|
|
868
1010
|
i["owner"] in text
|
|
869
1011
|
or bool(i.get("tool_use_id") and i["tool_use_id"] in text)
|
|
870
1012
|
)
|
|
871
|
-
if
|
|
1013
|
+
if (
|
|
1014
|
+
by_text
|
|
1015
|
+
and COMPLETED.search(text)
|
|
1016
|
+
and ts > (i.get("routed_at") or i["added"])
|
|
1017
|
+
):
|
|
872
1018
|
i["reported"] = ts # the agent finished after this ask and reported
|
|
873
|
-
if not i.get(
|
|
1019
|
+
if not i.get(
|
|
1020
|
+
"review"
|
|
1021
|
+
): # a review item stays: the review check on the PR decides
|
|
874
1022
|
i["answered"] = True
|
|
875
1023
|
i["done_note"] = "agent completed (task notification)"
|
|
876
1024
|
from_owner = bool(name) and name.lower() == i["owner"].lower()
|
|
877
|
-
if
|
|
878
|
-
|
|
879
|
-
|
|
1025
|
+
if (
|
|
1026
|
+
from_owner
|
|
1027
|
+
and not i.get("review")
|
|
1028
|
+
and ts > (i.get("routed_at") or i["added"])
|
|
1029
|
+
and is_report(text)
|
|
1030
|
+
and _report_is_about(all_, i, text)
|
|
1031
|
+
):
|
|
1032
|
+
i["reported"] = (
|
|
1033
|
+
ts # a claim, not evidence: the item closes on the artifact (refresh_prs) or on `work done`
|
|
1034
|
+
)
|
|
880
1035
|
i["claimed"] = text[:160]
|
|
881
1036
|
n += 1 # a change to save even when no last_heard moved
|
|
882
1037
|
if (name.lower() == i["owner"].lower() or by_text) and ts > (
|
|
@@ -885,10 +1040,14 @@ def heard(cfg: dict, events: list[tuple[float, str, str]]) -> int:
|
|
|
885
1040
|
i["last_heard"] = ts
|
|
886
1041
|
n += 1
|
|
887
1042
|
if i.get("state_ask") and ts > (i.get("routed_at") or 0):
|
|
888
|
-
i["answered"] =
|
|
1043
|
+
i["answered"] = (
|
|
1044
|
+
True # a state question is answered by one reply
|
|
1045
|
+
)
|
|
889
1046
|
closing = [x for x in all_ if x.get("answered")]
|
|
890
1047
|
for i in closing:
|
|
891
|
-
_archive(
|
|
1048
|
+
_archive(
|
|
1049
|
+
cfg, i, i.get("done_note") or "state question answered", time.time()
|
|
1050
|
+
)
|
|
892
1051
|
all_.remove(i)
|
|
893
1052
|
if n or closing:
|
|
894
1053
|
work_save(sd, all_)
|
|
@@ -896,22 +1055,39 @@ def heard(cfg: dict, events: list[tuple[float, str, str]]) -> int:
|
|
|
896
1055
|
|
|
897
1056
|
|
|
898
1057
|
COMPLETED = re.compile(r"<status>\s*completed\s*</status>")
|
|
899
|
-
PEER_BODY = re.compile(
|
|
900
|
-
|
|
901
|
-
|
|
1058
|
+
PEER_BODY = re.compile(
|
|
1059
|
+
r"<cross-session-message[^>]*>(.*?)(?:</cross-session-message>|\Z)", re.S
|
|
1060
|
+
)
|
|
1061
|
+
PEER_RESULT = re.compile(
|
|
1062
|
+
r"(?i)\b(done|finished|complete[d]?|merged|pushed|passed|passing|green|fixed|shipped|result|ready for)\b"
|
|
1063
|
+
)
|
|
1064
|
+
PEER_NOT_RESULT = re.compile(
|
|
1065
|
+
r"(?i)\b(blocked|failed|failing|cannot|can't|couldn't|unable|error|stuck|waiting)\b"
|
|
1066
|
+
)
|
|
902
1067
|
|
|
903
1068
|
|
|
904
1069
|
def _report_is_about(all_: list[dict], item: dict, text: str) -> bool:
|
|
905
1070
|
"""A report closes the owner's only item; when the owner holds several, it must name this item's PR or id."""
|
|
906
|
-
mine = [
|
|
907
|
-
|
|
1071
|
+
mine = [
|
|
1072
|
+
x for x in all_ if x.get("kind") == "routed" and x["owner"] == item["owner"]
|
|
1073
|
+
]
|
|
1074
|
+
return (
|
|
1075
|
+
len(mine) == 1
|
|
1076
|
+
or any(pr_num(u) in re.findall(r"\d+", text) for u in item["prs"])
|
|
1077
|
+
or item["id"] in text
|
|
1078
|
+
)
|
|
908
1079
|
|
|
909
1080
|
|
|
910
1081
|
def is_report(text: str) -> bool:
|
|
911
1082
|
"""A peer's message reports a result: a result word, no blocker word, and it does not end on a question."""
|
|
912
1083
|
m = PEER_BODY.search(text)
|
|
913
1084
|
body = (m[1] if m else text).strip()
|
|
914
|
-
return
|
|
1085
|
+
return (
|
|
1086
|
+
bool(body)
|
|
1087
|
+
and not body.endswith("?")
|
|
1088
|
+
and bool(PEER_RESULT.search(body))
|
|
1089
|
+
and not PEER_NOT_RESULT.search(body)
|
|
1090
|
+
)
|
|
915
1091
|
|
|
916
1092
|
|
|
917
1093
|
def peer_name(text: str) -> str:
|
|
@@ -1008,12 +1184,16 @@ def _landed(
|
|
|
1008
1184
|
out: dict[str, tuple[str, dict | None]] = {}
|
|
1009
1185
|
for u in item["prs"]:
|
|
1010
1186
|
info = got.get(u)
|
|
1011
|
-
revs =
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1187
|
+
revs = (
|
|
1188
|
+
[
|
|
1189
|
+
r
|
|
1190
|
+
for r in (info["reviews"] if info else [])
|
|
1191
|
+
if r["at"] >= (item.get("routed_at") or item["added"])
|
|
1192
|
+
and counts_as_review(cfg, r, info)
|
|
1193
|
+
]
|
|
1194
|
+
if info
|
|
1195
|
+
else []
|
|
1196
|
+
)
|
|
1017
1197
|
if not info or not revs:
|
|
1018
1198
|
out[u] = ("", None)
|
|
1019
1199
|
continue
|
|
@@ -1068,11 +1248,24 @@ def _advance(item: dict, det: dict, now: float) -> dict:
|
|
|
1068
1248
|
item["queue"] = rest if len(rest) > 1 else []
|
|
1069
1249
|
item["prs"] = rest[:1]
|
|
1070
1250
|
item["heads"] = {}
|
|
1071
|
-
item.update(
|
|
1072
|
-
|
|
1251
|
+
item.update(
|
|
1252
|
+
routed_at=now,
|
|
1253
|
+
head_moved=None,
|
|
1254
|
+
verdict_old_head=None,
|
|
1255
|
+
verdict_acked=None,
|
|
1256
|
+
chased_level=None,
|
|
1257
|
+
)
|
|
1258
|
+
_event(
|
|
1259
|
+
item,
|
|
1260
|
+
"advance",
|
|
1261
|
+
f"{_pr_no(done)} reviewed; now {_pr_no(rest[0]) if rest else 'none'}",
|
|
1262
|
+
now,
|
|
1263
|
+
)
|
|
1073
1264
|
return {
|
|
1074
1265
|
"key": f"{item['id']}:queue_advanced:{pr_num(done)}",
|
|
1075
|
-
"msg":
|
|
1266
|
+
"msg": (
|
|
1267
|
+
f"{item['id']} to {item['owner']}: {_pr_no(done)} {det['state']} at {det['commit'][:7]}; the clock restarts on the next PR. NEXT: read the review on GitHub and act on it"
|
|
1268
|
+
),
|
|
1076
1269
|
}
|
|
1077
1270
|
|
|
1078
1271
|
|
|
@@ -1081,7 +1274,11 @@ def artifact_exists(item: dict, url: str, info: dict) -> bool:
|
|
|
1081
1274
|
if info.get("state") in ("MERGED", "CLOSED"):
|
|
1082
1275
|
return True
|
|
1083
1276
|
first = str((item.get("heads0") or {}).get(url) or "")
|
|
1084
|
-
return
|
|
1277
|
+
return (
|
|
1278
|
+
bool(first)
|
|
1279
|
+
and not same_head(first, info["head"])
|
|
1280
|
+
and info.get("ci", "none") != "failing"
|
|
1281
|
+
)
|
|
1085
1282
|
|
|
1086
1283
|
|
|
1087
1284
|
def next_step(cfg: dict, d: dict, owner: str) -> str:
|
|
@@ -1103,7 +1300,13 @@ def next_step(cfg: dict, d: dict, owner: str) -> str:
|
|
|
1103
1300
|
|
|
1104
1301
|
def _reply_owed(cfg: dict, item: dict, done: dict[str, dict]) -> str:
|
|
1105
1302
|
"""Names the people who asked the hub for this review (inbound reply items on the same PRs)."""
|
|
1106
|
-
who = sorted(
|
|
1303
|
+
who = sorted(
|
|
1304
|
+
{
|
|
1305
|
+
x["owner"]
|
|
1306
|
+
for x in work_load(store.state(cfg))
|
|
1307
|
+
if x.get("kind") == "reply" and overlaps(list(done), x.get("prs", []))
|
|
1308
|
+
}
|
|
1309
|
+
)
|
|
1107
1310
|
return f" Reply owed to: {', '.join(who)}." if who else ""
|
|
1108
1311
|
|
|
1109
1312
|
|
|
@@ -1117,13 +1320,19 @@ def _close_landed(cfg: dict, item: dict, done: dict[str, dict], now: float) -> d
|
|
|
1117
1320
|
f"{_pr_no(u)} {d['state']} by {d['login']} at {d['commit'][:7]} (the head), CI {d.get('ci', 'none')}"
|
|
1118
1321
|
for u, d in done.items()
|
|
1119
1322
|
)
|
|
1120
|
-
gap =
|
|
1323
|
+
gap = (
|
|
1324
|
+
f" Still open: {' '.join(_pr_no(u) for u in item['prs'])} (no review at its head yet)."
|
|
1325
|
+
if item["prs"]
|
|
1326
|
+
else ""
|
|
1327
|
+
)
|
|
1121
1328
|
if not item["prs"]:
|
|
1122
1329
|
_archive(cfg, item, "review " + note, now)
|
|
1123
1330
|
first = next(iter(done.values()))
|
|
1124
1331
|
return {
|
|
1125
1332
|
"key": f"{item['id']}:review_landed:{pr_num(next(iter(done)))}",
|
|
1126
|
-
"msg":
|
|
1333
|
+
"msg": (
|
|
1334
|
+
f"{item['id']} to {item['owner']}: {note}.{gap}{_reply_owed(cfg, item, done)} NEXT: {next_step(cfg, first, item['owner'])}"
|
|
1335
|
+
),
|
|
1127
1336
|
}
|
|
1128
1337
|
|
|
1129
1338
|
|
|
@@ -1134,12 +1343,19 @@ def resolve_bare_refs(cfg: dict) -> None:
|
|
|
1134
1343
|
return
|
|
1135
1344
|
|
|
1136
1345
|
def fix(u: str) -> str:
|
|
1137
|
-
return
|
|
1346
|
+
return (
|
|
1347
|
+
u if u.startswith("http") else f"https://github.com/{repo}/pull/{pr_num(u)}"
|
|
1348
|
+
)
|
|
1138
1349
|
|
|
1139
1350
|
sd = store.state(cfg)
|
|
1140
1351
|
with store.locked(sd / "work.lock"):
|
|
1141
1352
|
all_ = work_load(sd)
|
|
1142
|
-
if not any(
|
|
1353
|
+
if not any(
|
|
1354
|
+
not u.startswith("http")
|
|
1355
|
+
for i in all_
|
|
1356
|
+
if i.get("kind") == "routed"
|
|
1357
|
+
for u in [*i["prs"], *i.get("queue", [])]
|
|
1358
|
+
):
|
|
1143
1359
|
return
|
|
1144
1360
|
for i in all_:
|
|
1145
1361
|
if i.get("kind") == "routed":
|
|
@@ -1175,15 +1391,23 @@ def refresh_prs(cfg: dict, now: float) -> list[dict]:
|
|
|
1175
1391
|
if not info:
|
|
1176
1392
|
continue
|
|
1177
1393
|
old = i["heads"].get(u)
|
|
1178
|
-
if not (
|
|
1394
|
+
if not (
|
|
1395
|
+
old and HEX_HEAD.fullmatch(old)
|
|
1396
|
+
): # unset, or mangled by an older redaction: rebaseline
|
|
1179
1397
|
i["heads"][u] = info["head"]
|
|
1180
1398
|
elif owner_is_author(cfg, i["owner"], info["author"]):
|
|
1181
|
-
i["review"] =
|
|
1399
|
+
i["review"] = (
|
|
1400
|
+
False # the person asked wrote the PR: their pushes are the work, not a stale review
|
|
1401
|
+
)
|
|
1182
1402
|
i["heads"][u] = info["head"]
|
|
1183
1403
|
elif i.get("pushes") and not i.get("review"):
|
|
1184
|
-
i["heads"][u] = info[
|
|
1404
|
+
i["heads"][u] = info[
|
|
1405
|
+
"head"
|
|
1406
|
+
] # the owner was asked to push to this PR: its pushes are the work
|
|
1185
1407
|
elif owner_is_author(cfg, i["owner"], info.get("head_author", "")):
|
|
1186
|
-
i["heads"][u] = info[
|
|
1408
|
+
i["heads"][u] = info[
|
|
1409
|
+
"head"
|
|
1410
|
+
] # the head moved by the owner's own commit: progress, not a stray push
|
|
1187
1411
|
i["last_heard"] = max(i.get("last_heard") or 0, now)
|
|
1188
1412
|
elif not same_head(old, info["head"]):
|
|
1189
1413
|
i["head_moved"] = {
|
|
@@ -1194,8 +1418,14 @@ def refresh_prs(cfg: dict, now: float) -> list[dict]:
|
|
|
1194
1418
|
}
|
|
1195
1419
|
_event(i, "head_moved", f"{old[:7]} -> {info['head'][:7]}", now)
|
|
1196
1420
|
i["heads"][u] = info["head"]
|
|
1197
|
-
if
|
|
1198
|
-
i
|
|
1421
|
+
if (
|
|
1422
|
+
i.get("waiting")
|
|
1423
|
+
and info["review_at"]
|
|
1424
|
+
and info["review_at"] > (i.get("routed_at") or 0)
|
|
1425
|
+
):
|
|
1426
|
+
i["waiting"] = (
|
|
1427
|
+
False # a review shows on the PR: the owner has started it
|
|
1428
|
+
)
|
|
1199
1429
|
if info["review_at"] and info["review_at"] > base(cfg, i):
|
|
1200
1430
|
i["last_heard"] = info["review_at"]
|
|
1201
1431
|
res = _landed(cfg, i, got) if i.get("review") else {}
|
|
@@ -1205,16 +1435,32 @@ def refresh_prs(cfg: dict, now: float) -> list[dict]:
|
|
|
1205
1435
|
old if old and acked != [old["commit"], old["head"]] else None
|
|
1206
1436
|
)
|
|
1207
1437
|
done = {u: d for u, (v, d) in res.items() if v == "closed" and d}
|
|
1208
|
-
if i.get("reported") and not i.get(
|
|
1438
|
+
if i.get("reported") and not i.get(
|
|
1439
|
+
"review"
|
|
1440
|
+
): # the owner said done: close only on its artifact
|
|
1209
1441
|
for u in i["prs"]:
|
|
1210
1442
|
info = got.get(u)
|
|
1211
1443
|
if info and artifact_exists(i, u, info):
|
|
1212
|
-
done[u] = {
|
|
1444
|
+
done[u] = {
|
|
1445
|
+
"state": "REPORTED",
|
|
1446
|
+
"login": i["owner"],
|
|
1447
|
+
"commit": info["head"],
|
|
1448
|
+
"ci": info.get("ci", "none"),
|
|
1449
|
+
}
|
|
1213
1450
|
if i.get("review"): # a merged or closed PR needs no review any more
|
|
1214
1451
|
for u in i["prs"]:
|
|
1215
1452
|
info = got.get(u)
|
|
1216
|
-
if
|
|
1217
|
-
|
|
1453
|
+
if (
|
|
1454
|
+
u not in done
|
|
1455
|
+
and info
|
|
1456
|
+
and info.get("state") in ("MERGED", "CLOSED")
|
|
1457
|
+
):
|
|
1458
|
+
done[u] = {
|
|
1459
|
+
"state": info["state"],
|
|
1460
|
+
"login": "GitHub",
|
|
1461
|
+
"commit": info["head"],
|
|
1462
|
+
"ci": info.get("ci", "none"),
|
|
1463
|
+
}
|
|
1218
1464
|
if done and i.get("queue"):
|
|
1219
1465
|
cur = i["prs"][0]
|
|
1220
1466
|
if cur in done:
|
|
@@ -350,6 +350,9 @@ REVERTS = [
|
|
|
350
350
|
('peer prompts redacted', 'hubcore/ledger.py', '"text": redact(" ".join(text.split()))[0][:300]', '"text": " ".join(text.split())[:300]', 'tests/test_ledger.py::test_peer_prompts_are_redacted_like_state'),
|
|
351
351
|
('eod lists PRs and peers', 'hubcore/status.py', 'glance(cfg, day) + [""] + ledger.day_lines(cfg, day)', 'glance(cfg, day)', 'tests/test_ledger.py::test_digest_and_eod_list_todays_prs_and_what_each_peer_was_asked'),
|
|
352
352
|
('digest lists PRs and peers', 'hubcore/status.py', 'return out + ledger.day_lines(cfg, store.day_of(cfg, since))', 'return out', 'tests/test_ledger.py::test_digest_and_eod_list_todays_prs_and_what_each_peer_was_asked'),
|
|
353
|
+
('fix job push is not a stall', 'hubcore/routed.py', ' bool(PR_REF.search(text + " " + summary))\n and bool(PUSH', ' False\n and bool(PUSH', 'tests/test_review_chain.py::test_an_owners_pushes_to_a_fix_job_are_not_a_stalled_head_but_a_reviews_moved_head_still_is'),
|
|
354
|
+
('fix-titled job is not a review', 'hubcore/routed.py', 'return not (LEADS_CHANGE.match(summary.strip().lower()) and not leads_review)', 'return True', 'tests/test_review_chain.py::test_a_fix_job_titled_with_review_findings_has_no_review_clock_but_a_real_review_does'),
|
|
355
|
+
('stated estimate sets the hard limit', 'hubcore/routed.py', ' hard = max(\n hard, float(item["estimate_min"])\n )', ' hard = hard', 'tests/test_review_chain.py::test_a_reviews_own_stated_estimate_sets_its_hard_limit'),
|
|
353
356
|
]
|
|
354
357
|
|
|
355
358
|
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"""Review tracking: merged PRs close, a re-brief moves the PRs, the next step after a review names an action, CI at the head."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
|
|
5
|
+
from test_hubkit import PR1, PR2, fake_gh, review, routed_items, send
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def gh_json(env, head, reviews=None, **extra):
|
|
9
|
+
(env.root / "gh.json").write_text(json.dumps({"headRefOid": head, "author": {"login": "pr-author"}, "reviews": reviews or [], **extra}))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_a_merged_pr_closes_its_review_item_instead_of_staying_overdue(env):
|
|
13
|
+
fake_gh(env, head="aaa1111")
|
|
14
|
+
env.bind()
|
|
15
|
+
send(env, "peer-a", f"Full gated review of {PR1}", "review 101")
|
|
16
|
+
gh_json(env, "aaa1111", state="MERGED")
|
|
17
|
+
out = env.run("tick", "--no-notify").stdout
|
|
18
|
+
assert routed_items(env) == [] and "MERGED" in out
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_a_rebrief_moves_the_prs_off_the_old_owner(env):
|
|
22
|
+
fake_gh(env, head="aaa1111")
|
|
23
|
+
env.bind()
|
|
24
|
+
send(env, "peer-a", f"Full gated review of {PR1}", "review 101")
|
|
25
|
+
send(env, "peer-b", f"Take over the review of {PR1}. Done-when: reviewed", "take over 101")
|
|
26
|
+
assert [i["owner"] for i in routed_items(env)] == ["peer-b"]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def test_an_approval_names_the_concrete_next_step_and_ci_at_the_head(env):
|
|
30
|
+
fake_gh(env, head="aaa1111")
|
|
31
|
+
env.bind()
|
|
32
|
+
send(env, "peer-a", f"Full gated review of {PR1}", "review 101")
|
|
33
|
+
gh_json(env, "aaa1111", [review("aaa1111")], statusCheckRollup=[{"conclusion": "SUCCESS"}])
|
|
34
|
+
out = env.run("tick", "--no-notify").stdout
|
|
35
|
+
assert "CI green" in out and "--match-head-commit aaa1111" in out
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def test_an_approval_on_red_ci_says_not_to_merge(env):
|
|
39
|
+
fake_gh(env, head="aaa1111")
|
|
40
|
+
env.bind()
|
|
41
|
+
send(env, "peer-a", f"Full gated review of {PR1}", "review 101")
|
|
42
|
+
gh_json(env, "aaa1111", [review("aaa1111")], statusCheckRollup=[{"conclusion": "FAILURE"}])
|
|
43
|
+
out = env.run("tick", "--no-notify").stdout
|
|
44
|
+
assert "CI is failing" in out and "do not merge on red" in out
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_an_owners_pushes_to_a_fix_job_are_not_a_stalled_head_but_a_reviews_moved_head_still_is(env):
|
|
48
|
+
fake_gh(env, head="aaa1111")
|
|
49
|
+
env.bind()
|
|
50
|
+
send(env, "peer-fix", f"Fix the gaps from the audit and update the tests. Done-when: tests pass. Output: the PR {PR1}. Estimate: 30m", "audit work")
|
|
51
|
+
send(env, "peer-rev", f"Full gated review of {PR2}", "review 102")
|
|
52
|
+
gh_json(env, "bbb2222")
|
|
53
|
+
out = env.run("tick", "--no-notify").stdout
|
|
54
|
+
items = {i["owner"]: i for i in routed_items(env)}
|
|
55
|
+
assert items["peer-fix"]["head_moved"] is None and items["peer-fix"]["heads"][PR1] == "bbb2222"
|
|
56
|
+
assert items["peer-rev"]["head_moved"] and "ALERT" in out
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def test_a_fix_job_titled_with_review_findings_has_no_review_clock_but_a_real_review_does(env):
|
|
60
|
+
from test_hubkit import age_routed
|
|
61
|
+
|
|
62
|
+
fake_gh(env, head="aaa1111")
|
|
63
|
+
env.bind()
|
|
64
|
+
fix = f"Fix the findings from the review of {PR1}. Done-when: tests pass. Output: the PR updated, ready for re-review of {PR1}.\nEstimate: 45m"
|
|
65
|
+
send(env, "peer-fix", fix, "Fix #101 review findings")
|
|
66
|
+
assert routed_items(env)[0]["review"] is False
|
|
67
|
+
age_routed(env, 29)
|
|
68
|
+
assert "past the hard limit" not in env.prompt("carry on").stdout
|
|
69
|
+
send(env, "peer-rev", f"Full gated review of {PR2}. Done-when: a verdict. Output: the verdict", "review 102")
|
|
70
|
+
age_routed(env, 29)
|
|
71
|
+
out = env.prompt("carry on").stdout
|
|
72
|
+
assert "peer-rev" in out and "past the hard limit" in out and out.count("past the hard limit") == 1
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_a_reviews_own_stated_estimate_sets_its_hard_limit(env):
|
|
76
|
+
from test_hubkit import age_routed
|
|
77
|
+
|
|
78
|
+
fake_gh(env, head="aaa1111")
|
|
79
|
+
env.bind()
|
|
80
|
+
send(env, "peer-rev", f"Full gated review of {PR1}. Done-when: a verdict. Output: the verdict.\nEstimate: 60m", "review 101")
|
|
81
|
+
age_routed(env, 29)
|
|
82
|
+
assert "past the hard limit" not in env.prompt("carry on").stdout
|
|
83
|
+
age_routed(env, 40)
|
|
84
|
+
assert "past the hard limit" in env.prompt("carry on").stdout
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"""Review tracking: merged PRs close, a re-brief moves the PRs, the next step after a review names an action, CI at the head."""
|
|
2
|
-
|
|
3
|
-
import json
|
|
4
|
-
|
|
5
|
-
from test_hubkit import PR1, fake_gh, review, routed_items, send
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def gh_json(env, head, reviews=None, **extra):
|
|
9
|
-
(env.root / "gh.json").write_text(json.dumps({"headRefOid": head, "author": {"login": "pr-author"}, "reviews": reviews or [], **extra}))
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def test_a_merged_pr_closes_its_review_item_instead_of_staying_overdue(env):
|
|
13
|
-
fake_gh(env, head="aaa1111")
|
|
14
|
-
env.bind()
|
|
15
|
-
send(env, "peer-a", f"Full gated review of {PR1}", "review 101")
|
|
16
|
-
gh_json(env, "aaa1111", state="MERGED")
|
|
17
|
-
out = env.run("tick", "--no-notify").stdout
|
|
18
|
-
assert routed_items(env) == [] and "MERGED" in out
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def test_a_rebrief_moves_the_prs_off_the_old_owner(env):
|
|
22
|
-
fake_gh(env, head="aaa1111")
|
|
23
|
-
env.bind()
|
|
24
|
-
send(env, "peer-a", f"Full gated review of {PR1}", "review 101")
|
|
25
|
-
send(env, "peer-b", f"Take over the review of {PR1}. Done-when: reviewed", "take over 101")
|
|
26
|
-
assert [i["owner"] for i in routed_items(env)] == ["peer-b"]
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
def test_an_approval_names_the_concrete_next_step_and_ci_at_the_head(env):
|
|
30
|
-
fake_gh(env, head="aaa1111")
|
|
31
|
-
env.bind()
|
|
32
|
-
send(env, "peer-a", f"Full gated review of {PR1}", "review 101")
|
|
33
|
-
gh_json(env, "aaa1111", [review("aaa1111")], statusCheckRollup=[{"conclusion": "SUCCESS"}])
|
|
34
|
-
out = env.run("tick", "--no-notify").stdout
|
|
35
|
-
assert "CI green" in out and "--match-head-commit aaa1111" in out
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
def test_an_approval_on_red_ci_says_not_to_merge(env):
|
|
39
|
-
fake_gh(env, head="aaa1111")
|
|
40
|
-
env.bind()
|
|
41
|
-
send(env, "peer-a", f"Full gated review of {PR1}", "review 101")
|
|
42
|
-
gh_json(env, "aaa1111", [review("aaa1111")], statusCheckRollup=[{"conclusion": "FAILURE"}])
|
|
43
|
-
out = env.run("tick", "--no-notify").stdout
|
|
44
|
-
assert "CI is failing" in out and "do not merge on red" in out
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|