Skip to content

refactor(cli): group state modules#2989

Merged
cv merged 89 commits intomainfrom
refactor/layer-state-modules
May 6, 2026
Merged

refactor(cli): group state modules#2989
cv merged 89 commits intomainfrom
refactor/layer-state-modules

Conversation

@cv
Copy link
Copy Markdown
Contributor

@cv cv commented May 4, 2026

Summary

Move registry, config, path, gateway, session, and sandbox persistence modules into src/lib/state/** so persistence boundaries are visible in paths.

Stack Navigation

Changes

  • Moved registry/config/path/gateway/session/sandbox state modules under src/lib/state/.
  • Moved co-located state tests and updated dist/source paths in integration tests.
  • Updated action, command, onboarding, policy, service, and test imports to the new state paths.
  • Updated CodeRabbit path instructions and migrated-path guard canonical paths for moved state modules.
  • Kept behavior unchanged; this PR is a structural move plus import updates.

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 --stage pre-push passes
  • npm run build:cli
  • npm run typecheck:cli
  • npx tsx scripts/check-layer-import-boundaries.ts
  • State and registry targeted tests pass
  • 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

  • Refactor

    • Internal state modules reorganized into a dedicated state/ layout for clearer structure and maintainability.
  • New Feature

    • Registry entries now support an optional imageTag field, allowing sandbox records to include image metadata.

cv added 30 commits May 2, 2026 13:36
@cv cv self-assigned this May 4, 2026
@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot Bot commented May 4, 2026

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
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 4, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: b137cbc8-cd6f-40c2-ac17-8ce259d33a12

📥 Commits

Reviewing files that changed from the base of the PR and between 7f14fbb and 176aed0.

📒 Files selected for processing (27)
  • .coderabbit.yaml
  • src/lib/actions/maintenance.ts
  • src/lib/actions/sandbox/connect.ts
  • src/lib/actions/sandbox/policy-channel.ts
  • src/lib/actions/sandbox/process-recovery.ts
  • src/lib/actions/sandbox/rebuild.ts
  • src/lib/actions/sandbox/snapshot.ts
  • src/lib/actions/sandbox/status.ts
  • src/lib/agent-runtime.ts
  • src/lib/messaging-conflict.test.ts
  • src/lib/messaging-conflict.ts
  • src/lib/onboard.ts
  • src/lib/policies.ts
  • src/lib/registry-recovery-action.test.ts
  • src/lib/registry-recovery-action.ts
  • src/lib/sandbox-config.ts
  • src/lib/sandbox-create-stream.ts
  • src/lib/state/sandbox.ts
  • src/nemoclaw.ts
  • test/config-set-cli-dispatch.test.ts
  • test/credential-rotation.test.ts
  • test/e2e/brev-e2e.test.ts
  • test/onboard-preset-diff.test.ts
  • test/onboard-selection.test.ts
  • test/onboard.test.ts
  • test/policies.test.ts
  • test/snapshot.test.ts

📝 Walkthrough

Walkthrough

Moves various state-related modules into a new src/lib/state/ subtree and updates imports, scripts, and tests to reference the new paths. No runtime behavior or public API signatures were altered.

Changes

State module relocation and path wiring

Layer / File(s) Summary
Data Shape / Core state files
src/lib/state/registry.ts, src/lib/state/sandbox.ts, src/lib/state/sandbox-session.ts, src/lib/state/config-io.ts, src/lib/state/gateway.ts, src/lib/state/paths.ts
Core state modules now live under src/lib/state/. paths.ts ROOT traversal changed to reach repo root (two → three levels up). Internal relative imports within these files adjusted to parent-directory paths.
Core Implementation usages
src/lib/*.ts, src/lib/actions/**/*, src/lib/agent-runtime.ts, src/nemoclaw.ts
All internal imports that previously referenced modules like ./registry, ./sandbox-state, ./sandbox-session-state, ./config-io, ./gateway-state, and ./paths were updated to their ./state/* equivalents across source files.
Wiring / Scripts / Tooling
.coderabbit.yaml, scripts/check-legacy-migrated-paths.ts, scripts/dev-tier-selector.js, scripts/ts-migration-assist.ts
Configuration and migration tooling updated to reference new state/ module locations (e.g., path_instructions, REMOVED_SHIM_MOVES, registry import rewrites).
Tests / Mocks / Dist path updates
test/**/*.test.ts, src/lib/*/*.test.ts, src/lib/state/*.test.ts
Tests and mocks updated to import/require the relocated dist modules (e.g., dist/lib/state/registry.js, dist/lib/state/sandbox.js) and to expect source files under src/lib/state. One test added/updated asserting SandboxEntry.imageTag optionality.
Documentation / Comments
src/lib/onboard.ts, test/e2e/brev-e2e.test.ts
Inline comments/docblocks updated to reference new state/ module paths.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🐰
I hopped through files, one by one,
Moved state to tidy under sun,
Paths now point where they belong,
Imports sing a tidy song,
A small refactor, neat and fun.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% 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 'refactor(cli): group state modules' clearly and accurately summarizes the main change: moving state-related modules into a src/lib/state/ directory for better organization.
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/layer-state-modules

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

@wscurran wscurran added NemoClaw CLI Use this label to identify issues with the NemoClaw command-line interface (CLI). refactor This is a refactor of the code and/or architecture. labels May 4, 2026
@cv cv requested a review from prekshivyas May 5, 2026 00:27
@cv cv added the v0.0.35 Release target label May 5, 2026
@prekshivyas prekshivyas self-assigned this May 5, 2026
@cjagwani cjagwani assigned cjagwani and unassigned cjagwani May 5, 2026
@ericksoa ericksoa added v0.0.36 Release target and removed v0.0.35 Release target labels May 6, 2026
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: 1

🧹 Nitpick comments (1)
src/lib/state/sandbox.ts (1)

29-33: Run the targeted sandbox persistence E2E jobs before merge.

Given this file’s persistence role, please run:

  • snapshot-commands-e2e
  • rebuild-openclaw-e2e

As per coding guidelines src/lib/state/sandbox.ts: “Changes affect data persistence across sandbox lifecycle operations” with the listed E2E recommendations.

🤖 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 `@src/lib/state/sandbox.ts` around lines 29 - 33, This change affects sandbox
persistence; before merging, run the targeted E2E jobs snapshot-commands-e2e and
rebuild-openclaw-e2e and ensure they pass; if they fail, investigate and fix
persistence-related logic in sandbox lifecycle code referenced in this file
(look at functions and modules imported here such as loadAgent,
resolveOpenshell, captureOpenshellCommand, sanitizeConfigFile, isSensitiveFile,
and shellQuote) and re-run the E2E jobs until green.
🤖 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 `@test/gateway-liveness-probe.test.ts`:
- Around line 75-84: The test's description references the old module name
"gateway-state.ts"; update the it(...) title in
test/gateway-liveness-probe.test.ts to reflect the current module path (e.g.,
change "does not modify isGatewayHealthy() in gateway-state.ts" to "does not
modify isGatewayHealthy() in src/lib/state/gateway.ts" or similar) so failure
messages point to the correct file; keep the rest of the test (the
fs.readFileSync and regex against isGatewayHealthy) unchanged.

---

Nitpick comments:
In `@src/lib/state/sandbox.ts`:
- Around line 29-33: This change affects sandbox persistence; before merging,
run the targeted E2E jobs snapshot-commands-e2e and rebuild-openclaw-e2e and
ensure they pass; if they fail, investigate and fix persistence-related logic in
sandbox lifecycle code referenced in this file (look at functions and modules
imported here such as loadAgent, resolveOpenshell, captureOpenshellCommand,
sanitizeConfigFile, isSensitiveFile, and shellQuote) and re-run the E2E jobs
until green.
🪄 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: CHILL

Plan: Enterprise

Run ID: fbe5bb22-a237-4848-9dc3-443c9372d386

📥 Commits

Reviewing files that changed from the base of the PR and between 301b0a7 and 668235a.

📒 Files selected for processing (61)
  • .coderabbit.yaml
  • scripts/check-legacy-migrated-paths.ts
  • scripts/dev-tier-selector.js
  • scripts/ts-migration-assist.ts
  • src/lib/actions/maintenance.ts
  • src/lib/actions/sandbox/connect.ts
  • src/lib/actions/sandbox/destroy.ts
  • src/lib/actions/sandbox/doctor.ts
  • src/lib/actions/sandbox/gateway-state.ts
  • src/lib/actions/sandbox/policy-channel.ts
  • src/lib/actions/sandbox/rebuild.ts
  • src/lib/actions/sandbox/snapshot.ts
  • src/lib/actions/sandbox/status.ts
  • src/lib/actions/upgrade-sandboxes.ts
  • src/lib/agent-runtime.ts
  • src/lib/commands/debug.ts
  • src/lib/commands/simple-global-oclif-adapters.test.ts
  • src/lib/commands/tunnel/common.ts
  • src/lib/credentials.ts
  • src/lib/debug.ts
  • src/lib/http-probe.ts
  • src/lib/list-command-deps.ts
  • src/lib/messaging-conflict.test.ts
  • src/lib/messaging-conflict.ts
  • src/lib/onboard.ts
  • src/lib/policies.ts
  • src/lib/registry-recovery-action.ts
  • src/lib/sandbox-config.ts
  • src/lib/sandbox-create-stream.ts
  • src/lib/sandbox-version.test.ts
  • src/lib/sandbox-version.ts
  • src/lib/shields-audit.ts
  • src/lib/state/config-io.test.ts
  • src/lib/state/config-io.ts
  • src/lib/state/gateway.ts
  • src/lib/state/paths.test.ts
  • src/lib/state/paths.ts
  • src/lib/state/registry.ts
  • src/lib/state/sandbox-session.test.ts
  • src/lib/state/sandbox-session.ts
  • src/lib/state/sandbox.ts
  • src/lib/status-command-deps.ts
  • src/nemoclaw.ts
  • test/credential-rotation.test.ts
  • test/e2e/brev-e2e.test.ts
  • test/gateway-liveness-probe.test.ts
  • test/gateway-state.test.ts
  • test/image-cleanup.test.ts
  • test/onboard-preset-diff.test.ts
  • test/onboard-resume-provider-recovery.test.ts
  • test/onboard-selection.test.ts
  • test/onboard.test.ts
  • test/policies.test.ts
  • test/policy-tiers-onboard.test.ts
  • test/rebuild-policy-presets.test.ts
  • test/registry.test.ts
  • test/repro-2010.test.ts
  • test/security-sandbox-tar-traversal.test.ts
  • test/shellquote-sandbox.test.ts
  • test/shields.test.ts
  • test/snapshot.test.ts

Comment thread test/gateway-liveness-probe.test.ts Outdated
@cv
Copy link
Copy Markdown
Contributor Author

cv commented May 6, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 6, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

cv added a commit that referenced this pull request May 6, 2026
## Summary
Move top-level/global workflow action modules into `src/lib/actions/**`
so command adapters call a visible action layer instead of flat
`src/lib` modules.

## Stack Navigation
- Position: 58 of 60
- Previous PR: [#2987 — refactor(cli): group sandbox
actions](#2987)
- Next PR: [#2989 — refactor(cli): group state
modules](#2989)

## Changes
- Moved deploy, maintenance, onboarding facade, root help,
upgrade-sandboxes, and global action facade modules under
`src/lib/actions/`.
- Moved the global action facade test with the module.
- Updated command adapters, root bootstrap, integration tests, and
callers to the new paths.
- Kept behavior unchanged; this PR is a structural move plus import
updates.

## 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 --stage pre-push` passes
- [x] `npm run build:cli`
- [x] `npm run typecheck:cli`
- [x] `npx tsx scripts/check-layer-import-boundaries.ts`
- [x] Global command/action targeted tests pass
- [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 (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

* **Refactor**
* Internal reorganization of CLI action module structure for improved
code organization and maintainability.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Carlos Villela <cvillela@nvidia.com>
Co-authored-by: Prekshi Vyas <34834085+prekshivyas@users.noreply.github.com>
@cv cv marked this pull request as ready for review May 6, 2026 18:08
@cv cv changed the base branch from refactor/layer-global-actions to main May 6, 2026 18:08
@cv cv enabled auto-merge (squash) May 6, 2026 18:08
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
Copy link
Copy Markdown
Contributor

@prekshivyas prekshivyas left a comment

Choose a reason for hiding this comment

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

LGTM. Same #2984/#2985/#2988-pattern PR — pure file-organization, 64 files / +138 / -138.

State modules (gateway, sandbox-session, config-io, paths, registry, sandbox) moved to src/lib/state/. Most consumer files +1/-1 or +2/-2 import-path updates. Largest individual diff is test/onboard.test.ts (+32/-32) — many state imports updated.

Tooling companions: .coderabbit.yaml path instructions, scripts/check-legacy-migrated-paths.ts guard list, scripts/dev-tier-selector.js, scripts/ts-migration-assist.ts — all single-line path migrations required by the move.

Verification checklist explicitly cites running check-layer-import-boundaries.ts from #2986.

CI: pr.yaml mostly green (lint/dco/check-hash/legacy-path-guard/changes PASS); macos-e2e/wsl-e2e/checks + pr-self-hosted builds still in flight at review time. No failures.

@cv cv merged commit f1c54ba into main May 6, 2026
12 of 13 checks passed
cv added a commit that referenced this pull request May 6, 2026
## Summary
Move the Docker adapter package under `src/lib/adapters/docker/**` so
Docker process boundaries live with the other adapter modules.

## Stack Navigation
- Position: 60 of 60
- Previous PR: [#2989 — refactor(cli): group state
modules](#2989)
- Next PR: top of stack

## Changes
- Moved `src/lib/docker/**` to `src/lib/adapters/docker/**`.
- Updated Docker adapter imports across actions, onboarding/runtime
helpers, services, shields, and tests.
- Updated the Docker abstraction guard to use the new adapter path.
- Kept behavior unchanged; this PR is a structural move plus import
updates.

## 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 --stage pre-push` passes
- [x] `npm run build:cli`
- [x] `npm run typecheck:cli`
- [x] `npx tsx scripts/check-layer-import-boundaries.ts`
- [x] Docker adapter targeted tests pass
- [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 (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

* **Refactor**
* Reorganized internal Docker utility modules for improved code
organization and maintainability. This structural change enhances the
codebase architecture without affecting any user-facing functionality or
features.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Carlos Villela <cvillela@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

NemoClaw CLI Use this label to identify issues with the NemoClaw command-line interface (CLI). refactor This is a refactor of the code and/or architecture. v0.0.36 Release target

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants