Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions src/fileWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,36 @@ export function ensureProjectScan(
webview: vscode.Webview | undefined,
persistAgents: () => void,
): void {
if (projectScanTimerRef.current) return;
// Seed with all existing JSONL files so we only react to truly new ones
// 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
.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 {
/* dir may not exist yet */
}

// Start the scan timer only once
if (projectScanTimerRef.current) return;
projectScanTimerRef.current = setInterval(() => {
scanForNewJsonlFiles(
projectDir,
Expand Down Expand Up @@ -183,19 +199,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,
Expand All @@ -208,6 +224,7 @@ function scanForNewJsonlFiles(
webview,
persistAgents,
);
break;
}
}
}
Expand Down