Skip to content

fix(cli): strip terminal controls from Claw project reports - #180625

Closed
wangmiao0668000666 wants to merge 2 commits into
openclaw:mainfrom
wangmiao0668000666:fix/claws-project-terminal-controls
Closed

wangmiao0668000666 wants to merge 2 commits into
openclaw:mainfrom
wangmiao0668000666:fix/claws-project-terminal-controls

Conversation

@wangmiao0668000666

@wangmiao0668000666 wangmiao0668000666 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

openclaw claws create|validate|build|dev write values taken from the project being inspected straight into the human report. In particular, openclaw claws validate <project> prints every entry it excludes:

Excluded: <path>

A checked-out Claw project can contain file and directory names with terminal control bytes, so validating a third-party project can clear the screen (ESC [2J), ring the terminal (BEL), or forge an extra report line with an embedded newline. The requested project root, the Package: <name>@<version> / Built Claw: <name>@<version> lines, and the Claw dev preview agent/workspace lines are written through the same boundary.

Precedent: #174989 (same module, same sanitizeTerminalText helper).

Why This Change Was Made

The human report in src/cli/claws-cli.project.ts is a terminal rendering boundary, and sanitizeTerminalText in packages/terminal-core/src/safe-text.ts is the canonical filter for it. src/cli/claws-cli-output.ts already imports that helper for diagnostics, so this reuses the owner that is already in place instead of adding a validator, option, or output format.

The interpolated report lines now pass their value through the helper: the project root (create, validate), the package name and version (create, validate, build, dev), each excluded path (validate), and the dev preview's agent id and workspace path. The --json branches are untouched.

Package name/version are additionally constrained by the canonical ClawHub-name and exact-semver checks in src/claws/reader.ts, so the control bytes reachable today come from the project root, excluded file names, and the preview workspace path; the identity lines are wrapped at the same boundary so the report does not depend on an upstream validator staying control-free.

Classification: behavior-completing

User Impact

Operators can validate, build, or preview a Claw project without its directory or file names driving the terminal: ESC/BEL are removed and a newline renders as the two characters \n, so each report line stays on one line. Values without control bytes, including the package identity and ordinary excluded paths, print exactly as before. --json callers receive the original bytes.

Evidence (real behavior proof, 2026-10-22 UTC)

Packaged-CLI RED→GREEN on the supported runtime: both builds produced with the repo's own scripts/tsdown-build.mts + runtime-postbuild chain on Node 24.22.1 (satisfies engines.node >=24.22.1 <25), run as node dist/index.js claws … subprocesses in an isolated Linux container with OPENCLAW_STATE_DIR/OPENCLAW_WORKSPACE_DIR pointed at throwaway dirs. No Gateway, session, token, or real config touched.

  • GREEN head: d672ae35b7ae8dc1c377eab85e744aa2765cebaf (exact PR head)
  • RED baseline: ae40e1864ba6ea2a8d0f37362933c6bbf59b2cff (current main, the rebase target)

The fixture: project directory author<ESC>[2J<BEL> plus an excluded file named payload<ESC>[2J<BEL>.bin. <ESC> is the raw byte 0x1b, <BEL> is 0x07; output below is shown through cat -v (^[ = ESC, ^G = BEL).

RED — main dist, human reports:

Created Claw project: /tmp/proof-out/author^[[2J^G
Valid Claw project: /tmp/proof-out/author^[[2J^G
Excluded: payload^[[2J^G.bin
Claw dev preview: [email protected]
Workspace: /tmp/proof-out/author^[[2J^G/preview-workspace
control-byte scan: create-human HAS RAW CONTROL BYTES; validate-human HAS RAW CONTROL BYTES; dev-human HAS RAW CONTROL BYTES

GREEN — exact-head dist, same commands:

Created Claw project: /tmp/proof-out/author
Valid Claw project: /tmp/proof-out/author
Excluded: payload.bin
Claw dev preview: [email protected]
Workspace: /tmp/proof-out/author/preview-workspace
control-byte scan: create-human clean; validate-human clean; dev-human clean

JSON preservation (both revisions, --json): root and excludedPaths carry the original bytes (4 \u001b escapes present in the payload), so machine consumers are unaffected. Legal control: Package: [email protected] and the artifact integrity sha256:5f2af05a… are byte-identical across revisions.

Regression test

src/cli/claws-cli.project.test.ts drives runClawsCreateCommand / runClawsValidateCommand / runClawsDevCommand against real files on disk and asserts the human report contains no control characters while the JSON payload preserves them. The control-character filesystem fixture is guarded to POSIX (it.skipIf(process.platform === "win32")), because Windows rejects those bytes in file names and would fail in fixture setup instead of exercising the sanitizer.

exact head d672ae35b7 — vitest.cli.config.ts shard, bare vitest, --maxWorkers=1
 ✓ Claw project CLI (4 tests, incl. keeps terminal controls out of the human Claw project report)
 Test Files  1 passed (1)
      Tests  4 passed (4)

Revision 2 changes

  • Rebased onto current main (ae40e1864b), which also clears the inherited check-test-types-core-4 red (that failure was main's own sessions-patch.test.ts/PatchFixture skew, fixed upstream in test(gateway): use current fixture for session appearance checks #180628).
  • The control-char filesystem regression is now POSIX-only (review finding).
  • The same sanitization now also covers the Claw dev preview human report (build.claw.name/version, plan.agent.finalId, plan.agent.workspace), and the regression exercises it.

Scope and risk

  • Production LOC: +19/-6 net across create/validate/build/dev human-report lines; 2 files, no new files
  • Existing-solutions preflight: reuses sanitizeTerminalText, the helper already imported by src/cli/claws-cli-output.ts per fix(cli): strip terminal controls from the inspected Claw agent name #174989; no new validator, option, config, or output format
  • Config/default, protocol/schema, authorization, storage, migration, upgrade impact: none

@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: XS labels Oct 22, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 22, 2026
@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR sanitizes project paths and identities in human-readable Claw reports while preserving raw JSON output.

Example: Validate a project containing a file named payload\u001b[2J\u0007\n.bin.

  • Before: The Excluded report emits terminal controls and an embedded newline.
  • After: The report prints Excluded: payload\n.bin on one line, while JSON preserves the original filename.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused existing-owner repair with shipped-entry-point red-to-green proof, a meaningful regression, and the earlier platform defect resolved; required CI is still pending.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The contributor records exact-head packaged CLI create, validate, and dev runs on Node 24.22.1 in an isolated Linux container, showing baseline ESC/BEL output removed after the fix and raw JSON values preserved; the focused regression also covers escaped newlines.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Inspecting a local or third-party Claw project can let filenames alter terminal state or forge report lines.
Reason: The patch repairs a reachable rendering defect using the same policy already accepted in the merged inspection fix, without changing lifecycle behavior or machine output.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current terminal-rendering defect with a focused change and sufficient packaged-CLI proof; the previous Windows finding is resolved, and no introduced correctness defect was found.

Priority: P2
Reviewed head: d672ae35b7ae8dc1c377eab85e744aa2765cebaf

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Claw CLI invokes project creation, validation, building, and preview owners, then renders their results as human-readable reports or JSON.

flowchart TD
  A[Claw CLI commands] --> B[Project lifecycle owners]
  B --> C[Result values]
  C --> D[Terminal text sanitizer]
  D --> E[Human report]
  C --> F[Raw JSON output]
Loading

Technical review

Best possible solution:

Retain the focused sanitization at the existing human-report boundary and land after the required exact-head checks pass.

Do we have a high-confidence way to reproduce the issue?

Current-main interpolation exposes filesystem-derived control characters, and the contributor supplies matching baseline-versus-head packaged-CLI output; this review ran no target code.

Is this the best way to solve the issue?

Reusing the canonical sanitizer at human-output interpolation is the smallest complete fix for the reported fields, preserves JSON bytes, and introduces no competing owner.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against d2c70ddbf19f.

Provenance checked

  • Create, validate, and build report interpolation changes intended behavior with a stated reason (7422222: The local author lifecycle added readable reports for scaffolding, validation, deterministic builds, and offline previews.)
  • Dev preview agent and workspace report placement keeps the original intent (5af1093: The refactor folded single-consumer preparation and reporting into the command owner while preserving output and cleanup behavior; the PR retains that ownership and sanitizes rendering.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Gio Della-Libera: Raw commit 7422222 adds src/cli/claws-cli.project.ts:151 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 7422222788c4; files: src/cli/claws-cli.project.ts)

PR surface

Source +9, Tests +28. Total +37 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 18 9 +9
Tests 1 28 0 +28
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 46 9 +37

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Control characters in project filenames can manipulate local authoring reports; the fix has a limited display-only scope.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-22T13:20:13.111Z sha 17be788ca3b9039f0585bd1b4b9ae97d5525972c :: needs real behavior proof before merge. :: [P2] Limit the control-character filesystem fixture to POSIX platforms

Reviewed October 22, 2026, 1:07 PM ET / 17:07 UTC (Revision 2).

@wangmiao0668000666
wangmiao0668000666 force-pushed the fix/claws-project-terminal-controls branch from 17be788 to d672ae3 Compare October 22, 2026 15:18
@openclaw-barnacle openclaw-barnacle Bot reopened this Oct 22, 2026
@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Revision 2 (head d672ae35b7):

  • Finding addressed: the control-character filesystem regression is now POSIX-only (it.skipIf(process.platform === "win32")); Windows would reject ESC/BEL/newline in file names during fixture setup.
  • Same boundary extended: the Claw dev preview human report (name/version, agent id, workspace path) now goes through sanitizeTerminalText too — main printed the preview workspace with raw control bytes (see RED below).
  • Proof upgraded to the packaged CLI on a supported runtime: both revisions were built with the repo's own tsdown + runtime-postbuild chain and run as node dist/index.js claws create|validate|dev subprocesses on Node 24.22.1 (satisfies engines.node), isolated state/workspace dirs. RED (main ae40e1864b): all three human reports contain raw ESC[2J/BEL; GREEN (exact head d672ae35b7): all three clean, --json payloads preserve the original bytes on both revisions. Full transcripts in the Evidence section.
  • CI note: the earlier check-test-types-core-4 red was inherited from main's own sessions-patch.test.ts/PatchFixture skew (fixed upstream in test(gateway): use current fixture for session appearance checks #180628); the rebase clears it.

@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 22, 2026
@wangmiao0668000666
wangmiao0668000666 deleted the fix/claws-project-terminal-controls branch October 23, 2026 01:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant