Skip to content

refactor(openclaw): migrate chat-send and device self-approval patch tools to .mts - #6967

Merged
cv merged 4 commits into
mainfrom
refactor/6928-6930-openclaw-patch-tools-mts
Jul 16, 2026
Merged

refactor(openclaw): migrate chat-send and device self-approval patch tools to .mts#6967
cv merged 4 commits into
mainfrom
refactor/6928-6930-openclaw-patch-tools-mts

Conversation

@laitingsheng

@laitingsheng laitingsheng commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Migrate the two OpenClaw compatibility patch tools from CommonJS to typed ESM .mts entrypoints that Node executes under native type stripping without tsx, following the patch-openclaw-mcp-npx.mts precedent. Module-boundary migration only — no patch shape, selector, marker, idempotency, exit-code, or audit-output change. The two tools share the Dockerfile patch block, the staged build context, the dependency-review note, and several test harnesses, so they move together in one change.

Related Issue

Resolves #6928
Resolves #6930
Part of #6918

Changes

Two commits, one per tool.

patch-openclaw-chat-send (#6928) — was plain CommonJS JavaScript:

  • scripts/patch-openclaw-chat-send.js.mts: requirenode: imports, shebang → #!/usr/bin/env -S node --experimental-strip-types, usage string, and explicit types across the patch helpers and the file-spec model (the file was untyped, so a typed .mts needs annotations to pass tsconfig.cli.json).
  • Dockerfile: COPY/chmod paths, and the RUN step gains --experimental-strip-types since the tool is no longer plain JavaScript.

patch-openclaw-device-self-approval (#6930) — was CommonJS-style TypeScript:

  • scripts/patch-openclaw-device-self-approval.ts.mts: require→imports and the redundant "use strict" directive dropped (ESM is strict). The Dockerfile RUN already passed --experimental-strip-types, so only the path extension changes.

Shared surface (both):

  • src/lib/sandbox/build-context.ts: staged build-context copy paths.
  • docs/security/openclaw-2026.6.10-dependency-review.md: script path references in the reviewed source boundary and the Patch 8 row.
  • Tests: openclaw-chat-send-patch, openclaw-device-self-approval-patch, openclaw-dependency-review (exact Dockerfile COPY/RUN contract), openclaw-integrity-pin-suite, openclaw-real-patched-dist-harness, sandbox-build-context, and the device patch harness.

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)

Quality Gates

  • Tests added or updated for changed behavior
  • Existing tests cover changed behavior — justification: the patch apply/--audit behaviour, selectors, markers, exit codes, upgrade contract, and the exact Dockerfile COPY/RUN lines are already pinned by openclaw-chat-send-patch, openclaw-device-self-approval-patch, openclaw-dependency-review, the integrity-pin suites, and sandbox-build-context; the migration repoints paths and module format without changing the contract, and those suites stay green.
  • Tests not applicable — justification:
  • Docs updated for user-facing behavior changes
  • Docs not applicable — justification: the only docs/ change is the internal security dependency-review note's script-path references; no user-facing page or behaviour changes.
  • Sensitive paths changed (security, policy, credentials, preflight, onboarding, inference, runner, sandbox, or messaging)
  • Sensitive-path review completed or maintainer-approved waiver recorded — reviewer/approval link/justification: module-format migration only; every patch selector, marker, and the device authorization/credential behaviour is byte-for-byte unchanged and covered by the patch and real-dist harness tests; awaiting maintainer sensitive-path review.
  • Non-success, skipped, or missing CI check accepted by maintainer — check name, approval link, and follow-up issue:

Verification

  • PR description includes a Signed-off-by: line and every commit appears as Verified in GitHub
  • Normal pre-commit, commit-msg, and pre-push hooks passed, or npm run check:diff passed when hooks were skipped or unavailable
  • Targeted behavior tests pass for the current change set, or tests are marked not applicable above — command/result: npx vitest run on the chat-send, device, dependency-review, sandbox-build-context, and integrity-pin suites → 101 passed; npm run typecheck:cli → pass (merged base, Node 22.22).
  • Applicable broad gate passed — npm test for broad runtime/test-harness changes; npm run check for repo-wide validation/coverage changes — command/result:
  • Quality Gates section completed with required justifications or waivers
  • No secrets, API keys, or credentials committed
  • npm run 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: Tinson Lai tinsonl@nvidia.com

Summary by CodeRabbit

  • Bug Fixes

    • Updated OpenClaw patch handling to use .mts TypeScript ESM modules for chat-send and device self-approval, improving compatibility across Docker and sandbox runtime patching.
    • Improved patch execution reliability with stricter, typed patch outcomes and safer processing behavior.
  • Documentation

    • Refreshed security/dependency review documentation and patch source references to match the new .mts patch script filenames.
  • Tests

    • Updated patch, harness, sandbox staging, Docker/build-context, and integrity/dependency review tests to validate the .mts module format.

Convert scripts/patch-openclaw-chat-send.js to a typed ESM .mts entrypoint run
under Node native type stripping, adding explicit types across the patch
helpers and the file-spec model. Update the shebang, usage string, Docker
copy/run paths, staged build context, and focused patch and build-context
tests; the RUN step gains --experimental-strip-types since the tool is no
longer plain JavaScript. Patch selectors, markers, idempotency, exit codes,
and audit output are unchanged.

Signed-off-by: Tinson Lai <tinsonl@nvidia.com>
Convert scripts/patch-openclaw-device-self-approval.ts to an explicit ESM .mts
entrypoint: the node:fs/node:path requires become imports and the redundant
"use strict" directive is dropped. Update the usage string, Docker copy/run
paths, staged build context, dependency-review note, and focused patch,
contract, and integrity-pin tests. Every CLI, handler, state, transaction, and
rollback selector and marker is byte-for-byte unchanged.

Signed-off-by: Tinson Lai <tinsonl@nvidia.com>

# Conflicts:
#	docs/security/openclaw-2026.6.10-dependency-review.md
@laitingsheng laitingsheng added the chore Build, CI, dependency, or tooling maintenance label Jul 15, 2026
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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: 32bb4c3c-f68a-47e2-a654-d46d419e3863

📥 Commits

Reviewing files that changed from the base of the PR and between cc5046e and ed3f6eb.

📒 Files selected for processing (4)
  • Dockerfile
  • src/lib/sandbox/build-context.ts
  • test/openclaw-dependency-review.test.ts
  • test/sandbox-build-context.test.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • test/openclaw-dependency-review.test.ts
  • src/lib/sandbox/build-context.ts
  • Dockerfile

📝 Walkthrough

Walkthrough

The OpenClaw chat-send and device self-approval patch tools were migrated to .mts entrypoints. Docker builds, optimized sandbox staging, documentation, harnesses, and contract tests now reference the new module paths.

Changes

OpenClaw patch module migration

Layer / File(s) Summary
Typed chat-send patch implementation
scripts/patch-openclaw-chat-send.mts
The chat-send patch uses typed ESM contracts for patch results, file recognition, resolution, processing, and CLI handling.
Device self-approval ESM entrypoint
scripts/patch-openclaw-device-self-approval.mts
The patch uses ESM imports and reports the updated .mts usage name.
Docker and sandbox integration
Dockerfile, src/lib/sandbox/build-context.ts
Patch copying, executable permissions, runtime execution, and optimized staging now use .mts filenames.
Documentation and validation contracts
docs/security/..., test/...
Dependency notes, harnesses, fixtures, usage assertions, real-dist checks, and Dockerfile contracts now expect the .mts scripts.

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

Possibly related issues

Possibly related PRs

  • NVIDIA/NemoClaw#6941 — Updates the related Docker and sandbox build-context staging pipeline for another OpenClaw patch migration.

Suggested labels: refactor, integration: openclaw

Suggested reviewers: ericksoa, atulya-singh

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 and concisely summarizes the main change: migrating the OpenClaw patch tools to .mts.
Linked Issues check ✅ Passed The PR matches the linked issues by migrating both patch tools to .mts and updating Docker, build-context, harness, docs, and tests without changing patch behavior.
Out of Scope Changes check ✅ Passed The changed files are all supporting pieces for the .mts migration and do not introduce unrelated scope.
✨ 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/6928-6930-openclaw-patch-tools-mts

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

@github-code-quality

github-code-quality Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Code Coverage Overview

Languages: TypeScript

TypeScript / code-coverage/plugin

The overall coverage remains at 96%, unchanged from the main branch.

TypeScript / code-coverage/cli

The overall coverage in the refactor/6928-6930-o... branch remains at 80%, unchanged from the main branch.

Show a code coverage summary of the most impacted files.
File main d03e9d7 refactor/6928-6930-o... ed3f6eb +/-
src/lib/agent/dashboard-ui.ts 89% 85% -4%
src/lib/state/o...estore-input.ts 96% 93% -3%
src/lib/agent/m...fest-readers.ts 97% 95% -2%
src/lib/securit...ntial-filter.ts 99% 98% -1%
src/lib/adapter...shell/client.ts 83% 88% +5%
src/lib/agent/aliases.ts 94% 100% +6%

Updated July 16, 2026 01:24 UTC
Code Coverage is in Public Preview. Learn more and provide us with your feedback.

@github-actions

Copy link
Copy Markdown
Contributor

@github-actions

github-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

PR Review Advisor — Informational

Advisor assessment: Informational / medium confidence
Next action: No advisor follow-up needed.
Findings: 0 blockers · 0 warnings · 0 suggestions
Status: No actionable findings remain in the canonical review ledger.

Model lanes

  • GPT-5.6 Terra (primary): Completed · medium confidence · 0 blockers · 0 warnings · 0 suggestions
  • Nemotron 3 Ultra (second opinion): Completed · high confidence · 0 blockers · 0 warnings · 0 suggestions
  • Model comparison: normalized findings match; normalized E2E selections differ; severity counts match.

Nemotron output stays in workflow artifacts and does not change the assessment above.

E2E guidance

Advisory only. E2E / PR Gate selects and runs jobs independently.

Recommended E2E: cloud-onboard

2 optional E2E recommendations
  • openclaw-tui-chat-correlation
  • issue-4462-scope-upgrade-approval

Workflow run details

This automated review informs maintainers. Warnings and suggestions do not require a response. A maintainer decides whether to merge.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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)
scripts/patch-openclaw-chat-send.mts (1)

402-443: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Fail closed instead of silently skipping an unresolved file.

resolveFile(..., { dryRun: false }) already marks optional files as skipped and calls fail() when a required file cannot be resolved. Therefore, if (!file) continue is unreachable today and could hide a future contract regression by reporting success without applying a required patch. Replace it with a fail-closed assertion or remove the redundant fallback.

Based on learnings, avoid adding defensive error handling around internal helper logic when no realistic failure mode exists. As per coding guidelines, do not add fallback layers without a current requirement.

🤖 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 `@scripts/patch-openclaw-chat-send.mts` around lines 402 - 443, Remove the
redundant `if (!file) continue` fallback in `runApplyMode` after `resolveFile`,
or replace it with a fail-closed assertion that calls `fail()` when no file is
resolved. Preserve the existing `skipped` handling and ensure unresolved
required files cannot be reported as successfully processed.

Sources: Coding guidelines, Learnings

🤖 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/sandbox-build-context.test.ts`:
- Around line 111-114: Extend the fixture assertions around writeFixture and the
optimized-context checks to verify superseded staged paths are absent, not only
that the new .mts files exist. Seed the legacy filenames where needed or
explicitly assert both old paths—patch-openclaw-chat-send.js and
patch-openclaw-device-self-approval.ts—do not exist, including the corresponding
cases noted in the comment.

---

Nitpick comments:
In `@scripts/patch-openclaw-chat-send.mts`:
- Around line 402-443: Remove the redundant `if (!file) continue` fallback in
`runApplyMode` after `resolveFile`, or replace it with a fail-closed assertion
that calls `fail()` when no file is resolved. Preserve the existing `skipped`
handling and ensure unresolved required files cannot be reported as successfully
processed.
🪄 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: 508243bc-8014-4fa4-aeda-e3042cff5983

📥 Commits

Reviewing files that changed from the base of the PR and between 3c9159f and cc5046e.

📒 Files selected for processing (11)
  • Dockerfile
  • docs/security/openclaw-2026.6.10-dependency-review.md
  • scripts/patch-openclaw-chat-send.mts
  • scripts/patch-openclaw-device-self-approval.mts
  • src/lib/sandbox/build-context.ts
  • test/helpers/openclaw-device-self-approval-patch-harness.ts
  • test/openclaw-chat-send-patch.test.ts
  • test/openclaw-dependency-review.test.ts
  • test/openclaw-integrity-pin-suite.ts
  • test/openclaw-real-patched-dist-harness.test.ts
  • test/sandbox-build-context.test.ts

Comment thread test/sandbox-build-context.test.ts
@prekshivyas prekshivyas self-assigned this Jul 16, 2026
Signed-off-by: Prekshi Vyas <prekshiv@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.

Reviewed the OpenClaw patch-tool migration and merge resolution against current main. The build context preserves all current patch tools, explicitly excludes the legacy staged files, and the focused patch/dependency/build-context tests pass.

@cv
cv merged commit 3af09cd into main Jul 16, 2026
84 of 85 checks passed
@cv
cv deleted the refactor/6928-6930-openclaw-patch-tools-mts branch July 16, 2026 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Build, CI, dependency, or tooling maintenance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate the OpenClaw device self-approval patch tool to .mts Migrate the OpenClaw chat-send patch tool to .mts

3 participants