@@ -11,6 +11,7 @@ import { resolveProviderConfig } from "../config/provider";
1111import { emptyProjectConfig } from "../domain/project" ;
1212import { ConfigError } from "../shared/errors" ;
1313import { parseCsvValues } from "../shared/text" ;
14+ import { withProgressSpan } from "../shared/tracing" ;
1415import { generateGitignore } from "../services/gitignore-service" ;
1516import { generateProjectScopes } from "../services/scope-service" ;
1617import { detectVcs , getVcsClient } from "../services/vcs" ;
@@ -24,40 +25,20 @@ import {
2425 vcsFlag ,
2526} from "./shared" ;
2627
27- export const commandInit = Command . make (
28- "init" ,
29- {
30- cwd : cwdFlag ,
31- vcs : vcsFlag ,
32- apiKey : apiKeyFlag ,
33- baseUrl : baseUrlFlag ,
34- model : modelFlag ,
35- free : freeFlag ,
36- scope : Flag . boolean ( "scope" ) . pipe ( Flag . withDescription ( "Generate scopes via AI." ) ) ,
37- gitignore : Flag . boolean ( "gitignore" ) . pipe ( Flag . withDescription ( "Generate .gitignore via AI." ) ) ,
38- force : Flag . boolean ( "force" ) . pipe (
39- Flag . withDescription ( "Overwrite existing config or .gitignore." ) ,
40- ) ,
41- maxCommits : Flag . integer ( "max-commits" ) . pipe (
42- Flag . withDefault ( 200 ) ,
43- Flag . withDescription ( "Maximum commit count to analyze for scopes." ) ,
44- ) ,
45- local : Flag . boolean ( "local" ) . pipe (
46- Flag . withDescription ( "Write config to .git-agent/config.local.yml." ) ,
47- ) ,
48- hook : Flag . string ( "hook" ) . pipe (
49- Flag . withDescription ( "Hook to configure. Repeat the flag or use comma-separated values." ) ,
50- Flag . between ( 0 , Number . MAX_SAFE_INTEGER ) ,
51- ) ,
52- } ,
53- Effect . fn ( function * ( input ) {
28+ const runInitCommand = Effect . fn (
29+ function * ( input ) {
5430 const fs = yield * FileSystem . FileSystem ;
5531 const vcsKind = yield * detectVcs ( input . cwd , toOptionalString ( input . vcs ) ) ;
32+ yield * Effect . annotateCurrentSpan ( {
33+ vcs : vcsKind ,
34+ } ) ;
5635 const vcs = getVcsClient ( vcsKind ) ;
5736 const isRepo = yield * vcs . isRepo ( input . cwd ) ;
5837 const hooks = parseCsvValues ( input . hook ) ;
5938 if ( ! isRepo ) {
60- const output = yield * vcs . initRepo ( input . cwd ) ;
39+ const output = yield * withProgressSpan ( vcs . initRepo ( input . cwd ) , "init.initialize-repository" , {
40+ vcs : vcsKind ,
41+ } ) ;
6142 if ( output . length > 0 ) {
6243 yield * Console . log ( output ) ;
6344 }
@@ -76,9 +57,7 @@ export const commandInit = Command.make(
7657 ) ;
7758 }
7859
79- const configPath = yield * input . local
80- ? localConfigPath ( repoRoot )
81- : projectConfigWritePath ( repoRoot ) ;
60+ const configPath = yield * input . local ? localConfigPath ( repoRoot ) : projectConfigWritePath ( repoRoot ) ;
8261 if ( ! input . force ) {
8362 const exists = yield * fs . exists ( configPath ) ;
8463 if ( exists ) {
@@ -109,24 +88,85 @@ export const commandInit = Command.make(
10988 }
11089
11190 if ( doGitignore || fullWizard ) {
112- const techs = yield * generateGitignore ( provider , vcs , repoRoot ) ;
91+ const techs = yield * withProgressSpan ( generateGitignore ( provider , vcs , repoRoot ) , "init.generate-gitignore" , {
92+ vcs : vcsKind ,
93+ full_wizard : fullWizard ,
94+ } ) ;
11395 yield * Console . log ( `.gitignore updated: ${ techs . join ( ", " ) } ` ) ;
11496 }
11597
11698 if ( doScope || fullWizard ) {
117- const scopes = yield * generateProjectScopes ( provider , vcs , repoRoot , input . maxCommits ) ;
99+ const scopes = yield * withProgressSpan (
100+ generateProjectScopes ( provider , vcs , repoRoot , input . maxCommits ) ,
101+ "init.generate-scopes" ,
102+ {
103+ vcs : vcsKind ,
104+ full_wizard : fullWizard ,
105+ max_commits : input . maxCommits ,
106+ } ,
107+ ) ;
118108 yield * mergeAndSaveScopes ( configPath , scopes ) ;
119109 yield * Console . log ( `scopes written to ${ configPath } ` ) ;
120110 }
121111
122112 if ( fullWizard ) {
123- yield * writeProjectField ( configPath , "hook" , "conventional" ) ;
113+ yield * withProgressSpan ( writeProjectField ( configPath , "hook" , "conventional" ) , "init.write-default-hook" , {
114+ path : configPath ,
115+ } ) ;
124116 } else if ( hooks . length > 0 ) {
125- yield * writeProjectField ( configPath , "hook" , hooks . join ( "," ) ) ;
117+ yield * withProgressSpan ( writeProjectField ( configPath , "hook" , hooks . join ( "," ) ) , "init.write-hook" , {
118+ path : configPath ,
119+ hook_count : hooks . length ,
120+ } ) ;
126121 }
127122
128123 if ( ! doScope && ! doGitignore && ! fullWizard && hooks . length > 0 ) {
129- yield * mergeAndSaveScopes ( configPath , emptyProjectConfig ( ) . scopes ) ;
124+ yield * withProgressSpan (
125+ mergeAndSaveScopes ( configPath , emptyProjectConfig ( ) . scopes ) ,
126+ "init.write-project-config" ,
127+ {
128+ path : configPath ,
129+ } ,
130+ ) ;
130131 }
132+ } ,
133+ ( effect , input ) =>
134+ withProgressSpan ( effect , "init.run" , {
135+ force : input . force ,
136+ gitignore : input . gitignore ,
137+ local : input . local ,
138+ requested_vcs : toOptionalString ( input . vcs ) ?? "auto" ,
139+ scope : input . scope ,
140+ } ) ,
141+ ) ;
142+
143+ export const commandInit = Command . make (
144+ "init" ,
145+ {
146+ cwd : cwdFlag ,
147+ vcs : vcsFlag ,
148+ apiKey : apiKeyFlag ,
149+ baseUrl : baseUrlFlag ,
150+ model : modelFlag ,
151+ free : freeFlag ,
152+ scope : Flag . boolean ( "scope" ) . pipe ( Flag . withDescription ( "Generate scopes via AI." ) ) ,
153+ gitignore : Flag . boolean ( "gitignore" ) . pipe ( Flag . withDescription ( "Generate .gitignore via AI." ) ) ,
154+ force : Flag . boolean ( "force" ) . pipe (
155+ Flag . withDescription ( "Overwrite existing config or .gitignore." ) ,
156+ ) ,
157+ maxCommits : Flag . integer ( "max-commits" ) . pipe (
158+ Flag . withDefault ( 200 ) ,
159+ Flag . withDescription ( "Maximum commit count to analyze for scopes." ) ,
160+ ) ,
161+ local : Flag . boolean ( "local" ) . pipe (
162+ Flag . withDescription ( "Write config to .git-agent/config.local.yml." ) ,
163+ ) ,
164+ hook : Flag . string ( "hook" ) . pipe (
165+ Flag . withDescription ( "Hook to configure. Repeat the flag or use comma-separated values." ) ,
166+ Flag . between ( 0 , Number . MAX_SAFE_INTEGER ) ,
167+ ) ,
168+ } ,
169+ Effect . fn ( function * ( input ) {
170+ yield * runInitCommand ( input ) ;
131171 } ) ,
132172) . pipe ( Command . withDescription ( "Initialize git-agent in the current repository." ) ) ;
0 commit comments