fix(git): follow repository instructions in generated source control text (#8804)

Co-authored-by: maria-rcks <[email protected]>
This commit is contained in:
mariaandmaria-rcks authored and GitHub committed 2026-08-30 18:02:10 -04:00
1 parent 8f525af5af
commit 60f2ce0279
4 files changed
+55 -18

No files matched your search

+11 -5
View File
@@ -1967,18 +1967,26 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
}),
);
it.effect("preserves repository conventions style when recent history is empty", () =>
it.effect("includes local agent instructions when recent history is empty", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
yield* runGit(repoDir, ["init", "--initial-branch=main"]);
yield* runGit(repoDir, ["config", "user.email", "[email protected]"]);
yield* runGit(repoDir, ["config", "user.name", "Test User"]);
const agentInstructions = "Use lowercase source control text.";
const claudeInstructions = "Keep pull request bodies brief.";
NodeFS.writeFileSync(NodePath.join(repoDir, "AGENTS.md"), agentInstructions);
NodeFS.writeFileSync(NodePath.join(repoDir, "CLAUDE.md"), claudeInstructions);
NodeFS.writeFileSync(NodePath.join(repoDir, "README.md"), "hello\n");
yield* runGit(repoDir, ["add", "README.md"]);
let generatedPolicy: TextGeneration.CommitMessageGenerationInput["policy"] = undefined;
const { manager } = yield* makeManager({
serverSettings: {
textGenerationModelSelection: {
instanceId: ProviderInstanceId.make("claudeAgent"),
model: "claude-sonnet-4-6",
},
sourceControlWritingStyle: {
mode: "repo_conventions" as const,
},
@@ -1997,10 +2005,8 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
expect(generatedPolicy).toEqual({
kind: "repo_conventions",
commitInstructions:
"Follow the repository's established commit message style when examples are available.",
changeRequestInstructions:
"Follow the repository's established change request title and body style when examples are available.",
commitInstructions: `Follow the repository's established commit message style when examples are available.\n\nLocal AGENTS.md:\n${agentInstructions}\n\nLocal CLAUDE.md:\n${claudeInstructions}`,
changeRequestInstructions: `Follow the repository's established change request title and body style when examples are available.\n\nLocal AGENTS.md:\n${agentInstructions}\n\nLocal CLAUDE.md:\n${claudeInstructions}`,
inferRepositoryConventions: true,
});
}),
+41 -12
View File
@@ -606,9 +606,24 @@ export const make = Effect.gen(function* () {
const providerRegistry = yield* ProviderRegistry.ProviderRegistry;
const projectSetupScriptRunner = yield* ProjectSetupScriptRunner.ProjectSetupScriptRunner;
const crypto = yield* Crypto.Crypto;
const fileSystem = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const sourceControlProvider = (cwd: string) => sourceControlProviders.resolve({ cwd });
const serverSettingsService = yield* ServerSettings.ServerSettingsService;
const readRepositoryInstructions = (cwd: string, fileName: string) =>
Effect.gen(function* () {
const root = yield* fileSystem.realPath(cwd);
const instructionPath = yield* fileSystem.realPath(path.join(root, fileName));
if (!instructionPath.startsWith(`${root}${path.sep}`)) {
return "";
}
const info = yield* fileSystem.stat(instructionPath);
if (info.type !== "File" || info.size > FileSystem.Size(20_000)) {
return "";
}
return (yield* fileSystem.readFileString(instructionPath)).trim();
}).pipe(Effect.orElseSucceed(() => ""));
const readRecentCommitSubjects = (cwd: string) =>
gitCore
@@ -627,26 +642,43 @@ export const make = Effect.gen(function* () {
Effect.orElseSucceed(() => []),
);
const resolveStylePolicy = (cwd: string, style: SourceControlWritingStyleSettings) =>
const resolveStylePolicy = (cwd: string, settings: SourceControlTextGenerationSettings) =>
Effect.gen(function* () {
switch (style.mode) {
switch (settings.style.mode) {
case "conventional_commits":
return conventionalCommitsTextGenerationPolicy;
case "custom":
return customTextGenerationPolicy(
style.customInstructions
settings.style.customInstructions
? {
commitInstructions: style.customInstructions,
changeRequestInstructions: style.customInstructions,
commitInstructions: settings.style.customInstructions,
changeRequestInstructions: settings.style.customInstructions,
}
: {},
);
case "repo_conventions": {
const subjects = yield* readRecentCommitSubjects(cwd);
if (subjects.length === 0) {
const agentInstructions = yield* readRepositoryInstructions(cwd, "AGENTS.md");
const isClaudeWriter =
settings.modelSelection.instanceId === "claudeAgent" ||
(yield* providerRegistry.getProviders).some(
(provider) =>
provider.instanceId === settings.modelSelection.instanceId &&
provider.driver === "claudeAgent",
);
const claudeInstructions = isClaudeWriter
? yield* readRepositoryInstructions(cwd, "CLAUDE.md")
: "";
const examples = [
...(subjects.length > 0
? [["Recent commit subjects from this repository:", ...subjects].join("\n")]
: []),
...(agentInstructions ? [`Local AGENTS.md:\n${agentInstructions}`] : []),
...(claudeInstructions ? [`Local CLAUDE.md:\n${claudeInstructions}`] : []),
].join("\n\n");
if (!examples) {
return repositoryConventionsTextGenerationPolicy;
}
const examples = ["Recent commit subjects from this repository:", ...subjects].join("\n");
return {
...repositoryConventionsTextGenerationPolicy,
commitInstructions: `${repositoryConventionsTextGenerationPolicy.commitInstructions}\n\n${examples}`,
@@ -848,9 +880,6 @@ export const make = Effect.gen(function* () {
),
),
);
const fileSystem = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const tempDir = process.env.TMPDIR ?? process.env.TEMP ?? process.env.TMP ?? "/tmp";
const canonicalizeExistingPath = (value: string) =>
fileSystem.realPath(value).pipe(Effect.orElseSucceed(() => value));
@@ -1565,7 +1594,7 @@ export const make = Effect.gen(function* () {
};
}
const policy = yield* resolveStylePolicy(input.cwd, input.settings.style);
const policy = yield* resolveStylePolicy(input.cwd, input.settings);
const generated = yield* textGeneration
.generateCommitMessage({
@@ -1751,7 +1780,7 @@ export const make = Effect.gen(function* () {
});
const baseRangeRef = yield* resolveBaseRangeRef(cwd, baseBranch);
const rangeContext = yield* gitCore.readRangeContext(cwd, baseRangeRef);
const policy = yield* resolveStylePolicy(cwd, settings.style);
const policy = yield* resolveStylePolicy(cwd, settings);
const changeRequestTemplate =
settings.style.followChangeRequestTemplates && provider.kind === "github"
? Option.getOrUndefined(yield* detectPrTemplate(cwd, baseRangeRef, gitCore.execute))
@@ -16,7 +16,7 @@ const EARLIER_CONTENT_TRUNCATION_MARKER = "[Earlier content truncated]\n\n";
function policyInstruction(instruction: string | undefined): ReadonlyArray<string> {
const trimmed = instruction?.trim();
return trimmed ? ["", "Additional instructions:", limitSection(trimmed, 4_000)] : [];
return trimmed ? ["", "Additional instructions:", limitSection(trimmed, 20_000)] : [];
}
// ---------------------------------------------------------------------------
+2
View File
@@ -33,6 +33,8 @@ T3 Code works with the platforms your team already uses:
- Push a branch and create a pull request from the Git actions controls in the toolbar
- T3 Code can suggest titles and descriptions based on your commits
- With **Repository conventions** selected, generated source control text follows the project's
`AGENTS.md` along with recent commit subjects. Claude writers also follow `CLAUDE.md`
- Supports GitHub Pull Requests, GitLab Merge Requests, Bitbucket Pull Requests, and Azure DevOps Pull Requests
**Stay on top of open reviews**