Repository navigation
feat(scope): lookup + macro support — PR C - #22
Merged
Merged
Conversation
Closes #15, closes #17. lookup (#15): left-joins a static CSV onto EventTable rows by field equality. Simplified from real SPL's lookup (no named lookup-table registration, no separate rename-on-input): `lookup "<path>.csv" <field> output <col> [as <alias>][, ...]`. The CSV needs a header row with a column matching <field>'s name; unmatched keys get nil. CSV is loaded eagerly at parse time (query/lookup.go) so a missing file or bad column name is an immediate parse error, matching how rex already compiles its regex eagerly. macros (#17): backtick `name` references in a query string expand to a named snippet loaded from ~/.claudescope/macros.json (query/macros.go). Uses JSON, not YAML as the ticket originally sketched, to avoid adding a dependency (only stdlib deps existed before this PR) — a flat JSON object of name -> pipe-query text covers the same use case. Macros can reference other macros; expansion is capped at 10 levels to catch cycles. Expansion happens as a string pre-pass in Parse(), before tokenizing, since backticks aren't otherwise meaningful in the grammar. SetMacrosPath is exported for tests to redirect the lookup path without touching the real home directory. Docs: lookup/macros added to `help` and skills/scope/SKILL.md; lookup noted as simplified-from-SPL, matching how ranges/transaction are already flagged as ClaudeScope extensions. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
4 of 5 tasks
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.
Third of 4 themed PRs building Tier-2 query features on the merged MVP (#19) + prior PRs (#20, #21). Theme: pulling in data/config from outside the query string.
Closes #15 (lookup), closes #17 (macros).
lookup — static CSV joins (#15)
Simplified from real SPL's
lookup(no named lookup-table registration, no separate rename-on-input clause):output A as x, B as y.nilfor every output column.query/lookup.go) — a missing file or bad column name is an immediate parse error, same posture asrexcompiling its regex eagerly.macros — reusable named queries (#17)
Backtick
`name`references expand to a snippet from~/.claudescope/macros.json:{"brownout": "where BatteryVoltage < 7 | ranges"}Deviation from the ticket: uses JSON, not YAML — the module had zero third-party dependencies before this PR (
go.modonly pulls ingo-nt4for live NT), and a flat name→string map doesn't need YAML's extra expressiveness. Happy to swap togopkg.in/yaml.v3if you'd rather standardize on YAML across the project.Expansion happens as a string pre-pass in
Parse(), before tokenizing (backticks aren't otherwise meaningful in the grammar). Macros can reference other macros; capped at 10 levels to catch cycles.query.SetMacrosPathis exported so tests (and this PR's tests) can redirect the lookup path without touching$HOME.Docs
Both added to
ClaudeScope helpandskills/scope/SKILL.md;lookupnoted as simplified-from-SPL, same posture asranges/transactionalready being flagged as ClaudeScope extensions.Test plan
go build ./...,go vet ./..., gofmt clean,go test ./... -raceall pass🤖 Generated with Claude Code