M5 收官:六个活动包 + 统一报价全图 + 任务推进器

活动包(按 MVP示例工作流 归一化):
- quote-intake  A1 受理归一(flow):LLM 抽取 → 条件跳步补全 → 查历史价 → DMN 打标 → 验收
- quote-pricing A4 成本定价(flow):DMN 利润模型 P-01 + 底价门禁 P-02;超限条目调人决策
- quote-negotiate A6 报价议价(flow):写类动作登记意向、放行即落地;建 D+3 跟进监听;
  议价结果建模为选择组三口(成交/有异议/拒绝)—— 业务分支走输出口,不用异常终态编码
- quote-archive A7 情报归档(flow):写共享域(历史价格情报/客户资料库/落地率统计)
- quote-sourcing A3 渠道寻源(loop):CMMN 四阶段 + 里程碑 + 裁量项 + 两个时间监听;
  DMN 采用策略判定;案例说明书与 XML 同版本
- quote-alternative A2 替代选型(loop):CMMN 三阶段 + userEventListener(客户改需求);
  DMN 替代等级判定;禁区「差异没核清的不放行」有机检形态

流程包全图:7 节点 + 3 网关 + 1 审批点
- 已裁定①:A5 = 审批点,G3 并入驳回走向(驳回 → 回 A4 重开新实例)
- 已裁定②:G2 = 并行网关,A3/A2 失败走向 = 容忍
- 已裁定④:议价回环 = 流程层回边(reopen)

闭合校验在此拦下一个真实建模错误(A4 有两条并发入边映射同名字段),
按规范改拓扑:TYPE-A 直通也走汇合;同时把「回边不是并发汇合」写进判定 ——
reopen 边不参与隐式合并检查。

app:task-advancer worker —— 过程在后端,运行中的任务一拍一拍推,不依赖浏览器在线;
进入等待或终结即停手,不空转。第一方工具补齐 P-01/P-02/画像/落地率/出站发送。

已验证(真机):
- 六个活动包经安装通道装入,静态审各 0 条提示
- 流程包闭合校验通过并发布
- 台账自生长:11 张表由活动声明物化(含 shared 三张共享域表)
- 邮件入站 → 触发器 → 工作流 → A1 落到冯兵工位 → 推进器推 2 拍:
  装载 5 步声明 → 执行 LLM 步 → 按声明重试 2 次 → 转人兜底 → awaiting-event
  (LLM 端点是占位 key,失败路径因此走通了 —— 正是声明给定的兜底)

358 个测试通过,门禁五道全绿

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KeDBx2PHLavbURXB8LJJ7m
This commit is contained in:
JCAI Main Agent
2026-07-27 02:37:04 +08:00
co-authored by Claude Opus 5
parent 78dc03bb58
commit 2f01eda3fb
24 changed files with 1862 additions and 25 deletions
+80
View File
@@ -0,0 +1,80 @@
/**
* 统一报价 A4 · 成本定价 —— 活动包代码入口(ADR-004)。
*
* flow 活动:下一步由步序声明给定。本文件只做声明装不下的两件事 ——
* 视图流控,与「结论不可静默覆写」的呈现:P-02 拦下的条目必须显式呈现给人。
*/
import { defineActivity } from '@sdk';
import type { ActivityBase, ActivityOutcome } from '@sdk';
const DRAFT = 'quote_pricing.draft';
export default defineActivity({
name: 'quote-pricing',
paradigm: 'flow',
async run(base: ActivityBase): Promise<ActivityOutcome> {
const items = await base.ledger.read(DRAFT);
const priced = items.filter((r) => typeof r['quoted_price'] === 'number');
// 底价门禁 P-02 拦下的条目 —— DMN 结论是**约束性输入**,不得静默覆写
const blocked = items.filter((r) => String(r['disposition'] ?? '').includes('拦截'));
await base.interaction.pushView([
{
t: 'kv',
title: '定价概览',
items: [
{ k: '条目', v: `${items.length} 条` },
{ k: '已定价', v: `${priced.length} 条` },
{ k: '底价门禁拦下', v: `${blocked.length} 条` },
],
},
{
t: 'table',
title: '报价草案',
cols: ['PN', '拟报单价', '毛利率', '偏离度', '门禁处置'],
rows: items.map((r) => [
String(r['pn'] ?? ''),
fmt(r['quoted_price']),
pct(r['margin']),
pct(r['deviation']),
String(r['disposition'] ?? '待判'),
]),
linkDonut: {
col: 4,
title: '门禁分布',
map: [
{ match: '直接放行', label: '直接放行', tone: 'ok' },
{ match: 'PM', label: 'PM 附理由', tone: 'warn' },
{ match: '拦截', label: '拦截', tone: 'danger' },
],
},
},
]);
if (priced.length < items.length) {
await base.interaction.say(`还有 ${items.length - priced.length} 条未定价,继续按利润模型 P-01 求值。`, 'conclusion');
return { kind: 'await', reason: '等待定价步完成' };
}
if (blocked.length > 0) {
// 超出授权边界 → 走「人 · 决策」,不自行破线
await base.interaction.say(
`${blocked.length} 条低于底价 20% 以上,已被底价门禁 P-02 拦下 —— 需要人裁决回调还是注明理由。`,
'criterion',
);
return { kind: 'await', reason: '等待超限条目的人裁决' };
}
await base.interaction.say(`${items.length} 条已全部定价且过底价门禁,可提交审批。`, 'criterion');
return { kind: 'submit', deliverable: 'quote-draft', rationale: '全条目带偏离度,底价门禁全过' };
},
});
function fmt(value: unknown): string {
return typeof value === 'number' ? value.toFixed(2) : '—';
}
function pct(value: unknown): string {
return typeof value === 'number' ? `${(value * 100).toFixed(1)}%` : '—';
}
+242
View File
@@ -0,0 +1,242 @@
/**
* 活动包清单 —— 统一报价 A4 · 成本定价。
*
* 业务素材:docs/MVP示例工作流.html §1.2(S1 取价基准 → S2 逐条定价 → S3 底价自检)。
* README《已裁定的落地决策》③:**A4 = flow** —— 取价、查表定价、自检的判断
* **全部装进 DMN 决策表确定性求值**;一旦出现「由 AI 决定怎么办」,按 AM 2.1 上升。
*/
import type { ActivityManifest, DmnModel } from '@contracts';
import { activityIdSchema } from '@contracts';
const DOMAIN = 'quote_pricing';
const ACTIVITY_ID = activityIdSchema.parse('quote-pricing');
/**
* 利润模型 P-01 —— 品牌 × 类型 × 客户等级 × 数量档 → 目标毛利。
* 「经验」段落不入决策表(那是技能 / 活动记忆种子:载方法不载权力)。
*/
export const P01_DMN: DmnModel = {
drd: [
{ decision: 'p01-margin', requires: [], inputs: ['customerGrade', 'materialType', 'volumeTier'] },
{ decision: 'p02-floor', requires: ['p01-margin'], inputs: ['quotedPrice', 'floorPrice'] },
],
tables: [
{
id: 'p01-margin',
label: '利润模型 P-01',
hitPolicy: 'FIRST',
inputs: [
{ name: 'customerGrade', expression: 'customerGrade' },
{ name: 'materialType', expression: 'materialType' },
{ name: 'volumeTier', expression: 'volumeTier' },
],
outputs: [{ name: 'marginLow' }, { name: 'marginHigh' }],
rules: [
{ id: 'p01-1', when: ['"战略客户"', '"A"', '"大批量"'], then: [0.08, 0.1], annotation: '战略客户 A 类标准件大批量 8%–10%' },
{ id: 'p01-2', when: ['"普通客户"', '"A"', '-'], then: [0.12, 0.15], annotation: '普通客户 A 类标准件 12%–15%' },
{ id: 'p01-3', when: ['-', '"B"', '-'], then: [0.15, 0.2], annotation: 'B 类波动件 15%–20%' },
{ id: 'p01-4', when: ['-', '"C"', '-'], then: [0.2, 0.5], annotation: 'C 类替代/EOL ≥20% 或一事一议' },
{ id: 'p01-default', when: ['-', '-', '-'], then: [0.12, 0.15], annotation: '兜底按普通客户标准件' },
],
},
{
/** 底价门禁 P-02 —— 偏离底价 ±20% 即止 */
id: 'p02-floor',
label: '底价门禁 P-02',
hitPolicy: 'FIRST',
inputs: [{ name: 'deviation', expression: 'deviation' }],
outputs: [{ name: 'disposition' }, { name: 'passable' }],
rules: [
{ id: 'p02-1', when: ['>= 0'], then: ['直接放行', true], annotation: '≥底价 → 直接放行' },
{ id: 'p02-2', when: ['[-0.20..0)'], then: ['PM 附理由放行', true], annotation: '低于底价 ≤20% → PM 附理由' },
{ id: 'p02-3', when: ['< -0.20'], then: ['拦截 · BOSS 拍板', false], annotation: '低于底价 >20% → 拦截' },
],
},
],
};
export const manifest: ActivityManifest = {
identity: {
activityId: ACTIVITY_ID,
name: 'A4 · 成本定价',
packageVersion: '0.1.0',
category: '统一报价',
paradigm: 'flow',
sdkVersion: '0.1.0-m5',
checksum: 'dev-checksum-quote-pricing',
},
contract: {
activityId: ACTIVITY_ID,
version: '0.1.0',
input: {
data: {
type: 'object',
required: ['customerCode', 'records'],
properties: {
customerCode: { type: 'string' },
records: { type: 'array' },
// B/C 类由 A3/A2 交回的底价与替代方案;A 类直通时为空
floorPrices: { type: 'array' },
},
},
messageAllowed: true,
},
output: {
mandatory: [
{
name: 'draft',
payload: {
type: 'object',
required: ['items'],
properties: { items: { type: 'array' } },
},
description: '报价草案(逐条带偏离度)',
},
],
selective: [],
},
requiredDeliverables: [{ key: 'quote-draft', label: '报价草案(全条目带偏离度)' }],
acceptanceCriteria: [
{ key: 'all-priced', label: '每条都有拟报单价与毛利率', level: 'L1', predicate: 'unpriced = 0' },
// 底价门禁沉为 L2 机检 —— 「约束力收缩」的终点
{ key: 'floor-gate', label: '偏离底价 ≤±20%,超限者已回调或注明理由', level: 'L2', modelRef: 'p02-floor' },
{ key: 'pm-release', label: 'BD 放行', level: 'L5' },
],
prohibitions: [
{ key: 'no-silent-override', statement: '不得静默绕开 P-02 的结论;要破线只能走「人 · 决策」' },
{ key: 'no-stale-floor', statement: '底价超一周未更新的,先刷底价再判' },
],
authorization: {
discretion: [{ key: 'margin-band', statement: '在 P-01 给出的毛利区间内自决;出区间必须调人决策' }],
preauthorizedActions: [],
humanCallBudget: 2,
},
resources: {
tools: [{ name: 'crm.history-price-read' }],
skills: [],
models: ['quote-extractor'],
roles: ['BD'],
budget: { steps: 60, tokens: 150_000, activeMinutes: 120, humanCalls: 2 },
},
},
declarations: {
models: ['quote-extractor'],
tools: [{ name: 'crm.history-price-read' }],
ledger: [
{
domain: DOMAIN,
object: 'draft',
label: '报价草案',
fields: [
{ name: 'pn', type: 'text', primaryKey: true, masked: false, label: 'PN' },
{ name: 'quoted_price', type: 'number', primaryKey: false, masked: false, label: '拟报单价' },
{ name: 'margin', type: 'number', primaryKey: false, masked: false, label: '毛利率' },
{ name: 'deviation', type: 'number', primaryKey: false, masked: false, label: '偏离度' },
{ name: 'disposition', type: 'text', primaryKey: false, masked: false, label: '门禁处置' },
],
},
],
listeners: [
{
origin: 'static',
eventType: 'human',
keyFilter: { kind: 'decision' },
semantic: 'complete-step',
deadline: 'PT4H',
escalation: ['nudge', 'escalate'],
},
],
// SLA <2h(MVP示例 §1.2 留痕 · SLA)
harness: {
memoryWindow: 20,
stallAfter: 'PT2H',
nudge: [{ after: 'PT1H', action: 'nudge' }],
retry: { times: 2, backoff: 'PT30S' },
},
},
assets: {
businessModel: {
paradigm: 'flow',
steps: [
{
kind: 'tool',
name: 'S1_basis',
label: 'S1 取价基准',
// Type A 取历史价近期价;B/C 取供应商底价表(C 类参考替代对标表)
input: { pn: 'pn' },
output: { domain: DOMAIN, object: 'draft', fields: { deviation: 'deviation' } },
tool: 'crm.history-price-read',
failure: { retry: { times: 2, backoff: 'PT1M' }, fallback: { kind: 'human', workOrder: 'execution' } },
},
{
kind: 'pure-tool',
name: 'S2_price',
label: 'S2 逐条定价(DMN · 利润模型 P-01)',
input: { customerGrade: 'customerGrade', materialType: 'materialType', volumeTier: 'volumeTier' },
output: { domain: DOMAIN, object: 'draft', fields: { margin: 'marginLow', quoted_price: 'quotedPrice' } },
tool: 'quote-pricing.margin',
failure: { retry: { times: 1, backoff: 'PT10S' }, fallback: { kind: 'blocked' } },
},
{
kind: 'pure-tool',
name: 'S3_floor_gate',
label: 'S3 底价自检(DMN · 底价门禁 P-02)',
input: { deviation: 'deviation' },
output: { domain: DOMAIN, object: 'draft', fields: { disposition: 'disposition' } },
tool: 'quote-pricing.floor-gate',
failure: { retry: { times: 1, backoff: 'PT10S' }, fallback: { kind: 'blocked' } },
},
{
kind: 'human',
name: 'S4_decide_breach',
label: '超限条目:调人决策(回调还是注明理由)',
// 只有门禁不过才调人 —— 条件必谓词,零 LLM
when: 'breached > 0',
input: {},
workOrder: 'execution',
card: { title: '有条目低于底价 20% 以上,请裁决', fields: ['disposition', 'reason'] },
deadline: 'PT4H',
failure: { retry: { times: 0, backoff: 'PT30S' }, fallback: { kind: 'blocked' } },
},
{
kind: 'human',
name: 'S5_release',
label: 'S5 报价草案验收放行',
input: {},
workOrder: 'acceptance',
card: { title: '报价草案(全条目带偏离度)请验收', deliverable: 'quote-draft' },
deadline: 'P1D',
failure: { retry: { times: 0, backoff: 'PT30S' }, fallback: { kind: 'blocked' } },
},
],
parallelGroups: [],
},
skills: [],
viewTemplates: [
{
name: 'pricing-summary',
html: '<div class="jc-card"><h3>报价草案</h3><p>已定价 <b data-slot="count"></b> 条</p></div>',
},
],
cardSchemas: {},
distillHooks: [
{
on: 'terminal',
prompt: '归纳本单定价的经验:哪些组合的毛利档被人回调过、底价门禁拦下的形态、破线的理由。',
},
],
},
samples: [
{
name: '战略客户 A 类大批量',
input: { customerCode: 'C001', records: [{ pn: 'LM358DR', type: 'A' }] },
expect: { ports: ['draft'] },
},
],
entry: { file: 'index.js', checksum: 'dev-entry-quote-pricing' },
};