Skip to content

feat(commands): add /foreach command for deterministic batch iteration and isolated prompt execution - #745

Merged
dwash96 merged 5 commits into
cecli-dev:v1.13.0from
philippeback:feature/foreach_command
Nov 13, 2026
Merged

dwash96 merged 5 commits into
cecli-dev:v1.13.0from
philippeback:feature/foreach_command

Conversation

@philippeback

Copy link
Copy Markdown

Resolves #744

Summary of Changes

Adds the /foreach slash command for deterministic, crash-resilient batch iteration across files with isolated prompt execution and comprehensive context clearing.

Details:

  • cecli/commands/foreach.py (ForeachCommand):
    • Implements /foreach [options] <glob_pattern> [::] <prompt_template>.
    • Pattern expansion: Resolves glob expressions relative to workspace root and exposes placeholders ({file}, {path}, {filename}, {name}, {stem}, {basename}, {ext}, {dir}, {dirname}, {index}, {total}).
    • Template safety (safe_substitute): Prevents Python KeyError exceptions when prompt templates include JSON tool arguments with literal curly braces (e.g. {"read_only": ["{file}"]}).
    • Idempotency skip guard (-u / --unless-exists <path>): Checks filesystem for destination file existence before issuing inference turns, allowing instant batch resumption on interruptions.
    • Holistic context clearing (-c / --clear):
      • Purges conversational message tags (CUR, DONE, DIFFS, FILE_CONTEXTS).
      • Purges file-related tags (READONLY_FILES, CHAT_FILES, EDIT_FILES, LINT) in ConversationManager to prevent prompt token accumulation.
      • Clears tracked resource sets (abs_fnames, abs_read_only_fnames, abs_read_only_stubs_fnames, files_added_in_exploration).
      • Calls flush_removals() on chunk removal buffers.
    • Execution options:
      • -n / --limit: Limits execution to N items.
      • --dry-run: Previews matches and substituted prompt templates without invoking the model.
      • --delay: Adds an optional delay between iterations.
    • Clean console output: Formats loop progression with clean Unicode indicators (🔄, ▶) and unescaped filenames.
  • cecli/commands/__init__.py:
    • Imported, registered in CommandRegistry, and exported in __all__.
  • Tests:
    • Added tests/commands/test_foreach.py covering placeholder substitution, --dry-run, -u unless-exists idempotency, limit filtering, and execution flow (6 unit tests, all passing).

@philippeback
philippeback force-pushed the feature/foreach_command branch from ae7e8ec to 9784b18 Compare November 12, 2026 10:55
@dwash96
dwash96 changed the base branch from main to v1.13.0 November 13, 2026 05:13
@dwash96
dwash96 merged commit d3fa73a into cecli-dev:v1.13.0 Nov 13, 2026
11 of 12 checks passed
@dwash96 dwash96 mentioned this pull request Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add /foreach command for deterministic batch iteration and isolated prompt execution

2 participants