AI Agents SDE Task Viewer
      • Context
      • Plan
      • Prd
  1. Home
  2. AgentSDE
  3. agent-core
  4. gh-533
  5. plan
  6. plan.md
plan.md(3.1 KB)· Apr 16, 2026· 2 min read
  • Summary
  • Files
  • Steps
  • Verification
  • Risks

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#

FileActionDescription
src/hooks/compound.service.tsmodifyReplace createOrUpdateFile() with createBranch() + createOrUpdateFile(branch) + createPR() + enableAutoMerge() flow
src/github/github.service.tsmodifyAdd createBranch() and enableAutoMerge() methods (both missing from the service)
src/github/github.service.spec.tsmodifyAdd unit tests for new createBranch() and enableAutoMerge() methods
src/hooks/compound.service.spec.tsmodifyUpdate tests to verify branch+PR flow instead of direct createOrUpdateFile on default branch
.claude/skills/compound-learnings/SKILL.mdinspectAlready uses PR path — verify no conditional branching on repo type remains

Steps#

  1. Add createBranch(owner, repo, branchName, fromSha) to GitHubService — calls POST /repos/{owner}/{repo}/git/refs with refs/heads/{branchName} from the given SHA. Handle 422 (branch exists) by deleting and recreating.
  2. Add enableAutoMerge(owner, repo, prNumber) to GitHubService — uses GraphQL enablePullRequestAutoMerge mutation with SQUASH merge method.
  3. Add getDefaultBranchSha(owner, repo) to GitHubService — calls GET /repos/{owner}/{repo} and reads default_branch, then resolves its HEAD SHA via GET /repos/{owner}/{repo}/git/ref/heads/{branch}.
  4. Refactor CompoundService.writeLearnings(): after building the AGENTS.md content, call getDefaultBranchSha() → createBranch() (branch name: agents-md/issue-{issueNumber}) → createOrUpdateFile() targeting the new branch → createPR() → enableAutoMerge(). Remove the direct-to-default-branch createOrUpdateFile() call.
  5. Update compound.service.spec.ts: mock createBranch, getDefaultBranchSha, createPR, enableAutoMerge on GitHubService; verify the PR flow is called instead of direct commit; cover edge cases (branch already exists, no existing AGENTS.md).
  6. Add unit tests for createBranch, enableAutoMerge, getDefaultBranchSha in github.service.spec.ts.

Verification#

  • npm run test passes — all new and updated unit tests green
  • npm run lint passes with zero warnings
  • npm run build compiles without errors

Risks#

  • Auto-merge requires repo setting enabled: enableAutoMerge fails 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).
ContextPrd