From 2755f95253ff60422e24f0b0778bb39c5cfd7aeb Mon Sep 17 00:00:00 2001 From: Shadow Date: Mon, 9 Mar 2026 19:52:54 +0100 Subject: [PATCH 1/2] fix: improve agent detection for non-extension-spawned terminals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When Claude Code is started outside of Pixel Agents (e.g. from an existing terminal), the extension fails to detect and track the agent because: 1. ensureProjectScan pre-registers ALL existing JSONL files as "known", preventing active sessions from being picked up. Now files that are both large (≥3KB) and recently modified (<10min) are skipped during pre-registration, allowing them to be detected by terminal scanning. 2. scanForNewJsonlFiles only checks vscode.window.activeTerminal when adopting orphaned JSONL files. If the Claude terminal isn't focused, it's never found. Now all terminals are scanned to find an untracked terminal to adopt. Co-Authored-By: Claude Opus 4.6 --- src/fileWatcher.ts | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/fileWatcher.ts b/src/fileWatcher.ts index f2a60dfd..22b8c1a8 100644 --- a/src/fileWatcher.ts +++ b/src/fileWatcher.ts @@ -110,13 +110,28 @@ export function ensureProjectScan( persistAgents: () => void, ): void { if (projectScanTimerRef.current) return; - // Seed with all existing JSONL files so we only react to truly new ones + // Seed with existing JSONL files so we only react to truly new ones. + // Skip recently active files (large + recently modified) so they can + // still be picked up by terminal scanning during the current session. try { + const now = Date.now(); const files = fs .readdirSync(projectDir) .filter((f) => f.endsWith('.jsonl')) .map((f) => path.join(projectDir, f)); for (const f of files) { + try { + const stat = fs.statSync(f); + const isRecentlyActive = now - stat.mtimeMs < 600_000 && stat.size >= 3000; + if (isRecentlyActive) { + console.log( + `[Pixel Agents] Skipping pre-register of active JSONL: ${path.basename(f)}`, + ); + continue; + } + } catch { + /* stat failed — pre-register to be safe */ + } knownJsonlFiles.add(f); } } catch { @@ -183,19 +198,19 @@ function scanForNewJsonlFiles( persistAgents, ); } else { - // No active agent → try to adopt the focused terminal - const activeTerminal = vscode.window.activeTerminal; - if (activeTerminal) { + // No active agent → scan all terminals (not just the focused one) + // to find an untracked Claude terminal that may own this JSONL file + for (const terminal of vscode.window.terminals) { let owned = false; for (const agent of agents.values()) { - if (agent.terminalRef === activeTerminal) { + if (agent.terminalRef === terminal) { owned = true; break; } } if (!owned) { adoptTerminalForFile( - activeTerminal, + terminal, file, projectDir, nextAgentIdRef, @@ -208,6 +223,7 @@ function scanForNewJsonlFiles( webview, persistAgents, ); + break; } } } From 95b3da07def1fc0c824c22a1b537b273f6650da9 Mon Sep 17 00:00:00 2001 From: Shadow Date: Mon, 9 Mar 2026 20:30:47 +0100 Subject: [PATCH 2/2] fix: move JSONL seeding before early return in ensureProjectScan The seeding logic (smart pre-registration that skips active JSONLs) was placed after `if (projectScanTimerRef.current) return`, meaning it only ran on the first call. Now it runs on every call, ensuring newly appeared files are always seeded correctly. Co-Authored-By: Claude Opus 4.6 --- src/fileWatcher.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/fileWatcher.ts b/src/fileWatcher.ts index 22b8c1a8..8c254f38 100644 --- a/src/fileWatcher.ts +++ b/src/fileWatcher.ts @@ -109,10 +109,9 @@ export function ensureProjectScan( webview: vscode.Webview | undefined, persistAgents: () => void, ): void { - if (projectScanTimerRef.current) return; - // Seed with existing JSONL files so we only react to truly new ones. - // Skip recently active files (large + recently modified) so they can - // still be picked up by terminal scanning during the current session. + // Always seed this directory's existing JSONL files (even if timer is already running) + // so we only react to truly new ones. Skip recently active files (large + recently + // modified) so they can still be picked up by terminal scanning during the current session. try { const now = Date.now(); const files = fs @@ -138,6 +137,8 @@ export function ensureProjectScan( /* dir may not exist yet */ } + // Start the scan timer only once + if (projectScanTimerRef.current) return; projectScanTimerRef.current = setInterval(() => { scanForNewJsonlFiles( projectDir,