deepflow 0.1.57 → 0.1.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/deepflow-auto.sh +23 -26
- package/package.json +1 -1
package/bin/deepflow-auto.sh
CHANGED
|
@@ -184,6 +184,8 @@ run_claude_monitored() {
|
|
|
184
184
|
|
|
185
185
|
local result_tmp
|
|
186
186
|
result_tmp="$(mktemp)"
|
|
187
|
+
local error_log
|
|
188
|
+
error_log="$(mktemp)"
|
|
187
189
|
|
|
188
190
|
# Outer loop: may restart with --resume when threshold is hit
|
|
189
191
|
while true; do
|
|
@@ -200,37 +202,22 @@ run_claude_monitored() {
|
|
|
200
202
|
local threshold_hit=false
|
|
201
203
|
local claude_pid=""
|
|
202
204
|
|
|
203
|
-
#
|
|
204
|
-
if [[ -n "$session_id" ]]; then
|
|
205
|
-
# When resuming, no prompt is piped
|
|
206
|
-
"${cmd_args[@]}" < /dev/null 2>/dev/null &
|
|
207
|
-
claude_pid=$!
|
|
208
|
-
else
|
|
209
|
-
echo "$prompt_text" | "${cmd_args[@]}" 2>/dev/null &
|
|
210
|
-
claude_pid=$!
|
|
211
|
-
fi
|
|
212
|
-
|
|
213
|
-
# Read stdout from the backgrounded process via /dev/fd — we need a pipe.
|
|
214
|
-
# Re-architect: use a FIFO so we can read line-by-line while also holding
|
|
215
|
-
# the PID for killing.
|
|
216
|
-
# Kill the background process we just started (we'll redo with a FIFO).
|
|
217
|
-
kill "$claude_pid" 2>/dev/null || true
|
|
218
|
-
wait "$claude_pid" 2>/dev/null || true
|
|
219
|
-
|
|
205
|
+
# Use a FIFO so we can read line-by-line while holding the PID for killing
|
|
220
206
|
local fifo_path
|
|
221
207
|
fifo_path="$(mktemp -u)"
|
|
222
208
|
mkfifo "$fifo_path"
|
|
223
209
|
|
|
224
210
|
if [[ -n "$session_id" ]]; then
|
|
225
|
-
"${cmd_args[@]}" < /dev/null > "$fifo_path" 2
|
|
211
|
+
"${cmd_args[@]}" < /dev/null > "$fifo_path" 2>>"$error_log" &
|
|
226
212
|
claude_pid=$!
|
|
227
213
|
else
|
|
228
|
-
echo "$prompt_text" | "${cmd_args[@]}" > "$fifo_path" 2
|
|
214
|
+
echo "$prompt_text" | "${cmd_args[@]}" > "$fifo_path" 2>>"$error_log" &
|
|
229
215
|
claude_pid=$!
|
|
230
216
|
fi
|
|
231
217
|
|
|
232
218
|
# Read the FIFO line-by-line
|
|
233
|
-
|
|
219
|
+
local capturing_result=false
|
|
220
|
+
while IFS= read -r line || [[ -n "$line" ]]; do
|
|
234
221
|
[[ -z "$line" ]] && continue
|
|
235
222
|
|
|
236
223
|
local parsed
|
|
@@ -271,14 +258,13 @@ run_claude_monitored() {
|
|
|
271
258
|
context_window="${pline#CONTEXT_WINDOW:}"
|
|
272
259
|
;;
|
|
273
260
|
RESULT_START)
|
|
274
|
-
|
|
275
|
-
local capturing_result=true
|
|
261
|
+
capturing_result=true
|
|
276
262
|
;;
|
|
277
263
|
RESULT_END)
|
|
278
264
|
capturing_result=false
|
|
279
265
|
;;
|
|
280
266
|
*)
|
|
281
|
-
if [[ "$
|
|
267
|
+
if [[ "$capturing_result" == "true" ]]; then
|
|
282
268
|
echo "$pline" >> "$result_tmp"
|
|
283
269
|
fi
|
|
284
270
|
;;
|
|
@@ -310,6 +296,12 @@ run_claude_monitored() {
|
|
|
310
296
|
# Wait for claude process to finish (if it hasn't been killed)
|
|
311
297
|
wait "$claude_pid" 2>/dev/null || true
|
|
312
298
|
|
|
299
|
+
# Log stderr if any
|
|
300
|
+
if [[ -s "$error_log" ]]; then
|
|
301
|
+
auto_log "claude stderr: $(cat "$error_log")"
|
|
302
|
+
: > "$error_log"
|
|
303
|
+
fi
|
|
304
|
+
|
|
313
305
|
if [[ "$threshold_hit" == "true" && -n "$current_session_id" ]]; then
|
|
314
306
|
# Restart with --resume and the captured session_id
|
|
315
307
|
session_id="$current_session_id"
|
|
@@ -323,6 +315,8 @@ run_claude_monitored() {
|
|
|
323
315
|
break
|
|
324
316
|
done
|
|
325
317
|
|
|
318
|
+
rm -f "$error_log"
|
|
319
|
+
|
|
326
320
|
# Write final context.json
|
|
327
321
|
if [[ "$context_window" -gt 0 && "$total_tokens" -gt 0 ]]; then
|
|
328
322
|
local final_pct=$(( total_tokens * 100 / context_window ))
|
|
@@ -466,10 +460,13 @@ run_single_spike() {
|
|
|
466
460
|
if [[ -d "$worktree_path" ]]; then
|
|
467
461
|
auto_log "Worktree already exists at ${worktree_path}, reusing"
|
|
468
462
|
else
|
|
469
|
-
|
|
463
|
+
local wt_err
|
|
464
|
+
wt_err="$(git worktree add -b "$branch_name" "$worktree_path" HEAD 2>&1)" || {
|
|
465
|
+
auto_log "worktree add -b failed: ${wt_err}"
|
|
470
466
|
# Branch may already exist from a previous run
|
|
471
|
-
git worktree add "$worktree_path" "$branch_name" 2
|
|
472
|
-
auto_log "ERROR: failed to create worktree for ${slug}"
|
|
467
|
+
wt_err="$(git worktree add "$worktree_path" "$branch_name" 2>&1)" || {
|
|
468
|
+
auto_log "ERROR: failed to create worktree for ${slug}: ${wt_err}"
|
|
469
|
+
echo "Worktree error for ${slug}: ${wt_err}" >&2
|
|
473
470
|
return 1
|
|
474
471
|
}
|
|
475
472
|
}
|