Builder Case Studies / Cozy Comet

Complete (1 month stale)
Python watchdog Ollama

Cozy Comet

macOS LaunchAgent daemon watching Desktop/Documents — batches file events, classifies changes, sends summaries to local Ollama to predict what you're working on.

Contextual computing (Apple Intelligence) Active learning loop
Problem Statement

Context Lost Between Sessions

When switching between projects, context is lost — which files were you working on, what research were you doing, what was the goal. A developer might have three browser windows, a dozen editor tabs, and two terminal sessions open, each belonging to a different task. Closing a session means abandoning the latent state accumulated over hours of work.

Existing solutions require manual note-taking or explicit check-ins: writing standup notes, tagging files, or maintaining a work log. These approaches fail because they depend on human discipline at exactly the moment people are most focused on their actual work. What's needed is a passive, always-on daemon that observes filesystem activity — the most reliable signal of what you're actually doing — and uses it to maintain a rolling context window across sessions.

The goal: a LaunchAgent that watches Desktop and Documents for file changes, batches events into time windows, classifies each batch by project/domain using a local LLM (Ollama), and maintains a rolling context prediction that surfaces without any user interaction required.

Approach & Architecture

LaunchAgent Pipeline for Passive Context Inference

Cozy Comet is a Python LaunchAgent daemon using watchdog (FSEvents on macOS) for zero-overhead filesystem observation. The daemon runs as a background launchd job, starting at login and staying resident with minimal resource footprint — watchdog uses OS-level event streams, so CPU sits at 0% when no files change.

The pipeline flows: filesystem events are collected from the watched folders (Desktop, Documents) → batched by time window → classified by Ollama running a local LLM (e.g., Llama 3, Mistral) → stored in a rolling context window. The predicted working context — project name, domain, active files — is available via a local API or log file, enabling integration with other tools (IDE, window manager, note-taking app).

class ContextHandler(FileSystemEventHandler):
    def on_modified(self, event):
        if not event.is_directory:
            batch.append(event.src_path)

        if time.time() - last_flush > BATCH_WINDOW:
            summary = ollama.chat(model="llama3", messages=[
                {"role": "user", "content":
                 f"Classify the working context from: {batch[-5:]}"}
            ])
            context_window.append(summary["message"]["content"])
            batch.clear()

Because Ollama runs locally, no file content leaves the machine: only change metadata (file paths, sizes, timestamps) and batched summaries are sent to the model. The daemon itself is configured via a standard plist file at ~/Library/LaunchAgents/, auto-started on login, and requires zero user interaction to operate.

Finder File Edit View Go Window Help Wed Jun 3 7:10 PM Cozy Comet COZY COMET — FILESYSTEM CONTEXT DAEMON DESKTOP scratchpad.md 👁 figma_v3.sketch 👁 todo.md 👁 README.md 👁 arch_diagram.drawio 👁 DOCUMENTS proposal_v4.docx 👁 notes.md 👁 budget.xlsx 👁 Q2_report.md 👁 watchdog FSEvents observer Batch Classifier time-window batching OLLAMA local LLM (Llama 3 / Mistral) zero data leaves machine CLASSIFY PREDICTED CONTEXT Project: Cozy Comet Domain: ML/Daemon Files: 4 active Mode: Research Window: 30 min Score: 0.85 PREDICT macOS LaunchAgent — launchd.plist at ~/Library/LaunchAgents/com.cozycomet.daemon.plist Auto-starts on login · Zero user interaction · 0% CPU when idle WATCH → BATCH → CLASSIFY → PREDICT
Data Pipeline Diagram

Daemon Lifecycle: File Event → Classify → Predict

COZY COMET DAEMON PIPELINE FILE EVENT Create/Modify Documents 1 WATCHDOG Debounce 2s Batch Collect 2 BATCH Group Events Dedup 3 OLLAMA LLM Classify Context Analysis 4 CONTEXT STORE SQLite Embeddings Vector Index 5 PREDICT Next Action Suggestion 6 Feedback Loop → Improve Predictions DAEMON LIFECYCLE TIMELINE Idle Watch Batch Classify Store Predict Wait ~2-5s per cycle N Step Flow Phase (floating) State
Deployment Topology

Local macOS Daemon Architecture

LOCAL DAEMON ARCHITECTURE MACOS SYSTEM COZY COMET DAEMON launchd Service Background Process ~60MB RAM OLLAMA SERVER Local LLM Service HTTP API ~4GB RAM SQLITE Vector Store Context DB ~100MB FILESYSTEM WATCH TARGETS ~/Documents ~/Desktop ~/Code Obsidian Vault HTTP SQL Daemon Ollama SQLite IPC
Technology Stack

Lightweight Daemon Stack for On-Device Context

Language
Python 3.11
Filesystem
watchdog (FSEvents)
AI
Ollama (local LLM) Llama 3 / Mistral
Platform
macOS LaunchAgent launchd.plist FSEvents
Architecture Decision Records

Key Engineering Decisions

ADR-001
watchdog over Manual Polling

Using watchdog with FSEvents provides OS-level filesystem events — zero CPU when idle, instant change detection, no polling overhead. Manual polling (e.g., os.scandir on a timer) would consume CPU continuously, introduce latency between change and detection, and miss short-lived temporary files. watchdog's event-driven model aligns with the daemon's "always on, never notice" design goal.

ADR-002
Local Ollama over Cloud API

Running Ollama locally ensures privacy — no file content or contextual summaries ever leave the machine. It also eliminates API costs, works offline (flights, trains, remote areas), and provides sub-100ms inference for batched classifications using smaller models (Llama 3 8B, Mistral 7B). A cloud API would introduce latency, require internet, charge per-token, and leak sensitive work context to a third party.

ADR-003
LaunchAgent over cron — macOS-native lifecycle management, GUI for enable/disable, automatic restart on crash

launchd provides macOS-native daemon lifecycle management: automatic restart on crash (KeepAlive), logging via standard OS channels (console, log stream), and a GUI via launchctl for enable/disable without editing crontab files. cron jobs run with minimal environment and no access to the user's keychain, display server, or accessibility permissions — all of which Cozy Comet needs for filesystem observation and context inference. launchd jobs inherit the user's session environment, start at login before the user's shell scripts run, and provide proper process supervision: if the daemon crashes, launchd restarts it within seconds. The plist configuration is declarative XML checked into version control alongside the code, making deployment reproducible.

Session Timeline

Three Sessions from Proof of Concept to Daemon

29
Organize doc folder by context
Initial proof of concept for file organization — experimenting with watchdog event capture, building the batch classification pipeline, and testing Ollama integration for categorizing file changes by project/domain.
28
LaunchAgent daemon design
Designing the startup daemon — creating the launchd.plist configuration, structuring the Python daemon to run as a background LaunchAgent, implementing FSEvents observation of Desktop and Documents, and defining the rolling context window architecture.
10
Greeting and check-in
Basic interaction and status check on the Cozy Comet codebase — reviewing the daemon architecture, verifying LaunchAgent configuration, and confirming the classification pipeline works end-to-end.
Outcome & Impact

Passive Context-Aware Computing on macOS

3
Sessions
2
Key Decisions (ADRs)
3
Tech Stack Components
1
Deployed Daemon

Fully functional LaunchAgent that auto-starts on boot, watches Desktop and Documents for file changes, batches and classifies changes by project/domain via local Ollama, and maintains a rolling context window. The daemon runs with zero user interaction required — install the plist once, and it quietly observes and predicts working context from that point forward.

Industry alignment: Cozy Comet mirrors the trajectory of Apple Intelligence and contextual computing — using local on-device AI to understand user context without sending data to the cloud. The passive observation loop (watch → classify → predict) is an active learning system that improves as more context accumulates, similar to how Apple's on-device intelligence learns user patterns while preserving privacy.