Skip to content

feat(signed-commit): accept an optional cwd so the tool works on any clone#2393

Merged
joshsny merged 1 commit into
mainfrom
posthog-code/signed-commit-cwd-arg
Jun 2, 2026
Merged

feat(signed-commit): accept an optional cwd so the tool works on any clone#2393
joshsny merged 1 commit into
mainfrom
posthog-code/signed-commit-cwd-arg

Conversation

@joshsny
Copy link
Copy Markdown
Contributor

@joshsny joshsny commented May 27, 2026

Problem

The git_signed_commit MCP tool's ctx.cwd is bound once at session
creation: agent-server.ts passes this.config.repositoryPath ?? "/tmp/workspace"
into the new session and the local-tools MCP server captures that as
its LocalToolCtx.cwd. Every git invocation in createSignedCommit
runs against that bound cwd, so a task that clones a second repo (or
works in any checkout outside the original session cwd) can't commit
from it — git remote get-url origin runs from the wrong directory
and fails.

Changes

  • Add an optional cwd field to signedCommitToolSchema.
  • In the local-tool handler, resolve it via path.resolve(ctx.cwd, argCwd)
    (absolute paths pass through, relative paths join the session cwd),
    override the ctx, and strip cwd from the input forwarded to
    createSignedCommit so the lower-level API surface is unchanged.
  • Default behavior is preserved: omit cwd and the tool still runs
    against the session cwd.

How did you test this?

  • pnpm --filter @posthog/agent typecheck — clean.
  • pnpm exec vitest run src/adapters/local-tools src/adapters/claude/mcp/local-tools
    passes. New signed-commit.test.ts covers: default-to-session-cwd,
    absolute override, relative resolution, that cwd isn't forwarded as
    a SignedCommitInput field, and the existing no-token error path.

Publish to changelog?

no


Created with PostHog Code

@joshsny joshsny requested a review from a team June 2, 2026 10:52
@joshsny joshsny marked this pull request as ready for review June 2, 2026 10:52
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Jun 2, 2026

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
packages/agent/src/adapters/local-tools/tools/signed-commit.test.ts:41-76
**Prefer parameterised tests for cwd resolution cases**

The three cases testing how `args.cwd` resolves to the final `ctx.cwd` (absent, absolute, relative) share an identical shape — call handler, read `createSignedCommit.mock.calls[0][0].cwd`, assert equality. They could be collapsed into a single `it.each` table to avoid repeating the identical handler call and assertion three times while keeping each resolution case explicit and readable.

Reviews (1): Last reviewed commit: "style: apply biome formatter to signed-c..." | Re-trigger Greptile

Comment thread packages/agent/src/adapters/local-tools/tools/signed-commit.test.ts
@joshsny joshsny closed this Jun 2, 2026
@joshsny joshsny force-pushed the posthog-code/signed-commit-cwd-arg branch from 7922010 to 1160f17 Compare June 2, 2026 11:01
…clone

Adds an optional `cwd` arg to git_signed_commit, resolved against the session cwd, so the agent can commit from any clone reachable in the sandbox. Rebased onto latest main, resolving the resolveGithubToken import move into utils/github-token.

Generated-By: PostHog Code
Task-Id: b3c1f40a-6137-4266-a6e0-a47b734c20d8
@joshsny joshsny reopened this Jun 2, 2026
@joshsny joshsny requested review from a team and removed request for a team June 2, 2026 11:07
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Jun 2, 2026

Reviews (2): Last reviewed commit: "feat(signed-commit): accept an optional ..." | Re-trigger Greptile

@joshsny joshsny enabled auto-merge (squash) June 2, 2026 11:13
@joshsny joshsny merged commit 3a3d425 into main Jun 2, 2026
18 checks passed
@joshsny joshsny deleted the posthog-code/signed-commit-cwd-arg branch June 2, 2026 11:18
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.

2 participants