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

vcs.ts

154 lines4.5 KB

1import * as Schema from "effect/Schema";
2import { TrimmedNonEmptyString } from "./baseSchemas.ts";
3​
4export const VcsDriverKind = Schema.Literals(["git", "jj", "unknown"]);
5export type VcsDriverKind = typeof VcsDriverKind.Type;
6​
7export const VcsFreshnessSource = Schema.Literals([
8 "live-local",
9 "cached-local",
10 "cached-remote",
11 "explicit-remote",
12]);
13export type VcsFreshnessSource = typeof VcsFreshnessSource.Type;
14​
15export const VcsFreshness = Schema.Struct({
16 source: VcsFreshnessSource,
17 observedAt: Schema.DateTimeUtc,
18 expiresAt: Schema.Option(Schema.DateTimeUtc),
19});
20export type VcsFreshness = typeof VcsFreshness.Type;
21​
22export const VcsDriverCapabilities = Schema.Struct({
23 kind: VcsDriverKind,
24 supportsWorktrees: Schema.Boolean,
25 supportsBookmarks: Schema.Boolean,
26 supportsAtomicSnapshot: Schema.Boolean,
27 supportsPushDefaultRemote: Schema.Boolean,
28 ignoreClassifier: Schema.Literals(["native", "git-compatible-fallback"]),
29});
30export type VcsDriverCapabilities = typeof VcsDriverCapabilities.Type;
31​
32export const VcsRepositoryIdentity = Schema.Struct({
33 kind: VcsDriverKind,
34 rootPath: TrimmedNonEmptyString,
35 metadataPath: Schema.NullOr(TrimmedNonEmptyString),
36 freshness: VcsFreshness,
37});
38export type VcsRepositoryIdentity = typeof VcsRepositoryIdentity.Type;
39​
40export const VcsListWorkspaceFilesResult = Schema.Struct({
41 paths: Schema.Array(TrimmedNonEmptyString),
42 truncated: Schema.Boolean,
43 freshness: VcsFreshness,
44});
45export type VcsListWorkspaceFilesResult = typeof VcsListWorkspaceFilesResult.Type;
46​
47export const VcsRemote = Schema.Struct({
48 name: TrimmedNonEmptyString,
49 url: TrimmedNonEmptyString,
50 pushUrl: Schema.Option(TrimmedNonEmptyString),
51 isPrimary: Schema.Boolean,
52});
53export type VcsRemote = typeof VcsRemote.Type;
54​
55export const VcsListRemotesResult = Schema.Struct({
56 remotes: Schema.Array(VcsRemote),
57 freshness: VcsFreshness,
58});
59export type VcsListRemotesResult = typeof VcsListRemotesResult.Type;
60​
61export class VcsProcessSpawnError extends Schema.TaggedErrorClass<VcsProcessSpawnError>()(
62 "VcsProcessSpawnError",
63 {
64 operation: Schema.String,
65 command: Schema.String,
66 cwd: Schema.String,
67 cause: Schema.Defect,
68 },
69) {
70 override get message(): string {
71 return `VCS process failed to spawn in ${this.operation}: ${this.command} (${this.cwd})`;
72 }
74​
75export class VcsProcessExitError extends Schema.TaggedErrorClass<VcsProcessExitError>()(
76 "VcsProcessExitError",
77 {
78 operation: Schema.String,
79 command: Schema.String,
80 cwd: Schema.String,
81 exitCode: Schema.Number,
82 detail: Schema.String,
83 },
84) {
85 override get message(): string {
86 return `VCS process failed in ${this.operation}: ${this.command} (${this.cwd}) exited with ${this.exitCode} - ${this.detail}`;
87 }
89​
90export class VcsProcessTimeoutError extends Schema.TaggedErrorClass<VcsProcessTimeoutError>()(
91 "VcsProcessTimeoutError",
92 {
93 operation: Schema.String,
94 command: Schema.String,
95 cwd: Schema.String,
96 timeoutMs: Schema.Number,
97 },
98) {
99 override get message(): string {
100 return `VCS process timed out in ${this.operation}: ${this.command} (${this.cwd}) after ${this.timeoutMs}ms`;
101 }
103​
104export class VcsOutputDecodeError extends Schema.TaggedErrorClass<VcsOutputDecodeError>()(
105 "VcsOutputDecodeError",
106 {
107 operation: Schema.String,
108 command: Schema.String,
109 cwd: Schema.String,
110 detail: Schema.String,
111 cause: Schema.optional(Schema.Defect),
112 },
113) {
114 override get message(): string {
115 return `VCS output decode failed in ${this.operation}: ${this.command} (${this.cwd}) - ${this.detail}`;
116 }
118​
119export class VcsRepositoryDetectionError extends Schema.TaggedErrorClass<VcsRepositoryDetectionError>()(
120 "VcsRepositoryDetectionError",
121 {
122 operation: Schema.String,
123 cwd: Schema.String,
124 detail: Schema.String,
125 cause: Schema.optional(Schema.Defect),
126 },
127) {
128 override get message(): string {
129 return `VCS repository detection failed in ${this.operation}: ${this.cwd} - ${this.detail}`;
130 }
132​
133export class VcsUnsupportedOperationError extends Schema.TaggedErrorClass<VcsUnsupportedOperationError>()(
134 "VcsUnsupportedOperationError",
135 {
136 operation: Schema.String,
137 kind: VcsDriverKind,
138 detail: Schema.String,
139 },
140) {
141 override get message(): string {
142 return `VCS operation is unsupported for ${this.kind} in ${this.operation}: ${this.detail}`;
143 }
145​
146export const VcsError = Schema.Union([
147 VcsProcessSpawnError,
148 VcsProcessExitError,
149 VcsProcessTimeoutError,
150 VcsOutputDecodeError,
151 VcsRepositoryDetectionError,
152 VcsUnsupportedOperationError,
153]);
154export type VcsError = typeof VcsError.Type;