feat(stdlib): add each command for per-item sub-pipeline iteration#13
Open
sfo2001 wants to merge 4 commits intoopenclaw:mainfrom
Open
feat(stdlib): add each command for per-item sub-pipeline iteration#13sfo2001 wants to merge 4 commits intoopenclaw:mainfrom
sfo2001 wants to merge 4 commits intoopenclaw:mainfrom
Conversation
Dead code left over from the clawd-only refactor in 5679042. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Extract getByPath and renderTemplate into template_utils.ts. Fix ReDoS vulnerability in template regex and add Object.hasOwn guard to block prototype chain traversal in getByPath. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add { } body parsing with backward-compatible bare brace handling,
recursion depth limit (50), and truncated error messages. Bare } at
depth 0 is treated as literal to avoid breaking existing pipelines.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add each { ... } pipeline operator that runs a sub-pipeline per input
item with {{.field}} interpolation. Includes _bodyRaw pass-through,
sideEffects metadata, and tests for runtime errors, prototype denylist,
and recursion depth.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
f384f9d to
542e2f6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Pipelines currently have no native way to read from or write to local files. Loading data requires shelling out (
exec cat+ manual parsing), and there is no structured JSON transformation primitive beyondmap.file.read,file.write, andjq-filterfill these gaps: pipelines can ingest local datasets, persist intermediate results, and apply arbitrary jq expressionswithout leaving the pipeline or spawning ad-hoc shell commands.
Summary
eachcommand: runs a sub-pipeline for each input item, collecting resultseach { map --unwrap url | exec curl "{{.}}" })template_utils.tsfrommapandtemplateto eliminate duplication{{.field}}interpolation in sub-pipeline args per item; nestedeachsupportedChanges
src/commands/stdlib/each.tssrc/commands/stdlib/template_utils.tssrc/parser.ts(brace body parsing)src/commands/stdlib/map.ts,template.ts(use shared util)src/commands/registry.ts(+1)test/each.test.ts(12 tests + 8 parser tests)+389 / -48 lines across 7 files.
Test plan
pnpm buildpassespnpm lintpassesnode --test dist/test/each.test.js-- 20 tests (12 each + 8 parser brace tests)mapandtemplatetests still pass (template_utils refactor)Use of AI