Open History to see the last commit
1/**
2 * TextGeneration - Effect service contract for AI-generated Git content.
3 *
4 * Generates commit messages and pull request titles/bodies from repository
5 * context prepared by Git services.
6 *
7 * @module TextGeneration
8 */
9import { ServiceMap } from "effect";
10import type { Effect } from "effect";
11import type { ChatAttachment } from "@t3tools/contracts";
12
13import type { TextGenerationError } from "../Errors.ts";
14
15export interface CommitMessageGenerationInput {
16 cwd: string;
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 /** Model to use for generation. Defaults to gpt-5.4-mini if not specified. */
23 model?: string;
24}
25
26export interface CommitMessageGenerationResult {
27 subject: string;
28 body: string;
29 /** Only present when `includeBranch` was set on the input. */
30 branch?: string | undefined;
31}
32
33export interface PrContentGenerationInput {
34 cwd: string;
35 baseBranch: string;
36 headBranch: string;
37 commitSummary: string;
38 diffSummary: string;
39 diffPatch: string;
40 /** Model to use for generation. Defaults to gpt-5.4-mini if not specified. */
41 model?: string;
42}
43
44export interface PrContentGenerationResult {
45 title: string;
46 body: string;
47}
48
49export interface BranchNameGenerationInput {
50 cwd: string;
51 message: string;
52 attachments?: ReadonlyArray<ChatAttachment> | undefined;
53 /** Model to use for generation. Defaults to gpt-5.4-mini if not specified. */
54 model?: string;
55}
56
57export interface BranchNameGenerationResult {
58 branch: string;
59}
60
61export interface ThreadTitleGenerationInput {
62 cwd: string;
63 message: string;
64 attachments?: ReadonlyArray<ChatAttachment> | undefined;
65 /** Model to use for generation. Defaults to gpt-5.4-mini if not specified. */
66 model?: string;
67}
68
69export interface ThreadTitleGenerationResult {
70 title: string;
71}
72
73export interface TextGenerationService {
74 generateCommitMessage(
75 input: CommitMessageGenerationInput,
76 ): Promise<CommitMessageGenerationResult>;
77 generatePrContent(input: PrContentGenerationInput): Promise<PrContentGenerationResult>;
78 generateBranchName(input: BranchNameGenerationInput): Promise<BranchNameGenerationResult>;
79 generateThreadTitle(input: ThreadTitleGenerationInput): Promise<ThreadTitleGenerationResult>;
80}
81
82/**
83 * TextGenerationShape - Service API for commit/PR text generation.
84 */
85export interface TextGenerationShape {
86 /**
87 * Generate a commit message from staged change context.
88 */
89 readonly generateCommitMessage: (
90 input: CommitMessageGenerationInput,
91 ) => Effect.Effect<CommitMessageGenerationResult, TextGenerationError>;
92
93 /**
94 * Generate pull request title/body from branch and diff context.
95 */
96 readonly generatePrContent: (
97 input: PrContentGenerationInput,
98 ) => Effect.Effect<PrContentGenerationResult, TextGenerationError>;
99
100 /**
101 * Generate a concise branch name from a user message.
102 */
103 readonly generateBranchName: (
104 input: BranchNameGenerationInput,
105 ) => Effect.Effect<BranchNameGenerationResult, TextGenerationError>;
106
107 /**
108 * Generate a concise thread title from thread message context.
109 */
110 readonly generateThreadTitle: (
111 input: ThreadTitleGenerationInput,
112 ) => Effect.Effect<ThreadTitleGenerationResult, TextGenerationError>;
113}
114
115/**
116 * TextGeneration - Service tag for commit and PR text generation.
117 */
118export class TextGeneration extends ServiceMap.Service<TextGeneration, TextGenerationShape>()(
119 "t3/git/Services/TextGeneration",
120) {}