cargo-cdk
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCargo CDK — declarative workspace-as-code
Cargo CDK — 声明式工作区即代码
Use this skill to define a Cargo workspace in TypeScript ( builders from
) and reconcile it to live infrastructure with .
It is the declarative counterpart to the imperative capability skills: instead
of running one CLI command per resource, you write the whole graph once and deploy
it repeatably, with a committed linking your code to what Cargo
created.
define*@cargo-ai/cdkcargo-ai cdk deploycargo.state.json使用此技能在TypeScript中定义Cargo工作区(来自的构建器),并通过将其与实时基础设施同步。它是命令式功能技能的声明式替代方案:无需为每个资源运行一条CLI命令,只需编写一次完整的资源关系图,即可重复部署,同时通过已提交的将代码与Cargo创建的资源关联起来。
@cargo-ai/cdkdefine*cargo-ai cdk deploycargo.state.json1) What this skill governs
1) 本技能涵盖范围
- Authoring every Cargo resource with a builder that returns a handle; wiring resources by passing handles to each other (the dependency graph is your variable graph).
define* - Deploying the graph: (offline diff) →
plan(create/update, write state) →deploy(tear down). Plus drift (destroy), adoption (refresh), and recovery (import).rollback - Typing the config against your workspace's real integration schemas
().
cargo-ai cdk types
The CDK spans every resource kind — so it overlaps every imperative capability
skill (, , , ,
, , …). Which to reach for is the first decision:
cargo-connectioncargo-storagecargo-aicargo-orchestrationcargo-contentcargo-hosting- 编写所有Cargo资源:使用构建器创建资源并返回句柄;通过传递句柄来连接资源(依赖关系图即变量关系图)。
define* - 部署资源关系图:(离线差异对比)→
plan(创建/更新,写入状态)→deploy(销毁资源)。此外还包括漂移检测(destroy)、资源纳入管理(refresh)和回滚(import)功能。rollback - 类型校验:针对工作区的实际集成架构对配置进行类型校验()。
cargo-ai cdk types
CDK覆盖所有资源类型——因此它与所有命令式功能技能(、、、、、……)存在重叠。首先需要决定使用哪一种:
cargo-connectioncargo-storagecargo-aicargo-orchestrationcargo-contentcargo-hosting2) CDK or the CLI? — the routing decision
2) 选择CDK还是CLI?——路由决策
Declarative (this skill) vs imperative (a capability skill).
Use the CDK when the user is managing resources as an artifact:
- "Set up / stand up / bootstrap a whole workspace (as code / from a template)."
- "Make this reproducible / version-controlled / in git / repeatable across environments (dev → prod)."
- "Deploy these connectors + models + agents together" (a multi-resource graph wired by dependency).
- Anything that should be re-runnable and diffable, where losing the definition would be a problem.
Use the matching capability skill (imperative ) when the
user is doing a one-off operation or exploring:
cargo-ai <domain>- "Create one connector", "add a column to this model", "list connectors", "run this workflow", "query storage", "read this agent's memory."
- Any read, ad-hoc query, or single mutation that doesn't need to live in code.
When unsure, ask whether the result should be committed and re-deployable. If yes
→ CDK. If it's a quick action or a read → the capability skill (see the
router to pick the right domain).
cargo声明式(本技能) vs 命令式(功能技能)
当用户将资源作为工件进行管理时,使用CDK:
- "搭建/启动整个工作区(以代码形式/基于模板)。"
- "实现可复现/版本控制/存入Git/跨环境重复部署(开发→生产)。"
- "同时部署这些连接器+模型+Agent"(通过依赖关系连接的多资源关系图)。
- 任何需要可重复运行、可差异对比的操作,丢失定义会造成问题的场景。
当用户执行一次性操作或探索性操作时,使用对应的功能技能(命令式):
cargo-ai <domain>- "创建一个连接器"、"为该模型添加一列"、"列出连接器"、"运行此工作流"、"查询存储"、"读取此Agent的内存"。
- 任何读取、临时查询或无需存入代码的单次修改操作。
若不确定,可询问用户结果是否需要提交并可重新部署。如果是→使用CDK。如果是快速操作或读取→使用功能技能(请查看路由选择合适的领域)。
cargo3) The lifecycle
3) 生命周期
cargo-ai cdk init <dir> scaffold a project from a template (blank | full)
│
cargo-ai cdk types generate per-workspace types for typed config (optional)
│
(author define* files) importing a .ts file IS registration — no manifest
│
cargo-ai cdk plan offline: compile the graph, diff against cargo.state.json
│
cargo-ai cdk deploy create/update resources in dependency order, write state
│
cargo-ai cdk destroy tear down resources recorded in stateSide branches: (read-only drift report) ·
(re-apply code over out-of-band edits) · (delete resources removed
from code) · (bind an existing live resource into
state) · (restore the pre-deploy state snapshot).
cargo-ai cdk refreshdeploy --refreshdeploy --prunecargo-ai cdk import <id> <uuid>cargo-ai cdk rollbackcargo-ai cdk init <dir> 从模板搭建项目(空白 | 完整)
│
cargo-ai cdk types 为工作区生成专属类型以实现类型化配置(可选)
│
(编写define*文件) 导入.ts文件即完成注册——无需清单文件
│
cargo-ai cdk plan 离线:编译资源关系图,与cargo.state.json对比差异
│
cargo-ai cdk deploy 按依赖顺序创建/更新资源,写入状态
│
cargo-ai cdk destroy 销毁状态记录中的资源分支操作:(只读漂移报告)· (在外部编辑之上重新应用代码)· (删除代码中移除的资源)· (将现有实时资源绑定到状态中)· (恢复部署前的状态快照)。
cargo-ai cdk refreshdeploy --refreshdeploy --prunecargo-ai cdk import <id> <uuid>cargo-ai cdk rollback4) Documentation hierarchy
4) 文档层级
- Level 1 — (this file): the decision model, lifecycle, critical rules, and routing.
SKILL.md - Level 2 — Guides:
,
guides/authoring-resources.md,guides/deploy-and-state.md.guides/typed-config.md - Level 2.5 — Recipes: — step-by-step playbooks to follow as your execution plan.
recipes/*.md - References — (the full builder catalog),
references/resources.md(everyreferences/commands.mdsubcommand + flags),cargo-ai cdk, andreferences/troubleshooting.md.references/examples/full-workspace.md
- 第1级 — (本文档):决策模型、生命周期、关键规则和路由逻辑。
SKILL.md - 第2级 — 指南:
、
guides/authoring-resources.md、guides/deploy-and-state.md。guides/typed-config.md - 第2.5级 — 操作手册:—— 分步执行手册,可作为执行计划。
recipes/*.md - 参考文档 — (完整构建器目录)、
references/resources.md(所有references/commands.md子命令+参数)、cargo-ai cdk,以及references/troubleshooting.md。references/examples/full-workspace.md
5) Read behavior — match the task to a doc and READ IT
5) 阅读策略 — 根据任务匹配文档并阅读
| When the task involves… | Read this first | What it gives you |
|---|---|---|
Writing | | The builder catalog, the handle/ref model, secrets, and how workflow bodies compile. |
| | The deploy lifecycle, |
Typed config, | | What |
| A field/spec/output for a specific builder | | Every builder → spec fields → which ref each takes → outputs. |
| Exact command flags | | Every |
| A deploy error / footgun | | The known failure modes and fixes. |
| 当任务涉及… | 首先阅读 | 能获得什么 |
|---|---|---|
编写 | | 构建器目录、句柄/引用模型、密钥管理,以及工作流主体的编译方式。 |
| | 部署生命周期、 |
类型化配置、 | | |
| 特定构建器的字段/规范/输出 | | 每个构建器→规范字段→接受的引用类型→输出内容。 |
| 精确的命令参数 | | 所有 |
| 部署错误/陷阱 | | 已知故障模式及修复方案。 |
Recipes — follow step-by-step when one matches
操作手册 — 当有匹配场景时按步骤执行
| Recipe | Use when… |
|---|---|
| Standing up a new workspace from scratch ( |
| Adding a data source + a model sourced from it, wired by handle. |
| Composing a model + tool + agent (with |
| Bringing an already-live workspace under CDK management via |
| Deploying non-interactively from CI (token auth + committed state). |
| 操作手册 | 适用场景… |
|---|---|
| 从头搭建新工作区( |
| 添加数据源+基于该数据源的模型,通过句柄连接。 |
| 组合模型+工具+Agent(通过 |
| 通过 |
| 从CI非交互式部署(令牌认证+已提交的状态)。 |
6) Critical rules
6) 关键规则
- Commit . It is the link from your code to the resources Cargo created — and the only handle on a deployed play or agent (they have no slug). Lose it and those resources orphan; recover a link with
cargo.state.json. It records onlycargo-ai cdk import— never secret values. Git-ignore the working files ({hash, uuid, outputs}scaffolds this):cdk initgitignore.cargo-ai/ cargo.state.lock cargo.state.bak.json cargo.state.audit.jsonl - Secrets: wire credentials with (often
secret("ENV_VAR")). The value is read from the environment at deploy time, kept out of the content hash and out of state, so rotating a token doesn't read as drift. Export the env var before deploying — a missing one fails the deploy with an unresolvedsecret("HUBSPOT_API_KEY")placeholder.${ENV_VAR} - Wire by handle, never by . Pass a
.uuidhandle directly (define*,dataset: hubspot), ortools: [enrich]for a resource you didn't define in code (xxRef("uuid"),connectorRef,modelRef,folderRef,toolRef, …). Where a reference needs per-call options, wrap it asagentRef(e.g.{ ref, …options }).models: [{ ref: contacts, readOnly: true }] - Run after workspace integrations change — it regenerates
cargo-ai cdk typesso.cargo-ai//defineConnectorconfig (anddefineModelin workflow bodies) type-check against the real schemas. Typing is a bonus, never a gate: deploy works without it.integrations.* - Run commands from the project root.
cdk/npxresolve from the nearestcargo-ai; run elsewhere andpackage.jsonand.cargo-ai/land in the wrong directory. Usecargo.state.jsonto be explicit.--dir <path> - in CI.
--yesanddeployprompt for confirmation; non-interactive runs must passdestroy.--yes
- 提交。它是代码与Cargo创建的资源之间的链接——也是已部署剧本或Agent的唯一句柄(它们没有别名)。丢失该文件会导致这些资源成为孤立资源;可通过
cargo.state.json恢复链接。它仅记录cargo-ai cdk import——绝不会存储密钥值。将工作文件加入Git忽略({hash, uuid, outputs}会自动生成该配置):cdk initgitignore.cargo-ai/ cargo.state.lock cargo.state.bak.json cargo.state.audit.jsonl - 密钥管理:使用(通常为
secret("ENV_VAR"))连接凭证。值会在部署时从环境变量读取,不会纳入内容哈希或状态,因此令牌轮换不会被识别为漂移。部署前需导出环境变量——缺失环境变量会导致部署失败,并提示未解析的secret("HUBSPOT_API_KEY")占位符。${ENV_VAR} - 通过句柄连接,绝不要使用。直接传递
.uuid句柄(define*、dataset: hubspot),或对未在代码中定义的资源使用tools: [enrich](xxRef("uuid")、connectorRef、modelRef、folderRef、toolRef……)。当引用需要每次调用的选项时,将其包装为agentRef(例如{ ref, …options })。models: [{ ref: contacts, readOnly: true }] - 工作区集成变更后运行——它会重新生成
cargo-ai cdk types,使.cargo-ai//defineConnector配置(以及工作流主体中的defineModel)能针对实际架构进行类型校验。类型校验是附加功能,并非强制要求:即使不使用也可正常部署。integrations.* - 从项目根目录运行命令。
cdk/npx会从最近的cargo-ai解析;在其他目录运行会导致package.json和.cargo-ai/存放在错误位置。可使用cargo.state.json明确指定路径。--dir <path> - CI中使用。
--yes和deploy会提示确认;非交互式运行必须传入destroy。--yes
Prerequisites
前置条件
Standard Cargo CLI setup (install, login, output conventions) is shared across all
skills — see .
../cargo/references/prerequisites.mdTwo CDK-specific extras:
- The project needs as a dependency (for the
@cargo-ai/cdkbuilders you import).define*scaffolds acargo-ai cdk initwith it — then runpackage.json.npm install - The domain ships with the CLI. Confirm with
cargo-ai cdk; ancargo-ai cdk --helpmeans the CLI is too old —unknown command.npm install -g @cargo-ai/cli@latest
标准Cargo CLI设置(安装、登录、输出约定)为所有技能共享——请查看。
../cargo/references/prerequisites.mdCDK专属的两个额外条件:
- 项目需要作为依赖(用于导入
@cargo-ai/cdk构建器)。define*会生成包含该依赖的cargo-ai cdk init——之后运行package.json。npm install - 域随CLI一同发布。通过
cargo-ai cdk确认;若提示cargo-ai cdk --help则说明CLI版本过旧——运行unknown command更新。npm install -g @cargo-ai/cli@latest
Help
帮助
- and
cargo-ai cdk --helpfor the live flag surface.cargo-ai cdk <subcommand> --help - When a documented command/flag/response doesn't match what you observe, file a
report: (see
cargo-ai workspaceManagement report create).../cargo-workspace-management/SKILL.md
- 和
cargo-ai cdk --help可查看实时参数说明。cargo-ai cdk <subcommand> --help - 当文档中的命令/参数/响应与实际不符时,提交报告:(请查看
cargo-ai workspaceManagement report create)。../cargo-workspace-management/SKILL.md