The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as Effect from "effect/Effect"; |
| 2 | import * as Schema from "effect/Schema"; |
| 3 | import { |
| 4 | ForwardCompatibleOptional, |
| 5 | NonNegativeInt, |
| 6 | PositiveInt, |
| 7 | ProjectId, |
| 8 | ThreadId, |
| 9 | TrimmedNonEmptyString, |
| 10 | } from "./baseSchemas.ts"; |
| 11 | import { SourceControlProviderError, SourceControlProviderInfo } from "./sourceControl.ts"; |
| 12 | import { VcsDriverKind } from "./vcs.ts"; |
| 13 | |
| 14 | const TrimmedNonEmptyStringSchema = TrimmedNonEmptyString; |
| 15 | const GitFilePath = Schema.String.check(Schema.isNonEmpty()); |
| 16 | const GIT_LIST_BRANCHES_MAX_LIMIT = 200; |
| 17 | |
| 18 | export const GitStackedAction = Schema.Literals([ |
| 19 | "commit", |
| 20 | "push", |
| 21 | "create_pr", |
| 22 | "commit_push", |
| 23 | "commit_push_pr", |
| 24 | ]); |
| 25 | export type GitStackedAction = typeof GitStackedAction.Type; |
| 26 | export const GitActionProgressPhase = Schema.Literals(["branch", "commit", "push", "pr"]); |
| 27 | export type GitActionProgressPhase = typeof GitActionProgressPhase.Type; |
| 28 | export const GitActionProgressKind = Schema.Literals([ |
| 29 | "action_started", |
| 30 | "phase_started", |
| 31 | "hook_started", |
| 32 | "hook_output", |
| 33 | "hook_finished", |
| 34 | "action_finished", |
| 35 | "action_failed", |
| 36 | ]); |
| 37 | export type GitActionProgressKind = typeof GitActionProgressKind.Type; |
| 38 | export const GitActionProgressStream = Schema.Literals(["stdout", "stderr"]); |
| 39 | export type GitActionProgressStream = typeof GitActionProgressStream.Type; |
| 40 | const GitCommitStepStatus = Schema.Literals([ |
| 41 | "created", |
| 42 | "skipped_no_changes", |
| 43 | "skipped_not_requested", |
| 44 | ]); |
| 45 | const GitPushStepStatus = Schema.Literals([ |
| 46 | "pushed", |
| 47 | "skipped_not_requested", |
| 48 | "skipped_up_to_date", |
| 49 | ]); |
| 50 | const GitBranchStepStatus = Schema.Literals(["created", "skipped_not_requested"]); |
| 51 | const GitPrStepStatus = Schema.Literals(["created", "opened_existing", "skipped_not_requested"]); |
| 52 | const VcsStatusChangeRequestState = Schema.Literals(["open", "closed", "merged"]); |
| 53 | const GitPullRequestReference = TrimmedNonEmptyStringSchema; |
| 54 | const GitPullRequestState = Schema.Literals(["open", "closed", "merged"]); |
| 55 | const GitPreparePullRequestThreadMode = Schema.Literals(["local", "worktree"]); |
| 56 | export const GitRunStackedActionToastRunAction = Schema.Struct({ |
| 57 | kind: GitStackedAction, |
| 58 | }); |
| 59 | export type GitRunStackedActionToastRunAction = typeof GitRunStackedActionToastRunAction.Type; |
| 60 | const GitRunStackedActionToastCta = Schema.Union([ |
| 61 | Schema.Struct({ |
| 62 | kind: Schema.Literal("none"), |
| 63 | }), |
| 64 | Schema.Struct({ |
| 65 | kind: Schema.Literal("open_pr"), |
| 66 | label: TrimmedNonEmptyStringSchema, |
| 67 | url: Schema.String, |
| 68 | }), |
| 69 | Schema.Struct({ |
| 70 | kind: Schema.Literal("run_action"), |
| 71 | label: TrimmedNonEmptyStringSchema, |
| 72 | action: GitRunStackedActionToastRunAction, |
| 73 | }), |
| 74 | ]); |
| 75 | export type GitRunStackedActionToastCta = typeof GitRunStackedActionToastCta.Type; |
| 76 | const GitRunStackedActionToast = Schema.Struct({ |
| 77 | title: TrimmedNonEmptyStringSchema, |
| 78 | description: Schema.optional(TrimmedNonEmptyStringSchema), |
| 79 | cta: GitRunStackedActionToastCta, |
| 80 | }); |
| 81 | export type GitRunStackedActionToast = typeof GitRunStackedActionToast.Type; |
| 82 | |
| 83 | export const VcsRef = Schema.Struct({ |
| 84 | name: TrimmedNonEmptyStringSchema, |
| 85 | isRemote: Schema.optional(Schema.Boolean), |
| 86 | remoteName: Schema.optional(TrimmedNonEmptyStringSchema), |
| 87 | // Full Git ref, for example refs/remotes/origin/feature. |
| 88 | upstreamRef: Schema.optional(TrimmedNonEmptyStringSchema), |
| 89 | current: Schema.Boolean, |
| 90 | isDefault: Schema.Boolean, |
| 91 | worktreePath: TrimmedNonEmptyStringSchema.pipe(Schema.NullOr), |
| 92 | }); |
| 93 | export type VcsRef = typeof VcsRef.Type; |
| 94 | |
| 95 | const VcsWorktree = Schema.Struct({ |
| 96 | path: TrimmedNonEmptyStringSchema, |
| 97 | refName: TrimmedNonEmptyStringSchema, |
| 98 | }); |
| 99 | const GitResolvedPullRequest = Schema.Struct({ |
| 100 | number: PositiveInt, |
| 101 | title: TrimmedNonEmptyStringSchema, |
| 102 | url: Schema.String, |
| 103 | baseBranch: TrimmedNonEmptyStringSchema, |
| 104 | headBranch: TrimmedNonEmptyStringSchema, |
| 105 | state: GitPullRequestState, |
| 106 | }); |
| 107 | export type GitResolvedPullRequest = typeof GitResolvedPullRequest.Type; |
| 108 | |
| 109 | export const VcsStatusInput = Schema.Struct({ |
| 110 | cwd: TrimmedNonEmptyStringSchema, |
| 111 | }); |
| 112 | export type VcsStatusInput = typeof VcsStatusInput.Type; |
| 113 | |
| 114 | export const VcsBranchStatus = Schema.Struct({ |
| 115 | refName: Schema.NullOr(Schema.String), |
| 116 | /** Absent from older servers, where a removed checkout looks like a detached HEAD. */ |
| 117 | isRepo: Schema.optional(Schema.Boolean), |
| 118 | }); |
| 119 | export type VcsBranchStatus = typeof VcsBranchStatus.Type; |
| 120 | |
| 121 | export const VcsStatusSubscriptionInput = Schema.Struct({ |
| 122 | ...VcsStatusInput.fields, |
| 123 | /** Passive observers receive cached remote status without retaining its refresh loop. */ |
| 124 | includeRemote: Schema.optional(Schema.Boolean), |
| 125 | }); |
| 126 | export type VcsStatusSubscriptionInput = typeof VcsStatusSubscriptionInput.Type; |
| 127 | |
| 128 | export const VcsPullInput = Schema.Struct({ |
| 129 | cwd: TrimmedNonEmptyStringSchema, |
| 130 | }); |
| 131 | export type VcsPullInput = typeof VcsPullInput.Type; |
| 132 | |
| 133 | export const GitRunStackedActionInput = Schema.Struct({ |
| 134 | actionId: TrimmedNonEmptyStringSchema, |
| 135 | cwd: TrimmedNonEmptyStringSchema, |
| 136 | action: GitStackedAction, |
| 137 | commitMessage: Schema.optional(TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(10_000))), |
| 138 | featureBranch: Schema.optional(Schema.Boolean), |
| 139 | filePaths: Schema.optional(Schema.Array(GitFilePath).check(Schema.isMinLength(1))), |
| 140 | threadId: Schema.optional(ThreadId), |
| 141 | projectId: Schema.optional(ProjectId), |
| 142 | }); |
| 143 | export type GitRunStackedActionInput = typeof GitRunStackedActionInput.Type; |
| 144 | |
| 145 | export const VcsListRefsInput = Schema.Struct({ |
| 146 | cwd: TrimmedNonEmptyStringSchema, |
| 147 | query: Schema.optional(TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(256))), |
| 148 | cursor: Schema.optional(NonNegativeInt), |
| 149 | includeMatchingRemoteRefs: Schema.optional(Schema.Boolean), |
| 150 | refKind: Schema.optional(Schema.Literals(["all", "local", "remote"])), |
| 151 | refresh: Schema.optional(Schema.Boolean), |
| 152 | limit: Schema.optional( |
| 153 | PositiveInt.check(Schema.isLessThanOrEqualTo(GIT_LIST_BRANCHES_MAX_LIMIT)), |
| 154 | ), |
| 155 | }); |
| 156 | export type VcsListRefsInput = typeof VcsListRefsInput.Type; |
| 157 | |
| 158 | export const VcsCreateWorktreeInput = Schema.Struct({ |
| 159 | cwd: TrimmedNonEmptyStringSchema, |
| 160 | refName: TrimmedNonEmptyStringSchema, |
| 161 | newRefName: Schema.optional(TrimmedNonEmptyStringSchema), |
| 162 | baseRefName: Schema.optional(TrimmedNonEmptyStringSchema), |
| 163 | path: Schema.NullOr(TrimmedNonEmptyStringSchema), |
| 164 | }); |
| 165 | export type VcsCreateWorktreeInput = typeof VcsCreateWorktreeInput.Type; |
| 166 | |
| 167 | export const GitPullRequestRefInput = Schema.Struct({ |
| 168 | cwd: TrimmedNonEmptyStringSchema, |
| 169 | reference: GitPullRequestReference, |
| 170 | }); |
| 171 | export type GitPullRequestRefInput = typeof GitPullRequestRefInput.Type; |
| 172 | |
| 173 | export const GitPreparePullRequestThreadInput = Schema.Struct({ |
| 174 | cwd: TrimmedNonEmptyStringSchema, |
| 175 | reference: GitPullRequestReference, |
| 176 | mode: GitPreparePullRequestThreadMode, |
| 177 | threadId: Schema.optional(ThreadId), |
| 178 | }); |
| 179 | export type GitPreparePullRequestThreadInput = typeof GitPreparePullRequestThreadInput.Type; |
| 180 | |
| 181 | export const VcsRemoveWorktreeInput = Schema.Struct({ |
| 182 | cwd: TrimmedNonEmptyStringSchema, |
| 183 | path: TrimmedNonEmptyStringSchema, |
| 184 | force: Schema.optional(Schema.Boolean), |
| 185 | }); |
| 186 | export type VcsRemoveWorktreeInput = typeof VcsRemoveWorktreeInput.Type; |
| 187 | |
| 188 | export const VcsCreateRefInput = Schema.Struct({ |
| 189 | cwd: TrimmedNonEmptyStringSchema, |
| 190 | refName: TrimmedNonEmptyStringSchema, |
| 191 | switchRef: Schema.optional(Schema.Boolean), |
| 192 | }); |
| 193 | export type VcsCreateRefInput = typeof VcsCreateRefInput.Type; |
| 194 | |
| 195 | export const VcsCreateRefResult = Schema.Struct({ |
| 196 | refName: TrimmedNonEmptyStringSchema, |
| 197 | }); |
| 198 | export type VcsCreateRefResult = typeof VcsCreateRefResult.Type; |
| 199 | |
| 200 | export const VcsSwitchRefInput = Schema.Struct({ |
| 201 | cwd: TrimmedNonEmptyStringSchema, |
| 202 | refName: TrimmedNonEmptyStringSchema, |
| 203 | }); |
| 204 | export type VcsSwitchRefInput = typeof VcsSwitchRefInput.Type; |
| 205 | |
| 206 | export const VcsInitInput = Schema.Struct({ |
| 207 | cwd: TrimmedNonEmptyStringSchema, |
| 208 | kind: Schema.optional(VcsDriverKind), |
| 209 | }); |
| 210 | export type VcsInitInput = typeof VcsInitInput.Type; |
| 211 | |
| 212 | const VcsStatusChangeRequest = Schema.Struct({ |
| 213 | number: PositiveInt, |
| 214 | title: TrimmedNonEmptyStringSchema, |
| 215 | url: Schema.String, |
| 216 | baseRef: TrimmedNonEmptyStringSchema, |
| 217 | headRef: TrimmedNonEmptyStringSchema, |
| 218 | state: VcsStatusChangeRequestState, |
| 219 | isDraft: Schema.optional(Schema.Boolean), |
| 220 | updatedAt: Schema.optional(Schema.NullOr(Schema.String)), |
| 221 | }); |
| 222 | |
| 223 | const VcsStatusLocalShape = { |
| 224 | isRepo: Schema.Boolean, |
| 225 | sourceControlProvider: Schema.optional(SourceControlProviderInfo), |
| 226 | hasPrimaryRemote: Schema.Boolean, |
| 227 | isDefaultRef: Schema.Boolean, |
| 228 | refName: Schema.NullOr(TrimmedNonEmptyStringSchema), |
| 229 | hasWorkingTreeChanges: Schema.Boolean, |
| 230 | workingTree: Schema.Struct({ |
| 231 | // Absolute worktree root on the environment that every files[].path is |
| 232 | // relative to. Absent when the server could not resolve it. |
| 233 | rootPath: Schema.optional(GitFilePath), |
| 234 | files: Schema.Array( |
| 235 | Schema.Struct({ |
| 236 | path: GitFilePath, |
| 237 | insertions: NonNegativeInt, |
| 238 | deletions: NonNegativeInt, |
| 239 | }), |
| 240 | ), |
| 241 | insertions: NonNegativeInt, |
| 242 | deletions: NonNegativeInt, |
| 243 | }), |
| 244 | branchChanges: Schema.optional( |
| 245 | Schema.Struct({ |
| 246 | baseRef: Schema.NullOr(TrimmedNonEmptyStringSchema), |
| 247 | insertions: NonNegativeInt, |
| 248 | deletions: NonNegativeInt, |
| 249 | }), |
| 250 | ), |
| 251 | }; |
| 252 | |
| 253 | const VcsStatusRemoteShape = { |
| 254 | hasUpstream: Schema.Boolean, |
| 255 | aheadCount: NonNegativeInt, |
| 256 | behindCount: NonNegativeInt, |
| 257 | aheadOfDefaultCount: Schema.optional(NonNegativeInt), |
| 258 | pr: Schema.NullOr(VcsStatusChangeRequest), |
| 259 | }; |
| 260 | |
| 261 | export const VcsStatusLocalResult = Schema.Struct(VcsStatusLocalShape); |
| 262 | export type VcsStatusLocalResult = typeof VcsStatusLocalResult.Type; |
| 263 | |
| 264 | export const VcsStatusRemoteResult = Schema.Struct(VcsStatusRemoteShape); |
| 265 | export type VcsStatusRemoteResult = typeof VcsStatusRemoteResult.Type; |
| 266 | |
| 267 | export const VcsStatusResult = Schema.Struct({ |
| 268 | ...VcsStatusLocalShape, |
| 269 | ...VcsStatusRemoteShape, |
| 270 | }); |
| 271 | export type VcsStatusResult = typeof VcsStatusResult.Type; |
| 272 | |
| 273 | export const VcsStatusStreamEvent = Schema.Union([ |
| 274 | Schema.TaggedStruct("snapshot", { |
| 275 | local: VcsStatusLocalResult, |
| 276 | remote: Schema.NullOr(VcsStatusRemoteResult), |
| 277 | }), |
| 278 | Schema.TaggedStruct("localUpdated", { |
| 279 | local: VcsStatusLocalResult, |
| 280 | }), |
| 281 | Schema.TaggedStruct("remoteUpdated", { |
| 282 | remote: Schema.NullOr(VcsStatusRemoteResult), |
| 283 | }), |
| 284 | ]); |
| 285 | export type VcsStatusStreamEvent = typeof VcsStatusStreamEvent.Type; |
| 286 | |
| 287 | export const VcsListRefsResult = Schema.Struct({ |
| 288 | isAtRepositoryRoot: Schema.optional(Schema.Boolean), |
| 289 | refs: Schema.Array(VcsRef), |
| 290 | isRepo: Schema.Boolean, |
| 291 | hasPrimaryRemote: Schema.Boolean, |
| 292 | nextCursor: NonNegativeInt.pipe(Schema.NullOr), |
| 293 | totalCount: NonNegativeInt, |
| 294 | }); |
| 295 | export type VcsListRefsResult = typeof VcsListRefsResult.Type; |
| 296 | |
| 297 | export const VcsCreateWorktreeResult = Schema.Struct({ |
| 298 | worktree: VcsWorktree, |
| 299 | }); |
| 300 | export type VcsCreateWorktreeResult = typeof VcsCreateWorktreeResult.Type; |
| 301 | |
| 302 | export const GitResolvePullRequestResult = Schema.Struct({ |
| 303 | pullRequest: GitResolvedPullRequest, |
| 304 | }); |
| 305 | export type GitResolvePullRequestResult = typeof GitResolvePullRequestResult.Type; |
| 306 | |
| 307 | export const GitPreparePullRequestThreadResult = Schema.Struct({ |
| 308 | pullRequest: GitResolvedPullRequest, |
| 309 | branch: TrimmedNonEmptyStringSchema, |
| 310 | worktreePath: TrimmedNonEmptyStringSchema.pipe(Schema.NullOr), |
| 311 | /** False when local commits or edits prevented a reused worktree from reaching the PR head. */ |
| 312 | isOnPullRequestHead: Schema.Boolean.pipe(Schema.withDecodingDefaultKey(Effect.succeed(true))), |
| 313 | }); |
| 314 | export type GitPreparePullRequestThreadResult = typeof GitPreparePullRequestThreadResult.Type; |
| 315 | |
| 316 | export const VcsSwitchRefResult = Schema.Struct({ |
| 317 | refName: Schema.NullOr(TrimmedNonEmptyStringSchema), |
| 318 | }); |
| 319 | export type VcsSwitchRefResult = typeof VcsSwitchRefResult.Type; |
| 320 | |
| 321 | export const GitRunStackedActionResult = Schema.Struct({ |
| 322 | action: GitStackedAction, |
| 323 | branch: Schema.Struct({ |
| 324 | status: GitBranchStepStatus, |
| 325 | name: Schema.optional(TrimmedNonEmptyStringSchema), |
| 326 | }), |
| 327 | commit: Schema.Struct({ |
| 328 | status: GitCommitStepStatus, |
| 329 | commitSha: Schema.optional(TrimmedNonEmptyStringSchema), |
| 330 | subject: Schema.optional(TrimmedNonEmptyStringSchema), |
| 331 | }), |
| 332 | push: Schema.Struct({ |
| 333 | status: GitPushStepStatus, |
| 334 | branch: Schema.optional(TrimmedNonEmptyStringSchema), |
| 335 | upstreamBranch: Schema.optional(TrimmedNonEmptyStringSchema), |
| 336 | setUpstream: Schema.optional(Schema.Boolean), |
| 337 | }), |
| 338 | pr: Schema.Struct({ |
| 339 | status: GitPrStepStatus, |
| 340 | url: Schema.optional(Schema.String), |
| 341 | number: Schema.optional(PositiveInt), |
| 342 | baseBranch: Schema.optional(TrimmedNonEmptyStringSchema), |
| 343 | headBranch: Schema.optional(TrimmedNonEmptyStringSchema), |
| 344 | title: Schema.optional(TrimmedNonEmptyStringSchema), |
| 345 | }), |
| 346 | toast: GitRunStackedActionToast, |
| 347 | }); |
| 348 | export type GitRunStackedActionResult = typeof GitRunStackedActionResult.Type; |
| 349 | |
| 350 | export const VcsPullResult = Schema.Struct({ |
| 351 | status: Schema.Literals(["pulled", "skipped_up_to_date"]), |
| 352 | refName: TrimmedNonEmptyStringSchema, |
| 353 | upstreamRef: TrimmedNonEmptyStringSchema.pipe(Schema.NullOr), |
| 354 | }); |
| 355 | export type VcsPullResult = typeof VcsPullResult.Type; |
| 356 | |
| 357 | // Git stderr can echo credentials from argv and remote URLs. Only a fixed |
| 358 | // reason reaches the error and its diagnostic suffix; newer, unknown reasons |
| 359 | // decode as absent through GitCommandError. |
| 360 | export const GitCommandFailureReason = Schema.Literals([ |
| 361 | "authentication_failed", |
| 362 | "branch_already_exists", |
| 363 | "branch_checked_out_in_worktree", |
| 364 | "config_locked", |
| 365 | "host_key_unverified", |
| 366 | "not_a_repository", |
| 367 | "path_already_exists", |
| 368 | "push_rejected_by_remote", |
| 369 | "push_rejected_non_fast_forward", |
| 370 | "ref_name_conflict", |
| 371 | "ref_not_found", |
| 372 | "remote_unreachable", |
| 373 | "tag_would_be_clobbered", |
| 374 | ]); |
| 375 | export type GitCommandFailureReason = typeof GitCommandFailureReason.Type; |
| 376 | |
| 377 | export class GitCommandError extends Schema.TaggedError<GitCommandError>()("GitCommandError", { |
| 378 | operation: Schema.String, |
| 379 | command: Schema.String, |
| 380 | cwd: Schema.String, |
| 381 | argumentCount: Schema.optional(Schema.Number), |
| 382 | exitCode: Schema.optional(Schema.Number), |
| 383 | stdoutLength: Schema.optional(Schema.Number), |
| 384 | stderrLength: Schema.optional(Schema.Number), |
| 385 | outputLength: Schema.optional(Schema.Number), |
| 386 | reason: ForwardCompatibleOptional(GitCommandFailureReason), |
| 387 | detail: Schema.String, |
| 388 | cause: Schema.optional(Schema.Defect()), |
| 389 | }) { |
| 390 | override get message(): string { |
| 391 | const reason = this.reason === undefined ? "" : ` (${this.reason})`; |
| 392 | return `Git command failed in ${this.operation} (${this.cwd}): ${this.detail}${reason}`; |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | export class TextGenerationError extends Schema.TaggedError<TextGenerationError>()( |
| 397 | "TextGenerationError", |
| 398 | { |
| 399 | operation: Schema.String, |
| 400 | detail: Schema.String, |
| 401 | cause: Schema.optional(Schema.Defect()), |
| 402 | }, |
| 403 | ) { |
| 404 | override get message(): string { |
| 405 | return `Text generation failed in ${this.operation}: ${this.detail}`; |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | export class GitManagerError extends Schema.TaggedError<GitManagerError>()("GitManagerError", { |
| 410 | operation: Schema.String, |
| 411 | cwd: Schema.String, |
| 412 | detail: Schema.String, |
| 413 | cause: Schema.optional(Schema.Defect()), |
| 414 | }) { |
| 415 | override get message(): string { |
| 416 | return `Git manager failed in ${this.operation}: ${this.detail}`; |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | export class GitPullRequestMaterializationError extends Schema.TaggedError<GitPullRequestMaterializationError>()( |
| 421 | "GitPullRequestMaterializationError", |
| 422 | { |
| 423 | cwd: TrimmedNonEmptyStringSchema, |
| 424 | pullRequestNumber: PositiveInt, |
| 425 | headRepository: Schema.NullOr(TrimmedNonEmptyStringSchema), |
| 426 | headBranch: TrimmedNonEmptyStringSchema, |
| 427 | localBranch: TrimmedNonEmptyStringSchema, |
| 428 | cause: Schema.Defect(), |
| 429 | }, |
| 430 | ) { |
| 431 | override get message(): string { |
| 432 | return `Failed to materialize pull request #${this.pullRequestNumber} branch ${this.headBranch} as ${this.localBranch}.`; |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | export const GitManagerServiceError = Schema.Union([ |
| 437 | GitManagerError, |
| 438 | GitPullRequestMaterializationError, |
| 439 | GitCommandError, |
| 440 | SourceControlProviderError, |
| 441 | TextGenerationError, |
| 442 | ]); |
| 443 | export type GitManagerServiceError = typeof GitManagerServiceError.Type; |
| 444 | |
| 445 | const GitActionProgressBase = Schema.Struct({ |
| 446 | actionId: TrimmedNonEmptyStringSchema, |
| 447 | cwd: TrimmedNonEmptyStringSchema, |
| 448 | action: GitStackedAction, |
| 449 | }); |
| 450 | |
| 451 | const GitActionStartedEvent = Schema.Struct({ |
| 452 | ...GitActionProgressBase.fields, |
| 453 | kind: Schema.Literal("action_started"), |
| 454 | phases: Schema.Array(GitActionProgressPhase), |
| 455 | }); |
| 456 | const GitActionPhaseStartedEvent = Schema.Struct({ |
| 457 | ...GitActionProgressBase.fields, |
| 458 | kind: Schema.Literal("phase_started"), |
| 459 | phase: GitActionProgressPhase, |
| 460 | label: TrimmedNonEmptyStringSchema, |
| 461 | }); |
| 462 | const GitActionHookStartedEvent = Schema.Struct({ |
| 463 | ...GitActionProgressBase.fields, |
| 464 | kind: Schema.Literal("hook_started"), |
| 465 | hookName: TrimmedNonEmptyStringSchema, |
| 466 | }); |
| 467 | const GitActionHookOutputEvent = Schema.Struct({ |
| 468 | ...GitActionProgressBase.fields, |
| 469 | kind: Schema.Literal("hook_output"), |
| 470 | hookName: Schema.NullOr(TrimmedNonEmptyStringSchema), |
| 471 | stream: GitActionProgressStream, |
| 472 | text: TrimmedNonEmptyStringSchema, |
| 473 | }); |
| 474 | const GitActionHookFinishedEvent = Schema.Struct({ |
| 475 | ...GitActionProgressBase.fields, |
| 476 | kind: Schema.Literal("hook_finished"), |
| 477 | hookName: TrimmedNonEmptyStringSchema, |
| 478 | exitCode: Schema.NullOr(Schema.Int), |
| 479 | durationMs: Schema.NullOr(NonNegativeInt), |
| 480 | }); |
| 481 | const GitActionFinishedEvent = Schema.Struct({ |
| 482 | ...GitActionProgressBase.fields, |
| 483 | kind: Schema.Literal("action_finished"), |
| 484 | result: GitRunStackedActionResult, |
| 485 | }); |
| 486 | const GitActionFailedEvent = Schema.Struct({ |
| 487 | ...GitActionProgressBase.fields, |
| 488 | kind: Schema.Literal("action_failed"), |
| 489 | phase: Schema.NullOr(GitActionProgressPhase), |
| 490 | message: TrimmedNonEmptyStringSchema, |
| 491 | }); |
| 492 | |
| 493 | export const GitActionProgressEvent = Schema.Union([ |
| 494 | GitActionStartedEvent, |
| 495 | GitActionPhaseStartedEvent, |
| 496 | GitActionHookStartedEvent, |
| 497 | GitActionHookOutputEvent, |
| 498 | GitActionHookFinishedEvent, |
| 499 | GitActionFinishedEvent, |
| 500 | GitActionFailedEvent, |
| 501 | ]); |
| 502 | export type GitActionProgressEvent = typeof GitActionProgressEvent.Type; |