feat: add 'ox query' as first-class top-level command#156
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds a top-level Changes
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)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 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 |
Co-Authored-By: SageOx <ox@sageox.ai>
a6ab0b9 to
ae623ad
Compare
There was a problem hiding this comment.
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
📒 Files selected for processing (9)
.beads/.gitignore.beads/dolt.20260304T071113Z.corrupt.backup/config.yaml.beads/interactions.jsonl.beads/metadata.jsoncmd/ox/agent_prime.gocmd/ox/agent_query.gocmd/ox/query.gocmd/ox/root.gointernal/api/query.go
💤 Files with no reviewable changes (2)
- .beads/metadata.json
- .beads/dolt.20260304T071113Z.corrupt.backup/config.yaml
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
cmd/ox/agent_query.gocmd/ox/query.go
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
cmd/ox/agent_query.gocmd/ox/query.go
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-levelox querycommand with layered agent detectionSAGEOX_AGENT_IDenv var → instance store lookup (gets both ID + type)agentx.CurrentAgent()for runtime type detectionRefactored
cmd/ox/agent_query.go— Extracted shared logic intoexecuteQuery()runAgentQuerynow thin wrapper that callsexecuteQuery()with agent metadatarunAgentQuery(agent-specific)Added agent metadata to
internal/api/query.goAgentIDandAgentTypein QueryRequestUpdated
cmd/ox/agent_prime.go— Guidance now showsox queryas preferred shorthandRegistered command in
cmd/ox/root.go— Added to "dev" command group alongside init/importBackwards Compatibility
Full backwards compatibility:
ox agent <id> querystill works exactly as before with context tracking.Test Plan
go build ./cmd/ox— compilesox query --help— shows usagego test ./cmd/ox/... -run TestParseQueryArgs— all 17 tests passmake lint— no issuesox query "test"— makes API call (404 expected until server endpoint deployed)SAGEOX_AGENT_ID=<id> ox query "test"— includes agent metadata in requestSession Recording
View session recording
Co-Authored-By: SageOx ox@sageox.ai
Summary by CodeRabbit
Release Notes
New Features
Chores