Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

feat(ultrawiki): GitHub discussions and repository profiles — still no clone

Ruben Lütke82b7b2663d50
diff --git a/jarvis/ultrawiki/adapters/github.py b/jarvis/ultrawiki/adapters/github.py
index 2e6ca41c3a..593f377fb9 100644
--- a/jarvis/ultrawiki/adapters/github.py
+++ b/jarvis/ultrawiki/adapters/github.py
@@ -1,10 +1,21 @@
"""GitHub pull adapter — the issues and pull requests you were part of.
The first real reader behind the plugin bridge. Of everything GitHub holds,
-this pulls the part that belongs in a *memory*: the issues and pull requests
-the account is **involved in** — authored, assigned, mentioned, or commented
-on. Those carry the decisions and the reasoning. A list of repository names
-does not, and the file tree is a code search's job, not a memory's.
+this pulls the part that belongs in a *memory*:
+
+1. the issues and pull requests the account is **involved in** — authored,
+ assigned, mentioned, or commented on — **with their comment threads**,
+ because the decision usually lives in the discussion rather than in the
+ opening post;
+2. one **profile per repository** — description, topics, primary language and
+ README — which is what makes "which project was that again?" answerable.
+
+**Nothing is cloned.** No repository is downloaded, no file tree walked, no
+commit history read. That is a decision, not a gap: the repositories reachable
+from one personal account here total roughly 900 MB of git data, and a
+lockfile, a minified bundle or a vendored dependency answers no question a
+person asks their own memory. Source code is a code search's job — Jarvis has
+CLI tools for that. A memory needs what was decided and why.
One search query does all of it (``involves:<login>``), which matters: the
Search API allows 30 requests a minute, an order of magnitude tighter than the
@@ -45,6 +56,7 @@ __all__ = [
"GitHubAdapterError",
"github_pull_adapter",
"item_from_issue",
+ "item_from_repo",
]
#: The plugin-bridge candidate id this adapter serves.
@@ -65,6 +77,21 @@ _TIMEOUT = httpx.Timeout(connect=5.0, read=25.0, write=10.0, pool=5.0)
#: cursor, rather than spending the user's last requests and failing mid-page.
_RATELIMIT_FLOOR = 3
+#: Comment threads cost one request per item that HAS comments. The core
+#: bucket allows 5 000 an hour, so this bound keeps ONE sync predictable
+#: rather than protecting the quota: past it the remaining threads stay as the
+#: "open the link" note they were before.
+_MAX_COMMENT_FETCHES = 300
+
+#: Per item — a 400-comment thread is a mailing list, not a decision record.
+_MAX_COMMENTS_PER_ITEM = 30
+
+#: A README is orientation, not documentation to be reproduced in full.
+_README_MAX_CHARS = 8000
+
+#: Repository pages of 100; four pages covers 400 repositories.
+_MAX_REPO_PAGES = 4
+
class GitHubAdapterError(RuntimeError):
"""A pull step failed. The message is safe to show and never holds the token."""
@@ -182,7 +209,9 @@ def _repo_of(issue: dict[str, Any]) -> str:
return "/".join(parts[-2:]) if len(parts) >= 3 else ""
-def item_from_issue(issue: dict[str, Any]) -> RawItem | None:
+def item_from_issue(
+ issue: dict[str, Any], comment_text: str = ""
+) -> RawItem | None:
"""One search hit as a ``RawItem``; ``None`` when it is unusable.
The body is composed rather than copied raw: a bare issue body loses which
@@ -221,10 +250,13 @@ def item_from_issue(issue: dict[str, Any]) -> RawItem | None:
header += f" · opened by {author}"
body_text = str(issue.get("body") or "").strip()
comments = int(issue.get("comments") or 0)
- if comments:
- # The comment threads are NOT fetched (one request per issue would
- # blow the 30/min search budget on the first sync). Saying how many
- # exist keeps the record honest about what it does not contain.
+ if comment_text:
+ # The discussion IS the record: the opening post says what was
+ # proposed, the thread says what was decided and why it changed.
+ body_text += f"\n\n--- discussion ---\n{comment_text}"
+ elif comments:
+ # Not fetched this run (the per-sync bound). Say so, rather than
+ # let the body imply the opening post was the whole conversation.
body_text += f"\n\n[{comments} comment(s) on GitHub — open the link to read them]"
return RawItem(
@@ -244,11 +276,155 @@ def item_from_issue(issue: dict[str, Any]) -> RawItem | None:
"state": state,
"labels": labels,
"comments": comments,
+ "comments_fetched": bool(comment_text),
"updated_at": updated,
},
)
+async def _comment_text(
+ client: httpx.AsyncClient, token: str, issue: dict[str, Any]
+) -> str:
+ """The discussion under one issue or pull request, as plain text.
+
+ Returns an empty string on ANY failure: a thread that cannot be read must
+ not lose the item it belongs to. The caller then falls back to the "open
+ the link" note, which is what the record said before comments existed.
+ """
+ url = str(issue.get("comments_url") or "").strip()
+ if not url:
+ return ""
+ try:
+ response = await _get(
+ client, url, token, params={"per_page": _MAX_COMMENTS_PER_ITEM}
+ )
+ rows = response.json()
+ except (GitHubAdapterError, ValueError):
+ log.debug("comment thread unavailable for %s", url, exc_info=True)
+ return ""
+ if not isinstance(rows, list):
+ return ""
+ lines: list[str] = []
+ for row in rows[:_MAX_COMMENTS_PER_ITEM]:
+ if not isinstance(row, dict):
+ continue
+ author = str((row.get("user") or {}).get("login") or "someone")
+ when = str(row.get("created_at") or "")[:10]
+ text = str(row.get("body") or "").strip()
+ if not text:
+ continue
+ lines.append(f"{author} ({when}): {text}")
+ total = int(issue.get("comments") or 0)
+ if total > len(lines) and total > _MAX_COMMENTS_PER_ITEM:
+ lines.append(f"[... {total - len(lines)} further comment(s) on GitHub]")
+ return "\n\n".join(lines)
+
+
+def item_from_repo(repo: dict[str, Any], readme: str = "") -> RawItem | None:
+ """One repository as a PROFILE item — what the project is, not what it contains.
+
+ This is the answer to "which project was that again?", and it is the only
+ repository-level thing worth storing: a name, what it is for, what it is
+ written in, and the README's own explanation. Deliberately NOT the code —
+ see the module docstring.
+ """
+ full_name = str(repo.get("full_name") or "").strip()
+ permalink = str(repo.get("html_url") or "").strip()
+ if not full_name or not permalink:
+ return None
+
+ description = str(repo.get("description") or "").strip()
+ language = str(repo.get("language") or "").strip()
+ topics = [str(topic) for topic in (repo.get("topics") or []) if topic]
+ visibility = "private" if repo.get("private") else "public"
+ pushed = str(repo.get("pushed_at") or "")
+ created = str(repo.get("created_at") or "")
+
+ header = f"{full_name} · repository · {visibility}"
+ if language:
+ header += f" · {language}"
+ if topics:
+ header += f" · {', '.join(topics)}"
+ parts = [header]
+ if description:
+ parts.append(description)
+ if readme:
+ parts.append(readme[:_README_MAX_CHARS])
+ if len(readme) > _README_MAX_CHARS:
+ parts.append("[README truncated — open the link for the rest]")
+
+ return RawItem(
+ external_id=f"repo:{repo.get('id')}",
+ title=full_name,
+ body="\n\n".join(parts).strip(),
+ permalink=permalink,
+ # A repository's "event time" is when it was created; the last push
+ # drives the cursor instead, via metadata.
+ timestamp_utc=created or pushed,
+ thread_key=full_name,
+ author_raw=str((repo.get("owner") or {}).get("login") or ""),
+ metadata={
+ "mtime_ns": _to_ns(pushed or created),
+ "repo": full_name,
+ "kind": "repository",
+ "state": visibility,
+ "language": language,
+ "topics": topics,
+ "pushed_at": pushed,
+ },
+ )
+
+
+async def _readme_text(client: httpx.AsyncClient, token: str, full_name: str) -> str:
+ """A repository's README as plain text, or empty when it has none.
+
+ Asked for as raw text rather than the base64 JSON blob: the raw media type
+ is one request either way and needs no decoding step to get wrong.
+ """
+ try:
+ response = await client.get(
+ f"{_API}/repos/{full_name}/readme",
+ headers={**_headers(token), "Accept": "application/vnd.github.raw"},
+ )
+ except httpx.HTTPError:
+ return ""
+ if response.status_code != 200:
+ # 404 simply means the repository has no README — a normal state.
+ return ""
+ return response.text.strip()
+
+
+async def _repository_items(
+ client: httpx.AsyncClient, token: str
+) -> AsyncIterator[RawItem]:
+ """A profile item for every repository the account can reach."""
+ for page in range(1, _MAX_REPO_PAGES + 1):
+ response = await _get(
+ client,
+ f"{_API}/user/repos",
+ token,
+ params={
+ "per_page": _PER_PAGE,
+ "page": page,
+ "affiliation": "owner,collaborator,organization_member",
+ "sort": "pushed",
+ },
+ )
+ rows = response.json()
+ if not isinstance(rows, list) or not rows:
+ break
+ for row in rows:
+ if not isinstance(row, dict):
+ continue
+ full_name = str(row.get("full_name") or "")
+ readme = await _readme_text(client, token, full_name) if full_name else ""
+ item = item_from_repo(row, readme)
+ if item is not None:
+ yield item
+ if len(rows) < _PER_PAGE:
+ break
+
+
async def github_pull_adapter(
ctx: ConnectorContext,
checkpoint: str | None = None,
@@ -264,6 +440,7 @@ async def github_pull_adapter(
token = _token()
since = _cursor_to_date(checkpoint)
yielded = 0
+ comment_fetches = 0
async with httpx.AsyncClient(timeout=_TIMEOUT, transport=transport) as client:
login = await _login(client, token)
@@ -292,7 +469,14 @@ async def github_pull_adapter(
for row in rows:
if not isinstance(row, dict):
continue
- item = item_from_issue(row)
+ # The thread is fetched only when there IS one, and only while
+ # the per-sync budget lasts — past it the item still lands,
+ # carrying its honest "open the link" note.
+ thread = ""
+ if int(row.get("comments") or 0) and comment_fetches < _MAX_COMMENT_FETCHES:
+ thread = await _comment_text(client, token, row)
+ comment_fetches += 1
+ item = item_from_issue(row, thread)
if item is not None:
yielded += 1
yield item
@@ -311,9 +495,22 @@ async def github_pull_adapter(
)
break
+ # Repository profiles last: they are the smallest and least urgent
+ # part of the read, so a rate-limit stop above costs the cheap thing
+ # rather than the discussions.
+ try:
+ async for repo_item in _repository_items(client, token):
+ yielded += 1
+ yield repo_item
+ except GitHubAdapterError as exc:
+ # A failed repository walk must not discard the issues already
+ # yielded — they are the valuable half.
+ log.info("GitHub adapter: repository profiles skipped (%s)", exc)
+
log.info(
- "GitHub adapter: yielded %d item(s) for %s (%s)",
+ "GitHub adapter: yielded %d item(s) for %s (%s), %d thread(s) fetched",
yielded,
ctx.source_id,
"incremental" if since else "backfill",
+ comment_fetches,
)
diff --git a/tests/unit/ultrawiki/test_github_adapter.py b/tests/unit/ultrawiki/test_github_adapter.py
index 40b11023bc..8844a235bc 100644
--- a/tests/unit/ultrawiki/test_github_adapter.py
+++ b/tests/unit/ultrawiki/test_github_adapter.py
@@ -51,6 +51,8 @@ def _issue(**overrides: Any) -> dict[str, Any]:
"title": "Ship the wake-word fix",
"html_url": "https://github.com/acme/widgets/issues/7",
"repository_url": "https://api.github.com/repos/acme/widgets",
+ # Search results carry this; the adapter reads the thread from it.
+ "comments_url": "https://api.github.com/repos/acme/widgets/issues/7/comments",
"state": "open",
"body": "The wake word misses every third call.",
"user": {"login": "rubenluetke10-beep"},
@@ -69,12 +71,26 @@ def _transport(
login: str = "rubenluetke10-beep",
headers: dict[str, str] | None = None,
seen: list[httpx.Request] | None = None,
+ comments: list[dict[str, Any]] | None = None,
+ repos: list[dict[str, Any]] | None = None,
+ readme: str = "",
) -> httpx.MockTransport:
def handler(request: httpx.Request) -> httpx.Response:
if seen is not None:
seen.append(request)
- if request.url.path == "/user":
+ path = request.url.path
+ if path == "/user":
return httpx.Response(200, content=json.dumps({"login": login}).encode())
+ if path == "/user/repos":
+ page = int(request.url.params.get("page", "1"))
+ rows = (repos or []) if page == 1 else []
+ return httpx.Response(200, content=json.dumps(rows).encode())
+ if path.endswith("/readme"):
+ if not readme:
+ return httpx.Response(404, content=b"{}")
+ return httpx.Response(200, content=readme.encode())
+ if path.endswith("/comments"):
+ return httpx.Response(200, content=json.dumps(comments or []).encode())
page = int(request.url.params.get("page", "1"))
rows = pages[page - 1] if page <= len(pages) else []
return httpx.Response(
@@ -251,3 +267,160 @@ def test_the_adapter_registers_under_the_bridge_candidate_id():
# The id must match what list_candidates reports, or the reader is
# registered under a name nothing looks up.
assert plugin_bridge.has_pull_adapter("plugin:github") is True
+
+# ---------------------------------------------------------------------------
+# Comment threads — where the decision usually lives
+# ---------------------------------------------------------------------------
+
+
+async def test_the_discussion_is_stored_not_just_the_opening_post():
+ """An opening post says what was PROPOSED; the thread says what was decided.
+
+ Storing only the first message is how a memory ends up confidently
+ reporting a plan that was argued out of existence three comments later.
+ """
+ thread = [
+ {
+ "user": {"login": "reviewer"},
+ "created_at": "2026-03-02T09:00:00Z",
+ "body": "This breaks the wake word on Linux.",
+ },
+ {
+ "user": {"login": "rubenluetke10-beep"},
+ "created_at": "2026-03-02T10:00:00Z",
+ "body": "Good catch — switching to the energy gate instead.",
+ },
+ ]
+ items = await _collect(
+ transport=_transport([[_issue(comments=2)]], comments=thread)
+ )
+ body = items[0].body
+ assert "--- discussion ---" in body
+ assert "reviewer (2026-03-02): This breaks the wake word on Linux." in body
+ assert "switching to the energy gate instead" in body
+ assert items[0].metadata["comments_fetched"] is True
+
+
+async def test_an_item_without_comments_costs_no_extra_request():
+ seen: list[httpx.Request] = []
+ await _collect(transport=_transport([[_issue(comments=0)]], seen=seen))
+ assert not [r for r in seen if r.url.path.endswith("/comments")]
+
+
+async def test_an_unreadable_thread_keeps_the_item_and_says_so():
+ """A failed thread must never take its item down with it."""
+
+ def handler(request: httpx.Request) -> httpx.Response:
+ if request.url.path == "/user":
+ return httpx.Response(200, content=json.dumps({"login": "x"}).encode())
+ if request.url.path.endswith("/comments"):
+ return httpx.Response(500, content=b"{}")
+ if request.url.path == "/user/repos":
+ return httpx.Response(200, content=b"[]")
+ return httpx.Response(
+ 200, content=json.dumps({"items": [_issue(comments=3)]}).encode()
+ )
+
+ items = await _collect(transport=httpx.MockTransport(handler))
+ assert len(items) == 1
+ # Falls back to the honest note rather than implying the post was all of it.
+ assert "3 comment(s) on GitHub" in items[0].body
+ assert items[0].metadata["comments_fetched"] is False
+
+
+async def test_a_huge_thread_is_capped_and_declares_the_remainder():
+ thread = [
+ {"user": {"login": "u"}, "created_at": "2026-03-02T09:00:00Z", "body": f"c{i}"}
+ for i in range(60)
+ ]
+ items = await _collect(
+ transport=_transport([[_issue(comments=200)]], comments=thread)
+ )
+ body = items[0].body
+ assert body.count("u (2026-03-02):") == 30
+ assert "further comment(s) on GitHub" in body
+
+
+# ---------------------------------------------------------------------------
+# Repository profiles — "which project was that again?"
+# ---------------------------------------------------------------------------
+
+
+def _repo(**overrides: Any) -> dict[str, Any]:
+ base: dict[str, Any] = {
+ "id": 555,
+ "full_name": "acme/widgets",
+ "html_url": "https://github.com/acme/widgets",
+ "description": "The widget pipeline.",
+ "language": "Python",
+ "topics": ["widgets", "pipeline"],
+ "private": True,
+ "owner": {"login": "acme"},
+ "created_at": "2025-01-05T08:00:00Z",
+ "pushed_at": "2026-03-09T12:00:00Z",
+ }
+ base.update(overrides)
+ return base
+
+
+async def test_a_repository_becomes_a_profile_not_a_code_dump():
+ items = await _collect(
+ transport=_transport(
+ [[]], repos=[_repo()], readme="# Widgets\n\nRuns the widget pipeline."
+ )
+ )
+ profile = next(i for i in items if i.metadata["kind"] == "repository")
+ assert profile.external_id == "repo:555"
+ assert profile.title == "acme/widgets"
+ assert profile.permalink == "https://github.com/acme/widgets"
+ # What it IS: visibility, language, topics, purpose, README.
+ assert "acme/widgets · repository · private · Python" in profile.body
+ assert "widgets, pipeline" in profile.body
+ assert "The widget pipeline." in profile.body
+ assert "Runs the widget pipeline." in profile.body
+ # And explicitly NOT a file tree: the timestamp is the repo's creation,
+ # the cursor rides on the last push.
+ assert profile.timestamp_utc == "2025-01-05T08:00:00Z"
+ assert profile.metadata["mtime_ns"] == gh._to_ns("2026-03-09T12:00:00Z")
+
+
+async def test_a_repository_without_a_readme_is_still_a_profile():
+ """404 on the README is a normal state, not a failure."""
+ items = await _collect(transport=_transport([[]], repos=[_repo()], readme=""))
+ profile = next(i for i in items if i.metadata["kind"] == "repository")
+ assert "The widget pipeline." in profile.body
+
+
+async def test_an_overlong_readme_is_truncated_with_a_pointer():
+ items = await _collect(
+ transport=_transport([[]], repos=[_repo()], readme="x" * 20000)
+ )
+ profile = next(i for i in items if i.metadata["kind"] == "repository")
+ assert "README truncated" in profile.body
+ assert len(profile.body) < 12000
+
+
+async def test_a_failed_repository_walk_keeps_the_issues_already_read():
+ """The issues are the valuable half; a repo-list failure must not void them."""
+
+ def handler(request: httpx.Request) -> httpx.Response:
+ if request.url.path == "/user":
+ return httpx.Response(200, content=json.dumps({"login": "x"}).encode())
+ if request.url.path == "/user/repos":
+ return httpx.Response(500, content=b"{}")
+ return httpx.Response(
+ 200, content=json.dumps({"items": [_issue()]}).encode()
+ )
+
+ items = await _collect(transport=httpx.MockTransport(handler))
+ assert [i.metadata["kind"] for i in items] == ["issue"]
+
+
+async def test_repositories_are_read_after_the_issues():
+ """A rate-limit stop should cost the cheap half, not the discussions."""
+ seen: list[httpx.Request] = []
+ await _collect(
+ transport=_transport([[_issue()]], repos=[_repo()], seen=seen, readme="hi")
+ )
+ paths = [r.url.path for r in seen]
+ assert paths.index("/search/issues") < paths.index("/user/repos")