Repository navigation
feat(query): describe structural DSL fields (#2006) - #2093
Conversation
📝 WalkthroughWalkthroughStructural query field metadata is refactored from raw string tuples to a new ChangesStructural field metadata enrichment and completion integration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 32e3944a0e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/unit/cli/test_command_aux_runtime.py`:
- Around line 197-200: The test in the loop only verifies a hardcoded subset of
four session fields instead of all registered session-scoped examples, which
means invalid examples like session.cwd, session.has, session.tool, or
session.until could go undetected. Refactor the test to dynamically iterate
through all available session.* field examples from the registry by using
structural_query_field_info to discover and compile every registered
session-scoped example, rather than manually specifying the four fields in the
tuple passed to the for loop.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 3b0c1e67-1633-4cb1-95b3-6efc4ad60741
📒 Files selected for processing (3)
polylogue/archive/query/completions.pypolylogue/archive/query/metadata.pytests/unit/cli/test_command_aux_runtime.py
| for field in ("session.messages", "session.words", "session.since", "session.origin"): | ||
| info = structural_query_field_info("message", field) | ||
| assert info is not None | ||
| compile_expression(f"exists message({info.example} AND role:assistant)") |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial | ⚡ Quick win
Compile every registered session.* example, not just the sampled subset.
The registry defines more session-scoped examples than these four, so examples like session.cwd, session.has, session.tool, or session.until can become invalid without this test failing.
Proposed test broadening
def test_query_structural_session_field_examples_are_executable() -> None:
from polylogue.archive.query.expression import compile_expression
- from polylogue.archive.query.metadata import structural_query_field_info
+ from polylogue.archive.query.metadata import structural_query_field_info, structural_query_fields
- for field in ("session.messages", "session.words", "session.since", "session.origin"):
+ for field in structural_query_fields("message"):
+ if not field.startswith("session."):
+ continue
info = structural_query_field_info("message", field)
assert info is not None
compile_expression(f"exists message({info.example} AND role:assistant)")🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tests/unit/cli/test_command_aux_runtime.py` around lines 197 - 200, The test
in the loop only verifies a hardcoded subset of four session fields instead of
all registered session-scoped examples, which means invalid examples like
session.cwd, session.has, session.tool, or session.until could go undetected.
Refactor the test to dynamically iterate through all available session.* field
examples from the registry by using structural_query_field_info to discover and
compile every registered session-scoped example, rather than manually specifying
the four fields in the tuple passed to the for loop.
|
Addressed the Codex finding in f8c0710 by making session-scoped structural examples explicit and executable. The new test compiles the advertised examples for message structural predicates, covering numeric/date-like/session-origin examples. |
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
Summary
Adds typed metadata for executable structural query fields so query completions and query-builder consumers can describe
messages/actions/blocks/assertions where ...fields precisely instead of emitting generic field text.Problem
The #2006 DSL substrate already executes structural unit predicates and inline owning-session scope such as
messages where session.origin:codex-session AND text:needle, butSTRUCTURAL_QUERY_UNIT_REGISTRYexposed each unit's fields as bare strings. That kept completion payloads technically correct but low-value for agents and web/query-builder surfaces that need to know what a field means.Solution
polylogue.archive.query.metadatanow models structural fields asStructuralQueryFieldInforecords with a name, description, and executable example. Existing callers still get the compatible string tuple throughstructural_query_fields(), while richer callers usestructural_query_field_info(). Query completions now include the field-specific description/example for unit fields andsession.*scope fields derived from the existing session field registry.This intentionally adds metadata only for fields already accepted and lowered by the current grammar/storage path; it does not add parser-only vocabulary.
Verification
devtools test tests/unit/cli/test_command_aux_runtime.py -k 'query_structural_field or query_structural_unit or query_field_candidates'-> 5 passed, 8 deselecteddevtools test tests/unit/cli/test_query_expression.py -k 'Descriptor or descriptor or structural or completion or terminal_message_source_accepts_session_scoped_predicate or exists_action_session_scoped_predicate_executes_against_archive'-> 29 passed, 215 deselectedpython -m mypy polylogue/archive/query/metadata.py polylogue/archive/query/completions.py tests/unit/cli/test_command_aux_runtime.py-> Success: no issues founddevtools test tests/unit/cli/test_query_expression.py tests/unit/cli/test_command_aux_runtime.py tests/unit/cli/test_click_app.py -k 'Descriptor or descriptor or structural or query_completions_json_outputs_structured_candidates or query_field_candidates'-> 37 passed, 288 deselecteddevtools verify --quick-> exit_code 0Ref #2006
Summary by CodeRabbit
New Features
Tests