三面拆分⑭:纯编排第三轮 —— 活动卸岗位、卡点废除全真边、边号 E1–En 图上可选

活动契约不带负责人岗位(用户定):
- schema:活动节点删 owner(审批点的 approver 是「卡到人的工位」的功能语义,保留)
- 运行时:活动任务默认**全员轮值**(在岗候选并集、最闲者先、staffId 稳定排序,
  owner-resolved 事件岗位记「(全员轮值)」);运营分派机制落地后让位 —— 债已记
- closure:活动点不核岗位,missing-owner-position 只出自审批点
- 员工面链条:活动点报**实际承接人**(实例→任务→人),没起的如实报「轮值待派」;
  NodeInstance 公开 taskId/approvalId(店面读回,与端口型合流)
- 画布/导出依赖文件/属性卡全线摘岗位;属性卡活动点明说「分派归运营」

卡点画法废除,顺序流一律真边(用户定):
- 种子图重画:四条回跳/直达(E4 直接定价、E6 选型后定价、E10 不通过、E12 有异议)
  全部画成折线真边,车道分层零交叉(顶 y30 / y190 / y230 / 缝隙对开 / 底 y380);
  卡点节点删净,图=恰 10 语义节点 + 14 真边一一对应(测试守着)
- graph-to-pkg 卡点认亲机制删除;pkg-to-graph 直接按 from→to 认亲
- 元素盘删卡点件;图例、属性卡卡点分支、kindLabel/kindTone 随删

边号 E1、E2…(用户定):
- 语义边 id 即边号:种子 E1–E14;合并器铸号(旧边保号、新边取下一空号,回归测试守着)
- 画布线标带号(`E3 直接寻源`,无注记的边也标 `E1`);拣选条以边号立牌,
  **条件不再上按钮** —— 条件/映射只住属性面
- 边在图上可选中:FlowDiagram 连线加宽透明命中垫(边可点时注解层提到形状层上),
  点线即切属性卡到该边(实测 E4 命中)

测试:closure 28、advance-order 6、graph-to-pkg 5(新增铸号例)、seed 8、
端到端八例真库全绿(全员轮值下照跑);五闸退出码验过。
库:purge 后重种,唯一 unified-quote@v1 生效(双面判据齐)。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KeDBx2PHLavbURXB8LJJ7m
This commit is contained in:
2026-07-28 19:02:07 +08:00
co-authored by Claude Fable 5
parent 281f4ef084
commit 7f0d25c337
21 changed files with 361 additions and 436 deletions
@@ -1,14 +1,14 @@
/**
* 流程包(无网关版)—— 守四件事:拓扑齐且零网关、分支即条件出边、
* 审批点两个去向都由图表达、回边标了 reopen。
* 流程包(纯编排版)—— 守四件事:拓扑齐、分支即条件出边、
* 审批点两个去向都由图表达、图上每条语义边都画成真边(卡点画法已废)。
*/
import { describe, expect, it } from 'vitest';
import { MVP_PACKAGE } from '../seed-mvp-flow.ts';
describe('MVP_PACKAGE', () => {
it('10 语义节点 · 14 边 · 一审批点双终点(网关在 schema 里已不存在)', () => {
it('10 语义节点 · 14 边编号 E1–E14 · 一审批点双终点', () => {
expect(MVP_PACKAGE.nodes).toHaveLength(10);
expect(MVP_PACKAGE.edges).toHaveLength(14);
expect(MVP_PACKAGE.edges.map((e) => e.id)).toEqual(Array.from({ length: 14 }, (_, i) => `E${i + 1}`));
expect(MVP_PACKAGE.nodes.filter((n) => n.kind === 'approval')).toHaveLength(1);
expect(MVP_PACKAGE.nodes.filter((n) => n.kind === 'end')).toHaveLength(2);
});
@@ -62,35 +62,29 @@ describe('MVP_PACKAGE', () => {
]);
});
it('手绘图存证:10 语义节点 + 4 卡点(直达两枚是正向边的呈现,回跳两枚照旧)', () => {
it('手绘图存证:恰是 10 个语义节点,零卡点(卡点画法已废)', () => {
const nodes = (MVP_PACKAGE.diagram as { nodes: { id: string; kind: string }[] }).nodes;
expect(nodes.filter((n) => n.kind === 'callout')).toHaveLength(4);
expect(nodes).toHaveLength(14);
expect(nodes.filter((n) => n.kind === 'callout')).toHaveLength(0);
expect(nodes).toHaveLength(10);
const drawn = new Set(nodes.map((n) => n.id));
for (const n of MVP_PACKAGE.nodes) expect(drawn.has(n.id), `图上缺 ${n.id}`).toBe(true);
});
/*
* 语义边必须**每条都画在图上**(直连线,或指向带 `to` 卡点的线)——
* 画布保存由画出来的边反推语义边,没画的那条会在第一次存盘时被静默丢掉
* 语义边必须**每条都画成真边** —— 画布保存由画出来的边反推语义边,
* 没画的那条会在第一次存盘时被静默丢掉
* (实测:A1→A3「直接寻源」漏画,mergeGraphIntoPackage 一过就没了)。
*/
it('图边对账:每条语义边都有画出来的对应(直连或经卡点)', () => {
const dia = MVP_PACKAGE.diagram as {
nodes: { id: string; kind: string; to?: string }[];
edges: { from: string; to: string }[];
};
const calloutTo = new Map(dia.nodes.filter((n) => n.kind === 'callout').map((n) => [n.id, n.to]));
const drawnPairs = new Set(dia.edges.map((e) => `${e.from}→${calloutTo.get(e.to) ?? e.to}`));
for (const e of MVP_PACKAGE.edges) {
expect(drawnPairs.has(`${e.from}→${e.to}`), `语义边 ${e.id}(${e.from}→${e.to})没画在图上`).toBe(true);
}
it('图边对账:每条语义边都画成真边,一一对应', () => {
const dia = MVP_PACKAGE.diagram as { edges: { from: string; to: string }[] };
const drawnPairs = dia.edges.map((e) => `${e.from}→${e.to}`).sort();
const semPairs = MVP_PACKAGE.edges.map((e) => `${e.from}→${e.to}`).sort();
expect(drawnPairs).toEqual(semPairs);
});
it('几何:坐标吸附 10px 珊格,框不重叠', () => {
const nodes = (MVP_PACKAGE.diagram as { nodes: { id: string; kind: string; x: number; y: number }[] }).nodes;
const size = (kind: string) =>
kind === 'callout' ? { w: 100, h: 30 } : kind === 'activity' ? { w: 100, h: 40 } : { w: 20, h: 20 };
const size = (kind: string) => (kind === 'activity' ? { w: 100, h: 40 } : { w: 20, h: 20 });
for (const n of nodes) {
expect(n.x % 10, `${n.id} x`).toBe(0);
expect(n.y % 10, `${n.id} y`).toBe(0);
+27 -17
View File
@@ -93,29 +93,39 @@ export function registerDeskRoutes(app: Hono<AppEnv>, container: Container): voi
return await Promise.all(
nodes.map(async (n) => {
const spec = n.kind === 'approval' ? n.approver : n.owner;
/*
* 报谁,要和**真正派单时的口径一致**(ADR-011:绑定先于策略)。
* 只按岗位报人的话,装了工作组的单会当面说谎:整条流实际都归起单人,
* 链上却写着各岗位的常驻人。所以这里也先看工作组绑定,再退回岗位解析。
* 报谁,要和**真正派单时的口径一致**。
* 审批点:ADR-011 绑定先于策略 —— 先看工作组绑定,再退回岗位解析。
* 活动点:契约不带岗位(分派归运营)—— 起了单的报**实际承接人**(任务上的),
* 还没起的如实报「轮值待派」,不编造具体承接人。
*/
const bound = workflow.workGroup?.[spec.position];
const boundStaff =
bound === undefined
? undefined
: await container.org.getStaff(staffIdSchema.parse(bound)).catch(() => undefined);
// 岗位唯一解析(sole)即报人名;否则只报岗位 —— 不编造具体承接人
const holders =
boundStaff !== undefined ? [] : await container.org.staffOfPosition(spec.position).catch(() => []);
const who = boundStaff ?? (holders.length === 1 ? holders[0] : undefined);
let who;
let fallbackName = '轮值待派';
let fallbackRole = '全员轮值';
if (n.kind === 'approval') {
const spec = n.approver;
fallbackName = spec.position;
fallbackRole = spec.position;
const bound = workflow.workGroup?.[spec.position];
const boundStaff =
bound === undefined
? undefined
: await container.org.getStaff(staffIdSchema.parse(bound)).catch(() => undefined);
// 岗位唯一解析(sole)即报人名;否则只报岗位
const holders =
boundStaff !== undefined ? [] : await container.org.staffOfPosition(spec.position).catch(() => []);
who = boundStaff ?? (holders.length === 1 ? holders[0] : undefined);
} else {
const inst = instances.find((x) => x.nodeId === n.id && x.taskId !== undefined);
const owned = inst?.taskId === undefined ? undefined : await container.task.get(taskIdSchema.parse(inst.taskId)).catch(() => undefined);
who = owned === undefined ? undefined : await container.org.getStaff(owned.ownerId).catch(() => undefined);
}
return {
nodeId: n.id,
label: n.label,
kind: n.kind === 'approval' ? ('approval' as const) : ('activity' as const),
ownerName: who?.name ?? spec.position,
ownerRole: who?.position.name ?? spec.position,
ownerName: who?.name ?? fallbackName,
ownerRole: who?.position.name ?? fallbackRole,
state:
n.id === task.nodeId
? ('current' as const)
+90 -82
View File
@@ -1,34 +1,23 @@
/**
* 「统一报价」流程包 —— **无网关**:语义取自 `docs/MVP示例工作流.html`,结构按新模型展开。
* 「统一报价」流程包 —— **纯编排**:语义取自 `docs/MVP示例工作流.html`,结构按新模型展开。
*
* 分支 = 源节点的条件出边(恰取一条,无条件边作默认兜底);汇合 = 多入边异或。
* FIG.1 的 G1/G2/G4 各自消失成 A1/A2/A6 的条件出边;G2J 与 G3 整颗不再需要。
* 10 节点 14 边;审批点 A5 的两个去向就是它自己的两条条件出边(verdict 由引擎注入)。
* 节点只分活动点与审批点(起止是结构件);分支 = 源节点的条件出边(恰取一条,
* 无条件边作默认兜底);汇合 = 多入边异或。活动契约不带负责人岗位 —— 分派归运营。
* 10 节点 14 边(E1–E14);审批点 A5 的两个去向就是它自己的两条条件出边(verdict 由引擎注入)。
*
* 几何:两带换行、零交叉;直达与回跳都用**卡点**表达(不画长线)——
* 卡点带 `to`,`mergeGraphIntoPackage` 只认语义边已存在的还原,编辑器保存不丢边。
* 几何:顺序流一律画成**真边**(卡点画法已废除,2026-07-28 第三轮),零交叉:
* 直达与回跳各占一条车道,长线避框走 —— 见 diagram 里逐段注记。
*/
import { processPackageSchema, triggerConfigSchema } from '@contracts';
import type { ProcessPackage } from '@contracts';
import type { Container } from './container.ts';
/** 活动节点:岗位独任、失败即终止 —— 槽位期不谈容忍 */
const activityNode = (
id: string,
label: string,
activityId: string,
position: string,
col: number,
row: number,
x: number,
y: number,
) => ({
/** 活动节点:失败即终止(槽位期不谈容忍);岗位不入契约 —— 分派归运营 */
const activityNode = (id: string, label: string, activityId: string, col: number, row: number, x: number, y: number) => ({
id,
kind: 'activity' as const,
label,
sub: position,
activityId,
owner: { position, strategy: 'sole' as const },
failure: { kind: 'terminate' as const },
layout: { row, col, x, y },
});
@@ -60,21 +49,16 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({
output: { type: 'object', properties: { landingRate: { type: 'number' } } },
},
/*
* **无网关**(产品决策 2026-07-28):分支 = 源节点的多条条件出边(恰取一条,
* 无条件边作默认兜底),汇合 = 多入边异或(上游互斥,只会来一条)。
* 与 Mastra 同构:条件挂在步与步之间,步保持纯粹。
* FIG.1 的 G1/G2/G4 于是各自消失成 A1/A2/A6 的条件出边;
* G2J(当年为绕「隐式合并」禁令而生的显式汇合点)与 G3(审批结果)整颗不再需要 ——
* A4 的三条正向入边互斥即合法,A5 的裁决就是它自己的两条条件出边。
*
* 10 节点:start · A1 受理 · A2 选型 · A3 寻源 · A4 定价 · A5 审批 · A6 议价 · A7 归档 · 双终点。
* 原 G1/G2/G4 各自消失成 A1/A2/A6 的条件出边;G2J 与 G3 整颗不再需要 ——
* A4 的三条正向入边互斥即合法,A5 的裁决就是它自己的两条条件出边。
*/
nodes: [
{ id: 'start', kind: 'start', label: '客户RFQ询价', layout: { row: 0, col: 0, x: 30, y: 70 } },
activityNode('A1', '客户RFQ受理', 'rfq-intake', 'BD', 1, 0, 110, 60),
activityNode('A2', '替代选型', 'alt-selection', 'FAE', 2, 0, 290, 60),
activityNode('A3', '寻源询价', 'sourcing-inquiry', 'PRM', 3, 0, 470, 60),
activityNode('A4', '成本定价', 'cost-pricing', 'BD', 4, 1, 110, 310),
activityNode('A1', '客户RFQ受理', 'rfq-intake', 1, 0, 110, 60),
activityNode('A2', '替代选型', 'alt-selection', 2, 0, 290, 60),
activityNode('A3', '寻源询价', 'sourcing-inquiry', 3, 0, 470, 60),
activityNode('A4', '成本定价', 'cost-pricing', 4, 1, 110, 310),
{
id: 'A5',
kind: 'approval',
@@ -83,7 +67,7 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({
approver: { position: 'PM', strategy: 'sole' },
/*
* 驳回走向声明式,不由临场决定:退回 A4 重新定价。
* 图上由 A5 自己的 `verdict = "reject"` 条件出边**显式表达同一件事**,
* 图上由 A5 自己的 `verdict = "reject"` 条件出边(E10)**显式表达同一件事**,
* 引擎先看图(有边走边,没边才退回本声明),两处须字字对齐 —— 有测试守着。
* 本声明不能删:schema 必填,且它是通用机制(不是每条流都把驳回画成边)。
*/
@@ -91,14 +75,14 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({
nudge: { steps: [{ after: 'PT20M', action: 'nudge' }], deadline: 'PT30M' },
layout: { row: 1, col: 5, x: 290, y: 310 },
},
activityNode('A6', '报价议价', 'quote-negotiation', 'BD', 6, 1, 470, 310),
activityNode('A7', '情报归档', 'intel-archive', 'BD', 7, 2, 630, 410),
activityNode('A6', '报价议价', 'quote-negotiation', 6, 1, 470, 310),
activityNode('A7', '情报归档', 'intel-archive', 7, 2, 630, 410),
{ id: 'end_won', kind: 'end', label: '转订单履约', layout: { row: 1, col: 7, x: 630, y: 320 } },
{ id: 'end_arch', kind: 'end', label: '归档闭环', layout: { row: 2, col: 8, x: 790, y: 420 } },
],
edges: [
{
id: 'e-start-a1',
id: 'E1',
from: 'start',
to: 'A1',
mapping: [
@@ -113,7 +97,7 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({
/* A1 的三条出边 —— 原 G1「是否需要选型」+ G2「是否需要寻源」在直达路径上的合并展开 */
{
id: 'e-a1-a2',
id: 'E2',
from: 'A1',
to: 'A2',
condition: 'needAlternative = true',
@@ -126,7 +110,7 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({
reopen: false,
},
{
id: 'e-a1-a3',
id: 'E3',
from: 'A1',
to: 'A3',
condition: 'needAlternative = false and needSourcing = true',
@@ -135,11 +119,11 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({
reopen: false,
},
// 默认兜底:不选型不寻源 → 直接定价(条件全不中时走它,旗齐时它就是第三种情形)
{ id: 'e-a1-a4', from: 'A1', to: 'A4', label: '直接定价', mapping: REENTER_A4, reopen: false },
{ id: 'E4', from: 'A1', to: 'A4', label: '直接定价', mapping: REENTER_A4, reopen: false },
/* A2 的两条出边 —— 原 G2 在选型路径上的那一问 */
{
id: 'e-a2-a3',
id: 'E5',
from: 'A2',
to: 'A3',
condition: 'needSourcing = true',
@@ -147,10 +131,10 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({
mapping: [{ target: 'pn', source: { from: 'output-port', port: 'intake', path: 'pn' } }],
reopen: false,
},
{ id: 'e-a2-a4', from: 'A2', to: 'A4', label: '选型后定价', mapping: REENTER_A4, reopen: false },
{ id: 'E6', from: 'A2', to: 'A4', label: '选型后定价', mapping: REENTER_A4, reopen: false },
{
id: 'e-a3-a4',
id: 'E7',
from: 'A3',
to: 'A4',
label: '供应商底价表',
@@ -161,11 +145,11 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({
],
reopen: false,
},
{ id: 'e-a4-a5', from: 'A4', to: 'A5', mapping: [], label: '报价草案提审', reopen: false },
{ id: 'E8', from: 'A4', to: 'A5', mapping: [], label: '报价草案提审', reopen: false },
/* A5 审批点自己的两条条件出边 —— 裁决(verdict)由引擎在裁决时放进载荷 */
{
id: 'e-a5-a6',
id: 'E9',
from: 'A5',
to: 'A6',
condition: 'verdict = "pass"',
@@ -179,7 +163,7 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({
reopen: false,
},
{
id: 'e-a5-a4',
id: 'E10',
from: 'A5',
to: 'A4',
condition: 'verdict = "reject"',
@@ -192,7 +176,7 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({
/* A6 的三条条件出边 —— outcome 由放行选口给出(选择组恰选一口) */
{
id: 'e-a6-won',
id: 'E11',
from: 'A6',
to: 'end_won',
condition: 'outcome = "won"',
@@ -202,7 +186,7 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({
reopen: false,
},
{
id: 'e-a6-a4',
id: 'E12',
from: 'A6',
to: 'A4',
condition: 'outcome = "revise"',
@@ -212,7 +196,7 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({
reopen: true,
},
{
id: 'e-a6-a7',
id: 'E13',
from: 'A6',
to: 'A7',
condition: 'outcome = "lost"',
@@ -227,17 +211,19 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({
],
reopen: false,
},
{ id: 'e-a7-end', from: 'A7', to: 'end_arch', mapping: [], label: '归档闭环', reopen: false },
{ id: 'E14', from: 'A7', to: 'end_arch', mapping: [], label: '归档闭环', reopen: false },
],
variables: [],
/*
* 手绘几何存证 —— 呈现以它为真相。两带换行、零交叉:
* 顶车道 y30:A1「直接寻源」跨过 A2 直达 A3(带上方,不碰任何框)
* 带 0(y60) start → A1 → A2 → A3 受理 · 选型 · 寻源
* 换行车道 y190:A3 右探下折横扫回左,进 A4 北口
* 带 1(y310) A4 → A5 → A6 → end_won 定价 · 审批 · 议价 · 成交
* 带 2(y410) A7 → end_arch 未成交闭环
* 直达与回跳都用**卡点**表达(不画长线):A1/A2 的「直接定价」牌与 A5/A6 的回 A4 牌。
* 手绘几何存证 —— 呈现以它为真相。顺序流全是真边,零交叉:
* 顶车道 y30:E3 直接寻源(A1 北口 → A3 北口,跨过 A2)
* 带 0(y60–100) start → A1 → A2 → A3
* E4 直接定价:A1 南口 x130 直落 A4 北口(x130 在所有横车道的左端之外)
* 车道 y190:E6 选型后定价(A2 南口 x310 落下,西行,x160 进 A4 北口)
* 车道 y230:E7 供应商底价表(A3 东探 x610 下行,西扫,x200 进 A4 北口)
* 带 1(y310–350) A4 → A5 → A6 → end_won;E8/E10 在 A4–A5 缝隙里一上一下对开
* 车道 y380:E12 有异议(A6 南口 x500 落下,西扫,x160 上顶 A4 南口)
* E13 拒绝/超时:A6 南口 x520 下行右拐进 A7;带 2(y410+) A7 → end_arch
*/
diagram: {
manual: true,
@@ -245,25 +231,20 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({
anchors: [],
nodes: [
{ id: 'start', kind: 'start', label: '客户RFQ询价', x: 30, y: 70, lx: 44, ly: 104 },
{ id: 'A1', kind: 'activity', label: '客户RFQ受理', code: 'A1', owner: 'BD', x: 110, y: 60 },
{ id: 'A2', kind: 'activity', label: '替代选型', code: 'A2', owner: 'FAE', x: 290, y: 60 },
{ id: 'A3', kind: 'activity', label: '寻源询价', code: 'A3', owner: 'PRM', x: 470, y: 60 },
{ id: 'A4', kind: 'activity', label: '成本定价', code: 'A4', owner: 'BD', x: 110, y: 310 },
{ id: 'A1', kind: 'activity', label: '客户RFQ受理', code: 'A1', x: 110, y: 60 },
{ id: 'A2', kind: 'activity', label: '替代选型', code: 'A2', x: 290, y: 60 },
{ id: 'A3', kind: 'activity', label: '寻源询价', code: 'A3', x: 470, y: 60 },
{ id: 'A4', kind: 'activity', label: '成本定价', code: 'A4', x: 110, y: 310 },
{ id: 'A5', kind: 'activity', label: '定价审批', code: 'A5', owner: 'PM', flavor: 'approval', x: 290, y: 310 },
{ id: 'A6', kind: 'activity', label: '报价议价', code: 'A6', owner: 'BD', x: 470, y: 310 },
{ id: 'A7', kind: 'activity', label: '情报归档', code: 'A7', owner: 'BD', x: 630, y: 410 },
{ id: 'A6', kind: 'activity', label: '报价议价', code: 'A6', x: 470, y: 310 },
{ id: 'A7', kind: 'activity', label: '情报归档', code: 'A7', x: 630, y: 410 },
{ id: 'end_won', kind: 'end', label: '转订单履约', x: 630, y: 320, lx: 640, ly: 352 },
{ id: 'end_arch', kind: 'end-bad', label: '归档闭环', x: 790, y: 420, lx: 800, ly: 452 },
/* 四枚卡点:直达两枚(正向,语义边真实存在)、回跳两枚 —— 全在各自源节点的上下车道 */
{ id: 'c_d1', kind: 'callout', label: '直接定价', to: 'A4', x: 110, y: 170 },
{ id: 'c_d2', kind: 'callout', label: '选型后定价', to: 'A4', x: 290, y: 170 },
{ id: 'c_reject', kind: 'callout', label: '退回调整', to: 'A4', x: 290, y: 240 },
{ id: 'c_revise', kind: 'callout', label: '返回调整', to: 'A4', x: 470, y: 240 },
],
edges: [
{ from: 'start', to: 'A1', points: [{ x: 50, y: 80 }, { x: 110, y: 80 }] },
{ from: 'A1', to: 'A2', label: '需要选型', points: [{ x: 210, y: 80 }, { x: 290, y: 80 }] },
// 直接寻源走顶车道 y30(A1 北口 → A3 北口):画布保存只认画出来的边,这条不画就会丢
// E3 顶车道:跨过 A2 直达 A3 北口
{
from: 'A1',
to: 'A3',
@@ -275,32 +256,59 @@ export const MVP_PACKAGE: ProcessPackage = processPackageSchema.parse({
{ x: 520, y: 60 },
],
},
// E4 直落:x130 在 E6(x160 起)与 E7(x200 起)两条横车道左端之外,零交叉
{ from: 'A1', to: 'A4', label: '直接定价', lx: 88, ly: 200, points: [{ x: 130, y: 100 }, { x: 130, y: 310 }] },
{ from: 'A2', to: 'A3', label: '仍需寻源', points: [{ x: 390, y: 80 }, { x: 470, y: 80 }] },
// 换行那一笔:A3 右探 → 降到 190 车道 → 横扫回左 → 落 A4 北口
// E6 车道 y190:A2 南口下行、西行、进 A4 北口
{
from: 'A3',
from: 'A2',
to: 'A4',
label: '供应商底价表',
// 标注钉在 y190 车道的空档(x390–610)—— 默认取折线中点,会被「选型后定价→A4」卡点压住
lx: 450,
ly: 183,
label: '选型后定价',
lx: 235,
ly: 182,
points: [
{ x: 570, y: 80 },
{ x: 610, y: 80 },
{ x: 610, y: 190 },
{ x: 310, y: 100 },
{ x: 310, y: 190 },
{ x: 160, y: 190 },
{ x: 160, y: 310 },
],
},
// 直达两枚卡点(正向):不选不寻 → 直接定价;选完不寻 → 定价
{ from: 'A1', to: 'c_d1', label: '不选不寻', points: [{ x: 160, y: 100 }, { x: 160, y: 170 }] },
{ from: 'A2', to: 'c_d2', label: '不再寻源', points: [{ x: 340, y: 100 }, { x: 340, y: 170 }] },
{ from: 'A4', to: 'A5', label: '报价草案提审', points: [{ x: 210, y: 330 }, { x: 290, y: 330 }] },
// E7 车道 y230:A3 东探绕行(x610),在 E6 之下、A5 上行线之上零交叉扫回
{
from: 'A3',
to: 'A4',
label: '供应商底价表',
lx: 420,
ly: 222,
points: [
{ x: 570, y: 80 },
{ x: 610, y: 80 },
{ x: 610, y: 230 },
{ x: 200, y: 230 },
{ x: 200, y: 310 },
],
},
// E8/E10:A4–A5 缝隙里一上一下对开(y320 提审,y340 退回)
{ from: 'A4', to: 'A5', label: '报价草案提审', lx: 250, ly: 312, points: [{ x: 210, y: 320 }, { x: 290, y: 320 }] },
{ from: 'A5', to: 'A6', label: '通过', tone: 'ok', points: [{ x: 390, y: 330 }, { x: 470, y: 330 }] },
{ from: 'A5', to: 'c_reject', label: '不通过', tone: 'bad', points: [{ x: 340, y: 310 }, { x: 340, y: 270 }], lx: 310, ly: 292 },
{ from: 'A5', to: 'A4', label: '不通过', tone: 'bad', lx: 250, ly: 352, points: [{ x: 290, y: 340 }, { x: 210, y: 340 }] },
{ from: 'A6', to: 'end_won', label: '成交', tone: 'ok', points: [{ x: 570, y: 330 }, { x: 630, y: 330 }] },
{ from: 'A6', to: 'c_revise', label: '有异议', tone: 'bad', points: [{ x: 520, y: 310 }, { x: 520, y: 270 }], lx: 545, ly: 292 },
{ from: 'A6', to: 'A7', label: '拒绝/超时', tone: 'bad', points: [{ x: 520, y: 350 }, { x: 520, y: 430 }, { x: 630, y: 430 }], lx: 545, ly: 388 },
// E12 车道 y380:A6 南口西扫,上顶 A4 南口
{
from: 'A6',
to: 'A4',
label: '有异议',
tone: 'bad',
lx: 330,
ly: 372,
points: [
{ x: 500, y: 350 },
{ x: 500, y: 380 },
{ x: 160, y: 380 },
{ x: 160, y: 350 },
],
},
{ from: 'A6', to: 'A7', label: '拒绝/超时', tone: 'bad', lx: 560, ly: 405, points: [{ x: 520, y: 350 }, { x: 520, y: 430 }, { x: 630, y: 430 }] },
{ from: 'A7', to: 'end_arch', label: '归档闭环', points: [{ x: 730, y: 430 }, { x: 790, y: 430 }] },
],
},
+12 -4
View File
@@ -29,14 +29,22 @@
随手画的半成品也存得进来(存出来即 `retired`,不生效);`setPackageState` 激活时
跑 `checkClosure`,不闭合抛 `NotClosedError`(HTTP 412 带整份报告)。
违规项:未完成边、必填未映射、类型冲突、孤立节点、多默认出边、
活动未装载、岗位不存在、容忍分支被下游必填依赖 —— 任一即 `closed = false`,激活被拒。
- **纯编排模型**(产品决策 2026-07-28 第二轮):流程包只决定**活动编排**与
活动未装载、审批岗位不存在、容忍分支被下游必填依赖 —— 任一即 `closed = false`,激活被拒。
(活动点不核岗位 —— 契约不带负责人,`missing-owner-position` 只出自审批点。)
- **纯编排模型**(产品决策 2026-07-28 二、三轮):流程包只决定**活动编排**与
**活动传递的契约**,不决定活动的实现方式(范式/版本住活动库,节点仅以
`activityId` 链接)。节点只分**活动点**与**审批点**(起点/终点是结构件);
`kind: 'gateway'` 已从 schema 摘除(库经外科手术清空,无历史包袱)。
`activityId` 链接),**也不带负责人岗位**(分派归运营;运营分派机制未建前,
活动任务运行时默认全员轮值 —— 在岗候选并集、最闲者先、staffId 稳定排序。
审批点例外:「卡到人的工位」是它的功能语义,`approver` 留在声明里,
工作组绑定 ADR-011 也只对它生效)。节点只分**活动点**与**审批点**
(起点/终点是结构件);`kind: 'gateway'` 已从 schema 摘除。
分支 = 源节点的多条条件出边(恰取一条,无条件边作默认兜底、至多一条),
汇合 = 多入边异或(上游互斥,只会来一条 —— `joinReady` 已删,没有「等回齐」)。
AND 并行暂无声明机制,将来以「并行组」加回(对应 Mastra `.parallel`,见 debt.md)。
- **边有编号身份**:语义边 id 即边号(E1、E2…,服务端/合并器铸号,旧边保号、
新边取下一个空号);画布线标带号、边在图上可选中,条件与映射住属性面。
顺序流一律画成**真边**(卡点画法已废除)—— 画布保存由画出来的边反推语义边,
图上没画的语义边会在存盘时丢失,种子与测试按「一一对应」守着。
- **激活双判据**:①图编排闭合完善(结构 + 属性 + 传递契约,`checkClosure` 的
非 unknown-activity 项)②活动装载(节点链接的实现已安装,`unknown-activity` 项)。
两面都清零才可激活;图照画照存,未装载不拦保存。
@@ -34,7 +34,6 @@ const pkg = (over: Partial<ProcessPackage> = {}): ProcessPackage =>
kind: 'activity',
label: 'A4 成本定价',
activityId: 'a4' as never,
owner: { position: 'BD', strategy: 'sole' },
failure: { kind: 'terminate' },
},
{ id: 'end' as never, kind: 'end', label: '终点' },
@@ -101,9 +100,31 @@ describe('checkClosure —— 不闭合不得激活', () => {
expect(report.violations.map((v) => v.kind)).toContain('unknown-activity');
});
it('岗位不存在即拦', () => {
const report = checkClosure({ pkg: pkg(), contracts, positions: new Set(['PM']) });
expect(report.violations.map((v) => v.kind)).toContain('missing-owner-position');
/* 活动点不核岗位(契约不带负责人);审批点的岗位是功能语义,不存在即拦 */
it('审批点岗位不存在即拦;活动点没有岗位可核', () => {
const withApproval = pkg({
nodes: [
...pkg().nodes,
{
id: 'AP' as never,
kind: 'approval',
label: '审批',
approver: { position: 'GONE', strategy: 'sole' },
reject: { kind: 'terminate' },
},
],
edges: [
...pkg().edges.filter((e) => e.id !== 'e2'),
{ id: 'e2', from: 'A4' as never, to: 'AP' as never, mapping: [], reopen: false },
{ id: 'e3', from: 'AP' as never, to: 'end' as never, mapping: [], reopen: false },
],
});
const violations = checkClosure({ pkg: withApproval, contracts, positions }).violations;
expect(violations.filter((v) => v.kind === 'missing-owner-position').map((v) => v.nodeId)).toEqual(['AP']);
// 活动节点引用的岗位集合再小也与它无关 —— 不产生岗位类违规
const noPositions = checkClosure({ pkg: pkg(), contracts, positions: new Set() }).violations;
expect(noPositions.filter((v) => v.kind === 'missing-owner-position')).toEqual([]);
});
it('孤立节点即拦', () => {
@@ -115,7 +136,6 @@ describe('checkClosure —— 不闭合不得激活', () => {
kind: 'activity',
label: '游离节点',
activityId: 'a4' as never,
owner: { position: 'BD', strategy: 'sole' },
failure: { kind: 'terminate' },
},
],
@@ -156,7 +176,6 @@ describe('checkClosure —— 不闭合不得激活', () => {
kind: 'activity',
label: 'A3 渠道寻源',
activityId: 'a4' as never,
owner: { position: 'PRM', strategy: 'sole' },
failure: { kind: 'tolerate' },
},
{
@@ -164,7 +183,6 @@ describe('checkClosure —— 不闭合不得激活', () => {
kind: 'activity',
label: 'A4 成本定价',
activityId: 'a4' as never,
owner: { position: 'BD', strategy: 'sole' },
failure: { kind: 'terminate' },
},
{ id: 'end' as never, kind: 'end', label: '终点' },
@@ -126,6 +126,8 @@ export function createProcessStore(db: Db): ProcessStore {
activated: r.activated,
...(r.terminal === null ? {} : { terminal: r.terminal as TerminalState }),
...(r.failureDigested === null ? {} : { failureDigested: r.failureDigested }),
...(r.taskId === null ? {} : { taskId: r.taskId }),
...(r.approvalId === null ? {} : { approvalId: r.approvalId }),
}),
);
},
@@ -57,8 +57,9 @@ export function checkClosure(input: ClosureInput): ClosureReport {
}
if (node.kind === 'activity') {
violations.push(...checkActivityNode(node, incoming.get(node.id) ?? [], contracts, positions));
violations.push(...checkActivityNode(node, incoming.get(node.id) ?? [], contracts));
}
// 活动点不核岗位(契约不带负责人 —— 分派归运营);审批点的岗位是功能语义,照核
if (node.kind === 'approval' && !positions.has(node.approver.position)) {
violations.push({
kind: 'missing-owner-position',
@@ -94,7 +95,6 @@ function checkActivityNode(
node: Extract<ProcessNode, { kind: 'activity' }>,
inbound: readonly Edge[],
contracts: ReadonlyMap<string, ActivityContractFace>,
positions: ReadonlySet<string>,
): ClosureViolation[] {
const out: ClosureViolation[] = [];
const face = contracts.get(node.activityId);
@@ -108,14 +108,6 @@ function checkActivityNode(
return out;
}
if (!positions.has(node.owner.position)) {
out.push({
kind: 'missing-owner-position',
nodeId: node.id,
message: `节点「${node.label}」的岗位不存在:${node.owner.position}`,
});
}
// 连一条边即须完成该边映射
for (const edge of inbound) {
if (edge.mapping.length === 0) {
@@ -120,6 +120,9 @@ export type NodeInstance = {
readonly failureDigested?: boolean;
/** XOR 未选分支从未激活 —— 不入集合 */
readonly activated: boolean;
/** 该实例派出的任务 / 审批(结构件与终点没有)—— 链条视图按它报实际承接人 */
readonly taskId?: string;
readonly approvalId?: string;
};
export function aggregateWorkflowState(
@@ -1,7 +1,7 @@
/**
* process 用例 —— 流程引擎:确定性流转,**零 LLM、零临场**(编码规范 §5.3;语义出处 OS 03 / 04)。
*
* 起单 · 调度节点 · 审批点卡工位 · 网关分合 · 每次流转记入事件。
* 起单 · 调度节点 · 审批点卡工位 · 条件出边选路 · 每次流转记入事件。
*/
import type { ProcessNode, ProcessPackage, StaffId, TerminalState, WorkflowState } from '@contracts';
import type { ProcessService, StartWorkflowInput } from '../../contract.ts';
@@ -87,7 +87,7 @@ export function createProcessService(deps: ProcessServiceDeps): ProcessService {
const dispatch = dispatchOf(node, payload);
if (dispatch === undefined) {
// 网关本身不是责任单元:直接继续流转
// 只剩起点会走到这(结构件无调度):被指为目标时直通,不建实例
await advanceFrom(record, pkg, node.id, payload);
return;
}
@@ -122,15 +122,31 @@ export function createProcessService(deps: ProcessServiceDeps): ProcessService {
return;
}
// 负责人 / 审批人:编排声明岗位,起单时确定性解析;结果与依据留痕
const spec = dispatch.kind === 'start-task' ? dispatch.node.owner : dispatch.node.approver;
const candidates = await deps.org.candidates(spec.position);
/*
* 绑定先于策略:工作组说了这个岗位是谁,策略就无从发问(ADR-011)。
* 在岗与否在这里核 —— 绑定是**跨岗位**指派,拿该岗位的候选集核不了它。
* 谁来干:**活动契约不带岗位**(纯编排,2026-07-28 第三轮)—— 分派是运营的事。
* 运营分派机制未建前,活动任务默认**全员轮值**(在岗候选并集,最闲者先,
* staffId 稳定排序保证同输入必同结果);审批点例外,「卡到人的工位」是它的
* 功能语义,仍按 approver 岗位解析,工作组绑定(ADR-011)也只对它生效。
*/
const boundTo = record.workGroup?.[spec.position];
const bound = boundTo !== undefined && (await deps.org.isActive(boundTo)) ? boundTo : undefined;
let spec;
let candidates;
let bound;
if (dispatch.kind === 'start-task') {
spec = { position: '(全员轮值)', strategy: 'sole' as const };
const seen = new Map<string, { staffId: string; name: string; openTasks: number }>();
for (const position of await deps.org.positions()) {
for (const c of await deps.org.candidates(position)) if (!seen.has(c.staffId)) seen.set(c.staffId, c);
}
candidates = [...seen.values()];
bound = undefined;
} else {
spec = dispatch.node.approver;
candidates = await deps.org.candidates(spec.position);
// 绑定先于策略:工作组说了这个岗位是谁,策略就无从发问(ADR-011)。
// 在岗与否在这里核 —— 绑定是**跨岗位**指派,拿该岗位的候选集核不了它。
const boundTo = record.workGroup?.[spec.position];
bound = boundTo !== undefined && (await deps.org.isActive(boundTo)) ? boundTo : undefined;
}
const resolution = resolveOwner(spec, { candidates, ...(bound === undefined ? {} : { bound }) });
if (resolution.kind === 'vacant') throw new PositionVacantError(spec.position);