Open History to see the last commit
1/**
2 * ProjectionSnapshotQuery - Read-model snapshot query service interface.
3 *
4 * Exposes the current orchestration projection snapshot for read-only API
5 * access.
6 *
7 * @module ProjectionSnapshotQuery
8 */
9import type {
10 OrchestrationCheckpointSummary,
11 OrchestrationProject,
12 OrchestrationProjectShell,
13 OrchestrationReadModel,
14 OrchestrationShellSnapshot,
15 OrchestrationThread,
16 OrchestrationThreadShell,
17 ProjectId,
18 ThreadId,
19} from "@t3tools/contracts";
20import { Context } from "effect";
21import type { Option } from "effect";
22import type { Effect } from "effect";
23
24import type { ProjectionRepositoryError } from "../../persistence/Errors.ts";
25
26export interface ProjectionSnapshotCounts {
27 readonly projectCount: number;
28 readonly threadCount: number;
29}
30
31export interface ProjectionThreadCheckpointContext {
32 readonly threadId: ThreadId;
33 readonly projectId: ProjectId;
34 readonly workspaceRoot: string;
35 readonly worktreePath: string | null;
36 readonly checkpoints: ReadonlyArray<OrchestrationCheckpointSummary>;
37}
38
39/**
40 * ProjectionSnapshotQueryShape - Service API for read-model snapshots.
41 */
42export interface ProjectionSnapshotQueryShape {
43 /**
44 * Read the latest orchestration projection snapshot.
45 *
46 * Rehydrates from projection tables and derives snapshot sequence from
47 * projector cursor state.
48 */
49 readonly getSnapshot: () => Effect.Effect<OrchestrationReadModel, ProjectionRepositoryError>;
50
51 /**
52 * Read the latest orchestration shell snapshot.
53 *
54 * Returns only projects and thread shell summaries so clients can bootstrap
55 * lightweight navigation state without hydrating every thread body.
56 */
57 readonly getShellSnapshot: () => Effect.Effect<
58 OrchestrationShellSnapshot,
59 ProjectionRepositoryError
60 >;
61
62 /**
63 * Read aggregate projection counts without hydrating the full read model.
64 */
65 readonly getCounts: () => Effect.Effect<ProjectionSnapshotCounts, ProjectionRepositoryError>;
66
67 /**
68 * Read the active project for an exact workspace root match.
69 */
70 readonly getActiveProjectByWorkspaceRoot: (
71 workspaceRoot: string,
72 ) => Effect.Effect<Option.Option<OrchestrationProject>, ProjectionRepositoryError>;
73
74 /**
75 * Read a single active project shell row by id.
76 */
77 readonly getProjectShellById: (
78 projectId: ProjectId,
79 ) => Effect.Effect<Option.Option<OrchestrationProjectShell>, ProjectionRepositoryError>;
80
81 /**
82 * Read the earliest active thread for a project.
83 */
84 readonly getFirstActiveThreadIdByProjectId: (
85 projectId: ProjectId,
86 ) => Effect.Effect<Option.Option<ThreadId>, ProjectionRepositoryError>;
87
88 /**
89 * Read the checkpoint context needed to resolve a single thread diff.
90 */
91 readonly getThreadCheckpointContext: (
92 threadId: ThreadId,
93 ) => Effect.Effect<Option.Option<ProjectionThreadCheckpointContext>, ProjectionRepositoryError>;
94
95 /**
96 * Read a single active thread shell row by id.
97 */
98 readonly getThreadShellById: (
99 threadId: ThreadId,
100 ) => Effect.Effect<Option.Option<OrchestrationThreadShell>, ProjectionRepositoryError>;
101
102 /**
103 * Read a single active thread detail snapshot by id.
104 */
105 readonly getThreadDetailById: (
106 threadId: ThreadId,
107 ) => Effect.Effect<Option.Option<OrchestrationThread>, ProjectionRepositoryError>;
108}
109
110/**
111 * ProjectionSnapshotQuery - Service tag for projection snapshot queries.
112 */
113export class ProjectionSnapshotQuery extends Context.Service<
114 ProjectionSnapshotQuery,
115 ProjectionSnapshotQueryShape
116>()("t3/orchestration/Services/ProjectionSnapshotQuery") {}