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 ProjectionSnapshotSequence {
32 readonly snapshotSequence: number;
33}
34
35export interface ProjectionThreadCheckpointContext {
36 readonly threadId: ThreadId;
37 readonly projectId: ProjectId;
38 readonly workspaceRoot: string;
39 readonly worktreePath: string | null;
40 readonly checkpoints: ReadonlyArray<OrchestrationCheckpointSummary>;
41}
42
43/**
44 * ProjectionSnapshotQueryShape - Service API for read-model snapshots.
45 */
46export interface ProjectionSnapshotQueryShape {
47 /**
48 * Read the lightweight command snapshot used to bootstrap the in-memory
49 * orchestration engine without hydrating message/activity/checkpoint bodies.
50 */
51 readonly getCommandReadModel: () => Effect.Effect<
52 OrchestrationReadModel,
53 ProjectionRepositoryError
54 >;
55
56 /**
57 * Read the latest orchestration projection snapshot.
58 *
59 * Rehydrates from projection tables and derives snapshot sequence from
60 * projector cursor state.
61 */
62 readonly getSnapshot: () => Effect.Effect<OrchestrationReadModel, ProjectionRepositoryError>;
63
64 /**
65 * Read the latest orchestration shell snapshot.
66 *
67 * Returns only projects and thread shell summaries so clients can bootstrap
68 * lightweight navigation state without hydrating every thread body.
69 */
70 readonly getShellSnapshot: () => Effect.Effect<
71 OrchestrationShellSnapshot,
72 ProjectionRepositoryError
73 >;
74
75 /**
76 * Read the latest projection snapshot sequence without hydrating read-model
77 * entities.
78 */
79 readonly getSnapshotSequence: () => Effect.Effect<
80 ProjectionSnapshotSequence,
81 ProjectionRepositoryError
82 >;
83
84 /**
85 * Read aggregate projection counts without hydrating the full read model.
86 */
87 readonly getCounts: () => Effect.Effect<ProjectionSnapshotCounts, ProjectionRepositoryError>;
88
89 /**
90 * Read the active project for an exact workspace root match.
91 */
92 readonly getActiveProjectByWorkspaceRoot: (
93 workspaceRoot: string,
94 ) => Effect.Effect<Option.Option<OrchestrationProject>, ProjectionRepositoryError>;
95
96 /**
97 * Read a single active project shell row by id.
98 */
99 readonly getProjectShellById: (
100 projectId: ProjectId,
101 ) => Effect.Effect<Option.Option<OrchestrationProjectShell>, ProjectionRepositoryError>;
102
103 /**
104 * Read the earliest active thread for a project.
105 */
106 readonly getFirstActiveThreadIdByProjectId: (
107 projectId: ProjectId,
108 ) => Effect.Effect<Option.Option<ThreadId>, ProjectionRepositoryError>;
109
110 /**
111 * Read the checkpoint context needed to resolve a single thread diff.
112 */
113 readonly getThreadCheckpointContext: (
114 threadId: ThreadId,
115 ) => Effect.Effect<Option.Option<ProjectionThreadCheckpointContext>, ProjectionRepositoryError>;
116
117 /**
118 * Read a single active thread shell row by id.
119 */
120 readonly getThreadShellById: (
121 threadId: ThreadId,
122 ) => Effect.Effect<Option.Option<OrchestrationThreadShell>, ProjectionRepositoryError>;
123
124 /**
125 * Read a single active thread detail snapshot by id.
126 */
127 readonly getThreadDetailById: (
128 threadId: ThreadId,
129 ) => Effect.Effect<Option.Option<OrchestrationThread>, ProjectionRepositoryError>;
130}
131
132/**
133 * ProjectionSnapshotQuery - Service tag for projection snapshot queries.
134 */
135export class ProjectionSnapshotQuery extends Context.Service<
136 ProjectionSnapshotQuery,
137 ProjectionSnapshotQueryShape
138>()("t3/orchestration/Services/ProjectionSnapshotQuery") {}