Skip to content

feat(query): describe structural DSL fields (#2006) - #2093

Merged
Sinity merged 2 commits into
masterfrom
feature/feat/query-dsl-session-scope-2006
Jun 18, 2026
Merged

Sinity merged 2 commits into
masterfrom
feature/feat/query-dsl-session-scope-2006

Conversation

@Sinity

@Sinity Sinity commented Jun 18, 2026 •

Copy link
Copy Markdown
Owner

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, but STRUCTURAL_QUERY_UNIT_REGISTRY exposed 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.metadata now models structural fields as StructuralQueryFieldInfo records with a name, description, and executable example. Existing callers still get the compatible string tuple through structural_query_fields(), while richer callers use structural_query_field_info(). Query completions now include the field-specific description/example for unit fields and session.* 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 deselected
  • devtools 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 deselected
  • python -m mypy polylogue/archive/query/metadata.py polylogue/archive/query/completions.py tests/unit/cli/test_command_aux_runtime.py -> Success: no issues found
  • devtools 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 deselected
  • devtools verify --quick -> exit_code 0

Ref #2006

Summary by CodeRabbit

  • New Features

    • Query field completions now display enhanced descriptions and practical examples for each field.
  • Tests

    • Extended test coverage for structural query field validation and example expressions.

@coderabbitai

coderabbitai Bot commented Jun 18, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Structural query field metadata is refactored from raw string tuples to a new StructuralQueryFieldInfo dataclass carrying name, description, and example. A new structural_query_field_info accessor is added and consumed by query_structural_field_candidates to produce richer completion descriptions. Tests are extended to cover the new descriptions and verify example expressions compile.

Changes

Structural field metadata enrichment and completion integration

Layer / File(s) Summary
StructuralQueryFieldInfo dataclass and registry rebuild
polylogue/archive/query/metadata.py
Introduces StructuralQueryFieldInfo (fields: name, description, example), changes StructuralQueryUnitInfo.fields from tuple[str, ...] to tuple[StructuralQueryFieldInfo, ...], rebuilds all structural field registries with typed metadata objects, updates structural_query_fields to extract names from info objects, adds structural_query_field_info(unit, field) -> StructuralQueryFieldInfo | None, and exports both via __all__.
Completion candidate description enrichment
polylogue/archive/query/completions.py
Imports structural_query_field_info and updates query_structural_field_candidates to use metadata-provided description, appending an Example: suffix when an example value is present; falls back to the original default description when no metadata is found.
Extended completion and metadata tests
tests/unit/cli/test_command_aux_runtime.py
Adds assertions for type candidate description text and session.origin candidate presence/description in the existing structural-field candidates test; adds a new test that retrieves session field metadata and compiles exists message(...) example expressions for executability.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Sinity/polylogue#2025: Both PRs wire exists <unit>(...) completion candidate generation to structural unit/field registries — the prior PR established the exported structural registries and completion helpers that this PR extends with per-field metadata.

Poem

🐇 Hop hop, the fields now speak their name,
With descriptions rich and examples tame,
No more bare strings in a tuple row,
Each field has metadata to help it glow.
The rabbit typed and tested with care —
StructuralQueryFieldInfo fills the air! 🌸

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 36.36% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding descriptions for structural DSL fields to improve query completions and metadata.
Description check ✅ Passed The description covers all required template sections with detailed explanations of the problem, solution, verification steps, and context.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/feat/query-dsl-session-scope-2006

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread polylogue/archive/query/metadata.py Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between ac84118 and f8c0710.

📒 Files selected for processing (3)
  • polylogue/archive/query/completions.py
  • polylogue/archive/query/metadata.py
  • tests/unit/cli/test_command_aux_runtime.py

Comment on lines +197 to +200
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)")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 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.

@Sinity

Sinity commented Jun 18, 2026

Copy link
Copy Markdown
Owner Author

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.

@Sinity
Sinity merged commit 7fae014 into master Jun 18, 2026
13 checks passed
@Sinity
Sinity deleted the feature/feat/query-dsl-session-scope-2006 branch June 18, 2026 07:01
@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

  • 59.F074 / P2: fixed-already at the checked revision: polylogue/archive/query/expression.py:1597-1607 now parses numeric comparison operators from session-scoped colon values, and lines 1649-1657 handle scoped date comparisons. metadata.py:718-745 provides explicit valid examples and omits the old session.lineage example.

Only the rows listed above are dispositioned. Held findings remain open.

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.

1 participant