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

workspaceFolders.ts

162 lines6.4 KB

1import * as Schema from "effect/Schema";
2​
3import { NonBlankString, ProjectId, ThreadId, TrimmedNonEmptyString } from "./baseSchemas.ts";
4​
5/** `git` folders are repositories with their own history; `plain` folders are only files. */
6export const WorkspaceFolderState = Schema.Literals(["git", "plain", "missing"]);
7export type WorkspaceFolderState = typeof WorkspaceFolderState.Type;
8​
9export const WorkspaceFolder = Schema.Struct({
10 name: TrimmedNonEmptyString,
11 path: NonBlankString,
12 state: WorkspaceFolderState,
13 /** Found inside the project folder by the server, not added by someone. */
14 discovered: Schema.optional(Schema.Boolean),
15 /** False for a `git` folder with no commit yet, which a worktree has nothing to check out of. */
16 hasCommits: Schema.optional(Schema.Boolean),
17});
18export type WorkspaceFolder = typeof WorkspaceFolder.Type;
19​
20export const WorkspaceListFoldersInput = Schema.Struct({
21 projectId: ProjectId,
22});
23export type WorkspaceListFoldersInput = typeof WorkspaceListFoldersInput.Type;
24​
25export const WorkspaceListFoldersResult = Schema.Struct({
26 /** The repositories found inside the project folder now, then the folders someone added. */
27 folders: Schema.Array(WorkspaceFolder),
28});
29export type WorkspaceListFoldersResult = typeof WorkspaceListFoldersResult.Type;
30​
31export const WorkspaceScanFoldersInput = Schema.Struct({
32 workspaceRoot: TrimmedNonEmptyString,
33});
34export type WorkspaceScanFoldersInput = typeof WorkspaceScanFoldersInput.Type;
35​
36export const WorkspaceScannedFolder = Schema.Struct({
37 /** Absolute path on the environment. */
38 path: TrimmedNonEmptyString,
39 name: TrimmedNonEmptyString,
40 isGitRepository: Schema.Boolean,
41 /** `child` sits one level under the scanned folder; `code-workspace` came from that file. */
42 source: Schema.Literals(["child", "code-workspace"]),
43});
44export type WorkspaceScannedFolder = typeof WorkspaceScannedFolder.Type;
45​
46export const WorkspaceScanFoldersResult = Schema.Struct({
47 /** Resolved path of the scanned folder. */
48 workspaceRoot: TrimmedNonEmptyString,
49 isGitRepository: Schema.Boolean,
50 /** The `.code-workspace` file the listed folders came from, when one was read. */
51 codeWorkspaceFile: Schema.NullOr(TrimmedNonEmptyString),
52 folders: Schema.Array(WorkspaceScannedFolder),
53});
54export type WorkspaceScanFoldersResult = typeof WorkspaceScanFoldersResult.Type;
55​
56/** A new worktree thread isolates every tracked repository by default only up to this many. */
57export const TASK_FOLDER_DEFAULT_REPOSITORIES_MAX = 8;
58​
59/** A tracked repository's own worktree inside a thread's task folder. */
60export const TaskFolderRepository = Schema.Struct({
61 /** The tracked folder's path, as the project stores it. */
62 repositoryPath: NonBlankString,
63 worktreePath: NonBlankString,
64 name: TrimmedNonEmptyString,
65});
66export type TaskFolderRepository = typeof TaskFolderRepository.Type;
67​
68/**
69 * The folder a worktree thread of a multi-repository project works in: the project folder and
70 * each chosen repository at the same relative places, every repository on the thread's branch.
71 */
72export const TaskFolder = Schema.Struct({
73 root: TrimmedNonEmptyString,
74 projectId: ProjectId,
75 /** The project folder this was laid out from. */
76 projectRoot: TrimmedNonEmptyString,
77 /** The folder `root` stands in for: a path below it sits at the same place below `root`. */
78 anchor: TrimmedNonEmptyString,
79 /** Where the project folder sits inside `root`: the thread's `worktreePath`. */
80 projectPath: TrimmedNonEmptyString,
81 /** False when the project folder is not a repository: `projectPath` then links to its files. */
82 projectIsWorktree: Schema.Boolean,
83 repositories: Schema.Array(TaskFolderRepository),
84});
85export type TaskFolder = typeof TaskFolder.Type;
86​
87export const WorkspaceTaskFolderInput = Schema.Struct({
88 /** A thread's `worktreePath`, or any path inside its task folder. */
89 worktreePath: TrimmedNonEmptyString,
90});
91export type WorkspaceTaskFolderInput = typeof WorkspaceTaskFolderInput.Type;
92​
93export const WorkspaceTaskFolderResult = Schema.Struct({
94 /** Null for a thread whose worktree is a single checkout. */
95 taskFolder: Schema.NullOr(TaskFolder),
96});
97export type WorkspaceTaskFolderResult = typeof WorkspaceTaskFolderResult.Type;
98​
99export const WorkspaceAddTaskFolderRepositoryInput = Schema.Struct({
100 threadId: ThreadId,
101 /** One of the project's tracked Git folders. */
102 repositoryPath: NonBlankString,
103});
104export type WorkspaceAddTaskFolderRepositoryInput =
105 typeof WorkspaceAddTaskFolderRepositoryInput.Type;
106​
107export const WorktreeLayoutCommandKind = Schema.Literals(["create", "remove"]);
108export type WorktreeLayoutCommandKind = typeof WorktreeLayoutCommandKind.Type;
109​
110/** One of a project's `worktreeLayout` commands, as its `t3.json` holds it now. */
111export const WorktreeLayoutCommand = Schema.Struct({
112 kind: WorktreeLayoutCommandKind,
113 command: Schema.String,
114 /** A person approved this exact text for this project. */
115 approved: Schema.Boolean,
116});
117export type WorktreeLayoutCommand = typeof WorktreeLayoutCommand.Type;
118​
119export const WorkspaceLayoutCommandsInput = Schema.Struct({
120 projectId: ProjectId,
121});
122export type WorkspaceLayoutCommandsInput = typeof WorkspaceLayoutCommandsInput.Type;
123​
124export const WorkspaceLayoutCommandsResult = Schema.Struct({
125 /** Empty for a project that declares no `worktreeLayout`. */
126 commands: Schema.Array(WorktreeLayoutCommand),
127});
128export type WorkspaceLayoutCommandsResult = typeof WorkspaceLayoutCommandsResult.Type;
129​
130export const WorkspaceApproveLayoutCommandsInput = Schema.Struct({
131 projectId: ProjectId,
132 approvals: Schema.Array(
133 Schema.Struct({
134 kind: WorktreeLayoutCommandKind,
135 /** The text the person was shown, so a file that changed since is not approved unseen. Null withdraws the approval. */
136 command: Schema.NullOr(Schema.String.check(Schema.isMaxLength(4096))),
137 }),
138 ),
139});
140export type WorkspaceApproveLayoutCommandsInput = typeof WorkspaceApproveLayoutCommandsInput.Type;
141​
142export class TaskFolderError extends Schema.TaggedError<TaskFolderError>()("TaskFolderError", {
143 operation: Schema.Literals(["plan", "create", "add-repository", "remove", "read", "approve"]),
144 detail: Schema.String,
145 cause: Schema.optional(Schema.Defect()),
146}) {
147 override get message(): string {
148 return this.detail;
149 }
151​
152export class WorkspaceFoldersError extends Schema.TaggedError<WorkspaceFoldersError>()(
153 "WorkspaceFoldersError",
154 {
155 operation: Schema.Literals(["list", "scan"]),
156 detail: Schema.String,
157 },
158) {
159 override get message(): string {
160 return this.detail;
161 }