Skip to content

Feat/agent ready cli - #114

Merged
nitisht merged 5 commits into
parseablehq:mainfrom
pratik50:feat/agent-ready-cli
Aug 7, 2026
Merged

Feat/agent ready cli#114
nitisht merged 5 commits into
parseablehq:mainfrom
pratik50:feat/agent-ready-cli

Conversation

@pratik50

@pratik50 pratik50 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Makes pb safer and more predictable for agents, scripts, and CI while preserving the existing human-readable CLI experience.

Summary by CodeRabbit

  • New Features

    • Added an agent command that provides machine-readable help, read-only command discovery, permissions, arguments, constraints, and error details.
    • Added consistent JSON output and structured error responses across CLI commands.
    • Documented automation behavior, JSON streaming, health-based exit statuses, and error formats.
  • Bug Fixes

    • Commands now correctly report HTTP, authentication, missing-resource, timeout, and invalid-input failures instead of silently succeeding.
    • Improved handling of empty JSON collections and malformed server responses.
    • Standardized output and error streams for clearer command-line behavior.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The CLI adds an agent manifest, shared JSON output utilities, structured error envelopes, HTTP status propagation, improved command diagnostics, and synchronized query iterator state. Tests and automation documentation cover the new behavior.

Changes

CLI contracts and rendering

Layer / File(s) Summary
Error and output contracts
cmd/errors.go, cmd/output.go, main.go
Adds typed CLI errors, error classification, JSON error envelopes, output-format normalization, JSON validation, empty-slice encoding, and centralized execution-error rendering.
Agent command manifest
cmd/agent.go, README.md
Adds pb agent with read-only command metadata, authorization and retryability details, constraints, and JSON discovery documentation.
Command error and output integration
cmd/*.go, pkg/analytics/analytics.go, pkg/config/config.go, pkg/datasets/datasets.go, pkg/model/savedQueries.go
Propagates structured input and HTTP errors, validates output formats, writes JSON through shared helpers, closes response bodies, and routes diagnostics to stderr.
Contract and command validation
cmd/*_test.go, main_test.go
Tests manifest contents, JSON rendering, error classification, output normalization, HTTP failures, malformed responses, empty collections, and diagnostic output.
Iterator state synchronization
pkg/iterator/iterator.go
Adds read/write locking around iterator state and releases locks before asynchronous population and query execution.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Agent
  participant Manifest
  participant CLI
  participant Output
  Agent->>Manifest: Build read-only command catalog
  Manifest-->>Agent: Return contract metadata
  Agent->>Output: Serialize text or JSON
  CLI->>Output: Render structured execution errors
Loading

Possibly related PRs

Suggested reviewers: nitisht

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 13.46% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: making the CLI agent-ready.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

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

🤖 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 `@cmd/diagnostics_test.go`:
- Around line 24-26: Restore the persistent interactive flag after each test: in
cmd/diagnostics_test.go lines 24-26, save query’s existing interactive value
before setting it and restore that value during test cleanup; apply the same
save-and-restore pattern to promqlRunCmd at lines 47-49. Use test cleanup so
restoration occurs even when assertions fail.

In `@cmd/output.go`:
- Around line 52-60: Wrap every malformed server-response error in CLIError with
Code set to ErrorInvalidResponse so errorDetails emits INVALID_RESPONSE: update
the invalid and multiple-value branches in cmd/output.go (lines 52-60), and the
invalid decoding paths in cmd/promql.go at lines 351-353, 429, 485, 549, 623,
678, 779, 834, 903, and 922; preserve each existing descriptive error message
and underlying error.

In `@cmd/pre.go`:
- Around line 42-43: Update the profile validation around conf.Profiles and
conf.DefaultProfile to verify that the configured default-profile name exists as
a key in conf.Profiles before assigning DefaultProfile. Return the existing
ErrorNotFound CLI error when the map is nil or the configured profile is absent,
rather than accepting a zero-value profile.

In `@cmd/role.go`:
- Around line 169-171: Update the missing-role error path in the command
handling logic to return newCLIError with ErrorNotFound and
missingRoleMessage(name, roles), passing nil for the underlying cause; preserve
the existing cmd.Annotations["errors"] assignment using the resulting error
message.

In `@cmd/user.go`:
- Around line 115-117: Update all three missing-resource branches in
cmd/user.go: the missing role at lines 115-117, the missing user at lines
230-232, and the missing role at lines 245-247. Replace each untyped error
return with newCLIError(ErrorNotFound, ..., nil), preserving the existing
descriptive messages and command annotations so JSON consumers receive the
NOT_FOUND contract.
- Around line 365-377: Check userRoleFetchError before constructing or writing
the JSON response in the outputJSON branch. If role enrichment fails, return
that error immediately so writeJSON is never called; only serialize
usersWithRoles after confirming all role requests succeeded.

In `@main.go`:
- Around line 55-64: Resolve rootOutputFormat before the version branch in
main.go and pass the effective format plus command output writer to
PrintVersion. Update cmd/version.go’s PrintVersion implementation to accept
these parameters and stop reading the package-level outputFormat, preserving
JSON output for --version --output=json. Affected sites: main.go lines 55-64
require reordering and argument passing; cmd/version.go lines 58-88 require the
PrintVersion signature and implementation update.

In `@pkg/config/config.go`:
- Around line 184-195: Update the config file-writing flow around file.Chmod and
file.Write to remove direct os.Stderr diagnostics and return contextual wrapped
errors instead. Preserve the underlying errors when reporting permission-setting
or data-writing failures, allowing the command-level error renderer to choose
the output stream and format.

In `@pkg/iterator/iterator.go`:
- Around line 81-84: Update QueryIterator.populateNextNonEmpty so hasData is
never invoked while iter.mu is held: snapshot the needed iterator state under
the lock, mark population in flight to prevent duplicate work, release the lock
for the callback, then reacquire it to commit results and clear the in-flight
state. Preserve synchronization for concurrent iterator methods and ensure
waiting callers are notified or can retry after population completes.

In `@README.md`:
- Around line 346-348: Update the agent catalog description in README.md to
match the fields actually emitted by agentManifest: describe command strings,
scope, profile requirements, and constraints, and remove claims about structured
arguments, flags, and required permissions unless those fields are added to
agentManifest.
🪄 Autofix

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: defaults

Review profile: CHILL

Plan: Pro

Run ID: dabfac83-f32b-4ca5-99e5-f49a1e435a07

📥 Commits

Reviewing files that changed from the base of the PR and between 1e9ab8a and 872509c.

📒 Files selected for processing (31)
  • README.md
  • cmd/agent.go
  • cmd/agent_test.go
  • cmd/cloud.go
  • cmd/dataset.go
  • cmd/diagnostics_test.go
  • cmd/errors.go
  • cmd/errors_test.go
  • cmd/exit_status_test.go
  • cmd/generate.go
  • cmd/output.go
  • cmd/output_test.go
  • cmd/pre.go
  • cmd/profile.go
  • cmd/promql.go
  • cmd/promql_test.go
  • cmd/query.go
  • cmd/queryList.go
  • cmd/queryList_test.go
  • cmd/role.go
  • cmd/status.go
  • cmd/tail.go
  • cmd/user.go
  • cmd/version.go
  • main.go
  • main_test.go
  • pkg/analytics/analytics.go
  • pkg/config/config.go
  • pkg/datasets/datasets.go
  • pkg/iterator/iterator.go
  • pkg/model/savedQueries.go

Comment thread cmd/diagnostics_test.go
Comment thread cmd/output.go Outdated
Comment thread cmd/pre.go
Comment thread cmd/role.go Outdated
Comment on lines +169 to +171
commandErr := fmt.Errorf("%s", missingRoleMessage(name, roles))
cmd.Annotations["errors"] = commandErr.Error()
return commandErr

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Use a typed not-found error.

This path returns a generic error. It has no explicit NOT_FOUND code for JSON error output. Return newCLIError(ErrorNotFound, missingRoleMessage(name, roles), nil) instead.

🤖 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 `@cmd/role.go` around lines 169 - 171, Update the missing-role error path in
the command handling logic to return newCLIError with ErrorNotFound and
missingRoleMessage(name, roles), passing nil for the underlying cause; preserve
the existing cmd.Annotations["errors"] assignment using the resulting error
message.

Comment thread cmd/user.go Outdated
Comment thread cmd/user.go Outdated
Comment thread main.go
Comment thread pkg/config/config.go Outdated
Comment thread pkg/iterator/iterator.go
Comment thread README.md Outdated
@nitisht
nitisht merged commit 25b275f into parseablehq:main Aug 7, 2026
2 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants