@cloudcrane/app-runtime

中文文档
0.8.0发布于 2026/11/08MITTypeScriptES Module近 30 天下载 1956

Builds a CloudCrane app spec into one HTML page, the same bytes every time, and the runtime that draws it with A2UI's renderer.

原始使用文档

@cloudcrane/app-runtime

Builds a CloudCrane app spec into one HTML page: the same bytes for the same spec and runtime version, every time. It writes no code and uses no AI: it checks the spec, turns its tokens into CSS, puts the spec in the page as data, and inlines the runtime that draws it with A2UI's renderer.

import { compile } from "@cloudcrane/app-runtime";

const { html, sha256, runtime } = compile(spec);
  • compile(spec) returns the page, its sha256 and the runtime it was built with (@cloudcrane/[email protected]+<hash>); it throws CompileError listing every problem when the spec doesn't validate.

  • compile(spec, { runtime: "shared" }) links the runtime instead of inlining it: the page names runtimeFile().path (/_cc/runtime/<version>-<hash>.js) with an integrity hash, so a host serves one copy to every spec app and a browser runs nothing but those bytes. The page is then a few KB. Inline is the default, for a page that stands alone.

  • Each runtime version is locked to one bundle hash (runtime-lock.json), so a version always draws apps the same way. The runtime's version (runtimeVersion in package.json) moves only when the bundle does; the package can release without it.

  • A coded component runs in a frame that's sandboxed (scripts only, so it has no storage and nothing of the page's), in a closed shadow root, reached only through a MessagePort. Under CloudCrane's lockdown the lockdown makes the frame (window.__ccFrame); elsewhere the runtime makes the same kind. The page drives it: a seed and the inputs, then its clock each frame, paused while hidden. The game kit turns that clock into fixed steps, so a game moves the same way for the same time and seed:

    game.start({ rate: 6, setup() {}, step() {}, draw(g, width, height) {} });
    game.on("swipe", (dir) => {}); // also "tap" and "input"
    game.state = { score }; // shown at /ui/coded/<id>/state
    game.emit("over", { score }); // the screen's action for "over" runs
    game.random(); // seeded by the page
    

    The page kit runs an HTML page as it is, full screen. Its localStorage works: what it holds is written into the frame when it opens, and each change goes to the page, which keeps it under <data.key>.coded.<id> (at most 4 MB), so it survives a reload and an update and the frame sees only its own. Both kits reach the page through window.__ccBus.

    A component's frame is allowed the device features the spec's uses declares (its allow), and the page must allow them for frames too (in Permissions-Policy, geolocation=* rather than (self)). Browsers give a frame with no origin of its own no camera or microphone, so a page kit whose spec declares either runs with the page's origin; it's then no more apart from the page than an app written straight into it. A game kit always stays apart.

  • @cloudcrane/app-runtime/host: what a host publishing spec apps needs in one import (validate, compile, derive the blueprint).

The runtime inlined in every page includes code from other open-source packages; their licences are in THIRD_PARTY_LICENSES.txt. zod 3.25 is a peer dependency. MIT licensed.

版本与发布记录

@cloudcrane/app-runtime 共发布 7 个版本,首次发布于 2026/10/28;过去 12 个月发布了 7 个版本。

版本发布日期距今
0.8.0latest2026/11/082 天前
0.6.02026/11/019 天前
0.5.02026/10/3011 天前
0.3.02026/10/3011 天前
0.2.02026/10/2911 天前
0.1.02026/10/2813 天前

关于 @cloudcrane/app-runtime 的常见问题

@cloudcrane/app-runtime 是什么?

Builds a CloudCrane app spec into one HTML page, the same bytes every time, and the runtime that draws it with A2UI's renderer.

如何安装 @cloudcrane/app-runtime?

在项目目录运行 npm install @cloudcrane/app-runtime,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:zod(^3.25.76)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@cloudcrane/app-runtime 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cloudcrane/app-runtime 支持 ESM 还是 CommonJS?

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

@cloudcrane/app-runtime 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.5。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@cloudcrane/app-runtime 可以商用吗?

@cloudcrane/app-runtime 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cloudcrane/app-runtime 的下载量有多少?

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

@cloudcrane/app-runtime 还在维护吗?

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