M4: 范式引擎与任务运行时

skill-engine(L4):载方法不载权力(白名单外工具即拒)、结晶片段经 ToolInvoker 留痕、
  装配入信封、技能目录渐进披露

flow-engine(L5):四种步型、确定性谓词跳步、重试与声明给定的兜底、
  异步步即监听(时限必配)、写类工具登记动作意向、步序位置持久

loop-engine(L5):自研 CMMN 子集解析器(表外构件直接报错,子集封顶可机器证明)、
  两副标准生命周期与迁移拓扑(引擎不得私改)、Enabled ≠ Active、
  语义性前提标待裁量评估(引擎不代裁量)、DMN 确定性求值 + 命中行留痕、
  DRD 缺口演绎与拓扑序、双向驱动与交集导航(断点即人环)、三型行动、
  终局唯放行与 Harness

task(L6):终态五名裁定(released 唯一成功)、Harness 预算环外强制与停滞熔断
  (监听中是健康态)、控制三语义(叫停不是终态,记最重档纠正)、改派留痕通知双方、
  断点续跑三份持久状态、封卷触发蒸馏钩子

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

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 01:51:22 +08:00
co-authored by Claude Opus 5
parent 2850e6d4ef
commit 3c974d2860
55 changed files with 7113 additions and 1 deletions
@@ -0,0 +1,40 @@
/**
* module: flow-engine —— 对外类型(编码规范 §10.1;语义出处 AM 05)。
*
* flow 范式:步序声明运行器(四种步型、重试与兜底、事件即步条件)。
* **零临场调度** —— 运行中不得由 LLM 决定步序、跳步或兜底。
*/
import type { FlowModel, FlowStep, TaskId } from '@contracts';
import type { FailureAction, FlowIssue, FlowPosition, NextAction, StepRuntime, StepState } from './internal/domain/step-sequence.ts';
export type { FailureAction, FlowIssue, FlowModel, FlowPosition, FlowStep, NextAction, StepRuntime, StepState };
export declare class FlowDeclarationInvalidError extends Error {
readonly issues: readonly FlowIssue[];
constructor(issues: readonly FlowIssue[]);
}
/** 一次推进的结果 —— 由 task 驱动,不自转 */
export type AdvanceOutcome = {
readonly position: FlowPosition;
readonly status: 'running' | 'awaiting' | 'finished' | 'blocked';
/** awaiting 时:在等什么 */
readonly waitingFor?: {
readonly kind: 'human' | 'event' | 'time';
readonly ref: string;
readonly deadline: string;
};
/** finished 时:末步验收工单的裁决决定终态 */
readonly released?: boolean;
readonly blockedReason?: string;
};
export type FlowEngineService = {
/** 装载步序声明并校验 —— 谱必须全程可静态检查 */
load(taskId: TaskId, model: FlowModel): Promise<FlowPosition>;
position(taskId: TaskId): Promise<FlowPosition | undefined>;
/** 推进一步(或若干确定步);异步步进入 awaiting 并登记监听 */
advance(taskId: TaskId): Promise<AdvanceOutcome>;
/** 事件即步的完成条件:人事件 / 数据事件 / 时间事件到达即续跑 */
resume(taskId: TaskId, event: {
kind: 'human' | 'data' | 'time';
ref: string;
payload: Record<string, unknown>;
}): Promise<AdvanceOutcome>;
};
+11
View File
@@ -0,0 +1,11 @@
/**
* module: flow-engine —— 唯一出口。只做 re-export,不写逻辑(编码规范 §10.1)。
*/
export type { AdvanceOutcome, FailureAction, FlowEngineService, FlowIssue, FlowModel, FlowPosition, FlowStep, NextAction, StepRuntime, StepState, } from './contract.ts';
export { FlowDeclarationInvalidError } from './contract.ts';
export type { CardGateway, Clock, FlowStateStore, IdGenerator, ListenerRegistrar, LlmStepGateway, MemoryRecorder, PredicateEvaluator, TaskContext, TaskDataGateway, ToolStepInvoker, } from './port.ts';
export type { FlowRunnerDeps } from './internal/usecase/flow-runner.ts';
export { createFlowRunner } from './internal/usecase/flow-runner.ts';
export { checkDeclaration, failureAction, initialPosition, lastStepIsAcceptance, markStep, nextAction, parallelGroupComplete, STEP_STATES, } from './internal/domain/step-sequence.ts';
export { createFlowStateStore } from './internal/adapter/flow-state-store.ts';
export { flowStateTable } from './internal/adapter/flow-state-schema.ts';
+110
View File
@@ -0,0 +1,110 @@
/**
* module: flow-engine —— 本模块要外界提供的能力(编码规范 §10.1 / §5.3)。
*/
import type { FlowModel, StaffId, TaskId } from '@contracts';
import type { FlowPosition } from './internal/domain/step-sequence.ts';
export type Clock = {
now(): Date;
};
export type IdGenerator = {
next(): string;
};
/** 运行时实例状态 —— 三份持久状态之一(OS 09) */
export type FlowStateStore = {
save(taskId: TaskId, model: FlowModel, position: FlowPosition): Promise<void>;
load(taskId: TaskId): Promise<{
model: FlowModel;
position: FlowPosition;
} | undefined>;
};
/** 条件谓词求值 —— app 注入 `@sfeel`;零 LLM */
export type PredicateEvaluator = (expression: string, scope: Readonly<Record<string, unknown>>) => boolean;
/** 任务数据 —— app 注入 `ledger`(L1):读任务视图 = 正式版 + 本任务草稿层 */
export type TaskDataGateway = {
view(taskId: TaskId): Promise<Record<string, unknown>>;
draftWrite(input: {
taskId: TaskId;
domain: string;
object: string;
key: Record<string, string | number>;
patch: Record<string, unknown>;
}): Promise<void>;
};
/** 工具步与纯工具步 —— app 注入 `toolbox`(L2) */
export type ToolStepInvoker = {
invoke(input: {
tool: string;
input: Record<string, unknown>;
activityId: string;
taskId: TaskId;
stepNo: number;
}): Promise<{
ok: boolean;
output?: Record<string, unknown>;
error?: {
message: string;
retryable: boolean;
};
}>;
/** 写类工具在 flow 里也走「登记动作意向」,除非契约显式预授权 */
registerIntent(input: {
taskId: TaskId;
tool: string;
input: Record<string, unknown>;
label: string;
}): Promise<void>;
isWriteEffect(tool: string): Promise<boolean>;
};
/** LLM 步 —— app 注入 `llm`(L1)的 ModelGateway;模板与出参 schema 随声明版本冻结 */
export type LlmStepGateway = {
generate(input: {
model: string;
prompt: string;
outputSchema: Record<string, unknown>;
taskId: TaskId;
stepNo: number;
}): Promise<{
ok: boolean;
object?: unknown;
error?: string;
}>;
};
/** 人类工具步 —— app 注入 `human-tool`(L3) */
export type CardGateway = {
issue(input: {
taskId: TaskId;
ownerId: StaffId;
humanCallCap: number;
workOrder: 'execution' | 'acceptance';
card: Record<string, unknown>;
}): Promise<{
id: string;
}>;
};
/** 监听登记 —— app 注入 `event`(L1):异步步的完成条件 = 监听,时限必配 */
export type ListenerRegistrar = {
register(input: {
taskId: TaskId;
eventType: 'data' | 'time' | 'human';
keyFilter: Record<string, string>;
deadline: string;
}): Promise<{
id: string;
}>;
};
export type MemoryRecorder = {
append(input: {
taskId: TaskId;
kind: 'action' | 'result' | 'engine-transition';
title: string;
detail?: Record<string, unknown>;
}): Promise<void>;
};
/** 任务上下文 —— 活动 ID、负责人、预算 */
export type TaskContext = {
of(taskId: TaskId): Promise<{
activityId: string;
ownerId: StaffId;
humanCallCap: number;
}>;
};