Archived
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:
co-authored by
Claude Opus 5
parent
2850e6d4ef
commit
3c974d2860
@@ -0,0 +1,104 @@
|
||||
/**
|
||||
* module: task —— 对外类型(编码规范 §10.1;语义出处 OS 04,AM 01/10)。
|
||||
*
|
||||
* 任务运行时:生命周期与**终态五名裁定**、Harness 预算执行器 / 停滞熔断、
|
||||
* 控制三语义、改派、断点续跑。范式(loop / flow)在此汇流 —— 对流程层与交互层不可区分。
|
||||
*/
|
||||
import type { BudgetCaps, ControlSemantic, Paradigm, StaffId, TaskId, TaskRuntimeState, TerminalState } from '@contracts';
|
||||
import type { BudgetBreach, Consumption, HarnessVerdict } from './internal/domain/harness.ts';
|
||||
import type { ControlOutcome, ResumeReadiness, TaskSnapshot, TerminalCause } from './internal/domain/lifecycle.ts';
|
||||
|
||||
export type {
|
||||
BudgetBreach,
|
||||
BudgetCaps,
|
||||
Consumption,
|
||||
ControlOutcome,
|
||||
ControlSemantic,
|
||||
HarnessVerdict,
|
||||
Paradigm,
|
||||
ResumeReadiness,
|
||||
TaskRuntimeState,
|
||||
TaskSnapshot,
|
||||
TerminalCause,
|
||||
TerminalState,
|
||||
};
|
||||
|
||||
export class TaskNotFoundError extends Error {
|
||||
constructor(readonly taskId: TaskId) {
|
||||
super(`任务不存在:${taskId}`);
|
||||
this.name = 'TaskNotFoundError';
|
||||
}
|
||||
}
|
||||
|
||||
export class TaskAlreadyTerminalError extends Error {
|
||||
constructor(
|
||||
readonly taskId: TaskId,
|
||||
readonly terminal: TerminalState,
|
||||
) {
|
||||
super(`任务已终结(${terminal}),不得再推进:${taskId} —— 流级重做一律重开新实例`);
|
||||
this.name = 'TaskAlreadyTerminalError';
|
||||
}
|
||||
}
|
||||
|
||||
/** 一单任务 —— 活动的运行时实例;**恰有一名负责人** */
|
||||
export type Task = {
|
||||
readonly id: TaskId;
|
||||
readonly activityId: string;
|
||||
readonly paradigm: Paradigm;
|
||||
/** 起单来源:工作流节点;登记触发的直起单为 undefined */
|
||||
readonly workflowId?: string;
|
||||
readonly nodeId?: string;
|
||||
readonly ownerId: StaffId;
|
||||
readonly title: string;
|
||||
readonly runtime: TaskRuntimeState;
|
||||
readonly terminal?: TerminalState;
|
||||
readonly reason?: string;
|
||||
/** 装载信封:包版本 + 各资产生效版 —— 行为可归因 */
|
||||
readonly envelope: Readonly<Record<string, unknown>>;
|
||||
readonly caps: BudgetCaps;
|
||||
readonly used: Consumption;
|
||||
readonly startedAt: string;
|
||||
readonly finishedAt?: string;
|
||||
};
|
||||
|
||||
export type StartTaskInput = {
|
||||
readonly activityId: string;
|
||||
readonly ownerId: StaffId;
|
||||
readonly title: string;
|
||||
readonly workflowId?: string;
|
||||
readonly nodeId?: string;
|
||||
/** 输入:data(按 schema 校验,缺项不得启动)+ message(委托消息,可为空) */
|
||||
readonly data: Record<string, unknown>;
|
||||
readonly message?: string;
|
||||
};
|
||||
|
||||
export type TickOutcome = {
|
||||
readonly task: Task;
|
||||
readonly verdict: HarnessVerdict;
|
||||
readonly progressed: boolean;
|
||||
};
|
||||
|
||||
export type TaskService = {
|
||||
/** 起单:装载 → 校验输入 → 建任务记忆 → 首个回合 */
|
||||
start(input: StartTaskInput): Promise<Task>;
|
||||
get(taskId: TaskId): Promise<Task>;
|
||||
listByOwner(ownerId: StaffId, openOnly?: boolean): Promise<Task[]>;
|
||||
/** org 停用前置检查要问的「在途任务」 */
|
||||
openTasksOf(ownerId: StaffId): Promise<Array<{ taskId: string; title: string }>>;
|
||||
|
||||
/** 推进一拍:**预算在环外先扣先判**,再交范式引擎 */
|
||||
tick(taskId: TaskId): Promise<TickOutcome>;
|
||||
/** 事件驱动续跑 —— 挂起期间事件不丢,恢复即补投 */
|
||||
deliver(taskId: TaskId, event: { kind: 'data' | 'time' | 'human' | 'control'; ref: string; payload: Record<string, unknown> }): Promise<TickOutcome>;
|
||||
|
||||
/** 控制三语义:暂停 / 叫停 / 终止 */
|
||||
control(taskId: TaskId, semantic: ControlSemantic, by: StaffId, reason?: string): Promise<ControlOutcome>;
|
||||
resume(taskId: TaskId, by: StaffId): Promise<Task>;
|
||||
/** 改派:在途任务的负责人变更,**留痕并通知双方** */
|
||||
reassign(taskId: TaskId, to: StaffId, by: StaffId): Promise<Task>;
|
||||
|
||||
/** 终态裁定 —— 完成由框架裁定,终态由系统命名 */
|
||||
finish(taskId: TaskId, cause: TerminalCause): Promise<Task>;
|
||||
/** 断点续跑的三份持久状态是否齐备 */
|
||||
resumeReadiness(taskId: TaskId): Promise<ResumeReadiness>;
|
||||
};
|
||||
Reference in New Issue
Block a user