Skip to content

fix: index CLI-created Claude sessions into Web UI#142

Merged
Zhang-Henry merged 1 commit intoOpenLAIR:mainfrom
t2ance:fix/cli-session-discovery-v2
Apr 9, 2026
Merged

fix: index CLI-created Claude sessions into Web UI#142
Zhang-Henry merged 1 commit intoOpenLAIR:mainfrom
t2ance:fix/cli-session-discovery-v2

Conversation

@t2ance
Copy link
Copy Markdown
Collaborator

@t2ance t2ance commented Apr 7, 2026

Summary

Supersedes #93 — rebased on latest main and addresses all review feedback.

CLI sessions created via the claude binary were not visible in the Web UI because they bypass the dr-claw server and write .jsonl files directly to ~/.claude/projects/. This PR adds two hooks to index them:

  • Startup reconcile: on server boot, scan all registered projects and index any existing CLI sessions into the database
  • File watcher accumulation: during the debounce window, accumulate .jsonl change events and call reconcileClaudeSessionIndex() for each before broadcasting

Changes from #93

All review feedback from @Zhang-Henry addressed:

Feedback Fix
Single reconcileClaudeSessionIndex failure aborts entire batch Per-item try/catch in both watcher and startup loops
pendingClaudeSessionEvents not cleared on watcher reinit Reset alongside projectsWatchers = []
projectName path traversal (., ..) Explicit guard before pushing event
Temp files (.#session.jsonl) pass through sessionId validated with /^[\w-]+$/ regex
console.error('[WARN]') inconsistency All warnings use console.warn
Startup log shows total count even if some failed Track reconciledCount separately

Additionally fixed: reconcileClaudeSessionIndex() full-scan passed limit=0 to getSessions(), which triggered the early-exit optimization immediately (allSessions.size >= 0 is always true). Changed to limit=Infinity so full scans read all .jsonl files.

Test plan

  • Register a project via Web UI
  • Open a CLI session in that project directory (cd /path/to/project && claude)
  • Chat briefly, then exit the CLI session
  • Verify the CLI session appears in the Web UI without manual refresh
  • Restart the server and verify CLI sessions still appear
  • Verify existing Web UI sessions are not affected (display name, starred status preserved)
  • Create two CLI sessions rapidly (within 1 second) and verify both appear

Address code review feedback from OpenLAIR#93:
- Wrap reconcile loops in per-item try/catch to prevent single failure
  from aborting the batch
- Clear pendingClaudeSessionEvents on watcher reinit
- Add path traversal guard for projectName (reject "." and "..")
- Filter temp files with alphanumeric/hyphen regex on sessionId
- Use console.warn instead of console.error for warnings
- Track reconciled count separately from total project count

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Zhang-Henry Zhang-Henry merged commit 5848e3d into OpenLAIR:main Apr 9, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants