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}
23
24export interface CommitMessageGenerationResult {
25 subject: string;
26 body: string;
27 /** Only present when `includeBranch` was set on the input. */
28 branch?: string | undefined;
29}
30
31export interface PrContentGenerationInput {
32 cwd: string;
33 baseBranch: string;
34 headBranch: string;
35 commitSummary: string;
36 diffSummary: string;
37 diffPatch: string;
38}
39
40export interface PrContentGenerationResult {
41 title: string;
42 body: string;
43}
44
45export interface BranchNameGenerationInput {
46 cwd: string;
47 message: string;
48 attachments?: ReadonlyArray<ChatAttachment> | undefined;
49}
50
51export interface BranchNameGenerationResult {
52 branch: string;
53}
54
55export interface TextGenerationService {
56 generateCommitMessage(
57 input: CommitMessageGenerationInput,
58 ): Promise<CommitMessageGenerationResult>;
59 generatePrContent(input: PrContentGenerationInput): Promise<PrContentGenerationResult>;
60 generateBranchName(input: BranchNameGenerationInput): Promise<BranchNameGenerationResult>;
61}
62
63/**
64 * TextGenerationShape - Service API for commit/PR text generation.
65 */
66export interface TextGenerationShape {
67 /**
68 * Generate a commit message from staged change context.
69 */
70 readonly generateCommitMessage: (
71 input: CommitMessageGenerationInput,
72 ) => Effect.Effect<CommitMessageGenerationResult, TextGenerationError>;
73
74 /**
75 * Generate pull request title/body from branch and diff context.
76 */
77 readonly generatePrContent: (
78 input: PrContentGenerationInput,
79 ) => Effect.Effect<PrContentGenerationResult, TextGenerationError>;
80
81 /**
82 * Generate a concise branch name from a user message.
83 */
84 readonly generateBranchName: (
85 input: BranchNameGenerationInput,
86 ) => Effect.Effect<BranchNameGenerationResult, TextGenerationError>;
87}
88
89/**
90 * TextGeneration - Service tag for commit and PR text generation.
91 */
92export class TextGeneration extends ServiceMap.Service<TextGeneration, TextGenerationShape>()(
93 "t3/git/Services/TextGeneration",
94) {}