Skip to content

Commit edf5dee

Browse files
xesrevinuGit Agent
andcommitted
refactor(domain): migrate schemas to effect
- Introduced Trailer schema and new commit domain types - Reworked project config to use effect-based schemas domain changes introduce effect-based schemas for commits and projects, updating types and validation Co-Authored-By: Git Agent <noreply@git-agent.dev>
1 parent 41c0639 commit edf5dee

2 files changed

Lines changed: 60 additions & 37 deletions

File tree

src/domain/commit.ts

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
export interface Trailer {
2-
readonly key: string;
3-
readonly value: string;
4-
}
1+
import { Schema } from "effect";
2+
3+
export const Trailer = Schema.Struct({
4+
key: Schema.String,
5+
value: Schema.String,
6+
});
7+
8+
export type Trailer = typeof Trailer.Type;
59

610
export const parseTrailerText = (input: string): Trailer | undefined => {
711
const separator = ": ";
@@ -22,28 +26,40 @@ export const parseTrailerText = (input: string): Trailer | undefined => {
2226
};
2327
};
2428

25-
export interface CommitMessage {
26-
readonly title: string;
27-
readonly bullets: ReadonlyArray<string>;
28-
readonly explanation: string;
29-
}
30-
31-
export interface CommitGroup {
32-
readonly files: ReadonlyArray<string>;
33-
readonly message: CommitMessage | undefined;
34-
}
35-
36-
export interface CommitPlan {
37-
readonly groups: ReadonlyArray<CommitGroup>;
38-
}
39-
40-
export interface SingleCommitResult {
41-
readonly title: string;
42-
readonly bullets: ReadonlyArray<string>;
43-
readonly explanation: string;
44-
readonly files: ReadonlyArray<string>;
45-
readonly output: string | undefined;
46-
}
29+
export const CommitMessage = Schema.Struct({
30+
title: Schema.String,
31+
bullets: Schema.Array(Schema.String),
32+
explanation: Schema.String,
33+
});
34+
35+
export type CommitMessage = typeof CommitMessage.Type;
36+
37+
export const CommitGroup = Schema.Struct({
38+
files: Schema.Array(Schema.String),
39+
message: CommitMessage.pipe(Schema.UndefinedOr),
40+
});
41+
42+
export type CommitGroup = typeof CommitGroup.Type;
43+
44+
export const CommitPlan = Schema.Struct({
45+
groups: Schema.Array(CommitGroup),
46+
});
47+
48+
export type CommitPlan = typeof CommitPlan.Type;
49+
50+
export const SingleCommitResult = Schema.Struct({
51+
title: Schema.String,
52+
bullets: Schema.Array(Schema.String),
53+
explanation: Schema.String,
54+
files: Schema.Array(Schema.String),
55+
output: Schema.String.pipe(Schema.UndefinedOr),
56+
});
57+
58+
export type SingleCommitResult = typeof SingleCommitResult.Type;
59+
60+
export const CommitResponse = Schema.Array(SingleCommitResult);
61+
62+
export type CommitResponse = typeof CommitResponse.Type;
4763

4864
export const renderCommitBody = (message: CommitMessage): string => {
4965
const bulletSection = message.bullets.map((bullet) => `- ${bullet}`).join("\n");

src/domain/project.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1-
export interface ProjectScope {
2-
readonly name: string;
3-
readonly description?: string;
4-
}
1+
import { Schema, SchemaTransformation } from "effect";
52

6-
export interface ProjectConfig {
7-
readonly scopes: ReadonlyArray<ProjectScope>;
8-
readonly hooks: ReadonlyArray<string>;
9-
readonly maxDiffLines: number;
10-
readonly noGitAgentCoAuthor: boolean;
11-
readonly noModelCoAuthor: boolean;
12-
}
3+
const TrimmedString = Schema.String.pipe(Schema.decode(SchemaTransformation.trim()));
4+
const NonEmptyTrimmedString = TrimmedString.check(Schema.isNonEmpty());
5+
6+
export class ProjectScope extends Schema.Class<ProjectScope>("ProjectScope")({
7+
name: NonEmptyTrimmedString,
8+
description: Schema.optionalKey(NonEmptyTrimmedString),
9+
}) {}
10+
11+
export const ProjectConfig = Schema.Struct({
12+
scopes: Schema.Array(ProjectScope),
13+
hooks: Schema.Array(NonEmptyTrimmedString),
14+
maxDiffLines: Schema.Int,
15+
noGitAgentCoAuthor: Schema.Boolean,
16+
noModelCoAuthor: Schema.Boolean,
17+
});
18+
19+
export type ProjectConfig = typeof ProjectConfig.Type;
1320

1421
export const emptyProjectConfig = (): ProjectConfig => ({
1522
scopes: [],

0 commit comments

Comments
 (0)