Skip to content

feat(cpp): GitHub tools and coding skills for gaiacode - #8795

Open
kovtcharov wants to merge 2 commits into
amd:mainfrom
kovtcharov:kalin/gaiacode-github
Open

kovtcharov wants to merge 2 commits into
amd:mainfrom
kovtcharov:kalin/gaiacode-github

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

gaiacode can now read a repository's issues, pull requests and CI from GitHub itself, and comment or open a draft pull request when the run allows it, with no `gh` install needed. That is what turns "fix issue 412" or "why is CI red on my PR" into work it can do. It ships three skills built on those tools: fix a failing check, turn an issue into a pull request, and review a pull request. Builds on amd/gaia#8788 (this branch carries its commit; merge that first).

Test plan

  • Linux build and the full C++ suite (`tests_mock`, 1,763 passed), plus 36 gaiacode tests: 13 GitHub tests against a fake GitHub API on 127.0.0.1 (remote parsing, host-bound tokens, the loopback-only override, reads, refused and allowed writes, credential scanning, a token-free log download, nulls, a moved repository, 401 and rate-limit errors) and an end-to-end run showing the skills and tools reach the model
  • `build_cpp.yml` Windows and macOS legs pass
  • On a real repository with `GH_TOKEN` set: `gaiacode -p "why is CI red on PR ?" --model --dangerously-skip-permissions` reads the failing check's log
🔍 Technical details
  • `cpp/agents/gaiacode/github.{h,cpp}` talk to the REST API through `HttpClient` with `returnRedirects`; only `gh_run_log` follows a redirect, re-requesting the signed blob URL with a header-less client.
  • Token sources by host: `GH_TOKEN`/`GITHUB_TOKEN` → github.com only; `GH_ENTERPRISE_TOKEN` → only the host `GH_HOST` names; then `gh auth token --hostname `, cached per host. `GITHUB_API_URL` is accepted on loopback or when it equals the host's own API base.
  • Writes are `ToolPolicy::CONFIRM` and also gated by `--allow-github-writes comment,pr`; outgoing text is refused when `holdsCredentials` matches or it contains the active token. Results pass through `redactToolOutput`.
  • Skills live in `cpp/agents/gaiacode/skills/` and are copied beside the binary at build time; `CodeAgent` loads a `SkillLibrary` like gaiacpp. They stay out of `hub/skills` because the Python flagship has no `gh_*` tools.

Refs #8682

@github-actions github-actions Bot added documentation Documentation changes cpp labels Nov 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Request changes

This PR lets gaiacode read issues, pull requests and CI from GitHub directly, and post a comment or a draft PR when the run allows it. It also ships three skills built on those tools. Token handling is careful: each token goes only to its own host, writes are opt-in twice, and text read from GitHub is marked as untrusted. One bug breaks the headline "why is CI red" flow on real repositories, though.

  • CI logs can't be fetched for real jobs. GitHub job IDs are now 11 digits, larger than a 32-bit number holds. The checks tool hands the model a garbled job ID, and the log tool caps any ID it is given at about 2.1 billion. Asking for a real job's log therefore requests a job that doesn't exist and fails. The tests use job ID 9, so they pass. Carry the ID as a 64-bit number from start to finish, and add a test with an ID like 45123456789.
  • A long list of checks can report "0 failing" when checks did fail. Only the first 100 check runs are read, and nothing says when there were more. On a busy repository the fix-CI skill can decide nothing failed. Either page through the rest or flag the result as cut off, the way the PR view already does for files.

Real-world evidence

N/A: no evidence bundle was produced for this run. The verdict rests on static review alone. The PR's own unchecked test-plan item (reading a real failing check's log with GH_TOKEN set) would have caught the job-ID bug, so please run it before merging.

🔍 Technical details

🟡 Important

1. Job IDs truncated to int (cpp/agents/gaiacode/github.cpp:454, :298, :464)
c.value("id", 0) deduces ValueType = int, so a real check-run ID such as 45123456789 is static_cast to a wrong value. positive() then clamps any input to 2147483647, so even a correct ID from the model becomes /actions/jobs/2147483647/logs and returns 404 ("not found on GitHub"). The skills' fix-ci step 2 fails on every current github.com repository. The fake server in test_gaiacode_github.cpp uses IDs 5 and 9.

long long positive(const json& args, const char* name) {
    if (!args.contains(name) || !args[name].is_number_integer() || args[name].get<long long>() < 1) {
        throw std::invalid_argument(std::string(name) + " must be a positive whole number");
    }
    return args[name].get<long long>();
}

Use c.value("id", 0LL) at :454, const long long job = positive(a, "job_id"); at :464, and change the other const int n = positive(...) calls to long long. Add a test that round-trips an ID above 2³¹ through gh_pr_checks → gh_run_log.

2. gh_pr_checks hides cut-off results (github.cpp:449-456)
check-runs?per_page=100 reads one page. The response carries total_count, but it is ignored, so failing can be 0 while failures sit on page 2. This is the dishonest-status class. The commit body says "cut-off lists say so", and gh_pr_view / gh_issue_view already do that.

            const json page = api.get("/repos/" + r.slug() + "/commits/" + sha + "/check-runs?per_page=100");
            for (const auto& c : page.value("check_runs", json::array())) {

Then add {"checks_total", page.value("total_count", 0)} and {"checks_truncated", page.value("total_count", 0) > static_cast<int>(checks.size())} to the result. Paging until total_count is reached would be better. Also consider counting startup_failure and action_required as failing (:452).

🟢 Minor

  • gh_issue_view reads the oldest 30 comments (:372). On a long issue, the latest comments are usually the most relevant. Consider fetching the last page, or sort=created&direction=desc.
  • gh_issue_list sets per_page=limit and then drops pull requests (:396-403), so it returns fewer issues than asked for without saying so.
  • parseRemote accepts any host, so a GitLab upstream is treated as GitHub Enterprise and wins over a GitHub origin (:143-147). Every tool then reports "not found on GitHub". Consider falling through to the next remote when the host isn't github.com or GH_HOST.
  • The gh auth token cache also stores an empty result (:326), so signing in with gh mid-session has no effect until restart. Cache only non-empty tokens.
  • The system prompt says the repository comes from "the git remotes … (upstream first)" even when --repo overrides them (code_agent.cpp:146).

Strengths

  • Tokens are bound to their host (GH_TOKEN only to github.com, GH_ENTERPRISE_TOKEN only to GH_HOST). The signed log redirect is fetched with a header-less client, so remote-embedded tokens and the token itself never reach a third-party host.
  • Writes need both CONFIRM and an explicit --allow-github-writes <kind>, and outgoing text is scanned for credentials and the live token. The layering is sound for a model that reads attacker-written issues.
  • GitHub's error cases (null fields, a moved repo, 401, rate limits) become actionable messages, and the fake-server tests cover them.

@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Request changes

🟡 CI logs still can't be fetched for real jobs. The checks list now pages through every check, which fixes the second finding from the last review. The job-ID bug is still there, though. Real GitHub job IDs are 11 digits, and both tools still squeeze them into a 32-bit number. The checks tool hands the model a garbled ID, and the log tool caps whatever ID it gets at about 2.1 billion, so "why is CI red" fails with "not found" on every current github.com repository. Carry the ID as a 64-bit number from start to finish, and add a test with an ID like 45123456789.

🔍 Technical details
  • cpp/agents/gaiacode/github.cpp:512: c.value("id", 0) deduces int. Use 0LL.
  • github.cpp:329-333: positive() returns int and clamps to 2147483647. Return long long with no clamp, and make job at :538 a long long.
  • cpp/tests/test_gaiacode_github.cpp: no test uses an ID above 2³¹. Round-trip one through gh_pr_checks → gh_run_log.

@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Request changes

🟡 CI logs still can't be fetched for real jobs. This push doesn't touch the job-ID bug from the last review. Real GitHub job IDs are 11 digits, but the checks tool still hands the model a 32-bit ID and the log tool still caps any ID at about 2.1 billion. So "why is CI red" fails with "not found" on every current github.com repository. Carry the job ID as a 64-bit number from the checks list through to the log request, and add a test that uses an ID like 45123456789.

🔍 Technical details
  • cpp/agents/gaiacode/github.cpp:521: c.value("id", 0) deduces int, so the ID is truncated. Use 0LL.
  • github.cpp:338-342: positive() returns int and clamps to 2147483647. Add a long long variant with no clamp for job_id, and make job at :564 a long long.
  • cpp/tests/test_gaiacode_github.cpp: still no test with an ID above 2³¹. Round-trip one through gh_pr_checks → gh_run_log.

@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Request changes

🟡 CI logs still can't be fetched for real jobs. This push adds rate-limit handling but leaves the job-ID bug from the last two reviews in place. Real GitHub job IDs are 11 digits. The checks tool still gives the model a 32-bit ID, and the log tool still caps any ID at about 2.1 billion. So "why is CI red" fails with "not found" on every current github.com repository. Carry the job ID as a 64-bit number from the checks list through to the log request, and add a test that uses an ID like 45123456789.

🔍 Technical details
  • cpp/agents/gaiacode/github.cpp:539: c.value("id", 0) deduces int, which truncates the ID. Use 0LL.
  • github.cpp:356-360: positive() returns int and clamps to 2147483647. Add a long long variant with no clamp for job_id, and make job at :582 a long long.
  • cpp/tests/test_gaiacode_github.cpp:243-250: the test still uses job ID 9. Round-trip an ID above 2³¹ through gh_pr_checks → gh_run_log.

…n it didn't make

gaiacode is GAIA's coding agent as one native binary: it reads, edits and searches a repository, runs its tests and reads the results, and holds its answer to what the turn actually ran. An answer that says the tests pass needs a real passing run after the last edit, measured from the working tree, or it is sent back and then flagged.

- Headless (-p) mode with the workspace pre-check before any approval.
- Test runners: pytest, go, cargo, npm, ctest, mocha, rspec, phpunit, JUnit, dotnet, swift.
- The shell checks gaiacpp makes (planted file names, guarded files, a script's own dollars) move to gaia_core so both agents share one copy.
- File edits are recorded in the store the Agent UI reads, so Changes and Undo work.
- git never stops for a password or passphrase.

Rebased onto main as one commit; the earlier history is in the pull request.
gaiacode works with GitHub itself, over its REST API with no gh CLI needed: it reads issues and pull requests, reads CI checks and job logs, and, once the user approves, comments, opens pull requests and issues, submits reviews with comments on lines of the change, and re-runs a CI job. It ships three skills (fix-ci, issue-to-pr, pr-review) and offers only the skills whose tools it has.

- Tokens go only to the host they belong to; text to be posted is checked for credentials.
- A review is pinned to the commit it read and refused when the pull request has moved on.
- Headless runs make a write only when --allow-github-writes names its kind.

Rebased onto main as one commit; the earlier history is in the pull request.
@kovtcharov
kovtcharov force-pushed the kalin/gaiacode-github branch from ffae71f to b42b61a Compare November 29, 2026 20:30
@kovtcharov
kovtcharov marked this pull request as draft November 29, 2026 20:30
@kovtcharov
kovtcharov marked this pull request as ready for review November 29, 2026 20:56
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

This lets gaiacode read issues, pull requests and CI logs from GitHub, and post to it when the user approves, with no gh install needed. It also adds three skills built on those tools: fix CI, issue to PR, and PR review. Tokens go only to the host they belong to, and every write needs both approval and --allow-github-writes. I found no security problem. One thing is worth fixing before merge:

  • The CI check can report "nothing failing" when something is. Older-style commit statuses are read from one page of 30. On a commit with more than 30 of them, a failure past the first page goes uncounted, and nothing in the result says the list was cut. Ask for 100 and flag it when GitHub reports more.

Also, this branch carries #8788's commit, and #8788 is still open. I reviewed this PR's own commit, and #8788 should merge first, as the description says.

Real-world evidence

N/A: no evidence bundle was produced for this run. The verdict rests on reading the code alone. The PR's own test plan still has the real-repository run unchecked (gaiacode -p "why is CI red on PR <n>?" with GH_TOKEN set). That run is the only proof the tools work against the real GitHub API rather than the fake one in the tests, so please tick it, with its output, before merge.

🔍 Technical details

🟡 Important

🟡 Commit statuses are capped at 30 and the cut isn't reported (cpp/agents/gaiacode/github.cpp:575). GET /commits/{sha}/status defaults to per_page=30. Check runs are paged and flagged with checks_truncated, but statuses aren't, so failing can be 0 while a status past the 30th is failure. This is the "dishonest status" class.

            if (const auto combined = api.getIfAllowed("/repos/" + r.slug() + "/commits/" + sha + "/status?per_page=100", why)) {
                statuses = combined->value("statuses", json::array());
                if (combined->value("total_count", 0) > static_cast<int>(statuses.size())) complete = false;

🟢 Minor

🟢 gh_issue_list refuses labels that contain / (github.cpp:485). Labels like area/cpp and type/bug are common, and they error out here. gh_search already percent-encodes its query, so the same encoding could replace the allowlist.

🟢 The pr-review skill's fetch fails on a second review after a force-push (skills/pr-review/SKILL.md). git fetch origin pull/<n>/head:pr-<n> rejects a non-fast-forward update to an existing pr-<n> branch. A leading + fixes it:

   `git fetch origin +pull/<number>/head:pr-<number>` then

🟢 Stale comment (cpp/agents/gaiacode/code_agent.h:39). It says the writes are "comment", "pr", but the CLI accepts five kinds: comment, pr, review, issue and rerun.

        /// GitHub writes this run may make: "comment", "pr", "review", "issue", "rerun".

🟢 parseRepoSlug doc says owner/name only (cpp/agents/gaiacode/github.h:36). The function also accepts host/owner/name for GitHub Enterprise, as --repo and the docs say.

Checked and fine

  • Token scoping. GH_TOKEN and GITHUB_TOKEN go to github.com only, and GH_ENTERPRISE_TOKEN only to the host GH_HOST names. gh auth token --hostname runs on a validated host. GITHUB_API_URL is accepted only on loopback or when it is the host's own API base, which covers Actions.
  • Log redirects. They are followed with a separate client that sends no Authorization header, and only to https or loopback targets.
  • Writes. Each needs both CONFIRM approval and --allow-github-writes, outgoing text is scanned for credentials and for the active token, and reviews are pinned to the commit they read.
  • Deadlines. Every HTTP call has a 30 s timeout, and the git/gh subprocesses have 10 s.
  • Sibling paths. requireTools is unset for gaiacpp, so its skill catalog doesn't change. The new skills sit outside hub/skills, so the Python flagship never offers tools it lacks.
  • Doc drift. The new flags, tools and token table in docs/cpp/gaiacode.mdx match main.cpp and github.cpp, and the page is in docs/docs.json.

Strengths

  • The token rules and the loopback-only override are tested against a fake GitHub server, including a moved repository, 401, rate limits, nulls and a log download that never sees the token.
  • Skills are filtered by the tools the agent actually has, so ~/.gaia/skills entries meant for the Python agent don't send gaiacode after tools it doesn't have.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cpp documentation Documentation changes enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants