Skip to content

Commit cf8870e

Browse files
authored
Merge pull request #210 from Fr-e-d/contrib/sync-1776862608
sync: update 2 file(s) in core/
2 parents b06ada3 + 737db35 commit cf8870e

2 files changed

Lines changed: 44 additions & 36 deletions

File tree

.gaai/core/scripts/daemon-monitor-tail.sh

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -89,45 +89,42 @@ parse_log() {
8989
tool_count=$(grep -c '"type":"tool_use"' "$log_file" 2>/dev/null || echo 0)
9090
fi
9191

92-
# ── Last activity: main agent + sub-agent (implement / QA), same compact format ──
93-
# jq filter: per-tool arg formatting (basename ONLY for file_path-based tools,
94-
# raw command for Bash — avoids "null" from `split("/") | last` on `2>/dev/null`).
95-
local JQ_TOOL_LINE='
96-
def clean: tostring | gsub("\n"; " ") | gsub(" +"; " ");
97-
def arg:
98-
if .name == "Bash" then (.input.command // "" | clean)
99-
elif .name == "Grep" then (.input.pattern // "" | clean)
100-
elif (.name == "Read" or .name == "Edit" or .name == "Write" or .name == "NotebookEdit") then ((.input.file_path // "" | clean) | split("/") | .[-1] // "")
101-
elif .name == "Task" then (.input.description // "" | clean)
102-
elif .name == "TodoWrite" then "(todos updated)"
103-
else ((.input.description // .input.file_path // .input.command // .input.query // "") | clean) end;
104-
"\(.name) \(arg)"
105-
'
106-
local last_main="" last_sub=""
92+
# ── Last activity (single line — whichever of main or sub-agent was most recent) ──
93+
# Sub-agent origin = either (a) Task tool sub-agent: same session, parent_tool_use_id != null,
94+
# or (b) nested `claude -p` (Implement Agent via nested-claude-spawn.js --log-file):
95+
# DIFFERENT session_id than the root delivery session.
96+
# Root session_id = first session_id seen in the log (init event).
97+
local last_event="" last_origin="" last_text="" root_sid=""
10798
if $HAS_JQ; then
108-
# Main: task_progress.description first, fall back to compact tool_use
109-
last_main=$(tail -500 "$log_file" 2>/dev/null \
110-
| jq -r 'select(.type=="system" and .subtype=="task_progress" and (.parent_tool_use_id // null) == null) | .description // empty' 2>/dev/null \
99+
root_sid=$(head -5 "$log_file" 2>/dev/null \
100+
| jq -r '.session_id // empty' 2>/dev/null \
101+
| head -1 || true)
102+
last_event=$(tail -500 "$log_file" 2>/dev/null \
103+
| jq -r --arg root_sid "$root_sid" '
104+
def clean: tostring | gsub("\n"; " ") | gsub(" +"; " ");
105+
def arg:
106+
if .name == "Bash" then (.input.command // "" | clean)
107+
elif .name == "Grep" then (.input.pattern // "" | clean)
108+
elif (.name == "Read" or .name == "Edit" or .name == "Write" or .name == "NotebookEdit") then ((.input.file_path // "" | clean) | split("/") | .[-1] // "")
109+
elif .name == "Task" then (.input.description // "" | clean)
110+
elif .name == "TodoWrite" then "(todos updated)"
111+
else ((.input.description // .input.file_path // .input.command // .input.query // "") | clean) end;
112+
. as $m |
113+
(if (($m.parent_tool_use_id // null) == null) and (($m.session_id // "") == $root_sid) then "MAIN" else "SUB" end) as $origin |
114+
if ($m.type=="system" and $m.subtype=="task_progress") then
115+
$origin + "\t" + ($m.description // "")
116+
elif $m.type=="assistant" then
117+
$m.message.content[]? | select(.type=="tool_use") | $origin + "\t" + .name + " " + arg
118+
else empty end' 2>/dev/null \
111119
| tail -1 || true)
112-
if [[ -z "$last_main" ]]; then
113-
last_main=$(tail -500 "$log_file" 2>/dev/null \
114-
| jq -r "select(.type==\"assistant\" and (.parent_tool_use_id // null) == null) | .message.content[]? | select(.type==\"tool_use\") | $JQ_TOOL_LINE" 2>/dev/null \
115-
| tail -1 || true)
116-
fi
117-
# Sub-agent: same logic, ptuid != null
118-
last_sub=$(tail -500 "$log_file" 2>/dev/null \
119-
| jq -r 'select(.type=="system" and .subtype=="task_progress" and (.parent_tool_use_id // null) != null) | .description // empty' 2>/dev/null \
120-
| tail -1 || true)
121-
if [[ -z "$last_sub" ]]; then
122-
last_sub=$(tail -500 "$log_file" 2>/dev/null \
123-
| jq -r "select(.type==\"assistant\" and (.parent_tool_use_id // null) != null) | .message.content[]? | select(.type==\"tool_use\") | $JQ_TOOL_LINE" 2>/dev/null \
124-
| tail -1 || true)
125-
fi
120+
last_origin="${last_event%%$'\t'*}"
121+
last_text="${last_event#*$'\t'}"
126122
else
127-
last_main=$(tail -200 "$log_file" 2>/dev/null \
123+
last_text=$(tail -200 "$log_file" 2>/dev/null \
128124
| grep -o '"type":"tool_use"[^}]*"name":"[^"]*"' \
129125
| tail -1 \
130126
| sed 's/.*"name":"\([^"]*\)".*/\1/' 2>/dev/null || true)
127+
last_origin="MAIN"
131128
fi
132129

133130
# ── Cost ──
@@ -146,9 +143,15 @@ parse_log() {
146143
fi
147144

148145
echo -e " ${color}${health_icon}${NC} ${tool_count} tools | Last update: ${color}${age_label} ago${NC}${duration_label:+ | Running: ${duration_label}}${cost:+ | \$${cost}}"
149-
# Use printf %s for data so literal "\n" in Bash commands stays literal (not interpreted)
150-
[[ -n "$last_main" ]] && printf ' %b→ %s%b\n' "$DIM" "$last_main" "$NC"
151-
[[ -n "$last_sub" ]] && printf ' %b ↳ %s%b\n' "$DIM" "$last_sub" "$NC"
146+
# Single activity line — prefix switches based on origin (main delivery vs nested sub-agent).
147+
# printf %s keeps literal "\n" in Bash commands literal (echo -e would interpret them).
148+
if [[ -n "$last_text" ]]; then
149+
if [[ "$last_origin" == "SUB" ]]; then
150+
printf ' %b↳ %s%b\n' "$DIM" "$last_text" "$NC"
151+
else
152+
printf ' %b→ %s%b\n' "$DIM" "$last_text" "$NC"
153+
fi
154+
fi
152155
}
153156

154157
while true; do

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
---
99

10+
## [Unreleased]
11+
12+
### Changed
13+
- fix(daemon-monitor): classify nested claude -p (Implement Agent) as sub-agent
14+
1015
## [2.19.0] - 2026-04-22
1116

1217
### Changed

0 commit comments

Comments
 (0)