| 1 | # HarmonyOS and OpenHarmony |
| 2 | |
| 3 | > 阅读简体中文版:[zh_hans/HarmonyOS.md](zh_hans/HarmonyOS.md)。 |
| 4 | |
| 5 | Codewhale runs on HarmonyOS PC two ways: the Linux ARM64 build inside the Linux |
| 6 | subsystem (融合开发引擎), or a native ARM64 build for OpenHarmony's own userspace. |
| 7 | Native HarmonyOS remains a Tier 2 cross-build target. The SDK check does not |
| 8 | establish device-level TUI, editor or model-turn qualification. |
| 9 | |
| 10 | ## Which One To Use |
| 11 | |
| 12 | | Target | How to run it | Distribution | |
| 13 | | --- | --- | --- | |
| 14 | | HarmonyOS PC, Linux subsystem (openEuler) | The ordinary Linux ARM64 build — it is a Linux virtual machine | GitHub release binaries; `install.sh`; npm secondary | |
| 15 | | Native HarmonyOS and OpenHarmony | `aarch64-unknown-linux-ohos`, signed before it will execute | `codewhale-ohos-arm64.tar.gz` when a release lists it; otherwise build and sign from source | |
| 16 | |
| 17 | Native HarmonyOS is not a Linux distribution: its userspace uses OpenHarmony's |
| 18 | musl-based C library and system APIs, so the Linux build does not run there. |
| 19 | Pick the subsystem if you want the shortest path; pick the native build when you |
| 20 | want no virtual machine between Codewhale and the device. |
| 21 | |
| 22 | ## Inside The Linux Subsystem |
| 23 | |
| 24 | Open a terminal in the subsystem and use the official installer: |
| 25 | |
| 26 | ```bash |
| 27 | curl -fsSL https://codewhale.net/install.sh | sh |
| 28 | "$HOME/.local/bin/codewhale" --version |
| 29 | ``` |
| 30 | |
| 31 | `codewhale update` upgrades it. For an occupied directory or a package-managed |
| 32 | install, see [the fresh-directory migration](INSTALL.md#migrating-from-npm-cargo-or-another-installation). |
| 33 | |
| 34 | Huawei's [support page](https://consumer.huawei.com/cn/support/content/zh-cn16091898/) |
| 35 | (Chinese; HarmonyOS 6.0, 6.1 and 7.0 desktops and laptops; checked 2026-10-21) |
| 36 | lists what the subsystem does not do: |
| 37 | |
| 38 | - openEuler is the only supported distribution, and it cannot be replaced. |
| 39 | - No service managers: start `sshd` and friends by hand. |
| 40 | - The kernel is fixed, so `modinfo`, `modprobe`, `rmmod` and `insmod` fail. |
| 41 | - Disk images cannot be mounted. Share files through `/mnt/linux_share`, where |
| 42 | new files are owned by root — `sudo git clone` into it if `git clone` refuses. |
| 43 | - No external USB devices or IPv6; `chsh` does not change the login shell. |
| 44 | - At most five snapshots; only the primary user can install the subsystem. |
| 45 | - Docker needs HarmonyOS 7.0 or later. |
| 46 | |
| 47 | ## Native Build |
| 48 | |
| 49 | Set `OHOS_NATIVE_SDK` to the OpenHarmony native SDK — the directory holding |
| 50 | `llvm/bin`, `sysroot` and `build/cmake/ohos.toolchain.cmake`. |
| 51 | |
| 52 | | Requirement | Notes | |
| 53 | | --- | --- | |
| 54 | | OpenHarmony native SDK (6.1 / API 26 used here) | DevEco Studio ships one at `<DevEco>/Contents/sdk/default/openharmony/native`; the public SDK download works too | |
| 55 | | Rust with the OHOS target | `rustup target add aarch64-unknown-linux-ohos` | |
| 56 | | A C toolchain and `cmake` | Both come from the SDK; `scripts/ohos/ohos-env.sh` puts them on `PATH` | |
| 57 | |
| 58 | Linux or macOS: |
| 59 | |
| 60 | ```bash |
| 61 | export OHOS_NATIVE_SDK=/path/to/openharmony/native |
| 62 | . ./scripts/ohos/ohos-env.sh |
| 63 | rustup target add aarch64-unknown-linux-ohos |
| 64 | export CODEWHALE_BUILD_SHA="$(git rev-parse HEAD)" |
| 65 | cargo build --locked --release --target aarch64-unknown-linux-ohos -p codewhale-cli |
| 66 | ``` |
| 67 | |
| 68 | Windows PowerShell: |
| 69 | |
| 70 | ```powershell |
| 71 | $env:OHOS_NATIVE_SDK="<path-to-openharmony-native-sdk>" |
| 72 | . .\scripts\ohos\ohos-env.ps1 |
| 73 | rustup target add aarch64-unknown-linux-ohos |
| 74 | $env:CODEWHALE_BUILD_SHA = (git rev-parse HEAD).Trim() |
| 75 | cargo build --locked --release --target aarch64-unknown-linux-ohos -p codewhale-cli |
| 76 | ``` |
| 77 | |
| 78 | `ohos-env.sh` / `ohos-env.ps1` export the target's linker, `CC`/`CXX`/`AR`, |
| 79 | CMake toolchain and bindgen settings, and put the SDK's own `cmake` on `PATH`, so |
| 80 | nothing machine-specific is checked in. On Windows the final link goes through |
| 81 | `scripts/ohos/ohos-clang.cmd`, which keeps `-target aarch64-linux-ohos`, the |
| 82 | sysroot and `-D__MUSL__` even when the SDK path contains spaces. |
| 83 | |
| 84 | The executable is `target/aarch64-unknown-linux-ohos/release/codewhale` (no |
| 85 | `.exe`, including when built on Windows); `--profile dist`, which the release |
| 86 | workflow uses, writes to `target/aarch64-unknown-linux-ohos/dist/` instead. A cold |
| 87 | release build takes about eight minutes on an Apple silicon laptop. Build from a |
| 88 | clean checkout when you care about the commit stamp — an incremental rebuild will |
| 89 | not re-stamp a binary that did not need rebuilding. Check the output: |
| 90 | |
| 91 | ```bash |
| 92 | file target/aarch64-unknown-linux-ohos/release/codewhale |
| 93 | # ELF 64-bit LSB pie executable, ARM aarch64, … dynamically linked, stripped |
| 94 | |
| 95 | "$OHOS_NATIVE_SDK/llvm/bin/llvm-readelf" -d \ |
| 96 | target/aarch64-unknown-linux-ohos/release/codewhale | grep NEEDED |
| 97 | # libtime_service_ndk.so and libc.so — the system libraries the device provides |
| 98 | ``` |
| 99 | |
| 100 | ## Signing And Installing |
| 101 | |
| 102 | A native HarmonyOS device executes only signed code: an unsigned ELF is refused |
| 103 | at `execve` with `Permission denied`, whatever its mode bits say, and `chmod +x` |
| 104 | does not change that. Signing is part of the build, not optional hardening. An |
| 105 | emulator is more permissive than a retail device, so test on the hardware you |
| 106 | target. |
| 107 | |
| 108 | One command builds, strips a copy, self-signs and verifies: |
| 109 | |
| 110 | ```bash |
| 111 | scripts/ohos/ohos-sign-binary.sh |
| 112 | ``` |
| 113 | |
| 114 | It leaves `target/aarch64-unknown-linux-ohos/release/codewhale-signed` (`--out |
| 115 | PATH` to move it) and fails rather than hand back a file that did not sign. By |
| 116 | hand: |
| 117 | |
| 118 | ```bash |
| 119 | tools="$(dirname "$OHOS_NATIVE_SDK")/toolchains/lib" |
| 120 | java -jar "$tools/binary-sign-tool.jar" sign -selfSign 1 \ |
| 121 | -inFile target/aarch64-unknown-linux-ohos/release/codewhale \ |
| 122 | -outFile target/aarch64-unknown-linux-ohos/release/codewhale |
| 123 | java -jar "$tools/binary-sign-tool.jar" display-sign \ |
| 124 | -inFile target/aarch64-unknown-linux-ohos/release/codewhale # … self-sign |
| 125 | ``` |
| 126 | |
| 127 | The C++ build of the same tool (`<sdk>/toolchains/lib/binary-sign-tool`, no Java |
| 128 | needed) takes identical arguments, and the DevBox app from AppGallery carries it |
| 129 | on the device. To sign while linking instead, add |
| 130 | `rustflags = ["-Clink-arg=-Wl,--code-sign"]` under |
| 131 | `[target.aarch64-unknown-linux-ohos]` in `.cargo/config.toml`; the SDK's `lld` |
| 132 | implements `--code-sign` and leaves it off by default. |
| 133 | |
| 134 | A self-signature is enough locally: it is not bound to a device and runs on any |
| 135 | HarmonyOS PC, but it grants no permissions. Do not sign with the certificate |
| 136 | DevEco Studio generates for app signing — those binaries are refused at run time |
| 137 | with `Operation not permitted` (errno 129). AppGallery Connect issues debugging |
| 138 | certificates if you need permissions; Codewhale needs none, and no JIT. |
| 139 | |
| 140 | Copy the signed file to the device and give it its exec bits before running it. |
| 141 | `hdc file send` lands files at `0660` and the user directory ignores `chmod`, so |
| 142 | the binary gains its mode another way: copy it on the device from a file that |
| 143 | already has the exec bits, or write it over an executable file already in place, |
| 144 | then confirm with `ls -l`. |
| 145 | |
| 146 | Run it from an application's terminal — the system terminal app (HiShell, bundle |
| 147 | `com.huawei.hmos.hishell`) or the integrated terminal in CodeArts — not from |
| 148 | `hdc shell`, which is a debugging channel that cannot execute files written under |
| 149 | `/data/local/tmp`. The first launch asks for permission once. |
| 150 | |
| 151 | ```bash |
| 152 | "$HOME/codewhale" --version |
| 153 | # codewhale 0.10.2 (859dc2ac7ac0) |
| 154 | ``` |
| 155 | |
| 156 | ## The VS Code Extension In CodeArts |
| 157 | |
| 158 | The [CodeWhale VS Code extension](https://github.com/HengQuWorld/CodeWhale-VSCode) |
| 159 | uses an HTTP webview to talk to the engine. The steps below describe the |
| 160 | CodeArts Agent integration route; an exact-build device run is still required |
| 161 | to qualify the editor workflow. |
| 162 | |
| 163 | 1. Put the signed engine on the `PATH` CodeArts gives its integrated terminal, or |
| 164 | point `brotherwhale.enginePath` at the file. |
| 165 | 2. In the extension panel, open the Open VSX page and install "CodeWhale" |
| 166 | (publisher `hengquworld`). That is the registry CodeArts reads, so no VSIX has |
| 167 | to be side-loaded. |
| 168 | 3. Open a workspace folder and start a conversation. The extension starts the |
| 169 | engine on demand and reports Ready in the status bar. |
| 170 | |
| 171 | ## What Works On The Device |
| 172 | |
| 173 | The existing observations are from one HarmonyOS 7.0.0.110 / API 26 2in1 |
| 174 | device with a self-signed build. They do not qualify later builds or the |
| 175 | workflows marked unverified below. |
| 176 | |
| 177 | | Surface | State | |
| 178 | | --- | --- | |
| 179 | | `--version`, `--help`, `doctor` | Observed working | |
| 180 | | `auth set` / `auth status` | Local commands start; use the store smoke below to verify a complete write/read on the chosen state directory | |
| 181 | | The VS Code extension in CodeArts Agent | Integration route above; exact-build device workflow unverified | |
| 182 | | `exec_shell` | The device provides `/bin/sh`; child spawning was observed by a probe, not a model turn | |
| 183 | | Interactive TUI | Device validation pending; use HiShell or the CodeArts integrated terminal because `hdc shell` allocates no tty | |
| 184 | | Local sandbox | Absent: commands run best-effort, and the engine says so | |
| 185 | | Persistent PTY tools (`terminal_*`) | Not registered on this target | |
| 186 | | Clipboard | OSC 52 (tmux `load-buffer -w`); text only, no image paste | |
| 187 | | `codewhale update` | Compiled out; move a new signed binary into place instead | |
| 188 | | Anything needing `git` | Only if you provide `git`; snapshots and `/undo` report why | |
| 189 | |
| 190 | A native HarmonyOS terminal is not a Linux shell: no `/bin/bash`, no package |
| 191 | manager. Codewhale reports a missing capability rather than substituting one. |
| 192 | |
| 193 | ## The User Directory |
| 194 | |
| 195 | `/storage/Users/currentUser` is hmdfs, a distributed filesystem that reports the |
| 196 | logged-in user as the owner of every object and applies its own modes (`0660` for |
| 197 | files, `2771` for directories) instead of the requested ones. Codewhale keeps its |
| 198 | state and keys there like anywhere else, and the store logs one warning naming the |
| 199 | mode it saw: the mount's own access control is what protects those files. |
| 200 | |
| 201 | Where you have a choice: |
| 202 | |
| 203 | - **Strict permission checks** need a filesystem that stores owner and mode. |
| 204 | Point `CODEWHALE_HOME` at the app sandbox to get them, keeping the path short: |
| 205 | the daemon socket is `<CODEWHALE_HOME>/run/daemon.sock` and the kernel rejects |
| 206 | paths longer than 107 bytes. |
| 207 | |
| 208 | ```sh |
| 209 | CODEWHALE_HOME=/data/storage/el2/base/files/cw codewhale serve --http |
| 210 | ``` |
| 211 | |
| 212 | `CODEWHALE_HOME` moves the whole state root, config and sessions included. |
| 213 | - **Keys** can also come from the provider's environment variable, which is |
| 214 | plaintext in the shell profile: |
| 215 | |
| 216 | ```bash |
| 217 | export DEEPSEEK_API_KEY=sk-… |
| 218 | codewhale |
| 219 | ``` |
| 220 | |
| 221 | - **One driver per workspace.** An engine holds a lease per working tree, so a |
| 222 | second one is refused with the holder's pid, client and age. That includes the |
| 223 | terminal and the editor on the same folder: close one before opening the other. |
| 224 | If the filesystem refuses advisory locks, the engine reports that exclusivity |
| 225 | is unavailable; two drivers are not excluded on that mount. |
| 226 | |
| 227 | `scripts/ohos/ohos-secrets-store-smoke.sh <directory>` checks the store end to end |
| 228 | against a real directory — it writes a key, reads it back through |
| 229 | `auth status`, and confirms `config.toml` holds no plaintext copy. |
| 230 | |
| 231 | ## Troubleshooting |
| 232 | |
| 233 | | Symptom | Cause | Fix | |
| 234 | | --- | --- | --- | |
| 235 | | `Required build dependency is missing. Halting build.` from `aws-lc-sys` | No `cmake` on `PATH` | Re-source `scripts/ohos/ohos-env.sh` (it adds the SDK's `cmake`), or install `cmake` | |
| 236 | | `Permission denied` when running the binary | Unsigned build, or no exec bits, or launched from `hdc shell` | Sign it, copy it in with its mode, run it from HiShell or CodeArts | |
| 237 | | `Operation not permitted` (errno 129) after signing | Signed with DevEco Studio's automatic app-signing certificate | Sign with the SDK's self-signature, or a debugging certificate from AppGallery Connect | |
| 238 | |
| 239 | ## Toolchain Notes |
| 240 | |
| 241 | - **Linker wrapper.** On Windows, `scripts/ohos/ohos-clang.{cmd,ps1}` reads |
| 242 | `OHOS_NATIVE_SDK` and contains no local paths; POSIX hosts invoke the SDK's |
| 243 | `clang` directly via `scripts/ohos/ohos-env.sh`. |
| 244 | - **No checked-in linker paths.** Cargo cannot expand environment variables |
| 245 | inside `linker` or CMake toolchain values, so those come from `ohos-env`. |
| 246 | - **Dependency guard.** `./scripts/release/check-ohos-deps.sh` runs without an |
| 247 | SDK and fails if a crate the target cannot carry — `portable-pty`, `nix`, |
| 248 | `starlark`, `arboard`, `keyring` — re-enters the graph. The SDK check in |
| 249 | `.github/workflows/ohos.yml` is the real build. |
| 250 | - **Identifying a build.** The commands above supply `CODEWHALE_BUILD_SHA`, |
| 251 | which embeds the first 12 characters in `--version`. An unstamped local build |
| 252 | reports `(dev)`; checking out `main` alone does not stamp it. A local rebuild |
| 253 | does not replace an installed binary. |
| 254 |