Skip to content

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

Draft
joshsny wants to merge 2 commits into
mainfrom
posthog-code/signed-commit-cwd-arg
Draft

feat(signed-commit): accept an optional cwd so the tool works on any clone#2393
joshsny wants to merge 2 commits 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 added 2 commits May 27, 2026 14:16
The signed-commit 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`). All git invocations inside `createSignedCommit` run
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.

Add an optional `cwd` to the tool schema. The handler resolves it against
the session cwd via `path.resolve` (absolute paths pass through, relative
paths join the session cwd) and uses it as the ctx for `createSignedCommit`.
Default behavior is unchanged: omit `cwd` and the tool still runs against
the session cwd.

Test covers the four cases: default-to-session-cwd, absolute override,
relative resolution, and that `cwd` isn't forwarded as a `SignedCommitInput`
field; plus the existing no-token error path.

Generated-By: PostHog Code
Task-Id: d4c15be5-816f-4f11-9c71-3e354a272681
Generated-By: PostHog Code
Task-Id: d4c15be5-816f-4f11-9c71-3e354a272681
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.

1 participant