cargo-segmentation
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCargo CLI — Segmentation
Cargo CLI — Segment 管理
Segments are the audience layer of a Cargo workspace: a named, saved filter over one model that answers "which records do I mean?" Everything downstream — a batch run, a play trigger, a CSV export, a change feed — takes a segment (or a segment-shaped filter) as its input.
Seefor full JSON response structures. Seereferences/response-shapes.mdfor common errors and how to fix them. Filter condition kinds and operators live inreferences/troubleshooting.md— the single source of truth for filter JSON.../cargo-orchestration/references/filter-syntax.md
Segment是Cargo工作区的受众层:它是针对单个模型的命名已保存筛选器,用于明确“我指的是哪些记录?”。所有下游操作——批量运行、Play触发器、CSV导出、变更推送——都以Segment(或Segment格式的筛选器)作为输入。
完整JSON响应结构请查看。 常见错误及修复方法请查看references/response-shapes.md。 筛选器条件类型和运算符定义在references/troubleshooting.md中——这是筛选器JSON的唯一权威来源。../cargo-orchestration/references/filter-syntax.md
Bootstrap
初始化
Already signed in ( returns a workspace)? Skip to the next section.
cargo-ai whoamibash
npm install -g @cargo-ai/cli # no global install? prefix every command with `npx @cargo-ai/cli`
cargo-ai login --email you@company.com # emailed code, no browser; creates the account on first use
# alternatives: --oauth (browser) · --token <api-token> (CI)
cargo-ai whoami # confirm the active workspace before any writeEvery command prints JSON to stdout; failures exit non-zero with . Anything that creates a run or a batch is async — pass or poll the matching . When the full skill bundle is installed, adds the CLI version pin, token scopes, and the admin-only surface.
{"errorMessage": "..."}--wait-until-finishedget../cargo/references/prerequisites.md已登录(返回工作区信息)?请跳至下一节。
cargo-ai whoamibash
npm install -g @cargo-ai/cli # 不想全局安装?在所有命令前添加前缀`npx @cargo-ai/cli`
cargo-ai login --email you@company.com # 通过邮件接收验证码,无需浏览器;首次使用会创建账号
# 其他登录方式:--oauth(浏览器授权)· --token <api-token>(CI环境)
cargo-ai whoami # 执行任何写入操作前,确认当前激活的工作区所有命令都会向标准输出打印JSON;执行失败时会以非零状态码退出,并返回。所有创建运行任务或批量任务的操作都是异步的——可添加参数等待完成,或轮询对应的命令。安装完整技能包后,会包含CLI版本固定、令牌权限范围以及管理员专属功能的说明。
{"errorMessage": "..."}--wait-until-finishedget../cargo/references/prerequisites.mdKey concepts
核心概念
| Term | What it is |
|---|---|
| Filter | A JSON object ( |
| Segment | A filter saved with a name, a |
| Change | One computed delta of a segment between two syncs — how many records were |
| Tracking columns | The subset of columns ( |
Filter vs segment — pick deliberately. A one-off question ("how many companies have >100 employees?") wants with an inline filter and no saved object. An audience you will run something against, schedule against, or track over time wants a real — because only a saved segment produces changes.
segment fetchsegment create| Term | 定义 |
|---|---|
| Filter | 一个JSON对象( |
| Segment | 已保存的筛选器,包含名称、 |
| Change | 两次同步之间Segment的计算差值——记录的 |
| Tracking columns | 列的子集(通过 |
筛选器与Segment的选择——需谨慎决策。一次性查询(如“员工数>100的公司有多少家?”)适合使用并传入内联筛选器,无需保存对象。若受众需用于执行任务、调度或长期跟踪,则需创建真正的——只有已保存的Segment才会产生变更记录。
segment fetchsegment createDiscover resources first
先发现已有资源
Always list before creating. A workspace usually already holds the segment you are about to duplicate.
bash
cargo-ai segmentation segment list # all segments (uuid, name, slug, modelUuid, recordsCount)
cargo-ai storage model list # find the modelUuid a segment must target
cargo-ai storage column list --model-uuid <uuid> # the column slugs your filter conditions referenceSegments created automatically by a play are named and carry — never edit or remove those by hand; they belong to the play that owns them.
GENERATED_PLAY_SEGMENTfromPlay: trueRetrieve in the UI: segments live under the model at . Get from .
app.getcargo.io/workspaces/<WORKSPACE_UUID>/models/<MODEL_UUID><WORKSPACE_UUID>cargo-ai whoami创建前务必先列出已有内容。工作区中通常已经存在你想要创建的同类Segment。
bash
cargo-ai segmentation segment list # 列出所有Segment(包含uuid、name、slug、modelUuid、recordsCount)
cargo-ai storage model list # 查找Segment必须关联的modelUuid
cargo-ai storage column list --model-uuid <uuid> # 筛选器条件引用的列slug由Play自动创建的Segment命名为,并带有标记——切勿手动编辑或删除此类Segment;它们属于创建它们的Play。
GENERATED_PLAY_SEGMENTfromPlay: true在UI中查看:Segment位于模型页面,地址为。可通过获取。
app.getcargo.io/workspaces/<WORKSPACE_UUID>/models/<MODEL_UUID>cargo-ai whoami<WORKSPACE_UUID>Quick reference
快速参考
bash
cargo-ai segmentation segment list
cargo-ai segmentation segment get <segment-uuid>
cargo-ai segmentation segment create --name "<name>" --model-uuid <uuid> --filter '<json>'
cargo-ai segmentation segment update --uuid <segment-uuid> --filter '<json>'
cargo-ai segmentation segment remove <segment-uuid>
cargo-ai segmentation segment fetch --model-uuid <uuid> --filter '<json>' --limit 50
cargo-ai segmentation segment download --model-uuid <uuid> --filter '<json>'
cargo-ai segmentation change list --segment-uuid <segment-uuid>
cargo-ai segmentation change fetch --uuid <change-uuid> --kinds added --limit 50
cargo-ai segmentation record fetch --model-uuid <uuid> --ids <id[,id…]>bash
cargo-ai segmentation segment list
cargo-ai segmentation segment get <segment-uuid>
cargo-ai segmentation segment create --name "<name>" --model-uuid <uuid> --filter '<json>'
cargo-ai segmentation segment update --uuid <segment-uuid> --filter '<json>'
cargo-ai segmentation segment remove <segment-uuid>
cargo-ai segmentation segment fetch --model-uuid <uuid> --filter '<json>' --limit 50
cargo-ai segmentation segment download --model-uuid <uuid> --filter '<json>'
cargo-ai segmentation change list --segment-uuid <segment-uuid>
cargo-ai segmentation change fetch --uuid <change-uuid> --kinds added --limit 50
cargo-ai segmentation record fetch --model-uuid <uuid> --ids <id[,id…]>Building a filter
构建筛选器
The full condition catalogue — every (, , , , , ) and every operator — is in . The shape:
kindstringnumberdatebooleanarrayrelation../cargo-orchestration/references/filter-syntax.mdjson
{
"conjonction": "and",
"groups": [
{
"conjonction": "and",
"conditions": [
{ "kind": "number", "columnSlug": "employee_count", "operator": "greaterThan", "value": 100 },
{ "kind": "string", "columnSlug": "email", "operator": "isNotEmpty" }
]
}
]
}, notconjonction. The French spelling is intentional and it is the single most expensive typo in the CLI: a misspelled key does not error — the filter silently matches nothing, and you conclude the data is empty. Grep your JSON forconjunctionbefore every call.conjunction
Match-everything filter: .
{"conjonction":"and","groups":[]}完整的条件目录——包括所有(、、、、、)和运算符——请查看。筛选器结构如下:
kindstringnumberdatebooleanarrayrelation../cargo-orchestration/references/filter-syntax.mdjson
{
"conjonction": "and",
"groups": [
{
"conjonction": "and",
"conditions": [
{ "kind": "number", "columnSlug": "employee_count", "operator": "greaterThan", "value": 100 },
{ "kind": "string", "columnSlug": "email", "operator": "isNotEmpty" }
]
}
]
}注意:是,而非conjonction。这是特意使用的法语拼写,也是CLI中代价最高的拼写错误:拼写错误不会触发报错——筛选器会静默匹配不到任何记录,你会误以为数据为空。每次调用前,请检查JSON中的拼写是否为conjunction。conjonction
匹配所有记录的筛选器:。
{"conjonction":"and","groups":[]}Size the audience before you build it
构建前先估算受众规模
Counting is free; running anything over an audience is not. Establish the size first, then decide.
bash
undefined计数是免费的;但针对受众执行操作会产生成本。先确认受众规模,再做决策。
bash
undefined1. How many records match? — inline filter, no saved object, 1 row back
1. 有多少条记录匹配?——使用内联筛选器,无需保存对象,返回1行结果
cargo-ai segmentation segment fetch
--model-uuid <uuid>
--filter '{"conjonction":"and","groups":[{"conjonction":"and","conditions":[ {"kind":"number","columnSlug":"employee_count","operator":"greaterThan","value":100}]}]}'
--limit 1
--model-uuid <uuid>
--filter '{"conjonction":"and","groups":[{"conjonction":"and","conditions":[ {"kind":"number","columnSlug":"employee_count","operator":"greaterThan","value":100}]}]}'
--limit 1
cargo-ai segmentation segment fetch
--model-uuid <uuid>
--filter '{"conjonction":"and","groups":[{"conjonction":"and","conditions":[ {"kind":"number","columnSlug":"employee_count","operator":"greaterThan","value":100}]}]}'
--limit 1
--model-uuid <uuid>
--filter '{"conjonction":"and","groups":[{"conjonction":"and","conditions":[ {"kind":"number","columnSlug":"employee_count","operator":"greaterThan","value":100}]}]}'
--limit 1
2. Happy with the shape? Save it as the real audience.
2. 对结果满意?将其保存为正式受众。
cargo-ai segmentation segment create
--name "Mid-market accounts"
--model-uuid <uuid>
--filter '<same json>'
--column-slugs "name,domain,employee_count"
--tracking-column-slugs "employee_count,funding_stage"
--name "Mid-market accounts"
--model-uuid <uuid>
--filter '<same json>'
--column-slugs "name,domain,employee_count"
--tracking-column-slugs "employee_count,funding_stage"
`segment get <uuid>` then reports `recordsCount` — the authoritative size. Cite that number, not your own estimate, before proposing a paid run over the segment.cargo-ai segmentation segment create
--name "Mid-market accounts"
--model-uuid <uuid>
--filter '<same json>'
--column-slugs "name,domain,employee_count"
--tracking-column-slugs "employee_count,funding_stage"
--name "Mid-market accounts"
--model-uuid <uuid>
--filter '<same json>'
--column-slugs "name,domain,employee_count"
--tracking-column-slugs "employee_count,funding_stage"
执行`segment get <uuid>`后会返回`recordsCount`——这是权威的受众规模。在提议针对该Segment执行付费任务前,请引用此数值,而非自行估算。Fetch vs download vs record fetch
Fetch、Download与Record Fetch的区别
| Command | Returns | Use for |
|---|---|---|
| Records inline as JSON, paginated ( | Inspecting a handful of rows, counting, previewing a filter before saving it |
| A signed URL to the full dataset | Handing the whole audience to the user or another tool — see |
| Specific records by id | Re-reading rows a change feed just told you about |
segment fetch --sync--enrichNever page a large segment into the conversation. Use to see the shape, then for the rest.
--limit 3download| 命令 | 返回内容 | 使用场景 |
|---|---|---|
| 以JSON格式返回分页记录(可通过 | 检查少量数据行、计数、保存前预览筛选器效果 |
| 完整数据集的签名URL | 将整个受众数据交付给用户或其他工具——请查看 |
| 指定ID的具体记录 | 重新读取变更推送刚通知的行数据 |
segment fetch --sync--enrich切勿对大型Segment进行分页查询。使用查看数据结构,然后使用获取完整数据。
--limit 3downloadChanges — the delta feed
变更记录——差值推送
Every time a segment syncs, Cargo computes a change: how the membership moved. This is what turns a static list into a signal.
bash
undefined每次Segment同步时,Cargo都会计算变更记录:受众成员的变化情况。这是将静态列表转化为信号的核心。
bash
undefinedWhat deltas exist for this segment?
该Segment有哪些差值记录?
cargo-ai segmentation change list --segment-uuid <segment-uuid>
cargo-ai segmentation change list --segment-uuid <segment-uuid>
→ { "changes": [ { "uuid", "totalRecordsCount", "addedRecordsCount",
→ { "changes": [ { "uuid", "totalRecordsCount", "addedRecordsCount",
"updatedRecordsCount", "removedRecordsCount",
"updatedRecordsCount", "removedRecordsCount",
"unchangedRecordsCount", "createdAt" } ] }
"unchangedRecordsCount", "createdAt" } ] }
Which records actually entered the audience in that delta?
该差值中哪些记录新增到了受众中?
cargo-ai segmentation change fetch --uuid <change-uuid> --kinds added --limit 50
`--kinds` is **required** on `change fetch` and takes `added`, `updated`, `removed`, or `unchanged` (comma-separated). Returned rows carry the `_kind`, `_id`, `_title`, and `_time` meta-columns alongside the model's own columns.
`updatedRecordsCount` is always `0` unless the segment was created with `--tracking-column-slugs` — the tracked columns define what "updated" means. Set them at creation time when the segment is meant to feed a monitoring motion.
A segment's most recent delta is also inlined on `segment list` / `segment get` as `lastChange`, so a "what moved?" question rarely needs a second call.cargo-ai segmentation change fetch --uuid <change-uuid> --kinds added --limit 50
`change fetch`必须指定`--kinds`参数,可选值为`added`、`updated`、`removed`或`unchanged`(可逗号分隔多个值)。返回的行数据除了模型自身的列外,还包含`_kind`、`_id`、`_title`和`_time`元列。
除非创建Segment时指定了`--tracking-column-slugs`,否则`updatedRecordsCount`始终为0——跟踪列定义了“更新”的含义。若Segment用于监控场景,请在创建时设置跟踪列。
Segment的最新差值记录也会内嵌在`segment list`/`segment get`的`lastChange`字段中,因此“有哪些变化?”这类问题通常无需额外调用。What consumes a segment
Segment的使用场景
Segments are an input, not an outcome. Once one exists:
- Run something over it — batch a connector action or workflow across every member: . Batches enroll from a segment; sample 10–20 records and get explicit approval before enrolling the full audience.
../cargo-orchestration/SKILL.md - Trigger a play on entry — a play whose trigger is a segment fires as records enter it. Play triggers use and generate their own
kind: "filter"; seeGENERATED_PLAY_SEGMENT.../cargo-orchestration/references/examples/plays.md - Export it — (
../cargo-analytics/SKILL.mdneedssegment download, not--model-uuid— a frequent 400).--segment-uuid - Watch it — alert when the audience empties, stalls, or spikes: .
../cargo-observability/SKILL.md - Act on it as GTM — signal segments (job change, funding, tech intent) drive the recipes in .
../cargo-gtm/SKILL.md - Declare it as code — in
defineSegmentwhen the audience should live in git.../cargo-cdk/SKILL.md
Segment是输入,而非输出。创建完成后可用于:
- 针对受众执行任务——为每个成员批量执行连接器操作或工作流:。批量任务从Segment获取受众;执行全量任务前,请先抽样10-20条记录并获得明确批准。
../cargo-orchestration/SKILL.md - 进入受众时触发Play——以Segment为触发器的Play会在记录进入受众时触发。Play触发器使用,并会生成自己的
kind: "filter";请查看GENERATED_PLAY_SEGMENT。../cargo-orchestration/references/examples/plays.md - 导出受众数据——(
../cargo-analytics/SKILL.md需要segment download,而非--model-uuid——这是常见的400错误原因)。--segment-uuid - 监控受众——当受众为空、停滞或激增时发送警报:。
../cargo-observability/SKILL.md - 作为GTM信号——信号类Segment(职位变动、融资、技术意向)驱动中的方案。
../cargo-gtm/SKILL.md - 以代码声明受众——若受众需存储在git中,请使用中的
../cargo-cdk/SKILL.md。defineSegment
Gotchas
常见陷阱
- , never
conjonction— silent empty result, no error.conjunction - takes
segment download, not--model-uuid. The filter travels with the request; the segment UUID is not a valid input there.--segment-uuid - needs
change fetch(the change UUID) plus--uuid. Passing the segment UUID returns a 400.--kinds - needs
change list. Calling it bare returns a 400 complaining that--segment-uuidis undefined.segmentUuid - on
--helpandchangesubcommands prints the parent help rather than the subcommand's flags (CLI ≥ 1.0.48). Use the Quick reference above; file a report if it still bites.record - A segment belongs to exactly one model. Cross-model audiences are a relationship + filter on the joined column, not two segments.
- segments are owned by a play. Editing one changes what that play targets; removing one breaks it.
fromPlay: true - on a segment caps membership, it is not a display page size —
--limitis the page size.--fetching-limit
- 必须使用,而非
conjonction——拼写错误会导致静默匹配不到任何记录,无报错信息。conjunction - 需要
segment download,而非--model-uuid。筛选器随请求传递,Segment UUID不是有效的输入参数。--segment-uuid - 需要
change fetch(指变更记录的UUID)和--uuid参数。传入Segment UUID会返回400错误。--kinds - 需要
change list参数。直接调用会返回400错误,提示--segment-uuid未定义。segmentUuid - 和
change子命令的record会打印父命令的帮助信息,而非子命令的参数说明(CLI ≥ 1.0.48)。请参考上方的快速参考;若问题仍存在,请提交反馈。--help - 一个Segment仅属于一个模型。跨模型受众需通过关联关系+关联列的筛选器实现,而非两个Segment。
- 的Segment属于对应的Play。编辑此类Segment会改变Play的目标受众;删除则会导致Play失效。
fromPlay: true - Segment的参数是限制受众成员数量,而非显示分页大小——
--limit才是分页大小。--fetching-limit
When the CLI fails
CLI执行失败时的处理
Two failed attempts on the same command, or behavior that contradicts this skill, goes to the team:
bash
cargo-ai workspaceManagement report create \
--title "<one-line summary>" \
--description "<commands run, errorMessage verbatim, expected vs actual, UUIDs>"同一命令连续两次失败,或行为与本文档描述不符,请提交反馈:
bash
cargo-ai workspaceManagement report create \
--title "<一行摘要>" \
--description "<执行的命令、完整errorMessage、预期与实际结果、相关UUID>"