Skip to content
TypeScript

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

maria60f2ce0279d5
diff --git a/apps/server/src/git/GitManager.test.ts b/apps/server/src/git/GitManager.test.ts
index 9e2cf15ecb7..64b5d428ab1 100644
--- a/apps/server/src/git/GitManager.test.ts
+++ b/apps/server/src/git/GitManager.test.ts
@@ -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,
});
}),
diff --git a/apps/server/src/git/GitManager.ts b/apps/server/src/git/GitManager.ts
index 5ea4a0072d6..4fb9f321206 100644
--- a/apps/server/src/git/GitManager.ts
+++ b/apps/server/src/git/GitManager.ts
@@ -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))
diff --git a/apps/server/src/textGeneration/TextGenerationPrompts.ts b/apps/server/src/textGeneration/TextGenerationPrompts.ts
index 5eaef8c36ce..c676a1760d0 100644
--- a/apps/server/src/textGeneration/TextGenerationPrompts.ts
+++ b/apps/server/src/textGeneration/TextGenerationPrompts.ts
@@ -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)] : [];
}
// ---------------------------------------------------------------------------
diff --git a/docs/user/source-control.md b/docs/user/source-control.md
index 3aa856cf992..d848226c1ba 100644
--- a/docs/user/source-control.md
+++ b/docs/user/source-control.md
@@ -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**