Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(skill): bootstrap github waiters from first page

cyh93f5104c292b
diff --git a/skills/background-watch-hook/scripts/_github_wait_common.py b/skills/background-watch-hook/scripts/_github_wait_common.py
index 3fd438762..10242e8c3 100644
--- a/skills/background-watch-hook/scripts/_github_wait_common.py
+++ b/skills/background-watch-hook/scripts/_github_wait_common.py
@@ -81,6 +81,7 @@ def list_paginated_with_count(
token: str | None,
*,
stop_after_id: int | None = None,
+ max_pages: int | None = None,
) -> tuple[list[dict[str, Any]], int]:
items: list[dict[str, Any]] = []
page = 1
@@ -99,6 +100,8 @@ def list_paginated_with_count(
if stop_after_id is not None and stop_after_id > 0:
if any(isinstance(item.get("id"), int) and int(item["id"]) <= stop_after_id for item in page_items):
break
+ if max_pages is not None and page >= max_pages:
+ break
if len(payload) < 100:
break
page += 1
diff --git a/skills/background-watch-hook/scripts/wait_issue.py b/skills/background-watch-hook/scripts/wait_issue.py
index 13d7f196c..c6e106e21 100644
--- a/skills/background-watch-hook/scripts/wait_issue.py
+++ b/skills/background-watch-hook/scripts/wait_issue.py
@@ -61,12 +61,14 @@ def _fetch_new_issue_state(
token: str | None,
*,
stop_after_id: int | None = None,
+ max_pages: int | None = None,
) -> tuple[dict[str, list[dict[str, Any]]], int]:
encoded_repo = urllib.parse.quote(repo, safe="/")
raw_issues, request_count = list_paginated_with_count(
f"https://api.github.com/repos/{encoded_repo}/issues?state=all&sort=created&direction=desc",
token,
stop_after_id=stop_after_id,
+ max_pages=max_pages,
)
issues = [item for item in raw_issues if not _is_pull_request_issue(item)]
return {"issues": issues, "raw_issue_cursor": max_id(raw_issues)}, request_count
@@ -230,12 +232,16 @@ def main() -> int:
)
else:
initial_raw_issue_stop_after_id = None
+ initial_raw_issue_max_pages = None
if args.since_raw_issue_id is not None and not args.catch_up:
initial_raw_issue_stop_after_id = args.since_raw_issue_id
+ elif not args.catch_up:
+ initial_raw_issue_max_pages = 1
state, requests_per_poll_count = _fetch_new_issue_state(
args.repo,
token,
stop_after_id=initial_raw_issue_stop_after_id,
+ max_pages=initial_raw_issue_max_pages,
)
except urllib.error.HTTPError as err:
print(f"GitHub API error: {err.code} {err.reason}", file=sys.stderr)
diff --git a/skills/background-watch-hook/scripts/wait_pr.py b/skills/background-watch-hook/scripts/wait_pr.py
index b37743340..597f8d137 100755
--- a/skills/background-watch-hook/scripts/wait_pr.py
+++ b/skills/background-watch-hook/scripts/wait_pr.py
@@ -125,12 +125,14 @@ def _fetch_new_pr_state(
token: str | None,
*,
stop_after_id: int | None = None,
+ max_pages: int | None = None,
) -> tuple[dict[str, list[dict[str, Any]]], int]:
encoded_repo = urllib.parse.quote(repo, safe="/")
pull_requests, request_count = list_paginated_with_count(
f"https://api.github.com/repos/{encoded_repo}/pulls?state=all&sort=created&direction=desc",
token,
stop_after_id=stop_after_id,
+ max_pages=max_pages,
)
return {"pull_requests": pull_requests}, request_count
@@ -324,12 +326,16 @@ def main() -> int:
state, requests_per_poll_count = _fetch_state(args.repo, args.pr, token)
else:
initial_pr_stop_after_id = None
+ initial_pr_max_pages = None
if args.since_pr_id is not None and not args.catch_up:
initial_pr_stop_after_id = args.since_pr_id
+ elif not args.catch_up:
+ initial_pr_max_pages = 1
state, requests_per_poll_count = _fetch_new_pr_state(
args.repo,
token,
stop_after_id=initial_pr_stop_after_id,
+ max_pages=initial_pr_max_pages,
)
except urllib.error.HTTPError as err:
print(f"GitHub API error: {err.code} {err.reason}", file=sys.stderr)
diff --git a/tests/test_wait_for_github_issue_activity.py b/tests/test_wait_for_github_issue_activity.py
index 74801d491..729ff8833 100644
--- a/tests/test_wait_for_github_issue_activity.py
+++ b/tests/test_wait_for_github_issue_activity.py
@@ -154,9 +154,10 @@ def test_fetch_new_issue_state_tracks_raw_cursor_and_request_count() -> None:
},
]
- def _fake_list_paginated_with_count(base_url, token, *, stop_after_id=None):
+ def _fake_list_paginated_with_count(base_url, token, *, stop_after_id=None, max_pages=None):
assert "issues?state=all" in base_url
assert stop_after_id == 401
+ assert max_pages is None
return raw_items, 3
with patch.object(module, "list_paginated_with_count", side_effect=_fake_list_paginated_with_count):
@@ -176,8 +177,8 @@ def test_main_uses_raw_issue_cursor_for_new_issue_paging() -> None:
module = _load_module()
calls: list[int | None] = []
- def _fake_fetch_new_issue_state(repo, token, *, stop_after_id=None):
- calls.append(stop_after_id)
+ def _fake_fetch_new_issue_state(repo, token, *, stop_after_id=None, max_pages=None):
+ calls.append((stop_after_id, max_pages))
if len(calls) == 1:
return (
{
@@ -225,7 +226,7 @@ def test_main_uses_raw_issue_cursor_for_new_issue_paging() -> None:
rc = module.main()
assert rc == 0
- assert calls == [None, 401]
+ assert calls == [(None, 1), (401, None)]
assert "issue #41" in stdout.getvalue()
@@ -233,8 +234,8 @@ def test_main_uses_since_raw_issue_cursor_for_initial_new_issue_fetch() -> None:
module = _load_module()
calls: list[int | None] = []
- def _fake_fetch_new_issue_state(repo, token, *, stop_after_id=None):
- calls.append(stop_after_id)
+ def _fake_fetch_new_issue_state(repo, token, *, stop_after_id=None, max_pages=None):
+ calls.append((stop_after_id, max_pages))
return (
{
"issues": [
@@ -275,7 +276,48 @@ def test_main_uses_since_raw_issue_cursor_for_initial_new_issue_fetch() -> None:
rc = module.main()
assert rc == 0
- assert calls == [401]
+ assert calls == [(401, None)]
+ assert "issue #41" in stdout.getvalue()
+
+
+def test_main_bootstraps_new_issue_watch_from_first_page_only() -> None:
+ module = _load_module()
+ calls: list[tuple[int | None, int | None]] = []
+
+ def _fake_fetch_new_issue_state(repo, token, *, stop_after_id=None, max_pages=None):
+ calls.append((stop_after_id, max_pages))
+ if len(calls) == 1:
+ return ({"issues": [], "raw_issue_cursor": 401}, 1)
+ return (
+ {
+ "issues": [
+ {
+ "id": 405,
+ "number": 41,
+ "title": "New issue",
+ "state": "open",
+ "html_url": "https://github.com/example/repo/issues/41",
+ "user": {"login": "someone"},
+ }
+ ],
+ "raw_issue_cursor": 406,
+ },
+ 1,
+ )
+
+ stdout = io.StringIO()
+ with (
+ patch.object(module, "_fetch_new_issue_state", side_effect=_fake_fetch_new_issue_state),
+ patch.object(module, "get_token", return_value="token"),
+ patch.object(module, "get_authenticated_login", return_value=None),
+ patch.object(module.time, "sleep", return_value=None),
+ patch("sys.argv", ["wait_issue.py", "--repo", "cyhhao/vibe-remote", "--new-issues", "--interval", "1"]),
+ redirect_stdout(stdout),
+ ):
+ rc = module.main()
+
+ assert rc == 0
+ assert calls == [(None, 1), (401, None)]
assert "issue #41" in stdout.getvalue()
@@ -330,8 +372,8 @@ def test_main_reduces_unauthenticated_new_issue_interval_after_bootstrap() -> No
fetch_calls: list[int | None] = []
sleep_calls: list[float] = []
- def _fake_fetch_new_issue_state(repo, token, *, stop_after_id=None):
- fetch_calls.append(stop_after_id)
+ def _fake_fetch_new_issue_state(repo, token, *, stop_after_id=None, max_pages=None):
+ fetch_calls.append((stop_after_id, max_pages))
if len(fetch_calls) == 1:
return ({"issues": [], "raw_issue_cursor": 0}, 50)
if len(fetch_calls) == 2:
@@ -383,5 +425,5 @@ def test_main_reduces_unauthenticated_new_issue_interval_after_bootstrap() -> No
assert rc == 0
assert sleep_calls == [3600.0, 60.0]
- assert fetch_calls == [None, None, None]
+ assert fetch_calls == [(None, 1), (None, None), (None, None)]
assert "issue #41" in stdout.getvalue()
diff --git a/tests/test_wait_for_github_pr_activity.py b/tests/test_wait_for_github_pr_activity.py
index 76fb16c7f..75433cc96 100644
--- a/tests/test_wait_for_github_pr_activity.py
+++ b/tests/test_wait_for_github_pr_activity.py
@@ -198,9 +198,10 @@ def test_fetch_new_pr_state_stops_after_cursor() -> None:
]
]
- def _fake_list_paginated_with_count(base_url, token, *, stop_after_id=None):
+ def _fake_list_paginated_with_count(base_url, token, *, stop_after_id=None, max_pages=None):
assert "pulls?state=all" in base_url
assert stop_after_id == 405
+ assert max_pages is None
return responses[0], 1
with patch.object(module, "list_paginated_with_count", side_effect=_fake_list_paginated_with_count):
@@ -218,8 +219,8 @@ def test_main_uses_since_pr_cursor_for_initial_new_pr_fetch() -> None:
module = _load_module()
calls: list[int | None] = []
- def _fake_fetch_new_pr_state(repo, token, *, stop_after_id=None):
- calls.append(stop_after_id)
+ def _fake_fetch_new_pr_state(repo, token, *, stop_after_id=None, max_pages=None):
+ calls.append((stop_after_id, max_pages))
return (
{
"pull_requests": [
@@ -257,7 +258,47 @@ def test_main_uses_since_pr_cursor_for_initial_new_pr_fetch() -> None:
rc = module.main()
assert rc == 0
- assert calls == [405]
+ assert calls == [(405, None)]
+ assert "pull_request #158" in stdout.getvalue()
+
+
+def test_main_bootstraps_new_pr_watch_from_first_page_only() -> None:
+ module = _load_module()
+ calls: list[tuple[int | None, int | None]] = []
+
+ def _fake_fetch_new_pr_state(repo, token, *, stop_after_id=None, max_pages=None):
+ calls.append((stop_after_id, max_pages))
+ if len(calls) == 1:
+ return ({"pull_requests": []}, 1)
+ return (
+ {
+ "pull_requests": [
+ {
+ "id": 410,
+ "number": 158,
+ "title": "New PR",
+ "state": "open",
+ "html_url": "https://github.com/example/repo/pull/158",
+ "user": {"login": "cyhhao"},
+ }
+ ]
+ },
+ 1,
+ )
+
+ stdout = io.StringIO()
+ with (
+ patch.object(module, "_fetch_new_pr_state", side_effect=_fake_fetch_new_pr_state),
+ patch.object(module, "get_token", return_value="token"),
+ patch.object(module, "get_authenticated_login", return_value=None),
+ patch.object(module.time, "sleep", return_value=None),
+ patch("sys.argv", ["wait_pr.py", "--repo", "cyhhao/vibe-remote", "--new-prs", "--interval", "1"]),
+ redirect_stdout(stdout),
+ ):
+ rc = module.main()
+
+ assert rc == 0
+ assert calls == [(None, 1), (None, None)]
assert "pull_request #158" in stdout.getvalue()
@@ -266,8 +307,8 @@ def test_main_reduces_unauthenticated_new_pr_interval_after_bootstrap() -> None:
fetch_calls: list[int | None] = []
sleep_calls: list[float] = []
- def _fake_fetch_new_pr_state(repo, token, *, stop_after_id=None):
- fetch_calls.append(stop_after_id)
+ def _fake_fetch_new_pr_state(repo, token, *, stop_after_id=None, max_pages=None):
+ fetch_calls.append((stop_after_id, max_pages))
if len(fetch_calls) == 1:
return ({"pull_requests": []}, 50)
if len(fetch_calls) == 2:
@@ -318,5 +359,5 @@ def test_main_reduces_unauthenticated_new_pr_interval_after_bootstrap() -> None:
assert rc == 0
assert sleep_calls == [3600.0, 60.0]
- assert fetch_calls == [None, None, None]
+ assert fetch_calls == [(None, 1), (None, None), (None, None)]
assert "pull_request #158" in stdout.getvalue()