1- import { getPackageManagerCommand } from '@nx-console/shared-npm' ;
21import { nxLatestProvenanceCheck } from '@nx-console/shared-utils' ;
32import { WorkspaceConfigurationStore } from '@nx-console/vscode-configuration' ;
43import { vscodeLogger } from '@nx-console/vscode-output-channels' ;
@@ -56,14 +55,13 @@ export async function runConfigureAiAgentsCommand() {
5655 source : 'command' ,
5756 } ) ;
5857
59- const pkgManagerCommands = await getPackageManagerCommand ( workspacePath ) ;
60- const configureCommand = `nx@latest configure-ai-agents` ;
58+ const command = constructCommand ( '' ) ;
6159 const task = new Task (
6260 { type : 'nx' } ,
6361 TaskScope . Workspace ,
64- configureCommand ,
62+ command ,
6563 'nx' ,
66- new ShellExecution ( ` ${ pkgManagerCommands . dlx } ${ configureCommand } ` , {
64+ new ShellExecution ( command , {
6765 cwd : workspacePath ,
6866 env : {
6967 ...process . env ,
@@ -76,6 +74,20 @@ export async function runConfigureAiAgentsCommand() {
7674 tasks . executeTask ( task ) ;
7775}
7876
77+ function constructCommand ( flags : string ) {
78+ // const workspacePath = getWorkspacePath();
79+ // const pkgManagerCommands = await getPackageManagerCommand(workspacePath);
80+
81+ // non a project install, so use NPX and don't pollute npx cache
82+ const tmpDir = join ( tmpdir ( ) , 'nx-console-tmp' ) ;
83+ try {
84+ rmSync ( tmpDir , { recursive : true , force : true } ) ;
85+ } catch ( e ) {
86+ // ignore
87+ }
88+ return `npx -y --cache=${ tmpDir } nx@latest configure-ai-agents ${ flags } ` ;
89+ }
90+
7991async function runAiAgentCheck ( ) {
8092 if ( WorkspaceConfigurationStore . instance . get ( 'aiCheckDontAskAgain' , false ) ) {
8193 return ;
@@ -88,8 +100,8 @@ async function runAiAgentCheck() {
88100 'lastAiCheckNotificationTimestamp' ,
89101 0 ,
90102 ) ;
91- const oneDayInMs = 24 * 60 * 60 * 1000 ;
92- if ( now - lastUpdateNotificationTimestamp < oneDayInMs ) {
103+ const gap = 12 * 60 * 60 * 1000 ;
104+ if ( now - lastUpdateNotificationTimestamp < gap ) {
93105 return ;
94106 }
95107
@@ -99,20 +111,14 @@ async function runAiAgentCheck() {
99111 }
100112
101113 try {
102- const pkgManagerCommands = await getPackageManagerCommand ( workspacePath ) ;
103-
104114 const hasProvenance = await nxLatestProvenanceCheck ( ) ;
105115 if ( hasProvenance !== true ) {
106116 return ;
107117 }
108118
109119 try {
110- getTelemetry ( ) . logUsage ( 'ai.configure-agents-check' ) ;
111- // non a project install, so use NPX and don't pollute npx cache
112- const tmpDir = join ( tmpdir ( ) , 'nx-console-tmp' ) ;
113- rmSync ( tmpDir , { recursive : true , force : true } ) ;
114- const checkCommand = `npx --cache=${ tmpDir } nx@latest configure-ai-agents --check` ;
115- await promisify ( exec ) ( checkCommand , {
120+ getTelemetry ( ) . logUsage ( 'ai.configure-agents-check-start' ) ;
121+ await promisify ( exec ) ( constructCommand ( '--check' ) , {
116122 cwd : workspacePath ,
117123 env : {
118124 ...process . env ,
@@ -121,7 +127,7 @@ async function runAiAgentCheck() {
121127 NX_AI_FILES_USE_LOCAL : 'true' ,
122128 } ,
123129 } ) ;
124- getTelemetry ( ) . logUsage ( 'ai.configure-agents-check-done ' ) ;
130+ getTelemetry ( ) . logUsage ( 'ai.configure-agents-check-end ' ) ;
125131 WorkspaceConfigurationStore . instance . set (
126132 'lastAiCheckNotificationTimestamp' ,
127133 now ,
@@ -133,6 +139,7 @@ async function runAiAgentCheck() {
133139 // There are many different reasons this could fail so we want to not spam users
134140 const stringified = JSON . stringify ( e ) ;
135141 if ( ! stringified . includes ( 'The following AI agents are out of date' ) ) {
142+ getTelemetry ( ) . logUsage ( 'ai.configure-agents-check-error' ) ;
136143 return ;
137144 }
138145 WorkspaceConfigurationStore . instance . set (
@@ -157,13 +164,13 @@ async function runAiAgentCheck() {
157164 } ) ;
158165
159166 // Run the configure command
160- const configureCommand = `nx@latest configure-ai-agents` ;
167+ const command = constructCommand ( '' ) ;
161168 const task = new Task (
162169 { type : 'nx' } ,
163170 TaskScope . Workspace ,
164- configureCommand ,
171+ command ,
165172 'nx' ,
166- new ShellExecution ( ` ${ pkgManagerCommands . dlx } ${ configureCommand } ` , {
173+ new ShellExecution ( command , {
167174 cwd : workspacePath ,
168175 env : {
169176 ...process . env ,
@@ -200,8 +207,7 @@ async function runAiAgentCheck() {
200207 }
201208
202209 // Run the check=all command to see if configuration is needed
203- const checkAllCommand = `${ pkgManagerCommands . dlx } nx@latest configure-ai-agents --check=all` ;
204-
210+ const checkAllCommand = constructCommand ( '--check=all' ) ;
205211 try {
206212 await promisify ( exec ) ( checkAllCommand , {
207213 cwd : workspacePath ,
@@ -245,13 +251,13 @@ async function runAiAgentCheck() {
245251 source : 'notification' ,
246252 } ) ;
247253
248- const configureCommand = `nx@latest configure-ai-agents` ;
254+ const command = constructCommand ( '' ) ;
249255 const task = new Task (
250256 { type : 'nx' } ,
251257 TaskScope . Workspace ,
252- configureCommand ,
258+ command ,
253259 'nx' ,
254- new ShellExecution ( ` ${ pkgManagerCommands . dlx } ${ configureCommand } ` , {
260+ new ShellExecution ( command , {
255261 cwd : workspacePath ,
256262 env : {
257263 ...process . env ,
0 commit comments