Files
JX-BPOS/activities/quote-intake/src/manifest.ts
T
ChaiHaoandClaude Opus 5 e72182003a M5/M6 修复串:判据 ③ 全链路跑通 —— 六处「声明与引擎对不上」
判据 ③ 现在从入站到 released 一路走通:步序推进 → LLM 步(密钥是占位符,
按声明降级为人兜底)→ 台账草稿层 → D1 条件跳步 → S4 工具 → S5 DMN 三分类
(LM358DR → Type A · 直接快答)→ 验收放行 → 草稿合并正式版 2 行 → 输出口
intake 发射 → 终态 released。

沿路修掉的六处,每一处都是「声明是这么写的,引擎不这么读」:

1. 人兜底卡只问一个笼统「结果」框 → 改问**这一步声明的出参字段**。
   出参契约属于步、不属于执行者:同一步谁做完,落进作用域的形状都得一样。
2. 人事件的载荷是回传协议壳 `{mode,workOrderId,values}`,
   引擎把整个壳当出参写 → 取 `values`。
3. 引擎作用域是 `{'域.对象': 行数组}`,而所有活动的步声明写的都是裸字段名 →
   任务视图三层铺开:起单入参在底、各对象最新行的字段铺顶层、地址式整表保留。
4. 起单入参从不落库、也进不了作用域 → task 存 `input_data`,断点续跑后仍在。
5. 步出参无法声明**写哪一行** → 出参加 `key`(主键列 → 作用域路径);
   六个活动包的每处出参补上键。台账几乎都有主键,不声明键就只能写无主键行。
6. `tick` 不处理 `finished`:谱走完仍按 running 一拍拍推,把预算烧到 exhausted,
   把「没人裁」误报成「跑爆了」→ 放行通过则落地收敛后 released;未放行则挂起等人。
   `flow.advance` 据末步验收裁决报 released —— **完成只出自放行通过**。

另两处装配缺口:
  · `release.land()` 实现完整却无人调用 —— 放行后从不落地。经 LandingGateway 接上。
  · `process.onTaskTerminal()` 实现完整却无人调用 —— 任务终态报不到流程层,
    流就停在那个节点上,既不流转也不走失败走向。task 在 L6 不得反向依赖 L7,
    这一跳由 app 缝合(延后绑定,同 container 里 TriggerMatcher 的手法)。

还有一处版本化缺陷:资产播种恒用 v1,`shouldSeedAsset` 一比就跳过 ——
只有**第一个**包版本的资产此生有效,之后装什么都跑旧的。改为播下一版;
进化管线放行出的更高版仍不被盖过;同版重复安装不再播种。

gates: tsc / eslint / depcruise(317 模块)/ api-report / 393 测试 全绿

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KeDBx2PHLavbURXB8LJJ7m
2026-07-27 04:31:23 +08:00

295 lines
11 KiB
TypeScript

/**
* 活动包清单 —— 统一报价 A1 · RFQ 需求分析(受理归一)。
*
* 业务素材出处:docs/MVP示例工作流.html §1.1;按 README《归一化对照表》映射为:
* SOP 节点 → **标准活动(flow)**;作业指导书 S1…S6 → **步序声明**(四种步型);
* 步内判断 D1 完整度 → **条件谓词**;三分类规则 P-03 → **DMN 决策表**;
* SLA(受理<15min、打标<45min)→ Harness 时限与预算。
*/
import type { ActivityManifest, DmnModel } from '@contracts';
import { activityIdSchema } from '@contracts';
const INTAKE_DOMAIN = 'quote_intake';
const ACTIVITY_ID = activityIdSchema.parse('quote-intake');
/**
* 三分类规则 P-03 —— 把「装得下的判断」从 LLM 手里拿走。
* 由纯工具步 `quote-intake.classify` 逐条求值,命中规则行留痕。
*/
export const P03_DMN: DmnModel = {
drd: [{ decision: 'p03-type', requires: [], inputs: ['historyDays', 'marketStable', 'lifecycle'] }],
tables: [{
id: 'p03-type',
label: '三分类规则 P-03',
hitPolicy: 'FIRST' as const,
inputs: [
{ name: 'historyDays', expression: 'historyDays' },
{ name: 'marketStable', expression: 'marketStable' },
{ name: 'lifecycle', expression: 'lifecycle' },
],
outputs: [{ name: 'type' }, { name: 'play' }],
rules: [
{ id: 'p03-c', when: ['-', '-', '"EOL","缺货","要求替代"'], then: ['C', '转案处理'], annotation: 'EOL/缺货/要替代 → C' },
{ id: 'p03-a', when: ['<= 90', 'true', '-'], then: ['A', '直接快答'], annotation: '历史价≤90天且行情稳 → A' },
{ id: 'p03-b', when: ['-', '-', '-'], then: ['B', '重估后报'], annotation: '无历史/过期/波动 → B' },
],
}],
};
export const manifest: ActivityManifest = {
identity: {
activityId: ACTIVITY_ID,
name: 'A1 · RFQ 需求分析',
packageVersion: '0.1.2',
category: '统一报价',
paradigm: 'flow',
sdkVersion: '0.1.0-m5',
checksum: 'dev-checksum-quote-intake',
},
/* 契约七件 */
contract: {
activityId: ACTIVITY_ID,
version: '0.1.0',
input: {
data: {
type: 'object',
required: ['customerCode', 'rfqRef'],
properties: {
customerCode: { type: 'string' },
rfqRef: { type: 'string' },
subject: { type: 'string' },
},
},
messageAllowed: true,
messageHint: '客户口头急单等特殊性写这里',
},
output: {
mandatory: [
{
name: 'intake',
payload: {
type: 'object',
required: ['records'],
properties: { records: { type: 'array' } },
},
description: '统一受理记录(已打标)',
},
],
selective: [],
},
requiredDeliverables: [
{ key: 'intake-record', label: '统一受理记录(打标)' },
{ key: 'type-table', label: '料号分类表' },
],
acceptanceCriteria: [
{ key: 'fields-complete', label: '八字段齐(PN/EAU/交期为必要三要素)', level: 'L1', predicate: 'missingKeyFields = 0' },
{ key: 'typed', label: '每条都已打标 A/B/C', level: 'L2', predicate: 'untyped = 0' },
{ key: 'downgrade-safe', label: '吃不准降 B,不许臆断 A', level: 'L3' },
{ key: 'owner-release', label: 'BD 放行', level: 'L5' },
],
prohibitions: [
{ key: 'no-guess-a', statement: '吃不准的一律降 B,不得臆断为 A' },
{ key: 'no-external-write', statement: '不得在放行前写任何外部系统' },
],
authorization: {
discretion: [{ key: 'ask-back', statement: '缺次要字段可受理并追问,缺 PN/数量/交期必须退回补全' }],
preauthorizedActions: [],
humanCallBudget: 3,
},
resources: {
tools: [{ name: 'crm.history-price-read' }],
skills: [],
models: ['quote-extractor'],
roles: ['BD'],
budget: { steps: 40, tokens: 120_000, activeMinutes: 60, humanCalls: 3 },
},
},
/* 声明 */
declarations: {
models: ['quote-extractor'],
tools: [{ name: 'crm.history-price-read' }],
ledger: [
{
domain: INTAKE_DOMAIN,
object: 'record',
label: '统一受理记录',
fields: [
{ name: 'customer_code', type: 'text', primaryKey: true, masked: false, label: '客户码' },
{ name: 'pn', type: 'text', primaryKey: true, masked: false, label: 'PN' },
{ name: 'brand', type: 'text', primaryKey: false, masked: false, label: '厂牌' },
{ name: 'eau', type: 'integer', primaryKey: false, masked: false, label: 'EAU' },
{ name: 'type_tag', type: 'text', primaryKey: false, masked: false, label: 'Type 标' },
{ name: 'target_price', type: 'number', primaryKey: false, masked: false, label: '目标价' },
{ name: 'lead_time', type: 'text', primaryKey: false, masked: false, label: '交期' },
{ name: 'status', type: 'text', primaryKey: false, masked: false, label: '状态' },
],
},
{
domain: INTAKE_DOMAIN,
object: 'type_table',
label: '料号分类表',
fields: [
{ name: 'pn', type: 'text', primaryKey: true, masked: false },
{ name: 'type_tag', type: 'text', primaryKey: false, masked: false },
{ name: 'basis', type: 'text', primaryKey: false, masked: false, label: '分级依据' },
{ name: 'history_hit', type: 'boolean', primaryKey: false, masked: false, label: '历史价命中' },
// 打标的三个判据必须落表:S5 的 DMN 从这里读,不落就无米下锅
{ name: 'history_days', type: 'integer', primaryKey: false, masked: false, label: '距上次报价天数' },
{ name: 'market_stable', type: 'boolean', primaryKey: false, masked: false, label: '行情稳定' },
{ name: 'lifecycle', type: 'text', primaryKey: false, masked: false, label: '生命周期' },
],
},
],
listeners: [
{
origin: 'static',
eventType: 'human',
keyFilter: { kind: 'elicitation' },
semantic: 'complete-step',
// 时限必配 —— 悬空监听安装时拒绝
deadline: 'P1D',
escalation: ['nudge', 'escalate'],
},
],
harness: {
memoryWindow: 20,
// SLA:受理<15min、打标<45min —— 停滞检测按此设
stallAfter: 'PT45M',
nudge: [{ after: 'PT15M', action: 'nudge' }],
retry: { times: 2, backoff: 'PT30S' },
},
},
/* 资产初始版:flow = 步序声明 */
assets: {
businessModel: {
paradigm: 'flow',
steps: [
{
kind: 'llm',
name: 'S3_normalize',
label: 'S3 逐条解析归一',
input: { rfqRef: 'rfqRef', customerCode: 'customerCode' },
output: {
domain: INTAKE_DOMAIN,
object: 'record',
key: { customer_code: 'customerCode', pn: 'pn' },
fields: { pn: 'pn', brand: 'brand', eau: 'eau' },
},
model: 'quote-extractor',
template:
'按《询价受理规范》把这份 RFQ 拆解为逐条需求,抄录 PN/数量/EAU/厂牌/目标价/交期。' +
'只输出 JSON。RFQ:{{rfqRef}}',
outputSchema: {
type: 'object',
required: ['records'],
properties: {
records: {
type: 'array',
items: {
type: 'object',
required: ['pn'],
properties: {
pn: { type: 'string' },
brand: { type: 'string' },
eau: { type: 'integer' },
targetPrice: { type: 'number' },
leadTime: { type: 'string' },
},
},
},
missingKeyFields: { type: 'integer' },
},
},
failure: { retry: { times: 2, backoff: 'PT30S' }, fallback: { kind: 'human', workOrder: 'execution' } },
},
{
kind: 'human',
name: 'S2_ask_back',
label: 'S2 追问补全信息',
// D1 判断完整度:缺 PN/数量/交期三要素才走补全 —— 条件必谓词,由引擎求值
when: 'missingKeyFields > 0',
input: {},
workOrder: 'execution',
card: { title: '缺关键字段,请向客户追问补全', fields: ['pn', 'eau', 'leadTime'] },
deadline: 'P1D',
failure: { retry: { times: 0, backoff: 'PT30S' }, fallback: { kind: 'blocked' } },
},
{
kind: 'tool',
name: 'S4_history',
label: 'S4 查历史价',
input: { pn: 'pn' },
// 情报四件全部落表:S5 打标要的就是这三件,只落 hit 会让下一步无米下锅
output: {
domain: INTAKE_DOMAIN,
object: 'type_table',
key: { pn: 'pn' },
fields: {
history_hit: 'hit',
history_days: 'historyDays',
market_stable: 'marketStable',
lifecycle: 'lifecycle',
},
},
tool: 'crm.history-price-read',
failure: { retry: { times: 2, backoff: 'PT1M' }, fallback: { kind: 'human', workOrder: 'execution' } },
},
{
kind: 'pure-tool',
name: 'S5_classify',
label: 'S5 逐条打标(DMN · 三分类规则 P-03)',
// 入参名 ← 作用域路径:作用域里是 S4 落表后的字段名
input: { historyDays: 'history_days', marketStable: 'market_stable', lifecycle: 'lifecycle' },
output: {
domain: INTAKE_DOMAIN,
object: 'type_table',
key: { pn: 'pn' },
fields: { type_tag: 'type', basis: 'play' },
},
tool: 'quote-intake.classify',
failure: { retry: { times: 1, backoff: 'PT10S' }, fallback: { kind: 'blocked' } },
},
{
kind: 'human',
name: 'S6_release',
label: 'S6 分流复核与派单 · 验收放行',
input: {},
workOrder: 'acceptance',
card: { title: '统一受理记录(打标)请验收' },
deadline: 'P1D',
failure: { retry: { times: 0, backoff: 'PT30S' }, fallback: { kind: 'blocked' } },
},
],
parallelGroups: [],
},
skills: [],
viewTemplates: [
{
name: 'intake-summary',
html: '<div class="jc-card"><h3>统一受理记录</h3><p>已归一 <b data-slot="count"></b> 条</p></div>',
},
],
cardSchemas: {},
distillHooks: [
{
on: 'terminal',
prompt: '归纳本单受理归一的经验:字段缺口形态、打标依据、被驳回的理由。',
},
],
},
/* 样例集 —— 首装审以静态审 + 样例集替代回放审 */
samples: [
{
name: '车规 Analog 询价',
input: { customerCode: 'C001', rfqRef: 'mail:m-1001', subject: '询价 RFQ - 车规 Analog' },
expect: { ports: ['intake'] },
},
],
entry: { file: 'index.js', checksum: 'dev-entry-quote-intake' },
};