Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions .agents/scripts/pulse-session-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ export PATH="/bin:/usr/bin:/usr/local/bin:/opt/homebrew/bin:${PATH}"

# Source config-helper for _jsonc_get (shared JSONC config reader)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=config-helper.sh
# shellcheck source=/dev/null
source "${SCRIPT_DIR}/config-helper.sh" 2>/dev/null || true

# Configuration
readonly SESSION_FLAG="${HOME}/.aidevops/logs/pulse-session.flag"
readonly STOP_FLAG="${HOME}/.aidevops/logs/pulse-session.stop"
readonly LOGFILE="${HOME}/.aidevops/logs/pulse.log"
readonly WRAPPER_LOGFILE="${HOME}/.aidevops/logs/pulse-wrapper.log"
readonly PIDFILE="${HOME}/.aidevops/logs/pulse.pid"
readonly MAX_WORKERS_FILE="${HOME}/.aidevops/logs/pulse-max-workers"
readonly REPOS_JSON="${HOME}/.config/aidevops/repos.json"
Expand Down Expand Up @@ -135,14 +136,16 @@ get_pulse_repo_count() {
# Get last pulse timestamp from log
#######################################
get_last_pulse_time() {
if [[ -f "$LOGFILE" ]]; then
local last_line
last_line=$(grep 'Starting pulse at' "$LOGFILE" | tail -1)
if [[ -n "$last_line" ]]; then
echo "$last_line" | grep -oE '[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z' | tail -1
return 0
local candidate_log last_line
for candidate_log in "$WRAPPER_LOGFILE" "$LOGFILE"; do
if [[ -f "$candidate_log" ]]; then
last_line=$(grep 'Starting pulse at' "$candidate_log" | tail -1)
if [[ -n "$last_line" ]]; then
echo "$last_line" | grep -oE '[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z' | tail -1
return 0
fi
fi
fi
done
echo "never"
return 0
}
Expand Down
21 changes: 20 additions & 1 deletion .agents/scripts/pulse-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,27 @@ export PATH="/bin:/usr/bin:/usr/local/bin:/opt/homebrew/bin:${PATH}"
# resolves correctly whether the script is executed directly (bash) or sourced
# from zsh. See GH#3931.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)" || return 2>/dev/null || exit
# shellcheck source=/dev/null
source "${SCRIPT_DIR}/config-helper.sh" 2>/dev/null || true
# shellcheck source=/dev/null
source "${SCRIPT_DIR}/shared-constants.sh"
# shellcheck source=/dev/null
source "${SCRIPT_DIR}/worker-lifecycle-common.sh"

if ! type config_get >/dev/null 2>&1; then
CONFIG_GET_FALLBACK_WARNED=0
config_get() {
local requested_key="$1"
local default_value="$2"
if [[ "$CONFIG_GET_FALLBACK_WARNED" -eq 0 ]]; then
printf '[pulse-wrapper] WARN: config_get fallback active; config-helper unavailable, so default config values are being applied starting with key "%s"\n' "$requested_key" >&2
CONFIG_GET_FALLBACK_WARNED=1
fi
printf '%s\n' "$default_value"
return 0
}
fi

#######################################
# Configuration
#######################################
Expand Down Expand Up @@ -98,6 +116,7 @@ SESSION_COUNT_WARN=$(_validate_int SESSION_COUNT_WARN "$SESSION_COUNT_WARN" 5 1)

PIDFILE="${HOME}/.aidevops/logs/pulse.pid"
LOGFILE="${HOME}/.aidevops/logs/pulse.log"
WRAPPER_LOGFILE="${HOME}/.aidevops/logs/pulse-wrapper.log"
SESSION_FLAG="${HOME}/.aidevops/logs/pulse-session.flag"
STOP_FLAG="${HOME}/.aidevops/logs/pulse-session.stop"
OPENCODE_BIN="${OPENCODE_BIN:-$(command -v opencode 2>/dev/null || echo "opencode")}"
Expand Down Expand Up @@ -1260,7 +1279,7 @@ check_session_count() {
run_pulse() {
local start_epoch
start_epoch=$(date +%s)
echo "[pulse-wrapper] Starting pulse at $(date -u +%Y-%m-%dT%H:%M:%SZ)" >>"$LOGFILE"
echo "[pulse-wrapper] Starting pulse at $(date -u +%Y-%m-%dT%H:%M:%SZ)" >>"$WRAPPER_LOGFILE"

# Build the prompt: /pulse + pre-fetched state
local prompt="/pulse"
Expand Down
Loading