Skip to content

Commit d2e1050

Browse files
committed
Merge branch 'master' into release
2 parents 56b9ab4 + 23abb24 commit d2e1050

File tree

2 files changed

+33
-26
lines changed

2 files changed

+33
-26
lines changed

libs/shared/telemetry/src/lib/telemetry-types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ export type TelemetryEvents =
7474
| 'ai.tool-call'
7575
| 'ai.resource-read'
7676
| 'ai.add-mcp'
77-
| 'ai.configure-agents-check'
78-
| 'ai.configure-agents-check-done'
77+
| 'ai.configure-agents-check-start'
78+
| 'ai.configure-agents-check-end'
79+
| 'ai.configure-agents-check-error'
7980
| 'ai.configure-agents-check-notification'
8081
| 'ai.configure-agents-action'
8182
| 'ai.configure-agents-dont-ask-again'

libs/vscode/mcp/src/lib/periodic-ai-check.ts

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { getPackageManagerCommand } from '@nx-console/shared-npm';
21
import { nxLatestProvenanceCheck } from '@nx-console/shared-utils';
32
import { WorkspaceConfigurationStore } from '@nx-console/vscode-configuration';
43
import { 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+
7991
async 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

Comments
 (0)