forked from ChaiHao/BPOS-MVP
G2 之后一直不分流,根因三条,逐条修: ① 输出口载荷是空的。`outputPortsOf` 原先从**作用域**里捞字段拼载荷, 而放行那一刻草稿层已合并并清空,捞到的只剩起单入参 —— 下游节点必然缺字段。 改为:载荷取自**落地收敛的事实**,由 `releaseWrite` 回报合并了哪些行, 经 release → task → app 一路带上来。这也正是「落地收敛,输出口才发射」的字面意思: 发射的就该是已经落地的那些事实。 `LandedFacts` 给两种读法:铺平(标量取值)与逐行(数组取值), 输出口声明里 `type: 'array'` 的属性填逐行,标量属性填铺平值(驼峰/下划线两种写法都认)。 ② 一条分支起不来,把整条终态上报连坐掀翻 —— 于是**上游任务的终态也报不上去**, 流停在原地,一行日志都没有。改为:该分支记 `node-start-failed` 事件 + 落一个 blocked 实例,其余分支照走,在治理台「需处置」里现形。 (这条是先修的:正因为它,前面两条才一直查不出来。) ③ 边映射引用了不存在的路径:`G2→A3` 的 pn 取 `intake.records`(那是想象中的 LLM 出参形状)、 `G2J→A4` 的 records 取 `initiation.records`(起单时根本还没有这些行)。 按输出口的真实声明改正。 结果:A1 released → G2 并行分叉 → **A3 渠道寻源落到林佩萱、A2 替代选型落到王梓名**, 两个 loop 活动同时在跑,岗位解析正确。 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
114 lines
4.5 KiB
TypeScript
114 lines
4.5 KiB
TypeScript
/**
|
|
* module: ledger —— 对外类型(编码规范 §10.1)。只有类型和常量,没有实现。
|
|
*/
|
|
import type {
|
|
LedgerAddress,
|
|
LedgerKey,
|
|
LedgerPage,
|
|
LedgerQuery,
|
|
LedgerRow,
|
|
ObjectDeclaration,
|
|
TaskId,
|
|
WriteKind,
|
|
} from '@contracts';
|
|
import type { MaterializedObject, MergeConflict, MergeNotice, MergedObject } from './internal/domain/schema-merge.ts';
|
|
import type { ConflictFinding } from './internal/domain/task-view.ts';
|
|
|
|
export type { LedgerAddress, LedgerKey, LedgerPage, LedgerQuery, LedgerRow, ObjectDeclaration, WriteKind };
|
|
export type { MaterializedObject, MergeConflict, MergeNotice, MergedObject, ConflictFinding };
|
|
|
|
export class DraftConflictError extends Error {
|
|
constructor(readonly findings: readonly ConflictFinding[]) {
|
|
super(`草稿与正式版并发冲突:${findings.length} 处字段已被他单改动`);
|
|
this.name = 'DraftConflictError';
|
|
}
|
|
}
|
|
|
|
export class SchemaConflictError extends Error {
|
|
constructor(readonly conflicts: readonly MergeConflict[]) {
|
|
super(`台账声明语义互斥,交数据管理裁决:${conflicts.map((c) => `${c.field}(${c.message})`).join('; ')}`);
|
|
this.name = 'SchemaConflictError';
|
|
}
|
|
}
|
|
|
|
export class ObjectNotMaterializedError extends Error {
|
|
constructor(readonly address: string) {
|
|
super(`台账对象未物化:${address}`);
|
|
this.name = 'ObjectNotMaterializedError';
|
|
}
|
|
}
|
|
|
|
/** 声明合并与物化的结果 —— 安装静态审读它:conflicts 非空即不上架 */
|
|
export type SchemaApplyResult = {
|
|
readonly merged: MergedObject | undefined;
|
|
readonly notices: readonly MergeNotice[];
|
|
readonly conflicts: readonly MergeConflict[];
|
|
readonly applied: boolean;
|
|
};
|
|
|
|
export type ObjectAddress = { readonly domain: string; readonly object: string };
|
|
|
|
export type SystemWrite = {
|
|
readonly address: ObjectAddress;
|
|
readonly key: LedgerKey;
|
|
readonly values: LedgerRow;
|
|
/** 归因:哪条入站 / 哪次流转产生了这次系统写 */
|
|
readonly cause: { readonly kind: 'inbound' | 'engine' | 'governance'; readonly ref: string };
|
|
/** 系统写也可挂到任务上(入站归一到某任务),数据事件的目标即它 */
|
|
readonly taskId?: TaskId;
|
|
};
|
|
|
|
export type DraftWrite = {
|
|
readonly taskId: TaskId;
|
|
readonly address: ObjectAddress;
|
|
readonly key: LedgerKey;
|
|
readonly patch: LedgerRow;
|
|
readonly tombstone?: boolean;
|
|
};
|
|
|
|
export type ReleaseWriteResult = {
|
|
readonly mergedRows: number;
|
|
readonly emittedEvents: number;
|
|
/**
|
|
* 合并进正式版的那些行(键 + 值)。
|
|
* 「落地收敛,输出口才发射」——发射的载荷就该是**这些已落地的事实**,
|
|
* 而不是从作用域里再猜一遍:放行后草稿层已清空,再猜就什么也猜不到。
|
|
*/
|
|
readonly merged: ReadonlyArray<{
|
|
readonly domain: string;
|
|
readonly object: string;
|
|
readonly key: Record<string, unknown>;
|
|
readonly values: Record<string, unknown>;
|
|
}>;
|
|
};
|
|
|
|
/**
|
|
* 写三分是**三个不同方法**,不是一个带 flag 的方法 —— 调用方拿不到「绕门」的形态(§7.2)。
|
|
* systemWrite —— 登记世界已发生的事实,不过放行门,写正式版并**即时**抛数据事件
|
|
* draftWrite —— 任务级草稿层,读己之写,**不抛**事件
|
|
* releaseWrite —— 放行通过,草稿合并入正式版,**此刻**抛数据事件;原子且过冲突检查
|
|
*/
|
|
export type LedgerService = {
|
|
applyDeclarations(declarations: readonly ObjectDeclaration[]): Promise<SchemaApplyResult[]>;
|
|
describe(address: ObjectAddress): Promise<MaterializedObject | undefined>;
|
|
listObjects(): Promise<ObjectAddress[]>;
|
|
|
|
systemWrite(write: SystemWrite): Promise<void>;
|
|
draftWrite(write: DraftWrite): Promise<void>;
|
|
releaseWrite(taskId: TaskId): Promise<ReleaseWriteResult>;
|
|
|
|
/** 正式版查询 —— 跨任务只见过门的事实 */
|
|
query(query: LedgerQuery): Promise<LedgerPage>;
|
|
/** 任务视图 = 正式版 + 本任务草稿层 */
|
|
taskView(taskId: TaskId, query: LedgerQuery): Promise<LedgerPage>;
|
|
/**
|
|
* **本任务自己写的**草稿条目(读己之写的读面)。
|
|
* 与 `taskView` 的区别:那个是「正式版 + 我的草稿」的合并视图,
|
|
* 这个只回我写过的那些行 —— 引擎求值要区分「这一单的事实」与「别人放行后的事实」。
|
|
*/
|
|
taskDrafts(taskId: TaskId): Promise<Array<{ domain: string; object: string; key: Record<string, unknown>; patch: Record<string, unknown> }>>;
|
|
/** 落地预检第五项:数据冲突检查 */
|
|
checkConflicts(taskId: TaskId): Promise<ConflictFinding[]>;
|
|
discardDrafts(taskId: TaskId): Promise<void>;
|
|
};
|