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

git.ts

213 lines7.4 KB

1import { Option, Schema } from "effect";
2import { NonNegativeInt, PositiveInt, TrimmedNonEmptyString } from "./baseSchemas";
3import { DEFAULT_GIT_TEXT_GENERATION_MODEL } from "./model";
4​
5const TrimmedNonEmptyStringSchema = TrimmedNonEmptyString;
6​
7// Domain Types
8​
9export const GitStackedAction = Schema.Literals(["commit", "commit_push", "commit_push_pr"]);
10export type GitStackedAction = typeof GitStackedAction.Type;
11const GitCommitStepStatus = Schema.Literals(["created", "skipped_no_changes"]);
12const GitPushStepStatus = Schema.Literals([
13 "pushed",
14 "skipped_not_requested",
15 "skipped_up_to_date",
16]);
17const GitBranchStepStatus = Schema.Literals(["created", "skipped_not_requested"]);
18const GitPrStepStatus = Schema.Literals(["created", "opened_existing", "skipped_not_requested"]);
19const GitStatusPrState = Schema.Literals(["open", "closed", "merged"]);
20const GitPullRequestReference = TrimmedNonEmptyStringSchema;
21const GitPullRequestState = Schema.Literals(["open", "closed", "merged"]);
22const GitPreparePullRequestThreadMode = Schema.Literals(["local", "worktree"]);
23​
24export const GitBranch = Schema.Struct({
25 name: TrimmedNonEmptyStringSchema,
26 isRemote: Schema.optional(Schema.Boolean),
27 remoteName: Schema.optional(TrimmedNonEmptyStringSchema),
28 current: Schema.Boolean,
29 isDefault: Schema.Boolean,
30 worktreePath: TrimmedNonEmptyStringSchema.pipe(Schema.NullOr),
31});
32export type GitBranch = typeof GitBranch.Type;
33​
34const GitWorktree = Schema.Struct({
35 path: TrimmedNonEmptyStringSchema,
36 branch: TrimmedNonEmptyStringSchema,
37});
38const GitResolvedPullRequest = Schema.Struct({
39 number: PositiveInt,
40 title: TrimmedNonEmptyStringSchema,
41 url: Schema.String,
42 baseBranch: TrimmedNonEmptyStringSchema,
43 headBranch: TrimmedNonEmptyStringSchema,
44 state: GitPullRequestState,
45});
46export type GitResolvedPullRequest = typeof GitResolvedPullRequest.Type;
47​
48// RPC Inputs
49​
50export const GitStatusInput = Schema.Struct({
51 cwd: TrimmedNonEmptyStringSchema,
52});
53export type GitStatusInput = typeof GitStatusInput.Type;
54​
55export const GitPullInput = Schema.Struct({
56 cwd: TrimmedNonEmptyStringSchema,
57});
58export type GitPullInput = typeof GitPullInput.Type;
59​
60export const GitRunStackedActionInput = Schema.Struct({
61 cwd: TrimmedNonEmptyStringSchema,
62 action: GitStackedAction,
63 commitMessage: Schema.optional(TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(10_000))),
64 featureBranch: Schema.optional(Schema.Boolean),
65 filePaths: Schema.optional(
66 Schema.Array(TrimmedNonEmptyStringSchema).check(Schema.isMinLength(1)),
67 ),
68 textGenerationModel: Schema.optional(TrimmedNonEmptyStringSchema).pipe(
69 Schema.withConstructorDefault(() => Option.some(DEFAULT_GIT_TEXT_GENERATION_MODEL)),
70 ),
71});
72export type GitRunStackedActionInput = typeof GitRunStackedActionInput.Type;
73​
74export const GitListBranchesInput = Schema.Struct({
75 cwd: TrimmedNonEmptyStringSchema,
76});
77export type GitListBranchesInput = typeof GitListBranchesInput.Type;
78​
79export const GitCreateWorktreeInput = Schema.Struct({
80 cwd: TrimmedNonEmptyStringSchema,
81 branch: TrimmedNonEmptyStringSchema,
82 newBranch: Schema.optional(TrimmedNonEmptyStringSchema),
83 path: Schema.NullOr(TrimmedNonEmptyStringSchema),
84});
85export type GitCreateWorktreeInput = typeof GitCreateWorktreeInput.Type;
86​
87export const GitPullRequestRefInput = Schema.Struct({
88 cwd: TrimmedNonEmptyStringSchema,
89 reference: GitPullRequestReference,
90});
91export type GitPullRequestRefInput = typeof GitPullRequestRefInput.Type;
92​
93export const GitPreparePullRequestThreadInput = Schema.Struct({
94 cwd: TrimmedNonEmptyStringSchema,
95 reference: GitPullRequestReference,
96 mode: GitPreparePullRequestThreadMode,
97});
98export type GitPreparePullRequestThreadInput = typeof GitPreparePullRequestThreadInput.Type;
99​
100export const GitRemoveWorktreeInput = Schema.Struct({
101 cwd: TrimmedNonEmptyStringSchema,
102 path: TrimmedNonEmptyStringSchema,
103 force: Schema.optional(Schema.Boolean),
104});
105export type GitRemoveWorktreeInput = typeof GitRemoveWorktreeInput.Type;
106​
107export const GitCreateBranchInput = Schema.Struct({
108 cwd: TrimmedNonEmptyStringSchema,
109 branch: TrimmedNonEmptyStringSchema,
110});
111export type GitCreateBranchInput = typeof GitCreateBranchInput.Type;
112​
113export const GitCheckoutInput = Schema.Struct({
114 cwd: TrimmedNonEmptyStringSchema,
115 branch: TrimmedNonEmptyStringSchema,
116});
117export type GitCheckoutInput = typeof GitCheckoutInput.Type;
118​
119export const GitInitInput = Schema.Struct({
120 cwd: TrimmedNonEmptyStringSchema,
121});
122export type GitInitInput = typeof GitInitInput.Type;
123​
124// RPC Results
125​
126const GitStatusPr = Schema.Struct({
127 number: PositiveInt,
128 title: TrimmedNonEmptyStringSchema,
129 url: Schema.String,
130 baseBranch: TrimmedNonEmptyStringSchema,
131 headBranch: TrimmedNonEmptyStringSchema,
132 state: GitStatusPrState,
133});
134​
135export const GitStatusResult = Schema.Struct({
136 branch: TrimmedNonEmptyStringSchema.pipe(Schema.NullOr),
137 hasWorkingTreeChanges: Schema.Boolean,
138 workingTree: Schema.Struct({
139 files: Schema.Array(
140 Schema.Struct({
141 path: TrimmedNonEmptyStringSchema,
142 insertions: NonNegativeInt,
143 deletions: NonNegativeInt,
144 }),
145 ),
146 insertions: NonNegativeInt,
147 deletions: NonNegativeInt,
148 }),
149 hasUpstream: Schema.Boolean,
150 aheadCount: NonNegativeInt,
151 behindCount: NonNegativeInt,
152 pr: Schema.NullOr(GitStatusPr),
153});
154export type GitStatusResult = typeof GitStatusResult.Type;
155​
156export const GitListBranchesResult = Schema.Struct({
157 branches: Schema.Array(GitBranch),
158 isRepo: Schema.Boolean,
159 hasOriginRemote: Schema.Boolean,
160});
161export type GitListBranchesResult = typeof GitListBranchesResult.Type;
162​
163export const GitCreateWorktreeResult = Schema.Struct({
164 worktree: GitWorktree,
165});
166export type GitCreateWorktreeResult = typeof GitCreateWorktreeResult.Type;
167​
168export const GitResolvePullRequestResult = Schema.Struct({
169 pullRequest: GitResolvedPullRequest,
170});
171export type GitResolvePullRequestResult = typeof GitResolvePullRequestResult.Type;
172​
173export const GitPreparePullRequestThreadResult = Schema.Struct({
174 pullRequest: GitResolvedPullRequest,
175 branch: TrimmedNonEmptyStringSchema,
176 worktreePath: TrimmedNonEmptyStringSchema.pipe(Schema.NullOr),
177});
178export type GitPreparePullRequestThreadResult = typeof GitPreparePullRequestThreadResult.Type;
179​
180export const GitRunStackedActionResult = Schema.Struct({
181 action: GitStackedAction,
182 branch: Schema.Struct({
183 status: GitBranchStepStatus,
184 name: Schema.optional(TrimmedNonEmptyStringSchema),
185 }),
186 commit: Schema.Struct({
187 status: GitCommitStepStatus,
188 commitSha: Schema.optional(TrimmedNonEmptyStringSchema),
189 subject: Schema.optional(TrimmedNonEmptyStringSchema),
190 }),
191 push: Schema.Struct({
192 status: GitPushStepStatus,
193 branch: Schema.optional(TrimmedNonEmptyStringSchema),
194 upstreamBranch: Schema.optional(TrimmedNonEmptyStringSchema),
195 setUpstream: Schema.optional(Schema.Boolean),
196 }),
197 pr: Schema.Struct({
198 status: GitPrStepStatus,
199 url: Schema.optional(Schema.String),
200 number: Schema.optional(PositiveInt),
201 baseBranch: Schema.optional(TrimmedNonEmptyStringSchema),
202 headBranch: Schema.optional(TrimmedNonEmptyStringSchema),
203 title: Schema.optional(TrimmedNonEmptyStringSchema),
204 }),
205});
206export type GitRunStackedActionResult = typeof GitRunStackedActionResult.Type;
207​
208export const GitPullResult = Schema.Struct({
209 status: Schema.Literals(["pulled", "skipped_up_to_date"]),
210 branch: TrimmedNonEmptyStringSchema,
211 upstreamBranch: TrimmedNonEmptyStringSchema.pipe(Schema.NullOr),
212});
213export type GitPullResult = typeof GitPullResult.Type;