caffeine-app

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Caffeine App (build from scratch)

Caffeine App(从头构建)

Caffeine (caffeine.ai) builds and hosts full-stack apps on the Internet Computer: a single Motoko backend canister plus a React/Vite frontend served as an assets canister. This skill teaches the exact project shape and the CLI build loop so you can produce a buildable Caffeine app from nothing.
This skill owns the project shape and the build workflow. It does NOT own the Motoko language. Before you write or edit any backend code, fetch and follow the
writing-motoko
skill: https://skills.internetcomputer.org/skills/writing-motoko/SKILL.md. That skill is authoritative for actor syntax, stable state,
mo:core
, and compiler errors. This skill only shows the minimal empty actor and where it lives.
Caffeine (caffeine.ai) 在 Internet Computer 上构建并托管全栈应用:一个 Motoko backend canister,加上一个作为 assets canister 托管的 React/Vite frontend。本 skill 讲解准确的 项目结构 和 CLI 构建循环,让你能够从零创建可构建的 Caffeine 应用。
本 skill 负责项目结构和构建工作流,但不负责 Motoko 语言。 在编写或编辑任何后端代码前,先获取并遵循
writing-motoko
skill:https://skills.internetcomputer.org/skills/writing-motoko/SKILL.md。该 skill 是 actor 语法、稳定状态、
mo:core
和编译器错误的权威依据。本 skill 只会展示最小空 actor 及其所在位置。

When to use this skill

何时使用本 skill

  • Creating/scaffolding a new Caffeine app or caffeine.ai project from scratch.
  • Writing or fixing
    caffeine.toml
    (workspace or canister manifest) or
    mops.toml
    .
  • Running the caffeine CLI loop:
    auth login
    ,
    doctor
    ,
    install
    ,
    check
    ,
    preview
    .
Do not use it for Motoko language details (use
writing-motoko
) or for raw IC/
dfx
/
icp
deployment (use
icp-cli
). Caffeine apps are built and deployed through the
caffeine
CLI and the caffeine.ai web app, not through
dfx
.
  • 从头创建或搭建新的 Caffeine 应用或 caffeine.ai 项目。
  • 编写或修复
    caffeine.toml
    (workspace 或 canister 清单)或
    mops.toml
    。
  • 运行 caffeine CLI 循环:
    auth login
    、
    doctor
    、
    install
    、
    check
    、
    preview
    。
请不要将本 skill 用于 Motoko 语言细节(使用
writing-motoko
),也不要用于原生 IC/
dfx
/
icp
部署(使用
icp-cli
)。Caffeine 应用通过
caffeine
CLI 和 caffeine.ai Web 应用进行构建与部署,而不是通过
dfx
。

Critical facts

关键事实

  • There is no
    caffeine init
    /
    caffeine new
    .
    "From scratch" means you create the files in this skill by hand, then run the build loop. (
    caffeine projects clone <id>
    only downloads an existing cloud project, and
    caffeine projects import <zip>
    only unpacks a project archive such as one made by
    caffeine export
    ; neither is a greenfield scaffold.)
  • Exactly one backend canister, and it must be named
    backend
    .
    mops.toml
    declares a single
    [canisters.backend]
    .
  • The frontend↔backend binding files are generated, never hand-written.
    src/frontend/src/backend.ts
    and
    src/frontend/src/declarations/
    are produced by
    caffeine-bindgen
    during the build. Editing them is pointless — they are overwritten.
  • Deploying to a live URL is done in the caffeine.ai web app, not the CLI. The CLI takes you as far as a built draft (
    caffeine preview --build
    , which needs a cloud
    project.id
    — see the build loop). There is no
    caffeine deploy
    /
    publish
    command.
  • 不存在
    caffeine init
    /
    caffeine new
    。
    “从头开始”意味着手动创建本 skill 中的文件,然后运行构建循环。(
    caffeine projects clone <id>
    只会下载现有云项目;
    caffeine projects import <zip>
    只会解包项目归档,例如由
    caffeine export
    生成的归档;两者都不是全新项目脚手架。)
  • 必须且只能有一个 backend canister,其名称必须为
    backend
    。
    mops.toml
    声明单个
    [canisters.backend]
    。
  • frontend↔backend 绑定文件由工具生成,绝不能手动编写。
    src/frontend/src/backend.ts
    和
    src/frontend/src/declarations/
    会在构建期间由
    caffeine-bindgen
    生成。对这些文件进行编辑没有意义,因为它们会被覆盖。
  • 部署到线上 URL 是通过 caffeine.ai Web 应用完成的,而不是 CLI。 CLI 只能将构建推进到 draft 状态(
    caffeine preview --build
    ,需要云端
    project.id
    ,详见构建循环)。不存在
    caffeine deploy
    /
    publish
    命令。

Prerequisites (run once)

前置条件(运行一次)

bash
undefined
bash
undefined

Install the CLI (public npm package). The binary is
caffeine
.

Install the CLI (public npm package). The binary is
caffeine
.

npm install -g @caffeineai/cli
npm install -g @caffeineai/cli

Authenticate against caffeine.ai. Opens a browser; without one (or with --device) it

Authenticate against caffeine.ai. Opens a browser; without one (or with --device) it

uses the device flow. On a host with no OS keychain (headless Linux, containers), add

uses the device flow. On a host with no OS keychain (headless Linux, containers), add

--insecure-storage to keep the token in ~/.caffeine/tokens.json (mode 0600) instead.

--insecure-storage to keep the token in ~/.caffeine/tokens.json (mode 0600) instead.

caffeine auth login caffeine auth status
caffeine auth login caffeine auth status

Check the environment: Node, pnpm, mops, caffeine-bindgen, that you are logged in,

Check the environment: Node, pnpm, mops, caffeine-bindgen, that you are logged in,

and that the Caffeine API is reachable (installs what it can).

and that the Caffeine API is reachable (installs what it can).

caffeine doctor --fix

If a global install is undesirable or fails, run every `caffeine` command through an
`npx -y @caffeineai/cli@latest` prefix instead — e.g. `npx -y @caffeineai/cli@latest auth status`.

`caffeine doctor` requires Node.js 20 or later (the template's `engines` field asks for
`>=20.19.0`) and checks pnpm, mops (2.13.0 or later), `caffeine-bindgen`, your login,
and whether the Caffeine API is reachable. With `--fix` it installs a missing pnpm, a
missing or outdated mops (`ic-mops`), and a missing `caffeine-bindgen`
(`@caffeineai/bindgen`) with `npm install -g`; it does not install Node.js. It does
**not** install the Motoko compiler (`moc`) or linter (`lintoko`): mops fetches those
automatically from the `[toolchain]` pins in `mops.toml`. On Windows, compiling Motoko
requires WSL. `dfx` is not part of the Caffeine build.
caffeine doctor --fix

如果不适合或无法进行全局安装,可以通过 `npx -y @caffeineai/cli@latest` 前缀运行每一条 `caffeine` 命令,例如 `npx -y @caffeineai/cli@latest auth status`。

`caffeine doctor` 要求使用 Node.js 20 或更高版本(模板的 `engines` 字段要求 `>=20.19.0`),并检查 pnpm、mops(2.13.0 或更高版本)、`caffeine-bindgen`、登录状态以及 Caffeine API 是否可以访问。使用 `--fix` 时,它会通过 `npm install -g` 安装缺失的 pnpm、缺失或过期的 mops(`ic-mops`)以及缺失的 `caffeine-bindgen`(`@caffeineai/bindgen`);但它不会安装 Node.js。它也**不会**安装 Motoko 编译器(`moc`)或 linter(`lintoko`):mops 会根据 `mops.toml` 中 `[toolchain]` 固定的版本自动获取它们。在 Windows 上,编译 Motoko 需要 WSL。`dfx` 不属于 Caffeine 构建流程。

Project shape

项目结构

A Caffeine app is a pnpm workspace with a root manifest and two canisters. Create this exact tree (file contents below):
text
my-app/
├── .old/src/backend/dist/
│   └── backend.most           # stable-signature baseline — seed with an empty actor (see below)
├── caffeine.toml              # root workspace manifest — MUST contain [workspace]
├── mops.toml                  # Motoko build config — ONE per project, at the root
├── package.json               # pnpm workspace root + the `bindgen` script
├── pnpm-workspace.yaml         # declares src/**/* as workspace packages
├── tsconfig.json               # root TS config
└── src/
    ├── backend/                # the single Motoko canister, named "backend"
    │   ├── caffeine.toml        #   canister manifest: type = "motoko"
    │   ├── main.mo              #   actor entry point (write with the `writing-motoko` skill)
    │   └── migrations/          #   enhanced-migration chain (see the `mops.toml` notes)
    │       └── 00000000_000000.mo #   first migration: initializes the actor's stable state
    └── frontend/               # the assets canister (React + Vite)
        ├── caffeine.toml        #   canister manifest: type = "assets"
        ├── package.json         #   frontend deps + scripts (see references/frontend-template.md)
        ├── vite.config.js       #   (see references/frontend-template.md)
        ├── tsconfig.json        #   (see references/frontend-template.md)
        ├── biome.json           #   (see references/frontend-template.md)
        ├── tailwind.config.js   #   (see references/frontend-template.md)
        ├── postcss.config.js    #   (see references/frontend-template.md)
        ├── index.html
        ├── env.json             #   runtime config — copied into dist/ on build
        ├── public/              #   static files served as-is (for example favicon.ico)
        └── src/
            ├── main.tsx          #   React entry (providers)
            ├── App.tsx
            ├── index.css
            ├── backend.ts        #   GENERATED by caffeine-bindgen — do NOT edit
            └── declarations/     #   GENERATED by caffeine-bindgen — do NOT edit
Only the root manifest, the two canister manifests,
mops.toml
,
main.mo
, and the small root config files are shown inline below. The full frontend boilerplate (
package.json
,
vite.config.js
, the Tailwind/PostCSS/Biome configs,
index.html
,
env.json
,
main.tsx
, a starter
App.tsx
) is in
references/frontend-template.md
— read it when you create the frontend.
Caffeine 应用是一个带根清单和两个 canister 的 pnpm workspace。请创建以下目录树(文件内容见下文):
text
my-app/
├── .old/src/backend/dist/
│   └── backend.most           # stable-signature baseline — seed with an empty actor (see below)
├── caffeine.toml              # root workspace manifest — MUST contain [workspace]
├── mops.toml                  # Motoko build config — ONE per project, at the root
├── package.json               # pnpm workspace root + the `bindgen` script
├── pnpm-workspace.yaml         # declares src/**/* as workspace packages
├── tsconfig.json               # root TS config
└── src/
    ├── backend/                # the single Motoko canister, named "backend"
    │   ├── caffeine.toml        #   canister manifest: type = "motoko"
    │   ├── main.mo              #   actor entry point (write with the `writing-motoko` skill)
    │   └── migrations/          #   enhanced-migration chain (see the `mops.toml` notes)
    │       └── 00000000_000000.mo #   first migration: initializes the actor's stable state
    └── frontend/               # the assets canister (React + Vite)
        ├── caffeine.toml        #   canister manifest: type = "assets"
        ├── package.json         #   frontend deps + scripts (see references/frontend-template.md)
        ├── vite.config.js       #   (see references/frontend-template.md)
        ├── tsconfig.json        #   (see references/frontend-template.md)
        ├── biome.json           #   (see references/frontend-template.md)
        ├── tailwind.config.js   #   (see references/frontend-template.md)
        ├── postcss.config.js    #   (see references/frontend-template.md)
        ├── index.html
        ├── env.json             #   runtime config — copied into dist/ on build
        ├── public/              #   static files served as-is (for example favicon.ico)
        └── src/
            ├── main.tsx          #   React entry (providers)
            ├── App.tsx
            ├── index.css
            ├── backend.ts        #   GENERATED by caffeine-bindgen — do NOT edit
            └── declarations/     #   GENERATED by caffeine-bindgen — do NOT edit
下面仅直接展示根清单、两个 canister 清单、
mops.toml
、
main.mo
和少量根配置文件。完整的前端 boilerplate(
package.json
、
vite.config.js
、Tailwind/PostCSS/Biome 配置、
index.html
、
env.json
、
main.tsx
和初始
App.tsx
)位于
references/frontend-template.md
中——创建前端时请阅读该文件。

Manifests

清单

Root
caffeine.toml
— the workspace

根
caffeine.toml
——workspace

The root manifest must contain a
[workspace]
section. That section is what marks it as the workspace root; without it, the CLI treats this file as an ordinary canister manifest and discovery fails.
toml
manifest_version = "0.1.0"

[project]
name = "My App"
根清单必须包含
[workspace]
部分
。正是该部分将其标记为 workspace 根;如果缺少该部分,CLI 会将此文件视为普通 canister 清单,并导致发现过程失败。
toml
manifest_version = "0.1.0"

[project]
name = "My App"

id is the cloud project id, a UUID. Omit it for a brand-new local project; once

id is the cloud project id, a UUID. Omit it for a brand-new local project; once

caffeine projects create
reports one, set it here (or pass --project-id to preview).

caffeine projects create
reports one, set it here (or pass --project-id to preview).

A placeholder such as "my-app" makes
caffeine preview
refuse to upload.

A placeholder such as "my-app" makes
caffeine preview
refuse to upload.

[workspace] include = [ "src/**" ]
[workspace] include = [ "src/**" ]

Build the backend before the frontend, because the frontend imports generated

Build the backend before the frontend, because the frontend imports generated

bindings produced from the backend's Candid interface.

bindings produced from the backend's Candid interface.

[canisters.frontend] depends_on = [ "backend" ]

`[workspace].include` is a list of globs the CLI scans for nested canister manifests.
`src/**` finds `src/backend/caffeine.toml` and `src/frontend/caffeine.toml`.
[canisters.frontend] depends_on = [ "backend" ]

`[workspace].include` 是 CLI 用于扫描嵌套 canister 清单的 glob 列表。`src/**` 可以找到 `src/backend/caffeine.toml` 和 `src/frontend/caffeine.toml`。

src/backend/caffeine.toml
— the Motoko canister

src/backend/caffeine.toml
——Motoko canister

toml
manifest_version = "0.1.0"

[project]
name = "backend"
type = "motoko"
main = "main.mo"

[build]
commands = ["mops build", "pnpm bindgen"]
out = "dist"

[check]
commands = ["mops check"]

[check.fix]
commands = ["mops check --fix"]
[build].commands
run in order:
mops build
compiles
main.mo
to Wasm + Candid, then
pnpm bindgen
(defined in the root
package.json
) turns that Candid into the frontend's TypeScript client.
caffeine check --fix
runs
[check.fix].commands
.
toml
manifest_version = "0.1.0"

[project]
name = "backend"
type = "motoko"
main = "main.mo"

[build]
commands = ["mops build", "pnpm bindgen"]
out = "dist"

[check]
commands = ["mops check"]

[check.fix]
commands = ["mops check --fix"]
[build].commands
会按顺序运行:
mops build
将
main.mo
编译为 Wasm + Candid,然后
pnpm bindgen
(定义在根
package.json
中)将该 Candid 转换为前端的 TypeScript client。
caffeine check --fix
会运行
[check.fix].commands
。

src/frontend/caffeine.toml
— the assets canister

src/frontend/caffeine.toml
——assets canister

toml
manifest_version = "0.1.0"

[project]
name = "frontend"
type = "assets"

[build]
commands = ["pnpm build"]
out = "dist"

[check]
commands = ["pnpm typecheck", "pnpm check"]

[check.fix]
commands = ["pnpm typecheck", "pnpm fix"]
toml
manifest_version = "0.1.0"

[project]
name = "frontend"
type = "assets"

[build]
commands = ["pnpm build"]
out = "dist"

[check]
commands = ["pnpm typecheck", "pnpm check"]

[check.fix]
commands = ["pnpm typecheck", "pnpm fix"]

mops.toml
— the Motoko build (one per project, at the root)

mops.toml
——Motoko 构建(每个项目根目录一个)

There is exactly one
[canisters.backend]
.
caffeine preview
checks only the structural pieces, which are invariant: the single
[canisters.backend]
,
[canisters.backend.check-stable]
with the path shown and no
skipIfMissing
, and
[build] outputDir = "src/backend/dist"
. Everything else — the toolchain versions, the
[moc]
flags and
-E
/
-W
/
-A
diagnostic codes, and the dependency list — is a current snapshot
that the Caffeine template bumps over time; see "Versions and dependencies drift" below.
toml
[package]
name = "backend"
version = "0.1.0"

[build]
outputDir = "src/backend/dist"
args = ["--release"]
check-wasm = true

[canisters.backend]
main = "src/backend/main.mo"

[canisters.backend.check-stable]
path = ".old/src/backend/dist/backend.most"

[toolchain]
moc = "2.1.0"
lintoko = "0.12.0"

[lint]
extends = true

[moc]
args = [
  "--implicit-package=core",
  "-no-check-ir",
  "-E=M0254",
  "-W=M0235,M0223,M0236,M0237",
  "-A=M0241"
]

[dependencies]
core = "2.6.1"
ic = "5.0.0"
caffeineai-authorization = "1.0.0"
caffeineai-lints = "0.1.0"
caffeineai-oql = "0.8.0"

[canisters.backend.migrations]
chain = "src/backend/migrations"
check-limit = 1
Notes:
  • New projects use moc 2. Under moc 2 a bare
    actor
    is persistent, and the
    persistent
    keyword only triggers warning M0217. Older guides add
    --default-persistent-actors
    or
    --generate-view-queries
    to
    [moc] args
    : those are moc 1.x flags that moc 2.0 removed, and passing them fails every compile with
    unknown option
    . Projects cloned from before the switch may still pin moc 1.x (the template's moc 1 variant is
    moc = "1.16.0"
    with
    --default-persistent-actors
    first in
    [moc] args
    ); leave such a project on its pinned version, or move it with the
    migrating-to-moc-2
    skill: https://github.com/caffeinelabs/skills/tree/main/skills/migrating-to-moc-2.
  • check-stable
    points at
    .old/src/backend/dist/backend.most
    , the stable-signature snapshot of the last deployed backend.
    caffeine check
    compares your stable state against it, and
    caffeine projects clone
    restores it from the cloud. Do not delete
    .old/
    . A from-scratch project must seed it with an empty actor, as the Caffeine template does, or
    caffeine check
    fails with
    Deployed file not found: .old/src/backend/dist/backend.most
    :
    motoko
    // Version: 1.0.0
    actor {};
    Do not set
    skipIfMissing = true
    instead: mops deprecated it, and
    caffeine preview
    rejects it because a skipped check only fails later, at deploy.
  • [canisters.backend.migrations]
    turns on enhanced migration (mops adds
    --enhanced-migration
    itself; do not put it in
    [moc] args
    ). Every
    .mo
    file in
    src/backend/migrations/
    , in name order, is one step that maps the previous stable state to the next. Stable fields in the actor have no initializers; their initial values come from the chain. A new project starts with
    00000000_000000.mo
    , which creates the state the starting
    main.mo
    declares (below) and sorts before the
    YYYYMMDD_HHMMSS.mo
    files later migrations use:
    motoko
    import AccessControl "mo:caffeineai-authorization/access-control";
    
    module {
      public type OldActor = {};
      public type NewActor = { accessControlState : AccessControl.AccessControlState };
    
      public func migration(_ : OldActor) : NewActor {
        { accessControlState = AccessControl.initState() };
      };
    };
    check-limit = 1
    allows one pending (not yet deployed) migration. Against the seeded empty baseline,
    00000000_000000.mo
    is itself pending, so until the first deploy you add new stable fields by editing that file, not by adding a second one; a second file fails
    caffeine check
    with
    too many pending migrations for check-limit=1
    . Never edit, rename, or delete a migration after it is deployed. The rules for writing migrations are in the
    migrating-motoko-actors
    skill: https://github.com/caffeinelabs/skills/tree/main/skills/migrating-motoko-actors.
  • core
    is the
    mo:core
    standard library. Use
    mo:core
    , never the deprecated
    mo:base
    — see the
    writing-motoko
    skill.
    caffeineai-oql
    provides the
    Expose
    mixin the starting
    main.mo
    includes (below).
  • caffeineai-authorization
    provides Internet Identity sign-in and roles (
    MixinAuthorization
    ,
    AccessControl
    ). It also ships a lint rule that fails
    caffeine check
    unless
    main.mo
    includes
    MixinAuthorization
    . To use custom authentication instead before the first deploy, remove the package (
    mops remove caffeineai-authorization
    ) together with its imports, include, state field, and migration line — see the
    extension-authorization
    skill: https://github.com/caffeinelabs/skills/tree/main/skills/extension-authorization. After a deploy, the applied first migration imports the package, so removing it breaks the build: keep the package and
    MixinAuthorization
    , and add custom checks alongside them.
  • [lint] extends = true
    runs the lint rules that dependencies ship (such as the one above) with the
    lintoko
    pinned in
    [toolchain]
    , as part of
    mops check
    .
  • ic
    provides the IC management canister's types and calls (
    mo:ic/Types
    ,
    mo:ic/Call
    ). Use it instead of
    import ... "ic:aaaaa-aa"
    , which only resolves with an
    --actor-idl
    flag that the template no longer passes.
  • Add a package with
    mops add <name>
    (one package per command) rather than by editing
    [dependencies]
    , so
    mops.lock
    stays in sync. The
    mops-cli
    skill covers the mops commands: https://github.com/caffeinelabs/skills/tree/main/skills/mops-cli.
Versions and dependencies drift. The
[toolchain]
versions, the
[moc]
-E
/
-W
/
-A
codes, and the frontend dependency set are template-managed and change over time (e.g. the
@dfinity/*
→
@icp-sdk/*
migration, moc/core bumps). Treat the exact values here as a snapshot — for current ones,
caffeine projects clone
a recent project and copy its
mops.toml
+
src/frontend/package.json
. Stable across versions: the file layout, the single
backend
canister,
check-stable
with the seeded baseline,
[build] outputDir
,
mo:core
, and
useActor(createActor)
.
必须且只能存在一个
[canisters.backend]
。
caffeine preview
只检查结构性内容,这些内容不会发生变化:单个
[canisters.backend]
、路径如所示且不含
skipIfMissing
的
[canisters.backend.check-stable]
,以及
[build] outputDir = "src/backend/dist"
。其他所有内容——[toolchain] 版本、
[moc]
flags 和
-E
/
-W
/
-A
诊断代码,以及依赖列表
——都是当前快照,Caffeine 模板会随着时间更新;请参阅下文“版本和依赖漂移”。
toml
[package]
name = "backend"
version = "0.1.0"

[build]
outputDir = "src/backend/dist"
args = ["--release"]
check-wasm = true

[canisters.backend]
main = "src/backend/main.mo"

[canisters.backend.check-stable]
path = ".old/src/backend/dist/backend.most"

[toolchain]
moc = "2.1.0"
lintoko = "0.12.0"

[lint]
extends = true

[moc]
args = [
  "--implicit-package=core",
  "-no-check-ir",
  "-E=M0254",
  "-W=M0235,M0223,M0236,M0237",
  "-A=M0241"
]

[dependencies]
core = "2.6.1"
ic = "5.0.0"
caffeineai-authorization = "1.0.0"
caffeineai-lints = "0.1.0"
caffeineai-oql = "0.8.0"

[canisters.backend.migrations]
chain = "src/backend/migrations"
check-limit = 1
注意事项:
  • 新项目使用 moc 2。 在 moc 2 下,普通的
    actor
    默认是 persistent 的,使用
    persistent
    关键字只会触发 M0217 警告。旧版指南会在
    [moc] args
    中添加
    --default-persistent-actors
    或
    --generate-view-queries
    :这些是 moc 1.x flags,moc 2.0 已将其移除,传入后每次编译都会因
    unknown option
    而失败。从切换前克隆的项目可能仍固定使用 moc 1.x(模板的 moc 1 变体使用
    moc = "1.16.0"
    ,并将
    --default-persistent-actors
    放在
    [moc] args
    的首位);可以让此类项目继续使用其固定版本,或使用
    migrating-to-moc-2
    skill 迁移: https://github.com/caffeinelabs/skills/tree/main/skills/migrating-to-moc-2。
  • check-stable
    指向
    .old/src/backend/dist/backend.most
    ,即上一次部署的后端的稳定签名快照。
    caffeine check
    会将当前稳定状态与其比较,而
    caffeine projects clone
    会从云端恢复它。不要删除
    .old/
    。从头创建的项目必须按照 Caffeine 模板的做法,使用空 actor 对其进行初始化,否则
    caffeine check
    会因以下错误而失败:
    Deployed file not found: .old/src/backend/dist/backend.most
    :
    motoko
    // Version: 1.0.0
    actor {};
    不要改为设置
    skipIfMissing = true
    :mops 已弃用此选项,而且
    caffeine preview
    会拒绝该设置,因为跳过检查只会让问题推迟到部署阶段才暴露。
  • [canisters.backend.migrations]
    用于启用增强迁移(mops 会自行添加
    --enhanced-migration
    ;不要将其放入
    [moc] args
    )。
    src/backend/migrations/
    中的每个
    .mo
    文件都会按名称顺序构成一步,将之前的稳定状态映射到下一个稳定状态。actor 中的稳定字段不能有 initializer;其初始值来自迁移链。新项目以
    00000000_000000.mo
    开始,它会创建起始
    main.mo
    所声明的状态(见下文),并且排在后续迁移使用的
    YYYYMMDD_HHMMSS.mo
    文件之前:
    motoko
    import AccessControl "mo:caffeineai-authorization/access-control";
    
    module {
      public type OldActor = {};
      public type NewActor = { accessControlState : AccessControl.AccessControlState };
    
      public func migration(_ : OldActor) : NewActor {
        { accessControlState = AccessControl.initState() };
      };
    };
    check-limit = 1
    允许存在一个尚未部署的迁移。相对于初始化后的空基线,
    00000000_000000.mo
    本身就是待部署迁移,因此在首次部署之前,应通过编辑该文件来添加新的稳定字段,而不是再添加第二个文件;添加第二个文件会导致
    caffeine check
    报错
    too many pending migrations for check-limit=1
    。迁移一旦部署,绝不能编辑、重命名或删除。编写迁移的规则请参阅
    migrating-motoko-actors
    skill: https://github.com/caffeinelabs/skills/tree/main/skills/migrating-motoko-actors。
  • core
    是
    mo:core
    标准库。请使用
    mo:core
    ,不要使用已弃用的
    mo:base
    ——参阅
    writing-motoko
    skill。
    caffeineai-oql
    提供起始
    main.mo
    所包含的
    Expose
    mixin(见下文)。
  • caffeineai-authorization
    提供 Internet Identity 登录和角色(
    MixinAuthorization
    、
    AccessControl
    )。它还附带一条 lint 规则:如果
    main.mo
    未包含
    MixinAuthorization
    ,
    caffeine check
    就会失败。如果要在首次部署前使用自定义认证,请按照
    extension-authorization
    skill 的说明移除该包(
    mops remove caffeineai-authorization
    ),并同时移除其 import、include、状态字段和迁移行: https://github.com/caffeinelabs/skills/tree/main/skills/extension-authorization。 部署后,已应用的首次迁移会导入该包,因此移除它会破坏构建:请保留该包和
    MixinAuthorization
    ,并在它们的基础上添加自定义检查。
  • [lint] extends = true
    会使用
    [toolchain]
    中固定的
    lintoko
    运行依赖附带的 lint 规则(例如上述规则),并将其作为
    mops check
    的一部分执行。
  • ic
    提供 IC 管理 canister 的类型和调用(
    mo:ic/Types
    、
    mo:ic/Call
    )。请使用它,而不要使用
    import ... "ic:aaaaa-aa"
    ;后者只有在传入
    --actor-idl
    flag 时才能解析,而模板已不再传入该 flag。
  • 添加包时请使用
    mops add <name>
    (每条命令添加一个包),不要直接编辑
    [dependencies]
    ,这样才能确保
    mops.lock
    保持同步。mops 命令详见
    mops-cli
    skill:https://github.com/caffeinelabs/skills/tree/main/skills/mops-cli。
版本和依赖漂移。
[toolchain]
版本、
[moc]
的
-E
/
-W
/
-A
代码以及前端依赖集均由模板管理,并会随时间变化(例如从
@dfinity/*
迁移到
@icp-sdk/*
,以及 moc/core 版本升级)。请将这里的具体值视为快照——如需获取当前版本,可使用
caffeine projects clone
克隆一个近期项目,然后复制其
mops.toml
和
src/frontend/package.json
。跨版本保持不变的内容包括:文件布局、单个
backend
canister、带初始化基线的
check-stable
、
[build] outputDir
、
mo:core
,以及
useActor(createActor)
。

package.json
(root) — pnpm workspace + the
bindgen
script

package.json
(根目录)——pnpm workspace +
bindgen
script

The
bindgen
script is the bridge from backend Candid to the frontend TS client. It is invoked by the backend canister's
[build]
step (
pnpm bindgen
).
json
{
  "name": "@caffeine/template-app",
  "type": "module",
  "engines": {
    "node": ">=20.19.0",
    "pnpm": ">=7.0.0",
    "npm": "please use pnpm"
  },
  "scripts": {
    "build": "pnpm -r --if-present run build",
    "typecheck": "pnpm -r --if-present run typecheck",
    "check": "pnpm -r --if-present run check",
    "fix": "pnpm -r --if-present run fix",
    "bindgen": "caffeine-bindgen --did-file ./src/backend/dist/backend.did --out-dir ./src/frontend/src --actor-interface-file --force"
  },
  "devDependencies": {
    "@icp-sdk/core": "^5.3.0",
    "sharp": "^0.34.4"
  }
}
The Caffeine template also pins pnpm with a
packageManager
field and adds
@dfinity/pic
for its hosted backend tests; a local project needs neither.
bindgen
script 是后端 Candid 与前端 TS client 之间的桥梁。它由 backend canister 的
[build]
步骤调用(
pnpm bindgen
)。
json
{
  "name": "@caffeine/template-app",
  "type": "module",
  "engines": {
    "node": ">=20.19.0",
    "pnpm": ">=7.0.0",
    "npm": "please use pnpm"
  },
  "scripts": {
    "build": "pnpm -r --if-present run build",
    "typecheck": "pnpm -r --if-present run typecheck",
    "check": "pnpm -r --if-present run check",
    "fix": "pnpm -r --if-present run fix",
    "bindgen": "caffeine-bindgen --did-file ./src/backend/dist/backend.did --out-dir ./src/frontend/src --actor-interface-file --force"
  },
  "devDependencies": {
    "@icp-sdk/core": "^5.3.0",
    "sharp": "^0.34.4"
  }
}
Caffeine 模板还会通过
packageManager
字段固定 pnpm 版本,并添加
@dfinity/pic
以支持其托管的后端测试;本地项目不需要这两项。

pnpm-workspace.yaml

pnpm-workspace.yaml

pnpm 10 reads
onlyBuiltDependencies
; pnpm 11 and later read only
allowBuilds
. Keep both so either version runs the packages' install scripts.
yaml
packages:
  - src/**/*
allowBuilds:
  '@biomejs/biome': true
  esbuild: true
  sharp: true
onlyBuiltDependencies:
  - '@biomejs/biome'
  - esbuild
  - sharp
pnpm 10 会读取
onlyBuiltDependencies
;pnpm 11 及更高版本只读取
allowBuilds
。两者都应保留,以确保任一版本都能运行各包的安装脚本。
yaml
packages:
  - src/**/*
allowBuilds:
  '@biomejs/biome': true
  esbuild: true
  sharp: true
onlyBuiltDependencies:
  - '@biomejs/biome'
  - esbuild
  - sharp

tsconfig.json
(root)

tsconfig.json
(根目录)

json
{
  "compilerOptions": {
    "strict": true,
    "target": "ES2020",
    "experimentalDecorators": true,
    "strictPropertyInitialization": false,
    "module": "esnext",
    "moduleResolution": "bundler",
    "allowJs": true,
    "outDir": "HACK_BECAUSE_OF_ALLOW_JS"
  }
}
json
{
  "compilerOptions": {
    "strict": true,
    "target": "ES2020",
    "experimentalDecorators": true,
    "strictPropertyInitialization": false,
    "module": "esnext",
    "moduleResolution": "bundler",
    "allowJs": true,
    "outDir": "HACK_BECAUSE_OF_ALLOW_JS"
  }
}

src/backend/main.mo
— the starting backend

src/backend/main.mo
——起始后端

The canonical template's starting
main.mo
includes two mixins:
MixinAuthorization
from
caffeineai-authorization
, which provides Internet Identity sign-in and roles (the first user to sign in becomes admin), and
Expose
from
caffeineai-oql
, which publishes the backend's query interface.
accessControlState
is a stable field with no initializer;
00000000_000000.mo
gives it its value. Add your own functions inside the actor, following the
writing-motoko
skill
.
motoko
import AccessControl "mo:caffeineai-authorization/access-control";
import MixinAuthorization "mo:caffeineai-authorization/MixinAuthorization";
import Expose "mo:caffeineai-oql/Expose";

actor {
  let accessControlState : AccessControl.AccessControlState;
  include MixinAuthorization(accessControlState, null);
  include Expose({ entities = [] });
};
To guard methods by role, store user profiles, or capture verified names and emails at sign-in, follow the
extension-authorization
skill.
Do not write more Motoko than this without loading the
writing-motoko
skill — it covers persistent actors, stable types,
mo:core
, and the compiler-error pitfalls that an agent will otherwise hallucinate.
Caffeine 标准模板中的起始
main.mo
包含两个 mixin:来自
caffeineai-authorization
的
MixinAuthorization
,用于提供 Internet Identity 登录和角色(第一个登录的用户会成为 admin);以及来自
caffeineai-oql
的
Expose
,用于发布后端的 query 接口。
accessControlState
是一个没有 initializer 的稳定字段,其值由
00000000_000000.mo
提供。请遵循
writing-motoko
skill
,在 actor 内添加自己的函数。
motoko
import AccessControl "mo:caffeineai-authorization/access-control";
import MixinAuthorization "mo:caffeineai-authorization/MixinAuthorization";
import Expose "mo:caffeineai-oql/Expose";

actor {
  let accessControlState : AccessControl.AccessControlState;
  include MixinAuthorization(accessControlState, null);
  include Expose({ entities = [] });
};
如需按角色保护方法、存储用户资料,或在登录时捕获已验证的姓名和邮箱,请遵循
extension-authorization
skill。
在加载
writing-motoko
skill 之前,不要编写超出上述范围的 Motoko 代码——该 skill 涵盖 persistent actor、稳定类型、
mo:core
,以及 Agent 容易产生幻觉的编译器错误陷阱。

The frontend

前端

Fetch this skill's companion reference file —
references/frontend-template.md
, which sits next to this
SKILL.md
(i.e.
…/skills/caffeine-app/references/frontend-template.md
) — and create the frontend files from it; it holds the verified
package.json
, the Vite/Tailwind/Biome configs,
main.tsx
, and the worked
useActor(createActor)
backend call. The essentials:
  • The entry point
    src/frontend/src/main.tsx
    wraps the app in
    InternetIdentityProvider
    (from
    @caffeineai/core-infrastructure
    ) and a TanStack
    QueryClientProvider
    .
  • The frontend talks to the backend through the generated module
    src/frontend/src/backend.ts
    (and
    src/frontend/src/declarations/
    ), which exports a
    createActor(...)
    factory typed from your backend's Candid. You do not write these — they appear after the first build. Call the backend by passing that
    createActor
    to
    useActor(createActor)
    from
    @caffeineai/core-infrastructure
    (the same package provides the auth provider used in
    main.tsx
    ); you do not hand-write the actor/config/storage glue. See the worked example in
    references/frontend-template.md
    .
  • Sign-in uses
    useInternetIdentity()
    from the same package (
    login()
    from a button's
    onClick
    ,
    clear()
    ,
    isAuthenticated
    , and Google, Microsoft, or company SSO variants).
    useActor
    re-creates the actor with the signed-in identity. The hook's full API and the sign-in UI rules are in the
    extension-core-infrastructure
    skill: https://github.com/caffeinelabs/skills/tree/main/skills/extension-core-infrastructure.
  • env.json
    holds runtime config placeholders (
    backend_host
    ,
    backend_canister_id
    ,
    project_id
    ,
    ii_derivation_origin
    ,
    storage_gateway_url
    ), all
    "undefined"
    locally; the frontend
    build
    script copies it into
    dist/
    (
    cp env.json dist/
    ), and
    @caffeineai/core-infrastructure
    fetches it at runtime. Caffeine injects real values when it serves the app. Keep
    env.json
    and the
    copy:env
    step.
获取本 skill 的配套参考文件——
references/frontend-template.md
,它与本
SKILL.md
位于同一目录(即
…/skills/caffeine-app/references/frontend-template.md
)——并根据该文件创建前端文件;其中包含经过验证的
package.json
、Vite/Tailwind/Biome 配置、
main.tsx
,以及可实际运行的
useActor(createActor)
后端调用示例。核心要点如下:
  • 入口文件
    src/frontend/src/main.tsx
    使用
    InternetIdentityProvider
    (来自
    @caffeineai/core-infrastructure
    )和 TanStack
    QueryClientProvider
    包装应用。
  • 前端通过生成的模块
    src/frontend/src/backend.ts
    (以及
    src/frontend/src/declarations/
    )与后端通信;该模块导出根据后端 Candid 类型化的
    createActor(...)
    factory。你不应编写这些文件——它们会在首次构建后出现。通过将
    createActor
    传给
    @caffeineai/core-infrastructure
    中的
    useActor(createActor)
    来调用后端(同一个包也提供
    main.tsx
    中使用的 auth provider);不要手动编写 actor/config/storage 连接代码。请参阅
    references/frontend-template.md
    中的完整示例。
  • 登录使用同一包中的
    useInternetIdentity()
    (通过按钮的
    onClick
    调用
    login()
    ,并支持
    clear()
    、
    isAuthenticated
    ,以及 Google、Microsoft 或企业 SSO 变体)。
    useActor
    会根据已登录的身份重新创建 actor。该 hook 的完整 API 和登录 UI 规则请参阅
    extension-core-infrastructure
    skill: https://github.com/caffeinelabs/skills/tree/main/skills/extension-core-infrastructure。
  • env.json
    保存运行时配置占位符(
    backend_host
    、
    backend_canister_id
    、
    project_id
    、
    ii_derivation_origin
    、
    storage_gateway_url
    ),本地环境中全部为
    "undefined"
    ;前端
    build
    script 会将其复制到
    dist/
    (
    cp env.json dist/
    ),而
    @caffeineai/core-infrastructure
    会在运行时获取它。Caffeine 在托管应用时会注入真实值。请保留
    env.json
    和
    copy:env
    步骤。

The build loop

构建循环

Run from the project root. Order matters.
bash
undefined
从项目根目录运行。顺序很重要。
bash
undefined

1. Install dependencies. On a brand-new project, generate the pnpm lockfile FIRST

1. Install dependencies. On a brand-new project, generate the pnpm lockfile FIRST

(first run only — see Common Pitfalls), then install the rest (pnpm + mops).

(first run only — see Common Pitfalls), then install the rest (pnpm + mops).

pnpm install caffeine install
pnpm install caffeine install

2. Write your backend in src/backend/main.mo using the
writing-motoko
skill, and your

2. Write your backend in src/backend/main.mo using the
writing-motoko
skill, and your

frontend in src/frontend/src/.

frontend in src/frontend/src/.

3. Build: compiles the backend, then
pnpm bindgen
regenerates the frontend client

3. Build: compiles the backend, then
pnpm bindgen
regenerates the frontend client

(src/frontend/src/backend.ts + declarations/), then the frontend
pnpm build
runs.

(src/frontend/src/backend.ts + declarations/), then the frontend
pnpm build
runs.

Run this BEFORE check, so the frontend has the generated ./backend to typecheck

Run this BEFORE check, so the frontend has the generated ./backend to typecheck

against. Artifacts land in src/backend/dist + src/frontend/dist (no cloud / no id).

against. Artifacts land in src/backend/dist + src/frontend/dist (no cloud / no id).

caffeine build
caffeine build

4. Lint + typecheck + auto-fix (runs each canister's [check.fix] commands:

4. Lint + typecheck + auto-fix (runs each canister's [check.fix] commands:

backend
mops check --fix
, frontend
pnpm typecheck
+
pnpm fix
).

backend
mops check --fix
, frontend
pnpm typecheck
+
pnpm fix
).

caffeine check --fix
caffeine check --fix

5. Upload a built draft (needs a cloud project id). For a brand-new app, create the

5. Upload a built draft (needs a cloud project id). For a brand-new app, create the

cloud project once to obtain an id, then preview:

cloud project once to obtain an id, then preview:

caffeine projects create # reports a new project id
caffeine projects create # reports a new project id

put that id in caffeine.toml [project] id = "...", OR pass --project-id:

put that id in caffeine.toml [project] id = "...", OR pass --project-id:

caffeine preview --build --project-id <id>

`caffeine preview` refuses to upload when sources changed since the last `caffeine build`;
`--build` rebuilds first. It also checks the `mops.toml` structure described above and
needs `src/backend/dist/backend.wasm` and `src/frontend/dist/index.html`. Do not
`caffeine projects clone` a project you just created: it has no code yet, so the clone
fails with `No committed draft found`.

Set `CAFFEINE_VERBOSE=1` to stream complete subprocess output from `caffeine install`,
`caffeine build`, and `caffeine check`. This is equivalent to passing `--verbose` to
each command. `--json` continues to suppress streamed output.

Without a TTY (an agent's shell, CI, piped output) progress and results print as plain
lines. Add `--json` to any command for a machine-readable `{ "ok": true, "data": ... }` or
`{ "ok": false, "error": ... }` envelope.

**Generation ordering.** `src/frontend/src/backend.ts` does not exist until a build runs
`pnpm bindgen`. So if your frontend imports from `./backend`, you must run `caffeine build`
at least once before `caffeine check` can typecheck the frontend. A brand-new app whose
`App.tsx` does not yet import `./backend` typechecks fine before the first build.

**Going live.** `caffeine preview --build` (with a `project.id`) produces a *draft* and
returns its URL. Promote a draft to a live URL in the caffeine.ai web app (open it with
`caffeine chat open` or visit caffeine.ai), or with the `caffeine_go_live` tool of the
Caffeine MCP connector. There is no CLI deploy command. Use
`caffeine projects show <id>` to see draft and live URLs, and any custom domains.
caffeine preview --build --project-id <id>

如果自上次执行 `caffeine build` 后源代码发生了变化,`caffeine preview` 会拒绝上传;`--build` 会先重新构建。它还会检查上文所述的 `mops.toml` 结构,并要求存在 `src/backend/dist/backend.wasm` 和 `src/frontend/dist/index.html`。不要对刚创建的项目执行 `caffeine projects clone`:该项目中还没有代码,因此克隆会因 `No committed draft found` 而失败。

设置 `CAFFEINE_VERBOSE=1` 后,`caffeine install`、`caffeine build` 和 `caffeine check` 会流式输出完整的子进程输出。这等价于为每条命令传入 `--verbose`。`--json` 则会继续抑制流式输出。

在没有 TTY 的情况下(Agent shell、CI、管道输出),进度和结果会以纯文本行输出。可以为任意命令添加 `--json`,以获得适合机器读取的 `{ "ok": true, "data": ... }` 或 `{ "ok": false, "error": ... }` 包装格式。

**生成顺序。** 在构建运行 `pnpm bindgen` 之前,`src/frontend/src/backend.ts` 并不存在。因此,如果前端从 `./backend` 导入,必须至少运行一次 `caffeine build`,之后 `caffeine check` 才能对前端进行类型检查。如果全新应用的 `App.tsx` 尚未导入 `./backend`,则首次构建前也能通过类型检查。

**正式上线。** `caffeine preview --build`(配合 `project.id`)会生成一个 *draft* 并返回其 URL。要将 draft 提升为线上 URL,请在 caffeine.ai Web 应用中操作(使用 `caffeine chat open` 打开或访问 caffeine.ai),或者使用 Caffeine MCP connector 的 `caffeine_go_live` tool。不存在 CLI deploy 命令。使用 `caffeine projects show <id>` 查看 draft URL、线上 URL 和所有自定义域名。

Alternative: let Caffeine's own AI build it

备选方案:让 Caffeine 自带的 AI 构建

If you cannot run the CLI locally (no shell, no toolchain), drive Caffeine's hosted AI instead: create a cloud project with
caffeine projects create
, then describe the app in natural language with
caffeine chat send --project-id <id> "<prompt>"
(or use the caffeine.ai web chat). Caffeine's hosted AI then scaffolds, builds, and deploys it server-side.
chat send
only sends the prompt and follows the AI's progress (or returns at once with
--detach
), so this does not contradict the CLI having no deploy command. This skill is for the local, hand-authored path.
如果无法在本地运行 CLI(没有 shell 或工具链),可以改用 Caffeine 托管的 AI:先通过
caffeine projects create
创建云项目,然后使用自然语言描述应用并执行
caffeine chat send --project-id <id> "<prompt>"
(也可以使用 caffeine.ai Web 聊天)。随后,Caffeine 托管的 AI 会在服务端搭建、构建和部署应用。
chat send
只负责发送 prompt,并跟踪 AI 的进度(或通过
--detach
立即返回),因此这并不与 CLI 没有 deploy 命令这一事实矛盾。本 skill 面向的是本地、手工编写的路径。

Component skills

组件 skills

Caffeine ships ready-made components for sign-in and roles, file storage, payments, email, invite links, and third-party connectors (Google, Slack, Twilio, and more). Each is a mops package (
caffeineai-*
), often an npm package (
@caffeineai/*
), and a skill that shows how to wire them. Before building one of those features, read its skill and use the component instead of writing it yourself.
  • A cloned project lists its component skills in
    skills-lock.json
    . Restore them into
    .agents/skills/
    from the project root:
    bash
    npx skills experimental_install -y
  • A project you scaffold by hand has no lock file. Fetch the skill you need from https://github.com/caffeinelabs/skills: one
    skills/<name>/SKILL.md
    per component, listed in its README.
Caffeine 提供现成组件,可用于登录和角色、文件存储、支付、邮件、邀请链接以及第三方连接器(Google、Slack、Twilio 等)。每个组件都是一个 mops 包(
caffeineai-*
),通常还配有 npm 包(
@caffeineai/*
)和说明如何接入的 skill。在构建其中某项功能之前,请先阅读对应的 skill,并使用组件,而不是自行实现。
  • 克隆得到的项目会在
    skills-lock.json
    中列出其组件 skills。请从项目根目录将它们恢复到
    .agents/skills/
    :
    bash
    npx skills experimental_install -y
  • 手动搭建的项目没有 lock file。请从 https://github.com/caffeinelabs/skills 获取所需 skill:每个组件对应一个
    skills/<name>/SKILL.md
    ,其列表见 README。

Using the app from Claude or another AI assistant

从 Claude 或其他 AI assistant 使用应用

A deployed Caffeine app already works with DFINITY's ICP MCP connector,
https://mcp.internetcomputer.org/mcp
. The user adds it to their assistant as a custom connector, signs in with Internet Identity, and asks it to open the app by its web address; the assistant then calls the app's backend methods as that user. Do not build an MCP server, an HTTP endpoint, or a secret link into the app for this. Clear backend method names and Candid types are what the assistant reads, so a capability it should have is an ordinary backend method.
已部署的 Caffeine 应用可以直接配合 DFINITY 的 ICP MCP connector
https://mcp.internetcomputer.org/mcp
使用。用户将其作为自定义 connector 添加到 assistant 中,使用 Internet Identity 登录,然后要求 assistant 通过应用的 Web 地址打开应用;assistant 随后会以该用户的身份调用应用的后端方法。请不要为此在应用中构建 MCP server、HTTP endpoint 或 secret link。清晰的方法名称和 Candid 类型才是 assistant 所读取的内容,因此它应具备的能力应实现为普通后端方法。

Common Pitfalls

常见问题

  1. Missing
    [workspace]
    in the root
    caffeine.toml
    .
    Without it the root file is parsed as a canister manifest and the CLI cannot find your canisters. The root manifest is defined by the presence of
    [workspace]
    , not by being at the top.
  2. Renaming the backend canister. It must be
    backend
    —
    mops.toml
    declares
    [canisters.backend]
    and the root
    bindgen
    script reads
    ./src/backend/dist/backend.did
    . Renaming breaks the build and the generated client.
  3. Hand-writing or editing
    src/frontend/src/backend.ts
    or
    declarations/
    .
    These are generated by
    caffeine-bindgen
    and overwritten on every build. Add backend methods in
    main.mo
    , rebuild, and the client regenerates. The generated header says "You should NOT make any changes in this file"; it is also excluded from Biome.
  4. Importing
    ./backend
    before the first build.
    The binding module is created by the build's
    pnpm bindgen
    step. Run
    caffeine preview --build
    (or
    caffeine build
    ) once before relying on
    import { createActor } from "./backend"
    .
  5. Trying to
    dfx deploy
    or expecting
    caffeine deploy
    .
    Caffeine apps build via the
    caffeine
    CLI and go live via the web app. There is no
    dfx
    in the workflow and no CLI deploy/publish command.
  6. Dropping required
    mops.toml
    settings.
    Keep the single
    [canisters.backend]
    ,
    [canisters.backend.check-stable]
    ,
    [build] outputDir
    , and a
    [toolchain] moc
    pin (mops cannot compile without one).
  7. Deleting
    .old/
    or
    env.json
    , or skipping
    copy:env
    .
    .old/
    holds the stable-signature snapshot
    check-stable
    compares against;
    env.json
    must be copied into
    dist/
    so the served frontend can read its runtime config.
  8. Writing Motoko without the
    writing-motoko
    skill.
    Modern Caffeine Motoko uses
    mo:core
    , persistent actors, and specific patterns. Guessing produces compiler errors. Load https://skills.internetcomputer.org/skills/writing-motoko/SKILL.md first.
  9. Using
    npm
    /
    yarn
    instead of
    pnpm
    .
    The workspace is pnpm-based (
    pnpm-workspace.yaml
    ,
    pnpm -r
    scripts).
    caffeine install
    uses pnpm + mops.
  10. caffeine install
    /
    build
    fails with
    ERR_PNPM_NO_LOCKFILE
    on a fresh project.
    In a non-interactive shell (an agent, CI, or any run without a TTY) these commands run
    pnpm install --frozen-lockfile
    , which requires a
    pnpm-lock.yaml
    that a brand-new project does not have. Run
    pnpm install
    once first to generate the lockfile, then the loop works. (An interactive terminal creates it for you.)
  11. First
    caffeine check
    fails with
    Deployed file not found: …/backend.most
    .
    The stable-signature check needs the last deployed snapshot, which a never-deployed project lacks. Seed
    .old/src/backend/dist/backend.most
    with an empty actor (shown under the
    mops.toml
    above).
    caffeine build
    does not create it.
  12. caffeine preview --build
    fails with
    No project.id in caffeine.toml
    .
    Uploading a draft needs a cloud project. Run
    caffeine projects create
    to get an id, set it in
    [project] id
    (or pass
    --project-id <id>
    ), then preview.
    caffeine build
    alone needs no id and is enough to verify the app compiles.
  13. too many pending migrations for check-limit=1
    .
    Only one migration can be pending at a time, and on a never-deployed project
    00000000_000000.mo
    already is. Fold the new state into that pending file instead of adding another.
  14. include-authorization
    lint error, or
    M0169
    "stable variable
    accessControlState
    … cannot be implicitly discarded".
    main.mo
    dropped
    MixinAuthorization
    or its
    accessControlState
    field while the package and the first migration still provide them. Keep the starting
    main.mo
    lines, or remove authorization completely as the
    extension-authorization
    skill describes.
  1. 根
    caffeine.toml
    中缺少
    [workspace]
    。
    缺少该部分时,根文件会被解析为 canister 清单,CLI 无法找到你的 canister。根清单由
    [workspace]
    的存在来定义,而不是由其位于顶层来定义。
  2. 重命名 backend canister。 它必须命名为
    backend
    ——
    mops.toml
    声明
    [canisters.backend]
    ,而根
    bindgen
    script 会读取
    ./src/backend/dist/backend.did
    。重命名会破坏构建及生成的 client。
  3. 手动编写或编辑
    src/frontend/src/backend.ts
    或
    declarations/
    。
    这些文件由
    caffeine-bindgen
    生成,并会在每次构建时被覆盖。请在
    main.mo
    中添加后端方法,然后重新构建,client 会自动重新生成。生成文件的头部注明“You should NOT make any changes in this file”;它也会被 Biome 排除。
  4. 首次构建前导入
    ./backend
    。
    绑定模块由构建中的
    pnpm bindgen
    步骤创建。在依赖
    import { createActor } from "./backend"
    之前,至少运行一次
    caffeine preview --build
    (或
    caffeine build
    )。
  5. 尝试执行
    dfx deploy
    或期待存在
    caffeine deploy
    。
    Caffeine 应用通过
    caffeine
    CLI 构建,并通过 Web 应用上线。工作流中没有
    dfx
    ,也没有 CLI deploy/publish 命令。
  6. 遗漏必需的
    mops.toml
    设置。
    请保留单个
    [canisters.backend]
    、
    [canisters.backend.check-stable]
    、
    [build] outputDir
    ,以及
    [toolchain] moc
    版本固定项(没有固定版本,mops 无法编译)。
  7. 删除
    .old/
    或
    env.json
    ,或者跳过
    copy:env
    。
    .old/
    保存
    check-stable
    用于比较的稳定签名快照;
    env.json
    必须复制到
    dist/
    ,这样托管的前端才能读取运行时配置。
  8. 未使用
    writing-motoko
    skill 就编写 Motoko。
    现代 Caffeine Motoko 使用
    mo:core
    、persistent actor 和特定模式。凭空猜测会产生编译错误。请先加载 https://skills.internetcomputer.org/skills/writing-motoko/SKILL.md。
  9. 使用
    npm
    /
    yarn
    而不是
    pnpm
    。
    该 workspace 基于 pnpm(
    pnpm-workspace.yaml
    、
    pnpm -r
    scripts)。
    caffeine install
    使用 pnpm + mops。
  10. 在全新项目上,
    caffeine install
    /
    build
    因
    ERR_PNPM_NO_LOCKFILE
    而失败。
    在非交互式 shell(Agent、CI 或任何没有 TTY 的运行)中,这些命令会执行
    pnpm install --frozen-lockfile
    ,而该命令要求存在
    pnpm-lock.yaml
    ,但全新项目并不具备该文件。请先运行一次
    pnpm install
    生成 lockfile,之后构建循环即可正常工作。(交互式终端会自动创建它。)
  11. 首次执行
    caffeine check
    时因
    Deployed file not found: …/backend.most
    而失败。
    稳定签名检查需要上一次部署的快照,而从未部署过的项目缺少该快照。请按照
    mops.toml
    部分所示,使用空 actor 初始化
    .old/src/backend/dist/backend.most
    。
    caffeine build
    不会创建该文件。
  12. caffeine preview --build
    因
    No project.id in caffeine.toml
    而失败。
    上传 draft 需要云项目。请运行
    caffeine projects create
    获取 id,将其设置在
    [project] id
    中(或传入
    --project-id <id>
    ),然后执行 preview。单独执行
    caffeine build
    不需要 id,并且足以验证应用能否编译。
  13. too many pending migrations for check-limit=1
    。
    同一时间只能存在一个待部署迁移,而在从未部署过的项目中,
    00000000_000000.mo
    已经是待部署迁移。应将新状态合并到该待部署文件中,而不是再添加一个文件。
  14. 出现
    include-authorization
    lint 错误,或 M0169“stable variable
    accessControlState
    … cannot be implicitly discarded”。
    main.mo
    删除了
    MixinAuthorization
    或其
    accessControlState
    字段,但包和首次迁移仍提供这些内容。请保留起始
    main.mo
    中的相关行,或者按照
    extension-authorization
    skill 的说明完整移除授权功能。

Related skills

相关 skills

Additional references

补充参考

  • references/frontend-template.md
    — the full, verbatim frontend boilerplate (
    package.json
    ,
    vite.config.js
    , Tailwind/PostCSS/Biome configs,
    tsconfig.json
    ,
    index.html
    ,
    env.json
    ,
    main.tsx
    , a starter
    App.tsx
    , and the backend-actor wiring pattern). Read it when you create
    src/frontend/
    .
  • references/frontend-template.md
    ——完整且逐字保留的前端 boilerplate(
    package.json
    、
    vite.config.js
    、Tailwind/PostCSS/Biome 配置、
    tsconfig.json
    、
    index.html
    、
    env.json
    、
    main.tsx
    、初始
    App.tsx
    ,以及 backend actor 接入模式)。创建
    src/frontend/
    时请阅读该文件。