Skip to content

feat: implement worktree routes#120

Open
2witstudios wants to merge 3 commits intomainfrom
ppg/issue-71-worktree-routes
Open

feat: implement worktree routes#120
2witstudios wants to merge 3 commits intomainfrom
ppg/issue-71-worktree-routes

Conversation

@2witstudios
Copy link
Owner

Summary

  • Adds Fastify server scaffold (src/server/index.ts) with CORS, bearer auth, health endpoint, and route registration
  • Implements three worktree action endpoints as a Fastify plugin (src/server/routes/worktrees.ts):
    • POST /api/worktrees/:id/merge — merge with configurable strategy (squash default, no-ff), force flag, cleanup toggle
    • POST /api/worktrees/:id/kill — kill all running agents in a worktree
    • POST /api/worktrees/:id/pr — create GitHub PR via gh CLI, store URL in manifest
  • Adds fastify and @fastify/cors dependencies
  • Adds serveStatePath / servePidPath helpers to lib/paths.ts
  • 15 tests covering success paths, error responses (404/409/500/502), merge strategies, cleanup, draft PRs, and external command failures

Test plan

  • npm run typecheck passes (no new errors)
  • npm test — all 233 tests pass (22 files)
  • Manual: start server via ppg serve, call merge/kill/pr endpoints against a real ppg session

Closes #71

Add Fastify server infrastructure and three worktree action endpoints:
- POST /api/worktrees/:id/merge — squash or no-ff merge with force flag and cleanup
- POST /api/worktrees/:id/kill — kill all running agents in a worktree
- POST /api/worktrees/:id/pr — create GitHub PR via gh CLI and store URL in manifest

Includes 15 tests covering success paths, error handling (404, 409, 500, 502),
merge strategies, cleanup toggles, draft PR flag, and gh/push failures.

Closes #71
@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai
Copy link

coderabbitai bot commented Feb 27, 2026

Warning

Rate limit exceeded

@2witstudios has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 10 minutes and 47 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 34deb69 and 6600b84.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (13)
  • package.json
  • src/commands/merge.ts
  • src/commands/pr.ts
  • src/commands/spawn.test.ts
  • src/core/kill.test.ts
  • src/core/kill.ts
  • src/core/merge.test.ts
  • src/core/merge.ts
  • src/core/pr.ts
  • src/lib/paths.ts
  • src/server/index.ts
  • src/server/routes/worktrees.test.ts
  • src/server/routes/worktrees.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ppg/issue-71-worktree-routes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Security:
- Use crypto.timingSafeEqual for bearer token comparison (was string ===)
- Use request.routeOptions.url for auth bypass check (was request.url)

Architecture:
- Extract mergeWorktree() to core/merge.ts (was duplicated in commands + routes)
- Extract killWorktreeAgents() to core/kill.ts (was duplicated in commands + routes)
- Extract createWorktreePr(), buildBodyFromResults(), truncateBody() to core/pr.ts
- Routes now import from core/ only, not commands/ (fixes layer violation)
- Commands are thin wrappers: core logic + CLI output

Code quality:
- errorReply() now returns FastifyReply (prevents undefined return after reply.send)
- Remove unused imports (FastifyRequest, warn, KillBody)
- Remove redundant requireManifest() calls before updateManifest()
- Use Fastify declare module augmentation for projectRoot typing

Tests:
- Add core/merge.test.ts (7 tests): strategies, branch checkout, force, cleanup, failure
- Add core/kill.test.ts (2 tests): running agents set to gone, no-op for idle
- Route tests mock at core/ layer instead of duplicating low-level mock setup
- 242 total tests passing (was 233)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement worktree routes

1 participant