diff --git a/activities/quote-alternative/src/manifest.ts b/activities/quote-alternative/src/manifest.ts index 2c970d5..4ec6758 100644 --- a/activities/quote-alternative/src/manifest.ts +++ b/activities/quote-alternative/src/manifest.ts @@ -6,6 +6,8 @@ * `⏱时限过半` → 时间监听(**时限必配**)。 */ import type { ActivityManifest, DmnModel } from '@contracts'; +import { ALTERNATIVE_SKILLS } from './skills.ts'; +import { ALTERNATIVE_CASE } from './views/report.ts'; import { activityIdSchema } from '@contracts'; import { CMMN_XML, NARRATIVE } from './case-model.ts'; @@ -39,7 +41,7 @@ export const manifest: ActivityManifest = { identity: { activityId: ACTIVITY_ID, name: 'A2 · 替代选型', - packageVersion: '0.1.0', + packageVersion: '0.1.2', category: '统一报价', paradigm: 'loop', sdkVersion: '0.1.0-m5', @@ -90,7 +92,7 @@ export const manifest: ActivityManifest = { }, resources: { tools: [{ name: 'crm.history-price-read' }], - skills: [], + skills: ALTERNATIVE_SKILLS.map((s) => s.id), models: ['quote-extractor'], roles: ['FAE'], budget: { steps: 100, tokens: 260_000, activeMinutes: 360, humanCalls: 6 }, @@ -162,10 +164,8 @@ export const manifest: ActivityManifest = { narrative: NARRATIVE, dmn: GRADE_DMN, }, - skills: [], - viewTemplates: [ - { name: 'alt-board', html: '

替代选型

' }, - ], + skills: ALTERNATIVE_SKILLS, + viewTemplates: [{ name: 'case-overview', html: ALTERNATIVE_CASE }], cardSchemas: {}, distillHooks: [ { on: 'milestone', milestone: 'M_candidates', prompt: '归纳本轮撒网的有效角度与无效角度。' }, diff --git a/activities/quote-alternative/src/skills.ts b/activities/quote-alternative/src/skills.ts new file mode 100644 index 0000000..3849783 --- /dev/null +++ b/activities/quote-alternative/src/skills.ts @@ -0,0 +1,45 @@ +/** + * A2 技能 —— 替代选型的方法经验(AM 08)。 + */ +import { skillIdSchema } from '@contracts'; +import type { Skill } from '@contracts'; + +export const ALTERNATIVE_SKILLS: Skill[] = [ + { + id: skillIdSchema.parse('alternative.screen-candidates'), + label: '圈替代候选', + applicability: '原型号停产或缺货,要找替代时。', + method: [ + '三层筛,一层比一层贵,所以要按顺序:', + '① **参数硬指标**:封装、电压范围、精度、温度等级 —— 不满足直接淘汰,不必往下看。', + '② **认证与合规**:车规 / 医疗 / 工业等级不可降级替代,客户没明说也不行。', + '③ **供应与价格**:到这一步才比价,前两层没过的便宜也没用。', + '', + '「Pin-to-pin 兼容」要看数据手册核实,不要信分销商的一句话 —— ', + '同封装不等于同引脚定义,这个错误要到打样才暴露。', + ].join('\n'), + crystallized: [], + knowledgeRefs: ['替代选型判据表'], + version: '1.0.0', + }, + { + id: skillIdSchema.parse('alternative.ask-customer'), + label: '什么时候必须问客户', + applicability: '候选已圈定,但存在客户口径不明的项时。', + method: [ + '这几件事**必须问**,不能替客户决定:', + '· 是否接受非原厂品牌;', + '· 是否接受参数降级(哪怕只降一档温度等级);', + '· 是否需要重新打样验证、由谁承担费用。', + '', + '问的方式是**跨任务征答**:卡以系统消息送到 BD 的消息要素,就地作答。', + '它不占对方的任务清单——那是一次性的解答请求,不是把责任转过去。', + '', + '问之前先把候选与判据整理好一并发过去:让对方**在数据上作判断**,', + '而不是回一句「你看着办」。', + ].join('\n'), + crystallized: [], + knowledgeRefs: [], + version: '1.0.0', + }, +]; diff --git a/activities/quote-alternative/src/views/report.ts b/activities/quote-alternative/src/views/report.ts new file mode 100644 index 0000000..7a3e012 --- /dev/null +++ b/activities/quote-alternative/src/views/report.ts @@ -0,0 +1,26 @@ +/** + * A2 视图模版 —— 案例全景(AM 07:loop 按案例模型的阶段与里程碑组织汇报)。 + */ +import { kvCard, noteCard, stagesCard, viewShell } from '@sdk'; + +export const ALTERNATIVE_CASE = viewShell({ + title: '替代选型 · 案例全景', + kicker: 'A2 · 案例活动(loop)', + tone: 'case', + body: + kvCard('本单标的', [ + ['原型号', 'originalPn', 'mono'], + ['芯片类型', 'chipType'], + ['当前阶段', 'activeStage', 'tag'], + ['当下可为', 'enabledCount'], + ['目标缺口', 'gapCount'], + ]) + + stagesCard('阶段(CMMN)', 'case:stages', '阶段推进到 Enabled 为止;触达世界的计划项须人工启动。') + + stagesCard('当下可为', 'case:enabled') + + stagesCard('目标缺口', 'case:gaps', '缺口决定下一步是调人还是立监听。') + + noteCard( + '跨人卡', + '选型常要向 BD 补客户口径 —— 那是跨任务征答:卡以系统消息送达对方的消息要素、就地作答,' + + '不占对方的任务清单,也不开放本任务的对话流。它是一次性的解答请求,不是责任转移。', + ), +}); diff --git a/activities/quote-archive/src/manifest.ts b/activities/quote-archive/src/manifest.ts index f0e4b42..301f6a5 100644 --- a/activities/quote-archive/src/manifest.ts +++ b/activities/quote-archive/src/manifest.ts @@ -5,7 +5,9 @@ * 「不成交也留资产:情报、客户画像、落地率」—— 写的是**共享域**,跨活动的沉淀事实。 */ import type { ActivityManifest } from '@contracts'; +import { ARCHIVE_SKILLS } from './skills.ts'; import { activityIdSchema } from '@contracts'; +import { ARCHIVE_LOGGED, ARCHIVE_RELEASE } from './views/report.ts'; const ACTIVITY_ID = activityIdSchema.parse('quote-archive'); @@ -13,7 +15,7 @@ export const manifest: ActivityManifest = { identity: { activityId: ACTIVITY_ID, name: 'A7 · 情报归档', - packageVersion: '0.1.2', + packageVersion: '0.1.4', category: '统一报价', paradigm: 'flow', sdkVersion: '0.1.0-m5', @@ -59,7 +61,7 @@ export const manifest: ActivityManifest = { authorization: { discretion: [], preauthorizedActions: [], humanCallBudget: 2 }, resources: { tools: [], - skills: [], + skills: ARCHIVE_SKILLS.map((s) => s.id), models: ['quote-extractor'], roles: ['BD'], budget: { steps: 30, tokens: 60_000, activeMinutes: 60, humanCalls: 2 }, @@ -130,6 +132,7 @@ export const manifest: ActivityManifest = { type: 'object', properties: { lostReason: { type: 'string' }, competitorPrice: { type: 'number' } }, }, + view: 'archive-logged', failure: { retry: { times: 2, backoff: 'PT30S' }, fallback: { kind: 'human', workOrder: 'execution' } }, }, { @@ -168,14 +171,16 @@ export const manifest: ActivityManifest = { workOrder: 'acceptance', card: { title: '情报归档请验收', deliverable: 'history-archive' }, deadline: 'P1D', + view: 'archive-release', failure: { retry: { times: 0, backoff: 'PT30S' }, fallback: { kind: 'blocked' } }, }, ], parallelGroups: [], }, - skills: [], + skills: ARCHIVE_SKILLS, viewTemplates: [ - { name: 'archive-summary', html: '

归档闭环

' }, + { name: 'archive-logged', html: ARCHIVE_LOGGED }, + { name: 'archive-release', html: ARCHIVE_RELEASE }, ], cardSchemas: {}, distillHooks: [ diff --git a/activities/quote-archive/src/skills.ts b/activities/quote-archive/src/skills.ts new file mode 100644 index 0000000..8d0256b --- /dev/null +++ b/activities/quote-archive/src/skills.ts @@ -0,0 +1,25 @@ +/** + * A7 技能 —— 归档的方法经验(AM 08)。 + */ +import { skillIdSchema } from '@contracts'; +import type { Skill } from '@contracts'; + +export const ARCHIVE_SKILLS: Skill[] = [ + { + id: skillIdSchema.parse('archive.log-lost-reason'), + label: '把拒绝原因写成下一单的判据', + applicability: '客户拒绝或超时,要登记结果时。', + method: [ + '「价格高」不是原因,是结论。要写的是**可比对的事实**:', + '· 竞对报价多少、差几个百分点;', + '· 输在价格、交期、还是资质/认证;', + '· 客户是否明说了可接受区间。', + '', + '判据要能被下一单**机器读取**:P-03 用「距上次报价 / 行情稳定」,P-01 用客户等级。', + '写成一段散文,它就只能被人读;写成字段,它才进得了决策表。', + ].join('\n'), + crystallized: [], + knowledgeRefs: [], + version: '1.0.0', + }, +]; diff --git a/activities/quote-archive/src/views/report.ts b/activities/quote-archive/src/views/report.ts new file mode 100644 index 0000000..464619f --- /dev/null +++ b/activities/quote-archive/src/views/report.ts @@ -0,0 +1,43 @@ +/** + * A7 视图模版 —— 归档两屏:结果登记 / 闭环待放行(AM 07)。 + * 归档是这条流的收尾:它写回的是**下一单的判据**,所以要说清「这次学到了什么」。 + */ +import { kvCard, noteCard, tableCard, viewShell } from '@sdk'; + +export const ARCHIVE_LOGGED = viewShell({ + title: '结果登记', + kicker: 'A7 · 情报归档', + tone: 'archive', + body: + kvCard('本单结果', [ + ['型号 PN', 'pn', 'mono'], + ['报价日期', 'quotedAt', 'mono'], + ['拒绝原因', 'lostReason'], + ['竞对价位', 'competitor_price'], + ]) + + noteCard('为什么要登记', '拒绝原因与竞对价位是下一单的判据:它们回写历史价格情报,供 P-03 的「距上次报价 / 行情稳定」与 P-01 的客户等级因子取用。这一单的败仗,是下一单的地形图。'), +}); + +export const ARCHIVE_RELEASE = viewShell({ + title: '情报归档 · 闭环待放行', + kicker: 'A7 · 成果预览', + tone: 'ok', + body: + tableCard('历史价格情报回写', 'mine:shared.history_price', [ + ['型号', 'pn', 'mono'], + ['报价日期', 'quoted_at', 'mono'], + ['拒绝原因', 'lost_reason'], + ]) + + kvCard('画像与落地率', [ + ['客户编码', 'customer_code', 'mono'], + ['画像标签', 'profile_tags'], + ['统计周期', 'period', 'mono'], + ['落地率', 'landing_rate'], + ]) + + noteCard( + '闭环的含义', + '放行后这条工作流走到终点节点,状态收敛为「已完成」。' + + '终态封卷触发蒸馏钩子:从任务记忆归纳出活动记忆的候选条目(带证据链),' + + '经回放与人放行才成为下一版业务模型的一部分 —— 记忆不载权力。', + ), +}); diff --git a/activities/quote-intake/src/manifest.ts b/activities/quote-intake/src/manifest.ts index ba333dd..7801e8b 100644 --- a/activities/quote-intake/src/manifest.ts +++ b/activities/quote-intake/src/manifest.ts @@ -7,6 +7,7 @@ * SLA(受理<15min、打标<45min)→ Harness 时限与预算。 */ import type { ActivityManifest, DmnModel } from '@contracts'; +import { INTAKE_SKILLS } from './skills.ts'; import { activityIdSchema } from '@contracts'; import { INTAKE_CLASSIFIED, INTAKE_OVERVIEW, INTAKE_RELEASE } from './views/report.ts'; @@ -41,7 +42,7 @@ export const manifest: ActivityManifest = { identity: { activityId: ACTIVITY_ID, name: 'A1 · RFQ 需求分析', - packageVersion: '0.1.7', + packageVersion: '0.1.8', category: '统一报价', paradigm: 'flow', sdkVersion: '0.1.0-m5', @@ -102,7 +103,7 @@ export const manifest: ActivityManifest = { }, resources: { tools: [{ name: 'crm.history-price-read' }], - skills: [], + skills: INTAKE_SKILLS.map((s) => s.id), models: ['quote-extractor'], roles: ['BD'], budget: { steps: 40, tokens: 120_000, activeMinutes: 60, humanCalls: 4 }, @@ -289,7 +290,7 @@ export const manifest: ActivityManifest = { ], parallelGroups: [], }, - skills: [], + skills: INTAKE_SKILLS, // 三张模版对应三种局面(事态全景 / 进展 / 成果预览),由步序声明按位置推送 viewTemplates: [ { name: 'intake-overview', html: INTAKE_OVERVIEW }, diff --git a/activities/quote-intake/src/skills.ts b/activities/quote-intake/src/skills.ts new file mode 100644 index 0000000..5116652 --- /dev/null +++ b/activities/quote-intake/src/skills.ts @@ -0,0 +1,53 @@ +/** + * A1 技能 —— 工具用法的方法经验(AM 08)。 + * + * 「白名单回答『能用什么』(权力),技能回答『怎么用好』(方法)——棋子确定,棋谱是资产。」 + * 每条技能 = 适用描述(何时适用)+ 方法正文(怎么判断、怎么编排工具) + * + 结晶片段脚本(可选:反复出现的确定性子序列)。 + * + * **载方法,不载权力**:这里提到的工具都在本活动白名单内;技能不扩权、不改约。 + */ +import { skillIdSchema } from '@contracts'; +import type { Skill } from '@contracts'; + +export const INTAKE_SKILLS: Skill[] = [ + { + id: skillIdSchema.parse('intake.read-rfq'), + label: '读懂一封询价', + applicability: '收到客户询价原文,需要拆成逐条需求时。正文格式五花八门:表格、纯文本、附件转述都可能。', + method: [ + '先找**锚点**再抄字段:PN 通常是连续的字母数字混排(如 LM358DR),年用量常带「K/片/pcs/年用量/EAU」,', + '目标价常带货币符号或「目标价/target」,交期常带「周/weeks/wks/交期/lead」。', + '', + '三条纪律:', + '① **原文没写的不要补**。宁可标 missingKeyFields,也不要按常识填一个「合理值」——', + ' 受理阶段编出来的数,会一路流到定价和报价单上,越往后越难发现。', + '② **单位归一但不换算口径**:12K → 12000 可以;「月用量 1000」不要自作主张乘 12,', + ' 那是业务判断,该走补全卡问客户。', + '③ **一条需求一行**。同一 PN 不同数量档是两行,不是一行的两个值。', + '', + '拆不动就交人:缺 PN / 数量 / 交期任一,把 missingKeyFields 加一,让 D1 判断把补全卡发出去。', + ].join('\n'), + crystallized: [], + knowledgeRefs: ['《询价受理规范》'], + version: '1.0.0', + }, + { + id: skillIdSchema.parse('intake.classify-basis'), + label: '打标前先备齐判据', + applicability: '要对料号做三分类(P-03)之前,判据不全时。', + method: [ + 'P-03 只认三个入参:距上次报价天数、行情是否稳定、生命周期状态。三者齐了,结论是**算出来**的,不是判出来的。', + '', + '所以打标前唯一该做的事是**把判据取齐**:调历史价情报工具,拿回这三项。', + '取不到(新料号无历史)不是错误——工具会回「无历史」,那本身就是判据:', + '距上次报价记为极大值 → 命中 B 类「重估后报」,这是对的,新料号本就该重估。', + '', + '不要绕过决策表自己判。规则表是可回放、可追责的;临场判断不是。', + ].join('\n'), + // 结晶片段:反复出现的确定性子序列 —— 取历史价这一步每单都一样 + crystallized: [{ tool: 'crm.history-price-read', input: { pn: 'pn' } }], + knowledgeRefs: ['三分类规则 P-03'], + version: '1.0.0', + }, +]; diff --git a/activities/quote-intake/src/views/report.ts b/activities/quote-intake/src/views/report.ts index 60b7a5c..03b8059 100644 --- a/activities/quote-intake/src/views/report.ts +++ b/activities/quote-intake/src/views/report.ts @@ -1,133 +1,77 @@ /** - * A1 视图模版 —— 视图区呈现的 HTML(AM 07)。 - * - * 「模版是**内容**不是代码」:这里没有脚本、没有事件处理器、没有外链; - * 槽位 `data-slot` 由基座按任务视图填数,行模版 `data-rows` 逐条展开。 - * 容器是沙箱 iframe(无脚本执行权),所以样式必须内联自带 —— 页面不继承工作台的 CSS。 - * - * 三张模版对应三种局面(事态全景 / 进展 / 成果预览),按步序位置推送。 + * A1 视图模版 —— 三种局面:事态全景 / 打标判据 / 成果预览(AM 07)。 + * 外壳与卡片件来自 `@sdk`:六个活动共用一套面貌,不各自发明。 */ +import { kvCard, noteCard, tableCard, viewShell } from '@sdk'; -/** 共用外壳:一套克制的排版,深浅色都能看 */ -const SHELL = (title: string, kicker: string, accent: string, body: string): string => ` - -
-
${kicker}

${title}

- ${body} -
`; +export const INTAKE_OVERVIEW = viewShell({ + title: 'RFQ 受理全景', + kicker: 'A1 · 统一受理', + tone: 'brand', + body: + kvCard('询价来源', [ + ['客户编码', 'customer_code', 'mono'], + ['询价单号', 'rfqRef', 'mono'], + ['主题', 'subject'], + ]) + + kvCard('归一结果', [ + ['型号 PN', 'pn', 'mono'], + ['厂牌', 'brand'], + ['年用量 EAU', 'eau'], + ['目标价', 'target_price'], + ['交期', 'lead_time'], + ['缺关键字段', 'missing_key_fields'], + ]) + + noteCard('这一屏在说什么', '归一由模型从询价原文抽取,逐条落任务级草稿层:本任务可见、正式版不可见、不产生数据事件。放行前的一切都还改得动。'), +}); -/** ① 事态全景:受理刚开始,先把「这一单是什么」摆清楚 */ -export const INTAKE_OVERVIEW = SHELL( - 'RFQ 受理全景', - 'A1 · 统一受理', - '#3370ff', - `
-

询价来源

-
-
客户编码
-
询价单号
-
主题
-
-
-
-

归一结果

-
-
型号 PN
-
厂牌
-
年用量 EAU
-
目标价
-
交期
-
缺关键字段
-
-

归一由模型从询价原文抽取,逐条落任务级草稿层;放行前不入正式版。

-
`, -); +export const INTAKE_CLASSIFIED = viewShell({ + title: '料号分类与判据', + kicker: 'A1 · 三分类 P-03', + tone: 'ok', + body: + kvCard('分类结论', [ + ['型号 PN', 'pn', 'mono'], + ['Type 标', 'type_tag', 'tag'], + ['分级依据', 'basis'], + ]) + + kvCard('打标判据(DMN 入参)', [ + ['距上次报价', 'history_days'], + ['行情稳定', 'market_stable'], + ['生命周期', 'lifecycle'], + ['历史价命中', 'history_hit'], + ]) + + noteCard( + '为什么是确定性的', + '三分类规则 P-03 是决策表不是模型判断:同样的判据必得同样的结论,零方差零 token,命中的规则行随出参留痕。' + + 'A = 直接快答;B = 重估后报(转寻源);C = 转案处理(转替代选型)。', + ), +}); -/** ② 进展:打标之后,把判据摊开 —— 人要在数据上作判断,数据就得摆出来 */ -export const INTAKE_CLASSIFIED = SHELL( - '料号分类与判据', - 'A1 · 三分类 P-03', - '#0aa294', - `
-

分类结论

-
-
型号 PN
-
Type 标
-
分级依据
-
-
-
-

打标判据(DMN 入参)

-
-
距上次报价
-
行情稳定
-
生命周期
-
历史价命中
-
-

- 三分类规则 P-03 是确定性决策表:同样的判据必得同样的结论,零方差零 token。 - A = 直接快答;B = 重估后报(转寻源);C = 转案处理(转替代选型)。 -

-
`, -); - -/** ③ 成果预览:验收放行前的最后一屏 —— 要放行的到底是什么,一眼看全 */ -export const INTAKE_RELEASE = SHELL( - '统一受理记录 · 待放行', - 'A1 · 成果预览', - '#7f3bf5', - `
-

本单交付

- - - - - - - - - - - -
型号厂牌年用量目标价交期
-
-
-

分流去向

-
-
Type 标
-
依据
-
-

- 放行通过即刻落地:草稿层合并入正式版、数据事件此刻才发射,G2 网关按 Type 分流。 - 放行是草稿态与事实态之间的那道门 —— 门前的一切都还改得动,门后的都算数了。 -

-
`, -); +export const INTAKE_RELEASE = viewShell({ + title: '统一受理记录 · 待放行', + kicker: 'A1 · 成果预览', + tone: 'case', + body: + tableCard( + '本单交付', + 'mine:quote_intake.record', + [ + ['型号', 'pn', 'mono'], + ['厂牌', 'brand'], + ['年用量', 'eau'], + ['目标价', 'target_price'], + ['交期', 'lead_time'], + ], + '只列本单写下的行 —— 别单放行过的记录不混进来。', + ) + + kvCard('分流去向', [ + ['Type 标', 'type_tag', 'tag'], + ['依据', 'basis'], + ]) + + noteCard( + '放行意味着什么', + '放行通过即刻落地:草稿层合并入正式版、数据事件此刻才发射,G2 网关按 Type 分流。' + + '放行是草稿态与事实态之间的那道门 —— 门前的都还改得动,门后的都算数了。', + ), +}); diff --git a/activities/quote-negotiate/src/manifest.ts b/activities/quote-negotiate/src/manifest.ts index be44e4f..28d8f5a 100644 --- a/activities/quote-negotiate/src/manifest.ts +++ b/activities/quote-negotiate/src/manifest.ts @@ -6,7 +6,9 @@ * 放行通过即落地(台账回写 + 出站发送)→ 输出口发射;并建 D+3 跟进监听。 */ import type { ActivityManifest } from '@contracts'; +import { NEGOTIATE_SKILLS } from './skills.ts'; import { activityIdSchema } from '@contracts'; +import { QUOTE_COMPOSED, QUOTE_RELEASE } from './views/report.ts'; const DOMAIN = 'quote_negotiate'; const ACTIVITY_ID = activityIdSchema.parse('quote-negotiate'); @@ -15,7 +17,7 @@ export const manifest: ActivityManifest = { identity: { activityId: ACTIVITY_ID, name: 'A6 · 报价议价', - packageVersion: '0.1.2', + packageVersion: '0.1.4', category: '统一报价', paradigm: 'flow', sdkVersion: '0.1.0-m5', @@ -69,7 +71,7 @@ export const manifest: ActivityManifest = { }, resources: { tools: [{ name: 'mail.send' }, { name: 'crm.history-price-read' }], - skills: [], + skills: NEGOTIATE_SKILLS.map((s) => s.id), models: ['quote-extractor'], roles: ['BD'], budget: { steps: 50, tokens: 120_000, activeMinutes: 60, humanCalls: 3 }, @@ -150,6 +152,7 @@ export const manifest: ActivityManifest = { required: ['lines'], properties: { lines: { type: 'array' }, validityDays: { type: 'integer' } }, }, + view: 'quote-composed', failure: { retry: { times: 2, backoff: 'PT30S' }, fallback: { kind: 'human', workOrder: 'execution' } }, }, { @@ -168,14 +171,16 @@ export const manifest: ActivityManifest = { workOrder: 'acceptance', card: { title: '正式报价单请验收 —— 放行即发出', deliverable: 'formal-quote' }, deadline: 'P1D', + view: 'quote-release', failure: { retry: { times: 0, backoff: 'PT30S' }, fallback: { kind: 'blocked' } }, }, ], parallelGroups: [], }, - skills: [], + skills: NEGOTIATE_SKILLS, viewTemplates: [ - { name: 'quote-preview', html: '

正式报价单

' }, + { name: 'quote-composed', html: QUOTE_COMPOSED }, + { name: 'quote-release', html: QUOTE_RELEASE }, ], cardSchemas: {}, distillHooks: [{ on: 'terminal', prompt: '归纳本单议价的经验:客户的还价幅度、成交与否的关键因素。' }], diff --git a/activities/quote-negotiate/src/skills.ts b/activities/quote-negotiate/src/skills.ts new file mode 100644 index 0000000..d72d5d5 --- /dev/null +++ b/activities/quote-negotiate/src/skills.ts @@ -0,0 +1,42 @@ +/** + * A6 技能 —— 议价与出单的方法经验(AM 08)。 + */ +import { skillIdSchema } from '@contracts'; +import type { Skill } from '@contracts'; + +export const NEGOTIATE_SKILLS: Skill[] = [ + { + id: skillIdSchema.parse('negotiate.compose-quote'), + label: '拟一份能发出去的报价单', + applicability: '定价已过审批,要生成正式报价单时。', + method: [ + '报价单是**要发给客户**的东西,所以每一项都得能兑现:', + '· 单价与交期照审批通过的草案抄,不做任何「顺手优化」——改价要重新过审批点。', + '· SPQ / MOQ / 贸易条款 / 有效期缺一不可:缺了客户会追问,追问就是又一轮往返。', + '· 有效期按行情波动定,不要一律写「长期有效」——那等于把汇率与料价风险自己扛了。', + '', + '拿不准的项**宁可空着走补全**,不要填一个看起来合理的值:', + '报价单一旦发出就是承诺,发出前的空白是成本,发出后的错误是损失。', + ].join('\n'), + crystallized: [], + knowledgeRefs: ['报价单模版规范'], + version: '1.0.0', + }, + { + id: skillIdSchema.parse('negotiate.pick-outcome'), + label: '选对议价出口', + applicability: '客户回复后,要确认议价结果出口时。', + method: [ + '三个出口对应三种后续,**恰发一口**:', + '· 成交 → 转订单履约,这条流走到终点。', + '· 有异议 → 回 A4 重开新实例重算 —— 注意是**新实例**,旧的已终、不再入算。', + '· 拒绝 / 超时 → 转 A7 情报归档:把拒绝原因与竞对价位登记下来。', + '', + '「拒绝」不是失败终态。这一单丢了,但拒绝原因回写历史情报后,', + '下一单的三分类与利润模型会用上它 —— 这才是归档存在的理由。', + ].join('\n'), + crystallized: [], + knowledgeRefs: [], + version: '1.0.0', + }, +]; diff --git a/activities/quote-negotiate/src/views/report.ts b/activities/quote-negotiate/src/views/report.ts new file mode 100644 index 0000000..88f2846 --- /dev/null +++ b/activities/quote-negotiate/src/views/report.ts @@ -0,0 +1,50 @@ +/** + * A6 视图模版 —— 议价两屏:正式报价单 / 待放行即发出(AM 07)。 + * 这是**唯一会触达外界**的活动:放行一刻要发信、要回写台账,所以那一屏必须说清后果。 + */ +import { kvCard, noteCard, tableCard, viewShell } from '@sdk'; + +export const QUOTE_COMPOSED = viewShell({ + title: '正式报价单', + kicker: 'A6 · 报价议价', + tone: 'brand', + body: + kvCard('报价抬头', [ + ['报价单号', 'quoteNo', 'mono'], + ['客户编码', 'customerCode', 'mono'], + ['型号 PN', 'pn', 'mono'], + ]) + + kvCard('报价条款', [ + ['单价', 'unit_price'], + ['交期', 'lead_time'], + ['最小包装量 SPQ', 'spq'], + ['最小起订量 MOQ', 'moq'], + ['贸易条款', 'trade_terms'], + ['有效期', 'valid_until'], + ]) + + noteCard('这一步还没碰外界', '报价单此刻只是草稿。发出动作是写类的,过程中只登记为「动作意向」——入参冻结、等放行,放行前一封信都不会发出去。'), +}); + +export const QUOTE_RELEASE = viewShell({ + title: '正式报价单 · 放行即发出', + kicker: 'A6 · 成果预览', + tone: 'danger', + body: + tableCard( + '本单报价', + 'mine:quote_negotiate.formal_quote', + [ + ['报价单号', 'quote_no', 'mono'], + ['型号', 'pn', 'mono'], + ['单价', 'unit_price'], + ['交期', 'lead_time'], + ], + ) + + noteCard( + '按下放行会发生什么', + '① 落地预检先跑:交付物齐备、动作意向可执行、授权在契约边界内 —— 预检不过不发卡。' + + '② 放行通过即刻落地:台账回写 + 出站发送(报价单发给客户),动作附幂等键。' + + '③ 落地收敛后输出口才发射 —— 下游只见落地完成的任务;已成动作留存不回滚。' + + '④ 出口三选一(成交 / 有异议 / 拒绝)恰发一口,随放行一并确认,G4 网关按它分流。', + ), +}); diff --git a/activities/quote-pricing/src/manifest.ts b/activities/quote-pricing/src/manifest.ts index 5d3cefc..8d8cf2c 100644 --- a/activities/quote-pricing/src/manifest.ts +++ b/activities/quote-pricing/src/manifest.ts @@ -6,7 +6,9 @@ * **全部装进 DMN 决策表确定性求值**;一旦出现「由 AI 决定怎么办」,按 AM 2.1 上升。 */ import type { ActivityManifest, DmnModel } from '@contracts'; +import { PRICING_SKILLS } from './skills.ts'; import { activityIdSchema } from '@contracts'; +import { PRICING_BASIS, PRICING_PRICED, PRICING_RELEASE } from './views/report.ts'; const DOMAIN = 'quote_pricing'; const ACTIVITY_ID = activityIdSchema.parse('quote-pricing'); @@ -59,7 +61,7 @@ export const manifest: ActivityManifest = { identity: { activityId: ACTIVITY_ID, name: 'A4 · 成本定价', - packageVersion: '0.1.3', + packageVersion: '0.1.5', category: '统一报价', paradigm: 'flow', sdkVersion: '0.1.0-m5', @@ -114,7 +116,7 @@ export const manifest: ActivityManifest = { }, resources: { tools: [{ name: 'quote-pricing.basis' }, { name: 'crm.history-price-read' }], - skills: [], + skills: PRICING_SKILLS.map((s) => s.id), models: ['quote-extractor'], roles: ['BD'], budget: { steps: 60, tokens: 150_000, activeMinutes: 120, humanCalls: 3 }, @@ -171,6 +173,7 @@ export const manifest: ActivityManifest = { // 取回来的是**基准价**;偏离率要等 S2 定出拟报价才算得出来(见 S2B) output: { domain: DOMAIN, object: 'draft', key: { pn: 'pn' }, fields: { last_price: 'lastPrice' } }, tool: 'crm.history-price-read', + view: 'pricing-basis', failure: { retry: { times: 2, backoff: 'PT1M' }, fallback: { kind: 'human', workOrder: 'execution' } }, }, { @@ -203,6 +206,7 @@ export const manifest: ActivityManifest = { input: { deviation: 'deviation' }, output: { domain: DOMAIN, object: 'draft', key: { pn: 'pn' }, fields: { disposition: 'disposition' } }, tool: 'quote-pricing.floor-gate', + view: 'pricing-priced', failure: { retry: { times: 1, backoff: 'PT10S' }, fallback: { kind: 'blocked' } }, }, { @@ -225,17 +229,17 @@ export const manifest: ActivityManifest = { workOrder: 'acceptance', card: { title: '报价草案(全条目带偏离度)请验收', deliverable: 'quote-draft' }, deadline: 'P1D', + view: 'pricing-release', failure: { retry: { times: 0, backoff: 'PT30S' }, fallback: { kind: 'blocked' } }, }, ], parallelGroups: [], }, - skills: [], + skills: PRICING_SKILLS, viewTemplates: [ - { - name: 'pricing-summary', - html: '

报价草案

已定价 条

', - }, + { name: 'pricing-basis', html: PRICING_BASIS }, + { name: 'pricing-priced', html: PRICING_PRICED }, + { name: 'pricing-release', html: PRICING_RELEASE }, ], cardSchemas: {}, distillHooks: [ diff --git a/activities/quote-pricing/src/skills.ts b/activities/quote-pricing/src/skills.ts new file mode 100644 index 0000000..0db4b7d --- /dev/null +++ b/activities/quote-pricing/src/skills.ts @@ -0,0 +1,41 @@ +/** + * A4 技能 —— 定价的方法经验(AM 08)。载方法,不载权力。 + */ +import { skillIdSchema } from '@contracts'; +import type { Skill } from '@contracts'; + +export const PRICING_SKILLS: Skill[] = [ + { + id: skillIdSchema.parse('pricing.pick-basis'), + label: '选对价格基准', + applicability: '定价开始,需要确定「跟谁比」时。', + method: [ + '基准的优先级:① 本客户近期成交价 → ② 同型号他客户成交价 → ③ 供应商底价表 → ④ 无基准。', + '越靠前越贴近这一单的真实议价空间;越靠后越要留余量。', + '', + '**无基准不是异常**,是一种基准:新料号、久未报价的老料号都会落到这里。', + '此时偏离率记 0(没有可偏离的对象),由底价门禁按「无基准」放行 —— ', + '不要拿一个不相干的价去凑一个偏离率出来,那比没有基准更危险:它看起来像有依据。', + ].join('\n'), + crystallized: [{ tool: 'crm.history-price-read', input: { pn: 'pn' } }], + knowledgeRefs: ['利润模型 P-01'], + version: '1.0.0', + }, + { + id: skillIdSchema.parse('pricing.read-gate'), + label: '读懂底价门禁的处置', + applicability: '底价门禁(P-02)给出处置结论,需要决定下一步时。', + method: [ + '门禁不是「拦下」而是**分流**:', + '· 直接放行 —— 偏离在容许带内,照常提审。', + '· 超限待裁 —— 偏离超 ±20%,交人决断:回调价格,还是注明理由硬报。', + ' 两条路都合法,但都要留下**理由**:这条留痕将来会成为客户等级与利润模型的迭代素材。', + '', + '不要为了让门禁「过」而回头改毛利参数 —— 那是把判据改成结论,', + '决策表就失去了它唯一的价值:同输入必同结论。', + ].join('\n'), + crystallized: [], + knowledgeRefs: ['底价门禁 P-02'], + version: '1.0.0', + }, +]; diff --git a/activities/quote-pricing/src/views/report.ts b/activities/quote-pricing/src/views/report.ts new file mode 100644 index 0000000..0cd8a3d --- /dev/null +++ b/activities/quote-pricing/src/views/report.ts @@ -0,0 +1,67 @@ +/** + * A4 视图模版 —— 定价的三屏:取价基准 / 定价与门禁 / 报价草案待放行(AM 07)。 + * 定价这件事最需要「把判据摊开」:人签的不是一个数字,是这个数字的来路。 + */ +import { kvCard, noteCard, tableCard, viewShell } from '@sdk'; + +export const PRICING_BASIS = viewShell({ + title: '取价基准', + kicker: 'A4 · 成本定价', + tone: 'brand', + body: + kvCard('本单标的', [ + ['客户编码', 'customerCode', 'mono'], + ['型号 PN', 'pn', 'mono'], + ['物料类型', 'materialType', 'tag'], + ]) + + kvCard('价格基准', [ + ['上次成交价', 'last_price'], + ['客户等级', 'customerGrade'], + ['数量档', 'volumeTier'], + ]) + + noteCard('基准从哪来', '基准价取自历史价情报(CRM)。新料号无历史时基准记 0,由底价门禁按无基准处置 —— 不凭空编一个偏离率出来。'), +}); + +export const PRICING_PRICED = viewShell({ + title: '定价与底价门禁', + kicker: 'A4 · DMN 两表', + tone: 'ok', + body: + kvCard('定价结论', [ + ['拟报单价', 'quoted_price'], + ['目标毛利', 'margin'], + ['相对基准偏离', 'deviation'], + ['门禁处置', 'disposition', 'tag'], + ]) + + noteCard( + '两张决策表各管一段', + '利润模型 P-01:客户等级 × 物料类型 × 数量档 → 目标毛利区间。' + + '底价门禁 P-02:偏离底价 ±20% 即止 —— 超限的不是「拦下」,而是转人裁断(回调还是注明理由)。' + + '两表都是确定性求值,同输入必同结论;命中的规则行随出参留痕,事后可逐条复盘。', + ), +}); + +export const PRICING_RELEASE = viewShell({ + title: '报价草案 · 待放行', + kicker: 'A4 · 成果预览', + tone: 'case', + body: + tableCard( + '本单报价草案', + 'mine:quote_pricing.draft', + [ + ['型号', 'pn', 'mono'], + ['基准价', 'last_price'], + ['拟报价', 'quoted_price'], + ['毛利', 'margin'], + ['偏离', 'deviation'], + ['门禁', 'disposition'], + ], + '逐条列出,便于放行前逐条核对。', + ) + + noteCard( + '放行之后', + '放行通过 → 草稿合并入正式版 → 进 AP 定价审批(卡到 PM 工位)。' + + '审批驳回按声明走向回 A4 重开新实例 —— 新任务 ID、留痕关联,不复活旧任务。', + ), +}); diff --git a/activities/quote-sourcing/src/manifest.ts b/activities/quote-sourcing/src/manifest.ts index 4c6b413..8cf8dbf 100644 --- a/activities/quote-sourcing/src/manifest.ts +++ b/activities/quote-sourcing/src/manifest.ts @@ -8,6 +8,8 @@ * `⏱时限/回价到期` → 时间监听(**时限必配**)。 */ import type { ActivityManifest, DmnModel } from '@contracts'; +import { SOURCING_SKILLS } from './skills.ts'; +import { SOURCING_CASE } from './views/report.ts'; import { activityIdSchema } from '@contracts'; import { CMMN_XML, NARRATIVE } from './case-model.ts'; @@ -43,7 +45,7 @@ export const manifest: ActivityManifest = { identity: { activityId: ACTIVITY_ID, name: 'A3 · 渠道寻源', - packageVersion: '0.1.0', + packageVersion: '0.1.2', category: '统一报价', paradigm: 'loop', sdkVersion: '0.1.0-m5', @@ -95,7 +97,7 @@ export const manifest: ActivityManifest = { }, resources: { tools: [{ name: 'mail.send' }, { name: 'crm.history-price-read' }], - skills: [], + skills: SOURCING_SKILLS.map((s) => s.id), models: ['quote-extractor'], roles: ['PRM'], budget: { steps: 120, tokens: 300_000, activeMinutes: 480, humanCalls: 8 }, @@ -168,10 +170,8 @@ export const manifest: ActivityManifest = { narrative: NARRATIVE, dmn: STRATEGY_DMN, }, - skills: [], - viewTemplates: [ - { name: 'sourcing-board', html: '

寻源看板

' }, - ], + skills: SOURCING_SKILLS, + viewTemplates: [{ name: 'case-overview', html: SOURCING_CASE }], cardSchemas: {}, distillHooks: [ { on: 'milestone', milestone: 'M_quotes', prompt: '归纳各渠道的回价节奏与配合度。' }, diff --git a/activities/quote-sourcing/src/skills.ts b/activities/quote-sourcing/src/skills.ts new file mode 100644 index 0000000..b1381d9 --- /dev/null +++ b/activities/quote-sourcing/src/skills.ts @@ -0,0 +1,46 @@ +/** + * A3 技能 —— 寻源的方法经验(AM 08)。 + * loop 里技能由 AI **按适用描述临场装配**:常驻上下文只有目录,按事加载正文。 + */ +import { skillIdSchema } from '@contracts'; +import type { Skill } from '@contracts'; + +export const SOURCING_SKILLS: Skill[] = [ + { + id: skillIdSchema.parse('sourcing.pick-channels'), + label: '按场景圈渠道', + applicability: '拿到料号与场景,要决定向谁发询时。', + method: [ + '渠道不是越多越好:发得越广,回价越慢、口径越乱、对供应商的信用消耗越大。', + '', + '按场景定档:', + '· 常规补货 → 原厂代理 2 家足够,比的是账期与交期。', + '· BOM 后期 / 急单 → 加 1–2 家现货商,比的是**能不能拿到货**,价格其次。', + '· 停产料 → 直接问现货商与拆解渠道,原厂问了也是白问。', + '', + '每多发一家,就多一份要等的回价 —— 发询前先想清楚:这一家的回价会改变你的决定吗?', + '不会,就别发。', + ].join('\n'), + crystallized: [], + knowledgeRefs: ['渠道分级台账'], + version: '1.0.0', + }, + { + id: skillIdSchema.parse('sourcing.wait-or-ask'), + label: '该等还是该问', + applicability: '当下可为与目标所需交集为空(依赖断点)时。', + method: [ + '断点只有两种解法,选错就是白等或白问:', + '· 缺口**在世界侧**(供应商还没回价、样品还在路上)→ 立监听,必配时限。', + ' 时限到了要有升级动作:催办 → 升级 → 改道,不能无限等。', + '· 缺口**只有人知道**(客户能不能接受替代、预算上限多少)→ 调人。', + '', + '判断标准很简单:**这个信息在系统外会自己到来吗?**', + '会 → 等(监听);不会 → 问(调人)。', + '把「该问的」等成超时,是寻源里最常见也最贵的错误。', + ].join('\n'), + crystallized: [], + knowledgeRefs: [], + version: '1.0.0', + }, +]; diff --git a/activities/quote-sourcing/src/views/report.ts b/activities/quote-sourcing/src/views/report.ts new file mode 100644 index 0000000..71b3b49 --- /dev/null +++ b/activities/quote-sourcing/src/views/report.ts @@ -0,0 +1,25 @@ +/** + * A3 视图模版 —— 案例全景(AM 07:loop 按案例模型的**阶段与里程碑**组织汇报)。 + * + * 画面素材全部来自语义引擎:阶段的生命周期态、当下可为(Enabled 集)、目标缺口。 + * 这些是算出来的确定事实,零 LLM 即可成屏 —— 模型只决定「下一步做什么」,不负责画面。 + */ +import { kvCard, noteCard, stagesCard, viewShell } from '@sdk'; + +export const SOURCING_CASE = viewShell({ + title: '渠道寻源 · 案例全景', + kicker: 'A3 · 案例活动(loop)', + tone: 'case', + body: + kvCard('本单标的', [ + ['型号 PN', 'pn', 'mono'], + ['场景', 'scenario'], + ['当前阶段', 'activeStage', 'tag'], + ['当下可为', 'enabledCount'], + ['目标缺口', 'gapCount'], + ]) + + stagesCard('阶段(CMMN)', 'case:stages', '阶段的生命周期态由语义引擎推进到 Enabled 为止;凡触达世界或产出关键交付的计划项必须人工启动 —— Enabled ≠ Active。') + + stagesCard('当下可为', 'case:enabled', 'AI 只能在这个集合里选下一步:可以越谱,不可越权。') + + stagesCard('目标缺口', 'case:gaps', '缺口只有人知道 → 调人;缺口在世界侧 → 立监听(必配时限)。当下可为 ∩ 目标所需 = 空,就是依赖断点。') + + noteCard('这个活动为什么是 loop', '寻源是一事一议:几家供应商、谁先回、要不要追加一轮,事前排不出谱。调度权交给 AI,系统只保证边框 —— 预算、停滞熔断、放行归人。'), +}); diff --git a/apps/api/src/app/container.ts b/apps/api/src/app/container.ts index c2281fb..b250d9d 100644 --- a/apps/api/src/app/container.ts +++ b/apps/api/src/app/container.ts @@ -47,6 +47,7 @@ import { createCardStore, createHumanToolService } from '@modules/human-tool'; import type { InteractionService } from '@modules/interaction'; import { createInteractionService, createInteractionStore, templateIsSafe } from '@modules/interaction'; import type { ActivityRegistryService } from '@modules/activity-registry'; +import { createSkillEngineService } from '@modules/skill-engine'; import { createRegistryService, createRegistryStore } from '@modules/activity-registry'; import type { ReleaseService } from '@modules/release'; import { createIntentStore, createReleaseService } from '@modules/release'; @@ -364,6 +365,30 @@ export async function createContainer(config: AppConfig): Promise { sdkVersion: '0.1.0-m5', }); + /* + * skill-engine(L4)—— 技能是活动内部的构件格式,由两个范式引擎装配。 + * 目录与白名单都取自**活动清单**:技能提及的工具不在本活动白名单者不可调, + * 装配前查扩权 —— 载方法,不载权力(AM 08)。 + */ + const skills = createSkillEngineService({ + catalog: { + skillsOf: async (activityId) => [...(await registry.manifestOf(activityId)).assets.skills], + allowlistOf: async (activityId) => + (await registry.manifestOf(activityId)).declarations.tools.map((t) => t.name), + }, + tools: { + invoke: (input) => toolInvoker.invoke(input), + }, + memory: { + append: async (input) => + void (await memory.append({ + ...input, + stamp: { contractVersion: '1', businessModelVersion: '1', skillVersions: [] }, + })), + }, + clock: systemClock, + }); + const release = createReleaseService({ intents: createIntentStore(db), ledger: { @@ -489,6 +514,7 @@ export async function createContainer(config: AppConfig): Promise { modelGateway, registry, release, + skills, schemas, }); diff --git a/apps/api/src/app/wiring/engines.ts b/apps/api/src/app/wiring/engines.ts index 44a1344..46d7f6a 100644 --- a/apps/api/src/app/wiring/engines.ts +++ b/apps/api/src/app/wiring/engines.ts @@ -16,6 +16,7 @@ import type { MessageService } from '@modules/message'; import type { OrgService } from '@modules/org'; import type { LlmService, ModelGateway } from '@modules/llm'; import type { ActivityRegistryService } from '@modules/activity-registry'; +import type { SkillEngineService } from '@modules/skill-engine'; import type { ReleaseService } from '@modules/release'; import { createFlowRunner, createFlowStateStore } from '@modules/flow-engine'; @@ -49,6 +50,7 @@ export type EngineWiringDeps = { readonly llm: LlmService; readonly modelGateway: ModelGateway; readonly registry: ActivityRegistryService; + readonly skills: SkillEngineService; readonly release: ReleaseService; readonly schemas: { validate(schema: Record, value: unknown): { ok: boolean; errors: string[] } }; }; @@ -115,6 +117,42 @@ export function wireEngines(deps: EngineWiringDeps): EngineWiring { }, }; + /* + * 视图流控网关 —— 两个范式共用一份。 + * 按名取模版 → 填数 → 推给前端。模版取自**该任务装载时的资产版本**(经 registry), + * 不是「当前最新」:在途任务按其启动时版本跑完,呈现也该跟着那一版。 + */ + const viewGateway = { + async push({ + taskId, + activityId, + template, + scope, + }: { + taskId: TaskId; + activityId: string; + template: string; + scope: Record; + }): Promise { + const manifest = await deps.registry.manifestOf(activityId); + const found = manifest.assets.viewTemplates.find((t) => t.name === template); + if (found === undefined) return; + + /* + * 视图作用域 = 任务视图 + **本单自己写下的行**。 + * 两者要分得开:任务视图里的 `域.对象` 是正式版 + 我的草稿的合并结果, + * 拿它画「本单交付」会把别单放行过的记录一并列出来。 + * 本单的行放在 `mine:域.对象` 下 —— 整键,取值不歧义。 + */ + const own: Record = {}; + for (const draft of await deps.ledger.taskDrafts(taskId)) { + const key = `mine:${draft.domain}.${draft.object}`; + (own[key] ??= []).push({ ...draft.key, ...draft.patch }); + } + await deps.interaction.pushViewHtml(taskId, renderView(found.html, { ...scope, ...own })); + }, + }; + /* ── 任务数据:引擎读**任务视图** = 正式版 + 本任务草稿层 ───────── */ const taskData = { /** @@ -286,31 +324,7 @@ export function wireEngines(deps: EngineWiringDeps): EngineWiring { data: taskData, tools: { ...toolGateway, invoke: (i) => toolGateway.invoke(i) }, schemas: deps.schemas, - views: { - /* - * 按名取模版 → 填数 → 推给前端。 - * 模版取自**该任务装载时的资产版本**(经 registry),不是「当前最新」—— - * 在途任务按其启动时版本跑完,呈现也该跟着那一版。 - */ - async push({ taskId, activityId, template, scope }) { - const manifest = await deps.registry.manifestOf(activityId); - const found = manifest.assets.viewTemplates.find((t) => t.name === template); - if (found === undefined) return; - - /* - * 视图作用域 = 任务视图 + **本单自己写下的行**。 - * 两者要分得开:任务视图里的 `域.对象` 是正式版 + 我的草稿的合并结果, - * 拿它画「本单交付」会把别单放行过的记录一并列出来。 - * 本单的行放在 `mine:域.对象` 下 —— 整键,取值不歧义。 - */ - const own: Record = {}; - for (const draft of await deps.ledger.taskDrafts(taskId)) { - const key = `mine:${draft.domain}.${draft.object}`; - (own[key] ??= []).push({ ...draft.key, ...draft.patch }); - } - await deps.interaction.pushViewHtml(taskId, renderView(found.html, { ...scope, ...own })); - }, - }, + views: viewGateway, llm: { async generate(input) { // LLM 在 flow 里只以「被调用的工具」出现,不是调度者 @@ -357,6 +371,11 @@ export function wireEngines(deps: EngineWiringDeps): EngineWiring { tools: toolGateway, cards, listeners, + views: viewGateway, + skills: { + index: (activityId) => deps.skills.index(activityId), + stamp: (activityId, ids) => deps.skills.stamp(activityId, ids), + }, memory: { append: memoryRecorder.append as never, loadActivityMemory: async (activityId: string, limit: number) => diff --git a/apps/api/src/modules/loop-engine/internal/usecase/turn-runner.ts b/apps/api/src/modules/loop-engine/internal/usecase/turn-runner.ts index 729c0d5..6824423 100644 --- a/apps/api/src/modules/loop-engine/internal/usecase/turn-runner.ts +++ b/apps/api/src/modules/loop-engine/internal/usecase/turn-runner.ts @@ -14,6 +14,8 @@ import type { ListenerRegistrar, LoopStateStore, MemoryRecorder, + SkillGateway, + ViewGateway, Sfeel, TaskContext, TaskDataGateway, @@ -41,6 +43,8 @@ export type TurnRunnerDeps = { readonly cards: CardGateway; readonly listeners: ListenerRegistrar; readonly memory: MemoryRecorder; + readonly views: ViewGateway; + readonly skills: SkillGateway; readonly tasks: TaskContext; readonly clock: Clock; }; @@ -232,12 +236,35 @@ export function createTurnRunner(deps: TurnRunnerDeps): LoopEngineService { }); } + const activityId = (await deps.tasks.of(taskId)).activityId; + const catalog = await deps.skills.index(activityId); + + /* + * 叙事面 = 案例说明书 + 活动记忆选摘 + **技能目录**。 + * 渐进披露(AM 08):常驻上下文只给「有哪些方法、何时适用」, + * 正文与知识引用等 AI 说要才加载 —— 一次把所有正文塞进去, + * 上下文会被方法论淹掉,真正的局面反而看不见。 + */ const narrative = [ model.narrative, - ...(await deps.memory.loadActivityMemory((await deps.tasks.of(taskId)).activityId, 20)).map( - (m) => `[${m.layer}] ${m.statement}`, - ), - ].join('\n\n'); + ...(await deps.memory.loadActivityMemory(activityId, 20)).map((m) => `[${m.layer}] ${m.statement}`), + catalog.length === 0 + ? '' + : `【可装配的技能(目录)】\n${catalog.map((s) => `- ${s.id} ${s.label}:${s.applicability}`).join('\n')}`, + ] + .filter((line) => line !== '') + .join('\n\n'); + + // 装配入信封:这一回合手上有哪些技能及其版本,记进任务记忆 —— 回放与归因依赖之 + if (catalog.length > 0) { + const stamp = await deps.skills.stamp(activityId, catalog.map((s) => s.id)); + await deps.memory.append({ + taskId, + kind: 'thought', + title: `装配技能:${stamp.map((s) => `${s.id}@${s.version}`).join('、')}`, + detail: { skills: [...stamp] }, + }); + } const action = await deps.agent.decide({ taskId, narrative, enabled, scope }); @@ -250,6 +277,31 @@ export function createTurnRunner(deps: TurnRunnerDeps): LoopEngineService { const applied = await applyAction(taskId, action, runtime); await deps.state.save(taskId, model, parsed, applied.runtime); + /* + * 每回合推一次案例全景 —— 呈现是投影,失败只丢这一帧,不影响回路推进。 + * 画面的素材全部来自语义引擎(阶段态 / 当下可为 / 缺口),零 LLM。 + */ + try { + await deps.views.push({ + taskId, + activityId: (await deps.tasks.of(taskId)).activityId, + template: 'case-overview', + scope: { + ...scope, + 'case:stages': parsed.items + .filter((i) => i.type === 'stage') + .map((i) => ({ name: i.name, state: applied.runtime.items.find((r) => r.id === i.id)?.state ?? '—' })), + 'case:enabled': enabled.entries.map((e) => ({ name: e.name, state: e.requiresManualStart ? '待启动' : '可进行' })), + 'case:gaps': enabled.gaps.map((g) => ({ name: g, state: '未满足' })), + gapCount: enabled.gaps.length, + enabledCount: enabled.entries.length, + activeStage: enabled.activeStages.join('、') || '—', + }, + }); + } catch { + // 呈现失败不影响回路:画面丢一帧,事实一件不少 + } + return { runtime: applied.runtime, enabled, diff --git a/apps/api/src/modules/loop-engine/port.ts b/apps/api/src/modules/loop-engine/port.ts index 294f323..e57a85d 100644 --- a/apps/api/src/modules/loop-engine/port.ts +++ b/apps/api/src/modules/loop-engine/port.ts @@ -77,6 +77,32 @@ export type ListenerRegistrar = { }): Promise<{ id: string }>; }; +/** + * 视图流控 —— app 注入 `interaction`(L3)。 + * 「loop:AI 按定位与局面临场组织视图流」(AM 07)。MVP 每回合推一次**案例全景**: + * 阶段与计划项的生命周期态、当下可为、目标缺口 —— 这些是语义引擎算出来的确定事实, + * 零 LLM 即可成屏;模型只决定「下一步做什么」,不负责画面。 + */ +export type ViewGateway = { + push(input: { + taskId: TaskId; + activityId: string; + template: string; + scope: Record; + }): Promise; +}; + +/** + * 技能 —— app 注入 `skill-engine`(L4)。 + * 「渐进披露:常驻上下文**仅有技能目录**,按事加载正文、按需下钻引用」(AM 08)。 + */ +export type SkillGateway = { + /** 目录:id + 何时适用 —— 只给这些,正文等 AI 说要才加载 */ + index(activityId: string): Promise>; + /** 装配入信封:这一回合装配了哪些技能及其版本,记入任务记忆 */ + stamp(activityId: string, skillIds: readonly string[]): Promise>; +}; + export type MemoryRecorder = { append(input: { taskId: TaskId; diff --git a/packages/activity-sdk/src/index.ts b/packages/activity-sdk/src/index.ts index 6f72953..cda781b 100644 --- a/packages/activity-sdk/src/index.ts +++ b/packages/activity-sdk/src/index.ts @@ -27,4 +27,7 @@ export type { export type { HostOptions, HostRecording, MockHost } from './host.ts'; export { createMockHost } from './host.ts'; +export type { Tone } from './view.ts'; +export { kvCard, noteCard, stagesCard, tableCard, viewShell } from './view.ts'; + export const SDK_VERSION = '0.1.0-m5'; diff --git a/packages/activity-sdk/src/view.ts b/packages/activity-sdk/src/view.ts new file mode 100644 index 0000000..3a9b546 --- /dev/null +++ b/packages/activity-sdk/src/view.ts @@ -0,0 +1,113 @@ +/** + * 视图模版工具箱 —— 活动开发者写「呈现」时看到的世界(AM 07)。 + * + * 模版是**内容不是代码**:这里产出的一律是无脚本、无事件处理器、无外链的静态 HTML; + * 数据由基座在推送时填(`data-slot` 取值、`data-rows` 逐条展开)。 + * 容器是沙箱 iframe(`sandbox=""`),因此**样式必须自带** —— 页面不继承工作台的 CSS。 + * + * 六个活动共用这一套外壳:汇报面貌一致,不是每个活动各自发明一套。 + */ + +export type Tone = 'brand' | 'ok' | 'warn' | 'danger' | 'case' | 'archive'; + +const ACCENT: Readonly> = { + brand: '#3370ff', + ok: '#0aa294', + warn: '#ff8800', + danger: '#e5484d', + case: '#7f3bf5', + archive: '#46586a', +}; + +/** 一套克制的排版;所有尺寸用相对单位,窄栏也不横向溢出 */ +const BASE_CSS = (accent: string): string => ` + :root { color-scheme: light; } + * { box-sizing: border-box; } + body { + margin: 0; padding: 18px; + font: 13px/1.6 -apple-system, "PingFang SC", "Noto Sans SC", "Segoe UI", sans-serif; + color: #1f2933; background: #f7f8fa; + } + .wrap { max-width: 760px; margin: 0 auto; } + .hd { display: flex; align-items: stretch; gap: 12px; margin-bottom: 14px; } + .hd .bar { width: 4px; border-radius: 2px; background: ${accent}; flex: none; } + .hd .kick { font-size: 11px; letter-spacing: .08em; color: #6a7686; } + .hd h1 { margin: 2px 0 0; font-size: 17px; font-weight: 650; letter-spacing: .01em; } + .card { background: #fff; border: 1px solid #e6e9ee; border-radius: 10px; padding: 14px 16px; margin-bottom: 12px; } + .card h2 { margin: 0 0 10px; font-size: 12px; font-weight: 600; color: #6a7686; letter-spacing: .04em; } + .kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px 18px; } + .kv > div { min-width: 0; } + .kv em { display: block; font-style: normal; font-size: 11px; color: #8b95a3; margin-bottom: 2px; } + .kv b { font-size: 14px; font-weight: 600; overflow-wrap: anywhere; } + .tbl-wrap { overflow-x: auto; } + table { width: 100%; border-collapse: collapse; font-size: 12px; } + th { text-align: left; font-weight: 600; color: #6a7686; padding: 6px 8px; border-bottom: 1px solid #e6e9ee; white-space: nowrap; } + td { padding: 7px 8px; border-bottom: 1px solid #f0f2f5; overflow-wrap: anywhere; } + tr:last-child td { border-bottom: 0; } + .mono { font-family: "SF Mono", Menlo, Consolas, monospace; } + .tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; + background: ${accent}1a; color: ${accent}; } + .note { font-size: 11px; color: #8b95a3; margin-top: 10px; line-height: 1.75; } + .steps { list-style: none; margin: 0; padding: 0; } + .steps li { position: relative; padding: 0 0 12px 20px; border-left: 2px solid #e6e9ee; } + .steps li:last-child { padding-bottom: 0; border-left-color: transparent; } + .steps li::before { content: ""; position: absolute; left: -5px; top: 5px; width: 8px; height: 8px; + border-radius: 50%; background: ${accent}; } + .steps .t { font-weight: 600; } + .steps .d { color: #8b95a3; font-size: 11.5px; } +`; + +/** 页头 + 卡片区 —— 每张模版都长这样,只换标题与内容 */ +export function viewShell(input: { + title: string; + kicker: string; + tone: Tone; + body: string; +}): string { + const accent = ACCENT[input.tone]; + return ` +
+
${input.kicker}

${input.title}

+ ${input.body} +
`; +} + +/** 键值卡:`[标签, 取值路径]`;`mono` 用等宽显示编号类字段 */ +export function kvCard(title: string, items: ReadonlyArray): string { + const cells = items + .map(([label, path, style]) => { + const cls = style === undefined ? '' : ` class="${style === 'mono' ? 'mono' : 'tag'}"`; + return `
${label}
`; + }) + .join(''); + return `

${title}

${cells}
`; +} + +/** 逐条表:行数不写死,由 `data-rows` 展开 */ +export function tableCard( + title: string, + rowsPath: string, + columns: ReadonlyArray, + note?: string, +): string { + const head = columns.map(([label]) => `${label}`).join(''); + const cells = columns + .map(([, path, style]) => ``) + .join(''); + return `

${title}

+ ${head} + ${cells} +
${note === undefined ? '' : `

${note}

`}
`; +} + +/** 说明卡:把「为什么这么做」摆在数据旁边 —— 人要在数据上作判断 */ +export function noteCard(title: string, html: string): string { + return `

${title}

${html}

`; +} + +/** 阶段时间线:loop 按案例模型的阶段与里程碑组织汇报(AM 07) */ +export function stagesCard(title: string, rowsPath: string, note?: string): string { + return `

${title}

    +
  • +
${note === undefined ? '' : `

${note}

`}
`; +}