feat(signed-commit): accept an optional cwd so the tool works on any clone#2393
Draft
joshsny wants to merge 2 commits into
Draft
feat(signed-commit): accept an optional cwd so the tool works on any clone#2393joshsny wants to merge 2 commits into
joshsny wants to merge 2 commits into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
git_signed_commitMCP tool'sctx.cwdis bound once at sessioncreation:
agent-server.tspassesthis.config.repositoryPath ?? "/tmp/workspace"into the new session and the local-tools MCP server captures that as
its
LocalToolCtx.cwd. Every git invocation increateSignedCommitruns 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 originruns from the wrong directoryand fails.
Changes
cwdfield tosignedCommitToolSchema.path.resolve(ctx.cwd, argCwd)(absolute paths pass through, relative paths join the session cwd),
override the ctx, and strip
cwdfrom the input forwarded tocreateSignedCommitso the lower-level API surface is unchanged.cwdand the tool still runsagainst 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-toolspasses. New
signed-commit.test.tscovers: default-to-session-cwd,absolute override, relative resolution, that
cwdisn't forwarded asa
SignedCommitInputfield, and the existing no-token error path.Publish to changelog?
no
Created with PostHog Code