Skip to content

Commit 5a9cf72

Browse files
committed
feat: extend chat heartbeats using last active file
1 parent c3a261c commit 5a9cf72

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ interface FileDiff {
5959

6060
const processedCallIds = new Set<string>();
6161
const pendingFiles = new Map<string, { language: string; absoluteFile?: string }>();
62+
let lastActiveFile: string | null = null;
6263

6364
let _token: string | null = null;
6465
let _projectName = "unknown";
@@ -199,6 +200,7 @@ function trackFile(filePath: string): void {
199200
language,
200201
absoluteFile: filePath,
201202
});
203+
lastActiveFile = filePath;
202204
}
203205

204206
// ---- Event guard ----
@@ -286,6 +288,7 @@ export const plugin: Plugin = async (ctx) => {
286288

287289
// Initialize state
288290
initState();
291+
lastActiveFile = null;
289292
_projectDir = directory;
290293
_worktree = worktree;
291294
_projectName = `${path.basename(directory)} opencode`;
@@ -343,7 +346,11 @@ export const plugin: Plugin = async (ctx) => {
343346

344347
"chat.message": async () => {
345348
try {
346-
// On any chat activity, try to process pending heartbeats
349+
// On any chat activity, try to process pending heartbeats.
350+
// Strict mode: only extend activity if a real file was previously touched.
351+
if (_token && pendingFiles.size === 0 && lastActiveFile) {
352+
trackFile(lastActiveFile);
353+
}
347354
if (_token && pendingFiles.size > 0) {
348355
await processHeartbeats();
349356
}

0 commit comments

Comments
 (0)