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