@@ -9,6 +9,40 @@ import { budgetReport, resetTelemetry } from '../lib/provider.mjs';
99import { commandExists , engineHome , ensureDir , kitVersion , loadConfig , parseArgs , projectPaths , readJson , requireProjectRoot , writeJson } from '../lib/core.mjs' ;
1010import { runWorkspace } from './workspace.mjs' ;
1111
12+ const MIN_PROVIDER_TURNS = 30 ;
13+ const TURN_KEYS = [ 'default' , 'modelCore' , 'modelEnterprise' , 'plan' , 'generate' , 'audit' ] ;
14+
15+ function normalizedTurns ( value ) {
16+ const parsed = Number ( value ) ;
17+ return Number . isFinite ( parsed ) ? Math . max ( MIN_PROVIDER_TURNS , Math . trunc ( parsed ) ) : MIN_PROVIDER_TURNS ;
18+ }
19+
20+ function normalizeTurnEnvironment ( ) {
21+ if ( process . env . DOCGEN_MAX_TURNS !== undefined ) {
22+ process . env . DOCGEN_MAX_TURNS = String ( normalizedTurns ( process . env . DOCGEN_MAX_TURNS ) ) ;
23+ }
24+ }
25+
26+ function enforceMinimumTurns ( root ) {
27+ const paths = projectPaths ( root ) ;
28+ const config = loadConfig ( root ) ;
29+ config . commandCode ??= { } ;
30+ config . commandCode . maxTurns ??= { } ;
31+ let changed = false ;
32+ for ( const key of TURN_KEYS ) {
33+ const current = config . commandCode . maxTurns [ key ] ;
34+ const next = normalizedTurns ( current ) ;
35+ if ( current !== next ) {
36+ config . commandCode . maxTurns [ key ] = next ;
37+ changed = true ;
38+ }
39+ }
40+ if ( changed ) writeJson ( paths . config , config ) ;
41+ return config . commandCode . maxTurns ;
42+ }
43+
44+ normalizeTurnEnvironment ( ) ;
45+
1246function usage ( ) {
1347 console . log ( `Command Code DocGen ${ kitVersion } — token-efficient semantic-index pipeline
1448
@@ -104,6 +138,7 @@ async function main() {
104138 if ( command === 'init' ) { init ( positional [ 0 ] ?? '.' ) ; return ; }
105139 if ( command === 'workspace' ) { await runWorkspace ( rest , { kitVersion } ) ; return ; }
106140 const root = requireProjectRoot ( ) ;
141+ enforceMinimumTurns ( root ) ;
107142 switch ( command ) {
108143 case 'migrate' : migrate ( root ) ; break ;
109144 case 'doctor' : doctor ( root ) ; break ;
0 commit comments