Skip to content

feat: v0.4.0 — Agent Status Line Integration#2

Merged
moose-lab merged 2 commits into
mainfrom
feat/v0.4.0-statusline
Mar 17, 2026
Merged

feat: v0.4.0 — Agent Status Line Integration#2
moose-lab merged 2 commits into
mainfrom
feat/v0.4.0-statusline

Conversation

@moose-lab

Copy link
Copy Markdown
Owner

Summary

DevLog v0.4.0 adds Claude Code status bar integration, letting DevLog display real-time cost and activity data in the terminal's status line area. The core challenge was performance: scanning 2000+ JSONL files takes >1s, but the status bar requires <300ms response.

What was done

Part A: Cache Infrastructure

  • Added StatsCache interface to src/core/types.ts with today/allTime stats and cache freshness metadata (todayDate for day-change invalidation, timestamp for 5-minute TTL)
  • Created src/core/cache.ts (~60 lines): atomic write via .tmp + rename, isCacheFresh() with day-change detection, updateCacheFromStats() helper to populate cache from full scans
  • Created src/core/fast-discovery.ts (~70 lines): uses fs.stat() mtime to skip files not modified today, then calls existing scanSession() only on today's files — reduces scan set from 2000+ to ~10-50 files
  • Hooked dashboard.ts and stats.ts to call updateCacheFromStats() as a side effect of their full scans (piggyback caching)

Part B: The statusline Command

  • Created src/commands/statusline.ts (~100 lines):
    • Reads stdin via Promise.race with 50ms timeout (Claude Code pipes session JSON)
    • Cache-first: if fresh cache exists, outputs immediately
    • Falls back to fast-discovery for today stats when cache is stale
    • Outputs plain text only (no ANSI/chalk — Claude Code handles styling)
    • Format: $2.10 this session · $12.34 today (7 sessions) · $2,906 total
  • Registered statusline command in cli.ts with --no-cache option

Part C: Setup Automation

  • Created src/commands/setup-statusline.ts (~55 lines):
    • Auto-detects devlog binary path via which
    • Reads and merges ~/.claude/settings.json (preserving existing settings)
    • Sets statusLine: { type: "command", command: "devlog statusline" }
    • Warms the cache with a full discovery scan on first setup
  • Registered setup-statusline command in cli.ts

Part D: Polish

  • Exported cache.ts and fast-discovery.ts from src/index.ts
  • Added "Agent Integration" section to help text
  • Version bumped to 0.4.0 across cli.ts, dashboard.ts, package.json

Performance Results

Mode Time
Cached (hot) ~200ms
Fast-discovery (today only) ~300-500ms
Full scan (2688 sessions) >1s

Files Changed

File Action Lines
src/core/types.ts Modified +20 (StatsCache interface)
src/core/cache.ts New ~60 lines
src/core/fast-discovery.ts New ~70 lines
src/commands/statusline.ts New ~100 lines
src/commands/setup-statusline.ts New ~55 lines
src/commands/dashboard.ts Modified +2 lines
src/commands/stats.ts Modified +6 lines
src/cli.ts Modified +36 lines
src/index.ts Modified +2 lines
package.json Modified version bump

Test Plan

  • npx tsup builds without errors
  • npx tsc --noEmit type-checks clean
  • devlog statusline outputs plain text status line (standalone mode)
  • echo '{"costUSD": 0.5}' | devlog statusline outputs with session data from stdin
  • devlog statusline --no-cache forces fresh scan
  • devlog dashboard still works, cache gets updated
  • devlog --version shows 0.4.0
  • devlog --help shows Agent Integration section
  • Performance: time devlog statusline ~200ms (cached)

🤖 Generated with Claude Code

GeeMoose and others added 2 commits March 5, 2026 17:28
Add Claude Code status bar support so DevLog can display real-time
cost and activity data in the terminal's status line area.

New files:
- src/core/cache.ts — Stats cache with atomic writes and freshness tracking
- src/core/fast-discovery.ts — Today-only fast scan using fs.stat() mtime filtering
- src/commands/statusline.ts — Plain-text status line output (stdin-aware)
- src/commands/setup-statusline.ts — Auto-configure ~/.claude/settings.json

Modified files:
- src/core/types.ts — Added StatsCache interface
- src/commands/dashboard.ts — Piggyback cache update after full scan
- src/commands/stats.ts — Piggyback cache update after full scan
- src/cli.ts — Register statusline + setup-statusline commands, update help text
- src/index.ts — Export cache and fast-discovery modules
- package.json — Version bump to 0.4.0

Performance: statusline responds in ~200ms (cached) vs >1s full scan,
achieved by caching + scanning only today-modified JSONL files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Claude Code sends {context_window, model, turn_number, session_id}
via stdin, not {costUSD}. Updated StdinSession interface and
formatStatusLine to show context window usage percentage.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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