The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 25, 11:00 UTC
optional
Julius Marminge committed
Mar 2, 2026 at 09:34 UTC
13094952186d16aaffea7609e78629bc5f9a57f2
5 files changed
+91
-27
apps/server/src/git/Layers/CodexTextGeneration.test.ts
+29
-2
@@ -189,15 +189,15 @@ function withFakeCodexEnv<A, E, R>(
189
const CodexTextGenerationTestLayer = makeCodexTextGenerationTestLayer(process.cwd());
190
191
it.layer(CodexTextGenerationTestLayer)("CodexTextGenerationLive", (it) => {
192
- it.effect("generates and sanitizes commit messages", () =>
192
+ it.effect("generates and sanitizes commit messages without branch by default", () =>
193
withFakeCodexEnv(
194
{
195
output: JSON.stringify({
196
subject:
197
" Add important change to the system with too much detail and a trailing period.\nsecondary line",
198
body: "\n- added migration\n- updated tests\n",
199
- branch: "fix/important-system-change",
199
}),
200
+ stdinMustNotContain: "branch must be a short semantic git branch fragment",
201
},
202
Effect.gen(function* () {
203
const textGeneration = yield* TextGeneration;
@@ -212,6 +212,33 @@ it.layer(CodexTextGenerationTestLayer)("CodexTextGenerationLive", (it) => {
212
expect(generated.subject.length).toBeLessThanOrEqual(72);
213
expect(generated.subject.endsWith(".")).toBe(false);
214
expect(generated.body).toBe("- added migration\n- updated tests");
215
+ expect(generated.branch).toBeUndefined();
216
+ }),
217
+ ),
218
+ );
219
+
220
+ it.effect("generates commit message with branch when includeBranch is true", () =>
221
+ withFakeCodexEnv(
222
+ {
223
+ output: JSON.stringify({
224
+ subject: "Add important change",
225
+ body: "",
226
+ branch: "fix/important-system-change",
227
+ }),
228
+ stdinMustContain: "branch must be a short semantic git branch fragment",
229
+ },
230
+ Effect.gen(function* () {
231
+ const textGeneration = yield* TextGeneration;
232
+
233
+ const generated = yield* textGeneration.generateCommitMessage({
234
+ cwd: process.cwd(),
235
+ branch: "feature/codex-effect",
236
+ stagedSummary: "M README.md",
237
+ stagedPatch: "diff --git a/README.md b/README.md",
238
+ includeBranch: true,
239
+ });
240
+
241
+ expect(generated.subject).toBe("Add important change");
242
expect(generated.branch).toBe("feature/fix/important-system-change");
243
}),
244
),
apps/server/src/git/Layers/CodexTextGeneration.ts
+27
-9
@@ -336,13 +336,19 @@ const makeCodexTextGeneration = Effect.gen(function* () {
336
});
337
338
const generateCommitMessage: TextGenerationShape["generateCommitMessage"] = (input) => {
339
+ const wantsBranch = input.includeBranch === true;
340
+
341
const prompt = [
342
"You write concise git commit messages.",
341
- "Return a JSON object with keys: subject, body, branch.",
343
+ wantsBranch
344
+ ? "Return a JSON object with keys: subject, body, branch."
345
+ : "Return a JSON object with keys: subject, body.",
346
"Rules:",
347
"- subject must be imperative, <= 72 chars, and no trailing period",
348
"- body can be empty string or short bullet points",
345
- "- branch must be a short semantic git branch fragment for this change",
349
+ ...(wantsBranch
350
+ ? ["- branch must be a short semantic git branch fragment for this change"]
351
+ : []),
352
"- capture the primary user-visible or developer-visible change",
353
"",
354
`Branch: ${input.branch ?? "(detached)"}`,
@@ -354,22 +360,31 @@ const makeCodexTextGeneration = Effect.gen(function* () {
360
limitSection(input.stagedPatch, 40_000),
361
].join("\n");
362
363
+ const outputSchemaJson = wantsBranch
364
+ ? Schema.Struct({
365
+ subject: Schema.String,
366
+ body: Schema.String,
367
+ branch: Schema.String,
368
+ })
369
+ : Schema.Struct({
370
+ subject: Schema.String,
371
+ body: Schema.String,
372
+ });
373
+
374
return runCodexJson({
375
operation: "generateCommitMessage",
376
cwd: input.cwd,
377
prompt,
361
- outputSchemaJson: Schema.Struct({
362
- subject: Schema.String,
363
- body: Schema.String,
364
- branch: Schema.String,
365
- }),
378
+ outputSchemaJson,
379
}).pipe(
380
Effect.map(
381
(generated) =>
382
({
383
subject: sanitizeCommitSubject(generated.subject),
384
body: generated.body.trim(),
372
- branch: sanitizeFeatureBranchName(generated.branch),
385
+ ...("branch" in generated && typeof generated.branch === "string"
386
+ ? { branch: sanitizeFeatureBranchName(generated.branch) }
387
+ : {}),
388
}) satisfies CommitMessageGenerationResult,
389
),
390
);
@@ -419,7 +434,10 @@ const makeCodexTextGeneration = Effect.gen(function* () {
434
435
const generateBranchName: TextGenerationShape["generateBranchName"] = (input) => {
436
return Effect.gen(function* () {
422
- const { imagePaths } = yield* materializeImageAttachments("generateBranchName", input.attachments);
437
+ const { imagePaths } = yield* materializeImageAttachments(
438
+ "generateBranchName",
439
+ input.attachments,
440
+ );
441
const attachmentLines = (input.attachments ?? []).map(
442
(attachment) =>
443
`- ${attachment.name} (${attachment.mimeType}, ${attachment.sizeBytes} bytes)`,
apps/server/src/git/Layers/GitManager.test.ts
+13
-7
@@ -32,7 +32,11 @@ interface FakeGitTextGeneration {
32
branch: string | null;
33
stagedSummary: string;
34
stagedPatch: string;
35
- }) => Effect.Effect<{ subject: string; body: string; branch: string }, TextGenerationError>;
35
+ includeBranch?: boolean;
36
+ }) => Effect.Effect<
37
+ { subject: string; body: string; branch?: string | undefined },
38
+ TextGenerationError
39
+ >;
40
generatePrContent: (input: {
41
cwd: string;
42
baseBranch: string;
@@ -104,11 +108,13 @@ function createBareRemote(): Effect.Effect<
108
109
function createTextGeneration(overrides: Partial<FakeGitTextGeneration> = {}): TextGenerationShape {
110
const implementation: FakeGitTextGeneration = {
107
- generateCommitMessage: () =>
111
+ generateCommitMessage: (input) =>
112
Effect.succeed({
113
subject: "Implement stacked git actions",
114
body: "",
111
- branch: "feature/implement-stacked-git-actions",
115
+ ...(input.includeBranch
116
+ ? { branch: "feature/implement-stacked-git-actions" }
117
+ : {}),
118
}),
119
generatePrContent: () =>
120
Effect.succeed({
@@ -506,13 +512,13 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
512
513
const { manager } = yield* makeManager({
514
textGeneration: {
509
- generateCommitMessage: () =>
515
+ generateCommitMessage: (input) =>
516
Effect.sync(() => {
517
generatedCount += 1;
518
return {
519
subject: "this should not be used",
520
body: "",
515
- branch: "feature/unused",
521
+ ...(input.includeBranch ? { branch: "feature/unused" } : {}),
522
};
523
}),
524
},
@@ -566,13 +572,13 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
572
573
const { manager } = yield* makeManager({
574
textGeneration: {
569
- generateCommitMessage: () =>
575
+ generateCommitMessage: (input) =>
576
Effect.sync(() => {
577
generatedCount += 1;
578
return {
579
subject: "unused",
580
body: "",
575
- branch: "feature/unused",
581
+ ...(input.includeBranch ? { branch: "feature/unused" } : {}),
582
};
583
}),
584
},
apps/server/src/git/Layers/GitManager.ts
+18
-8
@@ -85,10 +85,14 @@ function limitContext(value: string, maxChars: number): string {
85
return `${value.slice(0, maxChars)}\n\n[truncated]`;
86
}
87
88
-function sanitizeCommitMessage(generated: { subject: string; body: string; branch: string }): {
88
+function sanitizeCommitMessage(generated: {
89
subject: string;
90
body: string;
91
- branch: string;
91
+ branch?: string | undefined;
92
+}): {
93
+ subject: string;
94
+ body: string;
95
+ branch?: string | undefined;
96
} {
97
const rawSubject = generated.subject.trim().split(/\r?\n/g)[0]?.trim() ?? "";
98
const subject = rawSubject.replace(/[.]+$/g, "").trim();
@@ -96,7 +100,7 @@ function sanitizeCommitMessage(generated: { subject: string; body: string; branc
100
return {
101
subject: safeSubject,
102
body: generated.body.trim(),
99
- branch: generated.branch,
103
+ ...(generated.branch !== undefined ? { branch: generated.branch } : {}),
104
};
105
}
106
@@ -293,6 +297,8 @@ export const makeGitManager = Effect.gen(function* () {
297
cwd: string;
298
branch: string | null;
299
commitMessage?: string;
300
+ /** When true, also produce a semantic feature branch name. */
301
+ includeBranch?: boolean;
302
}) =>
303
Effect.gen(function* () {
304
const context = yield* gitCore.prepareCommitContext(input.cwd);
@@ -302,11 +308,12 @@ export const makeGitManager = Effect.gen(function* () {
308
309
const customCommit = parseCustomCommitMessage(input.commitMessage ?? "");
310
if (customCommit) {
305
- const branch = sanitizeFeatureBranchName(customCommit.subject);
311
return {
312
subject: customCommit.subject,
313
body: customCommit.body,
309
- branch,
314
+ ...(input.includeBranch
315
+ ? { branch: sanitizeFeatureBranchName(customCommit.subject) }
316
+ : {}),
317
commitMessage: formatCommitMessage(customCommit.subject, customCommit.body),
318
};
319
}
@@ -317,14 +324,16 @@ export const makeGitManager = Effect.gen(function* () {
324
branch: input.branch,
325
stagedSummary: limitContext(context.stagedSummary, 8_000),
326
stagedPatch: limitContext(context.stagedPatch, 50_000),
327
+ ...(input.includeBranch !== undefined ? { includeBranch: input.includeBranch } : {}),
328
})
329
.pipe(Effect.map((result) => sanitizeCommitMessage(result)));
330
323
- const branch = sanitizeFeatureBranchName(generated.branch);
331
return {
332
subject: generated.subject,
333
body: generated.body,
327
- branch,
334
+ ...(generated.branch !== undefined
335
+ ? { branch: sanitizeFeatureBranchName(generated.branch) }
336
+ : {}),
337
commitMessage: formatCommitMessage(generated.subject, generated.body),
338
};
339
});
@@ -456,6 +465,7 @@ export const makeGitManager = Effect.gen(function* () {
465
cwd: input.cwd,
466
branch: details.branch,
467
...(input.commitMessage ? { commitMessage: input.commitMessage } : {}),
468
+ includeBranch: true,
469
});
470
if (!suggestion) {
471
return yield* gitManagerError(
@@ -466,7 +476,7 @@ export const makeGitManager = Effect.gen(function* () {
476
477
return {
478
commitMessage: suggestion.commitMessage,
469
- branch: suggestion.branch,
479
+ branch: suggestion.branch ?? sanitizeFeatureBranchName(suggestion.subject),
480
};
481
},
482
);
apps/server/src/git/Services/TextGeneration.ts
+4
-1
@@ -17,12 +17,15 @@ export interface CommitMessageGenerationInput {
17
branch: string | null;
18
stagedSummary: string;
19
stagedPatch: string;
20
+ /** When true, the model also returns a semantic branch name for the change. */
21
+ includeBranch?: boolean;
22
}
23
24
export interface CommitMessageGenerationResult {
25
subject: string;
26
body: string;
25
- branch: string;
27
+ /** Only present when `includeBranch` was set on the input. */
28
+ branch?: string | undefined;
29
}
30
31
export interface PrContentGenerationInput {