feat(HAI-003): add file-system watcher to TaskStore for live dashboard updates
- Add watch() method using Node's built-in fs.watch with recursive option - Detect task.json changes and emit appropriate SSE events (created/moved/updated/deleted) - Debounce per-file changes (150ms) to coalesce rapid writes - Suppress duplicate events for in-process mutations via recentlyWritten set - Integrate watcher into dashboard server startup with clean SIGINT shutdown - Add @types/node to core package for proper TypeScript support
This commit is contained in:
@@ -15,6 +15,7 @@ export async function runDashboard(port: number, opts: { engine?: boolean; open?
|
||||
const cwd = process.cwd();
|
||||
const store = new TaskStore(cwd);
|
||||
await store.init();
|
||||
await store.watch();
|
||||
|
||||
// AI-powered merge handler
|
||||
const onMerge = (taskId: string) =>
|
||||
@@ -26,6 +27,14 @@ export async function runDashboard(port: number, opts: { engine?: boolean; open?
|
||||
// Start the web server with AI merge wired in
|
||||
const app = createServer(store, { onMerge });
|
||||
|
||||
// Clean shutdown for file watcher when engine is not active
|
||||
if (!opts.engine) {
|
||||
process.on("SIGINT", () => {
|
||||
store.stopWatching();
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
|
||||
// Optionally start the AI engine
|
||||
if (opts.engine) {
|
||||
const triage = new TriageProcessor(store, cwd, {
|
||||
@@ -52,6 +61,7 @@ export async function runDashboard(port: number, opts: { engine?: boolean; open?
|
||||
process.on("SIGINT", () => {
|
||||
triage.stop();
|
||||
scheduler.stop();
|
||||
store.stopWatching();
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
@@ -71,6 +81,7 @@ export async function runDashboard(port: number, opts: { engine?: boolean; open?
|
||||
} else {
|
||||
console.log(` AI engine: off (use --engine to enable)`);
|
||||
}
|
||||
console.log(` File watcher: ✓ active`);
|
||||
console.log(` Press Ctrl+C to stop`);
|
||||
console.log();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user