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

CheckpointStore.ts

101 lines3.0 KB

1/**
2 * CheckpointStore - Repository interface for filesystem-backed workspace checkpoints.
3 *
4 * Owns hidden Git-ref checkpoint capture/restore and diff computation for a
5 * workspace thread timeline. It does not store user-facing checkpoint metadata
6 * and does not coordinate provider conversation rollback.
7 *
8 * Uses Effect `Context.Service` for dependency injection and exposes typed
9 * domain errors for checkpoint storage operations.
10 *
11 * @module CheckpointStore
12 */
13import { Context } from "effect";
14import type { Effect } from "effect";
15​
16import type { CheckpointStoreError } from "../Errors.ts";
17import { CheckpointRef } from "@t3tools/contracts";
18​
19export interface CaptureCheckpointInput {
20 readonly cwd: string;
21 readonly checkpointRef: CheckpointRef;
23​
24export interface RestoreCheckpointInput {
25 readonly cwd: string;
26 readonly checkpointRef: CheckpointRef;
27 readonly fallbackToHead?: boolean;
29​
30export interface DiffCheckpointsInput {
31 readonly cwd: string;
32 readonly fromCheckpointRef: CheckpointRef;
33 readonly toCheckpointRef: CheckpointRef;
34 readonly fallbackFromToHead?: boolean;
35 readonly ignoreWhitespace: boolean;
37​
38export interface DeleteCheckpointRefsInput {
39 readonly cwd: string;
40 readonly checkpointRefs: ReadonlyArray<CheckpointRef>;
42​
43/**
44 * CheckpointStoreShape - Service API for checkpoint capture/restore and diff access.
45 */
46export interface CheckpointStoreShape {
47 /**
48 * Check whether cwd is inside a Git worktree.
49 */
50 readonly isGitRepository: (cwd: string) => Effect.Effect<boolean, CheckpointStoreError>;
51​
52 /**
53 * Capture a checkpoint commit and store it at the provided checkpoint ref.
54 *
55 * Uses an isolated temporary Git index and writes a hidden ref.
56 */
57 readonly captureCheckpoint: (
58 input: CaptureCheckpointInput,
59 ) => Effect.Effect<void, CheckpointStoreError>;
60​
61 /**
62 * Check whether a checkpoint ref exists.
63 */
64 readonly hasCheckpointRef: (
65 input: Omit<RestoreCheckpointInput, "fallbackToHead">,
66 ) => Effect.Effect<boolean, CheckpointStoreError>;
67​
68 /**
69 * Restore workspace/staging state to a checkpoint.
70 *
71 * Optionally falls back to current `HEAD` when the checkpoint ref is missing.
72 */
73 readonly restoreCheckpoint: (
74 input: RestoreCheckpointInput,
75 ) => Effect.Effect<boolean, CheckpointStoreError>;
76​
77 /**
78 * Compute patch diff between two checkpoint refs.
79 *
80 * Can optionally treat missing "from" ref as `HEAD`.
81 */
82 readonly diffCheckpoints: (
83 input: DiffCheckpointsInput,
84 ) => Effect.Effect<string, CheckpointStoreError>;
85​
86 /**
87 * Delete the provided checkpoint refs.
88 *
89 * Best-effort delete: missing refs are tolerated.
90 */
91 readonly deleteCheckpointRefs: (
92 input: DeleteCheckpointRefsInput,
93 ) => Effect.Effect<void, CheckpointStoreError>;
95​
96/**
97 * CheckpointStore - Service tag for checkpoint persistence and restore operations.
98 */
99export class CheckpointStore extends Context.Service<CheckpointStore, CheckpointStoreShape>()(
100 "t3/checkpointing/Services/CheckpointStore",
101) {}