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 TextGenerationService {
62 generateCommitMessage(
63 input: CommitMessageGenerationInput,
64 ): Promise<CommitMessageGenerationResult>;
65 generatePrContent(input: PrContentGenerationInput): Promise<PrContentGenerationResult>;
66 generateBranchName(input: BranchNameGenerationInput): Promise<BranchNameGenerationResult>;
67}
68
69/**
70 * TextGenerationShape - Service API for commit/PR text generation.
71 */
72export interface TextGenerationShape {
73 /**
74 * Generate a commit message from staged change context.
75 */
76 readonly generateCommitMessage: (
77 input: CommitMessageGenerationInput,
78 ) => Effect.Effect<CommitMessageGenerationResult, TextGenerationError>;
79
80 /**
81 * Generate pull request title/body from branch and diff context.
82 */
83 readonly generatePrContent: (
84 input: PrContentGenerationInput,
85 ) => Effect.Effect<PrContentGenerationResult, TextGenerationError>;
86
87 /**
88 * Generate a concise branch name from a user message.
89 */
90 readonly generateBranchName: (
91 input: BranchNameGenerationInput,
92 ) => Effect.Effect<BranchNameGenerationResult, TextGenerationError>;
93}
94
95/**
96 * TextGeneration - Service tag for commit and PR text generation.
97 */
98export class TextGeneration extends ServiceMap.Service<TextGeneration, TextGenerationShape>()(
99 "t3/git/Services/TextGeneration",
100) {}