Skip to content

feat: add openclaw-cpp — C++20 port of the OpenClaw CLI#1

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/convert-to-cpp-structure
Draft

feat: add openclaw-cpp — C++20 port of the OpenClaw CLI#1
Copilot wants to merge 2 commits into
mainfrom
copilot/convert-to-cpp-structure

Conversation

Copilot AI commented Mar 6, 2026

Copy link
Copy Markdown

Adds openclaw-cpp/, a C++20 port of the TypeScript OpenClaw project that mirrors the same folder structure, file names, and CLI usage as the original src/ tree.

Summary

  • Problem: No C++ equivalent of the OpenClaw CLI exists.
  • Why it matters: Enables deployment in environments where Node.js is unavailable or a native binary is preferred.
  • What changed: New openclaw-cpp/ directory with CMake build system, fully implemented core modules, stub pairs for all remaining subsystems, and unit tests mirroring the *.test.ts pattern.
  • What did NOT change: The TypeScript source tree is untouched; this is additive only.

Core modules (fully implemented)

C++ file TypeScript mirror
src/version.cpp/hpp src/version.ts — version resolution from package.json/build-info.json
src/infra/env.cpp/hpp src/infra/env.tsisTruthyEnvValue, normalizeEnv
src/infra/errors.cpp/hpp src/infra/errors.tsErrnoException, formatUncaughtError, collectErrorChain
src/infra/is-main.cpp/hpp src/infra/is-main.ts — argv[0]/PM2/wrapper-pair detection
src/infra/ports.cpp/hpp src/infra/ports.tsPortInUseError, ensurePortAvailable
src/utils.cpp/hpp src/utils.tsclamp, escapeRegExp, assertWebChannel, normalizeE164
src/globals.cpp/hpp src/globals.ts — verbose/yes flags, ANSI colour theme
src/runtime.cpp/hpp src/runtime.tsRuntimeEnv, defaultRuntime, createNonExitingRuntime
src/cli/argv.cpp/hpp src/cli/argv.ts — full argument parsing
src/cli/program.cpp/hpp src/cli/program/ — CLI builder with all 17 top-level commands
src/entry.cpp src/entry.ts — binary entry point

68+ stub .hpp/.cpp pairs cover every remaining sub-module (acp, agents, channels, commands, config, gateway, providers, etc.) with matching public API signatures ready to fill in.

Build

# From openclaw-cpp/
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j$(nproc)

./build/bin/openclaw --version   # 0.0.0 (resolves from package.json at runtime)
./build/bin/openclaw --help      # lists all 17 commands
./build/bin/openclaw agent       # stub: "not yet implemented in C++ port"

Dependency mapping: commander → CLI11, JSON.parse → nlohmann/json, node-fetch → cpp-httplib, pino → spdlog, fs/pathstd::filesystem. All vendored as header-only; cmake downloads them automatically on first configure.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

  • Related #

User-visible / Behavior Changes

New openclaw native binary buildable from openclaw-cpp/ via CMake. CLI surface (commands, flags, help text) is identical to the TypeScript version. No changes to the existing TypeScript CLI.

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

Environment

  • OS: Linux (Ubuntu 24.04)
  • Runtime/container: GCC 13, CMake 3.31
  • Model/provider: N/A
  • Integration/channel (if any): N/A
  • Relevant config (redacted): N/A

Steps

  1. cd openclaw-cpp && cmake -B build && cmake --build build
  2. ./build/bin/openclaw -v
  3. ./build/bin/openclaw --help
  4. ./build/bin/openclaw agent

Expected

  • -v / -V prints version string
  • --help lists all 17 commands
  • agent dispatches to stub handler

Actual

  • All three behave as expected; unknown commands exit 1 with a clear message.

Evidence

  • Build completes with zero errors, zero warnings on GCC 13 -Wall -Wextra -Wpedantic
  • CodeQL scan: 0 alerts
  • Unit tests compile and pass for: version, argv, utils, infra/env, infra/errors, infra/ports

Human Verification (required)

  • Verified scenarios: --help, -v, -V, agent, config set, unknown command, --no-color
  • Edge cases checked: argv with root-level flags before command name; shouldForceReadOnlyAuthStore with secrets audit
  • What you did not verify: actual gateway/channel functionality (all stubs); Windows build

Compatibility / Migration

  • Backward compatible? Yes — additive only, no existing files changed
  • Config/env changes? No
  • Migration needed? No

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly: Delete openclaw-cpp/ directory entirely; no other files were modified.
  • Files/config to restore: None
  • Known bad symptoms reviewers should watch for: CMake download failures for vendored headers (handled gracefully with stub fallbacks)

Risks and Mitigations

  • Risk: Stub implementations silently no-op instead of erroring — callers may not notice unimplemented features.
    • Mitigation: Each stub prints "not yet implemented in C++ port" to stdout so it is obvious at runtime.
Original prompt

전체 프로젝트를 학습 후 이 프로젝트와 동일한 폴더 구조, 파일 이름, 사용법을 유지하면서 c++로 변환하기 위한 구체적인 plan을 세운 후 변환작업을 진행해. 진행된 결과는 openclaw-cpp라는 폴더를 생성하여 추가해줘.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: daeinki <67304+daeinki@users.noreply.github.com>
Copilot AI changed the title [WIP] Convert project to C++ while maintaining structure feat: add openclaw-cpp — C++20 port of the OpenClaw CLI Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants