deepflow 0.1.64 → 0.1.65
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 +10 -21
- package/package.json +1 -1
package/bin/deepflow-auto.sh
CHANGED
|
@@ -168,32 +168,28 @@ discover_specs() {
|
|
|
168
168
|
# Context-monitored claude -p wrapper
|
|
169
169
|
# ---------------------------------------------------------------------------
|
|
170
170
|
|
|
171
|
-
# run_claude_monitored <working_dir> <prompt_text>
|
|
171
|
+
# run_claude_monitored <working_dir> <prompt_text>
|
|
172
172
|
#
|
|
173
173
|
# Runs `claude -p --output-format stream-json` and monitors token usage in
|
|
174
174
|
# real time. If usage reaches CONTEXT_THRESHOLD_PCT% of the context window the
|
|
175
|
-
# process is killed and
|
|
176
|
-
#
|
|
175
|
+
# process is killed and restarted with a fresh context (same prompt, clean
|
|
176
|
+
# session). Prior work persists in the worktree via committed files.
|
|
177
177
|
#
|
|
178
178
|
# The final result text is written to stdout. A side-effect context.json is
|
|
179
179
|
# written to <working_dir>/.deepflow/context.json for statusline consumption.
|
|
180
180
|
run_claude_monitored() {
|
|
181
181
|
local working_dir="$1"
|
|
182
182
|
local prompt_text="$2"
|
|
183
|
-
local session_id="${3:-}"
|
|
184
183
|
|
|
185
184
|
local result_tmp
|
|
186
185
|
result_tmp="$(mktemp)"
|
|
187
186
|
local error_log
|
|
188
187
|
error_log="$(mktemp)"
|
|
189
188
|
|
|
190
|
-
# Outer loop:
|
|
189
|
+
# Outer loop: restart with fresh context when threshold is hit
|
|
191
190
|
while true; do
|
|
192
191
|
# Build command arguments
|
|
193
192
|
local -a cmd_args=(claude -p --output-format stream-json --dangerously-skip-permissions)
|
|
194
|
-
if [[ -n "$session_id" ]]; then
|
|
195
|
-
cmd_args+=(--resume --session-id "$session_id")
|
|
196
|
-
fi
|
|
197
193
|
|
|
198
194
|
# Accumulated token count and context window size across events
|
|
199
195
|
local total_tokens=0
|
|
@@ -207,13 +203,8 @@ run_claude_monitored() {
|
|
|
207
203
|
fifo_path="$(mktemp -u)"
|
|
208
204
|
mkfifo "$fifo_path"
|
|
209
205
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
claude_pid=$!
|
|
213
|
-
else
|
|
214
|
-
echo "$prompt_text" | "${cmd_args[@]}" > "$fifo_path" 2>>"$error_log" &
|
|
215
|
-
claude_pid=$!
|
|
216
|
-
fi
|
|
206
|
+
echo "$prompt_text" | "${cmd_args[@]}" > "$fifo_path" 2>>"$error_log" &
|
|
207
|
+
claude_pid=$!
|
|
217
208
|
|
|
218
209
|
# Read the FIFO line-by-line (set +e to tolerate EINTR from signals)
|
|
219
210
|
local capturing_result=false
|
|
@@ -304,12 +295,10 @@ run_claude_monitored() {
|
|
|
304
295
|
: > "$error_log"
|
|
305
296
|
fi
|
|
306
297
|
|
|
307
|
-
if [[ "$threshold_hit" == "true"
|
|
308
|
-
# Restart with
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
context_window=0
|
|
312
|
-
auto_log "Restarting claude -p with --resume session_id=${session_id}"
|
|
298
|
+
if [[ "$threshold_hit" == "true" ]]; then
|
|
299
|
+
# Restart with fresh context — the prompt is re-sent but prior work
|
|
300
|
+
# persists in the worktree (committed files, etc.)
|
|
301
|
+
auto_log "Restarting claude -p with fresh context (prior work is in worktree)"
|
|
313
302
|
continue
|
|
314
303
|
fi
|
|
315
304
|
|