Skip to content

feat: add 'ox query' as first-class top-level command#156

Merged
rsnodgrass merged 4 commits into
mainfrom
ryan/query-command
Mar 9, 2026
Merged

feat: add 'ox query' as first-class top-level command#156
rsnodgrass merged 4 commits into
mainfrom
ryan/query-command

Conversation

@rsnodgrass
Copy link
Copy Markdown
Contributor

@rsnodgrass rsnodgrass commented Mar 7, 2026

Summary

Adds ox query "search text" as a top-level shorthand for semantic search of team knowledge, eliminating the need to know the agent ID. The command automatically detects agent context when running inside an agent session and passes agent metadata to the server for analytics and query improvement.

Changes

  • New cmd/ox/query.go — Top-level ox query command with layered agent detection

    • Checks SAGEOX_AGENT_ID env var → instance store lookup (gets both ID + type)
    • Falls back to agentx.CurrentAgent() for runtime type detection
    • Graceful degradation: query works even with no agent context
  • Refactored cmd/ox/agent_query.go — Extracted shared logic into executeQuery()

    • runAgentQuery now thin wrapper that calls executeQuery() with agent metadata
    • Context byte tracking stays in runAgentQuery (agent-specific)
    • Enhanced error messages: better hints for service outages, version issues, auth failures
  • Added agent metadata to internal/api/query.go

    • New optional fields: AgentID and AgentType in QueryRequest
    • Server gets richer signal for analytics and query improvement
  • Updated cmd/ox/agent_prime.go — Guidance now shows ox query as preferred shorthand

  • Registered command in cmd/ox/root.go — Added to "dev" command group alongside init/import

Backwards Compatibility

Full backwards compatibility: ox agent <id> query still works exactly as before with context tracking.

Test Plan

  • go build ./cmd/ox — compiles
  • ox query --help — shows usage
  • go test ./cmd/ox/... -run TestParseQueryArgs — all 17 tests pass
  • make lint — no issues
  • ox query "test" — makes API call (404 expected until server endpoint deployed)
  • Agent detection: SAGEOX_AGENT_ID=<id> ox query "test" — includes agent metadata in request

Session Recording

View session recording

Co-Authored-By: SageOx ox@sageox.ai

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a standalone query subcommand with configurable flags for limit, team, repository, and search mode (hybrid, kNN, BM25).
    • Added automatic agent context detection during query execution for enhanced tracking and analytics.
  • Chores

    • Removed Dolt database backend configuration files.
    • Simplified project ignore patterns using an allowlist approach.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 7, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3b2149a8-7893-4b22-a8af-08e7b5a24a24

📥 Commits

Reviewing files that changed from the base of the PR and between 0f976c4 and 625ed20.

📒 Files selected for processing (2)
  • cmd/ox/agent_query.go
  • cmd/ox/query.go

📝 Walkthrough

Walkthrough

Adds a top-level ox query CLI command, refactors agent query flow by extracting executeQuery, propagates AgentID/AgentType in QueryRequest, updates guidance to reference ox query, and removes Dolt config/metadata while tightening .beads/.gitignore to an allowlist.

Changes

Cohort / File(s) Summary
Config & artifact cleanup
\.beads/.gitignore, \.beads/dolt.20260304T071113Z.corrupt.backup/config.yaml, \.beads/metadata.json
Removed Dolt config and metadata files; replaced broad ignore rules with an allowlist in .beads/.gitignore permitting only .gitignore, README.md, config.yaml, and issues.jsonl.
New top-level CLI command
cmd/ox/query.go, cmd/ox/root.go
Added query subcommand (flags: --limit/-k, --team, --repo, --mode), argument parsing, agent-context detection, and registered the command under root/dev.
Agent query refactor & guidance update
cmd/ox/agent_query.go, cmd/ox/agent_prime.go
Extracted core flow into executeQuery returning bytes written; runAgentQuery delegates and tracks bytes; guidance text updated to reference generic ox query usage.
API request extension
internal/api/query.go
Added optional AgentID and AgentType fields to QueryRequest (agent_id,omitempty, agent_type,omitempty) to convey agent context to server.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI as "ox query"
    participant Parser as "parseQueryArgs"
    participant Detector as "detectAgentContext"
    participant Executor as "executeQuery"
    participant API as "Server API"

    User->>CLI: Invoke ox query "<text>"
    CLI->>Parser: parse args & flags
    Parser-->>CLI: queryArgs
    CLI->>Detector: detectAgentContext()
    alt SAGEOX_AGENT_ID present
        Detector-->>CLI: agentID, agentType
    else runtime agent available
        Detector-->>CLI: agentType
    else no agent
        Detector-->>CLI: (empty)
    end
    CLI->>Executor: executeQuery(queryArgs, agentID, agentType)
    Executor->>API: Send QueryRequest (includes AgentID/AgentType)
    API-->>Executor: Query results
    Executor-->>CLI: write results (returns bytesWritten)
    CLI->>CLI: trackContextBytes(bytesWritten)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐇 I hopped a query across the plain,
Switched routes to one command, gentle and plain,
I tucked agent IDs into the mole's den,
Swept Dolt crumbs away and tightened the pen,
A rabbit counts bytes and hops off again.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding 'ox query' as a first-class top-level command, which is the primary objective of the PR.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ryan/query-command

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.

Co-Authored-By: SageOx <ox@sageox.ai>
@rsnodgrass rsnodgrass force-pushed the ryan/query-command branch from a6ab0b9 to ae623ad Compare March 7, 2026 04:43
@rsnodgrass rsnodgrass marked this pull request as ready for review March 7, 2026 04:43
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmd/ox/agent_query.go`:
- Around line 166-175: The error path after client.Query(req) hardcodes
"sageox.ai" in the connectivity hint; change it to use the actual endpoint used
for the request (the ep variable) and normalize it with
endpoint.NormalizeEndpoint() before inserting into the message so
custom/self-hosted endpoints are shown correctly; update the return formatting
in the generic error branch to include the normalized endpoint host instead of
"sageox.ai" (refer to client.Query(req), the ep variable, and
endpoint.NormalizeEndpoint()).

In `@cmd/ox/query.go`:
- Around line 46-49: runQuery currently calls executeQuery(qa, agentID,
agentType) but discards the returned response size used for accounting; capture
the response size return value (like runAgentQuery does) and call
trackContextBytes(agentID, agentType, respSize) before returning (preserving
existing error handling), so context/token stats are updated on the agent-aware
ox query path.
- Around line 26-28: The command currently sets DisableFlagParsing: true which
prevents Cobra from parsing inherited persistent flags (e.g., --config, --quiet,
--verbose) when placed after the subcommand; remove or set DisableFlagParsing to
false in the command definition that uses cobra.ArbitraryArgs and runQuery so
Cobra will handle inherited flags normally (alternatively remove the
DisableFlagParsing field entirely) and keep the existing Args:
cobra.ArbitraryArgs and RunE: runQuery behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dc945e5f-ae4a-43a2-9fa8-551532552a6e

📥 Commits

Reviewing files that changed from the base of the PR and between 8983951 and ae623ad.

📒 Files selected for processing (9)
  • .beads/.gitignore
  • .beads/dolt.20260304T071113Z.corrupt.backup/config.yaml
  • .beads/interactions.jsonl
  • .beads/metadata.json
  • cmd/ox/agent_prime.go
  • cmd/ox/agent_query.go
  • cmd/ox/query.go
  • cmd/ox/root.go
  • internal/api/query.go
💤 Files with no reviewable changes (2)
  • .beads/metadata.json
  • .beads/dolt.20260304T071113Z.corrupt.backup/config.yaml

Comment thread cmd/ox/agent_query.go
Comment thread cmd/ox/query.go Outdated
Comment thread cmd/ox/query.go Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmd/ox/agent_query.go`:
- Around line 89-99: The usage string in queryUsage is out of sync with
parseQueryArgs (which supports a --mode flag); update the queryUsage constant to
include the --mode description (e.g., "--mode MODE    Search mode (default:
...)" or similar), ensuring the help text matches parseQueryArgs and the ox
agent <id> query parsing behavior; modify the queryUsage constant so that any
mention of flags lists --mode along with --limit, --team, and --repo, and verify
parseQueryArgs and any error/help output reference the same wording for --mode
to avoid stale flag documentation.

In `@cmd/ox/query.go`:
- Around line 77-89: The code currently returns immediately when
resolveInstance(envID) succeeds, which prevents falling back to
agentx.CurrentAgent() if inst.AgentType == ""; change the logic in the envID
handling so you always apply inst.AgentID to agentID but only set/return
agentType if inst.AgentType is non-empty; otherwise do not return and allow the
subsequent agentx.CurrentAgent() fallback to populate agentType. Update the
block around resolveInstance(envID), inst.AgentID/inst.AgentType, and the later
agentx.CurrentAgent() usage to implement this conditional-return behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 399e823a-bacb-4cc3-9fbd-c9ee49c28b44

📥 Commits

Reviewing files that changed from the base of the PR and between ae623ad and 2dd4cc2.

📒 Files selected for processing (2)
  • cmd/ox/agent_query.go
  • cmd/ox/query.go

Comment thread cmd/ox/agent_query.go
Comment thread cmd/ox/query.go
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmd/ox/agent_query.go`:
- Around line 124-147: The executeQuery function forwards qa.limit directly into
api.QueryRequest.K allowing zero or negative limits; add a validation near the
start of executeQuery (before constructing the QueryRequest) to reject
non-positive values from qa.limit (and thus from parseQueryArgs/Cobra) by
returning a clear error (e.g., fmt.Errorf("invalid --limit: must be > 0")).
Reference executeQuery and QueryRequest.K and enforce the check before creating
req so invalid limits are blocked client-side.
- Around line 167-175: The current error branch after client.Query wraps every
non-auth/version error with "is <endpoint> reachable?", which mislabels HTTP
errors (e.g., 403/404); update the error handling in the client.Query() response
path to distinguish network/reachability errors from ordinary HTTP/status
errors: keep the existing checks for api.ErrUnauthorized and
api.ErrVersionUnsupported, then use errors.Is/errors.As to detect
network-related errors (net.Error, *url.Error, context.DeadlineExceeded, etc.)
and only add the "is <endpoint> reachable?" suggestion for those; for other
errors (HTTP status or API-level failures) return the original error wrapped
with contextual text but without the reachability hint, referencing client.Query
and endpoint.NormalizeEndpoint to locate the branch to change.

In `@cmd/ox/query.go`:
- Around line 35-54: runQuery currently accepts an empty query string because
cobra.ExactArgs(1) allows "" — add validation in runQuery to reject empty or
whitespace-only queries by checking args[0] (or queryArgs.query) and returning
an error if it's empty; update the creation/usage of the queryArgs struct (query
field) so the validation occurs before proceeding to the mode switch (reference
runQuery and queryArgs.query).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4330b888-5b2f-4e67-8b4a-dfd360150c48

📥 Commits

Reviewing files that changed from the base of the PR and between 2dd4cc2 and 0f976c4.

📒 Files selected for processing (2)
  • cmd/ox/agent_query.go
  • cmd/ox/query.go

Comment thread cmd/ox/agent_query.go
Comment thread cmd/ox/agent_query.go Outdated
Comment thread cmd/ox/query.go
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