(args: BlocksArgs)
| 268 | } |
| 269 | |
| 270 | pub(crate) fn run_blocks(args: BlocksArgs) -> Result<()> { |
| 271 | if args.session_length <= 0.0 { |
| 272 | return Err(crate::cli_error("Session length must be a positive number")); |
| 273 | } |
| 274 | let shared = args.shared.clone(); |
| 275 | let entries = load_entries(&shared, None)?; |
| 276 | let mut blocks = identify_session_blocks(entries, args.session_length); |
| 277 | filter_blocks_by_date(&mut blocks, &shared); |
| 278 | sort_blocks(&mut blocks, &shared.order); |
| 279 | |
| 280 | if args.recent { |
| 281 | let cutoff = utc_now() |
| 282 | .checked_sub_millis(DEFAULT_RECENT_DAYS * MILLIS_PER_DAY) |
| 283 | .unwrap_or(TimestampMs::UNIX_EPOCH); |
| 284 | blocks.retain(|block| block.start_time >= cutoff || block.is_active); |
| 285 | } |
| 286 | |
| 287 | if args.active { |
| 288 | blocks.retain(|block| block.is_active); |
| 289 | } |
| 290 | |
| 291 | let max_tokens = blocks |
| 292 | .iter() |
| 293 | .filter(|block| !block.is_gap && !block.is_active) |
| 294 | .map(|block| block.token_counts.total()) |
| 295 | .max() |
| 296 | .unwrap_or(0); |
| 297 | |
| 298 | if wants_json(&shared) { |
| 299 | let output = json!({ |
| 300 | "blocks": blocks.iter().map(|block| block_json(block, args.token_limit.as_deref(), max_tokens)).collect::<Vec<_>>(), |
| 301 | }); |
| 302 | print_json_or_jq(output, shared.jq.as_deref(), shared.no_cost)?; |
| 303 | return Ok(()); |
| 304 | } |
| 305 | |
| 306 | if args.active && blocks.is_empty() { |
| 307 | println!("No active session block found."); |
| 308 | return Ok(()); |
| 309 | } |
| 310 | if args.active && blocks.len() == 1 { |
| 311 | print_active_block_detail(&blocks[0], args.token_limit.as_deref(), max_tokens, &shared); |
| 312 | return Ok(()); |
| 313 | } |
| 314 | print_blocks_table(&blocks, args.token_limit.as_deref(), max_tokens, &shared)?; |
| 315 | Ok(()) |
| 316 | } |
| 317 | |
| 318 | pub(crate) fn run_statusline(args: StatuslineArgs) -> Result<()> { |
| 319 | if args.context_low_threshold >= args.context_medium_threshold { |
no test coverage detected