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

workspaceFolders.ts

160 lines6.3 KB

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