@@ -34,6 +34,7 @@ import { planInit } from "~/core/planInit.js";
3434import { resolveInitRequest } from "~/core/resolveInitRequest.js" ;
3535import type { CliFlags } from "~/core/types.js" ;
3636import { makeLiveLayer } from "~/services/live.js" ;
37+ import { resolveNonInteractiveMode } from "~/utils/nonInteractive.js" ;
3738import { intro } from "~/utils/prompts.js" ;
3839import { proofGradient , renderTitle } from "~/utils/renderTitle.js" ;
3940
@@ -76,13 +77,6 @@ export const runDefaultCommand = (rawFlags?: Partial<CliFlags>) =>
7677 const fsService = yield * FileSystemService ;
7778 const consoleService = yield * ConsoleService ;
7879 const flags = { ...defaultCliFlags , ...rawFlags } ;
79-
80- if ( cliContext . nonInteractive || flags . CI || flags . nonInteractive ) {
81- throw new Error (
82- "The default command is interactive-only in non-interactive mode. Run an explicit command such as `proofkit init <name> --non-interactive`." ,
83- ) ;
84- }
85-
8680 const settingsPath = path . join ( cliContext . cwd , "proofkit.json" ) ;
8781 const hasProofKitProject = yield * Effect . promise ( ( ) => fsService . exists ( settingsPath ) ) ;
8882
@@ -98,6 +92,12 @@ export const runDefaultCommand = (rawFlags?: Partial<CliFlags>) =>
9892 return ;
9993 }
10094
95+ if ( cliContext . nonInteractive || flags . CI || flags . nonInteractive ) {
96+ throw new Error (
97+ "The default command is interactive-only in non-interactive mode. Run an explicit command such as `proofkit init <name> --non-interactive`." ,
98+ ) ;
99+ }
100+
101101 intro ( `No ${ proofGradient ( "ProofKit" ) } project found, running \`init\`` ) ;
102102 yield * runInit ( undefined , {
103103 ...flags ,
@@ -117,11 +117,23 @@ function optionalChoiceOption<Choices extends readonly string[]>(name: string, c
117117 return optionalOption ( choiceOption ( name , choices ) . pipe ( withOptionDescription ( description ) ) ) ;
118118}
119119
120+ function getCurrentTTYState ( ) {
121+ return {
122+ stdinIsTTY : process . stdin ?. isTTY ,
123+ stdoutIsTTY : process . stdout ?. isTTY ,
124+ } ;
125+ }
126+
120127function legacyEffect < T > (runLegacy: () => Promise < T > , options ?: { nonInteractive ?: boolean ; debug ?: boolean } ) {
128+ const nonInteractive = resolveNonInteractiveMode ( {
129+ nonInteractive : options ?. nonInteractive ,
130+ ...getCurrentTTYState ( ) ,
131+ } ) ;
132+
121133 return makeLiveLayer ( {
122134 cwd : process . cwd ( ) ,
123135 debug : options ?. debug === true ,
124- nonInteractive : options ?. nonInteractive === true ,
136+ nonInteractive,
125137 } ) ( Effect . promise ( runLegacy ) ) ;
126138}
127139
@@ -155,6 +167,12 @@ function makeInitCommand() {
155167 debug : booleanOption ( "debug" ) . pipe ( withOptionDescription ( "Run in debug mode" ) ) ,
156168 } ,
157169 ( { dir, ...options } ) => {
170+ const nonInteractive = resolveNonInteractiveMode ( {
171+ CI : options . CI ,
172+ nonInteractive : options . nonInteractive ,
173+ ...getCurrentTTYState ( ) ,
174+ } ) ;
175+
158176 const flags : CliFlags = {
159177 ...defaultCliFlags ,
160178 appType : getOrUndefined ( options . appType ) ,
@@ -177,7 +195,7 @@ function makeInitCommand() {
177195 return makeLiveLayer ( {
178196 cwd : process . cwd ( ) ,
179197 debug : flags . debug === true ,
180- nonInteractive : Boolean ( flags . CI || flags . nonInteractive ) ,
198+ nonInteractive,
181199 } ) ( runInit ( getOrUndefined ( dir ) , flags ) ) ;
182200 } ,
183201 ) . pipe ( withCommandDescription ( "Create a new project with ProofKit" ) ) ;
@@ -336,7 +354,11 @@ const rootCommand = makeCommand(
336354 makeLiveLayer ( {
337355 cwd : process . cwd ( ) ,
338356 debug : options . debug === true ,
339- nonInteractive : Boolean ( options . CI || options . nonInteractive ) ,
357+ nonInteractive : resolveNonInteractiveMode ( {
358+ CI : options . CI ,
359+ nonInteractive : options . nonInteractive ,
360+ ...getCurrentTTYState ( ) ,
361+ } ) ,
340362 } ) (
341363 runDefaultCommand ( {
342364 ...defaultCliFlags ,
0 commit comments