Skip to content

Commit 1ea474c

Browse files
xesrevinuGit Agent
andcommitted
feat(cli): refactor service composition
- Replaced direct service runs with layered Live services in CLI - Use CommitService instead of runCommitService - Use HookService instead of installHookValue - Instantiate GitignoreService and ScopeService in init - Wire new services into combined ServicesLive and Live refactors the CLI wiring to compose services in layered live environments, updating command code to use new service entries and providers. Co-Authored-By: Git Agent <noreply@git-agent.dev>
1 parent 3646c2a commit 1ea474c

4 files changed

Lines changed: 50 additions & 13 deletions

File tree

src/cli.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,40 @@ import { CliError, Command } from "effect/unstable/cli";
55
import * as FetchHttpClient from "effect/unstable/http/FetchHttpClient";
66
import PackageJson from "../package.json" with { type: "json" };
77
import { commandRoot } from "./commands/root.ts";
8+
import { CommitLlmServicesLive, CommitServiceLive } from "./services/commit-service.ts";
9+
import { GitignoreServiceLive } from "./services/gitignore-service.ts";
10+
import { HookServiceLive } from "./services/hooks.ts";
11+
import { LlmClientLive } from "./services/openai-client.ts";
12+
import { ScopeServiceLive } from "./services/scope-service.ts";
813
import { VcsLive } from "./services/vcs.ts";
914
import { renderError } from "./shared/errors.ts";
1015
import { gitAgentProgressRenderConfig } from "./shared/progress-config.ts";
1116
import { makeProgressLayer } from "./shared/tracing.ts";
1217

13-
const Live = Layer.mergeAll(
14-
NodeServices.layer,
15-
FetchHttpClient.layer,
16-
VcsLive.pipe(Layer.provide(NodeServices.layer)),
18+
const PlatformLive = Layer.mergeAll(NodeServices.layer, FetchHttpClient.layer);
19+
20+
const CoreServicesLive = Layer.mergeAll(VcsLive, HookServiceLive, LlmClientLive).pipe(
21+
Layer.provideMerge(PlatformLive),
22+
);
23+
24+
const FeatureServicesLive = Layer.mergeAll(
25+
CommitLlmServicesLive,
26+
ScopeServiceLive,
27+
GitignoreServiceLive,
28+
).pipe(Layer.provideMerge(CoreServicesLive));
29+
30+
const CommitRuntimeLive = CommitServiceLive.pipe(
31+
Layer.provideMerge(Layer.mergeAll(CoreServicesLive, FeatureServicesLive)),
32+
);
33+
34+
const ServicesLive = Layer.mergeAll(
35+
CoreServicesLive,
36+
FeatureServicesLive,
37+
CommitRuntimeLive,
1738
makeProgressLayer(gitAgentProgressRenderConfig),
18-
).pipe(Layer.provide(ConfigProvider.layer(ConfigProvider.fromEnv())));
39+
);
40+
41+
const Live = ServicesLive.pipe(Layer.provide(ConfigProvider.layer(ConfigProvider.fromEnv())));
1942

2043
const program = Command.run(commandRoot, {
2144
version: PackageJson.version,

src/commands/commit.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { loadProjectConfig } from "../config/project.ts";
44
import { resolveProviderConfig } from "../config/provider.ts";
55
import { parseTrailerText, type Trailer } from "../domain/commit.ts";
66
import { emptyProjectConfig } from "../domain/project.ts";
7-
import { runCommitService } from "../services/commit-service.ts";
7+
import { CommitService } from "../services/commit-service.ts";
88
import { Vcs } from "../services/vcs.ts";
99
import { ConfigError } from "../shared/errors.ts";
1010
import { printCommitResult, printDryRunResult } from "../shared/output.ts";
@@ -144,7 +144,8 @@ export const commandCommit = Command.make(
144144
provider.noModelCoAuthor || projectConfig.noModelCoAuthor,
145145
);
146146

147-
const commits = yield* runCommitService({
147+
const commitService = yield* CommitService;
148+
const commits = yield* commitService.run({
148149
cwd: repoRoot,
149150
provider,
150151
vcs,

src/commands/config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
writeUserField,
1818
} from "../config/provider.ts";
1919
import { localConfigPath, projectConfigWritePath, writeProjectField } from "../config/project.ts";
20-
import { installHookValue } from "../services/hooks.ts";
20+
import { HookService } from "../services/hooks.ts";
2121
import { Vcs } from "../services/vcs.ts";
2222
import {
2323
apiKeyFlag,
@@ -124,7 +124,8 @@ const configSet = Command.make(
124124
const vcsService = yield* Vcs;
125125
const { client: vcs } = yield* vcsService.resolve(input.cwd, toOptionalString(input.vcs));
126126
const repoRoot = yield* vcs.repoRoot(input.cwd);
127-
const prepared = yield* installHookValue(repoRoot, key, value);
127+
const hookService = yield* HookService;
128+
const prepared = yield* hookService.installValue(repoRoot, key, value);
128129
if (prepared.installedFrom != null) {
129130
yield* Console.log(`installed hook: ${prepared.installedFrom}`);
130131
}

src/commands/init.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {
88
} from "../config/project.ts";
99
import { resolveProviderConfig } from "../config/provider.ts";
1010
import { emptyProjectConfig } from "../domain/project.ts";
11-
import { generateGitignore } from "../services/gitignore-service.ts";
12-
import { generateProjectScopes } from "../services/scope-service.ts";
11+
import { GitignoreService } from "../services/gitignore-service.ts";
12+
import { ScopeService } from "../services/scope-service.ts";
1313
import { Vcs } from "../services/vcs.ts";
1414
import { ConfigError } from "../shared/errors.ts";
1515
import { parseCsvValues } from "../shared/text.ts";
@@ -115,13 +115,25 @@ export const commandInit = Command.make(
115115
});
116116
}
117117

118+
const gitignoreService = yield* GitignoreService;
119+
const scopeService = yield* ScopeService;
120+
118121
if (doGitignore || fullWizard) {
119-
const techs = yield* generateGitignore(provider, vcs, repoRoot);
122+
const techs = yield* gitignoreService.generateGitignore({
123+
provider,
124+
vcs,
125+
cwd: repoRoot,
126+
});
120127
yield* Console.log(`.gitignore updated: ${techs.join(", ")}`);
121128
}
122129

123130
if (doScope || fullWizard) {
124-
const scopes = yield* generateProjectScopes(provider, vcs, repoRoot, input.maxCommits);
131+
const scopes = yield* scopeService.generateProjectScopes({
132+
provider,
133+
vcs,
134+
cwd: repoRoot,
135+
maxCommits: input.maxCommits,
136+
});
125137
yield* mergeScopes(configPath, scopes);
126138
yield* Console.log(`scopes written to ${configPath}`);
127139
}

0 commit comments

Comments
 (0)