Plan: Write AGENTS.md learnings via PR instead of direct commit#
Summary#
Replace CompoundService.writeLearnings() direct Contents API write with a branch + PR + auto-merge flow. The current createOrUpdateFile() call fails with 409 on branch-protected repos because GitHub App tokens respect protection rules (unlike the old PAT admin bypass). The compound-learnings skill (SKILL.md) already uses the PR path — this aligns the server-side hook to match.
Files#
| File | Action | Description |
|---|---|---|
src/hooks/compound.service.ts | modify | Replace createOrUpdateFile() with createBranch() + createOrUpdateFile(branch) + createPR() + enableAutoMerge() flow |
src/github/github.service.ts | modify | Add createBranch() and enableAutoMerge() methods (both missing from the service) |
src/github/github.service.spec.ts | modify | Add unit tests for new createBranch() and enableAutoMerge() methods |
src/hooks/compound.service.spec.ts | modify | Update tests to verify branch+PR flow instead of direct createOrUpdateFile on default branch |
.claude/skills/compound-learnings/SKILL.md | inspect | Already uses PR path — verify no conditional branching on repo type remains |
Steps#
- Add
createBranch(owner, repo, branchName, fromSha)toGitHubService— callsPOST /repos/{owner}/{repo}/git/refswithrefs/heads/{branchName}from the given SHA. Handle 422 (branch exists) by deleting and recreating. - Add
enableAutoMerge(owner, repo, prNumber)toGitHubService— uses GraphQLenablePullRequestAutoMergemutation withSQUASHmerge method. - Add
getDefaultBranchSha(owner, repo)toGitHubService— callsGET /repos/{owner}/{repo}and readsdefault_branch, then resolves its HEAD SHA viaGET /repos/{owner}/{repo}/git/ref/heads/{branch}. - Refactor
CompoundService.writeLearnings(): after building the AGENTS.md content, callgetDefaultBranchSha()→createBranch()(branch name:agents-md/issue-{issueNumber}) →createOrUpdateFile()targeting the new branch →createPR()→enableAutoMerge(). Remove the direct-to-default-branchcreateOrUpdateFile()call. - Update
compound.service.spec.ts: mockcreateBranch,getDefaultBranchSha,createPR,enableAutoMergeon GitHubService; verify the PR flow is called instead of direct commit; cover edge cases (branch already exists, no existing AGENTS.md). - Add unit tests for
createBranch,enableAutoMerge,getDefaultBranchShaingithub.service.spec.ts.
Verification#
npm run testpasses — all new and updated unit tests greennpm run lintpasses with zero warningsnpm run buildcompiles without errors
Risks#
- Auto-merge requires repo setting enabled:
enableAutoMergefails if the repo doesn't have "Allow auto-merge" enabled in settings. Mitigation: catch and log the error, fall back gracefully (PR stays open for manual merge). - Branch name collision: A stale branch from a prior failed run could block creation. Mitigation: delete existing branch before creating (same pattern as the compound-learnings skill).