How hjiaxjason/pulse works
Purpose and Entry Point
Pulse is a Rust CLI for recording work activity and periodic “nudge” completions (such as water or stretching), then summarizing them for today or the current week. The executable starts in src/main.rs, parses commands through src/cli.rs, and routes them via src/commands/mod.rs.
Command Boundary
User-facing operations are organized as command handlers:
• Manual activity logging: src/commands/log.rs
• Daily and weekly reporting: src/commands/today.rs, src/commands/week.rs
• Nudge configuration inspection: src/commands/config.rs
• Installation-related behavior: src/commands/install.rs
CLI parsing is separated from command implementation, keeping argument interpretation in src/cli.rs and domain actions in the command modules.
Configuration Model
Nudge definitions are loaded from the user’s Pulse configuration, documented as ~/.config/pulse/config.toml. src/config.rs owns configuration representation and loading; src/commands/config.rs exposes it to the CLI. Configured nudge names and intervals drive the recurring activity behavior rather than being hard-coded.
Persistent State and Logging
Pulse distinguishes durable application state from log operations:
• src/state.rs manages persisted state needed to determine nudge timing/completion.
• src/log.rs defines recording and retrieval of manual entries and completed nudges.
• src/commands/log.rs converts explicit user input into log records.
The reporting commands consume the combined log history: manual entries plus nudge completions.
Scheduling and Tick Flow
src/tick.rs represents the recurring evaluation cycle: it checks configured intervals against persisted state and determines when nudges should be handled or recorded. This is the core boundary between static configuration (src/config.rs), prior activity (src/state.rs), and runtime prompting/notification behavior.
Background Runtime / macOS Integration
Daemon support is isolated under src/daemon/mod.rs; src/daemon/macos.rs provides the macOS-specific implementation. This platform boundary allows the CLI and core scheduling/logging logic to remain separate from operating-system background execution mechanisms.
Primary Control Flow
1. src/main.rs starts Pulse and invokes CLI dispatch.
2. src/cli.rs selects a handler in src/commands/.
3. Logging commands write activity through src/log.rs; configuration and state are read as required.
4. Daemon/tick execution uses src/tick.rs with src/config.rs and src/state.rs to evaluate recurring nudges.
5. today and week commands query log data and present period-specific summaries.
Main entry points: mod.rs Command handlers · tick.rs Nudge evaluation · log.rs Activity log · config.rs Configuration loader
Components 15
CLI & Commands
- Pulse executable
src/main.rs - CLI parser & dispatch
src/cli.rs - Command handlers
src/commands/mod.rs - Manual logging
src/commands/log.rs - Today report
src/commands/today.rs - Week report
src/commands/week.rs - Config inspection
src/commands/config.rs - Installation behavior
src/commands/install.rs
Core Data
- User nudge config · Defines nudge names and intervals.
- Configuration loader
src/config.rs - Persisted nudge state · Tracks timing and completion state.
src/state.rs - Activity log · Records and retrieves manual entries and nudge completions.
src/log.rs
Recurring Runtime
- Nudge evaluation
src/tick.rs - Background daemon
src/daemon/mod.rs - macOS daemon
src/daemon/macos.rs
Connections 17
- Pulse executable → CLI parser & dispatch: invokes
- CLI parser & dispatch → Command handlers: routes to
- Command handlers → Manual logging: includes
- Command handlers → Today report: includes
- Command handlers → Week report: includes
- Command handlers → Config inspection: includes
- Command handlers → Installation behavior: includes
- Manual logging → Activity log: writes entries
- Today report → Activity log: queries
- Week report → Activity log: queries
- Config inspection → Configuration loader: reads
- User nudge config → Configuration loader: loaded by
- Background daemon → Nudge evaluation: runs
- macOS daemon → Background daemon: implements
- Nudge evaluation → Configuration loader: uses intervals
- Nudge evaluation → Persisted nudge state: checks and updates
- Nudge evaluation → Activity log: records completions