The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import * as Context from "effect/Context"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | |
| 4 | import type { |
| 5 | VcsError, |
| 6 | VcsInitInput, |
| 7 | VcsListRemotesResult, |
| 8 | VcsListWorkspaceFilesResult, |
| 9 | VcsRepositoryIdentity, |
| 10 | } from "@t3tools/contracts"; |
| 11 | import { CheckpointRef } from "@t3tools/contracts"; |
| 12 | import * as VcsProcess from "./VcsProcess.ts"; |
| 13 | |
| 14 | export interface VcsCaptureCheckpointInput { |
| 15 | readonly cwd: string; |
| 16 | readonly checkpointRef: CheckpointRef; |
| 17 | /** The checkpoint this one follows, so a turn that switched branches starts where it landed. */ |
| 18 | readonly previousCheckpointRef?: CheckpointRef; |
| 19 | } |
| 20 | |
| 21 | export interface VcsRestoreCheckpointInput { |
| 22 | readonly cwd: string; |
| 23 | readonly checkpointRef: CheckpointRef; |
| 24 | readonly fallbackToHead?: boolean; |
| 25 | } |
| 26 | |
| 27 | export const CHECKPOINT_DIFF_MAX_OUTPUT_BYTES = 10_000_000; |
| 28 | |
| 29 | export interface VcsDiffCheckpointsInput { |
| 30 | readonly cwd: string; |
| 31 | readonly fromCheckpointRef: CheckpointRef; |
| 32 | readonly toCheckpointRef: CheckpointRef; |
| 33 | readonly fallbackFromToHead?: boolean; |
| 34 | readonly ignoreWhitespace: boolean; |
| 35 | readonly format?: "patch" | "numstat"; |
| 36 | /** Maximum bytes collected from the diff command. */ |
| 37 | readonly maxOutputBytes?: number; |
| 38 | /** An empty list yields an empty diff. */ |
| 39 | readonly filePaths?: ReadonlyArray<string>; |
| 40 | } |
| 41 | |
| 42 | export interface VcsListAuthoredPathsInput { |
| 43 | readonly cwd: string; |
| 44 | readonly fromCheckpointRef: CheckpointRef; |
| 45 | readonly toCheckpointRef: CheckpointRef; |
| 46 | } |
| 47 | |
| 48 | export interface VcsDeleteCheckpointRefsInput { |
| 49 | readonly cwd: string; |
| 50 | readonly checkpointRefs: ReadonlyArray<CheckpointRef>; |
| 51 | } |
| 52 | |
| 53 | export interface VcsCheckpointOps { |
| 54 | readonly captureCheckpoint: (input: VcsCaptureCheckpointInput) => Effect.Effect<void, VcsError>; |
| 55 | readonly hasCheckpointRef: ( |
| 56 | input: Omit<VcsRestoreCheckpointInput, "fallbackToHead">, |
| 57 | ) => Effect.Effect<boolean, VcsError>; |
| 58 | readonly restoreCheckpoint: ( |
| 59 | input: VcsRestoreCheckpointInput, |
| 60 | ) => Effect.Effect<boolean, VcsError>; |
| 61 | readonly diffCheckpoints: (input: VcsDiffCheckpointsInput) => Effect.Effect<string, VcsError>; |
| 62 | readonly listAuthoredPaths: ( |
| 63 | input: VcsListAuthoredPathsInput, |
| 64 | ) => Effect.Effect<ReadonlySet<string> | null, VcsError>; |
| 65 | readonly deleteCheckpointRefs: ( |
| 66 | input: VcsDeleteCheckpointRefsInput, |
| 67 | ) => Effect.Effect<void, VcsError>; |
| 68 | } |
| 69 | |
| 70 | export class VcsDriver extends Context.Service< |
| 71 | VcsDriver, |
| 72 | { |
| 73 | readonly execute: ( |
| 74 | input: Omit<VcsProcess.VcsProcessInput, "command">, |
| 75 | ) => Effect.Effect<VcsProcess.VcsProcessOutput, VcsError>; |
| 76 | readonly checkpoints: VcsCheckpointOps; |
| 77 | readonly detectRepository: ( |
| 78 | cwd: string, |
| 79 | ) => Effect.Effect<VcsRepositoryIdentity | null, VcsError>; |
| 80 | readonly isInsideWorkTree: (cwd: string) => Effect.Effect<boolean, VcsError>; |
| 81 | readonly listWorkspaceFiles: ( |
| 82 | cwd: string, |
| 83 | ) => Effect.Effect<VcsListWorkspaceFilesResult, VcsError>; |
| 84 | readonly listRemotes: (cwd: string) => Effect.Effect<VcsListRemotesResult, VcsError>; |
| 85 | readonly filterIgnoredPaths: ( |
| 86 | cwd: string, |
| 87 | relativePaths: ReadonlyArray<string>, |
| 88 | ) => Effect.Effect<ReadonlyArray<string>, VcsError>; |
| 89 | readonly initRepository: (input: VcsInitInput) => Effect.Effect<void, VcsError>; |
| 90 | } |
| 91 | >()("t3/vcs/VcsDriver") {} |