Skip to content

refactor(cli): validate logs flags with oclif - #2905

Merged
cv merged 14 commits into
mainfrom
refactor/oclif-ux-logs-flags
May 4, 2026
Merged

refactor(cli): validate logs flags with oclif#2905
cv merged 14 commits into
mainfrom
refactor/oclif-ux-logs-flags

Conversation

@cv

@cv cv commented May 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

Move the sandbox logs command's --tail, -n, --since, and --follow option shape into the oclif adapter so invalid flag values fail before any OpenShell calls. This also carries the log filter options through the logs action and updates help/registry metadata for the new flags.

Stack Navigation

Changes

  • Added SandboxLogsOptions and wired sandbox:logs to pass structured log options instead of a bare follow boolean.
  • Modeled --tail/-n with Flags.integer({ min: 1 }) and kept custom --since duration validation in the oclif command.
  • Updated log source argument construction so tail counts flow to both OpenClaw and OpenShell logs, while --since avoids an unfiltered gateway tail.
  • Expanded logs help metadata and root command registry flags.
  • Added CLI and command-adapter coverage for tail, since, follow, help, malformed values, and unknown flags.

Type of Change

  • Code change (feature, bug fix, or refactor)
  • Code change with doc updates
  • Doc only (prose changes, no code sample modifications)
  • Doc only (includes code sample changes)

Verification

  • npx prek run --all-files passes
  • npm test passes
  • Tests added or updated for new or changed behavior
  • No secrets, API keys, or credentials committed
  • Docs updated for user-facing behavior changes
  • make docs builds without warnings (doc changes only)
  • Doc pages follow the style guide (doc changes only)
  • New doc pages include SPDX header and frontmatter (new pages only)

Signed-off-by: Carlos Villela cvillela@nvidia.com

Summary by CodeRabbit

Release Notes

  • New Features
    • The sandbox:logs command now supports --tail/-n flag to display a specific number of log lines
    • Added --since flag to filter logs from a specified duration with validation and helpful error messages
    • Updated command documentation with usage examples

@cv cv self-assigned this May 3, 2026
@copy-pr-bot

copy-pr-bot Bot commented May 3, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented May 3, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 2baf5665-a485-49e8-968a-8cdd09e39d95

📥 Commits

Reviewing files that changed from the base of the PR and between 9513028 and a0c5636.

📒 Files selected for processing (1)
  • src/lib/sandbox-logs-cli-command.ts

📝 Walkthrough

Walkthrough

The sandbox:logs CLI command adds --tail/-n and --since flags to control output line count and time filtering. A normalizeSinceDuration helper validates the --since duration format. The runtime bridge now receives an options object with follow, lines, and since instead of just a boolean flag.

Changes

Log Filtering and Output Options

Layer / File(s) Summary
CLI Metadata
src/lib/sandbox-logs-cli-command.ts (lines 36–62)
static usage expanded to document --tail/-n and --since flags; static examples added with usage patterns; static flags extended with tail (integer, default from DEFAULT_SANDBOX_LOG_LINE_COUNT) and since (string) flag definitions.
Duration Validation
src/lib/sandbox-logs-cli-command.ts (lines 63–69)
Added private normalizeSinceDuration(since) helper that trims input, validates against LOGS_SINCE_DURATION_RE regex, and returns normalized string or null; exits with code 2 on invalid duration.
Runtime Bridge Integration
src/lib/sandbox-logs-cli-command.ts (lines 70–75)
Updated run() method to pass an options object { follow, lines, since } to the runtime bridge instead of a single follow boolean; lines stringified from flags.tail, since from normalizeSinceDuration(flags.since).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A fuzzy tail now counts the logs,
Since durations dance through CLI's bogs,
With validation swift and options bright,
The sandbox logs flow feels just right! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'refactor(cli): validate logs flags with oclif' accurately captures the main objective of the PR—adding flag validation for the logs command using oclif's validation framework.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 refactor/oclif-ux-logs-flags

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

@cv cv added the v0.0.34 label May 4, 2026
cv added a commit that referenced this pull request May 4, 2026
## Summary
Add oclif examples to low-risk global and utility commands so generated
help has concrete usage snippets. This starts the oclif UX pass without
changing command behavior.

## Stack Navigation
- Position: 12 of 60
- Previous PR: [#2901 — refactor(cli): expose explicit main
entrypoint](#2901)
- Next PR: [#2905 — refactor(cli): validate logs flags with
oclif](#2905)

## Changes
- Added examples for `list`, global `status`, `gateway-token`,
`credentials`, `credentials list`, and `credentials reset`.
- Added examples for `backup-all`, `upgrade-sandboxes`, and `gc`.
- Added examples for `uninstall`, `tunnel start`, `tunnel stop`, and
deprecated `start`/`stop` aliases.
- Added a help flag declaration to the uninstall oclif adapter to align
its metadata with other utility commands.

## Type of Change
- [x] Code change (feature, bug fix, or refactor)
- [ ] Code change with doc updates
- [ ] Doc only (prose changes, no code sample modifications)
- [ ] Doc only (includes code sample changes)

## Verification
- [x] `npx prek run --all-files` passes
- [x] `npm test` passes
- [ ] Tests added or updated for new or changed behavior
- [x] No secrets, API keys, or credentials committed
- [ ] Docs updated for user-facing behavior changes
- [ ] `make docs` builds without warnings (doc changes only)
- [ ] Doc pages follow the [style
guide](https://github.com/NVIDIA/NemoClaw/blob/main/docs/CONTRIBUTING.md)
(doc changes only)
- [ ] New doc pages include SPDX header and frontmatter (new pages only)

---
Signed-off-by: Carlos Villela <cvillela@nvidia.com>


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

## Release Notes

* **New Features**
* Added `sandbox doctor` command for comprehensive health diagnostics
across sandbox infrastructure, gateway, and services
* Introduced automated sandbox process recovery and health probing
capabilities
* Enhanced sandbox lifecycle management with improved destroy, rebuild,
and skill installation workflows

* **Documentation**
* Expanded CLI usage examples across multiple commands for improved
discoverability and guidance

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@cv
cv changed the base branch from refactor/oclif-ux-global-utility-commands to main May 4, 2026 22:17
@cv
cv marked this pull request as ready for review May 4, 2026 22:17
@cv
cv enabled auto-merge (squash) May 4, 2026 22:17
Signed-off-by: Carlos Villela <cvillela@nvidia.com>

@prekshivyas prekshivyas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM after rebase. Tiny additive change — 1 file / +6 / -0, just static examples = [...] on SandboxLogsCommand for richer --help output.

Note: the PR description describes substantive flag-validation work (Flags.integer({min:1}), --since regex, SandboxLogsOptions wiring, etc.) but all of that is already present in sandbox-logs-cli-command.ts on main — it landed via earlier PRs in the stack and got absorbed by the rebase. The actual remaining delta here is the examples block.

Public surface unchanged (examples only render in --help). CI: pr.yaml fully green including CodeRabbit; pr-self-hosted build-sandbox-images/arm64 still in flight at review time.

Nit (non-blocking): consider updating the PR description before merging so the squash-merge commit message accurately reflects what's actually being added (examples), not the substantive work that already landed.

@cv
cv merged commit 12a3850 into main May 4, 2026
14 checks passed
cv added a commit that referenced this pull request May 4, 2026
## Summary
Improve the oclif metadata and parser-owned validation for read-only
sandbox diagnostic commands. This keeps public sandbox-scoped help
output stable while making `doctor` and `config get` validation stricter
in the command adapter.

## Stack Navigation
- Position: 14 of 60
- Previous PR: [#2905 — refactor(cli): validate logs flags with
oclif](#2905)
- Next PR: [#2907 — refactor(cli): tighten policy and channel parser
validation](#2907)

## Changes
- Added examples for `connect`, sandbox-scoped `status`, `doctor`,
`config get`, `policy-list`, and `channels list` adapters.
- Made `sandbox:doctor` a strict oclif command with a required sandbox
arg and `--json` flag.
- Moved `config get --format` validation into oclif with `json|yaml`
options and removed the adapter-level manual format check.
- Preserved public `doctor --help` output through legacy dispatch and
expanded diagnostics validation coverage.
- Updated the hidden command registry metadata for `config get` flags.

## Type of Change
- [x] Code change (feature, bug fix, or refactor)
- [ ] Code change with doc updates
- [ ] Doc only (prose changes, no code sample modifications)
- [ ] Doc only (includes code sample changes)

## Verification
- [x] `npx prek run --all-files` passes
- [x] `npm test` passes
- [x] Tests added or updated for new or changed behavior
- [x] No secrets, API keys, or credentials committed
- [ ] Docs updated for user-facing behavior changes
- [ ] `make docs` builds without warnings (doc changes only)
- [ ] Doc pages follow the [style
guide](https://github.com/NVIDIA/NemoClaw/blob/main/docs/CONTRIBUTING.md)
(doc changes only)
- [ ] New doc pages include SPDX header and frontmatter (new pages only)

---
Signed-off-by: Carlos Villela <cvillela@nvidia.com>


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added command usage examples to help documentation for configuration,
status, policy, and channels commands.
  * Enhanced doctor command with explicit `--json` flag support.

* **Improvements**
* Updated configuration command help text to clearly advertise available
options (`--key` and `--format json|yaml`).
* Restricted `--format` flag to `json` and `yaml` values with stricter
validation.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Carlos Villela <cvillela@nvidia.com>
@cv
cv deleted the refactor/oclif-ux-logs-flags branch May 27, 2026 21:18
@wscurran wscurran added the refactor PR restructures code without intended behavior change label Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor PR restructures code without intended behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants