@ekrooh/bare

中文文档
0.7.0发布于 2026/11/08Apache-2.0ES Module构建来源已验证近 30 天下载 2549

One soul, many platforms — the boring bootstrap for cross-platform apps on the Bare runtime: wire protocol, plugin kernel, RPC messenger, transports, and native host bridges.

原始使用文档
文档目录12 节
  1. Model
  2. Repository layout
  3. Support matrix
  4. Message protocol
  5. Plugins
  6. Loopback server and auth
  7. Testing
  8. Commands
  9. Android build
  10. Consuming the published AAR
  11. iOS build
  12. Notes

@ekrooh/bare

One soul, many platforms. One codebase and identity across Android, iOS, web, and desktop.

Docs: https://anderscan.github.io/ekrooh

CI Release

The boring bootstrap for cross-platform apps on the Bare runtime (holepunch): a binary wire protocol, plugin kernel, RPC messenger, transports, and native host bridges, plus a reference app.

  • vision.md: what this project is and is not.
  • AGENTS.md: how to develop it and the canonical commands.
  • CONTRIBUTING.md: how to contribute.
  • RELEASING.md: how to cut a release.
  • docs/: internal ADRs (docs/adr/) and agent operations; not the public site.

Model

The frontend (browser or WebView) is written as if only a backend is reachable over a WebSocket carrying binary framed messages.

  • On device, the worklet runs one loopback HTTP+WS server that serves the web app, media files, and the protocol socket. The page connects to ws://location.host.
  • VITE_TRANSPORT_MODE=mock selects the mock transport (tests).
  • Browser dev points the WebSocket at the dev backend via VITE_BARE_WS_URL.

The UI never branches on worklets, Bare, or host IPC. @ekrooh/bare/core describes the wire protocol, not the runtime that implements it.

TermMeaning
FrontendWeb UI: Vite bundle in the browser, or the same bundle in a WebView.
BackendRuns the core bundle and speaks the framed protocol with the frontend.
HostNative shell (Android/iOS): starts the backend, owns system APIs, injects the session bootstrap.

Repository layout

  • core/: wire codec, plugin router, RPC messenger, host IPC (core/messages), loopback server (core/server), worklet entry (core/main.core.ts).
  • plugins/: canonical plugins (core.health, core.discovery, core.permissions, vendor.media) and typed event builders.
  • web/transports/: MessageTransport, WebSocket and mock transports.
  • android/: host library :bare-host (IPC coordinator, plugin registry, WebView client).
  • ios/: host Swift package BareHost (root Package.swift).
  • examples/: web/, android-app/, ios-app/, consumer-basic/.
  • e2e/: Playwright specs on the mock transport. scripts/: dev runner, Playwright wrapper, prebuild fetcher.
  • apps/docs/: public docs site (Astro Starlight, GitHub Pages).
  • templates/, research/: shared deploy templates; design notes.
  • prebuilds/: Bare Kit prebuilds (gitignored build output).

The public surface is the exports map in package.json (@ekrooh/bare/core, /runtime, /plugins, /plugins/*/events, /transports). It points at compiled ESM and type declarations in dist/ (built with vp pack). Consumers never see TypeScript source.

Support matrix

RuntimeStatusTransportNotes
Browser (dev)first-classWebSocketVite + local backend (VITE_BARE_WS_URL)
Browser (test)first-classMockDeterministic Playwright runs
Androidfirst-classWebSocketSame-origin loopback socket, cookie auth
iOSfirst-class (reference parity)WebSocketSame-origin loopback socket, cookie auth; host ships as source (ios/, SPM) on the release tag
Desktopreference (macOS)WebSocketZig host + system webview + sidecar bare; see examples/desktop-app

Parity policy: core protocol and plugin contracts are runtime-agnostic. Capabilities are opt-in plugins and may be runtime-specific. Plugins report unsupported behavior with deterministic errors. Feature code calls plugin events, never raw platform APIs.

Message protocol

Binary frame: version (1 byte), type (1 byte), headerLen (2 bytes, BE), payloadLen (3 bytes, BE), header (UTF-8 JSON), payload (optional). Implemented by MessageProtocol in core/messages (wire-codec.ts).

Header types: DISPATCH, INVOKE_REQUEST, INVOKE_RESPONSE (responses echo requestId). dispatch is fire-and-forget; invoke is request/response and timeout-bound.

Plugins

Core ships no product features. Plugin IDs are namespaced (app.photos; core.* and vendor.* are reserved for the framework); events are plugin-local (health.ping). Runtime adapters: web, android, ios, bare. Canonical plugins are listed under Repository layout.

Media never crosses the wire (frame cap 16 MiB). vendor.media is the reference for out-of-band bytes: the host picks or captures a file natively, the worklet mounts it on the loopback server and returns a URL, and the web layer loads that URL with cookie auth.

Loopback server and auth

One server (core/server/static-file-server.ts) serves the web app at /, plugin media mounts, and the WebSocket upgrade. On device it binds 127.0.0.1 on an ephemeral port. Every request is gated by a per-session token:

  1. The shell injects window.__ekrooh = { bootstrap }, a single-use nonce (never the raw token).
  2. The page calls POST /login with the nonce and receives a bare_session_<port> cookie (HttpOnly; SameSite=Strict; Path=/). The port in the name keeps two loopback servers in one cookie store apart. The raw token is never a login credential.
  3. The cookie authorizes <img>, <video>, fetch, and the WS upgrade. Non-browser clients send X-Bare-Token. There is no ?token= fallback (see docs/adr/0003-loopback-auth-surface.md).

Only the bootstrap mount at / is public pre-auth. The worklet writes { origin, port, bootstrap } to handoff.json in the host's sandbox dir (never the session token); the host loads http://127.0.0.1:<port>/index.html and deletes the file.

Every request must also target the bound loopback server (Host), and a page Origin must be that server or an explicitly allowed one, in every mode.

The dev backend (mode=dev) runs the same bundle with auth off on ws://localhost:8080, allowing the Vite dev origin (origin= tokens).

Testing

  • Unit: vitest (vp test) for the codec, router, RPC messenger, transports; JUnit for the Kotlin host; XCTest for the Swift host.
  • Type check: tsc --noEmit, part of vp check.
  • Integration: Playwright e2e on the mock transport (npm run test:e2e:web). Browsers resolve through scripts/playwright-local-browsers.mjs into .playwright-browsers/.
  • Native: npm run test:ios runs the Swift XCTest suite and a UI test on the simulator.

Commands

Canonical list: AGENTS.md. Common ones:

CommandPurpose
vp checkFormat, lint, type-check
vp testUnit tests
npm run testUnit + Playwright e2e
npm run devVite dev server + Bare backend (watch restart)
npm run dev:mockVite with mock transport
npm run build:coreBundle core/main.core.ts (esbuild)
npm run build:webBuild examples/web into the Android app's assets
npm run build:iosiOS inputs (addons, bundle, web assets, xcodegen)
npm run prebuildsFetch Bare Kit prebuilds (hash-checked, no token)
npm run playwright:installDownload Chromium into .playwright-browsers/
npm run smoke:loopbackSmoke-test the loopback server under bare

Android build

Needs the Android SDK (local.properties with sdk.dir=...) and Bare Kit prebuilds.

vp install
npm run prebuilds
npm run build       # core bundle + web assets
./gradlew :examples:android-app:assembleDebug

./gradlew build also runs the host library's JUnit tests.

Consuming the published AAR

io.github.anderscan.ekrooh:bare-host is on Maven Central (no credentials). Pin it to the same version as @ekrooh/bare:

dependencies {
  implementation "io.github.anderscan.ekrooh:bare-host:<version>"
}

GitHub Packages is a fallback that requires a read:packages token. Prefer Maven Central.

iOS build

Needs Xcode, Bare Kit prebuilds, and xcodegen.

vp install
npm run prebuilds   # also fetches prebuilds/ios/BareKit.xcframework
npm run build:ios
npm run test:ios

Notes

  • Treat examples/android-app/src/main/assets/ as build output. Vite clears hashed assets/main-*.{js,css} before rebuilding.

版本与发布记录

@ekrooh/bare 共发布 9 个版本,首次发布于 2026/08/14;过去 12 个月发布了 9 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.7.0latest2026/11/085 天前
0.6.22026/11/076 天前
0.6.12026/11/0212 天前
0.6.02026/10/2816 天前
0.5.02026/10/2718 天前
0.4.02026/08/172 个月前

关于 @ekrooh/bare 的常见问题

@ekrooh/bare 是什么?

One soul, many platforms — the boring bootstrap for cross-platform apps on the Bare runtime: wire protocol, plugin kernel, RPC messenger, transports, and native host bridges.

如何安装 @ekrooh/bare?

在项目目录运行 npm install @ekrooh/bare,或使用 pnpm add / yarn add / bun add。

@ekrooh/bare 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/ekrooh__bare 是否存在。

@ekrooh/bare 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@ekrooh/bare 可以商用吗?

@ekrooh/bare 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@ekrooh/bare 的下载量有多少?

根据 npm 官方下载统计,@ekrooh/bare 在 2026/10/13 – 2026/11/11 这 30 天内被下载 2,549 次,日均约 85 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ekrooh/bare 还在维护吗?

最新版本 0.7.0 发布于 2026/11/08(5 天前);至今共发布 9 个版本,其中过去 12 个月发布了 9 个;首次发布于 2026/08/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。