11import { Console , Effect , FileSystem } from "effect" ;
22import { Command , Flag } from "effect/unstable/cli" ;
3- import {
4- localConfigPath ,
5- mergeScopes ,
6- projectConfigWritePath ,
7- writeProjectField ,
8- } from "../config/project.ts" ;
9- import { resolveProviderConfig } from "../config/provider.ts" ;
3+ import { ConfigService } from "../config/service.ts" ;
104import { emptyProjectConfig } from "../domain/project.ts" ;
115import { GitignoreService } from "../services/gitignore-service.ts" ;
126import { ScopeService } from "../services/scope-service.ts" ;
@@ -17,7 +11,6 @@ import {
1711 apiKeyFlag ,
1812 baseUrlFlag ,
1913 cwdFlag ,
20- freeFlag ,
2114 modelFlag ,
2215 toOptionalString ,
2316 vcsFlag ,
@@ -31,7 +24,6 @@ export const commandInit = Command.make(
3124 apiKey : apiKeyFlag ,
3225 baseUrl : baseUrlFlag ,
3326 model : modelFlag ,
34- free : freeFlag ,
3527 scope : Flag . boolean ( "scope" ) . pipe ( Flag . withDescription ( "Generate scopes via AI." ) ) ,
3628 gitignore : Flag . boolean ( "gitignore" ) . pipe ( Flag . withDescription ( "Generate .gitignore via AI." ) ) ,
3729 force : Flag . boolean ( "force" ) . pipe (
@@ -42,14 +34,15 @@ export const commandInit = Command.make(
4234 Flag . withDescription ( "Maximum commit count to analyze for scopes." ) ,
4335 ) ,
4436 local : Flag . boolean ( "local" ) . pipe (
45- Flag . withDescription ( "Write config to .ai-commit/config.local.yml ." ) ,
37+ Flag . withDescription ( "Write config to .ai-commit/config.local.json ." ) ,
4638 ) ,
4739 hook : Flag . string ( "hook" ) . pipe (
4840 Flag . withDescription ( "Hook to configure. Repeat the flag or use comma-separated values." ) ,
4941 Flag . between ( 0 , Number . MAX_SAFE_INTEGER ) ,
5042 ) ,
5143 } ,
5244 Effect . fn ( "Command.Init" ) ( function * ( input ) {
45+ const configService = yield * ConfigService ;
5346 yield * Effect . annotateCurrentSpan ( {
5447 force : input . force ,
5548 gitignore : input . gitignore ,
@@ -88,10 +81,10 @@ export const commandInit = Command.make(
8881 }
8982
9083 const configPath = yield * input . local
91- ? localConfigPath ( repoRoot )
92- : projectConfigWritePath ( repoRoot ) ;
84+ ? configService . localConfigPath ( repoRoot )
85+ : configService . projectConfigPath ( repoRoot ) ;
9386
94- if ( ! input . force ) {
87+ if ( fullWizard && ! input . force ) {
9588 const exists = yield * fs . exists ( configPath ) ;
9689 if ( exists ) {
9790 return yield * new ConfigError ( {
@@ -100,7 +93,7 @@ export const commandInit = Command.make(
10093 }
10194 }
10295
103- const provider = yield * resolveProviderConfig ( {
96+ const provider = yield * configService . resolveProviderConfig ( {
10497 cwd : input . cwd ,
10598 vcs : vcsKind ,
10699 apiKey : toOptionalString ( input . apiKey ) ,
@@ -111,7 +104,7 @@ export const commandInit = Command.make(
111104 if ( ( doGitignore || doScope || fullWizard ) && provider . apiKey . length === 0 ) {
112105 return yield * new ConfigError ( {
113106 message :
114- "no API key configured (hint: set --api-key or add api_key to ~/.config/ai-commit/config.yml )" ,
107+ "no API key configured (hint: set --api-key or add api_key to ~/.config/ai-commit/config.json )" ,
115108 } ) ;
116109 }
117110
@@ -134,24 +127,24 @@ export const commandInit = Command.make(
134127 cwd : repoRoot ,
135128 maxCommits : input . maxCommits ,
136129 } ) ;
137- yield * mergeScopes ( configPath , scopes ) ;
130+ yield * configService . mergeScopes ( configPath , scopes ) ;
138131 yield * Console . log ( `scopes written to ${ configPath } ` ) ;
139132 }
140133
141134 if ( fullWizard ) {
142135 yield * Effect . withSpan (
143- writeProjectField ( configPath , "hook" , "conventional" ) ,
136+ configService . writeProjectField ( configPath , "hook" , "conventional" ) ,
144137 "Init.WriteDefaultHook" ,
145138 ) ;
146139 } else if ( hooks . length > 0 ) {
147140 yield * Effect . withSpan (
148- writeProjectField ( configPath , "hook" , hooks . join ( "," ) ) ,
141+ configService . writeProjectField ( configPath , "hook" , hooks . join ( "," ) ) ,
149142 "Init.WriteHook" ,
150143 ) ;
151144 }
152145
153146 if ( ! doScope && ! doGitignore && ! fullWizard && hooks . length > 0 ) {
154- yield * mergeScopes ( configPath , emptyProjectConfig ( ) . scopes ) ;
147+ yield * configService . mergeScopes ( configPath , emptyProjectConfig ( ) . scopes ) ;
155148 }
156149 } ) ,
157150) . pipe ( Command . withDescription ( "Initialize ai-commit in the current repository." ) ) ;
0 commit comments