Skip to content

Commit 51cf356

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

File tree

2 files changed

+26
-30
lines changed

2 files changed

+26
-30
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: 14 additions & 18 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(() => {
@@ -369,16 +369,6 @@ async function runAiAgentCheck() {
369369

370370
const now = Date.now();
371371

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-
382372
const workspacePath = getWorkspacePath();
383373
if (!workspacePath) {
384374
return;
@@ -438,6 +428,16 @@ async function runAiAgentCheck() {
438428
}
439429
}
440430

431+
const lastUpdateNotificationTimestamp =
432+
WorkspaceConfigurationStore.instance.get(
433+
'lastAiCheckNotificationTimestamp',
434+
0,
435+
);
436+
const gap = 12 * 60 * 60 * 1000;
437+
if (now - lastUpdateNotificationTimestamp < gap) {
438+
return;
439+
}
440+
441441
WorkspaceConfigurationStore.instance.set(
442442
'lastAiCheckNotificationTimestamp',
443443
now,
@@ -490,10 +490,6 @@ async function runAiAgentCheck() {
490490
}
491491
}
492492
getTelemetry().logUsage('ai.configure-agents-check-end');
493-
WorkspaceConfigurationStore.instance.set(
494-
'lastAiCheckNotificationTimestamp',
495-
now,
496-
);
497493

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

0 commit comments

Comments
 (0)