Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

TextGeneration.ts

123 lines3.6 KB

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 { Context } from "effect";
10import type { Effect } from "effect";
11import type { ChatAttachment, ModelSelection } from "@workbench/contracts";
12​
13import type { TextGenerationError } from "@workbench/contracts";
14​
15/** Providers that support git text generation (commit messages, PR content, branch names). */
16export type TextGenerationProvider = "codex" | "claudeAgent" | "cursor" | "opencode" | "pi";
17​
18export interface CommitMessageGenerationInput {
19 cwd: string;
20 branch: string | null;
21 stagedSummary: string;
22 stagedPatch: string;
23 /** When true, the model also returns a semantic branch name for the change. */
24 includeBranch?: boolean;
25 /** What model and provider to use for generation. */
26 modelSelection: ModelSelection;
28​
29export interface CommitMessageGenerationResult {
30 subject: string;
31 body: string;
32 /** Only present when `includeBranch` was set on the input. */
33 branch?: string | undefined;
35​
36export interface PrContentGenerationInput {
37 cwd: string;
38 baseBranch: string;
39 headBranch: string;
40 commitSummary: string;
41 diffSummary: string;
42 diffPatch: string;
43 /** What model and provider to use for generation. */
44 modelSelection: ModelSelection;
46​
47export interface PrContentGenerationResult {
48 title: string;
49 body: string;
51​
52export interface BranchNameGenerationInput {
53 cwd: string;
54 message: string;
55 attachments?: ReadonlyArray<ChatAttachment> | undefined;
56 /** What model and provider to use for generation. */
57 modelSelection: ModelSelection;
59​
60export interface BranchNameGenerationResult {
61 branch: string;
63​
64export interface ThreadTitleGenerationInput {
65 cwd: string;
66 message: string;
67 attachments?: ReadonlyArray<ChatAttachment> | undefined;
68 /** What model and provider to use for generation. */
69 modelSelection: ModelSelection;
71​
72export interface ThreadTitleGenerationResult {
73 title: string;
75​
76export interface TextGenerationService {
77 generateCommitMessage(
78 input: CommitMessageGenerationInput,
79 ): Promise<CommitMessageGenerationResult>;
80 generatePrContent(input: PrContentGenerationInput): Promise<PrContentGenerationResult>;
81 generateBranchName(input: BranchNameGenerationInput): Promise<BranchNameGenerationResult>;
82 generateThreadTitle(input: ThreadTitleGenerationInput): Promise<ThreadTitleGenerationResult>;
84​
85/**
86 * TextGenerationShape - Service API for commit/PR text generation.
87 */
88export interface TextGenerationShape {
89 /**
90 * Generate a commit message from staged change context.
91 */
92 readonly generateCommitMessage: (
93 input: CommitMessageGenerationInput,
94 ) => Effect.Effect<CommitMessageGenerationResult, TextGenerationError>;
95​
96 /**
97 * Generate pull request title/body from branch and diff context.
98 */
99 readonly generatePrContent: (
100 input: PrContentGenerationInput,
101 ) => Effect.Effect<PrContentGenerationResult, TextGenerationError>;
102​
103 /**
104 * Generate a concise branch name from a user message.
105 */
106 readonly generateBranchName: (
107 input: BranchNameGenerationInput,
108 ) => Effect.Effect<BranchNameGenerationResult, TextGenerationError>;
109​
110 /**
111 * Generate a concise thread title from a user's first message.
112 */
113 readonly generateThreadTitle: (
114 input: ThreadTitleGenerationInput,
115 ) => Effect.Effect<ThreadTitleGenerationResult, TextGenerationError>;
117​
118/**
119 * TextGeneration - Service tag for commit and PR text generation.
120 */
121export class TextGeneration extends Context.Service<TextGeneration, TextGenerationShape>()(
122 "t3/git/Services/TextGeneration",
123) {}