Skip to main content

Module utils

Module utils 

Source

Functions§

detect_package_manager
Detect the package manager used in the current directory. Returns “pnpm”, “yarn”, or “npm” based on lockfile presence.
exit_code_from_output
Extract exit code from a process output. Returns the actual exit code, or 128 + signal per Unix convention when terminated by a signal (no exit code available). Falls back to 1 on non-Unix platforms.
exit_code_from_status
Extract exit code from an ExitStatus (for .status() calls, not .output()). Returns the actual exit code, or 128 + signal per Unix convention when terminated by a signal. Falls back to 1 on non-Unix platforms.
fallback_tail
Return the last n lines of output with a label, for use as a fallback when filter parsing fails. Logs a diagnostic to stderr.
format_cpt
Format cost-per-token as $/MTok (e.g., “$3.86/MTok”)
format_tokens
Executes a command and returns cleaned stdout/stderr.
format_usd
Formats a USD amount with adaptive precision.
human_bytes
Convert bytes to human-readable format (KB, MB, GB, TB). Used for S3 object sizes.
join_with_overflow
Join items into a newline-separated string, appending an overflow hint when total > max.
ok_confirmation
Format a confirmation message: “ok <action> <detail>” Used for write operations (merge, create, comment, edit, etc.)
package_manager_exec
Build a Command using the detected package manager’s exec mechanism. Returns a Command ready to have tool-specific args appended.
resolve_binary
Resolve a binary name to its full path, honoring PATHEXT on Windows.
resolved_command
Create a Command with PATHEXT-aware binary resolution.
ruby_exec
Build a Command for Ruby tools, auto-detecting bundle exec. Uses bundle exec <tool> when a Gemfile exists (transitive deps like rake won’t appear in the Gemfile but still need bundler for version isolation).
shorten_arn
Extract short name from AWS ARN. Example: arn:aws:ecs:region:acct:service/cluster/name -> name For simple ARNs like arn:aws:iam::123:user/alice, returns alice.
strip_ansi
Strip ANSI escape codes (colors, styles) from a string.
tool_exists
Check if a tool exists on PATH (PATHEXT-aware on Windows).
truncate
Truncates a string to max_len characters, appending ... if needed.
truncate_iso_date
Truncate an ISO 8601 datetime string to just the date portion (first 10 chars).