Skip to content

refactor(cli): strict command floor + remove dead export (#1842) - #1885

Merged
Sinity merged 3 commits into
masterfrom
feature/refactor/cli-surface-prune-1842
Jun 15, 2026
Merged

Sinity merged 3 commits into
masterfrom
feature/refactor/cli-surface-prune-1842

Conversation

@Sinity

@Sinity Sinity commented Jun 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

First slice of the #1842 command-floor program: make find a real keyword,
enforce the strict bare-query floor, and remove the orphaned dead export
command. This is the foundation PR — no capability is removed (the verbs that
must absorb the old analytics/mark commands are not touched here; those are
later port-before-delete PRs).

Problem

  • find was never a keyword. _split_query_mode_args let it fall through as a
    literal query term, so polylogue find repo:x searched for the word "find".
    The grammar was documented in --help but not implemented.
  • Any unquoted bare root silently became a search (query-first), so a mistyped
    command ran a query instead of giving an actionable error.
  • polylogue/cli/commands/export.py defined export_command but was never in
    ROOT_COMMANDS — unreachable dead code. (Live bulk-export lives in
    cli/bulk_export.py, the read --all path.)

Solution

  • find keyword (query_group.py): strip a leading find and mark the
    query explicit; a later find stays a literal term.
  • Strict floor (QueryFirstGroupBase.invoke): an unsignalled bare root —
    no find, no -- escape, no field syntax (:), no quoted-whitespace token —
    raises a hint pointing at find / quoting, folding in the existing
    looks_like_subcommand_typo did-you-mean (so lst → polylogue list).
    Explicit/expression/quoted roots still search:
    • polylogue foo / polylogue foo bar → hint
    • polylogue find foo bar / polylogue 'repo:x' / polylogue 'machine learning' → search
    • polylogue find id:abc then read → dispatch
  • Dead export removal: delete export.py; rewrite docs/export.md and
    docs/getting-started.md examples onto the read verb; regenerate topology.
  • Tests adapted off bare-word search to find; new TestStrictCommandFloor
    pins the acceptance matrix.

Verification

  • devtools test tests/unit/cli → 1802 passed (-n 8).
  • devtools test tests/integration/test_cli_query_mode.py → 5 passed, 13 skipped (no regression).
  • devtools verify --quick → exit 0 (ruff format/lint, mypy --strict, render-all --check, doc-command + public-surface audits).
  • devtools render-all --check → in sync after topology regen.

#1842 handoff checklist

Issue slice: PR-1 foundation — `find` keyword + strict bare-query floor + dead `export` removal
Files inspected: cli/query_group.py, cli/click_command_registration.py, cli/verb_names.py, cli/query_verbs.py, cli/query_feedback.py, cli/parser_diagnostics.py, cli/commands/export.py, cli/bulk_export.py
Files changed: cli/query_group.py; cli/commands/export.py (deleted); tests/unit/cli/{test_click_app,test_embed_activation,test_query_exec_laws}.py; docs/export.md; docs/getting-started.md; docs/plans/topology-target.yaml; docs/topology-status.md
Old surface removed or retained: removed dead `export` command (was unregistered); old lenient bare-query behavior replaced by strict floor
Contracts/tests added: TestStrictCommandFloor (find strip, find+then dispatch, multi/single bare-root hints, field-expression + quoted-whitespace search, `--` escape)
Generated artifacts updated: topology-target.yaml, topology-status.md
Verification commands and results: see Verification above
Known caveats / SPEC_MISMATCH: documented in #1842 body — the analytics (cost/diagnostics/insights/neighbors/correlate/context/context_pack/facets) and mark-family (tags/user_state/blackboard/feedback) commands are NOT removed here; they require capability-absorption into analyze/mark (+ #1883 KV / MCP migration) first.
Follow-up intentionally not included: facets `--no-idf`→analyze (next PR); analyze ports; mark-family fold after #1883; integration test_cli_query_mode.py rewrite when read --view folds messages/raw/open.

Ref #1842

Summary by CodeRabbit

  • Bug Fixes

    • Improved query-first CLI parsing by enforcing explicit query intent, preventing ambiguous bare queries from executing unintentionally.
  • Documentation

    • Updated CLI export workflow to use read (single-session via --id <id> read, batch via --all read).
    • Refreshed export format naming and examples.
    • Clarified how to use the find subcommand for searches.
  • Tests

    • Updated CLI routing/integration tests to use find explicitly and added coverage for stricter “command floor” behavior.

Sinity and others added 2 commits June 14, 2026 21:17
Problem: `find` was never a real keyword — it fell through the query
parser as a literal search term, so `polylogue find repo:x` searched for
the word "find" too. And any unquoted bare root silently became a search,
so a mistyped command ran a query instead of erroring.

What changed:
- `_split_query_mode_args` strips a leading `find` and marks the query
  explicit (a later `find` stays a literal term).
- `QueryFirstGroupBase.invoke` refuses an unsignalled bare root — no
  `find`, no `--` escape, no field syntax, no quoted whitespace — with a
  hint pointing at `find` / quoting, folding in the existing did-you-mean
  subcommand suggestion so `lst` still suggests `list`.
- Tests that drove search via bare words now use `find`; added
  `TestStrictCommandFloor` pinning the acceptance matrix (find stripped,
  find+then dispatch, multi/single bare-root hints, field-expression and
  quoted-whitespace roots still search, `--` escape forces a query).

Ref #1842

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Problem: polylogue/cli/commands/export.py defined `export_command` but it
was never registered in ROOT_COMMANDS — unreachable dead code. The live
bulk-export logic lives in cli/bulk_export.py (the `read --all` path), so
nothing depends on it.

What changed:
- Delete export.py (verified: no production importer, no test imports the
  symbol; `insights export` is a different command).
- Rewrite docs/export.md and docs/getting-started.md `export` /
  `bulk-export` examples onto the surviving `read` verb
  (`--id <id> read`, `... read --all`).
- Regenerate topology projection/status for the removed module.

Ref #1842

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@coderabbitai

coderabbitai Bot commented Jun 14, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 8d0bc178-2421-48e8-99df-e6c7bece9dcb

📥 Commits

Reviewing files that changed from the base of the PR and between fdf6d15 and adc96ed.

📒 Files selected for processing (2)
  • polylogue/cli/query_group.py
  • tests/unit/cli/test_click_app.py

📝 Walkthrough

Walkthrough

Removes the standalone export_command CLI module and enforces a "strict command floor" in QueryFirstGroupBase: bare positional tokens no longer silently become query terms unless prefixed with find, escaped with --, or matching query-expression heuristics. Documentation is updated throughout to reflect the read-verb workflow, and all affected tests are updated to use explicit find invocations.

Changes

CLI strict command floor and export removal

Layer / File(s) Summary
Strict command floor in QueryFirstGroupBase
polylogue/cli/query_group.py
_split_query_mode_args now returns an explicit_query boolean (set when find or -- is used). Two new helpers — _looks_like_query_expression and _bare_root_error_message — detect query-like syntax and emit a did-you-mean UsageError. parse_args stores the flag in ctx.meta; invoke raises the error for ambiguous bare roots.
export_command deletion and topology metadata
polylogue/cli/commands/export.py, docs/plans/topology-target.yaml, docs/topology-status.md
The entire export.py module (export_command, _root_message_roles) is deleted; its entry is removed from the topology target list; Stable/Total declared/Realized counts are each decremented by 1.
Test updates for explicit find and TestStrictCommandFloor
tests/unit/cli/test_click_app.py, tests/unit/cli/test_embed_activation.py, tests/unit/cli/test_query_exec_laws.py
All existing search-invocation tests are updated to pass find before query terms. A new TestStrictCommandFloor suite verifies find-stripping, find … read dispatch, UsageError hints for bare roots, and that field expressions, quoted strings, and ---escaped tokens still trigger query execution.
Documentation aligned to read-verb workflow
docs/export.md, docs/getting-started.md
export/bulk-export commands replaced with --id <id> read and --since yesterday read --all; format names updated (text, ndjson); content-block filter examples rewritten as read-scoped flags.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

  • Polylogue: final hard-pruned CLI surface #1842: This PR directly implements the command-floor pruning strategy outlined in that issue — removing export.py (safe deletion), enforcing the strict query intent validation in query_group.py, updating docs to --id <id> read, and adjusting all tests to require explicit find invocations.
  • Sinity/polylogue#1811: This PR implements the find QUERY then ACTION grammar by removing the export_command root, replacing single-session and bulk-export invocations with --id ... read and read --all, and enforcing strict find-based command-floor parsing.

Possibly related PRs

  • Sinity/polylogue#764: Both PRs directly touch the polylogue/cli/commands/export.py surface — the earlier PR wired export_command to env.polylogue, while this PR removes the module entirely.
  • Sinity/polylogue#1863: Both PRs are part of the same read-verb unification: the earlier PR introduced the read verb router and began pruning legacy verbs; this PR removes the last export surface and enforces the command floor.

Poem

🐇 Hop hop, no more bare-word guessing games,
find now stands before the query frames.
The export command has hopped away,
read is the verb that rules the day.
With hints and heuristics in tow,
the strict command floor puts on a show! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.00% 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 captures the main changes: strict command floor enforcement and removal of the dead export command, both central to this PR.
Description check ✅ Passed The description covers all required sections: Summary, Problem, Solution, Verification, Changelog guidance, and Risks/Follow-ups with comprehensive detail and PR 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/refactor/cli-surface-prune-1842

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.

github-actions Bot pushed a commit that referenced this pull request Jun 14, 2026

@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: fdf6d15e60

ℹ️ 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/cli/query_group.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_click_app.py`:
- Around line 397-453: Add a new regression test method to the
TestStrictCommandFloor class that verifies a non-leading "find" token is treated
as a literal query term. The test should invoke the CLI with a query where
"find" appears after other search terms (not as the leading command), mock
execute_query_request, assert that the mock was called (indicating it was
processed as a query), and verify that "find" remains in the query parameters.
This complements the existing test_find_keyword_is_stripped_from_query test
which only validates leading-"find" stripping.
🪄 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: 0f802ffe-1479-4501-b763-82d1fe079de3

📥 Commits

Reviewing files that changed from the base of the PR and between 0eb2300 and fdf6d15.

📒 Files selected for processing (9)
  • docs/export.md
  • docs/getting-started.md
  • docs/plans/topology-target.yaml
  • docs/topology-status.md
  • polylogue/cli/commands/export.py
  • polylogue/cli/query_group.py
  • tests/unit/cli/test_click_app.py
  • tests/unit/cli/test_embed_activation.py
  • tests/unit/cli/test_query_exec_laws.py
💤 Files with no reviewable changes (1)
  • polylogue/cli/commands/export.py

Comment thread tests/unit/cli/test_click_app.py Resolved
Problem (Codex P2 on #1885): after a leading `find` is stripped, the next
token — if it is a verb word like `read`/`list`/`stats` — dispatched that
action over an empty query instead of being searched. `find read` read every
session rather than searching for the word "read".

What changed: in `_split_query_mode_args`, a verb token is treated as the verb
only when reached via `then` or after a query term already exists. After an
explicit `find` with nothing collected and no `then`, the verb word becomes a
literal query term (`find QUERY [then ACTION]` semantics). Added regression
tests: `find read` searches "read"; a non-leading `find` stays a literal term
(CodeRabbit nitpick).

Ref #1842
Co-Authored-By: Claude Opus 4.8 <[email protected]>
@Sinity

Sinity commented Jun 14, 2026

Copy link
Copy Markdown
Owner Author

Addressed both review findings in adc96ed:

  • Codex P2 (query_group.py — verb word after find): fixed. A verb token is now treated as the action only when reached via then or after a query term already exists. After an explicit find with nothing collected and no then, the verb word is a literal search term, so polylogue find read searches for "read" instead of running the read action over every session.
  • CodeRabbit nitpick (non-leading find literal): added the companion regression test.

New tests: test_verb_word_after_find_is_a_query_term, test_non_leading_find_stays_a_literal_query_term. devtools test tests/unit/cli/{test_click_app,test_diagnose_and_error_discipline,test_query_expression}.py → 198 passed; mypy clean on both files.

@Sinity
Sinity merged commit 91ba0c6 into master Jun 15, 2026
14 checks passed
@Sinity
Sinity deleted the feature/refactor/cli-surface-prune-1842 branch June 15, 2026 05:38
@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.

  • 61.F084 / P2: fixed-already at the checked revision: polylogue/cli/query_group.py:122 preserves a verb word in the first query position after explicit find unless then introduced it. Thus find read searches for read instead of dispatching an empty-query read action.

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