-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit.ts
More file actions
467 lines (396 loc) · 14 KB
/
git.ts
File metadata and controls
467 lines (396 loc) · 14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
import { z } from "zod";
import { agentKindSchema, projectLocationSchema, sessionRefSchema } from "./common";
export type RemoteHostPlatform = "github" | "gitlab" | "bitbucket" | "unknown";
export interface GitRemoteInfo {
url: string;
platform: RemoteHostPlatform;
owner: string;
repo: string;
}
export interface GitFileChange {
path: string;
oldPath?: string;
status: string;
staged: boolean;
insertions: number;
deletions: number;
}
export interface GitStatusResult {
isRepo: boolean;
branch: string;
tracking: string;
hasRemote: boolean;
remoteInfo: GitRemoteInfo | null;
ahead: number;
behind: number;
staged: GitFileChange[];
unstaged: GitFileChange[];
totalInsertions: number;
totalDeletions: number;
mergeInProgress?: boolean;
conflictFiles?: GitFileChange[];
}
export interface GitDiffResult {
diff: string;
}
export interface GitDiffBatchResult {
staged: Record<string, string>;
unstaged: Record<string, string>;
}
export interface GitFileContentResult {
oldContent: string;
newContent: string;
}
export const fileCheckpointChangedFileSchema = z.object({
path: z.string().min(1),
oldPath: z.string().min(1).optional(),
status: z.string().min(1),
});
export type FileCheckpointChangedFile = z.infer<typeof fileCheckpointChangedFileSchema>;
export const fileCheckpointRecordSchema = z.object({
threadId: z.string().min(1),
checkpointItemId: z.string().min(1),
ref: z.string().min(1),
commit: z.string().min(1),
capturedAt: z.string().min(1),
});
export type FileCheckpointRecord = z.infer<typeof fileCheckpointRecordSchema>;
export const fileCheckpointTurnSchema = fileCheckpointRecordSchema.extend({
baseCheckpointItemId: z.string().min(1),
baseRef: z.string().min(1),
changedFiles: z.array(fileCheckpointChangedFileSchema),
});
export type FileCheckpointTurn = z.infer<typeof fileCheckpointTurnSchema>;
export const getGitStatusPayloadSchema = z.object({
projectLocation: projectLocationSchema,
});
export type GetGitStatusPayload = z.infer<typeof getGitStatusPayloadSchema>;
export const createFileCheckpointPayloadSchema = z.object({
threadId: z.string().min(1),
checkpointItemId: z.string().min(1),
projectLocation: projectLocationSchema,
});
export type CreateFileCheckpointPayload = z.infer<typeof createFileCheckpointPayloadSchema>;
export interface CreateFileCheckpointResult {
checkpoint: FileCheckpointRecord;
}
export const finalizeFileCheckpointPayloadSchema = z.object({
threadId: z.string().min(1),
checkpointItemId: z.string().min(1),
baseCheckpointItemId: z.string().min(1),
projectLocation: projectLocationSchema,
});
export type FinalizeFileCheckpointPayload = z.infer<typeof finalizeFileCheckpointPayloadSchema>;
export interface FinalizeFileCheckpointResult {
checkpoint: FileCheckpointTurn;
}
export const listFileCheckpointsPayloadSchema = z.object({
threadId: z.string().min(1),
projectLocation: projectLocationSchema,
});
export type ListFileCheckpointsPayload = z.infer<typeof listFileCheckpointsPayloadSchema>;
export interface ListFileCheckpointsResult {
checkpoints: FileCheckpointRecord[];
turns: FileCheckpointTurn[];
}
export const restoreFileCheckpointPayloadSchema = z.object({
threadId: z.string().min(1),
checkpointItemId: z.string().min(1),
projectLocation: projectLocationSchema,
});
export type RestoreFileCheckpointPayload = z.infer<typeof restoreFileCheckpointPayloadSchema>;
export const gitWorktreeStatusBatchPayloadSchema = z.object({
projectLocation: projectLocationSchema,
worktreePaths: z.array(z.string().min(1)),
});
export type GitWorktreeStatusBatchPayload = z.infer<typeof gitWorktreeStatusBatchPayloadSchema>;
export interface GitWorktreeStatusBatchResult {
/** Map worktree filesystem path → status. Worktrees whose status fetch failed are omitted. */
statuses: Record<string, GitStatusResult>;
}
export const getGitDiffPayloadSchema = z.object({
projectLocation: projectLocationSchema,
filePath: z.string().optional(),
staged: z.boolean().default(false),
});
export type GetGitDiffPayload = z.infer<typeof getGitDiffPayloadSchema>;
export const getGitDiffBatchPayloadSchema = z.object({
projectLocation: projectLocationSchema,
untrackedPaths: z.array(z.string()).default([]),
});
export type GetGitDiffBatchPayload = z.infer<typeof getGitDiffBatchPayloadSchema>;
export const getGitFileContentPayloadSchema = z.object({
projectLocation: projectLocationSchema,
filePath: z.string().min(1),
staged: z.boolean(),
});
export type GetGitFileContentPayload = z.infer<typeof getGitFileContentPayloadSchema>;
export const gitStagePayloadSchema = z.object({
projectLocation: projectLocationSchema,
filePath: z.string().min(1),
});
export type GitStagePayload = z.infer<typeof gitStagePayloadSchema>;
export const gitUnstagePayloadSchema = z.object({
projectLocation: projectLocationSchema,
filePath: z.string().min(1),
});
export type GitUnstagePayload = z.infer<typeof gitUnstagePayloadSchema>;
export const gitRevertPayloadSchema = z.object({
projectLocation: projectLocationSchema,
filePath: z.string().min(1),
});
export type GitRevertPayload = z.infer<typeof gitRevertPayloadSchema>;
export const gitStageAllPayloadSchema = z.object({
projectLocation: projectLocationSchema,
});
export type GitStageAllPayload = z.infer<typeof gitStageAllPayloadSchema>;
export const gitUnstageAllPayloadSchema = z.object({
projectLocation: projectLocationSchema,
});
export type GitUnstageAllPayload = z.infer<typeof gitUnstageAllPayloadSchema>;
export const gitRevertAllPayloadSchema = z.object({
projectLocation: projectLocationSchema,
});
export type GitRevertAllPayload = z.infer<typeof gitRevertAllPayloadSchema>;
export const gitCommitPayloadSchema = z.object({
projectLocation: projectLocationSchema,
message: z.string().min(1),
addAll: z.boolean().default(false),
});
export type GitCommitPayload = z.infer<typeof gitCommitPayloadSchema>;
export interface GitCommitResult {
hash: string;
message: string;
}
export const generateCommitMessagePayloadSchema = z.object({
projectLocation: projectLocationSchema,
agentKind: agentKindSchema,
model: z.string().min(1).optional(),
effort: z.string().min(1).optional(),
});
export type GenerateCommitMessagePayload = z.infer<typeof generateCommitMessagePayloadSchema>;
export interface GenerateCommitMessageResult {
message: string;
}
export const generateTitlePayloadSchema = z.object({
projectLocation: projectLocationSchema,
agentKind: agentKindSchema,
prompt: z.string().min(1),
model: z.string().min(1).optional(),
effort: z.string().min(1).optional(),
});
export type GenerateTitlePayload = z.infer<typeof generateTitlePayloadSchema>;
export interface GenerateTitleResult {
title: string;
}
export const generatePrSummaryPayloadSchema = z.object({
projectLocation: projectLocationSchema,
agentKind: agentKindSchema,
branch: z.string().min(1),
baseBranch: z.string().min(1),
model: z.string().min(1).optional(),
effort: z.string().min(1).optional(),
});
export type GeneratePrSummaryPayload = z.infer<typeof generatePrSummaryPayloadSchema>;
export interface GeneratePrSummaryResult {
title: string;
description: string;
}
export const extractContextPayloadSchema = z.object({
threadId: z.string().min(1),
agentKind: agentKindSchema,
sessionRef: sessionRefSchema,
projectLocation: projectLocationSchema,
worktreePath: z.string().optional(),
model: z.string().optional(),
effort: z.string().optional(),
});
export type ExtractContextPayload = z.infer<typeof extractContextPayloadSchema>;
export interface ExtractContextResult {
summary: string;
sourceProvider: string;
sourceSessionId: string;
worktreePath?: string;
extractedAt: string;
}
export interface GitBranchInfo {
name: string;
current: boolean;
commit: string;
isRemote: boolean;
remote?: string;
}
export interface GitBranchListResult {
current: string;
branches: GitBranchInfo[];
}
export interface GitWorktreeInfo {
path: string;
branch: string;
commit: string;
isMain: boolean;
}
export interface GitWorktreeListResult {
worktrees: GitWorktreeInfo[];
}
export interface GitAddWorktreeResult {
path: string;
}
export const getGitBranchesPayloadSchema = z.object({
projectLocation: projectLocationSchema,
includeRemote: z.boolean().default(true),
});
export type GetGitBranchesPayload = z.infer<typeof getGitBranchesPayloadSchema>;
export const gitFetchPayloadSchema = z.object({
projectLocation: projectLocationSchema,
remote: z.string().default("origin"),
prune: z.boolean().default(false),
});
export type GitFetchPayload = z.infer<typeof gitFetchPayloadSchema>;
export const gitListWorktreesPayloadSchema = z.object({
projectLocation: projectLocationSchema,
});
export type GitListWorktreesPayload = z.infer<typeof gitListWorktreesPayloadSchema>;
export const gitAddWorktreePayloadSchema = z.object({
projectLocation: projectLocationSchema,
path: z.string().min(1).optional(),
branch: z.string().optional(),
createBranch: z.boolean().default(false),
startPoint: z.string().optional(),
});
export type GitAddWorktreePayload = z.infer<typeof gitAddWorktreePayloadSchema>;
export const gitRemoveWorktreePayloadSchema = z.object({
projectLocation: projectLocationSchema,
path: z.string().min(1),
force: z.boolean().default(false),
deleteBranch: z.boolean().default(false),
});
export type GitRemoveWorktreePayload = z.infer<typeof gitRemoveWorktreePayloadSchema>;
export const gitPruneWorktreesPayloadSchema = z.object({
projectLocation: projectLocationSchema,
activeWorktreePaths: z.array(z.string()),
});
export type GitPruneWorktreesPayload = z.infer<typeof gitPruneWorktreesPayloadSchema>;
export const gitDeleteBranchPayloadSchema = z.object({
projectLocation: projectLocationSchema,
branch: z.string().min(1),
force: z.boolean().default(false),
remote: z.string().optional(),
});
export type GitDeleteBranchPayload = z.infer<typeof gitDeleteBranchPayloadSchema>;
export const gitSwitchBranchPayloadSchema = z.object({
projectLocation: projectLocationSchema,
branch: z.string().min(1),
createNew: z.boolean().default(false),
});
export type GitSwitchBranchPayload = z.infer<typeof gitSwitchBranchPayloadSchema>;
export interface GitSwitchBranchResult {
branch: string;
created: boolean;
tracking: string;
ahead: number;
behind: number;
}
export const gitPullPayloadSchema = z.object({
projectLocation: projectLocationSchema,
remote: z.string().optional().default("origin"),
});
export type GitPullPayload = z.input<typeof gitPullPayloadSchema>;
export const gitPushPayloadSchema = z.object({
projectLocation: projectLocationSchema,
remote: z.string().optional().default("origin"),
branch: z.string().optional(),
setUpstream: z.boolean().optional().default(false),
});
export type GitPushPayload = z.input<typeof gitPushPayloadSchema>;
export const gitSyncPayloadSchema = z.object({
projectLocation: projectLocationSchema,
remote: z.string().optional().default("origin"),
});
export type GitSyncPayload = z.input<typeof gitSyncPayloadSchema>;
export interface GitSyncResult {
pulled: boolean;
pushed: boolean;
}
export const gitProjectSnapshotPayloadSchema = z.object({
projectLocation: projectLocationSchema,
/** Pass true to also include the gh availability check (`gh --version`). */
includeGhCheck: z.boolean().default(false),
});
export type GitProjectSnapshotPayload = z.infer<typeof gitProjectSnapshotPayloadSchema>;
export interface GitProjectSnapshotResult {
status: GitStatusResult | null;
branches: GitBranchListResult | null;
worktrees: GitWorktreeInfo[] | null;
ghAvailable: boolean | null;
}
export const gitGetWorktreeSourceBranchPayloadSchema = z.object({
projectLocation: projectLocationSchema,
branch: z.string().min(1),
/** When set, skip inference and use this branch as the source (e.g. PR baseRefName). */
sourceBranchOverride: z.string().optional(),
});
export type GitGetWorktreeSourceBranchPayload = z.infer<
typeof gitGetWorktreeSourceBranchPayloadSchema
>;
export interface GitGetWorktreeSourceBranchResult {
sourceBranch: string | null;
commitsAhead: number;
sourceAhead: number;
}
export const gitMergeToSourcePayloadSchema = z.object({
projectLocation: projectLocationSchema,
worktreeLocation: projectLocationSchema,
worktreeBranch: z.string().min(1),
sourceBranch: z.string().min(1),
});
export type GitMergeToSourcePayload = z.infer<typeof gitMergeToSourcePayloadSchema>;
export interface GitMergeToSourceResult {
merged: boolean;
fastForward: boolean;
newSourceCommit: string;
error?: string;
conflictFiles?: string[];
}
export const gitPullFromSourcePayloadSchema = z.object({
worktreeLocation: projectLocationSchema,
sourceBranch: z.string().min(1),
preserveLocalChanges: z.boolean().default(false),
});
export type GitPullFromSourcePayload = z.infer<typeof gitPullFromSourcePayloadSchema>;
export interface GitPullFromSourceResult {
merged: boolean;
fastForward: boolean;
needsStash?: boolean;
reapplyConflicting?: boolean;
stashPreserved?: boolean;
conflicting?: boolean;
error?: string;
conflictFiles?: string[];
}
export const gitAbortMergePayloadSchema = z.object({
worktreeLocation: projectLocationSchema,
});
export type GitAbortMergePayload = z.infer<typeof gitAbortMergePayloadSchema>;
export const gitFinishMergePayloadSchema = z.object({
worktreeLocation: projectLocationSchema,
});
export type GitFinishMergePayload = z.infer<typeof gitFinishMergePayloadSchema>;
export interface GitFinishMergeResult {
success: boolean;
error?: string;
}
export const gitWatchProjectPayloadSchema = z.object({
projectId: z.string().min(1),
projectLocation: projectLocationSchema,
});
export type GitWatchProjectPayload = z.infer<typeof gitWatchProjectPayloadSchema>;
export const gitWatchWorktreesPayloadSchema = z.object({
projectId: z.string().min(1),
worktreePaths: z.array(z.string()),
});
export type GitWatchWorktreesPayload = z.infer<typeof gitWatchWorktreesPayloadSchema>;
export const gitUnwatchProjectPayloadSchema = z.object({
projectId: z.string().min(1),
});
export type GitUnwatchProjectPayload = z.infer<typeof gitUnwatchProjectPayloadSchema>;