feat(s1p2): add inotify-based filesystem write detection with external conflict tracking

This commit is contained in:
Hibryda 2026-03-11 00:56:27 +01:00
parent 6b239c5ce5
commit e5d9f51df7
8 changed files with 501 additions and 7 deletions

View file

@ -1,4 +1,5 @@
<script lang="ts">
import { onDestroy } from 'svelte';
import type { ProjectConfig } from '../../types/groups';
import { PROJECT_ACCENTS } from '../../types/groups';
import ProjectHeader from './ProjectHeader.svelte';
@ -12,6 +13,9 @@
import MemoriesTab from './MemoriesTab.svelte';
import { getTerminalTabs } from '../../stores/workspace.svelte';
import { getProjectHealth } from '../../stores/health.svelte';
import { fsWatchProject, fsUnwatchProject, onFsWriteDetected } from '../../adapters/fs-watcher-bridge';
import { recordExternalWrite } from '../../stores/conflicts.svelte';
import { notify } from '../../stores/notifications.svelte';
interface Props {
project: ProjectConfig;
@ -47,6 +51,35 @@
function toggleTerminal() {
terminalExpanded = !terminalExpanded;
}
// S-1 Phase 2: start filesystem watcher for this project's CWD
$effect(() => {
const cwd = project.cwd;
const projectId = project.id;
if (!cwd) return;
// Start watching
fsWatchProject(projectId, cwd).catch(e =>
console.warn(`Failed to start fs watcher for ${projectId}:`, e)
);
// Listen for fs write events (filter to this project)
let unlisten: (() => void) | null = null;
onFsWriteDetected((event) => {
if (event.project_id !== projectId) return;
const isNew = recordExternalWrite(projectId, event.file_path, event.timestamp_ms);
if (isNew) {
const shortName = event.file_path.split('/').pop() ?? event.file_path;
notify('warning', `External write: ${shortName} — file also modified by agent`);
}
}).then(fn => { unlisten = fn; });
return () => {
// Cleanup: stop watching on unmount or project change
fsUnwatchProject(projectId).catch(() => {});
unlisten?.();
};
});
</script>
<div

View file

@ -81,13 +81,23 @@
<span class="project-id">({project.identifier})</span>
</div>
<div class="header-info">
{#if health && health.fileConflictCount > 0}
{#if health && health.externalConflictCount > 0}
<button
class="info-conflict"
title="{health.fileConflictCount} file conflict{health.fileConflictCount > 1 ? 's' : ''} — click to dismiss"
class="info-conflict info-conflict-external"
title="{health.externalConflictCount} external write{health.externalConflictCount > 1 ? 's' : ''} files modified outside agent — click to dismiss"
onclick={(e: MouseEvent) => { e.stopPropagation(); acknowledgeConflicts(project.id); }}
>
{health.fileConflictCount} conflict{health.fileConflictCount > 1 ? 's' : ''}
{health.externalConflictCount} ext write{health.externalConflictCount > 1 ? 's' : ''}
</button>
<span class="info-sep">·</span>
{/if}
{#if health && health.fileConflictCount - (health.externalConflictCount ?? 0) > 0}
<button
class="info-conflict"
title="{health.fileConflictCount - (health.externalConflictCount ?? 0)} agent conflict{health.fileConflictCount - (health.externalConflictCount ?? 0) > 1 ? 's' : ''} — click to dismiss"
onclick={(e: MouseEvent) => { e.stopPropagation(); acknowledgeConflicts(project.id); }}
>
{health.fileConflictCount - (health.externalConflictCount ?? 0)} conflict{health.fileConflictCount - (health.externalConflictCount ?? 0) > 1 ? 's' : ''}
</button>
<span class="info-sep">·</span>
{/if}
@ -253,6 +263,15 @@
background: color-mix(in srgb, var(--ctp-red) 25%, transparent);
}
.info-conflict-external {
color: var(--ctp-peach);
background: color-mix(in srgb, var(--ctp-peach) 12%, transparent);
}
.info-conflict-external:hover {
background: color-mix(in srgb, var(--ctp-peach) 25%, transparent);
}
.info-profile {
font-size: 0.65rem;
color: var(--ctp-blue);