Skip to content

Commit d095020

Browse files
committed
chore(vscode): tweak periodic ai check
1 parent a572eeb commit d095020

File tree

2 files changed

+27
-44
lines changed

2 files changed

+27
-44
lines changed

apps/intellij/src/main/kotlin/dev/nx/console/ai/PeriodicAiCheckService.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ class PeriodicAiCheckService(private val project: Project, private val cs: Corou
3131
"dev.nx.console.last_ai_check_notification_timestamp"
3232
private const val LAST_AI_CONFIGURE_NOTIFICATION_TIMESTAMP_KEY =
3333
"dev.nx.console.last_ai_configure_notification_timestamp"
34-
private const val ONE_MINUTE_MS = 60 * 1000L
35-
private const val ONE_HOUR_MS = 60 * 60 * 1000L
36-
private const val ONE_DAY_MS = 24 * 60 * 60 * 1000L
34+
private const val THREE_MINUTES_MS = 3 * 60 * 1000L
35+
private const val THREE_HOURS_MS = 3 * 60 * 60 * 1000L
36+
private const val TWELVE_HOURS_MS = 12 * 60 * 60 * 1000L
3737
private const val ONE_WEEK_MS = 7 * 24 * 60 * 60 * 1000L
3838
}
3939

@@ -46,11 +46,11 @@ class PeriodicAiCheckService(private val project: Project, private val cs: Corou
4646

4747
checkJob =
4848
cs.launch {
49-
delay(ONE_MINUTE_MS)
49+
delay(THREE_MINUTES_MS)
5050
runAiAgentCheck()
5151

5252
while (isActive) {
53-
delay(ONE_HOUR_MS)
53+
delay(THREE_HOURS_MS)
5454
runAiAgentCheck()
5555
}
5656
}
@@ -68,13 +68,6 @@ class PeriodicAiCheckService(private val project: Project, private val cs: Corou
6868

6969
val now = System.currentTimeMillis()
7070

71-
val lastUpdateNotificationTimestamp =
72-
PropertiesComponent.getInstance(project)
73-
.getLong(LAST_AI_CHECK_NOTIFICATION_TIMESTAMP_KEY, 0)
74-
if (now - lastUpdateNotificationTimestamp < ONE_DAY_MS) {
75-
return
76-
}
77-
7871
try {
7972
val workspaceRoot = project.basePath ?: "."
8073

@@ -98,6 +91,13 @@ class PeriodicAiCheckService(private val project: Project, private val cs: Corou
9891
val output = withContext(Dispatchers.IO) { ExecUtil.execAndGetOutput(checkCommand) }
9992

10093
if (output.stdout.contains("The following AI agents are out of date")) {
94+
val lastUpdateNotificationTimestamp =
95+
PropertiesComponent.getInstance(project)
96+
.getLong(LAST_AI_CHECK_NOTIFICATION_TIMESTAMP_KEY, 0)
97+
if (now - lastUpdateNotificationTimestamp < TWELVE_HOURS_MS) {
98+
return
99+
}
100+
101101
PropertiesComponent.getInstance(project)
102102
.setValue(LAST_AI_CHECK_NOTIFICATION_TIMESTAMP_KEY, now.toString())
103103

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

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,18 @@ let checkTimer: NodeJS.Timeout | undefined;
6464
let intervalTimer: NodeJS.Timeout | undefined;
6565

6666
export function setupPeriodicAiCheck(context: ExtensionContext) {
67-
// Run first check after 1 minute
67+
// Run first check after 3 minutes
6868
checkTimer = setTimeout(() => {
6969
runAiAgentCheck();
7070

71-
// Then check every hour
71+
// Then check every 3 hours
7272
intervalTimer = setInterval(
7373
() => {
7474
runAiAgentCheck();
7575
},
76-
60 * 60 * 1000,
76+
3 * 60 * 60 * 1000,
7777
);
78-
}, 60 * 1000);
78+
}, 3 * 60 * 1000);
7979

8080
context.subscriptions.push(
8181
new Disposable(() => {
@@ -144,25 +144,12 @@ async function constructCommand(flags: string, forceNpx = false) {
144144
// there are older versions of nx that have this outdated config
145145
// 'yarn' isn't actually a dlx command it's only for local packages
146146
if (dlx === 'yarn' || dlx === 'npx' || dlx === undefined) {
147-
dlx = 'npx -y --ignore-scripts';
147+
dlx = `npx -y --ignore-scripts ${cacheParam}`;
148148
}
149149

150150
return `${forceNpx ? `npx -y ${cacheParam} --ignore-scripts` : dlx} nx@latest configure-ai-agents ${flags}`.trim();
151151
}
152152

153-
async function getNxLatestVersion(): Promise<string | undefined> {
154-
try {
155-
const result = await promisify(exec)('npm view nx@latest version', {
156-
encoding: 'utf-8',
157-
timeout: 10000,
158-
});
159-
return result.stdout.trim();
160-
} catch (e) {
161-
vscodeLogger.log(`Failed to get nx@latest version: ${e}`);
162-
return undefined;
163-
}
164-
}
165-
166153
async function doRunAiAgentCheck(
167154
workspacePath: string,
168155
forceNpx = false,
@@ -369,16 +356,6 @@ async function runAiAgentCheck() {
369356

370357
const now = Date.now();
371358

372-
const lastUpdateNotificationTimestamp =
373-
WorkspaceConfigurationStore.instance.get(
374-
'lastAiCheckNotificationTimestamp',
375-
0,
376-
);
377-
const gap = 12 * 60 * 60 * 1000;
378-
if (now - lastUpdateNotificationTimestamp < gap) {
379-
return;
380-
}
381-
382359
const workspacePath = getWorkspacePath();
383360
if (!workspacePath) {
384361
return;
@@ -438,6 +415,16 @@ async function runAiAgentCheck() {
438415
}
439416
}
440417

418+
const lastUpdateNotificationTimestamp =
419+
WorkspaceConfigurationStore.instance.get(
420+
'lastAiCheckNotificationTimestamp',
421+
0,
422+
);
423+
const gap = 12 * 60 * 60 * 1000;
424+
if (now - lastUpdateNotificationTimestamp < gap) {
425+
return;
426+
}
427+
441428
WorkspaceConfigurationStore.instance.set(
442429
'lastAiCheckNotificationTimestamp',
443430
now,
@@ -490,10 +477,6 @@ async function runAiAgentCheck() {
490477
}
491478
}
492479
getTelemetry().logUsage('ai.configure-agents-check-end');
493-
WorkspaceConfigurationStore.instance.set(
494-
'lastAiCheckNotificationTimestamp',
495-
now,
496-
);
497480

498481
// If we get here, the update check passed (no updates needed)
499482
// Now check if we should prompt for configuration

0 commit comments

Comments
 (0)