caffeine-app
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCaffeine 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
skill: https://skills.internetcomputer.org/skills/writing-motoko/SKILL.md. That skill is
authoritative for actor syntax, stable state, , and compiler errors. This
skill only shows the minimal empty actor and where it lives.
writing-motokomo:coreCaffeine (caffeine.ai) 在 Internet Computer 上构建并托管全栈应用:一个 Motoko backend canister,加上一个作为 assets canister 托管的 React/Vite frontend。本 skill 讲解准确的 项目结构 和 CLI 构建循环,让你能够从零创建可构建的 Caffeine 应用。
本 skill 负责项目结构和构建工作流,但不负责 Motoko 语言。 在编写或编辑任何后端代码前,先获取并遵循 skill:https://skills.internetcomputer.org/skills/writing-motoko/SKILL.md。该 skill 是 actor 语法、稳定状态、 和编译器错误的权威依据。本 skill 只会展示最小空 actor 及其所在位置。
writing-motokomo:coreWhen to use this skill
何时使用本 skill
- Creating/scaffolding a new Caffeine app or caffeine.ai project from scratch.
- Writing or fixing (workspace or canister manifest) or
caffeine.toml.mops.toml - Running the caffeine CLI loop: ,
auth login,doctor,install,check.preview
Do not use it for Motoko language details (use ) or for raw IC//
deployment (use ). Caffeine apps are built and deployed through the
CLI and the caffeine.ai web app, not through .
writing-motokodfxicpicp-clicaffeinedfx- 从头创建或搭建新的 Caffeine 应用或 caffeine.ai 项目。
- 编写或修复 (workspace 或 canister 清单)或
caffeine.toml。mops.toml - 运行 caffeine CLI 循环:、
auth login、doctor、install、check。preview
请不要将本 skill 用于 Motoko 语言细节(使用 ),也不要用于原生 IC// 部署(使用 )。Caffeine 应用通过 CLI 和 caffeine.ai Web 应用进行构建与部署,而不是通过 。
writing-motokodfxicpicp-clicaffeinedfxCritical facts
关键事实
- There is no /
caffeine init. "From scratch" means you create the files in this skill by hand, then run the build loop. (caffeine newonly downloads an existing cloud project, andcaffeine projects clone <id>only unpacks a project archive such as one made bycaffeine projects import <zip>; neither is a greenfield scaffold.)caffeine export - Exactly one backend canister, and it must be named .
backenddeclares a singlemops.toml.[canisters.backend] - The frontend↔backend binding files are generated, never hand-written.
and
src/frontend/src/backend.tsare produced bysrc/frontend/src/declarations/during the build. Editing them is pointless — they are overwritten.caffeine-bindgen - 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 (, which needs a cloud
caffeine preview --build— see the build loop). There is noproject.id/caffeine deploycommand.publish
- 不存在 /
caffeine init。 “从头开始”意味着手动创建本 skill 中的文件,然后运行构建循环。(caffeine new只会下载现有云项目;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
undefinedbash
undefinedInstall the CLI (public npm package). The binary is caffeine
.
caffeineInstall the CLI (public npm package). The binary is caffeine
.
caffeinenpm 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 editOnly the root manifest, the two canister manifests, , , and
the small root config files are shown inline below. The full frontend boilerplate
(, , the Tailwind/PostCSS/Biome configs, ,
, , a starter ) is in
— read it when you
create the frontend.
mops.tomlmain.mopackage.jsonvite.config.jsindex.htmlenv.jsonmain.tsxApp.tsxreferences/frontend-template.mdCaffeine 应用是一个带根清单和两个 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 清单、、 和少量根配置文件。完整的前端 boilerplate(、、Tailwind/PostCSS/Biome 配置、、、 和初始 )位于 中——创建前端时请阅读该文件。
mops.tomlmain.mopackage.jsonvite.config.jsindex.htmlenv.jsonmain.tsxApp.tsxreferences/frontend-template.mdManifests
清单
Root caffeine.toml
— the workspace
caffeine.toml根 caffeine.toml
——workspace
caffeine.tomlThe root manifest must contain a 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.
[workspace]toml
manifest_version = "0.1.0"
[project]
name = "My App"根清单必须包含 部分。正是该部分将其标记为 workspace 根;如果缺少该部分,CLI 会将此文件视为普通 canister 清单,并导致发现过程失败。
[workspace]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 createcaffeine projects create
reports one, set it here (or pass --project-id to preview).
caffeine projects createA placeholder such as "my-app" makes caffeine preview
refuse to upload.
caffeine previewA placeholder such as "my-app" makes caffeine preview
refuse to upload.
caffeine preview[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.tomlsrc/backend/caffeine.toml
——Motoko canister
src/backend/caffeine.tomltoml
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].commandsmops buildmain.mopnpm bindgenpackage.jsoncaffeine check --fix[check.fix].commandstoml
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].commandsmops buildmain.mopnpm bindgenpackage.jsoncaffeine check --fix[check.fix].commandssrc/frontend/caffeine.toml
— the assets canister
src/frontend/caffeine.tomlsrc/frontend/caffeine.toml
——assets canister
src/frontend/caffeine.tomltoml
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.tomlmops.toml
——Motoko 构建(每个项目根目录一个)
mops.tomlThere is exactly one . checks only the
structural pieces, which are invariant: the single ,
with the path shown and no , and
. Everything else — the toolchain versions, the
flags and // diagnostic codes, and the dependency list — is a current
snapshot that the Caffeine template bumps over time; see "Versions and dependencies
drift" below.
[canisters.backend]caffeine preview[canisters.backend][canisters.backend.check-stable]skipIfMissing[build] outputDir = "src/backend/dist"[moc]-E-W-Atoml
[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 = 1Notes:
-
New projects use moc 2. Under moc 2 a bareis persistent, and the
actorkeyword only triggers warning M0217. Older guides addpersistentor--default-persistent-actorsto--generate-view-queries: those are moc 1.x flags that moc 2.0 removed, and passing them fails every compile with[moc] args. Projects cloned from before the switch may still pin moc 1.x (the template's moc 1 variant isunknown optionwithmoc = "1.16.0"first in--default-persistent-actors); leave such a project on its pinned version, or move it with the[moc] argsskill: https://github.com/caffeinelabs/skills/tree/main/skills/migrating-to-moc-2.migrating-to-moc-2 -
points at
check-stable, the stable-signature snapshot of the last deployed backend..old/src/backend/dist/backend.mostcompares your stable state against it, andcaffeine checkrestores it from the cloud. Do not deletecaffeine projects clone. A from-scratch project must seed it with an empty actor, as the Caffeine template does, or.old/fails withcaffeine check:Deployed file not found: .old/src/backend/dist/backend.mostmotoko// Version: 1.0.0 actor {};Do not setinstead: mops deprecated it, andskipIfMissing = truerejects it because a skipped check only fails later, at deploy.caffeine preview -
turns on enhanced migration (mops adds
[canisters.backend.migrations]itself; do not put it in--enhanced-migration). Every[moc] argsfile in.mo, 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 withsrc/backend/migrations/, which creates the state the starting00000000_000000.modeclares (below) and sorts before themain.mofiles later migrations use:YYYYMMDD_HHMMSS.momotokoimport AccessControl "mo:caffeineai-authorization/access-control"; module { public type OldActor = {}; public type NewActor = { accessControlState : AccessControl.AccessControlState }; public func migration(_ : OldActor) : NewActor { { accessControlState = AccessControl.initState() }; }; };allows one pending (not yet deployed) migration. Against the seeded empty baseline,check-limit = 1is 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 fails00000000_000000.mowithcaffeine check. Never edit, rename, or delete a migration after it is deployed. The rules for writing migrations are in thetoo many pending migrations for check-limit=1skill: https://github.com/caffeinelabs/skills/tree/main/skills/migrating-motoko-actors.migrating-motoko-actors -
is the
corestandard library. Usemo:core, never the deprecatedmo:core— see themo:baseskill.writing-motokoprovides thecaffeineai-oqlmixin the startingExposeincludes (below).main.mo -
provides Internet Identity sign-in and roles (
caffeineai-authorization,MixinAuthorization). It also ships a lint rule that failsAccessControlunlesscaffeine checkincludesmain.mo. To use custom authentication instead before the first deploy, remove the package (MixinAuthorization) together with its imports, include, state field, and migration line — see themops remove caffeineai-authorizationskill: 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 andextension-authorization, and add custom checks alongside them.MixinAuthorization -
runs the lint rules that dependencies ship (such as the one above) with the
[lint] extends = truepinned inlintoko, as part of[toolchain].mops check -
provides the IC management canister's types and calls (
ic,mo:ic/Types). Use it instead ofmo:ic/Call, which only resolves with animport ... "ic:aaaaa-aa"flag that the template no longer passes.--actor-idl -
Add a package with(one package per command) rather than by editing
mops add <name>, so[dependencies]stays in sync. Themops.lockskill covers the mops commands: https://github.com/caffeinelabs/skills/tree/main/skills/mops-cli.mops-cli
Versions and dependencies drift. Theversions, the[toolchain][moc]/-E/-Wcodes, and the frontend dependency set are template-managed and change over time (e.g. the-A→@dfinity/*migration, moc/core bumps). Treat the exact values here as a snapshot — for current ones,@icp-sdk/*a recent project and copy itscaffeine projects clone+mops.toml. Stable across versions: the file layout, the singlesrc/frontend/package.jsoncanister,backendwith the seeded baseline,check-stable,[build] outputDir, andmo:core.useActor(createActor)
必须且只能存在一个 。 只检查结构性内容,这些内容不会发生变化:单个 、路径如所示且不含 的 ,以及 。其他所有内容——[toolchain] 版本、 flags 和 // 诊断代码,以及依赖列表——都是当前快照,Caffeine 模板会随着时间更新;请参阅下文“版本和依赖漂移”。
[canisters.backend]caffeine preview[canisters.backend]skipIfMissing[canisters.backend.check-stable][build] outputDir = "src/backend/dist"[moc]-E-W-Atoml
[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 下,普通的默认是 persistent 的,使用
actor关键字只会触发 M0217 警告。旧版指南会在persistent中添加[moc] args或--default-persistent-actors:这些是 moc 1.x flags,moc 2.0 已将其移除,传入后每次编译都会因--generate-view-queries而失败。从切换前克隆的项目可能仍固定使用 moc 1.x(模板的 moc 1 变体使用unknown option,并将moc = "1.16.0"放在--default-persistent-actors的首位);可以让此类项目继续使用其固定版本,或使用[moc] argsskill 迁移: https://github.com/caffeinelabs/skills/tree/main/skills/migrating-to-moc-2。migrating-to-moc-2 -
指向
check-stable,即上一次部署的后端的稳定签名快照。.old/src/backend/dist/backend.most会将当前稳定状态与其比较,而caffeine check会从云端恢复它。不要删除caffeine projects clone。从头创建的项目必须按照 Caffeine 模板的做法,使用空 actor 对其进行初始化,否则.old/会因以下错误而失败:caffeine check:Deployed file not found: .old/src/backend/dist/backend.mostmotoko// Version: 1.0.0 actor {};不要改为设置:mops 已弃用此选项,而且skipIfMissing = true会拒绝该设置,因为跳过检查只会让问题推迟到部署阶段才暴露。caffeine preview -
用于启用增强迁移(mops 会自行添加
[canisters.backend.migrations];不要将其放入--enhanced-migration)。[moc] args中的每个src/backend/migrations/文件都会按名称顺序构成一步,将之前的稳定状态映射到下一个稳定状态。actor 中的稳定字段不能有 initializer;其初始值来自迁移链。新项目以.mo开始,它会创建起始00000000_000000.mo所声明的状态(见下文),并且排在后续迁移使用的main.mo文件之前:YYYYMMDD_HHMMSS.momotokoimport 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=1skill: https://github.com/caffeinelabs/skills/tree/main/skills/migrating-motoko-actors。migrating-motoko-actors -
是
core标准库。请使用mo:core,不要使用已弃用的mo:core——参阅mo:baseskill。writing-motoko提供起始caffeineai-oql所包含的main.momixin(见下文)。Expose -
提供 Internet Identity 登录和角色(
caffeineai-authorization、MixinAuthorization)。它还附带一条 lint 规则:如果AccessControl未包含main.mo,MixinAuthorization就会失败。如果要在首次部署前使用自定义认证,请按照caffeine checkskill 的说明移除该包(extension-authorization),并同时移除其 import、include、状态字段和迁移行: https://github.com/caffeinelabs/skills/tree/main/skills/extension-authorization。 部署后,已应用的首次迁移会导入该包,因此移除它会破坏构建:请保留该包和mops remove caffeineai-authorization,并在它们的基础上添加自定义检查。MixinAuthorization -
会使用
[lint] extends = true中固定的[toolchain]运行依赖附带的 lint 规则(例如上述规则),并将其作为lintoko的一部分执行。mops check -
提供 IC 管理 canister 的类型和调用(
ic、mo:ic/Types)。请使用它,而不要使用mo:ic/Call;后者只有在传入import ... "ic:aaaaa-aa"flag 时才能解析,而模板已不再传入该 flag。--actor-idl -
添加包时请使用(每条命令添加一个包),不要直接编辑
mops add <name>,这样才能确保[dependencies]保持同步。mops 命令详见mops.lockskill:https://github.com/caffeinelabs/skills/tree/main/skills/mops-cli。mops-cli
版本和依赖漂移。版本、[toolchain]的[moc]/-E/-W代码以及前端依赖集均由模板管理,并会随时间变化(例如从-A迁移到@dfinity/*,以及 moc/core 版本升级)。请将这里的具体值视为快照——如需获取当前版本,可使用@icp-sdk/*克隆一个近期项目,然后复制其caffeine projects clone和mops.toml。跨版本保持不变的内容包括:文件布局、单个src/frontend/package.jsoncanister、带初始化基线的backend、check-stable、[build] outputDir,以及mo:core。useActor(createActor)
package.json
(root) — pnpm workspace + the bindgen
script
package.jsonbindgenpackage.json
(根目录)——pnpm workspace + bindgen
script
package.jsonbindgenThe script is the bridge from backend Candid to the frontend TS client. It is
invoked by the backend canister's step ().
bindgen[build]pnpm bindgenjson
{
"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 field and adds
for its hosted backend tests; a local project needs neither.
packageManager@dfinity/picbindgen[build]pnpm bindgenjson
{
"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 模板还会通过 字段固定 pnpm 版本,并添加 以支持其托管的后端测试;本地项目不需要这两项。
packageManager@dfinity/picpnpm-workspace.yaml
pnpm-workspace.yamlpnpm-workspace.yaml
pnpm-workspace.yamlpnpm 10 reads ; pnpm 11 and later read only . Keep
both so either version runs the packages' install scripts.
onlyBuiltDependenciesallowBuildsyaml
packages:
- src/**/*
allowBuilds:
'@biomejs/biome': true
esbuild: true
sharp: true
onlyBuiltDependencies:
- '@biomejs/biome'
- esbuild
- sharppnpm 10 会读取 ;pnpm 11 及更高版本只读取 。两者都应保留,以确保任一版本都能运行各包的安装脚本。
onlyBuiltDependenciesallowBuildsyaml
packages:
- src/**/*
allowBuilds:
'@biomejs/biome': true
esbuild: true
sharp: true
onlyBuiltDependencies:
- '@biomejs/biome'
- esbuild
- sharptsconfig.json
(root)
tsconfig.jsontsconfig.json
(根目录)
tsconfig.jsonjson
{
"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.mosrc/backend/main.mo
——起始后端
src/backend/main.moThe canonical template's starting includes two mixins:
from , which provides Internet Identity sign-in and roles (the
first user to sign in becomes admin), and from , which
publishes the backend's query interface. is a stable field with no
initializer; gives it its value. Add your own functions inside the
actor, following the skill.
main.moMixinAuthorizationcaffeineai-authorizationExposecaffeineai-oqlaccessControlState00000000_000000.mowriting-motokomotoko
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 skill.
extension-authorizationDo not write more Motoko than this without loading
the skill — it covers persistent actors, stable types, , and the
compiler-error pitfalls that an agent will otherwise hallucinate.
writing-motokomo:coreCaffeine 标准模板中的起始 包含两个 mixin:来自 的 ,用于提供 Internet Identity 登录和角色(第一个登录的用户会成为 admin);以及来自 的 ,用于发布后端的 query 接口。 是一个没有 initializer 的稳定字段,其值由 提供。请遵循 skill,在 actor 内添加自己的函数。
main.mocaffeineai-authorizationMixinAuthorizationcaffeineai-oqlExposeaccessControlState00000000_000000.mowriting-motokomotoko
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 = [] });
};如需按角色保护方法、存储用户资料,或在登录时捕获已验证的姓名和邮箱,请遵循 skill。
extension-authorization在加载 skill 之前,不要编写超出上述范围的 Motoko 代码——该 skill 涵盖 persistent actor、稳定类型、,以及 Agent 容易产生幻觉的编译器错误陷阱。
writing-motokomo:coreThe frontend
前端
Fetch this skill's companion reference file —
, which sits next to
this (i.e. ) — and create
the frontend files from it; it holds the verified , the Vite/Tailwind/Biome
configs, , and the worked backend call. The essentials:
references/frontend-template.mdSKILL.md…/skills/caffeine-app/references/frontend-template.mdpackage.jsonmain.tsxuseActor(createActor)- The entry point wraps the app in
src/frontend/src/main.tsx(fromInternetIdentityProvider) and a TanStack@caffeineai/core-infrastructure.QueryClientProvider - The frontend talks to the backend through the generated module
(and
src/frontend/src/backend.ts), which exports asrc/frontend/src/declarations/factory typed from your backend's Candid. You do not write these — they appear after the first build. Call the backend by passing thatcreateActor(...)tocreateActorfromuseActor(createActor)(the same package provides the auth provider used in@caffeineai/core-infrastructure); you do not hand-write the actor/config/storage glue. See the worked example inmain.tsx.references/frontend-template.md - Sign-in uses from the same package (
useInternetIdentity()from a button'slogin(),onClick,clear(), and Google, Microsoft, or company SSO variants).isAuthenticatedre-creates the actor with the signed-in identity. The hook's full API and the sign-in UI rules are in theuseActorskill: https://github.com/caffeinelabs/skills/tree/main/skills/extension-core-infrastructure.extension-core-infrastructure - holds runtime config placeholders (
env.json,backend_host,backend_canister_id,project_id,ii_derivation_origin), allstorage_gateway_urllocally; the frontend"undefined"script copies it intobuild(dist/), andcp env.json dist/fetches it at runtime. Caffeine injects real values when it serves the app. Keep@caffeineai/core-infrastructureand theenv.jsonstep.copy:env
获取本 skill 的配套参考文件——,它与本 位于同一目录(即 )——并根据该文件创建前端文件;其中包含经过验证的 、Vite/Tailwind/Biome 配置、,以及可实际运行的 后端调用示例。核心要点如下:
references/frontend-template.mdSKILL.md…/skills/caffeine-app/references/frontend-template.mdpackage.jsonmain.tsxuseActor(createActor)- 入口文件 使用
src/frontend/src/main.tsx(来自InternetIdentityProvider)和 TanStack@caffeineai/core-infrastructure包装应用。QueryClientProvider - 前端通过生成的模块 (以及
src/frontend/src/backend.ts)与后端通信;该模块导出根据后端 Candid 类型化的src/frontend/src/declarations/factory。你不应编写这些文件——它们会在首次构建后出现。通过将createActor(...)传给createActor中的@caffeineai/core-infrastructure来调用后端(同一个包也提供useActor(createActor)中使用的 auth provider);不要手动编写 actor/config/storage 连接代码。请参阅main.tsx中的完整示例。references/frontend-template.md - 登录使用同一包中的 (通过按钮的
useInternetIdentity()调用onClick,并支持login()、clear(),以及 Google、Microsoft 或企业 SSO 变体)。isAuthenticated会根据已登录的身份重新创建 actor。该 hook 的完整 API 和登录 UI 规则请参阅useActorskill: https://github.com/caffeinelabs/skills/tree/main/skills/extension-core-infrastructure。extension-core-infrastructure - 保存运行时配置占位符(
env.json、backend_host、backend_canister_id、project_id、ii_derivation_origin),本地环境中全部为storage_gateway_url;前端"undefined"script 会将其复制到build(dist/),而cp env.json dist/会在运行时获取它。Caffeine 在托管应用时会注入真实值。请保留@caffeineai/core-infrastructure和env.json步骤。copy:env
The build loop
构建循环
Run from the project root. Order matters.
bash
undefined从项目根目录运行。顺序很重要。
bash
undefined1. 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
writing-motoko2. Write your backend in src/backend/main.mo using the writing-motoko
skill, and your
writing-motokofrontend in src/frontend/src/.
frontend in src/frontend/src/.
3. Build: compiles the backend, then pnpm bindgen
regenerates the frontend client
pnpm bindgen3. Build: compiles the backend, then pnpm bindgen
regenerates the frontend client
pnpm bindgen(src/frontend/src/backend.ts + declarations/), then the frontend pnpm build
runs.
pnpm build(src/frontend/src/backend.ts + declarations/), then the frontend pnpm build
runs.
pnpm buildRun 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
).
mops check --fixpnpm typecheckpnpm fixbackend mops check --fix
, frontend pnpm typecheck
+ pnpm fix
).
mops check --fixpnpm typecheckpnpm fixcaffeine 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 , then describe the app in
natural language with (or use the
caffeine.ai web chat). Caffeine's hosted AI then scaffolds, builds, and deploys it
server-side. only sends the prompt and follows the AI's progress (or returns
at once with ), so this does not contradict the CLI having no deploy command.
This skill is for the local, hand-authored path.
caffeine projects createcaffeine chat send --project-id <id> "<prompt>"chat send--detach如果无法在本地运行 CLI(没有 shell 或工具链),可以改用 Caffeine 托管的 AI:先通过 创建云项目,然后使用自然语言描述应用并执行 (也可以使用 caffeine.ai Web 聊天)。随后,Caffeine 托管的 AI 会在服务端搭建、构建和部署应用。 只负责发送 prompt,并跟踪 AI 的进度(或通过 立即返回),因此这并不与 CLI 没有 deploy 命令这一事实矛盾。本 skill 面向的是本地、手工编写的路径。
caffeine projects createcaffeine chat send --project-id <id> "<prompt>"chat send--detachComponent 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 (), often an npm package (), 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.
caffeineai-*@caffeineai/*-
A cloned project lists its component skills in. Restore them into
skills-lock.jsonfrom the project root:.agents/skills/bashnpx 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: oneper component, listed in its README.
skills/<name>/SKILL.md
Caffeine 提供现成组件,可用于登录和角色、文件存储、支付、邮件、邀请链接以及第三方连接器(Google、Slack、Twilio 等)。每个组件都是一个 mops 包(),通常还配有 npm 包()和说明如何接入的 skill。在构建其中某项功能之前,请先阅读对应的 skill,并使用组件,而不是自行实现。
caffeineai-*@caffeineai/*-
克隆得到的项目会在中列出其组件 skills。请从项目根目录将它们恢复到
skills-lock.json:.agents/skills/bashnpx skills experimental_install -y -
手动搭建的项目没有 lock file。请从 https://github.com/caffeinelabs/skills 获取所需 skill:每个组件对应一个,其列表见 README。
skills/<name>/SKILL.md
Using the app from Claude or another AI assistant
从 Claude 或其他 AI assistant 使用应用
A deployed Caffeine app already works with DFINITY's ICP MCP connector,
. 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.
https://mcp.internetcomputer.org/mcp已部署的 Caffeine 应用可以直接配合 DFINITY 的 ICP MCP connector 使用。用户将其作为自定义 connector 添加到 assistant 中,使用 Internet Identity 登录,然后要求 assistant 通过应用的 Web 地址打开应用;assistant 随后会以该用户的身份调用应用的后端方法。请不要为此在应用中构建 MCP server、HTTP endpoint 或 secret link。清晰的方法名称和 Candid 类型才是 assistant 所读取的内容,因此它应具备的能力应实现为普通后端方法。
https://mcp.internetcomputer.org/mcpCommon Pitfalls
常见问题
- Missing in the root
[workspace]. 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 ofcaffeine.toml, not by being at the top.[workspace] - Renaming the backend canister. It must be —
backenddeclaresmops.tomland the root[canisters.backend]script readsbindgen. Renaming breaks the build and the generated client../src/backend/dist/backend.did - Hand-writing or editing or
src/frontend/src/backend.ts. These are generated bydeclarations/and overwritten on every build. Add backend methods incaffeine-bindgen, rebuild, and the client regenerates. The generated header says "You should NOT make any changes in this file"; it is also excluded from Biome.main.mo - Importing before the first build. The binding module is created by the build's
./backendstep. Runpnpm bindgen(orcaffeine preview --build) once before relying oncaffeine build.import { createActor } from "./backend" - Trying to or expecting
dfx deploy. Caffeine apps build via thecaffeine deployCLI and go live via the web app. There is nocaffeinein the workflow and no CLI deploy/publish command.dfx - Dropping required settings. Keep the single
mops.toml,[canisters.backend],[canisters.backend.check-stable], and a[build] outputDirpin (mops cannot compile without one).[toolchain] moc - Deleting or
.old/, or skippingenv.json.copy:envholds the stable-signature snapshot.old/compares against;check-stablemust be copied intoenv.jsonso the served frontend can read its runtime config.dist/ - Writing Motoko without the skill. Modern Caffeine Motoko uses
writing-motoko, persistent actors, and specific patterns. Guessing produces compiler errors. Load https://skills.internetcomputer.org/skills/writing-motoko/SKILL.md first.mo:core - Using /
npminstead ofyarn. The workspace is pnpm-based (pnpm,pnpm-workspace.yamlscripts).pnpm -ruses pnpm + mops.caffeine install - /
caffeine installfails withbuildon a fresh project. In a non-interactive shell (an agent, CI, or any run without a TTY) these commands runERR_PNPM_NO_LOCKFILE, which requires apnpm install --frozen-lockfilethat a brand-new project does not have. Runpnpm-lock.yamlonce first to generate the lockfile, then the loop works. (An interactive terminal creates it for you.)pnpm install - First fails with
caffeine check. The stable-signature check needs the last deployed snapshot, which a never-deployed project lacks. SeedDeployed file not found: …/backend.mostwith an empty actor (shown under the.old/src/backend/dist/backend.mostabove).mops.tomldoes not create it.caffeine build - fails with
caffeine preview --build. Uploading a draft needs a cloud project. RunNo project.id in caffeine.tomlto get an id, set it incaffeine projects create(or pass[project] id), then preview.--project-id <id>alone needs no id and is enough to verify the app compiles.caffeine build - . Only one migration can be pending at a time, and on a never-deployed project
too many pending migrations for check-limit=1already is. Fold the new state into that pending file instead of adding another.00000000_000000.mo - lint error, or
include-authorization"stable variableM0169… cannot be implicitly discarded".accessControlStatedroppedmain.moor itsMixinAuthorizationfield while the package and the first migration still provide them. Keep the startingaccessControlStatelines, or remove authorization completely as themain.moskill describes.extension-authorization
- 根 中缺少
caffeine.toml。 缺少该部分时,根文件会被解析为 canister 清单,CLI 无法找到你的 canister。根清单由[workspace]的存在来定义,而不是由其位于顶层来定义。[workspace] - 重命名 backend canister。 它必须命名为 ——
backend声明mops.toml,而根[canisters.backend]script 会读取bindgen。重命名会破坏构建及生成的 client。./src/backend/dist/backend.did - 手动编写或编辑 或
src/frontend/src/backend.ts。 这些文件由declarations/生成,并会在每次构建时被覆盖。请在caffeine-bindgen中添加后端方法,然后重新构建,client 会自动重新生成。生成文件的头部注明“You should NOT make any changes in this file”;它也会被 Biome 排除。main.mo - 首次构建前导入 。 绑定模块由构建中的
./backend步骤创建。在依赖pnpm bindgen之前,至少运行一次import { createActor } from "./backend"(或caffeine preview --build)。caffeine build - 尝试执行 或期待存在
dfx deploy。 Caffeine 应用通过caffeine deployCLI 构建,并通过 Web 应用上线。工作流中没有caffeine,也没有 CLI deploy/publish 命令。dfx - 遗漏必需的 设置。 请保留单个
mops.toml、[canisters.backend]、[canisters.backend.check-stable],以及[build] outputDir版本固定项(没有固定版本,mops 无法编译)。[toolchain] moc - 删除 或
.old/,或者跳过env.json。copy:env保存.old/用于比较的稳定签名快照;check-stable必须复制到env.json,这样托管的前端才能读取运行时配置。dist/ - 未使用 skill 就编写 Motoko。 现代 Caffeine Motoko 使用
writing-motoko、persistent actor 和特定模式。凭空猜测会产生编译错误。请先加载 https://skills.internetcomputer.org/skills/writing-motoko/SKILL.md。mo:core - 使用 /
npm而不是yarn。 该 workspace 基于 pnpm(pnpm、pnpm-workspace.yamlscripts)。pnpm -r使用 pnpm + mops。caffeine install - 在全新项目上,/
caffeine install因build而失败。 在非交互式 shell(Agent、CI 或任何没有 TTY 的运行)中,这些命令会执行ERR_PNPM_NO_LOCKFILE,而该命令要求存在pnpm install --frozen-lockfile,但全新项目并不具备该文件。请先运行一次pnpm-lock.yaml生成 lockfile,之后构建循环即可正常工作。(交互式终端会自动创建它。)pnpm install - 首次执行 时因
caffeine check而失败。 稳定签名检查需要上一次部署的快照,而从未部署过的项目缺少该快照。请按照Deployed file not found: …/backend.most部分所示,使用空 actor 初始化mops.toml。.old/src/backend/dist/backend.most不会创建该文件。caffeine build - 因
caffeine preview --build而失败。 上传 draft 需要云项目。请运行No project.id in caffeine.toml获取 id,将其设置在caffeine projects create中(或传入[project] id),然后执行 preview。单独执行--project-id <id>不需要 id,并且足以验证应用能否编译。caffeine build - 。 同一时间只能存在一个待部署迁移,而在从未部署过的项目中,
too many pending migrations for check-limit=1已经是待部署迁移。应将新状态合并到该待部署文件中,而不是再添加一个文件。00000000_000000.mo - 出现 lint 错误,或 M0169“stable variable
include-authorization… cannot be implicitly discarded”。accessControlState删除了main.mo或其MixinAuthorization字段,但包和首次迁移仍提供这些内容。请保留起始accessControlState中的相关行,或者按照main.moskill 的说明完整移除授权功能。extension-authorization
Related skills
相关 skills
- — REQUIRED companion. Authoritative for all backend Motoko code: https://skills.internetcomputer.org/skills/writing-motoko/SKILL.md. Always load it before editing
writing-motoko.src/backend/main.mo - — load before changing the actor's stable state: how to write and fold migrations in
migrating-motoko-actors. https://github.com/caffeinelabs/skills/tree/main/skills/migrating-motoko-actorssrc/backend/migrations/ - —
extension-core-infrastructure,InternetIdentityProvider, anduseInternetIdentityon the frontend. https://github.com/caffeinelabs/skills/tree/main/skills/extension-core-infrastructureuseActor - — roles, guards, user profiles, and the sign-in screen built on
extension-authorization. https://github.com/caffeinelabs/skills/tree/main/skills/extension-authorizationcaffeineai-authorization - — mops commands:
mops-cli,mops add, toolchain pins. https://github.com/caffeinelabs/skills/tree/main/skills/mops-climops check - — moving a cloned moc 1 project to moc 2. https://github.com/caffeinelabs/skills/tree/main/skills/migrating-to-moc-2
migrating-to-moc-2 - — for raw Internet Computer /
icp-cli/dfxprojects. Not used by Caffeine; reach for it only when the user is not building a Caffeine app.icp
- ——必需的配套 skill,是所有后端 Motoko 代码的权威依据: https://skills.internetcomputer.org/skills/writing-motoko/SKILL.md。编辑
writing-motoko前务必先加载它。src/backend/main.mo - ——修改 actor 的稳定状态前加载,用于了解如何在
migrating-motoko-actors中编写和合并迁移。 https://github.com/caffeinelabs/skills/tree/main/skills/migrating-motoko-actorssrc/backend/migrations/ - ——前端中的
extension-core-infrastructure、InternetIdentityProvider和useInternetIdentity。 https://github.com/caffeinelabs/skills/tree/main/skills/extension-core-infrastructureuseActor - ——角色、权限守卫、用户资料,以及基于
extension-authorization的登录界面。 https://github.com/caffeinelabs/skills/tree/main/skills/extension-authorizationcaffeineai-authorization - ——mops 命令,如
mops-cli、mops add和 toolchain 版本固定。 https://github.com/caffeinelabs/skills/tree/main/skills/mops-climops check - ——将克隆的 moc 1 项目迁移到 moc 2。 https://github.com/caffeinelabs/skills/tree/main/skills/migrating-to-moc-2
migrating-to-moc-2 - ——用于原生 Internet Computer /
icp-cli/dfx项目。Caffeine 不使用此 skill;仅当用户不是在构建 Caffeine 应用时使用它。icp
Additional references
补充参考
- — the full, verbatim frontend boilerplate (
references/frontend-template.md,package.json, Tailwind/PostCSS/Biome configs,vite.config.js,tsconfig.json,index.html,env.json, a startermain.tsx, and the backend-actor wiring pattern). Read it when you createApp.tsx.src/frontend/
- ——完整且逐字保留的前端 boilerplate(
references/frontend-template.md、package.json、Tailwind/PostCSS/Biome 配置、vite.config.js、tsconfig.json、index.html、env.json、初始main.tsx,以及 backend actor 接入模式)。创建App.tsx时请阅读该文件。src/frontend/