feat: SessionConnector::watch live import streaming (F4.1) #20
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem Statement
Spec F4.1 (terraphim-agent-session-search-spec.md, lines 293-308) defines
SessionConnector::watch()returningOption<mpsc::Receiver<Session>>so live AI-coding sessions can stream into the index without a full re-import. The current trait incrates/terraphim_sessions/src/connector/mod.rs(lines 88-105) exposes onlysource_id,display_name,detect,default_path, andimport-- there is nowatchmethod on any connector. As a result, REPL users must manually run/sessions importafter each Claude Code or Cursor session, and the Tantivy index (issue #5) cannot receive incremental updates. This blocks the "live cross-tool memory" promise of Phase 2.Acceptance Criteria
async fn watch(&self) -> Option<tokio::sync::mpsc::Receiver<Session>>with a defaultNoneimplementation to theSessionConnectortraitwatchforNativeClaudeConnectorusingnotify(or equivalent) to detect new/modified~/.claude/**/*.jsonlfiles; emitSessionitems as files appear or growConnectorRegistry::watch_all() -> mpsc::Receiver<Session>that fans-in receivers from all registered connectorsSessionService(incrates/terraphim_sessions/src/service.rs) with astart_watcher()helper that spawns a background task draining the merged stream into the cacheAiderConnector,ClineConnector, CLA connectors) keep the defaultNoneimplementation; they are not required to add file watchers in this PRcrates/terraphim_sessions/src/connector/native.rsverifies that creating a new JSONL file under a temp dir produces aSessionon the watch channel within 2 secondscargo test -p terraphim_sessionspassescargo clippy -p terraphim_sessions -- -D warningspassesProposed Approach
Add
watchas a trait method with a default implementation returningNoneso existing connectors do not break. Usetokio::sync::mpsc::channel(64)for backpressure. ForNativeClaudeConnector, spawn anotify::recommended_watcheron the resolved Claude data directory and translateCreate/Modifyevents intoimport_single_file()calls.ConnectorRegistry::watch_all()collects each connector's optional receiver and forwards items through a single output channel usingtokio::spawnper source.Crates affected:
crates/terraphim_sessions-- trait change,NativeClaudeConnector::watch, registry helper, service helperterraphim_agentREPL in this PR; REPL wiring follows in a separate issue)Key types/functions to add:
SessionConnector::watch(trait method, defaultNone)NativeClaudeConnector::watch(concrete impl)ConnectorRegistry::watch_allSessionService::start_watcherDependencies
None. Independent of the open Tantivy index issue (#5); when both are implemented, a follow-up can push streamed sessions directly into Tantivy.
Verification
Manual: in a scratch script, call
ConnectorRegistry::new().watch_all(), thentouch ~/.claude/projects/test/conversation.jsonland confirm aSessionarrives on the channel.Scope
Single PR, ~200-350 LOC including the trait change, one concrete
watchimplementation, registry fan-in, service helper, and the unit test. REPL surface (e.g. a/sessions watchcommand) is intentionally deferred.