Skip to content

[Bug] Batch prompts use the caller's branch and previous commit instead of each repository #315

Description

@404-Page-Found

Description

batch passes each repository's staged diff into generateSuggestions(), but generateSuggestions() reads branch and previous-commit context from process.cwd() via getBranchName() and getLastCommitMessage().

When commit-echo batch <directory> --recursive is run from a non-Git parent directory, custom prompt variables {{branch}} and {{message}} therefore resolve to unknown / empty values for every repository. When the caller directory is itself a different Git repository, all batch items can inherit that unrelated repository's context.

Location

  • src/commands/batch.ts:168-176 — per-repository call to generateSuggestions()
  • src/llm/client.ts:45-54 — branch/message context is read without a repository path
  • src/git/diff.ts:299-312getBranchName() and getLastCommitMessage() default to process.cwd()

Relevant code

// batch.ts
const result = await generateSuggestions(config, diff, profile, apiKey);

// llm/client.ts
const branch = getBranchName();
const message = getLastCommitMessage();

The per-repo diff is correct because the batch caller explicitly passes repoPath to getStagedDiff(repoPath), but the contextual prompt fields have no equivalent repository parameter.

Steps to Reproduce

  1. Create two Git repositories under a non-Git directory, each on a distinct branch and with a distinct last commit subject.
  2. Configure a custom prompt containing {{branch}} and/or {{message}}.
  3. Run commit-echo batch <parent> --recursive.
  4. Inspect the requests sent to the LLM.
  5. The branch/previous-message fields do not come from the repository whose diff is being summarized.

Expected Behavior

Every batch request should resolve {{branch}} and {{message}} from the repository currently being processed.

Actual Behavior

Those fields are evaluated from the process working directory rather than the repository being processed.

Suggested Fix

Add an explicit cwd (or repository context object) to generateSuggestions() / prompt-context collection, and pass repoPath from batchCommand(). Add an end-to-end regression test with multiple repositories and distinct branch/message values.

Impact

Custom batch prompt templates can receive unrelated repository context, leading to misleading commit suggestions and incorrect project-specific instructions exactly where the command is supposed to process many repositories independently.

Reviewed against current main at 6c01ad0a853501e9617a3af0a5db3b515dd8ed53.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingp2Medium priority; affects normal use

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions