Repository navigation
Expand file tree
/
Copy pathProjectService.ts
More file actions
649 lines (611 loc) · 23.6 KB
/
Copy pathProjectService.ts
File metadata and controls
649 lines (611 loc) · 23.6 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
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
import {
CommandId,
type OrchestrationProjectShell,
ProjectId,
type Project,
type ProjectCreatePayload,
type ProjectUpdatePayload,
type ProjectSnapshot,
type ThreadId,
} from "@t3tools/contracts";
import * as KeyedLock from "@t3tools/shared/KeyedLock";
import * as Context from "effect/Context";
import * as DateTime from "effect/DateTime";
import * as Effect from "effect/Effect";
import * as FileSystem from "effect/FileSystem";
import * as Layer from "effect/Layer";
import * as Option from "effect/Option";
import * as Result from "effect/Result";
import * as Schema from "effect/Schema";
import { withCommandMetrics } from "../observability/Metrics.ts";
import * as EventSink from "../orchestration-v2/EventSink.ts";
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
import * as LegacyV1ThreadImporter from "../orchestration-v2/legacy/LegacyV1ThreadImporter.ts";
import * as ProjectionStore from "../orchestration-v2/ProjectionStore.ts";
import {
decodeProjectCommandRejection,
encodeProjectCommandRejection,
planProjectCommand,
type ProjectCommand,
} from "../orchestration-v2/ProjectCommands.ts";
import * as ProjectStore from "../orchestration-v2/ProjectStore.ts";
import * as ThreadCommandExecutor from "../orchestration-v2/ThreadCommandExecutor.ts";
import { planThreadDeletion } from "../orchestration-v2/ThreadDeletion.ts";
import * as ServerSettings from "../serverSettings.ts";
import { makeIsManagedWorktreePath } from "../worktreesDirectory.ts";
import * as ProjectEnrichmentService from "./ProjectEnrichmentService.ts";
import * as WorkspacePaths from "../workspace/WorkspacePaths.ts";
export interface ProjectCreateInput extends ProjectCreatePayload {
readonly commandId: CommandId;
readonly projectId: ProjectId;
}
export interface ProjectUpdateInput extends ProjectUpdatePayload {
readonly commandId: CommandId;
readonly projectId: ProjectId;
}
export interface ProjectBootstrapInput extends ProjectCreateInput {}
export interface ProjectDeleteInput {
readonly commandId: CommandId;
readonly projectId: ProjectId;
readonly force?: boolean;
}
export class ProjectNotFoundError extends Schema.TaggedError<ProjectNotFoundError>()(
"ProjectNotFoundError",
{ projectId: ProjectId },
) {
override get message(): string {
return `Project ${this.projectId} was not found.`;
}
}
export class ProjectConflictError extends Schema.TaggedError<ProjectConflictError>()(
"ProjectConflictError",
{
projectId: ProjectId,
workspaceRoot: Schema.String,
conflictingProjectId: ProjectId,
},
) {
override get message(): string {
return `Workspace ${this.workspaceRoot} already belongs to project ${this.conflictingProjectId}.`;
}
}
export class ProjectNotEmptyError extends Schema.TaggedError<ProjectNotEmptyError>()(
"ProjectNotEmptyError",
{ projectId: ProjectId },
) {
override get message(): string {
return `Project ${this.projectId} is not empty.`;
}
}
/** A change the project's rules refuse, such as an invalid script ID: the caller's input is wrong, nothing failed. */
export class ProjectInvalidError extends Schema.TaggedError<ProjectInvalidError>()(
"ProjectInvalidError",
{ projectId: ProjectId, detail: Schema.String },
) {
override get message(): string {
return this.detail;
}
}
export class ProjectOperationError extends Schema.TaggedError<ProjectOperationError>()(
"ProjectOperationError",
{
operation: Schema.Literals([
"normalize-workspace",
"read-project",
"list-projects",
"list-threads",
"delete-thread",
"dispatch-project-command",
]),
projectId: Schema.optional(ProjectId),
workspaceRoot: Schema.optional(Schema.String),
cause: Schema.Defect(),
},
) {
override get message(): string {
return `Project operation '${this.operation}' failed${this.projectId === undefined ? "" : ` for ${this.projectId}`}.`;
}
}
export type ProjectServiceError =
| ProjectNotFoundError
| ProjectConflictError
| ProjectNotEmptyError
| ProjectInvalidError
| ProjectOperationError;
export class ProjectService extends Context.Service<
ProjectService,
{
readonly create: (input: ProjectCreateInput) => Effect.Effect<Project, ProjectServiceError>;
readonly bootstrap: (
input: ProjectBootstrapInput,
) => Effect.Effect<
{ readonly project: Project; readonly created: boolean },
ProjectServiceError
>;
readonly update: (input: ProjectUpdateInput) => Effect.Effect<Project, ProjectServiceError>;
readonly delete: (input: ProjectDeleteInput) => Effect.Effect<Project, ProjectServiceError>;
readonly getById: (
projectId: ProjectId,
options?: { readonly includeDeleted?: boolean },
) => Effect.Effect<Option.Option<Project>, ProjectOperationError>;
readonly getByWorkspaceRoot: (
workspaceRoot: string,
options?: { readonly includeDeleted?: boolean },
) => Effect.Effect<Option.Option<Project>, ProjectOperationError>;
/**
* Where to scan `cwd`'s workspace inventory. A thread's removed managed worktree scans its
* project, which turn start recreates the worktree from; anything else, or a failure, is `cwd`.
*/
readonly workspaceScanDirectory: (cwd: string) => Effect.Effect<string>;
readonly snapshot: Effect.Effect<ProjectSnapshot, ProjectOperationError>;
/**
* A page of active projects in creation order, each with its repository
* identity resolved, so a caller can match projects by repository.
*/
readonly listPage: (input: {
readonly cursor: number;
readonly limit: number;
}) => Effect.Effect<
{ readonly projects: ReadonlyArray<Project>; readonly nextCursor: number | null },
ProjectOperationError
>;
readonly getShell: (
projectId: ProjectId,
) => Effect.Effect<Option.Option<OrchestrationProjectShell>, ProjectOperationError>;
readonly listShells: (options?: {
readonly projectIds?: ReadonlyArray<ProjectId>;
}) => Effect.Effect<ReadonlyArray<OrchestrationProjectShell>, ProjectOperationError>;
}
>()("t3/project/ProjectService") {}
export const make = Effect.gen(function* () {
const projects = yield* ProjectStore.ProjectStoreV2;
const projectEnrichment = yield* ProjectEnrichmentService.ProjectEnrichmentService;
const workspacePaths = yield* WorkspacePaths.WorkspacePaths;
const threadProjections = yield* ProjectionStore.ProjectionStoreV2;
const eventSink = yield* EventSink.EventSinkV2;
const idAllocator = yield* IdAllocator.IdAllocatorV2;
const legacyImporter = yield* LegacyV1ThreadImporter.LegacyV1ThreadImporter;
const threadCommands = yield* ThreadCommandExecutor.ThreadCommandExecutor;
const serverSettings = yield* ServerSettings.ServerSettingsService;
const fileSystem = yield* FileSystem.FileSystem;
const isManagedWorktreePath = yield* makeIsManagedWorktreePath;
const projectLocks = yield* KeyedLock.make<ProjectId>();
const workspaceLocks = yield* KeyedLock.make<string>();
const toProject = (
row: ProjectStore.ProjectRow,
enrichment: ProjectEnrichmentService.ProjectEnrichment | null,
): Project => ({
id: row.projectId,
title: row.title,
workspaceRoot: row.workspaceRoot,
repositoryIdentity: enrichment?.repositoryIdentity ?? null,
faviconPath: row.faviconPath ?? enrichment?.faviconPath ?? null,
defaultModelSelection: row.defaultModelSelection,
defaultThreadEnvMode: row.defaultThreadEnvMode,
autoPull: row.autoPull,
projectIcon: row.projectIcon,
scripts: row.scripts,
pinnedAt: row.pinnedAt,
archivedAt: row.archivedAt,
createdAt: row.createdAt,
updatedAt: row.updatedAt,
deletedAt: row.deletedAt,
});
const hydrate = Effect.fn("ProjectService.hydrate")(function* (row: ProjectStore.ProjectRow) {
const enrichment =
row.deletedAt === null
? yield* projectEnrichment.getAvailable(row.workspaceRoot)
: yield* projectEnrichment.peek(row.workspaceRoot);
return toProject(row, enrichment);
});
const readRow = (projectId: ProjectId, options?: { readonly includeDeleted?: boolean }) =>
projects
.get(projectId, options)
.pipe(
Effect.mapError(
(cause) => new ProjectOperationError({ operation: "read-project", projectId, cause }),
),
);
const normalizeWorkspaceRoot = (input: {
readonly projectId?: ProjectId;
readonly workspaceRoot: string;
readonly createIfMissing?: boolean;
}) =>
workspacePaths
.normalizeWorkspaceRoot(input.workspaceRoot, {
createIfMissing: input.createIfMissing ?? false,
})
.pipe(
Effect.mapError(
(cause) =>
new ProjectOperationError({
operation: "normalize-workspace",
...(input.projectId === undefined ? {} : { projectId: input.projectId }),
workspaceRoot: input.workspaceRoot,
cause,
}),
),
);
const commit = Effect.fn("ProjectService.commit")(function* (command: ProjectCommand) {
const { projectId } = command;
const dispatchError = (cause: unknown) =>
new ProjectOperationError({ operation: "dispatch-project-command", projectId, cause });
const workspaceRoot = command.type === "project.delete" ? undefined : command.workspaceRoot;
const planAndCommit = Effect.gen(function* () {
const project = Option.getOrUndefined(yield* readRow(projectId, { includeDeleted: true }));
const workspaceOwner =
workspaceRoot === undefined
? undefined
: Option.getOrUndefined(
yield* projects
.findActiveByWorkspaceRoot(workspaceRoot)
.pipe(Effect.mapError(dispatchError)),
);
const now = yield* DateTime.now;
const eventId = yield* idAllocator.allocate
.event({ commandId: command.commandId })
.pipe(Effect.mapError(dispatchError));
const planned = planProjectCommand({
command,
state: { project, workspaceOwner },
eventId,
now,
});
if (Result.isSuccess(planned)) {
const { receipt } = yield* eventSink.commitProjectCommand({
commandId: command.commandId,
projectId,
commandType: command.type,
acceptedAt: now,
event: planned.success,
});
return receipt;
}
return yield* eventSink.commitRejectedProjectCommand({
commandId: command.commandId,
projectId,
commandType: command.type,
rejectedAt: now,
error: encodeProjectCommandRejection(planned.failure),
});
});
const receipt = yield* projectLocks
.withLock(
projectId,
workspaceRoot === undefined
? planAndCommit
: workspaceLocks.withLock(workspaceRoot, planAndCommit),
)
.pipe(Effect.mapError(dispatchError));
if (receipt.projectId !== projectId || receipt.commandType !== command.type) {
return yield* dispatchError(
`Command ${command.commandId} was already used by ${receipt.commandType} for ${receipt.projectId}.`,
);
}
// Retries re-plan against their own effects; the first receipt determines the outcome.
if (receipt.status === "accepted") return;
const rejection = Option.getOrUndefined(decodeProjectCommandRejection(receipt.error));
switch (rejection?._tag) {
case "ProjectWorkspaceConflictError":
return yield* new ProjectConflictError({
projectId,
workspaceRoot: rejection.workspaceRoot,
conflictingProjectId: rejection.conflictingProjectId,
});
case "ProjectCommandMissingProjectError":
return yield* new ProjectNotFoundError({ projectId });
case "ProjectCommandInvariantError":
return yield* new ProjectInvalidError({ projectId, detail: rejection.detail });
default:
return yield* dispatchError(
rejection ?? receipt.error ?? "The command was previously rejected.",
);
}
}, withCommandMetrics);
const readCommitted = Effect.fn("ProjectService.readCommitted")(function* (projectId: ProjectId) {
const row = yield* readRow(projectId, { includeDeleted: true });
if (Option.isNone(row)) {
return yield* new ProjectOperationError({
operation: "read-project",
projectId,
cause: "The accepted project command did not produce a project row.",
});
}
return yield* hydrate(row.value);
});
const getById: ProjectService["Service"]["getById"] = Effect.fn("ProjectService.getById")(
function* (projectId, options) {
const row = yield* readRow(projectId, options);
return Option.isNone(row) ? Option.none() : Option.some(yield* hydrate(row.value));
},
);
const workspaceScanDirectory = Effect.fn("ProjectService.workspaceScanDirectory")(
function* (cwd: string) {
if (yield* fileSystem.exists(cwd).pipe(Effect.orElseSucceed(() => true))) return cwd;
if (!(yield* isManagedWorktreePath(cwd))) return cwd;
const snapshot = yield* Effect.flatten(
threadProjections.readShellSnapshot({ worktreePath: cwd }),
);
const thread = [...snapshot.threads, ...snapshot.archivedThreads].find(
(candidate) => candidate.branch !== null,
);
if (thread === undefined) return cwd;
return Option.getOrUndefined(yield* readRow(thread.projectId))?.workspaceRoot ?? cwd;
},
(effect, cwd) => Effect.orElseSucceed(effect, () => cwd),
);
const getByWorkspaceRoot: ProjectService["Service"]["getByWorkspaceRoot"] = Effect.fn(
"ProjectService.getByWorkspaceRoot",
)(function* (workspaceRoot, options) {
const normalized = yield* normalizeWorkspaceRoot({ workspaceRoot });
const row = yield* (
options?.includeDeleted === true
? projects
.list({ includeDeleted: true })
.pipe(
Effect.map((rows) =>
Option.fromUndefinedOr(rows.find((row) => row.workspaceRoot === normalized)),
),
)
: projects.findActiveByWorkspaceRoot(normalized)
).pipe(
Effect.mapError((cause) => new ProjectOperationError({ operation: "list-projects", cause })),
);
return Option.isNone(row) ? Option.none() : Option.some(yield* hydrate(row.value));
});
const create: ProjectService["Service"]["create"] = Effect.fn("ProjectService.create")(
function* (input) {
const workspaceRoot = yield* normalizeWorkspaceRoot({
projectId: input.projectId,
workspaceRoot: input.workspaceRoot,
createIfMissing: input.createWorkspaceRootIfMissing ?? false,
});
yield* commit({
type: "project.create",
commandId: input.commandId,
projectId: input.projectId,
title: input.title,
workspaceRoot,
...(input.scripts === undefined ? {} : { scripts: input.scripts }),
});
yield* projectEnrichment.invalidate([workspaceRoot]);
return yield* readCommitted(input.projectId);
},
);
const update: ProjectService["Service"]["update"] = Effect.fn("ProjectService.update")(
function* (input) {
const existing = yield* readRow(input.projectId);
if (Option.isNone(existing)) {
return yield* new ProjectNotFoundError({ projectId: input.projectId });
}
const previousRoot = existing.value.workspaceRoot;
const workspaceRoot =
input.workspaceRoot === undefined
? previousRoot
: yield* normalizeWorkspaceRoot({
projectId: input.projectId,
workspaceRoot: input.workspaceRoot,
});
yield* commit({
type: "project.meta.update",
commandId: input.commandId,
projectId: input.projectId,
...(input.title === undefined ? {} : { title: input.title }),
...(workspaceRoot === previousRoot ? {} : { workspaceRoot }),
...(input.defaultModelSelection === undefined
? {}
: { defaultModelSelection: input.defaultModelSelection }),
...(input.autoPull === undefined ? {} : { autoPull: input.autoPull }),
...(input.projectIcon === undefined ? {} : { projectIcon: input.projectIcon }),
...(input.faviconPath === undefined ? {} : { faviconPath: input.faviconPath }),
...(input.defaultThreadEnvMode === undefined
? {}
: { defaultThreadEnvMode: input.defaultThreadEnvMode }),
...(input.scripts === undefined ? {} : { scripts: input.scripts }),
...(input.pinned === undefined ? {} : { pinned: input.pinned }),
...(input.archived === undefined ? {} : { archived: input.archived }),
});
if (workspaceRoot !== previousRoot) {
yield* projectEnrichment.invalidate([previousRoot, workspaceRoot]);
}
return yield* readCommitted(input.projectId);
},
);
const bootstrap: ProjectService["Service"]["bootstrap"] = Effect.fn("ProjectService.bootstrap")(
function* (input) {
const existing = yield* getByWorkspaceRoot(input.workspaceRoot);
if (Option.isSome(existing)) return { project: existing.value, created: false };
return { project: yield* create(input), created: true };
},
);
const deleteChildThread = Effect.fn("ProjectService.deleteChildThread")(function* (
input: ProjectDeleteInput,
threadId: ThreadId,
) {
yield* legacyImporter.ensureTranscript(threadId);
const projection = yield* threadProjections.getThreadRecords(threadId, [
"runs",
"attempts",
"nodes",
"runtimeRequests",
"subagents",
"providerSessions",
]);
if (projection.thread.deletedAt !== null || projection.thread.projectId !== input.projectId) {
return;
}
const command = {
type: "thread.delete" as const,
commandId: CommandId.make(`${input.commandId}:delete-thread:${threadId}`),
threadId,
};
const now = yield* DateTime.now;
const plan = yield* planThreadDeletion({
command,
projection,
attachmentIds: yield* threadProjections.getThreadAttachmentIds(threadId),
now,
idAllocator,
});
const committed = yield* eventSink.commitCommand({
commandId: command.commandId,
commandType: command.type,
threadId,
acceptedAt: now,
events: plan.events,
effects: plan.effects,
});
if (
committed.receipt.threadId !== command.threadId ||
committed.receipt.commandType !== command.type
) {
return yield* Effect.fail("The thread deletion command ID belongs to a different command.");
}
if (committed.receipt.status === "rejected") {
return yield* Effect.fail(
committed.receipt.error ?? "Thread deletion was previously rejected.",
);
}
});
const deleteChildThreads = Effect.fn("ProjectService.deleteChildThreads")(function* (
input: ProjectDeleteInput,
) {
const { projectId } = input;
const snapshot = yield* threadProjections
.getShellSnapshot({ projectId })
.pipe(
Effect.mapError(
(cause) => new ProjectOperationError({ operation: "list-threads", projectId, cause }),
),
);
const projectThreads = [...snapshot.threads, ...snapshot.archivedThreads];
if (projectThreads.length > 0 && input.force !== true) {
return yield* new ProjectNotEmptyError({ projectId });
}
// Delete children durably before the project so a failed cascade can be retried.
yield* Effect.forEach(
projectThreads,
(thread) =>
threadCommands
.withLock(thread.id, deleteChildThread(input, thread.id))
.pipe(
Effect.mapError(
(cause) =>
new ProjectOperationError({ operation: "delete-thread", projectId, cause }),
),
),
{ concurrency: 1, discard: true },
);
});
// Best-effort cleanup releases disabled instances kept alive by overrides; crashes have no replay to revisit deletion.
const clearProjectSettingsOverrides = (projectId: ProjectId) =>
serverSettings.updateSettings({ projectSettingsOverrides: { [projectId]: null } }).pipe(
Effect.asVoid,
Effect.catchCause((cause) =>
Effect.logWarning(
`Failed to clear settings overrides for deleted project ${projectId}.`,
cause,
),
),
);
const deleteProject: ProjectService["Service"]["delete"] = Effect.fn("ProjectService.delete")(
function* (input) {
const { projectId } = input;
// Read deleted rows so retries replay receipts and other command ids fail as not found.
const existing = yield* readRow(projectId, { includeDeleted: true });
if (Option.isNone(existing)) {
return yield* new ProjectNotFoundError({ projectId });
}
const isFirstDelete = existing.value.deletedAt === null;
if (isFirstDelete) {
yield* deleteChildThreads(input);
}
yield* commit({ type: "project.delete", commandId: input.commandId, projectId });
if (isFirstDelete) {
yield* clearProjectSettingsOverrides(projectId);
}
yield* projectEnrichment.invalidate([existing.value.workspaceRoot]);
return yield* readCommitted(projectId);
},
);
const enrichShell = (shell: OrchestrationProjectShell) =>
projectEnrichment.getAvailable(shell.workspaceRoot).pipe(
Effect.map((enrichment) => ({
...shell,
repositoryIdentity: enrichment.repositoryIdentity,
})),
);
const getShell: ProjectService["Service"]["getShell"] = Effect.fn("ProjectService.getShell")(
function* (projectId) {
const shell = yield* projects
.getShell(projectId)
.pipe(
Effect.mapError(
(cause) => new ProjectOperationError({ operation: "read-project", projectId, cause }),
),
);
return Option.isNone(shell) ? shell : Option.some(yield* enrichShell(shell.value));
},
);
const listShells: ProjectService["Service"]["listShells"] = Effect.fn(
"ProjectService.listShells",
)(function* (options) {
const shells = yield* projects
.listShells(options)
.pipe(
Effect.mapError(
(cause) => new ProjectOperationError({ operation: "list-projects", cause }),
),
);
return yield* Effect.forEach(shells, enrichShell, { concurrency: 16 });
});
const listRows = projects
.list()
.pipe(
Effect.mapError((cause) => new ProjectOperationError({ operation: "list-projects", cause })),
);
const snapshot = Effect.gen(function* () {
const rows = yield* listRows;
const hydrated = yield* Effect.forEach(rows, hydrate, { concurrency: 8 });
return {
projects: hydrated,
updatedAt: DateTime.formatIso(yield* DateTime.now),
} satisfies ProjectSnapshot;
});
const listPage: ProjectService["Service"]["listPage"] = Effect.fn("ProjectService.listPage")(
function* ({ cursor, limit }) {
const rows = (yield* listRows).filter((project) => project.deletedAt === null);
const projects = yield* Effect.forEach(
rows.slice(cursor, cursor + limit),
(row) =>
hydrate(row).pipe(
Effect.filterOrElse(
(project) => project.repositoryIdentity !== null,
(project) =>
projectEnrichment
.readRepositoryIdentity(project.workspaceRoot)
.pipe(Effect.map((repositoryIdentity) => ({ ...project, repositoryIdentity }))),
),
),
{ concurrency: 8 },
);
return { projects, nextCursor: cursor + limit < rows.length ? cursor + limit : null };
},
);
return ProjectService.of({
create,
bootstrap,
update,
delete: deleteProject,
getById,
getByWorkspaceRoot,
workspaceScanDirectory,
snapshot,
listPage,
getShell,
listShells,
});
});
export const layer = Layer.effect(ProjectService, make).pipe(
Layer.provide(ThreadCommandExecutor.layer),
);