Repository navigation
Closed
Description
Problem
When running repetitive or batch tasks across many files (e.g., generating documentation, migrating syntax, running code audits, or batch-refactoring dozens of files), relying on an LLM supervisor loop to iterate over file lists is fragile and inefficient:
- Supervisor Fatigue & Cognitive Drift: Across 20+ files, agent supervisors frequently lose track of their position, re-process already completed files, or terminate prematurely.
- Excessive Round-Trip Latency: A supervisory agent delegating to worker subagents incurs multi-turn coordination overhead (delegating -> checking worker status -> re-reading the written file to verify -> deciding next file), turning a 2-turn job into 7+ round-trips (~90s per file on local models).
- Context Accumulation & State Leaks: Without deterministic boundaries, conversation messages, cached file chunks (
MessageTag.READONLY_FILES), and internal resource sets (abs_read_only_fnames) accumulate across iterations, causing prompt sizes to balloon into context exhaustion.
Proposed Solution
Introduce a native /foreach slash command for deterministic, crash-resilient batch execution:
/foreach [options] <glob_pattern> [::] <prompt_template>Key Capabilities:
- Glob & Path Resolution:
- Matches filesystem paths using glob expressions (e.g.
src/**/*.pyorpine_sources/PBK_*.pine). - Populates template placeholders:
{file},{path},{filename},{stem},{dir},{index}, and{total}. - Uses
safe_substitute()to allow JSON strings containing literal curly braces in prompts (e.g.{"read_only": ["{file}"]}) without formatting errors.
- Matches filesystem paths using glob expressions (e.g.
- Zero-Overhead Idempotency (
-u/--unless-exists <path>):- Checks if evaluated output path already exists before initiating an inference turn. If the target exists, it skips execution in microseconds.
- Makes batch workloads completely crash-resilient: re-running resumes immediately from the first incomplete item.
- Holistic Context & Cache Isolation (
-c/--clear):- Ensures an isolated slate for every iteration.
- Clears message tags (
CUR,DONE,DIFFS,FILE_CONTEXTS,READONLY_FILES,CHAT_FILES,EDIT_FILES,LINT). - Wipes tracked resource sets (
abs_fnames,abs_read_only_fnames,abs_read_only_stubs_fnames,files_added_in_exploration) and flushes chunk removal buffers so prompt sizes remain lean and constant.
- Safety & Control:
-n <limit>: Process at most N items for testing.--dry-run: Preview candidate matches and substituted prompt templates without executing.--delay <seconds>: Optional pause between iterations to allow GPU cooling or rate limit compliance.- Clean console formatting without escaped markup or terminal artifacts.
Metadata
Metadata
Assignees
Labels
No labels
Activity