fix: ai --last — prefer newer source (auto-capture beats stale pos logs)
gates / consistency-and-conventions (push) Failing after 14s
gates / consistency-and-conventions (push) Failing after 14s
--last now compares mtime of pos dispatcher logs vs captured output (last_cmd_output) and uses whichever is newer, instead of always preferring pos logs even when they are hours old.
This commit is contained in:
+16
-6
@@ -410,12 +410,22 @@ cmd_ask() {
|
||||
# --last: append the most recent logged pos command output AFTER the
|
||||
# question, so the model diagnoses the real failure.
|
||||
if [ "$LAST_MODE" -eq 1 ]; then
|
||||
local log_file=""
|
||||
# Priority 1: most recent pos dispatcher log
|
||||
log_file="$(newest_pos_log 2>/dev/null)" || true
|
||||
# Priority 2: captured output from any command
|
||||
if [ -z "$log_file" ] && [ -s "$LAST_CMD_OUTPUT_FILE" ]; then
|
||||
log_file="$LAST_CMD_OUTPUT_FILE"
|
||||
local log_file="" pos_log="" captured_log=""
|
||||
pos_log="$(newest_pos_log 2>/dev/null)" || true
|
||||
[ -s "$LAST_CMD_OUTPUT_FILE" ] && captured_log="$LAST_CMD_OUTPUT_FILE"
|
||||
# Use whichever source is newer (auto-capture beats stale pos logs)
|
||||
if [ -n "$pos_log" ] && [ -n "$captured_log" ]; then
|
||||
local pos_age=$(( $(date +%s) - $(stat -c %Y "$pos_log") ))
|
||||
local cap_age=$(( $(date +%s) - $(stat -c %Y "$captured_log") ))
|
||||
if [ "$cap_age" -lt "$pos_age" ]; then
|
||||
log_file="$captured_log"
|
||||
else
|
||||
log_file="$pos_log"
|
||||
fi
|
||||
elif [ -n "$captured_log" ]; then
|
||||
log_file="$captured_log"
|
||||
else
|
||||
log_file="$pos_log"
|
||||
fi
|
||||
[ -n "$log_file" ] || err "No recent output found — run 'pos ai gemini capture <cmd>' first, or pipe: cmd 2>&1 | pos ai gemini ask \"what happened\""
|
||||
last_log_annotate "$log_file"
|
||||
|
||||
+16
-6
@@ -412,12 +412,22 @@ cmd_ask() {
|
||||
# --last: append the most recent logged pos command output AFTER the
|
||||
# question, so the model diagnoses the real failure.
|
||||
if [ "$LAST_MODE" -eq 1 ]; then
|
||||
local log_file=""
|
||||
# Priority 1: most recent pos dispatcher log
|
||||
log_file="$(newest_pos_log 2>/dev/null)" || true
|
||||
# Priority 2: captured output from any command
|
||||
if [ -z "$log_file" ] && [ -s "$LAST_CMD_OUTPUT_FILE" ]; then
|
||||
log_file="$LAST_CMD_OUTPUT_FILE"
|
||||
local log_file="" pos_log="" captured_log=""
|
||||
pos_log="$(newest_pos_log 2>/dev/null)" || true
|
||||
[ -s "$LAST_CMD_OUTPUT_FILE" ] && captured_log="$LAST_CMD_OUTPUT_FILE"
|
||||
# Use whichever source is newer (auto-capture beats stale pos logs)
|
||||
if [ -n "$pos_log" ] && [ -n "$captured_log" ]; then
|
||||
local pos_age=$(( $(date +%s) - $(stat -c %Y "$pos_log") ))
|
||||
local cap_age=$(( $(date +%s) - $(stat -c %Y "$captured_log") ))
|
||||
if [ "$cap_age" -lt "$pos_age" ]; then
|
||||
log_file="$captured_log"
|
||||
else
|
||||
log_file="$pos_log"
|
||||
fi
|
||||
elif [ -n "$captured_log" ]; then
|
||||
log_file="$captured_log"
|
||||
else
|
||||
log_file="$pos_log"
|
||||
fi
|
||||
[ -n "$log_file" ] || err "No recent output found — run 'pos ai openrouter capture <cmd>' first, or pipe: cmd 2>&1 | pos ai openrouter ask \"what happened\""
|
||||
last_log_annotate "$log_file"
|
||||
|
||||
Reference in New Issue
Block a user