Skip to content

Commit 8dbb4a1

Browse files
feat(example-crm): business vocabulary on crm_opportunity_metrics (ADR-0149 D1) (#31771)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi94CosmCy4wibc3rRg4ppMsN)_ Fixes #31591 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:给示例 CRM 的商机指标数据集(crm_opportunity_metrics)的 3 个维度和 3 个指标都写上业务定义(description)和用户常用说法(synonyms,中英混排,29 个),并补了中文翻译;hotcrm 的九个数据集另立了卡 objectstack-ai/hotcrm#2425。 - 为什么改:ADR-0149 要求 AI 通过数据集语义层回答业务问题,这是第一份真实词汇数据,也是 D5 问数准确率评测的「改前/改后」基线。 - 风险与回滚:只改示例元数据与它的测试,不发布任何包;回滚即还原这三个文件。 - 先看:`examples/app-crm/src/datasets/opportunity.dataset.ts`(总金额的定义:含在途、赢单、输单,既不是在途漏斗也不是已确认收入)、`examples/app-crm/src/translations/crm.translation.ts`、`examples/app-crm/test/smoke.test.ts`。 - 两分钟验证:`pnpm --filter @objectstack/example-crm exec vitest run test/smoke.test.ts`,预期 24 个用例全绿。 - 需要你做的:无,席位落地。 ## What changes - `crm_opportunity_metrics`: every member (dimensions `stage`, `account`, `close_date`; measures `opp_count`, `total_amount`, `avg_amount`) gains a `description` written as a plain business definition (what it counts, what it excludes; ADR-0149 M1 ruled A, no model instructions) and `synonyms` a business user would type, English and Chinese in the one list (D1: synonyms are match input, never locale-keyed). Near-duplicates of the label were left out (no "total amount", "average deal size", "opportunities"). - Deliberate choice: a synonym that names a narrower meaning than the measure is a defect, not a style point (these are D5's first data). `total_amount` sums open, won and lost deals alike, so it carries no "revenue" / 「营收」 synonym and no "pipeline value" / 「漏斗金额」 synonym (in sales usage both mean a subset: won deals, open deals). Its description says it is neither the open pipeline nor booked revenue, and how to narrow it to each. `avg_amount` averages every stage, so it carries no 「平均成交额」 (成交 reads as won deals). - zh-CN bundle: the spec card (#31587) made member `description` translatable at `datasets.NAME.{dimensions,measures}.MEMBER.description` (display text, like `label`) and gave `synonyms` no bundle key. Following that rule, each member description has its zh-CN translation; no synonym key was invented. The `en` block of this bundle has no `datasets` section today (the source metadata is English), so none was added. - hotcrm half: filed as objectstack-ai/hotcrm#2425 through the relay (`issue-create.mjs`) with the same rules. Code search on hotcrm's default branch finds **nine** dataset files, not the eight the card names (`account_metrics`, `contact_metrics`, `event_metrics`, `forecast_metrics`, `lead_metrics`, `opportunity_metrics`, `task_metrics`, `case_metrics`, `product_metrics`); the card asks hotcrm's lane to confirm scope. ### D5 baseline (before / after, this dataset) | | members | members with description | synonyms | |---|---|---|---| | before (`0105a687`) | 6 (3 dimensions, 3 measures) | 0 | 0 | | after | 6 | 6 (+ 6 zh-CN translations) | 29 (stage 6, account 6, close_date 5, opp_count 5, total_amount 4, avg_amount 3) | No member is left without synonyms. ## Tests New top-level `describe` in `examples/app-crm/test/smoke.test.ts` (the example's shared harness file), read on the composed stack: - the dataset passes `DatasetSchema.safeParse`, vocabulary `superRefine` included; - every dimension and measure has a non-empty `description` and at least one synonym (member roster pinned); - every member description has a non-empty zh-CN translation that is not the English text echoed. No existing test was edited. Ablation (`scripts/ablation-replace.mjs`, each leg restored to blob == HEAD, `git diff HEAD` empty; example source runs under vitest directly, no dist leg): - `stage` synonym `'sales stage'` → `'customer'` (collides with `account`'s synonym): the stack's own load refuses — file collection fails with `datasets.0.dimensions.1.synonyms.0: synonym "customer" of dimension "account" is also a synonym of dimension "stage" in this dataset …` (the composed stack parses before any `it` runs, so the refusal arrives one layer earlier than the new parse pin). - delete `avg_amount`'s zh-CN `description`: `× translates every member description into zh-CN` — `AssertionError: avg_amount: expected false to be true`. - delete `avg_amount`'s `synonyms`: `× gives every dimension and measure a description and at least one synonym` — `AssertionError: avg_amount: expected 0 to be greater than 0`. ## Acceptance notes - Changeset: none, `skip-changeset`. `@objectstack/example-crm` is `private: true`; `.changeset/config.json` versions private packages (`privatePackages.version: true`) but the package publishes nothing, and its CHANGELOG has only ever carried dependency bumps. AGENTS.md reserves a changeset for a diff that publishes. - Note for a later card, not changed here: `avg_amount`'s existing zh-CN label 「平均成交额」 reads as "average won-deal amount" while the measure averages every stage (open, won, lost). The label is out of this card's scope; a later card could relabel it 「平均商机金额」. - The term matcher that reads `synonyms` (ADR-0149 D7 card 2, service-analytics) has not landed; until it does these keys are declared data with ledger rows `planned`, as D6 states. ## Verification Head `2d04c9f8` (seat fix round 1 on top of `f17fabe3`: dropped three synonyms, reworded `total_amount`'s description in en and zh-CN; `f17fabe3` merged `origin/main`, touching no `examples/` or `packages/spec` file). <details><summary>example-crm test + typecheck (lock VERDICT command-exit 0)</summary> `pnpm --filter @objectstack/example-crm test && pnpm --filter @objectstack/example-crm typecheck` on `2d04c9f8` (closure built on `f17fabe3`; the fix round touched only example source): Test Files 7 passed (7), Tests 51 passed (51), typecheck no errors. </details> <details><summary>derived gates</summary> On `2d04c9f8`, `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` derived 40 families; all 40 run, every one exit 0 (`--ran` reconciliation: 40 run, 0 NOT-MEASURED, 0 UNRUN). ``` node scripts/check-closing-keyword-parity.mjs :: exit 0 node scripts/check-closing-keyword-parity.mjs --self-test :: exit 0 node scripts/check-comment-mask-adoption.mjs :: exit 0 node scripts/check-comment-mask-adoption.mjs --self-test :: exit 0 node scripts/check-comment-mask-corpus.mjs :: exit 0 node scripts/check-dts-emitted.mjs --self-test :: exit 0 node scripts/ci/assert-turbo-remote-cache.mjs --self-test :: exit 0 node scripts/ci/plan-test-core-shards.mjs --self-test :: exit 0 node scripts/ci/prune-turbo-cache.mjs --self-test :: exit 0 pnpm --filter @objectstack/spec run check:duration-unit-keys :: exit 0 pnpm check:ci-filter-parity :: exit 0 pnpm check:cross-package-test-inputs :: exit 0 pnpm check:driver-memory-census :: exit 0 pnpm check:dts-closure :: exit 0 pnpm check:dual-build-cjs-loads :: exit 0 pnpm check:engine-double-contract :: exit 0 pnpm check:examples-live-imports :: exit 0 pnpm check:gitlink-declared :: exit 0 pnpm check:i18n-coverage :: exit 0 pnpm check:keyed-text-bounds :: exit 0 pnpm check:lean-entry-closure :: exit 0 pnpm check:logger-receiver-detach :: exit 0 pnpm check:nul-bytes :: exit 0 pnpm check:org-identifier :: exit 0 pnpm check:page-declaration-shape :: exit 0 pnpm check:published-files :: exit 0 pnpm check:query-options-erasure :: exit 0 pnpm check:refd-timer-probe :: exit 0 pnpm check:registry-log-declared :: exit 0 pnpm check:rest-log-spy-declared :: exit 0 pnpm check:sourcemap-no-sources-content :: exit 0 pnpm check:system-context-census :: exit 0 pnpm check:test-source-alias :: exit 0 pnpm check:tier-file-adoption :: exit 0 pnpm check:type-check-coverage :: exit 0 pnpm check:type-check-debt :: exit 0 pnpm check:undeclared-dep-imports :: exit 0 pnpm check:vouch-for-reference-callers :: exit 0 pnpm check:watch-hint-literal :: exit 0 pnpm check:where-matcher :: exit 0 ``` </details> <details><summary>lint</summary> `pnpm exec eslint --no-inline-config` on the three changed files: exit 0. </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01ADHkmQaUC9ShR9MNZLdNV4 <!-- signed: domain:server#2 · os-steve · session_01ADHkmQaUC9ShR9MNZLdNV4 --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 7931f81 commit 8dbb4a1

3 files changed

Lines changed: 136 additions & 12 deletions

File tree

‎examples/app-crm/src/datasets/opportunity.dataset.ts‎

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,85 @@ export const OpportunityDataset = defineDataset({
1616
description: 'Semantic layer for sales-pipeline counts and amounts',
1717
object: 'crm_opportunity',
1818

19+
// ADR-0149 D1 business vocabulary. `synonyms` are the words a person types in
20+
// a question, every language in the one list (they are matched, never drawn,
21+
// and never translated); `description` is a plain business definition of the
22+
// member, not an instruction to a model (M1, ruled A), and IS translated at
23+
// `datasets.crm_opportunity_metrics.{dimensions,measures}.<member>.description`.
1924
dimensions: [
20-
{ name: 'stage', label: 'Stage', field: 'stage', type: 'string' },
25+
{
26+
name: 'stage',
27+
label: 'Stage',
28+
field: 'stage',
29+
type: 'string',
30+
description:
31+
'Where the opportunity stands in the sales process: Prospecting, Qualification, Proposal, '
32+
+ 'Closed Won or Closed Lost. The first three are the open pipeline; the last two are finished deals.',
33+
synonyms: ['sales stage', 'deal stage', 'pipeline stage', '销售阶段', '商机阶段', '漏斗阶段'],
34+
},
2135
// Lookup dimension — the analytics layer resolves the account FK to its
2236
// display name in `rows`, but exposes the raw FK via drillRawRows so a
2337
// report drill filters by the stored id (ADR-0021 D2), not the name.
24-
{ name: 'account', label: 'Account', field: 'account', type: 'lookup' },
38+
{
39+
name: 'account',
40+
label: 'Account',
41+
field: 'account',
42+
type: 'lookup',
43+
description:
44+
'The customer company the opportunity is being sold to. Every opportunity belongs to exactly one account; '
45+
+ 'results show the account name.',
46+
synonyms: ['customer', 'client', 'company', '客户', '公司', '客户名称'],
47+
},
2548
// ADR-0021 single-form: the monthly bucketing the trend widget used to carry
2649
// as `categoryGranularity: 'month'` now lives on the dimension itself.
27-
{ name: 'close_date', label: 'Close Date', field: 'close_date', type: 'date', dateGranularity: 'month' },
50+
{
51+
name: 'close_date',
52+
label: 'Close Date',
53+
field: 'close_date',
54+
type: 'date',
55+
dateGranularity: 'month',
56+
description:
57+
'The date the deal closed, or for an open opportunity the date it is expected to close, grouped by '
58+
+ 'calendar month. It is not the date the opportunity was created.',
59+
synonyms: ['closing month', 'expected close date', '成交日期', '预计成交日期', '成交月份'],
60+
},
2861
],
2962

3063
// The amount measures carry no `currency`: they inherit the `amount` field's
3164
// currency, which is the tenant default (ADR-0104 D1). A hard-coded code here
3265
// would print `$` for a tenant whose books are in another currency.
3366
measures: [
34-
{ name: 'opp_count', label: 'Opportunities', aggregate: 'count' },
35-
{ name: 'total_amount', label: 'Total Amount', aggregate: 'sum', field: 'amount', format: '0,0' },
36-
{ name: 'avg_amount', label: 'Avg Deal Size', aggregate: 'avg', field: 'amount', format: '0,0' },
67+
{
68+
name: 'opp_count',
69+
label: 'Opportunities',
70+
aggregate: 'count',
71+
description:
72+
'How many opportunities there are, at every stage: open, won and lost alike. '
73+
+ 'To count won deals only, narrow it to the Closed Won stage.',
74+
synonyms: ['deal count', 'number of deals', '商机数', '商机数量', '机会数'],
75+
},
76+
{
77+
name: 'total_amount',
78+
label: 'Total Amount',
79+
aggregate: 'sum',
80+
field: 'amount',
81+
format: '0,0',
82+
description:
83+
'The sum of the Amount of every opportunity at every stage, open, won and lost alike, so it is neither '
84+
+ 'the open pipeline nor booked revenue. Open pipeline is this total narrowed to the three open stages; '
85+
+ 'won revenue is it narrowed to Closed Won.',
86+
synonyms: ['deal value', 'opportunity amount', '商机金额', '金额合计'],
87+
},
88+
{
89+
name: 'avg_amount',
90+
label: 'Avg Deal Size',
91+
aggregate: 'avg',
92+
field: 'amount',
93+
format: '0,0',
94+
description:
95+
'The average Amount of one opportunity, at every stage: open, won and lost alike. '
96+
+ 'Opportunities with no amount entered are left out of the average.',
97+
synonyms: ['average deal value', 'average opportunity amount', '平均商机金额'],
98+
},
3799
],
38100
});

‎examples/app-crm/src/translations/crm.translation.ts‎

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,14 +370,32 @@ export const CrmTranslationBundle = defineTranslationBundle({
370370
label: '商机指标',
371371
description: '销售漏斗的商机数与金额。',
372372
dimensions: {
373-
stage: { label: '阶段' },
374-
account: { label: '客户' },
375-
close_date: { label: '成交日期' },
373+
stage: {
374+
label: '阶段',
375+
description: '商机在销售流程中所处的阶段:初步接洽、需求确认、方案报价、赢单或输单。前三个是在途商机,后两个是已结束的商机。',
376+
},
377+
account: {
378+
label: '客户',
379+
description: '商机所销售的客户公司。每个商机恰好属于一个客户;结果显示客户名称。',
380+
},
381+
close_date: {
382+
label: '成交日期',
383+
description: '商机实际结束的日期;在途商机则为预计成交日期,按自然月归组。不是商机的创建日期。',
384+
},
376385
},
377386
measures: {
378-
opp_count: { label: '商机数' },
379-
total_amount: { label: '总金额' },
380-
avg_amount: { label: '平均成交额' },
387+
opp_count: {
388+
label: '商机数',
389+
description: '商机的个数,涵盖所有阶段:在途、赢单与输单都计入。只数赢单时,限定在赢单阶段。',
390+
},
391+
total_amount: {
392+
label: '总金额',
393+
description: '所有商机金额之和,涵盖所有阶段:在途、赢单与输单都计入,因此它既不是在途漏斗金额,也不是已确认收入。在途漏斗是限定在三个在途阶段的这一合计;赢单收入是限定在赢单阶段的这一合计。',
394+
},
395+
avg_amount: {
396+
label: '平均成交额',
397+
description: '单个商机的平均金额,涵盖所有阶段:在途、赢单与输单都计入。未填写金额的商机不参与平均。',
398+
},
381399
},
382400
},
383401
},

‎examples/app-crm/test/smoke.test.ts‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,47 @@ describe('Pipeline dashboard schema validation', () => {
257257
expect(parsed.widgets).toHaveLength(6);
258258
});
259259
});
260+
261+
/**
262+
* [ADR-0149 D1, D7 card 6] The first authored dataset vocabulary: every member of
263+
* `crm_opportunity_metrics` carries a business `description` and the `synonyms` a
264+
* person types in a question, the whole dataset passes the spec's own parse (its
265+
* dataset-level rule refuses a synonym that answers to two members), and each
266+
* member description has its zh-CN translation — a description is display text,
267+
* so it is translated like `label`; synonyms are match input and are not.
268+
*/
269+
describe('crm_opportunity_metrics business vocabulary (ADR-0149 D1)', () => {
270+
const dataset = (stack.datasets ?? []).find((d) => d.name === 'crm_opportunity_metrics');
271+
const members = [
272+
...(dataset?.dimensions ?? []).map((m) => ({ group: 'dimensions' as const, member: m })),
273+
...(dataset?.measures ?? []).map((m) => ({ group: 'measures' as const, member: m })),
274+
];
275+
276+
it('passes the spec dataset parse, vocabulary rules included', async () => {
277+
const { DatasetSchema } = await import('@objectstack/spec/ui');
278+
const parsed = DatasetSchema.safeParse(dataset);
279+
expect(parsed.error?.issues ?? []).toEqual([]);
280+
expect(parsed.success).toBe(true);
281+
});
282+
283+
it('gives every dimension and measure a description and at least one synonym', () => {
284+
expect(members.map(({ member }) => member.name)).toEqual([
285+
'stage', 'account', 'close_date', 'opp_count', 'total_amount', 'avg_amount',
286+
]);
287+
for (const { member } of members) {
288+
expect(typeof member.description === 'string' && member.description.trim().length > 0, member.name).toBe(true);
289+
expect((member.synonyms ?? []).length, member.name).toBeGreaterThan(0);
290+
}
291+
});
292+
293+
it('translates every member description into zh-CN', () => {
294+
const zh = (stack.translations ?? [])[0] as
295+
| { 'zh-CN'?: { datasets?: Record<string, Record<string, Record<string, { description?: string }>>> } }
296+
| undefined;
297+
const bundle = zh?.['zh-CN']?.datasets?.crm_opportunity_metrics;
298+
for (const { group, member } of members) {
299+
const text = bundle?.[group]?.[member.name]?.description;
300+
expect(typeof text === 'string' && text.length > 0 && text !== member.description, member.name).toBe(true);
301+
}
302+
});
303+
});

0 commit comments

Comments
 (0)