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

GitManager.ts

104 lines3.1 KB

1/**
2 * GitManager - Effect service contract for stacked Git workflows.
3 *
4 * Orchestrates status inspection and commit/push/PR flows by composing
5 * lower-level Git and external tool services.
6 *
7 * @module GitManager
8 */
9import {
10 GitActionProgressEvent,
11 GitPreparePullRequestThreadInput,
12 GitPreparePullRequestThreadResult,
13 GitPullRequestRefInput,
14 GitResolvePullRequestResult,
15 GitRunStackedActionInput,
16 GitRunStackedActionResult,
17 GitStatusLocalResult,
18 GitStatusRemoteResult,
19 GitStatusInput,
20 GitStatusResult,
21} from "@t3tools/contracts";
22import { ServiceMap } from "effect";
23import type { Effect } from "effect";
24import type { GitManagerServiceError } from "@t3tools/contracts";
25​
26export interface GitActionProgressReporter {
27 readonly publish: (event: GitActionProgressEvent) => Effect.Effect<void, never>;
29​
30export interface GitRunStackedActionOptions {
31 readonly actionId?: string;
32 readonly progressReporter?: GitActionProgressReporter;
34​
35/**
36 * GitManagerShape - Service API for high-level Git workflow actions.
37 */
38export interface GitManagerShape {
39 /**
40 * Read current repository Git status plus open PR metadata when available.
41 */
42 readonly status: (
43 input: GitStatusInput,
44 ) => Effect.Effect<GitStatusResult, GitManagerServiceError>;
45​
46 /**
47 * Read local repository status without remote hosting enrichment.
48 */
49 readonly localStatus: (
50 input: GitStatusInput,
51 ) => Effect.Effect<GitStatusLocalResult, GitManagerServiceError>;
52​
53 /**
54 * Read remote tracking / PR status for a repository.
55 */
56 readonly remoteStatus: (
57 input: GitStatusInput,
58 ) => Effect.Effect<GitStatusRemoteResult | null, GitManagerServiceError>;
59​
60 /**
61 * Clear any cached local status snapshot for a repository.
62 */
63 readonly invalidateLocalStatus: (cwd: string) => Effect.Effect<void, never>;
64​
65 /**
66 * Clear any cached remote status snapshot for a repository.
67 */
68 readonly invalidateRemoteStatus: (cwd: string) => Effect.Effect<void, never>;
69​
70 /**
71 * Clear any cached status snapshot for a repository so the next read is fresh.
72 */
73 readonly invalidateStatus: (cwd: string) => Effect.Effect<void, never>;
74​
75 /**
76 * Resolve a pull request by URL/number against the current repository.
77 */
78 readonly resolvePullRequest: (
79 input: GitPullRequestRefInput,
80 ) => Effect.Effect<GitResolvePullRequestResult, GitManagerServiceError>;
81​
82 /**
83 * Prepare a new thread workspace from a pull request in local or worktree mode.
84 */
85 readonly preparePullRequestThread: (
86 input: GitPreparePullRequestThreadInput,
87 ) => Effect.Effect<GitPreparePullRequestThreadResult, GitManagerServiceError>;
88​
89 /**
90 * Run a Git action (`commit`, `push`, `create_pr`, `commit_push`, `commit_push_pr`).
91 * When `featureBranch` is set, creates and checks out a feature branch first.
92 */
93 readonly runStackedAction: (
94 input: GitRunStackedActionInput,
95 options?: GitRunStackedActionOptions,
96 ) => Effect.Effect<GitRunStackedActionResult, GitManagerServiceError>;
98​
99/**
100 * GitManager - Service tag for stacked Git workflow orchestration.
101 */
102export class GitManager extends ServiceMap.Service<GitManager, GitManagerShape>()(
103 "t3/git/Services/GitManager",
104) {}